From 7fe0c2aac0cdd8236fe218efa457d29b497e3c75 Mon Sep 17 00:00:00 2001 From: Kirollos Date: Sat, 16 Nov 2024 23:26:06 +0200 Subject: [PATCH] refactor: FillStruct() implemented to tidy up code readability --- DiscordEuroscope/ConfigData.cpp | 7 +++++++ DiscordEuroscope/ConfigData.h | 5 ++++- DiscordEuroscope/ConfigManager.cpp | 1 + DiscordEuroscope/ConfigManager.h | 1 - DiscordEuroscope/DiscordEuroscopeExt.cpp | 16 ++++++++-------- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/DiscordEuroscope/ConfigData.cpp b/DiscordEuroscope/ConfigData.cpp index 64bd9be..851554c 100644 --- a/DiscordEuroscope/ConfigData.cpp +++ b/DiscordEuroscope/ConfigData.cpp @@ -16,6 +16,7 @@ */ #include "stdafx.h" +#include "inc/discord_rpc.h" #include "ConfigData.h" namespace DiscordEuroScope_Configuration @@ -47,4 +48,10 @@ namespace DiscordEuroScope_Configuration this->states[i].used = false; } } + + void Button::FillStruct(DiscordButton* refButton) const + { + refButton->label = label.c_str(); + refButton->url = url.c_str(); + } } \ No newline at end of file diff --git a/DiscordEuroscope/ConfigData.h b/DiscordEuroscope/ConfigData.h index 0afc35b..615ab6e 100644 --- a/DiscordEuroscope/ConfigData.h +++ b/DiscordEuroscope/ConfigData.h @@ -19,11 +19,12 @@ #ifndef _CONFIGDATA_H_ #define _CONFIGDATA_H_ -#include "config.h" #include #include #include +struct DiscordButton; // discord_rpc.h + namespace DiscordEuroScope_Configuration { typedef struct @@ -52,6 +53,8 @@ namespace DiscordEuroScope_Configuration { return !label.empty() && !url.empty(); } + + void FillStruct(DiscordButton* refButton) const; }; enum States_Enum diff --git a/DiscordEuroscope/ConfigManager.cpp b/DiscordEuroscope/ConfigManager.cpp index f832c1a..2bb6abf 100644 --- a/DiscordEuroscope/ConfigManager.cpp +++ b/DiscordEuroscope/ConfigManager.cpp @@ -16,6 +16,7 @@ */ #include "stdafx.h" +#include "config.h" #include "ConfigManager.h" #include "MessageFormatter.h" #include "ESEHandler.h" diff --git a/DiscordEuroscope/ConfigManager.h b/DiscordEuroscope/ConfigManager.h index 39277dc..0809902 100644 --- a/DiscordEuroscope/ConfigManager.h +++ b/DiscordEuroscope/ConfigManager.h @@ -19,7 +19,6 @@ #ifndef _CONFIGMANAGER_H_ #define _CONFIGMANAGER_H_ -#include "config.h" #include #include #include diff --git a/DiscordEuroscope/DiscordEuroscopeExt.cpp b/DiscordEuroscope/DiscordEuroscopeExt.cpp index 043adf0..fda7888 100644 --- a/DiscordEuroscope/DiscordEuroscopeExt.cpp +++ b/DiscordEuroscope/DiscordEuroscopeExt.cpp @@ -126,11 +126,11 @@ VOID CALLBACK DiscordTimer(_In_ HWND hwnd, _In_ UINT uMsg, _In_ UINT_PTR idEvent if (configButtons[0].IsValid()) { - buttons[0] = { configButtons[0].label.c_str(), configButtons[0].url.c_str() }; + configButtons[0].FillStruct(buttons); // Nested condition because there will never be a single button in index 1. if (configButtons[1].IsValid()) { - buttons[1] = { configButtons[1].label.c_str(), configButtons[1].url.c_str() }; + configButtons[1].FillStruct(buttons+1); } else { buttons[1] = { "" , "" }; @@ -158,11 +158,11 @@ VOID CALLBACK DiscordTimer(_In_ HWND hwnd, _In_ UINT uMsg, _In_ UINT_PTR idEvent if (configButtons[0].IsValid()) { - buttons[0] = { configButtons[0].label.c_str(), configButtons[0].url.c_str() }; + configButtons[0].FillStruct(buttons); // Nested condition because there will never be a single button in index 1. if (configButtons[1].IsValid()) { - buttons[1] = { configButtons[1].label.c_str(), configButtons[1].url.c_str() }; + configButtons[1].FillStruct(buttons+1); } else { buttons[1] = { "" , "" }; @@ -192,11 +192,11 @@ VOID CALLBACK DiscordTimer(_In_ HWND hwnd, _In_ UINT uMsg, _In_ UINT_PTR idEvent if (configButtons[0].IsValid()) { - buttons[0] = { configButtons[0].label.c_str(), configButtons[0].url.c_str() }; + configButtons[0].FillStruct(buttons); // Nested condition because there will never be a single button in index 1. if (configButtons[1].IsValid()) { - buttons[1] = { configButtons[1].label.c_str(), configButtons[1].url.c_str() }; + configButtons[1].FillStruct(buttons+1); } else { buttons[1] = { "" , "" }; @@ -283,11 +283,11 @@ VOID CALLBACK DiscordTimer(_In_ HWND hwnd, _In_ UINT uMsg, _In_ UINT_PTR idEvent if (configButtons[0].IsValid()) { - buttons[0] = { configButtons[0].label.c_str(), configButtons[0].url.c_str() }; + configButtons[0].FillStruct(buttons); // Nested condition because there will never be a single button in index 1. if (configButtons[1].IsValid()) { - buttons[1] = { configButtons[1].label.c_str(), configButtons[1].url.c_str() }; + configButtons[1].FillStruct(buttons+1); } else { buttons[1] = { "" , "" };