[linux] Use $XDG_CONFIG_HOME if defined instead of $HOME/.config (fix #2332)

This commit is contained in:
David Capello 2021-04-08 15:56:32 -03:00
parent f1b02a3347
commit 64f96f0851
3 changed files with 30 additions and 7 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
@ -81,7 +81,7 @@ ConfigModule::ConfigModule()
#elif !defined(_WIN32)
// On Linux we migrate the old configuration file name
// (.asepriterc -> ~/.config/aseprite/aseprite.ini)
// (~/.asepriterc -> ~/.config/aseprite/aseprite.ini)
{
ResourceFinder old_rf;
old_rf.includeHomeDir(".asepriterc");

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
@ -105,8 +105,8 @@ void ResourceFinder::includeDataDir(const char* filename)
#else
// $HOME/.config/aseprite/filename
sprintf(buf, ".config/aseprite/data/%s", filename);
includeHomeDir(buf);
sprintf(buf, "aseprite/data/%s", filename);
includeHomeConfigDir(buf);
// $BINDIR/data/filename
sprintf(buf, "data/%s", filename);
@ -150,6 +150,24 @@ void ResourceFinder::includeHomeDir(const char* filename)
#endif
}
#if !defined(_WIN32) && !defined(__APPLE__)
// For Linux: It's $XDG_CONFIG_HOME or $HOME/.config
void ResourceFinder::includeHomeConfigDir(const char* filename)
{
char* configHome = std::getenv("XDG_CONFIG_HOME");
if (configHome && *configHome) {
// $XDG_CONFIG_HOME/filename
addPath(base::join_path(configHome, filename));
}
else {
// $HOME/.config/filename
includeHomeDir(base::join_path(std::string(".config"), filename).c_str());
}
}
#endif // !defined(_WIN32) && !defined(__APPLE__)
void ResourceFinder::includeUserDir(const char* filename)
{
#ifdef _WIN32
@ -185,7 +203,7 @@ void ResourceFinder::includeUserDir(const char* filename)
#else // !__APPLE__
// $HOME/.config/aseprite/filename
includeHomeDir((std::string(".config/aseprite/") + filename).c_str());
includeHomeConfigDir((std::string("aseprite/") + filename).c_str());
#endif
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -42,6 +42,11 @@ namespace app {
void includeDataDir(const char* filename);
void includeHomeDir(const char* filename);
#if !defined(_WIN32) && !defined(__APPLE__)
// For Linux: It's $XDG_CONFIG_HOME or $HOME/.config
void includeHomeConfigDir(const char* filename);
#endif
// Tries to add the given filename in these locations:
// For Windows:
// - If ASEPRITE_USER_FOLDER environment variable is defined, it