Skip to content

Added Flatpak runtime detection #1301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
11 changes: 0 additions & 11 deletions UnleashedRecomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ if (WIN32)
option(UNLEASHED_RECOMP_D3D12 "Add D3D12 support for rendering" ON)
endif()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
option(UNLEASHED_RECOMP_FLATPAK "Configure the build for Flatpak compatibility." OFF)
endif()

function(BIN2C)
cmake_parse_arguments(BIN2C_ARGS "" "TARGET_OBJ;SOURCE_FILE;DEST_FILE;ARRAY_NAME;COMPRESSION_TYPE" "" ${ARGN})

Expand Down Expand Up @@ -300,13 +296,6 @@ else()
add_executable(UnleashedRecomp ${UNLEASHED_RECOMP_CXX_SOURCES})
endif()

if (UNLEASHED_RECOMP_FLATPAK)
target_compile_definitions(UnleashedRecomp PRIVATE
"UNLEASHED_RECOMP_FLATPAK"
"GAME_INSTALL_DIRECTORY=\"/var/data\""
)
endif()

if (UNLEASHED_RECOMP_D3D12)
find_package(directx-headers CONFIG REQUIRED)
find_package(directx12-agility CONFIG REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion UnleashedRecomp/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PPC_FUNC_IMPL(__imp__sub_824EB490);
PPC_FUNC(sub_824EB490)
{
App::s_isInit = true;
App::s_isMissingDLC = !Installer::checkAllDLC(GetGamePath());
App::s_isMissingDLC = !Installer::checkAllDLC(g_gameInstallPath);
App::s_language = Config::Language;

SWA::SGlobals::Init();
Expand Down
4 changes: 2 additions & 2 deletions UnleashedRecomp/kernel/xam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName, const
}
else if (pContentData->dwContentType == XCONTENTTYPE_DLC)
{
root = GAME_INSTALL_DIRECTORY "/dlc";
root = g_gameInstallPath / "dlc";
}
else
{
root = GAME_INSTALL_DIRECTORY;
root = g_gameInstallPath;
}

XamRegisterContent(*pContentData, root);
Expand Down
10 changes: 5 additions & 5 deletions UnleashedRecomp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ void KiSystemStartup()
{
const auto gameContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Game");
const auto updateContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Update");
XamRegisterContent(gameContent, GAME_INSTALL_DIRECTORY "/game");
XamRegisterContent(updateContent, GAME_INSTALL_DIRECTORY "/update");
XamRegisterContent(gameContent, (g_gameInstallPath / "game").string());
XamRegisterContent(updateContent, (g_gameInstallPath / "update").string());

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

std::error_code ec;
for (auto& file : std::filesystem::directory_iterator(GAME_INSTALL_DIRECTORY "/dlc", ec))
for (auto& file : std::filesystem::directory_iterator(g_gameInstallPath / "dlc", ec))
{
if (file.is_directory())
{
Expand Down Expand Up @@ -244,7 +244,7 @@ int main(int argc, char *argv[])
HostStartup();

std::filesystem::path modulePath;
bool isGameInstalled = Installer::checkGameInstall(GAME_INSTALL_DIRECTORY, modulePath);
bool isGameInstalled = Installer::checkGameInstall(g_gameInstallPath, modulePath);
bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled;
if (runInstallerWizard)
{
Expand All @@ -254,7 +254,7 @@ int main(int argc, char *argv[])
std::_Exit(1);
}

if (!InstallerWizard::Run(GAME_INSTALL_DIRECTORY, isGameInstalled && forceDLCInstaller))
if (!InstallerWizard::Run(g_gameInstallPath, isGameInstalled && forceDLCInstaller))
{
std::_Exit(0);
}
Expand Down
2 changes: 1 addition & 1 deletion UnleashedRecomp/mod/mod_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void ModLoader::Init()
{
configIni = {};

if (!configIni.read(GAME_INSTALL_DIRECTORY "/cpkredir.ini"))
if (!configIni.read(g_gameInstallPath / "cpkredir.ini"))
return;
}

Expand Down
4 changes: 4 additions & 0 deletions UnleashedRecomp/user/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <ui/game_window.h>
#include <user/paths.h>

#if defined(__linux__)
const bool g_isRunningUnderFlatpak = getenv("FLATPAK_ID") != nullptr;
#endif

std::vector<IConfigDef*> g_configDefinitions;

#define CONFIG_DEFINE_ENUM_TEMPLATE(type) \
Expand Down
4 changes: 4 additions & 0 deletions UnleashedRecomp/user/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <locale/locale.h>

#if defined(__linux__)
extern const bool g_isRunningUnderFlatpak;
#endif

class IConfigDef
{
public:
Expand Down
1 change: 1 addition & 0 deletions UnleashedRecomp/user/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

bool CheckPortable()
{
Expand Down
13 changes: 8 additions & 5 deletions UnleashedRecomp/user/paths.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#pragma once

#include <mod/mod_loader.h>
#include "config.h"

#define USER_DIRECTORY "UnleashedRecomp"

#ifndef GAME_INSTALL_DIRECTORY
#define GAME_INSTALL_DIRECTORY "."
#endif

extern std::filesystem::path g_executableRoot;

inline std::filesystem::path GetGamePath()
{
return GAME_INSTALL_DIRECTORY;
#if defined(__linux__)
if (g_isRunningUnderFlatpak)
return "/var/data";
else
#endif
return ".";
}

bool CheckPortable();
std::filesystem::path BuildUserPath();
const std::filesystem::path& GetUserPath();
extern const std::filesystem::path g_gameInstallPath;

inline std::filesystem::path GetSavePath(bool checkForMods)
{
Expand Down
2 changes: 1 addition & 1 deletion flatpak/io.github.hedge_dev.unleashedrecomp.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"name": "UnleashedRecomp",
"buildsystem": "simple",
"build-commands": [
"cmake --preset linux-release -DUNLEASHED_RECOMP_FLATPAK=ON -DSDL2MIXER_VORBIS=VORBISFILE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache",
"cmake --preset linux-release -DSDL2MIXER_VORBIS=VORBISFILE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache",
"cmake --build out/build/linux-release --target UnleashedRecomp",
"mkdir -p /app/bin",
"cp out/build/linux-release/UnleashedRecomp/UnleashedRecomp /app/bin/UnleashedRecomp",
Expand Down
Loading