Skip to content

Commit

Permalink
UI: Fix missing support for portable configuration files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
PatTheMav committed Sep 18, 2024
1 parent a289581 commit 5ade18d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
5 changes: 4 additions & 1 deletion UI/cmake/os-linux.cmake
Original file line number Diff line number Diff line change
@@ -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}" $<$<BOOL:ENABLE_PORTABLE_CONFIG>:ENABLE_PORTABLE_CONFIG>
)
target_link_libraries(obs-studio PRIVATE Qt::GuiPrivate Qt::DBus)

target_sources(obs-studio PRIVATE system-info-posix.cpp)
Expand Down
26 changes: 19 additions & 7 deletions UI/obs-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmake/linux/defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5ade18d

Please sign in to comment.