Use XDG_DATA_HOME

This commit is contained in:
Dennis Felsing 2022-02-02 00:51:40 +01:00
parent 790c1cc0aa
commit 50e9e4c8c4
4 changed files with 21 additions and 11 deletions

View File

@ -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;;

View File

@ -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

View File

@ -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)

View File

@ -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