diff --git a/src/openrct2-ui/interface/Theme.cpp b/src/openrct2-ui/interface/Theme.cpp index 167196a3d1..fd25a92873 100644 --- a/src/openrct2-ui/interface/Theme.cpp +++ b/src/openrct2-ui/interface/Theme.cpp @@ -617,9 +617,9 @@ namespace ThemeManager ActiveAvailableThemeIndex = 1; bool configValid = false; - if (!String::IsNullOrEmpty(gConfigInterface.CurrentThemePreset)) + if (!gConfigInterface.CurrentThemePreset.empty()) { - if (LoadThemeByConfigName(gConfigInterface.CurrentThemePreset)) + if (LoadThemeByConfigName(gConfigInterface.CurrentThemePreset.c_str())) { configValid = true; } @@ -627,7 +627,7 @@ namespace ThemeManager if (!configValid) { - String::DiscardDuplicate(&gConfigInterface.CurrentThemePreset, ThemeManagerGetAvailableThemeConfigName(1)); + gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(1); } } @@ -709,7 +709,7 @@ void ThemeManagerSetActiveAvailableTheme(size_t index) } } ThemeManager::ActiveAvailableThemeIndex = index; - String::DiscardDuplicate(&gConfigInterface.CurrentThemePreset, ThemeManagerGetAvailableThemeConfigName(index)); + gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(index); ColourSchemeUpdateAll(); } @@ -805,7 +805,7 @@ void ThemeRename(const utf8* name) if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path)) { ThemeManager::ActiveAvailableThemeIndex = i; - String::DiscardDuplicate(&gConfigInterface.CurrentThemePreset, ThemeManagerGetAvailableThemeConfigName(1)); + gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(1); break; } } @@ -830,7 +830,7 @@ void ThemeDuplicate(const utf8* name) if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path)) { ThemeManager::ActiveAvailableThemeIndex = i; - String::DiscardDuplicate(&gConfigInterface.CurrentThemePreset, ThemeManagerGetAvailableThemeConfigName(i)); + gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(i); break; } } @@ -841,7 +841,7 @@ void ThemeDelete() File::Delete(ThemeManager::CurrentThemePath); ThemeManager::LoadTheme(const_cast(&PredefinedThemeRCT2)); ThemeManager::ActiveAvailableThemeIndex = 1; - String::DiscardDuplicate(&gConfigInterface.CurrentThemePreset, ThemeManagerGetAvailableThemeConfigName(1)); + gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(1); } void ThemeManagerInitialise() diff --git a/src/openrct2-ui/windows/CustomCurrency.cpp b/src/openrct2-ui/windows/CustomCurrency.cpp index 0a8a3f9d52..28953a2eaa 100644 --- a/src/openrct2-ui/windows/CustomCurrency.cpp +++ b/src/openrct2-ui/windows/CustomCurrency.cpp @@ -164,9 +164,7 @@ public: CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, std::string(text).c_str(), CURRENCY_SYMBOL_MAX_SIZE); - safe_strcpy( - gConfigGeneral.CustomCurrencySymbol, CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, - CURRENCY_SYMBOL_MAX_SIZE); + gConfigGeneral.CustomCurrencySymbol = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode; ConfigSaveDefault(); window_invalidate_all(); diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index bc1d8207a1..e848ef084f 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -199,7 +199,6 @@ namespace OpenRCT2 gfx_unload_g2(); gfx_unload_g1(); Audio::Close(); - ConfigRelease(); Instance = nullptr; } diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index bc1251e369..e462d9c9fb 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -147,7 +147,7 @@ namespace Config model->CustomCurrencyRate = reader->GetInt32("custom_currency_rate", 10); model->CustomCurrencyAffix = reader->GetEnum( "custom_currency_affix", CurrencyAffix::Suffix, Enum_CurrencySymbolAffix); - model->CustomCurrencySymbol = reader->GetCString("custom_currency_symbol", "Ctm"); + model->CustomCurrencySymbol = reader->GetString("custom_currency_symbol", "Ctm"); model->EdgeScrolling = reader->GetBoolean("edge_scrolling", true); model->EdgeScrollingSpeed = reader->GetInt32("edge_scrolling_speed", 12); model->FullscreenMode = reader->GetInt32("fullscreen_mode", 0); @@ -325,8 +325,8 @@ namespace Config model->ToolbarShowChat = reader->GetBoolean("toolbar_show_chat", false); model->ToolbarShowZoom = reader->GetBoolean("toolbar_show_zoom", true); model->ConsoleSmallFont = reader->GetBoolean("console_small_font", false); - model->CurrentThemePreset = reader->GetCString("current_theme", "*RCT2"); - model->CurrentTitleSequencePreset = reader->GetCString("current_title_sequence", "*OPENRCT2"); + model->CurrentThemePreset = reader->GetString("current_theme", "*RCT2"); + model->CurrentTitleSequencePreset = reader->GetString("current_title_sequence", "*OPENRCT2"); model->RandomTitleSequence = reader->GetBoolean("random_title_sequence", false); model->ObjectSelectionFilterFlags = reader->GetInt32("object_selection_filter_flags", 0x3FFF); model->ScenarioselectLastTab = reader->GetInt32("scenarioselect_last_tab", 0); @@ -511,8 +511,8 @@ namespace Config if (reader->ReadSection("font")) { auto model = &gConfigFonts; - model->FileName = reader->GetCString("file_name", nullptr); - model->FontName = reader->GetCString("font_name", nullptr); + model->FileName = reader->GetString("file_name", ""); + model->FontName = reader->GetString("font_name", ""); model->OffsetX = reader->GetInt32("x_offset", false); model->OffsetY = reader->GetInt32("y_offset", true); model->SizeTiny = reader->GetInt32("size_tiny", true); @@ -775,7 +775,6 @@ PluginConfiguration gConfigPlugin; void ConfigSetDefaults() { - ConfigRelease(); Config::SetDefaults(); } @@ -786,7 +785,6 @@ bool ConfigOpen(u8string_view path) return false; } - ConfigRelease(); auto result = Config::ReadFile(path); if (result) { @@ -800,15 +798,6 @@ bool ConfigSave(u8string_view path) return Config::WriteFile(path); } -void ConfigRelease() -{ - SafeFree(gConfigGeneral.CustomCurrencySymbol); - SafeFree(gConfigInterface.CurrentThemePreset); - SafeFree(gConfigInterface.CurrentTitleSequencePreset); - SafeFree(gConfigFonts.FileName); - SafeFree(gConfigFonts.FontName); -} - u8string ConfigGetDefaultPath() { auto env = GetContext()->GetPlatformEnvironment(); diff --git a/src/openrct2/config/Config.h b/src/openrct2/config/Config.h index 282b6dd5c4..0f42da874d 100644 --- a/src/openrct2/config/Config.h +++ b/src/openrct2/config/Config.h @@ -77,7 +77,7 @@ struct GeneralConfiguration CurrencyType CurrencyFormat; int32_t CustomCurrencyRate; CurrencyAffix CustomCurrencyAffix; - utf8* CustomCurrencySymbol; + u8string CustomCurrencySymbol; // Controls bool EdgeScrolling; @@ -130,8 +130,8 @@ struct InterfaceConfiguration bool ToolbarShowZoom; bool ConsoleSmallFont; bool RandomTitleSequence; - utf8* CurrentThemePreset; - utf8* CurrentTitleSequencePreset; + u8string CurrentThemePreset; + u8string CurrentTitleSequencePreset; int32_t ObjectSelectionFilterFlags; int32_t ScenarioselectLastTab; bool ListRideVehiclesSeparately; @@ -139,7 +139,7 @@ struct InterfaceConfiguration struct SoundConfiguration { - std::string Device; + u8string Device; bool MasterSoundEnabled; uint8_t MasterVolume; TitleMusicKind TitleMusic; @@ -152,21 +152,21 @@ struct SoundConfiguration struct NetworkConfiguration { - std::string PlayerName; + u8string PlayerName; int32_t DefaultPort; - std::string ListenAddress; - std::string DefaultPassword; + u8string ListenAddress; + u8string DefaultPassword; bool StayConnected; bool Advertise; - std::string AdvertiseAddress; + u8string AdvertiseAddress; int32_t Maxplayers; - std::string ServerName; - std::string ServerDescription; - std::string ServerGreeting; - std::string MasterServerUrl; - std::string ProviderName; - std::string ProviderEmail; - std::string ProviderWebsite; + u8string ServerName; + u8string ServerDescription; + u8string ServerGreeting; + u8string MasterServerUrl; + u8string ProviderName; + u8string ProviderEmail; + u8string ProviderWebsite; bool KnownKeysOnly; bool LogChat; bool LogServerActions; @@ -198,8 +198,8 @@ struct NotificationConfiguration struct FontConfiguration { - utf8* FileName; - utf8* FontName; + u8string FileName; + u8string FontName; int32_t OffsetX; int32_t OffsetY; int32_t SizeTiny; @@ -217,7 +217,7 @@ struct FontConfiguration struct PluginConfiguration { bool EnableHotReloading; - std::string AllowedHosts; + u8string AllowedHosts; }; enum class Sort : int32_t @@ -268,7 +268,6 @@ bool ConfigOpen(u8string_view path); bool ConfigSave(u8string_view path); u8string ConfigGetDefaultPath(); void ConfigSetDefaults(); -void ConfigRelease(); bool ConfigSaveDefault(); bool ConfigFindOrBrowseInstallDirectory(); diff --git a/src/openrct2/config/IniReader.cpp b/src/openrct2/config/IniReader.cpp index 07e7d956f9..46fbbc783d 100644 --- a/src/openrct2/config/IniReader.cpp +++ b/src/openrct2/config/IniReader.cpp @@ -427,17 +427,6 @@ public: } }; -utf8* IIniReader::GetCString(const std::string& name, const utf8* defaultValue) const -{ - std::string szValue; - if (!TryGetString(name, &szValue)) - { - return String::Duplicate(defaultValue); - } - - return String::Duplicate(szValue.c_str()); -} - std::unique_ptr CreateIniReader(OpenRCT2::IStream* stream) { return std::make_unique(stream); diff --git a/src/openrct2/config/IniReader.hpp b/src/openrct2/config/IniReader.hpp index f9e9546e1a..7a0181329b 100644 --- a/src/openrct2/config/IniReader.hpp +++ b/src/openrct2/config/IniReader.hpp @@ -45,8 +45,6 @@ struct IIniReader return configEnum.GetValue(szValue, defaultValue); } - - utf8* GetCString(const std::string& name, const utf8* defaultValue) const; }; [[nodiscard]] std::unique_ptr CreateIniReader(OpenRCT2::IStream* stream); diff --git a/src/openrct2/interface/Fonts.cpp b/src/openrct2/interface/Fonts.cpp index 5ab52fe316..4441a6db4a 100644 --- a/src/openrct2/interface/Fonts.cpp +++ b/src/openrct2/interface/Fonts.cpp @@ -128,12 +128,12 @@ static bool LoadFont(LocalisationService& localisationService, TTFFontSetDescrip static bool LoadCustomConfigFont(LocalisationService& localisationService) { static TTFFontSetDescriptor TTFFontCustom = { { - { gConfigFonts.FileName, gConfigFonts.FontName, gConfigFonts.SizeTiny, gConfigFonts.OffsetX, gConfigFonts.OffsetY, - gConfigFonts.HeightTiny, gConfigFonts.HintingThreshold, nullptr }, - { gConfigFonts.FileName, gConfigFonts.FontName, gConfigFonts.SizeSmall, gConfigFonts.OffsetX, gConfigFonts.OffsetY, - gConfigFonts.HeightSmall, gConfigFonts.HintingThreshold, nullptr }, - { gConfigFonts.FileName, gConfigFonts.FontName, gConfigFonts.SizeMedium, gConfigFonts.OffsetX, gConfigFonts.OffsetY, - gConfigFonts.HeightMedium, gConfigFonts.HintingThreshold, nullptr }, + { gConfigFonts.FileName.c_str(), gConfigFonts.FontName.c_str(), gConfigFonts.SizeTiny, gConfigFonts.OffsetX, + gConfigFonts.OffsetY, gConfigFonts.HeightTiny, gConfigFonts.HintingThreshold, nullptr }, + { gConfigFonts.FileName.c_str(), gConfigFonts.FontName.c_str(), gConfigFonts.SizeSmall, gConfigFonts.OffsetX, + gConfigFonts.OffsetY, gConfigFonts.HeightSmall, gConfigFonts.HintingThreshold, nullptr }, + { gConfigFonts.FileName.c_str(), gConfigFonts.FontName.c_str(), gConfigFonts.SizeMedium, gConfigFonts.OffsetX, + gConfigFonts.OffsetY, gConfigFonts.HeightMedium, gConfigFonts.HintingThreshold, nullptr }, } }; ttf_dispose(); @@ -153,7 +153,7 @@ void TryLoadFonts(LocalisationService& localisationService) if (fontFamily != FAMILY_OPENRCT2_SPRITE) { - if (!String::IsNullOrEmpty(gConfigFonts.FileName)) + if (!gConfigFonts.FileName.empty()) { if (LoadCustomConfigFont(localisationService)) { diff --git a/src/openrct2/localisation/Currency.cpp b/src/openrct2/localisation/Currency.cpp index 01892232bc..55a0a4d115 100644 --- a/src/openrct2/localisation/Currency.cpp +++ b/src/openrct2/localisation/Currency.cpp @@ -40,10 +40,10 @@ void currency_load_custom_currency_config() { CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate = gConfigGeneral.CustomCurrencyRate; CurrencyDescriptors[EnumValue(CurrencyType::Custom)].affix_unicode = gConfigGeneral.CustomCurrencyAffix; - if (gConfigGeneral.CustomCurrencySymbol != nullptr) + if (!gConfigGeneral.CustomCurrencySymbol.empty()) { safe_strcpy( - CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, gConfigGeneral.CustomCurrencySymbol, + CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, gConfigGeneral.CustomCurrencySymbol.c_str(), CURRENCY_SYMBOL_MAX_SIZE); } } diff --git a/src/openrct2/title/TitleScreen.cpp b/src/openrct2/title/TitleScreen.cpp index b7366d2eda..6c7bf2d7ae 100644 --- a/src/openrct2/title/TitleScreen.cpp +++ b/src/openrct2/title/TitleScreen.cpp @@ -201,8 +201,7 @@ void TitleScreen::ChangePresetSequence(size_t preset) } const utf8* configId = title_sequence_manager_get_config_id(preset); - SafeFree(gConfigInterface.CurrentTitleSequencePreset); - gConfigInterface.CurrentTitleSequencePreset = _strdup(configId); + gConfigInterface.CurrentTitleSequencePreset = configId; if (!_previewingSequence) _currentSequence = preset; @@ -319,8 +318,7 @@ bool TitleScreen::TryLoadSequence(bool loadPreview) { // Forcefully change the preset to a preset that works. const utf8* configId = title_sequence_manager_get_config_id(targetSequence); - SafeFree(gConfigInterface.CurrentTitleSequencePreset); - gConfigInterface.CurrentTitleSequencePreset = _strdup(configId); + gConfigInterface.CurrentTitleSequencePreset = configId; } _currentSequence = targetSequence; gfx_invalidate_screen(); @@ -397,7 +395,7 @@ void title_set_hide_version_info(bool value) size_t title_get_config_sequence() { - return title_sequence_manager_get_index_for_config_id(gConfigInterface.CurrentTitleSequencePreset); + return title_sequence_manager_get_index_for_config_id(gConfigInterface.CurrentTitleSequencePreset.c_str()); } size_t title_get_current_sequence() diff --git a/test/tests/IniReaderTest.cpp b/test/tests/IniReaderTest.cpp index 521a3e7692..633370ebea 100644 --- a/test/tests/IniReaderTest.cpp +++ b/test/tests/IniReaderTest.cpp @@ -35,7 +35,7 @@ TEST_F(IniReaderTest, create_empty) auto ir = CreateIniReader(&ms); ASSERT_NE(ir, nullptr); ASSERT_EQ(ir->GetBoolean("nobody", true), true); - ASSERT_EQ(ir->GetCString("expects", nullptr), nullptr); + ASSERT_EQ(ir->GetString("expects", ""), ""); ASSERT_EQ(ir->GetEnum("spanish", 12345, Enum_Currency), 12345); ASSERT_EQ(ir->GetFloat("inquisition", 1.234f), 1.234f); ASSERT_EQ(ir->GetInt32("universal_answer", 42), 42); @@ -64,9 +64,8 @@ TEST_F(IniReaderTest, read_prepared) // values from different sections ASSERT_EQ(ir->GetInt32("one", 42), 42); ASSERT_EQ(ir->GetBoolean("boolval", false), true); - const utf8* str = ir->GetCString("path", nullptr); - ASSERT_STREQ(str, u8"C:'\\some/dir\\here/神鷹暢遊"); - Memory::Free(str); + const auto& str = ir->GetString("path", ""); + ASSERT_STREQ(str.c_str(), u8"C:'\\some/dir\\here/神鷹暢遊"); // go back a section ASSERT_EQ(ir->ReadSection("int"), true); ASSERT_EQ(ir->GetInt32("one", 42), 1); @@ -107,9 +106,8 @@ TEST_F(IniReaderTest, read_untrimmed) // there should only be data from the last section ASSERT_EQ(ir->ReadSection("section"), true); ASSERT_EQ(ir->GetBoolean("one", false), true); - const utf8* str = ir->GetCString("str", nullptr); - ASSERT_STREQ(str, " xxx "); - Memory::Free(str); + const auto& str = ir->GetString("str", ""); + ASSERT_STREQ(str.c_str(), " xxx "); ASSERT_EQ(ir->GetString("str", "yyy"), " xxx "); ASSERT_EQ(ir->GetString("nosuchthing", " yyy "), " yyy "); }