Skip to content

Commit

Permalink
refactor: FillStruct() implemented to tidy up code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirollos committed Nov 16, 2024
1 parent be04129 commit 7fe0c2a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
7 changes: 7 additions & 0 deletions DiscordEuroscope/ConfigData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "stdafx.h"
#include "inc/discord_rpc.h"
#include "ConfigData.h"

namespace DiscordEuroScope_Configuration
Expand Down Expand Up @@ -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();
}
}
5 changes: 4 additions & 1 deletion DiscordEuroscope/ConfigData.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
#ifndef _CONFIGDATA_H_
#define _CONFIGDATA_H_

#include "config.h"
#include <string>
#include <vector>
#include <map>

struct DiscordButton; // discord_rpc.h

namespace DiscordEuroScope_Configuration
{
typedef struct
Expand Down Expand Up @@ -52,6 +53,8 @@ namespace DiscordEuroScope_Configuration
{
return !label.empty() && !url.empty();
}

void FillStruct(DiscordButton* refButton) const;
};

enum States_Enum
Expand Down
1 change: 1 addition & 0 deletions DiscordEuroscope/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "stdafx.h"
#include "config.h"
#include "ConfigManager.h"
#include "MessageFormatter.h"
#include "ESEHandler.h"
Expand Down
1 change: 0 additions & 1 deletion DiscordEuroscope/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef _CONFIGMANAGER_H_
#define _CONFIGMANAGER_H_

#include "config.h"
#include <string>
#include <vector>
#include <map>
Expand Down
16 changes: 8 additions & 8 deletions DiscordEuroscope/DiscordEuroscopeExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] = { "" , "" };
Expand Down Expand Up @@ -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] = { "" , "" };
Expand Down Expand Up @@ -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] = { "" , "" };
Expand Down Expand Up @@ -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] = { "" , "" };
Expand Down

0 comments on commit 7fe0c2a

Please sign in to comment.