mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-16 06:08:12 -05:00
Refactor
* Minor style changes * Move function definitions * Split utility.hpp * Enable include of export-symbol-helper.hpp in tests
This commit is contained in:
committed by
WarmUpTill
parent
dcba7c535d
commit
01cf000cbe
@@ -1,5 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef UNIT_TEST
|
||||
|
||||
#define EXPORT
|
||||
#define ADVSS_EXPORT
|
||||
|
||||
#else
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
@@ -12,3 +19,5 @@
|
||||
#else
|
||||
#define ADVSS_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // UNIT_TEST
|
||||
|
||||
@@ -14,7 +14,9 @@ std::variant<double, std::string> EvalMathExpression(const std::string &expr)
|
||||
static std::random_device rd;
|
||||
static std::mt19937 gen(rd());
|
||||
static std::uniform_real_distribution<double> dis(0.0, 1.0);
|
||||
static auto randomFunc = []() { return dis(gen); };
|
||||
static auto randomFunc = []() {
|
||||
return dis(gen);
|
||||
};
|
||||
|
||||
if (!setupDone) {
|
||||
symbolTable.add_function("random", randomFunc);
|
||||
@@ -42,10 +44,12 @@ std::optional<double> GetDouble(const std::string &str)
|
||||
{
|
||||
char *end = nullptr;
|
||||
double value = std::strtod(str.c_str(), &end);
|
||||
|
||||
if (end != str.c_str() && *end == '\0' && value != HUGE_VAL &&
|
||||
value != -HUGE_VAL) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -53,11 +57,18 @@ std::optional<int> GetInt(const std::string &str)
|
||||
{
|
||||
char *end = nullptr;
|
||||
int value = std::strtol(str.c_str(), &end, 10);
|
||||
|
||||
if (end != str.c_str() && *end == '\0' && value != INT_MAX &&
|
||||
value != INT_MIN) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool DoubleEquals(double left, double right, double epsilon)
|
||||
{
|
||||
return (fabs(left - right) < epsilon);
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -9,8 +9,9 @@ namespace advss {
|
||||
|
||||
std::variant<double, std::string>
|
||||
EvalMathExpression(const std::string &expression);
|
||||
bool IsValidNumber(const std::string &);
|
||||
EXPORT std::optional<double> GetDouble(const std::string &);
|
||||
EXPORT std::optional<int> GetInt(const std::string &);
|
||||
bool IsValidNumber(const std::string &str);
|
||||
EXPORT std::optional<double> GetDouble(const std::string &str);
|
||||
EXPORT std::optional<int> GetInt(const std::string &str);
|
||||
EXPORT bool DoubleEquals(double left, double right, double epsilon);
|
||||
|
||||
} // namespace advss
|
||||
|
||||
50
lib/utils/path-helpers.cpp
Normal file
50
lib/utils/path-helpers.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "path-helpers.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "obs.hpp"
|
||||
|
||||
#include <obs-frontend-api.h>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::string GetDataFilePath(const std::string &file)
|
||||
{
|
||||
std::string root_path = obs_get_module_data_path(obs_current_module());
|
||||
if (!root_path.empty()) {
|
||||
return root_path + "/" + file;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
QString GetDefaultSettingsSaveLocation()
|
||||
{
|
||||
QString desktopPath = QStandardPaths::writableLocation(
|
||||
QStandardPaths::DesktopLocation);
|
||||
|
||||
auto scName = obs_frontend_get_current_scene_collection();
|
||||
QString sceneCollectionName(scName);
|
||||
bfree(scName);
|
||||
|
||||
auto timestamp = QDateTime::currentDateTime();
|
||||
auto path = desktopPath + "/adv-ss-" + sceneCollectionName + "-" +
|
||||
timestamp.toString("yyyy.MM.dd.hh.mm.ss");
|
||||
|
||||
// Check if scene collection name contains invalid path characters
|
||||
QFile file(path);
|
||||
if (file.exists()) {
|
||||
return path;
|
||||
}
|
||||
|
||||
bool validPath = file.open(QIODevice::WriteOnly);
|
||||
if (validPath) {
|
||||
file.remove();
|
||||
return path;
|
||||
}
|
||||
|
||||
return desktopPath + "/adv-ss-" +
|
||||
timestamp.toString("yyyy.MM.dd.hh.mm.ss");
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
12
lib/utils/path-helpers.hpp
Normal file
12
lib/utils/path-helpers.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "export-symbol-helper.hpp"
|
||||
|
||||
#include <QString>
|
||||
#include <string>
|
||||
|
||||
namespace advss {
|
||||
|
||||
EXPORT std::string GetDataFilePath(const std::string &file);
|
||||
QString GetDefaultSettingsSaveLocation();
|
||||
|
||||
} // namespace advss
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "regex-config.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "path-helpers.hpp"
|
||||
#include "ui-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QLayout>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "status-control.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "path-helpers.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "ui-helpers.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
#include "utility.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "obs.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <obs-frontend-api.h>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
#include <sstream>
|
||||
|
||||
namespace advss {
|
||||
@@ -17,11 +11,6 @@ std::pair<int, int> GetCursorPos()
|
||||
return {cursorPos.x(), cursorPos.y()};
|
||||
}
|
||||
|
||||
bool DoubleEquals(double left, double right, double epsilon)
|
||||
{
|
||||
return (fabs(left - right) < epsilon);
|
||||
}
|
||||
|
||||
bool ReplaceAll(std::string &str, const std::string &from,
|
||||
const std::string &to)
|
||||
{
|
||||
@@ -85,51 +74,11 @@ std::string ToString(double value)
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string GetDataFilePath(const std::string &file)
|
||||
{
|
||||
std::string root_path = obs_get_module_data_path(obs_current_module());
|
||||
if (!root_path.empty()) {
|
||||
return root_path + "/" + file;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
QString GetDefaultSettingsSaveLocation()
|
||||
{
|
||||
QString desktopPath = QStandardPaths::writableLocation(
|
||||
QStandardPaths::DesktopLocation);
|
||||
|
||||
auto scName = obs_frontend_get_current_scene_collection();
|
||||
QString sceneCollectionName(scName);
|
||||
bfree(scName);
|
||||
|
||||
auto timestamp = QDateTime::currentDateTime();
|
||||
auto path = desktopPath + "/adv-ss-" + sceneCollectionName + "-" +
|
||||
timestamp.toString("yyyy.MM.dd.hh.mm.ss");
|
||||
|
||||
// Check if scene collection name contains invalid path characters
|
||||
QFile file(path);
|
||||
if (file.exists()) {
|
||||
return path;
|
||||
}
|
||||
|
||||
bool validPath = file.open(QIODevice::WriteOnly);
|
||||
if (validPath) {
|
||||
file.remove();
|
||||
return path;
|
||||
}
|
||||
|
||||
return desktopPath + "/adv-ss-" +
|
||||
timestamp.toString("yyyy.MM.dd.hh.mm.ss");
|
||||
}
|
||||
|
||||
void listAddClicked(QListWidget *list, QWidget *newWidget,
|
||||
QPushButton *addButton,
|
||||
QMetaObject::Connection *addHighlight)
|
||||
{
|
||||
if (!list || !newWidget) {
|
||||
blog(LOG_WARNING,
|
||||
"listAddClicked called without valid list or widget");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <QMetaObject>
|
||||
#include <QPushButton>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QWidget>
|
||||
#include <string>
|
||||
|
||||
@@ -14,8 +13,6 @@ namespace advss {
|
||||
|
||||
EXPORT std::pair<int, int> GetCursorPos();
|
||||
|
||||
EXPORT bool DoubleEquals(double left, double right, double epsilon);
|
||||
|
||||
bool ReplaceAll(std::string &str, const std::string &from,
|
||||
const std::string &to);
|
||||
EXPORT std::optional<std::string> GetJsonField(const std::string &json,
|
||||
@@ -23,9 +20,6 @@ EXPORT std::optional<std::string> GetJsonField(const std::string &json,
|
||||
EXPORT bool CompareIgnoringLineEnding(QString &s1, QString &s2);
|
||||
std::string ToString(double value);
|
||||
|
||||
EXPORT std::string GetDataFilePath(const std::string &file);
|
||||
QString GetDefaultSettingsSaveLocation();
|
||||
|
||||
/* Legacy helpers */
|
||||
|
||||
void listAddClicked(QListWidget *list, QWidget *newWidget,
|
||||
|
||||
Reference in New Issue
Block a user