mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-15 07:44:10 +00:00
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:
parent
5a406201a6
commit
cfddf1112b
|
@ -88,6 +88,38 @@ static bool SceneCollectionExists(const char *findName)
|
||||||
return found;
|
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,
|
static bool GetSceneCollectionName(QWidget *parent, std::string &name,
|
||||||
std::string &file,
|
std::string &file,
|
||||||
const char *oldName = nullptr)
|
const char *oldName = nullptr)
|
||||||
|
@ -95,9 +127,6 @@ static bool GetSceneCollectionName(QWidget *parent, std::string &name,
|
||||||
bool rename = oldName != nullptr;
|
bool rename = oldName != nullptr;
|
||||||
const char *title;
|
const char *title;
|
||||||
const char *text;
|
const char *text;
|
||||||
char path[512];
|
|
||||||
size_t len;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (rename) {
|
if (rename) {
|
||||||
title = Str("Basic.Main.RenameSceneCollection.Title");
|
title = Str("Basic.Main.RenameSceneCollection.Title");
|
||||||
|
@ -128,29 +157,10 @@ static bool GetSceneCollectionName(QWidget *parent, std::string &name,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetFileSafeName(name.c_str(), file)) {
|
if (!GetUnusedSceneCollectionFile(name, file)) {
|
||||||
blog(LOG_WARNING, "Failed to create safe file name for '%s'",
|
|
||||||
name.c_str());
|
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +176,10 @@ bool OBSBasic::AddSceneCollection(bool create_new, const QString &qname)
|
||||||
name = QT_TO_UTF8(qname);
|
name = QT_TO_UTF8(qname);
|
||||||
if (SceneCollectionExists(name.c_str()))
|
if (SceneCollectionExists(name.c_str()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!GetUnusedSceneCollectionFile(name, file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveProjectNow();
|
SaveProjectNow();
|
||||||
|
|
Loading…
Reference in a new issue