mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 04:41:39 +00:00
Add Linux home path for GetUserPath().
This commit is contained in:
parent
9b6e4406b7
commit
2664f3bfd7
2 changed files with 30 additions and 6 deletions
|
|
@ -4,13 +4,19 @@
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <ShlObj_core.h>
|
||||||
|
#include <wrl/client.h>
|
||||||
|
|
||||||
|
using Microsoft::WRL::ComPtr;
|
||||||
|
#elif defined(__linux__)
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pwd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SWA_D3D12
|
#ifdef SWA_D3D12
|
||||||
#include <dxcapi.h>
|
#include <dxcapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ShlObj_core.h>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
@ -35,14 +41,11 @@
|
||||||
#include <imgui_impl_sdl2.h>
|
#include <imgui_impl_sdl2.h>
|
||||||
#include <o1heap.h>
|
#include <o1heap.h>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <wrl/client.h>
|
|
||||||
#include <smolv.h>
|
#include <smolv.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <miniaudio.h>
|
#include <miniaudio.h>
|
||||||
#include <extras/miniaudio_libvorbis.h>
|
#include <extras/miniaudio_libvorbis.h>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
using Microsoft::WRL::ComPtr;
|
|
||||||
|
|
||||||
#include "framework.h"
|
#include "framework.h"
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,35 @@ inline std::filesystem::path GetUserPath()
|
||||||
if (std::filesystem::exists("portable.txt"))
|
if (std::filesystem::exists("portable.txt"))
|
||||||
return std::filesystem::current_path();
|
return std::filesystem::current_path();
|
||||||
|
|
||||||
std::filesystem::path userPath{};
|
std::filesystem::path userPath;
|
||||||
|
|
||||||
// TODO: handle platform-specific paths.
|
#if defined(_WIN32)
|
||||||
PWSTR knownPath = NULL;
|
PWSTR knownPath = NULL;
|
||||||
if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &knownPath) == S_OK)
|
if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &knownPath) == S_OK)
|
||||||
userPath = std::filesystem::path{ knownPath } / USER_DIRECTORY;
|
userPath = std::filesystem::path{ knownPath } / USER_DIRECTORY;
|
||||||
|
|
||||||
CoTaskMemFree(knownPath);
|
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;
|
return userPath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue