Bläddra i källkod

UI: Use filename stem as fallback value on empty collection name

If - for some reason - the name in a scene collection is empty (or
the key doesn't even exist), use the filename stem as a fallback name.

This ensures that the scene collection entry in the cache has a valid
non-empty name.

Using an std::string allows the use of its "empty" method to check for
this otherwise invalid state of the collection data.

Ported from 1baa4619e4ba2c8c59b275b009a7cdadb1ab6724.

Co-authored-by: PatTheMav <[email protected]>
Ryan Foster 9 månader sedan
förälder
incheckning
07be61a2e3
1 ändrade filer med 4 tillägg och 4 borttagningar
  1. 4 4
      UI/window-basic-main-scene-collections.cpp

+ 4 - 4
UI/window-basic-main-scene-collections.cpp

@@ -388,12 +388,12 @@ void OBSBasic::RefreshSceneCollectionCache()
 			obs_data_create_from_json_file_safe(entry.path().u8string().c_str(), "bak");
 			obs_data_create_from_json_file_safe(entry.path().u8string().c_str(), "bak");
 
 
 		std::string candidateName;
 		std::string candidateName;
-		const char *collectionName = obs_data_get_string(collectionData, "name");
+		std::string collectionName = obs_data_get_string(collectionData, "name");
 
 
-		if (!collectionName) {
-			candidateName = entry.path().filename().u8string();
+		if (collectionName.empty()) {
+			candidateName = entry.path().stem().u8string();
 		} else {
 		} else {
-			candidateName = collectionName;
+			candidateName = std::move(collectionName);
 		}
 		}
 
 
 		foundCollections.try_emplace(candidateName,
 		foundCollections.try_emplace(candidateName,