From 32cfa1626fb5002b9d1cf40e8c6e9c7d2871d5c5 Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Wed, 18 Sep 2024 23:02:25 +0200 Subject: [PATCH] UI: Fix missing support for portable configuration files Windows and Linux allow the storage of configuration files relative to the binary location, which is enabled by default on Windows and has to be explicitly enabled on Linux. This was originally conflated with the LINUX_PORTABLE build setting which also allowed the application itself to be run from non-default locations on a Linux system. This change reintroduces the functionality behind the ENABLE_PORTABLE_CONFIG build setting on Linux. It also adds necessary code to make this setting compatible with the recently introduced relocatable settings code changes: When portable mode is enabled, user configuration, scene collections, and profiles are stored in the config directory created for portable mode. --- UI/cmake/os-linux.cmake | 5 ++++- UI/obs-app.cpp | 26 +++++++++++++++++++------- cmake/linux/defaults.cmake | 1 + 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/UI/cmake/os-linux.cmake b/UI/cmake/os-linux.cmake index c37e977428e116..d4b7454518a163 100644 --- a/UI/cmake/os-linux.cmake +++ b/UI/cmake/os-linux.cmake @@ -1,5 +1,8 @@ target_sources(obs-studio PRIVATE platform-x11.cpp) -target_compile_definitions(obs-studio PRIVATE USE_XDG OBS_INSTALL_PREFIX="${OBS_INSTALL_PREFIX}") +target_compile_definitions( + obs-studio + PRIVATE USE_XDG OBS_INSTALL_PREFIX="${OBS_INSTALL_PREFIX}" $<$:ENABLE_PORTABLE_CONFIG> +) target_link_libraries(obs-studio PRIVATE Qt::GuiPrivate Qt::DBus) target_sources(obs-studio PRIVATE system-info-posix.cpp) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index 9e1db2967896bc..7166cbf7917c67 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -720,12 +720,24 @@ bool OBSApp::InitGlobalConfig() InitGlobalConfigDefaults(); InitGlobalLocationDefaults(); - userConfigLocation = std::filesystem::u8path( - config_get_string(appConfig, "Locations", "Configuration")); - userScenesLocation = std::filesystem::u8path( - config_get_string(appConfig, "Locations", "SceneCollections")); - userProfilesLocation = std::filesystem::u8path( - config_get_string(appConfig, "Locations", "Profiles")); + if (IsPortableMode()) { + userConfigLocation = std::filesystem::u8path( + config_get_default_string(appConfig, "Locations", + "Configuration")); + userScenesLocation = std::filesystem::u8path( + config_get_default_string(appConfig, "Locations", + "SceneCollections")); + userProfilesLocation = std::filesystem::u8path( + config_get_default_string(appConfig, "Locations", + "Profiles")); + } else { + userConfigLocation = std::filesystem::u8path(config_get_string( + appConfig, "Locations", "Configuration")); + userScenesLocation = std::filesystem::u8path(config_get_string( + appConfig, "Locations", "SceneCollections")); + userProfilesLocation = std::filesystem::u8path( + config_get_string(appConfig, "Locations", "Profiles")); + } bool userConfigResult = InitUserConfig(userConfigLocation, lastVersion); @@ -2434,7 +2446,7 @@ static void load_debug_privilege(void) #define CONFIG_PATH BASE_PATH "/config" -#if defined(LINUX_PORTABLE) || defined(_WIN32) +#if defined(ENABLE_PORTABLE_CONFIG) || defined(_WIN32) #define ALLOW_PORTABLE_MODE 1 #else #define ALLOW_PORTABLE_MODE 0 diff --git a/cmake/linux/defaults.cmake b/cmake/linux/defaults.cmake index a495f019816f19..17c3c890ca4a8b 100644 --- a/cmake/linux/defaults.cmake +++ b/cmake/linux/defaults.cmake @@ -6,6 +6,7 @@ option(ENABLE_PULSEAUDIO "Enable PulseAudio support" ON) option(ENABLE_WAYLAND "Enable building with support for Wayland" ON) option(ENABLE_RELOCATABLE "Enable relocatable build" OFF) +option(ENABLE_PORTABLE_CONFIG "Enable support for portable config file location" OFF) # Set default installation directories include(GNUInstallDirs)