diff --git a/CMakeLists.txt b/CMakeLists.txt index 853f206cd3..0e4a83d27f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index 41cb65c24c..9c0fe7eab5 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -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) diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index b623043220..5ba825f5e2 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -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); }