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>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.
#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;
}#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.
The build process is fairly simple: it is a standard CMake project.
- Clone the project or download it
git clone https://github.com/sisyffe/storepaths.git
cd storepaths- Check that you have CMake installed. If the following command fails, install cmake:
cmake --version- Configure the project
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release- Build the project. If you get any errors there, good luck ! (more seriously post an issue)
cmake --build build # "build" refers to the directory- 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.
- 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)
# ...