Skip to content

Commit

Permalink
Emulate windows registry by environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
feliwir committed Sep 13, 2024
1 parent 3f1b7ea commit adda106
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/game/common/system/asciistring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,27 @@ void Utf8String::To_Lower()
Set(buf);
}

/**
* Converts this string to upper case
*/
void Utf8String::To_Upper()
{
// Size specifically matches original code for compatibility.
char buf[MAX_TO_LOWER_BUF_LEN];

if (m_data == nullptr) {
return;
}

strcpy(buf, Peek());

for (char *c = buf; *c != '\0'; ++c) {
*c = toupper(*c);
}

Set(buf);
}

/**
* @brief Convert any windows path separators to posix ('\' to '/').
*/
Expand Down
1 change: 1 addition & 0 deletions src/game/common/system/asciistring.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Utf8String

void Trim();
void To_Lower();
void To_Upper(); // Not in original code.
void Remove_Last_Char();

void Format(const char *format, ...);
Expand Down
26 changes: 24 additions & 2 deletions src/game/common/system/registryget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,18 @@ bool Get_String_From_Registry(Utf8String subkey, Utf8String value, Utf8String &d

return success;
#else
return false;
Utf8String key = "CNC_ZH_";
key += value;
key.To_Upper();
captainslog_info(
"Get_String_From_Registry (environment) - looking in %s for key %s\n", key.Str(), value.Str());
const char *env_value = getenv(key.Str());
bool success = env_value != nullptr;
if (success) {
destination = env_value;
}

return success;
#endif
}

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

return success;
#else
return false;
Utf8String key = "CNC_GEN_";
key += value;
key.To_Upper();
captainslog_info(
"Get_String_From_Generals_Registry (environment) - looking in %s for key %s\n", key.Str(), value.Str());
const char *env_value = getenv(key.Str());
bool success = env_value != nullptr;
if (success) {
destination = env_value;
}

return success;
#endif
}

Expand Down

0 comments on commit adda106

Please sign in to comment.