From 8bfc28f8513475057786df66bbaf0bcd965de2d9 Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Tue, 8 Apr 2025 19:19:40 +0200 Subject: [PATCH] frontend: Use default location for user settings as fallback When a unique path is set up as the location for user settings, profiles, or scene collections, migrating the files from one computer to another will lead to confusing error messages as the original paths might not exist on the new machine. The default directories for configuration files are already created by this point, so using those paths as a fallback should enable OBS Studio to also create the corresponding fallback settings files. --- frontend/OBSApp.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/frontend/OBSApp.cpp b/frontend/OBSApp.cpp index d67a258bf..3da732715 100644 --- a/frontend/OBSApp.cpp +++ b/frontend/OBSApp.cpp @@ -434,7 +434,7 @@ bool OBSApp::InitGlobalConfig() uint32_t lastVersion = config_get_int(appConfig, "General", "LastVersion"); - if (lastVersion < MAKE_SEMANTIC_VERSION(31, 0, 0)) { + if (lastVersion && lastVersion < MAKE_SEMANTIC_VERSION(31, 0, 0)) { bool migratedUserSettings = config_get_bool(appConfig, "General", "Pre31Migrated"); if (!migratedUserSettings) { @@ -448,19 +448,34 @@ bool OBSApp::InitGlobalConfig() InitGlobalConfigDefaults(); InitGlobalLocationDefaults(); + std::filesystem::path defaultUserConfigLocation = + std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "Configuration")); + std::filesystem::path defaultUserScenesLocation = + std::filesystem::u8path(config_get_default_string(appConfig, "Locations", "SceneCollections")); + std::filesystem::path defaultUserProfilesLocation = + std::filesystem::u8path(config_get_default_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")); + userConfigLocation = std::move(defaultUserConfigLocation); + userScenesLocation = std::move(defaultUserScenesLocation); + userProfilesLocation = std::move(defaultUserProfilesLocation); } else { - userConfigLocation = + std::filesystem::path currentUserConfigLocation = std::filesystem::u8path(config_get_string(appConfig, "Locations", "Configuration")); - userScenesLocation = + std::filesystem::path currentUserScenesLocation = std::filesystem::u8path(config_get_string(appConfig, "Locations", "SceneCollections")); - userProfilesLocation = std::filesystem::u8path(config_get_string(appConfig, "Locations", "Profiles")); + std::filesystem::path currentUserProfilesLocation = + std::filesystem::u8path(config_get_string(appConfig, "Locations", "Profiles")); + + userConfigLocation = (std::filesystem::exists(currentUserConfigLocation)) + ? std::move(currentUserConfigLocation) + : std::move(defaultUserConfigLocation); + userScenesLocation = (std::filesystem::exists(currentUserScenesLocation)) + ? std::move(currentUserScenesLocation) + : std::move(defaultUserScenesLocation); + userProfilesLocation = (std::filesystem::exists(currentUserProfilesLocation)) + ? std::move(currentUserProfilesLocation) + : std::move(defaultUserProfilesLocation); } bool userConfigResult = InitUserConfig(userConfigLocation, lastVersion);