mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-01-03 10:10:06 -06:00
Implemented Windows registry read/write (#225)
* Implemented Windows registry read/write * Simplify registry API and handle path writes * Linux SetWorkingDirectory * Implement reading path and unicode string from windows registry * Use string_view value names for registry * Use RegGetValueW * Paths adjustments * / * Update working directory update failure message * Updated linux SetWorkingDirectory * Update flatpak define * Remove RootDirectoryPath and save registry at startup * dont save registry on exit * Slight formatting update --------- Co-authored-by: Sajid <sajidur78@gmail.com>
This commit is contained in:
52
UnleashedRecomp/user/paths.cpp
Normal file
52
UnleashedRecomp/user/paths.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "paths.h"
|
||||
#include <os/process.h>
|
||||
|
||||
std::filesystem::path g_executableRoot = os::process::GetExecutablePath().remove_filename();
|
||||
std::filesystem::path g_userPath = BuildUserPath();
|
||||
|
||||
bool CheckPortable()
|
||||
{
|
||||
return std::filesystem::exists(g_executableRoot / "portable.txt");
|
||||
}
|
||||
|
||||
std::filesystem::path BuildUserPath()
|
||||
{
|
||||
if (CheckPortable())
|
||||
return g_executableRoot;
|
||||
|
||||
std::filesystem::path userPath;
|
||||
|
||||
#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.
|
||||
std::filesystem::path homePath = homeDir;
|
||||
std::filesystem::path configPath = homePath / ".config";
|
||||
if (std::filesystem::exists(configPath))
|
||||
userPath = configPath / USER_DIRECTORY;
|
||||
else
|
||||
userPath = homePath / ("." USER_DIRECTORY);
|
||||
}
|
||||
#else
|
||||
static_assert(false, "GetUserPath() not implemented for this platform.");
|
||||
#endif
|
||||
|
||||
return userPath;
|
||||
}
|
||||
|
||||
const std::filesystem::path& GetUserPath()
|
||||
{
|
||||
return g_userPath;
|
||||
}
|
||||
Reference in New Issue
Block a user