git repos / blockattack-game

commit 5bd8105f

Poul Sander · 2022-02-12 18:15
5bd8105f183142778e5d047004e7b7eca4f091f9 patch · browse files
parent 52c0a77a31ebed65b56ca47e30dd15dc9c8fdeb5

Changed PlatformFolders to 4.2.0

Changed files

M source/code/sago/platform_folders.cpp before
M source/code/sago/platform_folders.h before
diff --git a/source/code/sago/platform_folders.cpp b/source/code/sago/platform_folders.cpp index 1531e91..b1a0874 100644 --- a/source/code/sago/platform_folders.cpp +++ b/source/code/sago/platform_folders.cpp
@@ -103,8 +103,7 @@ std::string win32_utf16_to_utf8(const wchar_t* wstr) {
}
if (actualSize == 0) {
// WideCharToMultiByte return 0 for errors.
- const std::string errorMsg = "UTF16 to UTF8 failed with error code: " + GetLastError();
- throw std::runtime_error(errorMsg.c_str());
+ throw std::runtime_error("UTF16 to UTF8 failed with error code: " + std::to_string(GetLastError()));
}
return res;
}
@@ -238,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<std::string>& homes) {
#ifdef _WIN32
homes.push_back(GetAppDataCommon());
diff --git a/source/code/sago/platform_folders.h b/source/code/sago/platform_folders.h index 4563410..742c829 100644 --- a/source/code/sago/platform_folders.h +++ b/source/code/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: