UI: Refactor importer to use GetUnusedSceneCollectionFile
parent
9b1d1c1b3d
commit
461a0c5484
|
@ -517,19 +517,6 @@ void OBSImporter::dragEnterEvent(QDragEnterEvent *ev)
|
||||||
ev->accept();
|
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()
|
void OBSImporter::browseImport()
|
||||||
{
|
{
|
||||||
QString Pattern = "(*.json *.bpres *.xml *.xconfig)";
|
QString Pattern = "(*.json *.bpres *.xml *.xconfig)";
|
||||||
|
@ -560,42 +547,30 @@ void OBSImporter::importCollections()
|
||||||
if (selected == Qt::Unchecked)
|
if (selected == Qt::Unchecked)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QString path = optionsModel->index(i, ImporterColumn::Path)
|
std::string pathStr =
|
||||||
.data(Qt::DisplayRole)
|
optionsModel->index(i, ImporterColumn::Path)
|
||||||
.value<QString>();
|
.data(Qt::DisplayRole)
|
||||||
QString name = optionsModel->index(i, ImporterColumn::Name)
|
.value<QString>()
|
||||||
.data(Qt::DisplayRole)
|
.toStdString();
|
||||||
.value<QString>();
|
std::string nameStr =
|
||||||
|
optionsModel->index(i, ImporterColumn::Name)
|
||||||
std::string pathStr = path.toStdString();
|
.data(Qt::DisplayRole)
|
||||||
std::string nameStr = name.toStdString();
|
.value<QString>()
|
||||||
|
.toStdString();
|
||||||
|
|
||||||
json11::Json res;
|
json11::Json res;
|
||||||
ImportSC(pathStr, nameStr, res);
|
ImportSC(pathStr, nameStr, res);
|
||||||
|
|
||||||
if (res != json11::Json()) {
|
if (res != json11::Json()) {
|
||||||
json11::Json::object out = res.object_items();
|
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(" ", "_");
|
GetUnusedSceneCollectionFile(name, file);
|
||||||
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();
|
|
||||||
|
|
||||||
std::string save = dst;
|
std::string save = dst;
|
||||||
save += "/";
|
save += "/";
|
||||||
save += file.toStdString();
|
save += file;
|
||||||
save += ".json";
|
save += ".json";
|
||||||
|
|
||||||
std::string out_str = json11::Json(out).dump();
|
std::string out_str = json11::Json(out).dump();
|
||||||
|
@ -606,8 +581,7 @@ void OBSImporter::importCollections()
|
||||||
false);
|
false);
|
||||||
|
|
||||||
blog(LOG_INFO, "Import Scene Collection: %s (%s) - %s",
|
blog(LOG_INFO, "Import Scene Collection: %s (%s) - %s",
|
||||||
name.toStdString().c_str(),
|
name.c_str(), file.c_str(),
|
||||||
file.toStdString().c_str(),
|
|
||||||
success ? "SUCCESS" : "FAILURE");
|
success ? "SUCCESS" : "FAILURE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue