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")
set(TARGET_NAME "SWA")
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
option(SWA_FLATPAK "Configure the build for Flatpak compatibility." OFF)
endif()
if (WIN32)
option(SWA_D3D12 "Add D3D12 support for rendering" ON)
endif()
@ -49,14 +53,14 @@ add_compile_options(
-Wno-int-to-void-pointer-cast
-Wno-invalid-offsetof
-Wno-null-arithmetic
-Wno-null-conversion
-Wno-null-conversion
-Wno-tautological-undefined-compare
)
if (WIN32)
add_compile_options(/fp:strict)
else()
add_compile_options(-ffp-model=strict)
)
if (WIN32)
add_compile_options(/fp:strict)
else()
add_compile_options(-ffp-model=strict)
endif()
add_compile_definitions(
@ -183,46 +187,46 @@ set(SWA_INSTALL_CXX_SOURCES
"install/hashes/mazuri.cpp"
"install/hashes/spagonia.cpp"
"install/hashes/update.cpp"
)
)
set(SWA_USER_CXX_SOURCES
"user/achievement_data.cpp"
"user/config.cpp"
)
set(SWA_THIRDPARTY_SOURCES
"${SWA_THIRDPARTY_ROOT}/imgui/backends/imgui_impl_sdl2.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_demo.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_draw.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_tables.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_widgets.cpp"
"${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack/lzxd.c"
"${SWA_THIRDPARTY_ROOT}/tiny-AES-c/aes.c"
"${SWA_TOOLS_ROOT}/ShaderRecomp/thirdparty/smol-v/source/smolv.cpp"
)
set(SWA_THIRDPARTY_INCLUDES
"${SWA_THIRDPARTY_ROOT}/concurrentqueue"
)
set(SWA_THIRDPARTY_SOURCES
"${SWA_THIRDPARTY_ROOT}/imgui/backends/imgui_impl_sdl2.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_demo.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_draw.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_tables.cpp"
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_widgets.cpp"
"${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack/lzxd.c"
"${SWA_THIRDPARTY_ROOT}/tiny-AES-c/aes.c"
"${SWA_TOOLS_ROOT}/ShaderRecomp/thirdparty/smol-v/source/smolv.cpp"
)
set(SWA_THIRDPARTY_INCLUDES
"${SWA_THIRDPARTY_ROOT}/concurrentqueue"
"${SWA_THIRDPARTY_ROOT}/ddspp"
"${SWA_THIRDPARTY_ROOT}/imgui"
"${SWA_THIRDPARTY_ROOT}/imgui"
"${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack"
"${SWA_THIRDPARTY_ROOT}/magic_enum/include"
"${SWA_THIRDPARTY_ROOT}/magic_enum/include"
"${SWA_THIRDPARTY_ROOT}/miniaudio"
"${SWA_THIRDPARTY_ROOT}/stb"
"${SWA_THIRDPARTY_ROOT}/tiny-AES-c"
"${SWA_THIRDPARTY_ROOT}/stb"
"${SWA_THIRDPARTY_ROOT}/tiny-AES-c"
"${SWA_THIRDPARTY_ROOT}/TinySHA1"
"${SWA_THIRDPARTY_ROOT}/unordered_dense/include"
"${SWA_THIRDPARTY_ROOT}/volk"
"${SWA_THIRDPARTY_ROOT}/Vulkan-Headers/include"
"${SWA_THIRDPARTY_ROOT}/VulkanMemoryAllocator/include"
"${SWA_TOOLS_ROOT}/bc_diff"
"${SWA_THIRDPARTY_ROOT}/volk"
"${SWA_THIRDPARTY_ROOT}/Vulkan-Headers/include"
"${SWA_THIRDPARTY_ROOT}/VulkanMemoryAllocator/include"
"${SWA_TOOLS_ROOT}/bc_diff"
"${SWA_TOOLS_ROOT}/ShaderRecomp/thirdparty/smol-v/source"
)
if (SWA_D3D12)
list(APPEND SWA_THIRDPARTY_INCLUDES "${SWA_THIRDPARTY_ROOT}/D3D12MemoryAllocator/include")
list(APPEND SWA_THIRDPARTY_SOURCES "${SWA_THIRDPARTY_ROOT}/D3D12MemoryAllocator/src/D3D12MemAlloc.cpp")
)
if (SWA_D3D12)
list(APPEND SWA_THIRDPARTY_INCLUDES "${SWA_THIRDPARTY_ROOT}/D3D12MemoryAllocator/include")
list(APPEND SWA_THIRDPARTY_SOURCES "${SWA_THIRDPARTY_ROOT}/D3D12MemoryAllocator/src/D3D12MemAlloc.cpp")
endif()
set_source_files_properties(${SWA_THIRDPARTY_SOURCES} PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
@ -244,7 +248,7 @@ set(SWA_CXX_SOURCES
${SWA_PATCHES_CXX_SOURCES}
${SWA_UI_CXX_SOURCES}
${SWA_INSTALL_CXX_SOURCES}
${SWA_USER_CXX_SOURCES}
${SWA_USER_CXX_SOURCES}
${SWA_THIRDPARTY_SOURCES}
)
@ -259,13 +263,17 @@ endif()
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)
find_package(directx-headers CONFIG REQUIRED)
find_package(directx12-agility CONFIG REQUIRED)
target_compile_definitions(UnleashedRecomp PRIVATE SWA_D3D12)
endif()
find_package(directx-dxc REQUIRED)
find_package(directx-dxc REQUIRED)
if (SWA_D3D12)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/D3D12)
@ -281,7 +289,7 @@ if (SWA_D3D12)
Microsoft::DirectX-Headers
Microsoft::DirectX-Guids
Microsoft::DirectX12-Agility
Microsoft::DirectXShaderCompiler
Microsoft::DirectXShaderCompiler
Microsoft::DXIL
dxgi
)
@ -299,7 +307,7 @@ if (WIN32)
endif()
target_link_libraries(UnleashedRecomp PRIVATE
fmt::fmt
fmt::fmt
libzstd_static
msdf-atlas-gen::msdf-atlas-gen
nfd::nfd
@ -308,12 +316,13 @@ target_link_libraries(UnleashedRecomp PRIVATE
SDL2::SDL2-static
tomlplusplus::tomlplusplus
UnleashedRecompLib
Vorbis::vorbisfile
xxHash::xxhash )
Vorbis::vorbisfile
xxHash::xxhash
)
target_include_directories(UnleashedRecomp PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/api"
"${CMAKE_CURRENT_SOURCE_DIR}/api"
${SWA_THIRDPARTY_INCLUDES}
)

View file

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

View file

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

View file

@ -96,7 +96,7 @@ static double g_appearTime = 0.0;
static double g_disappearTime = DBL_MAX;
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_updateSourcePath;
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();
NFD_Init();

View file

@ -9,5 +9,5 @@ struct InstallerWizard
static void Init();
static void Draw();
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
static inline std::vector<IConfigDef*> g_configDefinitions{};
inline std::vector<IConfigDef*> g_configDefinitions;
CONFIG_DEFINE_ENUM_TEMPLATE(ELanguage)
{

View file

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

View file

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