From 461a0c5484a61a0029ba46dc91dcf9f36aae23a7 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Thu, 17 Dec 2020 01:28:17 -0500 Subject: [PATCH] UI: Refactor importer to use GetUnusedSceneCollectionFile --- UI/window-importer.cpp | 56 +++++++++++------------------------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/UI/window-importer.cpp b/UI/window-importer.cpp index f8626c2d9..d0c5e3dd3 100644 --- a/UI/window-importer.cpp +++ b/UI/window-importer.cpp @@ -517,19 +517,6 @@ void OBSImporter::dragEnterEvent(QDragEnterEvent *ev) ev->accept(); } -static bool CheckConfigExists(const char *dir, QString name) -{ - - QString dst = dir; - dst += "/"; - dst += name; - dst += ".json"; - - dst.replace(" ", "_"); - - return os_file_exists(dst.toStdString().c_str()); -} - void OBSImporter::browseImport() { QString Pattern = "(*.json *.bpres *.xml *.xconfig)"; @@ -560,42 +547,30 @@ void OBSImporter::importCollections() if (selected == Qt::Unchecked) continue; - QString path = optionsModel->index(i, ImporterColumn::Path) - .data(Qt::DisplayRole) - .value(); - QString name = optionsModel->index(i, ImporterColumn::Name) - .data(Qt::DisplayRole) - .value(); - - std::string pathStr = path.toStdString(); - std::string nameStr = name.toStdString(); + std::string pathStr = + optionsModel->index(i, ImporterColumn::Path) + .data(Qt::DisplayRole) + .value() + .toStdString(); + std::string nameStr = + optionsModel->index(i, ImporterColumn::Name) + .data(Qt::DisplayRole) + .value() + .toStdString(); json11::Json res; ImportSC(pathStr, nameStr, res); if (res != json11::Json()) { json11::Json::object out = res.object_items(); - QString file = res["name"].string_value().c_str(); + std::string name = res["name"].string_value(); + std::string file; - file.replace(" ", "_"); - file.replace("/", "_"); - bool safe = !CheckConfigExists(dst, file); - int x = 1; - while (!safe) { - file = name; - file += "_("; - file += QString::number(x); - file += ")"; - - safe = !CheckConfigExists(dst, file); - x++; - } - - out["name"] = file.toStdString(); + GetUnusedSceneCollectionFile(name, file); std::string save = dst; save += "/"; - save += file.toStdString(); + save += file; save += ".json"; std::string out_str = json11::Json(out).dump(); @@ -606,8 +581,7 @@ void OBSImporter::importCollections() false); blog(LOG_INFO, "Import Scene Collection: %s (%s) - %s", - name.toStdString().c_str(), - file.toStdString().c_str(), + name.c_str(), file.c_str(), success ? "SUCCESS" : "FAILURE"); } }