UI: Fix bug in untested/unused function code path

In the current user interface code, OBSBasic::AddSceneCollection has a
qname parameter to allow explicitly specifying a name, but that code
path is unused in the UI code itself, and qname is typically empty.  If
qname is not empty, it does not properly generate a file name associated
with that specified scene collection name.  This fixes that issue.
This commit is contained in:
jp9000 2019-12-04 15:47:16 -08:00
parent 5a406201a6
commit cfddf1112b

View file

@ -88,6 +88,38 @@ static bool SceneCollectionExists(const char *findName)
return found;
}
static bool GetUnusedSceneCollectionFile(std::string &name, std::string &file)
{
char path[512];
size_t len;
int ret;
if (!GetFileSafeName(name.c_str(), file)) {
blog(LOG_WARNING, "Failed to create safe file name for '%s'",
name.c_str());
return false;
}
ret = GetConfigPath(path, sizeof(path), "obs-studio/basic/scenes/");
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get scene collection config path");
return false;
}
len = file.size();
file.insert(0, path);
if (!GetClosestUnusedFileName(file, "json")) {
blog(LOG_WARNING, "Failed to get closest file name for %s",
file.c_str());
return false;
}
file.erase(file.size() - 5, 5);
file.erase(0, file.size() - len);
return true;
}
static bool GetSceneCollectionName(QWidget *parent, std::string &name,
std::string &file,
const char *oldName = nullptr)
@ -95,9 +127,6 @@ static bool GetSceneCollectionName(QWidget *parent, std::string &name,
bool rename = oldName != nullptr;
const char *title;
const char *text;
char path[512];
size_t len;
int ret;
if (rename) {
title = Str("Basic.Main.RenameSceneCollection.Title");
@ -128,29 +157,10 @@ static bool GetSceneCollectionName(QWidget *parent, std::string &name,
break;
}
if (!GetFileSafeName(name.c_str(), file)) {
blog(LOG_WARNING, "Failed to create safe file name for '%s'",
name.c_str());
if (!GetUnusedSceneCollectionFile(name, file)) {
return false;
}
ret = GetConfigPath(path, sizeof(path), "obs-studio/basic/scenes/");
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get scene collection config path");
return false;
}
len = file.size();
file.insert(0, path);
if (!GetClosestUnusedFileName(file, "json")) {
blog(LOG_WARNING, "Failed to get closest file name for %s",
file.c_str());
return false;
}
file.erase(file.size() - 5, 5);
file.erase(0, file.size() - len);
return true;
}
@ -166,6 +176,10 @@ bool OBSBasic::AddSceneCollection(bool create_new, const QString &qname)
name = QT_TO_UTF8(qname);
if (SceneCollectionExists(name.c_str()))
return false;
if (!GetUnusedSceneCollectionFile(name, file)) {
return false;
}
}
SaveProjectNow();