mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-12-31 08:21:11 -06:00
* Initial mod loader implementation. * Allow iterating in mod directories. * Initial append archive implementation. * Avoid calling function wrappers when loading append ARs. For some reason they cause issues. Should investigate later. * UMM merge archive support. * Load merge archives without archive lists. * Less thread locals. I shouldn't worry about string allocations this much when the game itself spams them... * Check for read-only UMM archives. TODO: Skip merging as it's currently just doing duplicate loads. * Skip loading merge archives if they are read-only. * Merge only archives. * Implement decompression. * Fix append ARLs not loading. * Initial save file redirection implementation. * Slightly refactor resolved path usage. * Implement save file redirection fallback. * Set a default save file path if none is provided. * Check for enabled option & replace backward slashes with forward ones in mod save file paths. * Convert back slashes to forward ones when iterating directories. * Make CSB limit dynamic. * Cache append/merge archive lookups. * Close stream after reading compressed ARL. * Fix UMM/HMM ARL file path inconsistency.
70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <mod/mod_loader.h>
|
|
|
|
#define USER_DIRECTORY "SWA"
|
|
|
|
#ifndef GAME_INSTALL_DIRECTORY
|
|
#define GAME_INSTALL_DIRECTORY "."
|
|
#endif
|
|
|
|
inline std::filesystem::path GetGamePath()
|
|
{
|
|
return GAME_INSTALL_DIRECTORY;
|
|
}
|
|
|
|
inline std::filesystem::path GetUserPath()
|
|
{
|
|
if (std::filesystem::exists(GAME_INSTALL_DIRECTORY "/portable.txt"))
|
|
return GAME_INSTALL_DIRECTORY;
|
|
|
|
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;
|
|
}
|
|
|
|
inline std::filesystem::path GetSavePath(bool checkForMods)
|
|
{
|
|
if (checkForMods && !ModLoader::s_saveFilePath.empty())
|
|
return ModLoader::s_saveFilePath.parent_path();
|
|
else
|
|
return GetUserPath() / "save";
|
|
}
|
|
|
|
// Returned file name may not necessarily be
|
|
// equal to SYS-DATA as mods can assign anything.
|
|
inline std::filesystem::path GetSaveFilePath(bool checkForMods)
|
|
{
|
|
if (checkForMods && !ModLoader::s_saveFilePath.empty())
|
|
return ModLoader::s_saveFilePath;
|
|
else
|
|
return GetSavePath(false) / "SYS-DATA";
|
|
}
|