From 50e9e4c8c427bc51941f01c6978a0f320245b787 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Wed, 2 Feb 2022 00:51:40 +0100 Subject: [PATCH] Use XDG_DATA_HOME --- other/config_directory.sh | 5 +++-- src/base/system.cpp | 21 +++++++++++++++------ src/engine/shared/storage.cpp | 2 +- storage.cfg | 4 ++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/other/config_directory.sh b/other/config_directory.sh index abd53aa84..b9231f1d9 100755 --- a/other/config_directory.sh +++ b/other/config_directory.sh @@ -13,8 +13,9 @@ case "$(uname -s)" in open "$HOME/Library/Application Support/Teeworlds/" fi;; *) - if [ -d "$HOME/.ddnet/" ]; then - xdg-open "$HOME/.ddnet/" + DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" + if [ -d "$DATA_HOME/ddnet/" ]; then + xdg-open "$DATA_HOME/ddnet/" else xdg-open "$HOME/.teeworlds/" fi;; diff --git a/src/base/system.cpp b/src/base/system.cpp index e073c2869..2bf37d84d 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -2346,14 +2346,23 @@ int fs_storage_path(const char *appname, char *path, int max) #if defined(CONF_PLATFORM_HAIKU) str_format(path, max, "%s/config/settings/%s", home, appname); - return 0; -#endif - -#if defined(CONF_PLATFORM_MACOS) +#elif defined(CONF_PLATFORM_MACOS) str_format(path, max, "%s/Library/Application Support/%s", home, appname); #else - str_format(path, max, "%s/.%s", home, appname); - for(int i = str_length(home) + 2; path[i]; i++) + if(str_comp(appname, "Teeworlds") == 0) + { + // fallback for old directory for Teeworlds compatibility + str_format(path, max, "%s/.%s", home, appname); + } + else + { + char *data_home = getenv("XDG_DATA_HOME"); + if(data_home) + str_format(path, max, "%s/%s", data_home, appname); + else + str_format(path, max, "%s/.local/share/%s", home, appname); + } + for(int i = str_length(path) - str_length(appname); path[i]; i++) path[i] = tolower((unsigned char)path[i]); #endif diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp index 6f274d6b1..4b9f1abb4 100644 --- a/src/engine/shared/storage.cpp +++ b/src/engine/shared/storage.cpp @@ -60,7 +60,7 @@ public: } // add save directories - if(StorageType != STORAGETYPE_BASIC && m_NumPaths && (!m_aaStoragePaths[TYPE_SAVE][0] || !fs_makedir(m_aaStoragePaths[TYPE_SAVE]))) + if(StorageType != STORAGETYPE_BASIC && m_NumPaths && (!m_aaStoragePaths[TYPE_SAVE][0] || !fs_makedir_rec_for(m_aaStoragePaths[TYPE_SAVE]) || !fs_makedir(m_aaStoragePaths[TYPE_SAVE]))) { char aPath[IO_MAX_PATH_LENGTH]; if(StorageType == STORAGETYPE_CLIENT) diff --git a/storage.cfg b/storage.cfg index 344b51c4c..e00b0935c 100644 --- a/storage.cfg +++ b/storage.cfg @@ -6,10 +6,10 @@ # all data (settings.cfg, screenshots, ...) are stored. # There are 3 special paths available: # $USERDIR -# - ~/.appname on UNIX based systems +# - $XDG_DATA_HOME/appname (Usually ~/.local/share/appname) on UNIX based systems # - ~/Library/Applications Support/Appname on macOS # - %APPDATA%/Appname on Windows based systems -# Appname is DDNet, if that doesn't exist Teeworlds is used as a fallback +# Appname is DDNet, if that doesn't exist but Teeworlds does, it is used as a fallback # $DATADIR # - the 'data' directory which is part of an official # release