Skip to content

sisyffe/storepaths

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The storepaths library

Introduction

This cross-platform cross-language library allows you to retrieve common application folders location. In these folders you can store application-created data. For example, you can retrieve the configuration folder, the "data" folder, or the cache folder for the current user. To use this library, there is no complicated platform-checking operations to do, you just need to include a single header file:

#include <storepaths/storepaths.h>

Compatibility

Available platforms:

Platform Status
macOS ✅ Tests passed
Windows ✅ Tests passed
Linux ✅ Tests passed

The library can be used both in C and C++ with the same header file.

Examples

C++

#include <iostream>
#include <storepaths/storepaths.h>

#define APPNAME "Snake Game"

int main() {
    auto [dataFolder, dataFolderInfo] = storepaths::getDataFolder(APPNAME);
    if (!dataFolderInfo.succeeded) {
        // Error handling
    }

    std::cout << "Data folder: " << dataFolder << std::endl;
    return 0;
}

C

#include <stdio.h>
#include <storepaths/storepaths.h>

#define APPNAME "Snake Game"

int main(void) {
    char dataFolder[MAX_PATH_LENGTH]; // MAX_PATH_LENGTH is from the library
    PathInfo dataFolderInfo = getDataFolder(dataFolder, sizeof(dataFolder), APPNAME);
    if (!dataFolderInfo.succeeded) {
        // Error handling
    }

    printf("Data folder: %s", dataFolder);
    return 0;
}

The output may be:

  • on macOS (OSX): /Users/bob/Library/Application Support/Snake Game/config/,
  • on Windows: C:\Users\bob\AppData\Roaming\Snake Game\config\,
  • on linux systems: /home/bob/.config/Snake Game/.

The folder is created on the disk if it doesn't exist when the function is called. Every function returns an absolute path.

How to use the library

Build it yourself

The build process is fairly simple: it is a standard CMake project.

  1. Clone the project or download it
git clone https://github.com/sisyffe/storepaths.git
cd storepaths
  1. Check that you have CMake installed. If the following command fails, install cmake:
cmake --version
  1. Configure the project
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
  1. Build the project. If you get any errors there, good luck ! (more seriously post an issue)
cmake --build build # "build" refers to the directory
  1. Extract the files
  • The static library is at build/libstorepaths.a. Donc forgot to link it to your project!
  • The include directory is at include/storepaths.

In the CMakeLists.txt file, there is an option called BUILD_SHARED_LIBS (it build the library in .so/.dll/.dylib instead of .a/.lib), by default, it is OFF but you can enable it by adding -DBUILD_STATIC_LIBS=ON before including the path.

Other ways

  • Add it to your git repository a submodule and add it as a subdirectory of your project :
git submodule add https://github.com/sisyffe/storepaths.git

And then, in your CMakeLists.txt file:

# ...
add_subdirectory(storepaths)
target_include_directories(your-project PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/storepaths/include
        # ...
)
target_link_libraries(your-project PRIVATE storepaths)
# ...
  • You may want to install it as a package. Currently, it is not available in any package manager (e.g. Homebrew, APT...). Adding and install feature through CMake is planned.

About

C/C++ cross-platform library used to retrieve application specific data folders such as configuration, data, cache... folders.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors