diff --git a/Core/GameEngine/Include/Common/UserPreferences.h b/Core/GameEngine/Include/Common/UserPreferences.h index f1b9f3ea786..dd7ce6b100d 100644 --- a/Core/GameEngine/Include/Common/UserPreferences.h +++ b/Core/GameEngine/Include/Common/UserPreferences.h @@ -60,11 +60,13 @@ class UserPreferences : public PreferenceMap Real getReal(AsciiString key, Real defaultValue) const; Int getInt(AsciiString key, Int defaultValue) const; AsciiString getAsciiString(AsciiString key, AsciiString defaultValue) const; + UnicodeString getUnicodeString(AsciiString key, UnicodeString defaultValue) const; void setBool(AsciiString key, Bool val); void setReal(AsciiString key, Real val); void setInt(AsciiString key, Int val); void setAsciiString(AsciiString key, AsciiString val); + void setUnicodeString(AsciiString key, UnicodeString val); protected: AsciiString m_filename; diff --git a/Core/GameEngine/Source/Common/UserPreferences.cpp b/Core/GameEngine/Source/Common/UserPreferences.cpp index ae9f7636b7b..c90c795ae02 100644 --- a/Core/GameEngine/Source/Common/UserPreferences.cpp +++ b/Core/GameEngine/Source/Common/UserPreferences.cpp @@ -260,6 +260,19 @@ AsciiString UserPreferences::getAsciiString(AsciiString key, AsciiString default return it->second; } +UnicodeString UserPreferences::getUnicodeString(AsciiString key, UnicodeString defaultValue) const +{ + UserPreferences::const_iterator it = find(key); + if (it == end()) + { + return defaultValue; + } + + UnicodeString ret; + ret.translate(it->second); + return ret; +} + void UserPreferences::setBool(AsciiString key, Bool val) { (*this)[key] = boolAsStr(val); @@ -280,6 +293,13 @@ void UserPreferences::setAsciiString(AsciiString key, AsciiString val) (*this)[key] = val; } +void UserPreferences::setUnicodeString(AsciiString key, UnicodeString val) +{ + AsciiString str; + str.translate(val); + (*this)[key] = str; +} + //----------------------------------------------------------------------------- // QuickMatchPreferences base class //----------------------------------------------------------------------------- @@ -515,22 +535,16 @@ void CustomMatchPreferences::setLastLadder(const AsciiString& addr, UnsignedShor (*this)["LastLadderPort"] = strVal; } -AsciiString CustomMatchPreferences::getLastLobbyName() const +UnicodeString CustomMatchPreferences::getLastLobbyName() const { - CustomMatchPreferences::const_iterator it = find("LastLobbyName"); - if (it == end()) - { - return AsciiString::TheEmptyString; - } - - AsciiString ret = it->second; + UnicodeString ret = getUnicodeString("LastLobbyName", UnicodeString::TheEmptyString); ret.trim(); return ret; } -void CustomMatchPreferences::setLastLobbyName(const AsciiString& name) +void CustomMatchPreferences::setLastLobbyName(const UnicodeString& name) { - (*this)["LastLobbyName"] = name; + setUnicodeString("LastLobbyName", name); } AsciiString CustomMatchPreferences::getLastLadderAddr( void ) diff --git a/GeneralsMD/Code/GameEngine/Include/Common/CustomMatchPreferences.h b/GeneralsMD/Code/GameEngine/Include/Common/CustomMatchPreferences.h index 228a7e46b4d..5aea5cee8a4 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/CustomMatchPreferences.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/CustomMatchPreferences.h @@ -44,8 +44,8 @@ class CustomMatchPreferences : public UserPreferences CustomMatchPreferences(); virtual ~CustomMatchPreferences() override; - AsciiString getLastLobbyName() const; - void setLastLobbyName(const AsciiString& name); + UnicodeString getLastLobbyName() const; + void setLastLobbyName(const UnicodeString& name); void setLastLadder(const AsciiString& addr, UnsignedShort port); AsciiString getLastLadderAddr(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupHostGame.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupHostGame.cpp index 074b472fa6d..b5f98aed513 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupHostGame.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupHostGame.cpp @@ -336,12 +336,8 @@ void PopupHostGameInit( WindowLayout *layout, void *userData ) #if defined(GENERALS_ONLINE) { CustomMatchPreferences pref; - AsciiString lastLobbyName = pref.getLastLobbyName(); - if (!lastLobbyName.isEmpty()) - { - name.translate(lastLobbyName.str()); - } - else + name = pref.getLastLobbyName(); + if (name.isEmpty()) { name.translate("Generals Online Lobby"); } @@ -605,19 +601,8 @@ WindowMsgHandledType PopupHostGameSystem( GameWindow *window, UnsignedInt msg, W #if defined(GENERALS_ONLINE) // save last used lobby name to CustomPref.ini { - char buffer[256]; - const WideChar* w = name.str(); - int i = 0; - for (; w[i] != 0 && i < 255; ++i) - { - buffer[i] = (char)(w[i] & 0xFF); - } - buffer[i] = 0; - - AsciiString lobbyNameAscii = buffer; - CustomMatchPreferences pref; - pref.setLastLobbyName(lobbyNameAscii); + pref.setLastLobbyName(name); pref.write(); } #endif