Skip to content

Commit f15abf3

Browse files
authored
unify(common): Merge Registry code (TheSuperHackers#2193)
1 parent 64786cc commit f15abf3

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

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

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

3131
#include <Common/AsciiString.h>
3232

33+
/**
34+
* Get a string from the original Generals Registry
35+
*/
36+
Bool GetStringFromGeneralsRegistry(AsciiString path, AsciiString key, AsciiString& val);
3337
/**
3438
* Get a string from the registry
3539
*/

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

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

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

122140
fullPath.concat(path);
123141
DEBUG_LOG(("GetStringFromRegistry - looking in %s for key %s", fullPath.str(), key.str()));
@@ -131,7 +149,11 @@ Bool GetStringFromRegistry(AsciiString path, AsciiString key, AsciiString& val)
131149

132150
Bool GetUnsignedIntFromRegistry(AsciiString path, AsciiString key, UnsignedInt& val)
133151
{
152+
#if RTS_GENERALS
134153
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Generals";
154+
#elif RTS_ZEROHOUR
155+
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour";
156+
#endif
135157

136158
fullPath.concat(path);
137159
DEBUG_LOG(("GetUnsignedIntFromRegistry - looking in %s for key %s", fullPath.str(), key.str()));
@@ -146,6 +168,7 @@ Bool GetUnsignedIntFromRegistry(AsciiString path, AsciiString key, UnsignedInt&
146168
AsciiString GetRegistryLanguage(void)
147169
{
148170
static Bool cached = FALSE;
171+
// NOTE: static causes a memory leak, but we have to keep it because the value is cached.
149172
static AsciiString val = "english";
150173
if (cached) {
151174
return val;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ Bool GetStringFromGeneralsRegistry(AsciiString path, AsciiString key, AsciiStrin
131131

132132
Bool GetStringFromRegistry(AsciiString path, AsciiString key, AsciiString& val)
133133
{
134+
#if RTS_GENERALS
135+
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Generals";
136+
#elif RTS_ZEROHOUR
134137
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour";
138+
#endif
135139

136140
fullPath.concat(path);
137141
DEBUG_LOG(("GetStringFromRegistry - looking in %s for key %s", fullPath.str(), key.str()));
@@ -145,7 +149,11 @@ Bool GetStringFromRegistry(AsciiString path, AsciiString key, AsciiString& val)
145149

146150
Bool GetUnsignedIntFromRegistry(AsciiString path, AsciiString key, UnsignedInt& val)
147151
{
152+
#if RTS_GENERALS
153+
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Generals";
154+
#elif RTS_ZEROHOUR
148155
AsciiString fullPath = "SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour";
156+
#endif
149157

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

0 commit comments

Comments
 (0)