diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bfa2ca8..fe499da3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,6 +177,8 @@ target_sources( lib/utils/obs-dock.hpp lib/utils/obs-module-helper.cpp lib/utils/obs-module-helper.hpp + lib/utils/path-helpers.cpp + lib/utils/path-helpers.hpp lib/utils/plugin-state-helpers.cpp lib/utils/plugin-state-helpers.hpp lib/utils/priority-helper.cpp diff --git a/lib/advanced-scene-switcher.cpp b/lib/advanced-scene-switcher.cpp index c91444f0..ac810e08 100644 --- a/lib/advanced-scene-switcher.cpp +++ b/lib/advanced-scene-switcher.cpp @@ -3,6 +3,7 @@ #include "log-helper.hpp" #include "macro-helpers.hpp" #include "obs-module-helper.hpp" +#include "path-helpers.hpp" #include "platform-funcs.hpp" #include "scene-switch-helpers.hpp" #include "source-helpers.hpp" diff --git a/lib/general.cpp b/lib/general.cpp index 0567f7b9..f8d33af0 100644 --- a/lib/general.cpp +++ b/lib/general.cpp @@ -3,6 +3,7 @@ #include "filter-combo-box.hpp" #include "layout-helpers.hpp" #include "macro.hpp" +#include "path-helpers.hpp" #include "selection-helpers.hpp" #include "source-helpers.hpp" #include "splitter-helpers.hpp" diff --git a/lib/macro/macro-action-variable.cpp b/lib/macro/macro-action-variable.cpp index f4a6eeb4..f3594a02 100644 --- a/lib/macro/macro-action-variable.cpp +++ b/lib/macro/macro-action-variable.cpp @@ -68,6 +68,7 @@ static void modifyNumValue(Variable &var, double val, const bool increment) if (!current.has_value()) { return; } + if (increment) { var.SetValue(*current + val); } else { diff --git a/lib/macro/macro-condition-edit.cpp b/lib/macro/macro-condition-edit.cpp index 93aae46f..30541045 100644 --- a/lib/macro/macro-condition-edit.cpp +++ b/lib/macro/macro-condition-edit.cpp @@ -2,6 +2,7 @@ #include "advanced-scene-switcher.hpp" #include "macro-properties.hpp" #include "macro.hpp" +#include "path-helpers.hpp" #include "section.hpp" #include "ui-helpers.hpp" #include "utility.hpp" diff --git a/lib/macro/macro-tab.cpp b/lib/macro/macro-tab.cpp index 44d84147..d4407ebb 100644 --- a/lib/macro/macro-tab.cpp +++ b/lib/macro/macro-tab.cpp @@ -5,7 +5,9 @@ #include "macro-properties.hpp" #include "macro-tree.hpp" #include "macro.hpp" +#include "math-helpers.hpp" #include "name-dialog.hpp" +#include "path-helpers.hpp" #include "switcher-data.hpp" #include "ui-helpers.hpp" #include "utility.hpp" diff --git a/lib/macro/macro-tree.cpp b/lib/macro/macro-tree.cpp index b436d2ad..d579ca45 100644 --- a/lib/macro/macro-tree.cpp +++ b/lib/macro/macro-tree.cpp @@ -1,5 +1,6 @@ #include "macro-tree.hpp" #include "macro.hpp" +#include "path-helpers.hpp" #include "sync-helpers.hpp" #include "ui-helpers.hpp" #include "utility.hpp" @@ -21,7 +22,9 @@ namespace advss { MacroTreeItem::MacroTreeItem(MacroTree *tree, std::shared_ptr macroItem, bool highlight) - : _tree(tree), _highlight(highlight), _macro(macroItem) + : _tree(tree), + _highlight(highlight), + _macro(macroItem) { setAttribute(Qt::WA_TranslucentBackground); // This is necessary for some theses to display active selections properly @@ -72,7 +75,9 @@ MacroTreeItem::MacroTreeItem(MacroTree *tree, std::shared_ptr macroItem, Update(true); setLayout(_boxLayout); - auto setRunning = [this](bool val) { _macro->SetPaused(!val); }; + auto setRunning = [this](bool val) { + _macro->SetPaused(!val); + }; connect(_running, &QAbstractButton::clicked, setRunning); connect(_tree->window(), SIGNAL(HighlightMacrosChanged(bool)), this, SLOT(EnableHighlight(bool))); @@ -523,7 +528,9 @@ MacroTreeModel::GetCurrentMacros(const QModelIndexList &selection) const MacroTreeModel::MacroTreeModel(MacroTree *st_, std::deque> ¯os) - : QAbstractListModel(st_), _mt(st_), _macros(macros) + : QAbstractListModel(st_), + _mt(st_), + _macros(macros) { UpdateGroupState(false); } diff --git a/lib/utils/export-symbol-helper.hpp b/lib/utils/export-symbol-helper.hpp index 151614f7..d5f4e2b9 100644 --- a/lib/utils/export-symbol-helper.hpp +++ b/lib/utils/export-symbol-helper.hpp @@ -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 diff --git a/lib/utils/math-helpers.cpp b/lib/utils/math-helpers.cpp index 6da048f4..91adbaf7 100644 --- a/lib/utils/math-helpers.cpp +++ b/lib/utils/math-helpers.cpp @@ -14,7 +14,9 @@ std::variant EvalMathExpression(const std::string &expr) static std::random_device rd; static std::mt19937 gen(rd()); static std::uniform_real_distribution 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 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 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 diff --git a/lib/utils/math-helpers.hpp b/lib/utils/math-helpers.hpp index c2515ea3..608a0a24 100644 --- a/lib/utils/math-helpers.hpp +++ b/lib/utils/math-helpers.hpp @@ -9,8 +9,9 @@ namespace advss { std::variant EvalMathExpression(const std::string &expression); -bool IsValidNumber(const std::string &); -EXPORT std::optional GetDouble(const std::string &); -EXPORT std::optional GetInt(const std::string &); +bool IsValidNumber(const std::string &str); +EXPORT std::optional GetDouble(const std::string &str); +EXPORT std::optional GetInt(const std::string &str); +EXPORT bool DoubleEquals(double left, double right, double epsilon); } // namespace advss diff --git a/lib/utils/path-helpers.cpp b/lib/utils/path-helpers.cpp new file mode 100644 index 00000000..439ff6b2 --- /dev/null +++ b/lib/utils/path-helpers.cpp @@ -0,0 +1,50 @@ +#include "path-helpers.hpp" +#include "obs-module-helper.hpp" +#include "obs.hpp" + +#include +#include +#include +#include + +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 diff --git a/lib/utils/path-helpers.hpp b/lib/utils/path-helpers.hpp new file mode 100644 index 00000000..b572e73a --- /dev/null +++ b/lib/utils/path-helpers.hpp @@ -0,0 +1,12 @@ +#pragma once +#include "export-symbol-helper.hpp" + +#include +#include + +namespace advss { + +EXPORT std::string GetDataFilePath(const std::string &file); +QString GetDefaultSettingsSaveLocation(); + +} // namespace advss diff --git a/lib/utils/regex-config.cpp b/lib/utils/regex-config.cpp index 7f9deed5..8c8a5f0d 100644 --- a/lib/utils/regex-config.cpp +++ b/lib/utils/regex-config.cpp @@ -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 diff --git a/lib/utils/status-control.cpp b/lib/utils/status-control.cpp index bccea431..83817814 100644 --- a/lib/utils/status-control.cpp +++ b/lib/utils/status-control.cpp @@ -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" diff --git a/lib/utils/utility.cpp b/lib/utils/utility.cpp index fd73a7b7..9896723e 100644 --- a/lib/utils/utility.cpp +++ b/lib/utils/utility.cpp @@ -1,12 +1,6 @@ #include "utility.hpp" -#include "obs-module-helper.hpp" -#include "obs.hpp" #include -#include -#include -#include -#include #include namespace advss { @@ -17,11 +11,6 @@ std::pair 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; } diff --git a/lib/utils/utility.hpp b/lib/utils/utility.hpp index aa382d46..2d80bb84 100644 --- a/lib/utils/utility.hpp +++ b/lib/utils/utility.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -14,8 +13,6 @@ namespace advss { EXPORT std::pair 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 GetJsonField(const std::string &json, @@ -23,9 +20,6 @@ EXPORT std::optional 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, diff --git a/lib/variables/variable.cpp b/lib/variables/variable.cpp index 5ff9bc84..3773be6b 100644 --- a/lib/variables/variable.cpp +++ b/lib/variables/variable.cpp @@ -70,17 +70,19 @@ std::optional Variable::IntValue() const return GetInt(Value()); } -void Variable::SetValue(const std::string &val) +void Variable::SetValue(const std::string &value) { - _value = val; - _lastUsed = std::chrono::high_resolution_clock::now(); + _value = value; + + UpdateLastUsed(); lastVariableChange = std::chrono::high_resolution_clock::now(); } void Variable::SetValue(double value) { _value = ToString(value); - _lastUsed = std::chrono::high_resolution_clock::now(); + + UpdateLastUsed(); lastVariableChange = std::chrono::high_resolution_clock::now(); } diff --git a/lib/variables/variable.hpp b/lib/variables/variable.hpp index 37f3cf5a..88cf5fe3 100644 --- a/lib/variables/variable.hpp +++ b/lib/variables/variable.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include namespace advss { @@ -22,8 +22,8 @@ public: EXPORT std::string Value(bool updateLastUsed = true) const; EXPORT std::optional DoubleValue() const; EXPORT std::optional IntValue() const; - void SetValue(const std::string &val); - void SetValue(double); + void SetValue(const std::string &value); + void SetValue(double value); std::string GetDefaultValue() const { return _defaultValue; } static std::shared_ptr Create() { diff --git a/plugins/base/macro-condition-obs-stats.cpp b/plugins/base/macro-condition-obs-stats.cpp index 65dd1846..6e64b206 100644 --- a/plugins/base/macro-condition-obs-stats.cpp +++ b/plugins/base/macro-condition-obs-stats.cpp @@ -1,8 +1,9 @@ #include "macro-condition-obs-stats.hpp" #include "layout-helpers.hpp" -#include "utility.hpp" +#include "math-helpers.hpp" #include +#include namespace advss { diff --git a/plugins/midi/midi-helpers.cpp b/plugins/midi/midi-helpers.cpp index 5c61caf9..126a1bae 100644 --- a/plugins/midi/midi-helpers.cpp +++ b/plugins/midi/midi-helpers.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -564,7 +565,8 @@ static inline QStringList getOutputDeviceNames() } MidiDeviceSelection::MidiDeviceSelection(QWidget *parent, MidiDeviceType t) - : QComboBox(parent), _type(t) + : QComboBox(parent), + _type(t) { AddSelectionEntry(this, obs_module_text("AdvSceneSwitcher.selectItem")); diff --git a/plugins/twitch/category-selection.cpp b/plugins/twitch/category-selection.cpp index 714194ac..b6a195f0 100644 --- a/plugins/twitch/category-selection.cpp +++ b/plugins/twitch/category-selection.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -189,8 +190,9 @@ void CategoryGrabber::Search(const std::string &) int startCount = _categoryMap.size(); std::string cursor; - httplib::Params params = { - {"first", "100"}, {"after", cursor}, {"query", _searchString}}; + httplib::Params params = {{"first", "100"}, + {"after", cursor}, + {"query", _searchString}}; auto response = SendGetRequest(*_token, uri, path, params); while (response.status == 200 && !_stop) { diff --git a/tests/mocks/utility.cpp b/tests/mocks/utility.cpp index e815415e..cf7009e6 100644 --- a/tests/mocks/utility.cpp +++ b/tests/mocks/utility.cpp @@ -9,11 +9,6 @@ std::pair GetCursorPos() return {0, 0}; } -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) {