Skip to content

Commit 7fe0c2a

Browse files
committed
refactor: FillStruct() implemented to tidy up code readability
1 parent be04129 commit 7fe0c2a

5 files changed

Lines changed: 20 additions & 10 deletions

File tree

DiscordEuroscope/ConfigData.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "stdafx.h"
19+
#include "inc/discord_rpc.h"
1920
#include "ConfigData.h"
2021

2122
namespace DiscordEuroScope_Configuration
@@ -47,4 +48,10 @@ namespace DiscordEuroScope_Configuration
4748
this->states[i].used = false;
4849
}
4950
}
51+
52+
void Button::FillStruct(DiscordButton* refButton) const
53+
{
54+
refButton->label = label.c_str();
55+
refButton->url = url.c_str();
56+
}
5057
}

DiscordEuroscope/ConfigData.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
#ifndef _CONFIGDATA_H_
2020
#define _CONFIGDATA_H_
2121

22-
#include "config.h"
2322
#include <string>
2423
#include <vector>
2524
#include <map>
2625

26+
struct DiscordButton; // discord_rpc.h
27+
2728
namespace DiscordEuroScope_Configuration
2829
{
2930
typedef struct
@@ -52,6 +53,8 @@ namespace DiscordEuroScope_Configuration
5253
{
5354
return !label.empty() && !url.empty();
5455
}
56+
57+
void FillStruct(DiscordButton* refButton) const;
5558
};
5659

5760
enum States_Enum

DiscordEuroscope/ConfigManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "stdafx.h"
19+
#include "config.h"
1920
#include "ConfigManager.h"
2021
#include "MessageFormatter.h"
2122
#include "ESEHandler.h"

DiscordEuroscope/ConfigManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#ifndef _CONFIGMANAGER_H_
2020
#define _CONFIGMANAGER_H_
2121

22-
#include "config.h"
2322
#include <string>
2423
#include <vector>
2524
#include <map>

DiscordEuroscope/DiscordEuroscopeExt.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ VOID CALLBACK DiscordTimer(_In_ HWND hwnd, _In_ UINT uMsg, _In_ UINT_PTR idEvent
126126

127127
if (configButtons[0].IsValid())
128128
{
129-
buttons[0] = { configButtons[0].label.c_str(), configButtons[0].url.c_str() };
129+
configButtons[0].FillStruct(buttons);
130130
// Nested condition because there will never be a single button in index 1.
131131
if (configButtons[1].IsValid())
132132
{
133-
buttons[1] = { configButtons[1].label.c_str(), configButtons[1].url.c_str() };
133+
configButtons[1].FillStruct(buttons+1);
134134
}
135135
else {
136136
buttons[1] = { "" , "" };
@@ -158,11 +158,11 @@ VOID CALLBACK DiscordTimer(_In_ HWND hwnd, _In_ UINT uMsg, _In_ UINT_PTR idEvent
158158

159159
if (configButtons[0].IsValid())
160160
{
161-
buttons[0] = { configButtons[0].label.c_str(), configButtons[0].url.c_str() };
161+
configButtons[0].FillStruct(buttons);
162162
// Nested condition because there will never be a single button in index 1.
163163
if (configButtons[1].IsValid())
164164
{
165-
buttons[1] = { configButtons[1].label.c_str(), configButtons[1].url.c_str() };
165+
configButtons[1].FillStruct(buttons+1);
166166
}
167167
else {
168168
buttons[1] = { "" , "" };
@@ -192,11 +192,11 @@ VOID CALLBACK DiscordTimer(_In_ HWND hwnd, _In_ UINT uMsg, _In_ UINT_PTR idEvent
192192

193193
if (configButtons[0].IsValid())
194194
{
195-
buttons[0] = { configButtons[0].label.c_str(), configButtons[0].url.c_str() };
195+
configButtons[0].FillStruct(buttons);
196196
// Nested condition because there will never be a single button in index 1.
197197
if (configButtons[1].IsValid())
198198
{
199-
buttons[1] = { configButtons[1].label.c_str(), configButtons[1].url.c_str() };
199+
configButtons[1].FillStruct(buttons+1);
200200
}
201201
else {
202202
buttons[1] = { "" , "" };
@@ -283,11 +283,11 @@ VOID CALLBACK DiscordTimer(_In_ HWND hwnd, _In_ UINT uMsg, _In_ UINT_PTR idEvent
283283

284284
if (configButtons[0].IsValid())
285285
{
286-
buttons[0] = { configButtons[0].label.c_str(), configButtons[0].url.c_str() };
286+
configButtons[0].FillStruct(buttons);
287287
// Nested condition because there will never be a single button in index 1.
288288
if (configButtons[1].IsValid())
289289
{
290-
buttons[1] = { configButtons[1].label.c_str(), configButtons[1].url.c_str() };
290+
configButtons[1].FillStruct(buttons+1);
291291
}
292292
else {
293293
buttons[1] = { "" , "" };

0 commit comments

Comments
 (0)