Add game install directory override for flatpak.

This commit is contained in:
Dario 2024-12-17 22:16:14 -03:00
parent 16a94e93b7
commit 81aec7d5f4
8 changed files with 73 additions and 58 deletions

View file

@ -1,6 +1,10 @@
project("UnleashedRecomp") project("UnleashedRecomp")
set(TARGET_NAME "SWA") set(TARGET_NAME "SWA")
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
option(SWA_FLATPAK "Configure the build for Flatpak compatibility." OFF)
endif()
if (WIN32) if (WIN32)
option(SWA_D3D12 "Add D3D12 support for rendering" ON) option(SWA_D3D12 "Add D3D12 support for rendering" ON)
endif() endif()
@ -259,6 +263,10 @@ endif()
set_target_properties(UnleashedRecomp PROPERTIES OUTPUT_NAME ${TARGET_NAME}) set_target_properties(UnleashedRecomp PROPERTIES OUTPUT_NAME ${TARGET_NAME})
if (SWA_FLATPAK)
target_compile_definitions(UnleashedRecomp PRIVATE "GAME_INSTALL_DIRECTORY=\"/var/data\"")
endif()
if (SWA_D3D12) if (SWA_D3D12)
find_package(directx-headers CONFIG REQUIRED) find_package(directx-headers CONFIG REQUIRED)
find_package(directx12-agility CONFIG REQUIRED) find_package(directx12-agility CONFIG REQUIRED)
@ -309,7 +317,8 @@ target_link_libraries(UnleashedRecomp PRIVATE
tomlplusplus::tomlplusplus tomlplusplus::tomlplusplus
UnleashedRecompLib UnleashedRecompLib
Vorbis::vorbisfile Vorbis::vorbisfile
xxHash::xxhash ) xxHash::xxhash
)
target_include_directories(UnleashedRecomp PRIVATE target_include_directories(UnleashedRecomp PRIVATE
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}

View file

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

View file

@ -50,8 +50,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, std::filesystem::exists("./game") ? "./game" : "."); XamRegisterContent(gameContent, GAME_INSTALL_DIRECTORY "/game");
XamRegisterContent(updateContent, "./update"); XamRegisterContent(updateContent, GAME_INSTALL_DIRECTORY "/update");
const auto savePath = GetSavePath(); const auto savePath = GetSavePath();
const auto saveName = "SYS-DATA"; const auto saveName = "SYS-DATA";
@ -70,7 +70,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("./dlc", ec)) for (auto& file : std::filesystem::directory_iterator(GAME_INSTALL_DIRECTORY "/dlc", ec))
{ {
if (file.is_directory()) if (file.is_directory())
{ {
@ -151,13 +151,13 @@ int main(int argc, char *argv[])
HostStartup(); HostStartup();
bool isGameInstalled = Installer::checkGameInstall("."); bool isGameInstalled = Installer::checkGameInstall(GAME_INSTALL_DIRECTORY);
bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled; bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled;
if (runInstallerWizard) if (runInstallerWizard)
{ {
Video::CreateHostDevice(); Video::CreateHostDevice();
if (!InstallerWizard::Run(isGameInstalled && forceDLCInstaller)) if (!InstallerWizard::Run(GAME_INSTALL_DIRECTORY, isGameInstalled && forceDLCInstaller))
{ {
return 1; return 1;
} }

View file

@ -96,7 +96,7 @@ static double g_appearTime = 0.0;
static double g_disappearTime = DBL_MAX; static double g_disappearTime = DBL_MAX;
static bool g_isDisappearing = false; static bool g_isDisappearing = false;
static std::filesystem::path g_installPath = "."; static std::filesystem::path g_installPath;
static std::filesystem::path g_gameSourcePath; static std::filesystem::path g_gameSourcePath;
static std::filesystem::path g_updateSourcePath; static std::filesystem::path g_updateSourcePath;
static std::array<std::filesystem::path, int(DLC::Count)> g_dlcSourcePaths; static std::array<std::filesystem::path, int(DLC::Count)> g_dlcSourcePaths;
@ -1426,8 +1426,10 @@ void InstallerWizard::Shutdown()
} }
} }
bool InstallerWizard::Run(bool skipGame) bool InstallerWizard::Run(std::filesystem::path installPath, bool skipGame)
{ {
g_installPath = installPath;
EmbeddedPlayer::Init(); EmbeddedPlayer::Init();
NFD_Init(); NFD_Init();

View file

@ -9,5 +9,5 @@ struct InstallerWizard
static void Init(); static void Init();
static void Draw(); static void Draw();
static void Shutdown(); static void Shutdown();
static bool Run(bool skipGame); static bool Run(std::filesystem::path installPath, bool skipGame);
}; };

View file

@ -50,7 +50,7 @@ public:
#define WINDOWPOS_CENTRED 0x2FFF0000 #define WINDOWPOS_CENTRED 0x2FFF0000
static inline std::vector<IConfigDef*> g_configDefinitions{}; inline std::vector<IConfigDef*> g_configDefinitions;
CONFIG_DEFINE_ENUM_TEMPLATE(ELanguage) CONFIG_DEFINE_ENUM_TEMPLATE(ELanguage)
{ {

View file

@ -2,6 +2,10 @@
#define USER_DIRECTORY "SWA" #define USER_DIRECTORY "SWA"
#ifndef GAME_INSTALL_DIRECTORY
#define GAME_INSTALL_DIRECTORY "."
#endif
inline std::filesystem::path GetGamePath() inline std::filesystem::path GetGamePath()
{ {
return std::filesystem::current_path(); return std::filesystem::current_path();

View file

@ -19,7 +19,7 @@
"name": "UnleashedRecomp", "name": "UnleashedRecomp",
"buildsystem": "simple", "buildsystem": "simple",
"build-commands": [ "build-commands": [
"cmake --preset linux-release", "cmake --preset linux-release -DSWA_FLATPAK=ON",
"cmake --build out/build/linux-release", "cmake --build out/build/linux-release",
"mkdir -p /app/bin", "mkdir -p /app/bin",
"cp out/build/linux-release/UnleashedRecomp/SWA /app/bin/SWA" "cp out/build/linux-release/UnleashedRecomp/SWA /app/bin/SWA"
@ -27,7 +27,7 @@
"sources": [ "sources": [
{ {
"type": "git", "type": "git",
"branch": "linux", "branch": "linux-flatpak",
"disable-shallow-clone": true, "disable-shallow-clone": true,
"url": "https://github.com/hedge-dev/UnleashedRecomp.git" "url": "https://github.com/hedge-dev/UnleashedRecomp.git"
}, },