mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
UICommon: Respect XDG Base Directory Specification on POSIX systems.
This commit is contained in:
parent
491e149545
commit
e20b08491c
@ -76,8 +76,6 @@ else()
|
||||
set(datadir ${CMAKE_INSTALL_PREFIX}/share/dolphin-emu CACHE PATH "datadir")
|
||||
add_definitions(-DDATA_DIR="${datadir}/")
|
||||
endif()
|
||||
set(userdir ".dolphin-emu" CACHE STRING "User directory")
|
||||
add_definitions(-DUSER_DIR="${userdir}")
|
||||
|
||||
# Set where the binary files will be built. The program will not execute from
|
||||
# here. You must run "make install" to install these to the proper location
|
||||
|
@ -24,11 +24,7 @@
|
||||
#define DOLPHIN_DATA_DIR "/sdcard/dolphin-emu"
|
||||
#else
|
||||
#define USERDATA_DIR "user"
|
||||
#ifdef USER_DIR
|
||||
#define DOLPHIN_DATA_DIR USER_DIR
|
||||
#else
|
||||
#define DOLPHIN_DATA_DIR ".dolphin"
|
||||
#endif
|
||||
#define DOLPHIN_DATA_DIR "dolphin-emu"
|
||||
#endif
|
||||
|
||||
// Shared data dirs (Sys and shared User for Linux)
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user