Moved game data folder to ~/.local/share/UnleashedRecomp

This commit is contained in:
Jujstme 2025-03-06 22:04:10 +01:00
parent df5e48f528
commit 13c0146b42
9 changed files with 109 additions and 80 deletions

View file

@ -303,7 +303,7 @@ endif()
if (UNLEASHED_RECOMP_FLATPAK) if (UNLEASHED_RECOMP_FLATPAK)
target_compile_definitions(UnleashedRecomp PRIVATE target_compile_definitions(UnleashedRecomp PRIVATE
"UNLEASHED_RECOMP_FLATPAK" "UNLEASHED_RECOMP_FLATPAK"
"GAME_INSTALL_DIRECTORY=\"/var/data\"" "GAME_INSTALL_DIRECTORY_PREPROC=\"/var/data\""
) )
endif() endif()

View file

@ -33,7 +33,7 @@ PPC_FUNC_IMPL(__imp__sub_824EB490);
PPC_FUNC(sub_824EB490) PPC_FUNC(sub_824EB490)
{ {
App::s_isInit = true; App::s_isInit = true;
App::s_isMissingDLC = !Installer::checkAllDLC(GetGamePath()); App::s_isMissingDLC = !Installer::checkAllDLC(g_gamepath);
App::s_language = Config::Language; App::s_language = Config::Language;
SWA::SGlobals::Init(); SWA::SGlobals::Init();

View file

@ -315,11 +315,11 @@ uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName, const
} }
else if (pContentData->dwContentType == XCONTENTTYPE_DLC) else if (pContentData->dwContentType == XCONTENTTYPE_DLC)
{ {
root = GAME_INSTALL_DIRECTORY "/dlc"; root = g_gamepath + "/dlc";
} }
else else
{ {
root = GAME_INSTALL_DIRECTORY; root = g_gamepath;
} }
XamRegisterContent(*pContentData, root); XamRegisterContent(*pContentData, root);

View file

