Skip to content

Commit d7d7c20

Browse files
committed
Added Flatpak runtime detection
1 parent cc1018a commit d7d7c20

File tree

10 files changed

+27
-26
lines changed

10 files changed

+27
-26
lines changed

UnleashedRecomp/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ if (WIN32)
44
option(UNLEASHED_RECOMP_D3D12 "Add D3D12 support for rendering" ON)
55
endif()
66

7-
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
8-
option(UNLEASHED_RECOMP_FLATPAK "Configure the build for Flatpak compatibility." OFF)
9-
endif()
10-
117
function(BIN2C)
128
cmake_parse_arguments(BIN2C_ARGS "" "TARGET_OBJ;SOURCE_FILE;DEST_FILE;ARRAY_NAME;COMPRESSION_TYPE" "" ${ARGN})
139

@@ -300,13 +296,6 @@ else()
300296
add_executable(UnleashedRecomp ${UNLEASHED_RECOMP_CXX_SOURCES})
301297
endif()
302298

303-
if (UNLEASHED_RECOMP_FLATPAK)
304-
target_compile_definitions(UnleashedRecomp PRIVATE
305-
"UNLEASHED_RECOMP_FLATPAK"
306-
"GAME_INSTALL_DIRECTORY=\"/var/data\""
307-
)
308-
endif()
309-
310299
if (UNLEASHED_RECOMP_D3D12)
311300
find_package(directx-headers CONFIG REQUIRED)
312301
find_package(directx12-agility CONFIG REQUIRED)

UnleashedRecomp/app.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ PPC_FUNC_IMPL(__imp__sub_824EB490);
3333
PPC_FUNC(sub_824EB490)
3434
{
3535
App::s_isInit = true;
36-
App::s_isMissingDLC = !Installer::checkAllDLC(GetGamePath());
36+
App::s_isMissingDLC = !Installer::checkAllDLC(g_gameInstallPath);
3737
App::s_language = Config::Language;
3838

3939
SWA::SGlobals::Init();

UnleashedRecomp/kernel/xam.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName, const
315315
}
316316
else if (pContentData->dwContentType == XCONTENTTYPE_DLC)
317317
{
318-
root = GAME_INSTALL_DIRECTORY "/dlc";
318+
root = g_gameInstallPath / "dlc";
319319
}
320320
else
321321
{
322-
root = GAME_INSTALL_DIRECTORY;
322+
root = g_gameInstallPath;
323323
}
324324

325325
XamRegisterContent(*pContentData, root);

UnleashedRecomp/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ void KiSystemStartup()
6161
{
6262
const auto gameContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Game");
6363
const auto updateContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Update");
64-
XamRegisterContent(gameContent, GAME_INSTALL_DIRECTORY "/game");
65-
XamRegisterContent(updateContent, GAME_INSTALL_DIRECTORY "/update");
64+
XamRegisterContent(gameContent, (g_gameInstallPath / "game").string());
65+
XamRegisterContent(updateContent, (g_gameInstallPath / "update").string());
6666

6767
const auto saveFilePath = GetSaveFilePath(true);
6868
bool saveFileExists = std::filesystem::exists(saveFilePath);
@@ -94,7 +94,7 @@ void KiSystemStartup()
9494
XamContentCreateEx(0, "D", &gameContent, OPEN_EXISTING, nullptr, nullptr, 0, 0, nullptr);
9595

9696
std::error_code ec;
97-
for (auto& file : std::filesystem::directory_iterator(GAME_INSTALL_DIRECTORY "/dlc", ec))
97+
for (auto& file : std::filesystem::directory_iterator(g_gameInstallPath / "dlc", ec))
9898
{
9999
if (file.is_directory())
100100
{
@@ -244,7 +244,7 @@ int main(int argc, char *argv[])
244244
HostStartup();
245245

246246
std::filesystem::path modulePath;
247-
bool isGameInstalled = Installer::checkGameInstall(GAME_INSTALL_DIRECTORY, modulePath);
247+
bool isGameInstalled = Installer::checkGameInstall(g_gameInstallPath, modulePath);
248248
bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled;
249249
if (runInstallerWizard)
250250
{
@@ -254,7 +254,7 @@ int main(int argc, char *argv[])
254254
std::_Exit(1);
255255
}
256256

257-
if (!InstallerWizard::Run(GAME_INSTALL_DIRECTORY, isGameInstalled && forceDLCInstaller))
257+
if (!InstallerWizard::Run(g_gameInstallPath, isGameInstalled && forceDLCInstaller))
258258
{
259259
std::_Exit(0);
260260
}

UnleashedRecomp/mod/mod_loader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void ModLoader::Init()
100100
{
101101
configIni = {};
102102

103-
if (!configIni.read(GAME_INSTALL_DIRECTORY "/cpkredir.ini"))
103+
if (!configIni.read(g_gameInstallPath / "cpkredir.ini"))
104104
return;
105105
}
106106

UnleashedRecomp/user/config.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <ui/game_window.h>
44
#include <user/paths.h>
55

6+
#if defined(__linux__)
7+
const bool g_isRunningUnderFlatpak = getenv("FLATPAK_ID") != nullptr;
8+
#endif
9+
610
std::vector<IConfigDef*> g_configDefinitions;
711

812
#define CONFIG_DEFINE_ENUM_TEMPLATE(type) \

UnleashedRecomp/user/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#include <locale/locale.h>
44

5+
#if defined(__linux__)
6+
extern const bool g_isRunningUnderFlatpak;
7+
#endif
8+
59
class IConfigDef
610
{
711
public:

UnleashedRecomp/user/paths.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
std::filesystem::path g_executableRoot = os::process::GetExecutablePath().remove_filename();
55
std::filesystem::path g_userPath = BuildUserPath();
6+
extern const std::filesystem::path g_gameInstallPath = GetGamePath();
67

78
bool CheckPortable()
89
{

UnleashedRecomp/user/paths.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
#pragma once
22

33
#include <mod/mod_loader.h>
4+
#include "config.h"
45

56
#define USER_DIRECTORY "UnleashedRecomp"
67

7-
#ifndef GAME_INSTALL_DIRECTORY
8-
#define GAME_INSTALL_DIRECTORY "."
9-
#endif
10-
118
extern std::filesystem::path g_executableRoot;
129

1310
inline std::filesystem::path GetGamePath()
1411
{
15-
return GAME_INSTALL_DIRECTORY;
12+
#if defined(__linux__)
13+
if (g_isRunningUnderFlatpak)
14+
return "/var/data";
15+
else
16+
#endif
17+
return ".";
1618
}
1719

1820
bool CheckPortable();
1921
std::filesystem::path BuildUserPath();
2022
const std::filesystem::path& GetUserPath();
23+
extern const std::filesystem::path g_gameInstallPath;
2124

2225
inline std::filesystem::path GetSavePath(bool checkForMods)
2326
{

flatpak/io.github.hedge_dev.unleashedrecomp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"name": "UnleashedRecomp",
2121
"buildsystem": "simple",
2222
"build-commands": [
23-
"cmake --preset linux-release -DUNLEASHED_RECOMP_FLATPAK=ON -DSDL2MIXER_VORBIS=VORBISFILE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache",
23+
"cmake --preset linux-release -DSDL2MIXER_VORBIS=VORBISFILE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache",
2424
"cmake --build out/build/linux-release --target UnleashedRecomp",
2525
"mkdir -p /app/bin",
2626
"cp out/build/linux-release/UnleashedRecomp/UnleashedRecomp /app/bin/UnleashedRecomp",

0 commit comments

Comments
 (0)