From d704c6a3ac9e28e007814e01a152adeeb9c57fd5 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Mon, 23 Jan 2023 01:50:50 -0800 Subject: [PATCH] common: Support macOS application data path conventions. (#6258) --- src/common/common_paths.h | 4 ++++ src/common/file_util.cpp | 25 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/common/common_paths.h b/src/common/common_paths.h index eec4dde9c..1699f14e6 100644 --- a/src/common/common_paths.h +++ b/src/common/common_paths.h @@ -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" diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 73c606972..7a53d294a 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -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 }