UI: Fix GetUnusedSceneCollectionFile filename creation

GetUnusedSceneCollectionFile tries to create a safe, unused filename for
a new scene collection JSON file based on the user-specified scene
collection name. It would check the length of the safe version of the
user-specified name, but then it doesn't consider that the length may
have changed when GetClosestUnusedFileName was called to alter the
filename to prevent filename collisions by adding an incremented integer
to the end of the filename. This could result in OBS thinking a filename
was safe and available, but the resulting filename could be one that
already exists. OBS could then overwrite a scene collection JSON file
with this new file without any indication that the file previously
existed.

Instead of trying to calculate a length based off of the returned
filename, let's just use the length of the config path since it's a
known string.
This commit is contained in:
Ryan Foster 2020-05-19 07:32:41 -04:00
parent efa9ee0f3d
commit 27a3da2e70

View file

@ -92,7 +92,6 @@ static bool SceneCollectionExists(const char *findName)
static bool GetUnusedSceneCollectionFile(std::string &name, std::string &file)
{
char path[512];
size_t len;
int ret;
if (!GetFileSafeName(name.c_str(), file)) {
@ -107,7 +106,6 @@ static bool GetUnusedSceneCollectionFile(std::string &name, std::string &file)
return false;
}
len = file.size();
file.insert(0, path);
if (!GetClosestUnusedFileName(file, "json")) {
@ -117,7 +115,7 @@ static bool GetUnusedSceneCollectionFile(std::string &name, std::string &file)
}
file.erase(file.size() - 5, 5);
file.erase(0, file.size() - len);
file.erase(0, strlen(path));
return true;
}