浏览代码

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.
PatTheMav 6 月之前
父节点
当前提交
8bfc28f851
共有 1 个文件被更改,包括 25 次插入10 次删除
  1. 25 10
      frontend/OBSApp.cpp

+ 25 - 10
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);