diff --git a/UI/window-basic-main-scene-collections.cpp b/UI/window-basic-main-scene-collections.cpp index fb0cdf522..551cb969e 100644 --- a/UI/window-basic-main-scene-collections.cpp +++ b/UI/window-basic-main-scene-collections.cpp @@ -73,7 +73,7 @@ void EnumSceneCollections(std::function &&cb) os_globfree(glob); } -static bool SceneCollectionExists(const char *findName) +bool SceneCollectionExists(const char *findName) { bool found = false; auto func = [&](const char *name, const char *) { diff --git a/UI/window-importer.cpp b/UI/window-importer.cpp index 27b8c5477..18e683248 100644 --- a/UI/window-importer.cpp +++ b/UI/window-importer.cpp @@ -30,6 +30,8 @@ #include "qt-wrappers.hpp" #include "importers/importers.hpp" +extern bool SceneCollectionExists(const char *findName); + enum ImporterColumn { Selected, Name, @@ -532,6 +534,23 @@ void OBSImporter::browseImport() } } +bool GetUnusedName(std::string &name) +{ + if (!SceneCollectionExists(name.c_str())) + return false; + + std::string newName; + int inc = 2; + do { + newName = name; + newName += " "; + newName += std::to_string(inc++); + } while (SceneCollectionExists(newName.c_str())); + + name = newName; + return true; +} + void OBSImporter::importCollections() { setEnabled(false); @@ -566,6 +585,12 @@ void OBSImporter::importCollections() std::string name = res["name"].string_value(); std::string file; + if (GetUnusedName(name)) { + json11::Json::object newOut = out; + newOut["name"] = name; + out = newOut; + } + GetUnusedSceneCollectionFile(name, file); std::string save = dst;