Utils: Refactor into dedicated components

This commit is contained in:
tt2468 2021-08-26 19:00:48 -07:00
parent 306844e42d
commit 43a889c1d4
10 changed files with 103 additions and 74 deletions

View File

@ -97,10 +97,10 @@ set(obs-websocket_SOURCES
src/forms/SettingsDialog.cpp src/forms/SettingsDialog.cpp
src/forms/ConnectInfo.cpp src/forms/ConnectInfo.cpp
src/forms/resources.qrc src/forms/resources.qrc
src/utils/Crypto.cpp
src/utils/Json.cpp src/utils/Json.cpp
src/utils/Crypto.cpp
src/utils/Platform.cpp
src/utils/Obs.cpp src/utils/Obs.cpp
src/utils/Platform.cpp
deps/qr/cpp/QrCode.cpp) deps/qr/cpp/QrCode.cpp)
set(obs-websocket_HEADERS set(obs-websocket_HEADERS
@ -117,6 +117,10 @@ set(obs-websocket_HEADERS
src/requesthandler/rpc/RequestStatus.h src/requesthandler/rpc/RequestStatus.h
src/forms/SettingsDialog.h src/forms/SettingsDialog.h
src/forms/ConnectInfo.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 src/utils/Utils.h
deps/qr/cpp/QrCode.hpp) deps/qr/cpp/QrCode.hpp)

View File

@ -1,7 +1,7 @@
#include <QByteArray> #include <QByteArray>
#include <QCryptographicHash> #include <QCryptographicHash>
#include "Utils.h" #include "Crypto.h"
#include "../plugin-macros.generated.h" #include "../plugin-macros.generated.h"
std::string Utils::Crypto::GenerateSalt() std::string Utils::Crypto::GenerateSalt()

13
src/utils/Crypto.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include <string>
#include <QString>
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);
}
}

View File

@ -1,4 +1,4 @@
#include "Utils.h" #include "Json.h"
#include "../plugin-macros.generated.h" #include "../plugin-macros.generated.h"
bool Utils::Json::JsonArrayIsValidObsArray(json j) bool Utils::Json::JsonArrayIsValidObsArray(json j)

14
src/utils/Json.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include <obs.hpp>
#include <nlohmann/json.hpp>
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);
}
}

View File

@ -1,8 +1,9 @@
#include <inttypes.h> #include <inttypes.h>
#include <QString>
#include <obs-frontend-api.h> #include <obs-frontend-api.h>
#include <util/util_uint64.h> #include <util/util_uint64.h>
#include "Utils.h" #include "Obs.h"
#include "../obs-websocket.h" #include "../obs-websocket.h"
#include "../plugin-macros.generated.h" #include "../plugin-macros.generated.h"

47
src/utils/Obs.h Normal file
View File

@ -0,0 +1,47 @@
#pragma once
#include <string>
#include <obs.hpp>
#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<std::string> GetSceneCollectionList();
std::vector<std::string> GetProfileList();
std::vector<obs_hotkey_t *> GetHotkeyList();
std::vector<std::string> GetHotkeyNameList();
std::vector<json> GetSceneList();
std::vector<json> GetSceneItemList(obs_scene_t *scene, bool basic = false);
std::vector<json> GetTransitionList();
std::vector<json> GetInputList(std::string inputKind = "");
std::vector<std::string> 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);
}
}
}

View File

@ -4,7 +4,7 @@
#include <QHostAddress> #include <QHostAddress>
#include <obs-frontend-api.h> #include <obs-frontend-api.h>
#include "Utils.h" #include "Platform.h"
#include "../plugin-macros.generated.h" #include "../plugin-macros.generated.h"
std::string Utils::Platform::GetLocalAddress() std::string Utils::Platform::GetLocalAddress()

14
src/utils/Platform.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include <string>
#include <QString>
#include <QSystemTrayIcon>
namespace Utils {
namespace Platform {
std::string GetLocalAddress();
QString GetCommandLineArgument(QString arg);
bool GetCommandLineFlagSet(QString arg);
void SendTrayNotification(QSystemTrayIcon::MessageIcon icon, QString title, QString body);
}
}

View File

@ -1,70 +1,6 @@
#pragma once #pragma once
#include <string> #include "Crypto.h"
#include <QString> #include "Json.h"
#include <QSystemTrayIcon> #include "Obs.h"
#include <obs.hpp> #include "Platform.h"
#include <nlohmann/json.hpp>
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<std::string> GetSceneCollectionList();
std::vector<std::string> GetProfileList();
std::vector<obs_hotkey_t *> GetHotkeyList();
std::vector<std::string> GetHotkeyNameList();
std::vector<json> GetSceneList();
std::vector<json> GetSceneItemList(obs_scene_t *scene, bool basic = false);
std::vector<json> GetTransitionList();
std::vector<json> GetInputList(std::string inputKind = "");
std::vector<std::string> 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);
}
}
}