@ -51,8 +51,8 @@ void KiSystemStartup()
{ {
const auto gameContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Game"); const auto gameContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Game");
const auto updateContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Update"); const auto updateContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Update");
XamRegisterContent(gameContent, GAME_INSTALL_DIRECTORY "/game"); XamRegisterContent(gameContent, g_gamepath + "/game");
XamRegisterContent(updateContent, GAME_INSTALL_DIRECTORY "/update"); XamRegisterContent(updateContent, g_gamepath + "/update");
const auto saveFilePath = GetSaveFilePath(true); const auto saveFilePath = GetSaveFilePath(true);
bool saveFileExists = std::filesystem::exists(saveFilePath); bool saveFileExists = std::filesystem::exists(saveFilePath);
@ -84,7 +84,7 @@ void KiSystemStartup()
XamContentCreateEx(0, "D", &gameContent, OPEN_EXISTING, nullptr, nullptr, 0, 0, nullptr); XamContentCreateEx(0, "D", &gameContent, OPEN_EXISTING, nullptr, nullptr, 0, 0, nullptr);
std::error_code ec; std::error_code ec;
for (auto& file : std::filesystem::directory_iterator(GAME_INSTALL_DIRECTORY "/dlc", ec)) for (auto& file : std::filesystem::directory_iterator(g_gamepath + "/dlc", ec))
{ {
if (file.is_directory()) if (file.is_directory())
{ {
@ -198,7 +198,7 @@ int main(int argc, char *argv[])
HostStartup(); HostStartup();
std::filesystem::path modulePath; std::filesystem::path modulePath;
bool isGameInstalled = Installer::checkGameInstall(GAME_INSTALL_DIRECTORY, modulePath); bool isGameInstalled = Installer::checkGameInstall(g_gamepath, modulePath);
bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled; bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled;
if (runInstallerWizard) if (runInstallerWizard)
{ {
@ -208,7 +208,7 @@ int main(int argc, char *argv[])
std::_Exit(1); std::_Exit(1);
} }
if (!InstallerWizard::Run(GAME_INSTALL_DIRECTORY, isGameInstalled && forceDLCInstaller)) if (!InstallerWizard::Run(g_gamepath, isGameInstalled && forceDLCInstaller))
{ {
std::_Exit(0); std::_Exit(0);
} }

View file

@ -100,7 +100,7 @@ void ModLoader::Init()
{ {
configIni = {}; configIni = {};
if (!configIni.read(GAME_INSTALL_DIRECTORY "/cpkredir.ini")) if (!configIni.read(g_gamepath + "/cpkredir.ini"))
return; return;
} }

View file

@ -8,6 +8,12 @@ std::vector<IConfigDef*> g_configDefinitions;
#define CONFIG_DEFINE_ENUM_TEMPLATE(type) \ #define CONFIG_DEFINE_ENUM_TEMPLATE(type) \
static std::unordered_map<std::string, type> g_##type##_template = static std::unordered_map<std::string, type> g_##type##_template =
#if defined(__linux__)
const bool g_isRuntimeFlatpak = getenv("FLATPAK_SANDBOX_DIR") != nullptr;
#else
const bool g_isRuntimeFlatpak = false;
#endif
CONFIG_DEFINE_ENUM_TEMPLATE(ELanguage) CONFIG_DEFINE_ENUM_TEMPLATE(ELanguage)
{ {
{ "English", ELanguage::English }, { "English", ELanguage::English },

View file

@ -2,6 +2,8 @@
#include <locale/locale.h> #include <locale/locale.h>
extern const bool g_isRuntimeFlatpak;
class IConfigDef class IConfigDef
{ {
public: public:

View file

@ -1,14 +1,38 @@
#include "paths.h" #include "paths.h"
#include <user/config.h>
#include <os/process.h> #include <os/process.h>
std::filesystem::path g_executableRoot = os::process::GetExecutablePath().remove_filename(); std::filesystem::path g_executableRoot = os::process::GetExecutablePath().remove_filename();
std::filesystem::path g_userPath = BuildUserPath(); std::filesystem::path g_userPath = BuildUserPath();
extern const std::string g_gamepath = GetGamePath().string();
bool CheckPortable() bool CheckPortable()
{ {
return std::filesystem::exists(g_executableRoot / "portable.txt"); return std::filesystem::exists(g_executableRoot / "portable.txt");
} }
std::filesystem::path GetGamePath()
{
#if defined(__linux__)
if (g_isRuntimeFlatpak || CheckPortable())
return GAME_INSTALL_DIRECTORY_PREPROC;
const char* homeDir = getenv("HOME");
if (homeDir == nullptr)
{
return GAME_INSTALL_DIRECTORY_PREPROC;
}
else
{
std::filesystem::path homePath = homeDir;
std::filesystem::path gamePath = homePath / ".local/share" / USER_DIRECTORY;
return gamePath;
}
#else
return GAME_INSTALL_DIRECTORY_PREPROC;
#endif
}
std::filesystem::path BuildUserPath() std::filesystem::path BuildUserPath()
{ {
if (CheckPortable()) if (CheckPortable())

View file

@ -4,18 +4,15 @@
#define USER_DIRECTORY "UnleashedRecomp" #define USER_DIRECTORY "UnleashedRecomp"
#ifndef GAME_INSTALL_DIRECTORY #ifndef GAME_INSTALL_DIRECTORY_PREPROC
#define GAME_INSTALL_DIRECTORY "." #define GAME_INSTALL_DIRECTORY_PREPROC "."
#endif #endif
inline std::filesystem::path GetGamePath()
{
return GAME_INSTALL_DIRECTORY;
}
bool CheckPortable(); bool CheckPortable();
std::filesystem::path BuildUserPath(); std::filesystem::path BuildUserPath();
const std::filesystem::path& GetUserPath(); const std::filesystem::path& GetUserPath();
extern const std::string g_gamepath;
std::filesystem::path GetGamePath();
inline std::filesystem::path GetSavePath(bool checkForMods) inline std::filesystem::path GetSavePath(bool checkForMods)
{ {