mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 22:29:39 -06:00
UICommon: Respect XDG Base Directory Specification on POSIX systems.
This commit is contained in:
@ -137,11 +137,50 @@ void SetUserDirectory(const std::string& custom_path)
|
||||
user_path += DIR_SEP;
|
||||
#else
|
||||
if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
|
||||
{
|
||||
user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
||||
}
|
||||
else
|
||||
user_path = std::string(getenv("HOME") ?
|
||||
getenv("HOME") : getenv("PWD") ?
|
||||
getenv("PWD") : "") + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
{
|
||||
const char* home = getenv("HOME");
|
||||
if (!home)
|
||||
home = getenv("PWD");
|
||||
if (!home)
|
||||
home = "";
|
||||
std::string home_path = std::string(home) + DIR_SEP;
|
||||
|
||||
#if defined(__APPLE__) || defined(ANDROID)
|
||||
user_path = home_path + DOLPHIN_DATA_DIR DIR_SEP;
|
||||
#else
|
||||
// We are on a non-Apple and non-Android POSIX system, let's respect XDG basedir.
|
||||
// The only case we don't is when there is an existing ~/.dolphin-emu directory.
|
||||
// See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
|
||||
user_path = home_path + "." DOLPHIN_DATA_DIR DIR_SEP;
|
||||
if (!File::Exists(user_path))
|
||||
{
|
||||
const char* data_home = getenv("XDG_DATA_HOME");
|
||||
std::string data_path = std::string(data_home && data_home[0] == '/' ?
|
||||
data_home :
|
||||
(home_path + ".local" DIR_SEP "share")) + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
|
||||
const char* config_home = getenv("XDG_CONFIG_HOME");
|
||||
std::string config_path = std::string(config_home && config_home[0] == '/' ?
|
||||
config_home :
|
||||
(home_path + ".config")) + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
|
||||
const char* cache_home = getenv("XDG_CACHE_HOME");
|
||||
std::string cache_path = std::string(cache_home && cache_home[0] == '/' ?
|
||||
cache_home :
|
||||
(home_path + ".cache")) + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
|
||||
|
||||
File::SetUserPath(D_USER_IDX, data_path);
|
||||
File::SetUserPath(D_CONFIG_IDX, config_path);
|
||||
File::SetUserPath(D_CACHE_IDX, cache_path);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
File::SetUserPath(D_USER_IDX, user_path);
|
||||
}
|
||||
|
Reference in New Issue
Block a user