Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,4 @@ FodyWeavers.xsd

UnleashedRecompLib/build
UnleashedRecompLib/ppc*
.vscode
11 changes: 10 additions & 1 deletion MarathonRecomp/user/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion MarathonRecomp/user/paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,44 @@ inline std::unordered_map<std::string, std::filesystem::path> g_pathCache;
bool CheckPortable();
std::filesystem::path BuildUserPath();
const std::filesystem::path& GetUserPath();

inline std::filesystem::path GetGamePath()
{
#ifdef __APPLE__
// On macOS, there is the expectation that the app may be installed to
// /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
Expand Down
Loading