diff --git a/UnleashedRecomp/stdafx.h b/UnleashedRecomp/stdafx.h index f673f185..b8800fb7 100644 --- a/UnleashedRecomp/stdafx.h +++ b/UnleashedRecomp/stdafx.h @@ -4,13 +4,19 @@ #if defined(_WIN32) #include +#include +#include + +using Microsoft::WRL::ComPtr; +#elif defined(__linux__) +#include +#include #endif #ifdef SWA_D3D12 #include #endif -#include #include #include #include @@ -35,14 +41,11 @@ #include #include #include -#include #include #include #include #include #include -using Microsoft::WRL::ComPtr; - #include "framework.h" #include "mutex.h" diff --git a/UnleashedRecomp/user/paths.h b/UnleashedRecomp/user/paths.h index 5af9d4ba..88d6c53a 100644 --- a/UnleashedRecomp/user/paths.h +++ b/UnleashedRecomp/user/paths.h @@ -12,14 +12,35 @@ inline std::filesystem::path GetUserPath() if (std::filesystem::exists("portable.txt")) return std::filesystem::current_path(); - std::filesystem::path userPath{}; + std::filesystem::path userPath; - // TODO: handle platform-specific paths. +#if defined(_WIN32) PWSTR knownPath = NULL; if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &knownPath) == S_OK) userPath = std::filesystem::path{ knownPath } / USER_DIRECTORY; CoTaskMemFree(knownPath); +#elif defined(__linux__) + const char *homeDir = getenv("HOME"); + if (homeDir == nullptr) + { + homeDir = getpwuid(getuid())->pw_dir; + } + + if (homeDir != nullptr) + { + // Prefer to store in the .config directory if it exists. Use the home directory otherwise. + const std::string dirName = "." USER_DIRECTORY; + std::filesystem::path homePath = homeDir; + std::filesystem::path configPath = homePath / ".config"; + if (std::filesystem::exists(configPath)) + userPath = configPath / dirName; + else + userPath = homePath / dirName; + } +#else + static_assert(false, "GetUserPath() not implemented for this platform."); +#endif return userPath; }