Skip to content

Commit adda106

Browse files
committed
Emulate windows registry by environment variables
1 parent 3f1b7ea commit adda106

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/game/common/system/asciistring.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,27 @@ void Utf8String::To_Lower()
389389
Set(buf);
390390
}
391391

392+
/**
393+
* Converts this string to upper case
394+
*/
395+
void Utf8String::To_Upper()
396+
{
397+
// Size specifically matches original code for compatibility.
398+
char buf[MAX_TO_LOWER_BUF_LEN];
399+
400+
if (m_data == nullptr) {
401+
return;
402+
}
403+
404+
strcpy(buf, Peek());
405+
406+
for (char *c = buf; *c != '\0'; ++c) {
407+
*c = toupper(*c);
408+
}
409+
410+
Set(buf);
411+
}
412+
392413
/**
393414
* @brief Convert any windows path separators to posix ('\' to '/').
394415
*/

src/game/common/system/asciistring.h

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class Utf8String
126126

127127
void Trim();
128128
void To_Lower();
129+
void To_Upper(); // Not in original code.
129130
void Remove_Last_Char();
130131

131132
void Format(const char *format, ...);

src/game/common/system/registryget.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,18 @@ bool Get_String_From_Registry(Utf8String subkey, Utf8String value, Utf8String &d
9090

9191
return success;
9292
#else
93-
return false;
93+
Utf8String key = "CNC_ZH_";
94+
key += value;
95+
key.To_Upper();
96+
captainslog_info(
97+
"Get_String_From_Registry (environment) - looking in %s for key %s\n", key.Str(), value.Str());
98+
const char *env_value = getenv(key.Str());
99+
bool success = env_value != nullptr;
100+
if (success) {
101+
destination = env_value;
102+
}
103+
104+
return success;
94105
#endif
95106
}
96107

@@ -108,7 +119,18 @@ bool Get_String_From_Generals_Registry(Utf8String subkey, Utf8String value, Utf8
108119

109120
return success;
110121
#else
111-
return false;
122+
Utf8String key = "CNC_GEN_";
123+
key += value;
124+
key.To_Upper();
125+
captainslog_info(
126+
"Get_String_From_Generals_Registry (environment) - looking in %s for key %s\n", key.Str(), value.Str());
127+
const char *env_value = getenv(key.Str());
128+
bool success = env_value != nullptr;
129+
if (success) {
130+
destination = env_value;
131+
}
132+
133+
return success;
112134
#endif
113135
}
114136

0 commit comments

Comments
 (0)