From cfddf1112b04455b0ccd7070b9ee1e32aaaa2ac0 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 4 Dec 2019 15:47:16 -0800 Subject: [PATCH] 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. --- UI/window-basic-main-scene-collections.cpp | 60 +++++++++++++--------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/UI/window-basic-main-scene-collections.cpp b/UI/window-basic-main-scene-collections.cpp index cceef021a..e0ea3d125 100644 --- a/UI/window-basic-main-scene-collections.cpp +++ b/UI/window-basic-main-scene-collections.cpp @@ -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()); - 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()); + if (!GetUnusedSceneCollectionFile(name, file)) { 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(); -- GitLab