diff --git a/.gitignore b/.gitignore index 3093c5c8..64a0ae62 100644 --- a/.gitignore +++ b/.gitignore @@ -404,3 +404,4 @@ FodyWeavers.xsd UnleashedRecompLib/build UnleashedRecompLib/ppc* +.vscode diff --git a/MarathonRecomp/user/paths.cpp b/MarathonRecomp/user/paths.cpp index e3dbf101..1c6584a0 100644 --- a/MarathonRecomp/user/paths.cpp +++ b/MarathonRecomp/user/paths.cpp @@ -36,7 +36,16 @@ std::filesystem::path BuildUserPath() // Prefer to store in the .config directory if it exists. Use the home directory otherwise. std::filesystem::path homePath = homeDir; #if defined(__linux__) - std::filesystem::path configPath = homePath / ".config"; + const char* configDir = getenv("XDG_CONFIG_HOME"); + std::filesystem::path configPath = ""; + if (configDir == nullptr) + { + configPath = homePath / ".config"; + } else + { + configPath = configDir; + } + #else std::filesystem::path configPath = homePath / "Library" / "Application Support"; #endif diff --git a/MarathonRecomp/user/paths.h b/MarathonRecomp/user/paths.h index 11f4abe8..9db377ff 100644 --- a/MarathonRecomp/user/paths.h +++ b/MarathonRecomp/user/paths.h @@ -14,7 +14,6 @@ inline std::unordered_map g_pathCache; bool CheckPortable(); std::filesystem::path BuildUserPath(); const std::filesystem::path& GetUserPath(); - inline std::filesystem::path GetGamePath() { #ifdef __APPLE__ @@ -22,6 +21,37 @@ inline std::filesystem::path GetGamePath() // /Applications/, and the bundle should not be modified. Thus we need // to install game files to the user directory instead of next to the app. return GetUserPath(); +#elif defined(__linux__) + // On Linux, and some other Unix-like systems like FreeBSD, + // following freedesktop's XDG Base Directory Specification is encouraged. + // https://specifications.freedesktop.org/basedir/latest/ + // basically, user-specific files should be installed to a user-set variable of $XDG_DATA_HOME + // If $XDG_DATA_HOME is either not set or empty, a default of $HOME/.local/share should be used. + if (CheckPortable()) + { + return GAME_INSTALL_DIRECTORY; + } + const char* homeDir = getenv("HOME"); + if (homeDir == nullptr) + { + homeDir = getpwuid(getuid())->pw_dir; + } + std::filesystem::path homePath = ""; + if (homeDir != nullptr) { + // Prefer to store in the .config directory if it exists. Use the home directory otherwise. + homePath = homeDir; + } + const char* dataDir = getenv("XDG_DATA_HOME"); + std::filesystem::path dataPath = ""; + if (dataDir != nullptr) + { + dataPath = dataDir; + } else + { + dataPath = homePath / ".local" / "share"; + } + std::filesystem::path gamePath = dataPath / "MarathonRecomp"; + return gamePath; #else return GAME_INSTALL_DIRECTORY; #endif