Skip to content

Commit 2433256

Browse files
committed
unify(common): Merge Registry code
1 parent 2c26a90 commit 2433256

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

Generals/Code/GameEngine/Include/Common/Registry.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030

3131
#include <Common/AsciiString.h>
3232

33+
#if RTS_ZEROHOUR
34+
/**
35+
* Get a string from the original Generals Registry
36+
*/
37+
Bool GetStringFromGeneralsRegistry(AsciiString path, AsciiString key, AsciiString& val);
38+
#endif
3339
/**
3440
* Get a string from the registry
3541
*/

Generals/Code/GameEngine/Source/Common/System/registry.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,29 @@ Bool setUnsignedIntInRegistry( HKEY root, AsciiString path, AsciiString key, Uns
115115
return (returnValue == ERROR_SUCCESS);
116116
}
117117

118+
#if RTS_ZEROHOUR
119+
Bool GetStringFromGeneralsRegistry(AsciiString path, AsciiString key, AsciiString& val)
120+
{
121+
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Generals";
122+
123+
fullPath.concat(path);
124+
DEBUG_LOG(("GetStringFromRegistry - looking in %s for key %s", fullPath.str(), key.str()));
125+
if (getStringFromRegistry(HKEY_LOCAL_MACHINE, fullPath.str(), key.str(), val))
126+
{
127+
return TRUE;
128+
}
129+
130+
return getStringFromRegistry(HKEY_CURRENT_USER, fullPath.str(), key.str(), val);
131+
}
132+
#endif
133+
118134
Bool GetStringFromRegistry(AsciiString path, AsciiString key, AsciiString& val)
119135
{
136+
#if RTS_GENERALS
120137
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Generals";
138+
#elif RTS_ZEROHOUR
139+
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour";
140+
#endif
121141

122142
fullPath.concat(path);
123143
DEBUG_LOG(("GetStringFromRegistry - looking in %s for key %s", fullPath.str(), key.str()));
@@ -131,7 +151,11 @@ Bool GetStringFromRegistry(AsciiString path, AsciiString key, AsciiString& val)
131151

132152
Bool GetUnsignedIntFromRegistry(AsciiString path, AsciiString key, UnsignedInt& val)
133153
{
154+
#if RTS_GENERALS
134155
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Generals";
156+
#elif RTS_ZEROHOUR
157+
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour";
158+
#endif
135159

136160
fullPath.concat(path);
137161
DEBUG_LOG(("GetUnsignedIntFromRegistry - looking in %s for key %s", fullPath.str(), key.str()));
@@ -146,6 +170,7 @@ Bool GetUnsignedIntFromRegistry(AsciiString path, AsciiString key, UnsignedInt&
146170
AsciiString GetRegistryLanguage(void)
147171
{
148172
static Bool cached = FALSE;
173+
// NOTE: static causes a memory leak, but we have to keep it because the value is cached.
149174
static AsciiString val = "english";
150175
if (cached) {
151176
return val;

GeneralsMD/Code/GameEngine/Include/Common/Registry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030

3131
#include <Common/AsciiString.h>
3232

33+
#if RTS_ZEROHOUR
3334
/**
3435
* Get a string from the original Generals Registry
3536
*/
3637
Bool GetStringFromGeneralsRegistry(AsciiString path, AsciiString key, AsciiString& val);
38+
#endif
3739
/**
3840
* Get a string from the registry
3941
*/

GeneralsMD/Code/GameEngine/Source/Common/System/registry.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Bool setUnsignedIntInRegistry( HKEY root, AsciiString path, AsciiString key, Uns
115115
return (returnValue == ERROR_SUCCESS);
116116
}
117117

118+
#if RTS_ZEROHOUR
118119
Bool GetStringFromGeneralsRegistry(AsciiString path, AsciiString key, AsciiString& val)
119120
{
120121
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Generals";
@@ -128,10 +129,15 @@ Bool GetStringFromGeneralsRegistry(AsciiString path, AsciiString key, AsciiStrin
128129

129130
return getStringFromRegistry(HKEY_CURRENT_USER, fullPath.str(), key.str(), val);
130131
}
132+
#endif
131133

132134
Bool GetStringFromRegistry(AsciiString path, AsciiString key, AsciiString& val)
133135
{
136+
#if RTS_GENERALS
137+
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Generals";
138+
#elif RTS_ZEROHOUR
134139
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour";
140+
#endif
135141

136142
fullPath.concat(path);
137143
DEBUG_LOG(("GetStringFromRegistry - looking in %s for key %s", fullPath.str(), key.str()));
@@ -145,7 +151,11 @@ Bool GetStringFromRegistry(AsciiString path, AsciiString key, AsciiString& val)
145151

146152
Bool GetUnsignedIntFromRegistry(AsciiString path, AsciiString key, UnsignedInt& val)
147153
{
154+
#if RTS_GENERALS
155+
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Generals";
156+
#elif RTS_ZEROHOUR
148157
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour";
158+
#endif
149159

150160
fullPath.concat(path);
151161
DEBUG_LOG(("GetUnsignedIntFromRegistry - looking in %s for key %s", fullPath.str(), key.str()));

0 commit comments

Comments
 (0)