common: Support macOS application data path conventions. (#6258)

This commit is contained in:
Steveice10 2023-01-23 01:50:50 -08:00 committed by GitHub
parent 9b20bcea0f
commit d704c6a3ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -20,6 +20,10 @@
#else
#ifdef _WIN32
#define EMU_DATA_DIR "Citra"
#elif defined(__APPLE__)
#define MACOS_EMU_DATA_DIR "Library" DIR_SEP "Application Support" DIR_SEP "Citra"
// For compatibility with XDG paths.
#define EMU_DATA_DIR "citra-emu"
#elif ANDROID
// On Android internal storage is mounted as "/sdcard"
#define SDCARD_DIR "sdcard"

View File

@ -709,13 +709,26 @@ void SetUserPath(const std::string& path) {
g_paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
g_paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
} else {
std::string data_dir = GetUserDirectory("XDG_DATA_HOME");
std::string config_dir = GetUserDirectory("XDG_CONFIG_HOME");
std::string cache_dir = GetUserDirectory("XDG_CACHE_HOME");
std::string data_dir = GetUserDirectory("XDG_DATA_HOME") + DIR_SEP EMU_DATA_DIR DIR_SEP;
std::string config_dir =
GetUserDirectory("XDG_CONFIG_HOME") + DIR_SEP EMU_DATA_DIR DIR_SEP;
std::string cache_dir =
GetUserDirectory("XDG_CACHE_HOME") + DIR_SEP EMU_DATA_DIR DIR_SEP;
user_path = data_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
g_paths.emplace(UserPath::ConfigDir, config_dir + DIR_SEP EMU_DATA_DIR DIR_SEP);
g_paths.emplace(UserPath::CacheDir, cache_dir + DIR_SEP EMU_DATA_DIR DIR_SEP);
#if defined(__APPLE__)
// If XDG directories don't already exist from a previous setup, use standard macOS
// paths.
if (!FileUtil::Exists(data_dir) && !FileUtil::Exists(config_dir) &&
!FileUtil::Exists(cache_dir)) {
data_dir = GetHomeDirectory() + DIR_SEP MACOS_EMU_DATA_DIR DIR_SEP;
config_dir = data_dir + CONFIG_DIR DIR_SEP;
cache_dir = data_dir + CACHE_DIR DIR_SEP;
}
#endif
user_path = data_dir;
g_paths.emplace(UserPath::ConfigDir, config_dir);
g_paths.emplace(UserPath::CacheDir, cache_dir);
}
#endif
}