diff --git a/README.md b/README.md index 2e13049..e988ad5 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ int main() { std::cout << "Config: " << sago::getConfigHome() << "\n"; std::cout << "Data: " << sago::getDataHome() << "\n"; + std::cout << "State: " << sago::getStateDir() << "\n"; std::cout << "Cache: " << sago::getCacheDir() << "\n"; std::cout << "Documents: " << sago::getDocumentsFolder() << "\n"; std::cout << "Desktop: " << sago::getDesktopFolder() << "\n"; @@ -113,6 +114,7 @@ int main() ``` Config: /home/poul/.config Data: /home/poul/.local/share +State: /home/poul/.local/state Cache: /home/poul/.cache Documents: /home/poul/Dokumenter Desktop: /home/poul/Skrivebord @@ -129,6 +131,7 @@ Save Games 2: /home/poul/.local/share ``` Config: C:\users\poul\Application Data Data: C:\users\poul\Application Data +State: C:\users\poul\Local Settings\Application Data Cache: C:\users\poul\Local Settings\Application Data Documents: C:\users\poul\Mine dokumenter Desktop: C:\users\poul\Skrivebord @@ -145,6 +148,7 @@ Save Games 2: C:\users\poul\Saved Games ``` Config: /Users/poul/Library/Application Support Data: /Users/poul/Library/Application Support +State: /Users/poul/Library/Application Support Cache: /Users/poul/Library/Caches Documents: /Users/poul/Documents Desktop: /Users/poul/Desktop diff --git a/platform_folders.cpp b/platform_folders.cpp index 08a23df..0c796b6 100644 --- a/platform_folders.cpp +++ b/platform_folders.cpp @@ -30,6 +30,7 @@ int main() { std::cout << "Config: " << sago::getConfigHome() << "\n"; std::cout << "Data: " << sago::getDataHome() << "\n"; + std::cout << "State: " << sago::getStateDir() << "\n"; std::cout << "Cache: " << sago::getCacheDir() << "\n"; std::cout << "Documents: " << sago::getDocumentsFolder() << "\n"; std::cout << "Desktop: " << sago::getDesktopFolder() << "\n"; diff --git a/sago/platform_folders.cpp b/sago/platform_folders.cpp index f4a1cd1..b1a0874 100644 --- a/sago/platform_folders.cpp +++ b/sago/platform_folders.cpp @@ -237,6 +237,16 @@ std::string getCacheDir() { #endif } +std::string getStateDir() { +#ifdef _WIN32 + return GetAppDataLocal(); +#elif defined(__APPLE__) + return getHome()+"/Library/Application Support"; +#else + return getLinuxFolderDefault("XDG_STATE_HOME", ".local/state"); +#endif +} + void appendAdditionalDataDirectories(std::vector& homes) { #ifdef _WIN32 homes.push_back(GetAppDataCommon()); diff --git a/sago/platform_folders.h b/sago/platform_folders.h index 4563410..742c829 100644 --- a/sago/platform_folders.h +++ b/sago/platform_folders.h @@ -55,7 +55,7 @@ std::string win32_utf16_to_utf8(const wchar_t* wstr); * string data_home = getDataHome()+"/My Program Name/"; * @endcode * On Windows this defaults to %APPDATA% (Roaming profile) - * On Linux this defaults to ~/.local/share but can be configured + * On Linux this defaults to ~/.local/share but can be configured by the user * @return The base folder for storing program data. */ std::string getDataHome(); @@ -67,7 +67,7 @@ std::string getDataHome(); * string data_home = getConfigHome()+"/My Program Name/"; * @endcode * On Windows this defaults to %APPDATA% (Roaming profile) - * On Linux this defaults to ~/.config but can be configured + * On Linux this defaults to ~/.config but can be configured by the user * @return The base folder for storing config data. */ std::string getConfigHome(); @@ -76,15 +76,29 @@ std::string getConfigHome(); * Retrives the base folder for storing cache files. * You must add the program name yourself like this: * @code{.cpp} - * string data_home = getCacheDir()+"/My Program Name/"; + * string data_home = getCacheDir()+"/My Program Name/cache/"; * @endcode * On Windows this defaults to %APPDATALOCAL% - * On Linux this defaults to ~/.cache but can be configured - * @return The base folder for storing data that do not need to be backed up. + * On Linux this defaults to ~/.cache but can be configured by the user + * Note that it is recommended to append "cache" after the program name to prevent conflicting with "StateDir" under Windows + * @return The base folder for storing data that do not need to be backed up and might be deleted. */ std::string getCacheDir(); /** + * Retrives the base folder used for state files. + * You must add the program name yourself like this: + * @code{.cpp} + * string data_home = getStateDir()+"/My Program Name/"; + * @endcode + * On Windows this defaults to %APPDATALOCAL% + * On Linux this defaults to ~/.local/state but can be configured by the user + * On OS X this is the same as getDataHome() + * @return The base folder for storing data that do not need to be backed up but should not be reguarly deleted either. + */ +std::string getStateDir(); + +/** * This will append extra folders that your program should be looking for data files in. * This does not normally include the path returned by GetDataHome(). * If you want all the folders you should do something like: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8bf74c6..c11103e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,6 +47,7 @@ _def_test("getMusicFolder") _def_test("getPicturesFolder") _def_test("getPublicFolder") _def_test("getSaveGamesFolder1") +_def_test("getStateDir") _def_test("getVideoFolder") _def_test("integration") _def_test("internalTest") \ No newline at end of file diff --git a/test/getStateDir.cpp b/test/getStateDir.cpp new file mode 100644 index 0000000..294a00c --- /dev/null +++ b/test/getStateDir.cpp @@ -0,0 +1,7 @@ +#include "tester.hpp" +#include "../sago/platform_folders.h" + +int main() { + run_test(sago::getStateDir()); + return 0; +}