UI: Make GetUnusedSceneCollectionFile usable elsewhere

This commit is contained in:
Ryan Foster 2020-12-17 01:27:15 -05:00 committed by Jim
parent 535f6b0adc
commit 9b1d1c1b3d
3 changed files with 31 additions and 30 deletions

View file

@ -2293,6 +2293,36 @@ bool GetClosestUnusedFileName(std::string &path, const char *extension)
return true;
}
bool GetUnusedSceneCollectionFile(std::string &name, std::string &file)
{
char path[512];
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;
}
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, strlen(path));
return true;
}
bool WindowPositionValid(QRect rect)
{
for (QScreen *screen : QGuiApplication::screens()) {

View file

@ -213,6 +213,7 @@ inline const char *Str(const char *lookup)
bool GetFileSafeName(const char *name, std::string &file);
bool GetClosestUnusedFileName(std::string &path, const char *extension);
bool GetUnusedSceneCollectionFile(std::string &name, std::string &file);
bool WindowPositionValid(QRect rect);

View file

@ -89,36 +89,6 @@ static bool SceneCollectionExists(const char *findName)
return found;
}
static bool GetUnusedSceneCollectionFile(std::string &name, std::string &file)
{
char path[512];
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;
}
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, strlen(path));
return true;
}
static bool GetSceneCollectionName(QWidget *parent, std::string &name,
std::string &file,
const char *oldName = nullptr)