From 43a889c1d47ad9d121c76a2b45287738ba614517 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Thu, 26 Aug 2021 19:00:48 -0700 Subject: [PATCH] Utils: Refactor into dedicated components --- CMakeLists.txt | 8 +++-- src/utils/Crypto.cpp | 2 +- src/utils/Crypto.h | 13 ++++++++ src/utils/Json.cpp | 2 +- src/utils/Json.h | 14 ++++++++ src/utils/Obs.cpp | 3 +- src/utils/Obs.h | 47 +++++++++++++++++++++++++++ src/utils/Platform.cpp | 2 +- src/utils/Platform.h | 14 ++++++++ src/utils/Utils.h | 72 +++--------------------------------------- 10 files changed, 103 insertions(+), 74 deletions(-) create mode 100644 src/utils/Crypto.h create mode 100644 src/utils/Json.h create mode 100644 src/utils/Obs.h create mode 100644 src/utils/Platform.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d023baa6..0fc4a01e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,10 +97,10 @@ set(obs-websocket_SOURCES src/forms/SettingsDialog.cpp src/forms/ConnectInfo.cpp src/forms/resources.qrc + src/utils/Crypto.cpp src/utils/Json.cpp - src/utils/Crypto.cpp - src/utils/Platform.cpp src/utils/Obs.cpp + src/utils/Platform.cpp deps/qr/cpp/QrCode.cpp) set(obs-websocket_HEADERS @@ -117,6 +117,10 @@ set(obs-websocket_HEADERS src/requesthandler/rpc/RequestStatus.h src/forms/SettingsDialog.h src/forms/ConnectInfo.h + src/utils/Crypto.h + src/utils/Json.h + src/utils/Obs.h + src/utils/Platform.h src/utils/Utils.h deps/qr/cpp/QrCode.hpp) diff --git a/src/utils/Crypto.cpp b/src/utils/Crypto.cpp index adeaa6dd..284d98a0 100644 --- a/src/utils/Crypto.cpp +++ b/src/utils/Crypto.cpp @@ -1,7 +1,7 @@ #include #include -#include "Utils.h" +#include "Crypto.h" #include "../plugin-macros.generated.h" std::string Utils::Crypto::GenerateSalt() diff --git a/src/utils/Crypto.h b/src/utils/Crypto.h new file mode 100644 index 00000000..a3d89a93 --- /dev/null +++ b/src/utils/Crypto.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +namespace Utils { + namespace Crypto { + std::string GenerateSalt(); + std::string GenerateSecret(std::string password, std::string salt); + bool CheckAuthenticationString(std::string secret, std::string challenge, std::string authenticationString); + QString GeneratePassword(size_t length = 16); + } +} diff --git a/src/utils/Json.cpp b/src/utils/Json.cpp index 8692fb70..bf65b3e4 100644 --- a/src/utils/Json.cpp +++ b/src/utils/Json.cpp @@ -1,4 +1,4 @@ -#include "Utils.h" +#include "Json.h" #include "../plugin-macros.generated.h" bool Utils::Json::JsonArrayIsValidObsArray(json j) diff --git a/src/utils/Json.h b/src/utils/Json.h new file mode 100644 index 00000000..b9ccbd3b --- /dev/null +++ b/src/utils/Json.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +using json = nlohmann::json; + +namespace Utils { + namespace Json { + bool JsonArrayIsValidObsArray(json j); + obs_data_t *JsonToObsData(json j); + json ObsDataToJson(obs_data_t *d, bool includeDefault = false); + } +} \ No newline at end of file diff --git a/src/utils/Obs.cpp b/src/utils/Obs.cpp index 63fc5da9..85b6a807 100644 --- a/src/utils/Obs.cpp +++ b/src/utils/Obs.cpp @@ -1,8 +1,9 @@ #include +#include #include #include -#include "Utils.h" +#include "Obs.h" #include "../obs-websocket.h" #include "../plugin-macros.generated.h" diff --git a/src/utils/Obs.h b/src/utils/Obs.h new file mode 100644 index 00000000..4a30eabc --- /dev/null +++ b/src/utils/Obs.h @@ -0,0 +1,47 @@ +#pragma once + +#include +#include + +#include "Json.h" + +namespace Utils { + namespace Obs { + namespace StringHelper { + std::string GetObsVersionString(); + std::string GetCurrentSceneCollection(); + std::string GetCurrentProfile(); + std::string GetCurrentProfilePath(); + std::string GetSourceTypeString(obs_source_t *source); + std::string GetInputMonitorTypeString(obs_source_t *input); + std::string GetMediaInputStateString(obs_source_t *input); + std::string GetLastReplayBufferFilePath(); + std::string GetOutputTimecodeString(obs_output_t *output); + } + + namespace NumberHelper { + uint64_t GetOutputDuration(obs_output_t *output); + } + + namespace ListHelper { + std::vector GetSceneCollectionList(); + std::vector GetProfileList(); + std::vector GetHotkeyList(); + std::vector GetHotkeyNameList(); + std::vector GetSceneList(); + std::vector GetSceneItemList(obs_scene_t *scene, bool basic = false); + std::vector GetTransitionList(); + std::vector GetInputList(std::string inputKind = ""); + std::vector GetInputKindList(bool unversioned = false, bool includeDisabled = false); + } + + namespace SearchHelper { + obs_hotkey_t *GetHotkeyByName(std::string name); + } + + namespace ActionHelper { + obs_sceneitem_t *CreateSceneItem(obs_source_t *input, obs_scene_t *scene, bool sceneItemEnabled = true); + obs_sceneitem_t *CreateInput(std::string inputName, std::string inputKind, obs_data_t *inputSettings, obs_scene_t *scene, bool sceneItemEnabled = true); + } + } +} \ No newline at end of file diff --git a/src/utils/Platform.cpp b/src/utils/Platform.cpp index a1d27018..e4f0b300 100644 --- a/src/utils/Platform.cpp +++ b/src/utils/Platform.cpp @@ -4,7 +4,7 @@ #include #include -#include "Utils.h" +#include "Platform.h" #include "../plugin-macros.generated.h" std::string Utils::Platform::GetLocalAddress() diff --git a/src/utils/Platform.h b/src/utils/Platform.h new file mode 100644 index 00000000..c1a58f82 --- /dev/null +++ b/src/utils/Platform.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include + +namespace Utils { + namespace Platform { + std::string GetLocalAddress(); + QString GetCommandLineArgument(QString arg); + bool GetCommandLineFlagSet(QString arg); + void SendTrayNotification(QSystemTrayIcon::MessageIcon icon, QString title, QString body); + } +} \ No newline at end of file diff --git a/src/utils/Utils.h b/src/utils/Utils.h index 3790e50e..4948362c 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -1,70 +1,6 @@ #pragma once -#include -#include -#include -#include -#include - -using json = nlohmann::json; - -namespace Utils { - namespace Json { - bool JsonArrayIsValidObsArray(json j); - obs_data_t *JsonToObsData(json j); - json ObsDataToJson(obs_data_t *d, bool includeDefault = false); - } - - namespace Crypto { - std::string GenerateSalt(); - std::string GenerateSecret(std::string password, std::string salt); - bool CheckAuthenticationString(std::string secret, std::string challenge, std::string authenticationString); - QString GeneratePassword(size_t length = 16); - } - - namespace Platform { - std::string GetLocalAddress(); - QString GetCommandLineArgument(QString arg); - bool GetCommandLineFlagSet(QString arg); - void SendTrayNotification(QSystemTrayIcon::MessageIcon icon, QString title, QString body); - } - - namespace Obs { - namespace StringHelper { - std::string GetObsVersionString(); - std::string GetCurrentSceneCollection(); - std::string GetCurrentProfile(); - std::string GetCurrentProfilePath(); - std::string GetSourceTypeString(obs_source_t *source); - std::string GetInputMonitorTypeString(obs_source_t *input); - std::string GetMediaInputStateString(obs_source_t *input); - std::string GetLastReplayBufferFilePath(); - std::string GetOutputTimecodeString(obs_output_t *output); - } - - namespace NumberHelper { - uint64_t GetOutputDuration(obs_output_t *output); - } - - namespace ListHelper { - std::vector GetSceneCollectionList(); - std::vector GetProfileList(); - std::vector GetHotkeyList(); - std::vector GetHotkeyNameList(); - std::vector GetSceneList(); - std::vector GetSceneItemList(obs_scene_t *scene, bool basic = false); - std::vector GetTransitionList(); - std::vector GetInputList(std::string inputKind = ""); - std::vector GetInputKindList(bool unversioned = false, bool includeDisabled = false); - } - - namespace SearchHelper { - obs_hotkey_t *GetHotkeyByName(std::string name); - } - - namespace ActionHelper { - obs_sceneitem_t *CreateSceneItem(obs_source_t *input, obs_scene_t *scene, bool sceneItemEnabled = true); - obs_sceneitem_t *CreateInput(std::string inputName, std::string inputKind, obs_data_t *inputSettings, obs_scene_t *scene, bool sceneItemEnabled = true); - } - } -} +#include "Crypto.h" +#include "Json.h" +#include "Obs.h" +#include "Platform.h"