diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 42b05aab32..864538c5ca 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -7,8 +7,10 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include +#include "Config.h" + #include "../Context.h" +#include "../OpenRCT2.h" #include "../core/Console.hpp" #include "../core/File.h" #include "../core/FileStream.hpp" @@ -17,37 +19,34 @@ #include "../core/String.hpp" #include "../drawing/IDrawingEngine.h" #include "../interface/Window.h" +#include "../localisation/Currency.h" +#include "../localisation/Date.h" +#include "../localisation/Language.h" #include "../network/network.h" -#include "../OpenRCT2.h" +#include "../paint/VirtualFloor.h" +#include "../platform/platform.h" +#include "../scenario/Scenario.h" #include "../ui/UiContext.h" -#include "Config.h" #include "ConfigEnum.hpp" #include "IniReader.hpp" #include "IniWriter.hpp" -#include "../localisation/Currency.h" -#include "../localisation/Date.h" -#include "../localisation/Language.h" -#include "../paint/VirtualFloor.h" -#include "../platform/platform.h" -#include "../scenario/Scenario.h" +#include using namespace OpenRCT2; using namespace OpenRCT2::Ui; namespace Config { - #pragma region Enums +#pragma region Enums - static const auto Enum_MeasurementFormat = ConfigEnum( - { + static const auto Enum_MeasurementFormat = ConfigEnum({ ConfigEnumEntry("IMPERIAL", MEASUREMENT_FORMAT_IMPERIAL), ConfigEnumEntry("METRIC", MEASUREMENT_FORMAT_METRIC), ConfigEnumEntry("SI", MEASUREMENT_FORMAT_SI), }); - static const auto Enum_Currency = ConfigEnum( - { + static const auto Enum_Currency = ConfigEnum({ ConfigEnumEntry("GBP", CURRENCY_POUNDS), ConfigEnumEntry("USD", CURRENCY_DOLLARS), ConfigEnumEntry("FRF", CURRENCY_FRANC), @@ -67,42 +66,36 @@ namespace Config ConfigEnumEntry("CUSTOM", CURRENCY_CUSTOM), }); - static const auto Enum_CurrencySymbolAffix = ConfigEnum( - { + static const auto Enum_CurrencySymbolAffix = ConfigEnum({ ConfigEnumEntry("PREFIX", CURRENCY_PREFIX), ConfigEnumEntry("SUFFIX", CURRENCY_SUFFIX), }); - static const auto Enum_DateFormat = ConfigEnum( - { + static const auto Enum_DateFormat = ConfigEnum({ ConfigEnumEntry("DD/MM/YY", DATE_FORMAT_DAY_MONTH_YEAR), ConfigEnumEntry("MM/DD/YY", DATE_FORMAT_MONTH_DAY_YEAR), ConfigEnumEntry("YY/MM/DD", DATE_FORMAT_YEAR_MONTH_DAY), ConfigEnumEntry("YY/DD/MM", DATE_FORMAT_YEAR_DAY_MONTH), }); - static const auto Enum_DrawingEngine = ConfigEnum( - { + static const auto Enum_DrawingEngine = ConfigEnum({ ConfigEnumEntry("SOFTWARE", DRAWING_ENGINE_SOFTWARE), ConfigEnumEntry("SOFTWARE_HWD", DRAWING_ENGINE_SOFTWARE_WITH_HARDWARE_DISPLAY), ConfigEnumEntry("OPENGL", DRAWING_ENGINE_OPENGL), }); - static const auto Enum_Temperature = ConfigEnum( - { + static const auto Enum_Temperature = ConfigEnum({ ConfigEnumEntry("CELSIUS", TEMPERATURE_FORMAT_C), ConfigEnumEntry("FAHRENHEIT", TEMPERATURE_FORMAT_F), }); - static const auto Enum_ScaleQuality = ConfigEnum( - { + static const auto Enum_ScaleQuality = ConfigEnum({ ConfigEnumEntry("NEAREST_NEIGHBOUR", SCALE_QUALITY_NN), ConfigEnumEntry("LINEAR", SCALE_QUALITY_LINEAR), ConfigEnumEntry("SMOOTH_NEAREST_NEIGHBOUR", SCALE_QUALITY_SMOOTH_NN), }); - static const auto Enum_VirtualFloorStyle = ConfigEnum( - { + static const auto Enum_VirtualFloorStyle = ConfigEnum({ ConfigEnumEntry("OFF", VIRTUAL_FLOOR_STYLE_OFF), ConfigEnumEntry("CLEAR", VIRTUAL_FLOOR_STYLE_CLEAR), ConfigEnumEntry("GLASSY", VIRTUAL_FLOOR_STYLE_GLASSY), @@ -119,10 +112,10 @@ namespace Config return LanguagesDescriptors[value].locale; } - int32_t GetValue(const std::string &key, int32_t defaultValue) const override + int32_t GetValue(const std::string& key, int32_t defaultValue) const override { int32_t i = 0; - for (const auto &langDesc : LanguagesDescriptors) + for (const auto& langDesc : LanguagesDescriptors) { if (String::Equals(key.c_str(), langDesc.locale)) { @@ -134,9 +127,9 @@ namespace Config } } Enum_LanguageEnum; - #pragma endregion +#pragma endregion - static void ReadGeneral(IIniReader * reader) + static void ReadGeneral(IIniReader* reader) { if (reader->ReadSection("general")) { @@ -146,7 +139,8 @@ namespace Config model->confirmation_prompt = reader->GetBoolean("confirmation_prompt", false); model->currency_format = reader->GetEnum("currency_format", platform_get_locale_currency(), Enum_Currency); model->custom_currency_rate = reader->GetInt32("custom_currency_rate", 10); - model->custom_currency_affix = reader->GetEnum("custom_currency_affix", CURRENCY_SUFFIX, Enum_CurrencySymbolAffix); + model->custom_currency_affix + = reader->GetEnum("custom_currency_affix", CURRENCY_SUFFIX, Enum_CurrencySymbolAffix); model->custom_currency_symbol = reader->GetCString("custom_currency_symbol", "Ctm"); model->edge_scrolling = reader->GetBoolean("edge_scrolling", true); model->edge_scrolling_speed = reader->GetInt32("edge_scrolling_speed", 12); @@ -157,12 +151,14 @@ namespace Config model->rct2_path = reader->GetCString("game_path", nullptr); model->landscape_smoothing = reader->GetBoolean("landscape_smoothing", true); model->language = reader->GetEnum("language", platform_get_locale_language(), Enum_LanguageEnum); - model->measurement_format = reader->GetEnum("measurement_format", platform_get_locale_measurement_format(), Enum_MeasurementFormat); + model->measurement_format = reader->GetEnum( + "measurement_format", platform_get_locale_measurement_format(), Enum_MeasurementFormat); model->play_intro = reader->GetBoolean("play_intro", false); model->save_plugin_data = reader->GetBoolean("save_plugin_data", true); model->debugging_tools = reader->GetBoolean("debugging_tools", false); model->show_height_as_units = reader->GetBoolean("show_height_as_units", false); - model->temperature_format = reader->GetEnum("temperature_format", platform_get_locale_temperature_format(), Enum_Temperature); + model->temperature_format + = reader->GetEnum("temperature_format", platform_get_locale_temperature_format(), Enum_Temperature); model->window_height = reader->GetInt32("window_height", -1); model->window_snap_proximity = reader->GetInt32("window_snap_proximity", 5); model->window_width = reader->GetInt32("window_width", -1); @@ -170,7 +166,8 @@ namespace Config model->drawing_engine = reader->GetEnum("drawing_engine", DRAWING_ENGINE_SOFTWARE, Enum_DrawingEngine); model->uncap_fps = reader->GetBoolean("uncap_fps", false); model->use_vsync = reader->GetBoolean("use_vsync", true); - model->virtual_floor_style = reader->GetEnum("virtual_floor_style", VIRTUAL_FLOOR_STYLE_GLASSY, Enum_VirtualFloorStyle); + model->virtual_floor_style + = reader->GetEnum("virtual_floor_style", VIRTUAL_FLOOR_STYLE_GLASSY, Enum_VirtualFloorStyle); // Default config setting is false until ghost trains are implemented #4540 model->test_unfinished_tracks = reader->GetBoolean("test_unfinished_tracks", false); @@ -215,7 +212,7 @@ namespace Config } } - static void WriteGeneral(IIniWriter * writer) + static void WriteGeneral(IIniWriter* writer) { auto model = &gConfigGeneral; writer->WriteSection("general"); @@ -286,7 +283,7 @@ namespace Config writer->WriteEnum("virtual_floor_style", model->virtual_floor_style, Enum_VirtualFloorStyle); } - static void ReadInterface(IIniReader * reader) + static void ReadInterface(IIniReader* reader) { if (reader->ReadSection("interface")) { @@ -303,7 +300,7 @@ namespace Config } } - static void WriteInterface(IIniWriter * writer) + static void WriteInterface(IIniWriter* writer) { auto model = &gConfigInterface; writer->WriteSection("interface"); @@ -318,7 +315,7 @@ namespace Config writer->WriteInt32("object_selection_filter_flags", model->object_selection_filter_flags); } - static void ReadSound(IIniReader * reader) + static void ReadSound(IIniReader* reader) { if (reader->ReadSection("sound")) { @@ -334,7 +331,7 @@ namespace Config } } - static void WriteSound(IIniWriter * writer) + static void WriteSound(IIniWriter* writer) { auto model = &gConfigSound; writer->WriteSection("sound"); @@ -348,7 +345,7 @@ namespace Config writer->WriteString("audio_device", model->device); } - static void ReadNetwork(IIniReader * reader) + static void ReadNetwork(IIniReader* reader) { if (reader->ReadSection("network")) { @@ -390,7 +387,7 @@ namespace Config } } - static void WriteNetwork(IIniWriter * writer) + static void WriteNetwork(IIniWriter* writer) { auto model = &gConfigNetwork; writer->WriteSection("network"); @@ -414,7 +411,7 @@ namespace Config writer->WriteBoolean("pause_server_if_no_clients", model->pause_server_if_no_clients); } - static void ReadNotifications(IIniReader * reader) + static void ReadNotifications(IIniReader* reader) { if (reader->ReadSection("notifications")) { @@ -439,7 +436,7 @@ namespace Config } } - static void WriteNotifications(IIniWriter * writer) + static void WriteNotifications(IIniWriter* writer) { auto model = &gConfigNotifications; writer->WriteSection("notifications"); @@ -462,7 +459,7 @@ namespace Config writer->WriteBoolean("guest_died", model->guest_died); } - static void ReadTwitch(IIniReader * reader) + static void ReadTwitch(IIniReader* reader) { if (reader->ReadSection("twitch")) { @@ -477,7 +474,7 @@ namespace Config } } - static void WriteTwitch(IIniWriter * writer) + static void WriteTwitch(IIniWriter* writer) { auto model = &gConfigTwitch; writer->WriteSection("twitch"); @@ -490,7 +487,7 @@ namespace Config writer->WriteBoolean("news", model->enable_news); } - static void ReadFont(IIniReader * reader) + static void ReadFont(IIniReader* reader) { if (reader->ReadSection("font")) { @@ -512,7 +509,7 @@ namespace Config } } - static void WriteFont(IIniWriter * writer) + static void WriteFont(IIniWriter* writer) { auto model = &gConfigFonts; writer->WriteSection("font"); @@ -546,13 +543,13 @@ namespace Config ReadFont(reader.get()); return true; } - catch (const std::exception &) + catch (const std::exception&) { return false; } } - static bool ReadFile(const std::string &path) + static bool ReadFile(const std::string& path) { try { @@ -567,13 +564,13 @@ namespace Config ReadFont(reader.get()); return true; } - catch (const std::exception &) + catch (const std::exception&) { return false; } } - static bool WriteFile(const std::string &path) + static bool WriteFile(const std::string& path) { try { @@ -591,7 +588,7 @@ namespace Config WriteFont(writer.get()); return true; } - catch (const std::exception &ex) + catch (const std::exception& ex) { Console::WriteLine("Error saving to '%s'", path.c_str()); Console::WriteLine(ex.what()); @@ -608,8 +605,7 @@ namespace Config { log_verbose("config_find_rct2_path(...)"); - static constexpr const utf8 * searchLocations[] = - { + static constexpr const utf8* searchLocations[] = { R"(C:\GOG Games\RollerCoaster Tycoon 2 Triple Thrill Pack)", R"(C:\Program Files\Atari\RollerCoaster Tycoon 2)", R"(C:\Program Files\GalaxyClient\Games\RollerCoaster Tycoon 2 Triple Thrill Pack)", @@ -623,7 +619,7 @@ namespace Config R"(C:\Program Files (x86)\Steam\steamapps\common\Rollercoaster Tycoon 2)" }; - for (const utf8 * location : searchLocations) + for (const utf8* location : searchLocations) { if (platform_original_game_data_exists(location)) { @@ -649,13 +645,13 @@ namespace Config } } // namespace Config -GeneralConfiguration gConfigGeneral; -InterfaceConfiguration gConfigInterface; -SoundConfiguration gConfigSound; -TwitchConfiguration gConfigTwitch; -NetworkConfiguration gConfigNetwork; -NotificationConfiguration gConfigNotifications; -FontConfiguration gConfigFonts; +GeneralConfiguration gConfigGeneral; +InterfaceConfiguration gConfigInterface; +SoundConfiguration gConfigSound; +TwitchConfiguration gConfigTwitch; +NetworkConfiguration gConfigNetwork; +NotificationConfiguration gConfigNotifications; +FontConfiguration gConfigFonts; void config_set_defaults() { @@ -663,7 +659,7 @@ void config_set_defaults() Config::SetDefaults(); } -bool config_open(const utf8 * path) +bool config_open(const utf8* path) { if (!File::Exists(path)) { @@ -679,7 +675,7 @@ bool config_open(const utf8 * path) return result; } -bool config_save(const utf8 * path) +bool config_save(const utf8* path) { return Config::WriteFile(path); } @@ -712,7 +708,7 @@ void config_release() SafeFree(gConfigFonts.font_name); } -void config_get_default_path(utf8 * outPath, size_t size) +void config_get_default_path(utf8* outPath, size_t size) { platform_get_user_directory(outPath, nullptr, size); Path::Append(outPath, size, "config.ini"); @@ -745,7 +741,8 @@ bool config_find_or_browse_install_directory() while (true) { auto uiContext = GetContext()->GetUiContext(); - uiContext->ShowMessageBox("OpenRCT2 needs files from the original RollerCoaster Tycoon 2 in order to work. \nPlease select the directory where you installed RollerCoaster Tycoon 2."); + uiContext->ShowMessageBox("OpenRCT2 needs files from the original RollerCoaster Tycoon 2 in order to work. " + "\nPlease select the directory where you installed RollerCoaster Tycoon 2."); std::string installPath = uiContext->ShowDirectoryDialog("Please select your RCT2 directory"); if (installPath.empty()) @@ -761,11 +758,12 @@ bool config_find_or_browse_install_directory() return true; } - std::string message = String::StdFormat("Could not find %s" PATH_SEPARATOR "Data" PATH_SEPARATOR "g1.dat at this path", installPath.c_str()); + std::string message = String::StdFormat( + "Could not find %s" PATH_SEPARATOR "Data" PATH_SEPARATOR "g1.dat at this path", installPath.c_str()); uiContext->ShowMessageBox(message); } } - catch (const std::exception &ex) + catch (const std::exception& ex) { Console::Error::WriteLine(ex.what()); return false; @@ -773,4 +771,3 @@ bool config_find_or_browse_install_directory() } return true; } - diff --git a/src/openrct2/config/Config.h b/src/openrct2/config/Config.h index a5936b49f7..e937267a7a 100644 --- a/src/openrct2/config/Config.h +++ b/src/openrct2/config/Config.h @@ -14,179 +14,179 @@ struct GeneralConfiguration { // Paths - utf8 * rct1_path; - utf8 * rct2_path; + utf8* rct1_path; + utf8* rct2_path; // Display - int32_t default_display; - int32_t window_width; - int32_t window_height; - int32_t fullscreen_mode; - int32_t fullscreen_width; - int32_t fullscreen_height; - float window_scale; - int32_t drawing_engine; - int32_t scale_quality; - bool uncap_fps; - bool use_vsync; - bool show_fps; - bool minimize_fullscreen_focus_loss; + int32_t default_display; + int32_t window_width; + int32_t window_height; + int32_t fullscreen_mode; + int32_t fullscreen_width; + int32_t fullscreen_height; + float window_scale; + int32_t drawing_engine; + int32_t scale_quality; + bool uncap_fps; + bool use_vsync; + bool show_fps; + bool minimize_fullscreen_focus_loss; // Map rendering - bool landscape_smoothing; - bool always_show_gridlines; - int32_t virtual_floor_style; - bool day_night_cycle; - bool enable_light_fx; - bool upper_case_banners; - bool render_weather_effects; - bool render_weather_gloom; - bool disable_lightning_effect; - bool show_guest_purchases; + bool landscape_smoothing; + bool always_show_gridlines; + int32_t virtual_floor_style; + bool day_night_cycle; + bool enable_light_fx; + bool upper_case_banners; + bool render_weather_effects; + bool render_weather_gloom; + bool disable_lightning_effect; + bool show_guest_purchases; // Localisation - int32_t language; - int32_t measurement_format; - int32_t temperature_format; - bool show_height_as_units; - int32_t date_format; - int32_t currency_format; - int32_t custom_currency_rate; - int32_t custom_currency_affix; - utf8 * custom_currency_symbol; + int32_t language; + int32_t measurement_format; + int32_t temperature_format; + bool show_height_as_units; + int32_t date_format; + int32_t currency_format; + int32_t custom_currency_rate; + int32_t custom_currency_affix; + utf8* custom_currency_symbol; // Controls - bool edge_scrolling; - int32_t edge_scrolling_speed; - bool trap_cursor; - bool invert_viewport_drag; - bool zoom_to_cursor; + bool edge_scrolling; + int32_t edge_scrolling_speed; + bool trap_cursor; + bool invert_viewport_drag; + bool zoom_to_cursor; // Miscellaneous - bool play_intro; - int32_t window_snap_proximity; - bool allow_loading_with_incorrect_checksum; - bool save_plugin_data; - bool test_unfinished_tracks; - bool no_test_crashes; - bool debugging_tools; - int32_t autosave_frequency; - bool auto_staff_placement; - bool handymen_mow_default; - bool auto_open_shops; - int32_t default_inspection_interval; - int32_t window_limit; - int32_t scenario_select_mode; - bool scenario_unlocking_enabled; - bool scenario_hide_mega_park; - bool steam_overlay_pause; - bool show_real_names_of_guests; - bool allow_early_completion; + bool play_intro; + int32_t window_snap_proximity; + bool allow_loading_with_incorrect_checksum; + bool save_plugin_data; + bool test_unfinished_tracks; + bool no_test_crashes; + bool debugging_tools; + int32_t autosave_frequency; + bool auto_staff_placement; + bool handymen_mow_default; + bool auto_open_shops; + int32_t default_inspection_interval; + int32_t window_limit; + int32_t scenario_select_mode; + bool scenario_unlocking_enabled; + bool scenario_hide_mega_park; + bool steam_overlay_pause; + bool show_real_names_of_guests; + bool allow_early_completion; - bool confirmation_prompt; - int32_t load_save_sort; - utf8 * last_save_game_directory; - utf8 * last_save_landscape_directory; - utf8 * last_save_scenario_directory; - utf8 * last_save_track_directory; - utf8 * last_run_version; + bool confirmation_prompt; + int32_t load_save_sort; + utf8* last_save_game_directory; + utf8* last_save_landscape_directory; + utf8* last_save_scenario_directory; + utf8* last_save_track_directory; + utf8* last_run_version; }; struct InterfaceConfiguration { - bool toolbar_show_finances; - bool toolbar_show_research; - bool toolbar_show_cheats; - bool toolbar_show_news; - bool toolbar_show_mute; - bool console_small_font; - utf8 * current_theme_preset; - utf8 * current_title_sequence_preset; - int32_t object_selection_filter_flags; + bool toolbar_show_finances; + bool toolbar_show_research; + bool toolbar_show_cheats; + bool toolbar_show_news; + bool toolbar_show_mute; + bool console_small_font; + utf8* current_theme_preset; + utf8* current_title_sequence_preset; + int32_t object_selection_filter_flags; }; struct SoundConfiguration { - utf8 * device; - uint8_t master_volume; - uint8_t title_music; - bool sound_enabled; - uint8_t sound_volume; - bool ride_music_enabled; - uint8_t ride_music_volume; - bool audio_focus; + utf8* device; + uint8_t master_volume; + uint8_t title_music; + bool sound_enabled; + uint8_t sound_volume; + bool ride_music_enabled; + uint8_t ride_music_volume; + bool audio_focus; }; struct TwitchConfiguration { - utf8 * channel; - utf8 * api_url; - bool enable_follower_peep_names; - bool enable_follower_peep_tracking; - bool enable_chat_peep_names; - bool enable_chat_peep_tracking; - bool enable_news; + utf8* channel; + utf8* api_url; + bool enable_follower_peep_names; + bool enable_follower_peep_tracking; + bool enable_chat_peep_names; + bool enable_chat_peep_tracking; + bool enable_news; }; struct NetworkConfiguration { - utf8 * player_name; - int32_t default_port; - char * listen_address; - utf8 * default_password; - bool stay_connected; - bool advertise; - int32_t maxplayers; - utf8 * server_name; - utf8 * server_description; - utf8 * server_greeting; - utf8 * master_server_url; - utf8 * provider_name; - utf8 * provider_email; - utf8 * provider_website; - bool known_keys_only; - bool log_chat; - bool log_server_actions; - bool pause_server_if_no_clients; + utf8* player_name; + int32_t default_port; + char* listen_address; + utf8* default_password; + bool stay_connected; + bool advertise; + int32_t maxplayers; + utf8* server_name; + utf8* server_description; + utf8* server_greeting; + utf8* master_server_url; + utf8* provider_name; + utf8* provider_email; + utf8* provider_website; + bool known_keys_only; + bool log_chat; + bool log_server_actions; + bool pause_server_if_no_clients; }; struct NotificationConfiguration { - bool park_award; - bool park_marketing_campaign_finished; - bool park_warnings; - bool park_rating_warnings; - bool ride_broken_down; - bool ride_crashed; - bool ride_warnings; - bool ride_researched; - bool guest_warnings; - bool guest_lost; - bool guest_left_park; - bool guest_queuing_for_ride; - bool guest_on_ride; - bool guest_left_ride; - bool guest_bought_item; - bool guest_used_facility; - bool guest_died; + bool park_award; + bool park_marketing_campaign_finished; + bool park_warnings; + bool park_rating_warnings; + bool ride_broken_down; + bool ride_crashed; + bool ride_warnings; + bool ride_researched; + bool guest_warnings; + bool guest_lost; + bool guest_left_park; + bool guest_queuing_for_ride; + bool guest_on_ride; + bool guest_left_ride; + bool guest_bought_item; + bool guest_used_facility; + bool guest_died; }; struct FontConfiguration { - utf8 * file_name; - utf8 * font_name; - int32_t x_offset; - int32_t y_offset; - int32_t size_tiny; - int32_t size_small; - int32_t size_medium; - int32_t size_big; - int32_t height_tiny; - int32_t height_small; - int32_t height_medium; - int32_t height_big; - bool enable_hinting; - int32_t hinting_threshold; + utf8* file_name; + utf8* font_name; + int32_t x_offset; + int32_t y_offset; + int32_t size_tiny; + int32_t size_small; + int32_t size_medium; + int32_t size_big; + int32_t height_tiny; + int32_t height_small; + int32_t height_medium; + int32_t height_big; + bool enable_hinting; + int32_t hinting_threshold; }; enum SORT @@ -217,17 +217,17 @@ enum MEASUREMENT_FORMAT MEASUREMENT_FORMAT_SI }; -extern GeneralConfiguration gConfigGeneral; -extern InterfaceConfiguration gConfigInterface; -extern SoundConfiguration gConfigSound; -extern TwitchConfiguration gConfigTwitch; -extern NetworkConfiguration gConfigNetwork; -extern NotificationConfiguration gConfigNotifications; -extern FontConfiguration gConfigFonts; +extern GeneralConfiguration gConfigGeneral; +extern InterfaceConfiguration gConfigInterface; +extern SoundConfiguration gConfigSound; +extern TwitchConfiguration gConfigTwitch; +extern NetworkConfiguration gConfigNetwork; +extern NotificationConfiguration gConfigNotifications; +extern FontConfiguration gConfigFonts; -bool config_open(const utf8 * path); -bool config_save(const utf8 * path); -void config_get_default_path(utf8 *outPath, size_t size); +bool config_open(const utf8* path); +bool config_save(const utf8* path); +void config_get_default_path(utf8* outPath, size_t size); void config_set_defaults(); void config_release(); bool config_save_default(); diff --git a/src/openrct2/config/ConfigEnum.hpp b/src/openrct2/config/ConfigEnum.hpp index dc4b8ab60d..48305a2aaf 100644 --- a/src/openrct2/config/ConfigEnum.hpp +++ b/src/openrct2/config/ConfigEnum.hpp @@ -9,34 +9,32 @@ #pragma once +#include "../core/String.hpp" + #include #include #include -#include "../core/String.hpp" -template -struct ConfigEnumEntry +template struct ConfigEnumEntry { std::string Key; - T Value; + T Value; ConfigEnumEntry(std::string key, T value) - : Key(std::move(key)), - Value(value) + : Key(std::move(key)) + , Value(value) { } }; -template -interface IConfigEnum +template interface IConfigEnum { virtual ~IConfigEnum() = default; virtual std::string GetName(T value) const abstract; - virtual T GetValue(const std::string &key, T defaultValue) const abstract; + virtual T GetValue(const std::string& key, T defaultValue) const abstract; }; -template -class ConfigEnum final : public IConfigEnum +template class ConfigEnum final : public IConfigEnum { private: const std::vector> _entries; @@ -49,7 +47,7 @@ public: std::string GetName(T value) const override { - for (const auto &entry : _entries) + for (const auto& entry : _entries) { if (entry.Value == value) { @@ -59,9 +57,9 @@ public: return std::string(); } - T GetValue(const std::string &key, T defaultValue) const override + T GetValue(const std::string& key, T defaultValue) const override { - for (const auto &entry : _entries) + for (const auto& entry : _entries) { if (String::Equals(entry.Key, key, true)) { diff --git a/src/openrct2/config/IniReader.cpp b/src/openrct2/config/IniReader.cpp index 5dc2233c47..2b187e4e9c 100644 --- a/src/openrct2/config/IniReader.cpp +++ b/src/openrct2/config/IniReader.cpp @@ -7,29 +7,31 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "IniReader.hpp" + +#include "../common.h" +#include "../core/IStream.hpp" +#include "../core/String.hpp" +#include "../core/StringBuilder.hpp" + #include #include #include #include #include -#include "../common.h" -#include "../core/IStream.hpp" -#include "../core/String.hpp" -#include "../core/StringBuilder.hpp" -#include "IniReader.hpp" /** * Simple tuple (start, length) representing a text span in a buffer. */ struct Span { - size_t Start = 0; - size_t Length = 0; + size_t Start = 0; + size_t Length = 0; Span() = default; Span(size_t start, size_t length) - : Start(start), - Length(length) + : Start(start) + , Length(length) { } }; @@ -39,28 +41,28 @@ struct Span */ struct LineRange { - size_t Start = 0; - size_t End = 0; + size_t Start = 0; + size_t End = 0; LineRange() = default; LineRange(size_t start, size_t end) - : Start(start), - End(end) + : Start(start) + , End(end) { } }; struct StringIHash { - std::size_t operator()(const std::string &s) const + std::size_t operator()(const std::string& s) const { using Traits = std::char_traits; std::size_t seed = 0; - for (const char &c : s) + for (const char& c : s) { const Traits::int_type value = std::toupper(Traits::to_int_type(c)); // Simple Hash Combine as used by Boost.Functional/Hash - seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2); + seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2); } return seed; } @@ -68,16 +70,18 @@ struct StringIHash struct StringICmp { - bool operator()(const std::string &a, const std::string &b) const + bool operator()(const std::string& a, const std::string& b) const { using Traits = std::char_traits; - if (a.size() != b.size()) return false; + if (a.size() != b.size()) + return false; const char *s1 = a.data(), *s2 = b.data(); for (std::size_t i = a.size(); i > 0; --i, ++s1, ++s2) { const int c1 = std::toupper(Traits::to_int_type(*s1)); const int c2 = std::toupper(Traits::to_int_type(*s2)); - if (c1 != c2) return false; + if (c1 != c2) + return false; } return true; } @@ -86,13 +90,13 @@ struct StringICmp class IniReader final : public IIniReader { private: - std::vector _buffer; - std::vector _lines; - std::unordered_map _sections; - std::unordered_map _values; + std::vector _buffer; + std::vector _lines; + std::unordered_map _sections; + std::unordered_map _values; public: - explicit IniReader(IStream * stream) + explicit IniReader(IStream* stream) { uint64_t length = stream->GetLength() - stream->GetPosition(); _buffer.resize(length); @@ -111,7 +115,7 @@ public: ParseSections(); } - bool ReadSection(const std::string &name) override + bool ReadSection(const std::string& name) override { auto it = _sections.find(name); if (it == _sections.end()) @@ -123,7 +127,7 @@ public: return true; } - bool GetBoolean(const std::string &name, bool defaultValue) const override + bool GetBoolean(const std::string& name, bool defaultValue) const override { bool result = defaultValue; std::string value; @@ -134,7 +138,7 @@ public: return result; } - int32_t GetInt32(const std::string &name, int32_t defaultValue) const override + int32_t GetInt32(const std::string& name, int32_t defaultValue) const override { int32_t result = defaultValue; std::string value; @@ -144,14 +148,14 @@ public: { result = std::stoi(value); } - catch (const std::exception &) + catch (const std::exception&) { } } return result; } - float GetFloat(const std::string &name, float defaultValue) const override + float GetFloat(const std::string& name, float defaultValue) const override { float result = defaultValue; std::string value; @@ -161,14 +165,14 @@ public: { result = std::stof(value); } - catch (const std::exception &) + catch (const std::exception&) { } } return result; } - std::string GetString(const std::string &name, const std::string &defaultValue) const override + std::string GetString(const std::string& name, const std::string& defaultValue) const override { std::string result; if (!TryGetString(name, &result)) @@ -178,7 +182,7 @@ public: return result; } - bool TryGetString(const std::string &name, std::string * outValue) const override + bool TryGetString(const std::string& name, std::string* outValue) const override { auto it = _values.find(name); if (it == _values.end()) @@ -197,8 +201,8 @@ private: { return; } - utf8 * file = (utf8 *)_buffer.data(); - utf8 * content = String::SkipBOM(file); + utf8* file = (utf8*)_buffer.data(); + utf8* content = String::SkipBOM(file); if (file != content) { size_t skipLength = content - file; @@ -295,7 +299,7 @@ private: _values[key] = value; } - std::string TrimComment(const std::string &s) + std::string TrimComment(const std::string& s) { char inQuotes = 0; bool escaped = false; @@ -319,7 +323,7 @@ private: return s; } - std::string UnquoteValue(const std::string &s) + std::string UnquoteValue(const std::string& s) { std::string result = s; size_t length = s.size(); @@ -333,7 +337,7 @@ private: return result; } - std::string UnescapeValue(const std::string &s) + std::string UnescapeValue(const std::string& s) { if (s.find_first_of('\\') == std::string::npos) { @@ -359,7 +363,7 @@ private: std::string GetLine(size_t index) { - utf8 * szBuffer = (utf8 *)_buffer.data(); + utf8* szBuffer = (utf8*)_buffer.data(); auto span = _lines[index]; auto line = std::string(szBuffer + span.Start, span.Length); return line; @@ -400,7 +404,7 @@ public: } }; -utf8 * IIniReader::GetCString(const std::string &name, const utf8 * defaultValue) const +utf8* IIniReader::GetCString(const std::string& name, const utf8* defaultValue) const { std::string szValue; if (!TryGetString(name, &szValue)) @@ -411,12 +415,12 @@ utf8 * IIniReader::GetCString(const std::string &name, const utf8 * defaultValue return String::Duplicate(szValue.c_str()); } -IIniReader * CreateIniReader(IStream * stream) +IIniReader* CreateIniReader(IStream* stream) { return new IniReader(stream); } -IIniReader * CreateDefaultIniReader() +IIniReader* CreateDefaultIniReader() { return new DefaultIniReader(); } diff --git a/src/openrct2/config/IniReader.hpp b/src/openrct2/config/IniReader.hpp index c6e710047d..20b3a6ae24 100644 --- a/src/openrct2/config/IniReader.hpp +++ b/src/openrct2/config/IniReader.hpp @@ -9,26 +9,26 @@ #pragma once -#include #include "../common.h" +#include + interface IStream; -template struct IConfigEnum; +template struct IConfigEnum; interface IIniReader { virtual ~IIniReader() = default; - virtual bool ReadSection(const std::string &name) abstract; + virtual bool ReadSection(const std::string& name) abstract; - virtual bool GetBoolean(const std::string &name, bool defaultValue) const abstract; - virtual int32_t GetInt32(const std::string &name, int32_t defaultValue) const abstract; - virtual float GetFloat(const std::string &name, float defaultValue) const abstract; - virtual std::string GetString(const std::string &name, const std::string &defaultValue) const abstract; - virtual bool TryGetString(const std::string &name, std::string * outValue) const abstract; + virtual bool GetBoolean(const std::string& name, bool defaultValue) const abstract; + virtual int32_t GetInt32(const std::string& name, int32_t defaultValue) const abstract; + virtual float GetFloat(const std::string& name, float defaultValue) const abstract; + virtual std::string GetString(const std::string& name, const std::string& defaultValue) const abstract; + virtual bool TryGetString(const std::string& name, std::string* outValue) const abstract; - template - T GetEnum(const std::string &name, T defaultValue, const IConfigEnum &configEnum) const + template T GetEnum(const std::string& name, T defaultValue, const IConfigEnum& configEnum) const { std::string szValue; if (!TryGetString(name, &szValue)) @@ -39,8 +39,8 @@ interface IIniReader return configEnum.GetValue(szValue, defaultValue); } - utf8 * GetCString(const std::string &name, const utf8 * defaultValue) const; + utf8* GetCString(const std::string& name, const utf8* defaultValue) const; }; -IIniReader * CreateIniReader(IStream * stream); -IIniReader * CreateDefaultIniReader(); +IIniReader* CreateIniReader(IStream* stream); +IIniReader* CreateDefaultIniReader(); diff --git a/src/openrct2/config/IniWriter.cpp b/src/openrct2/config/IniWriter.cpp index 007d2dabdb..7f01e6429a 100644 --- a/src/openrct2/config/IniWriter.cpp +++ b/src/openrct2/config/IniWriter.cpp @@ -7,26 +7,27 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include -#include "../core/IStream.hpp" -#include "../core/String.hpp" #include "IniWriter.hpp" +#include "../core/IStream.hpp" +#include "../core/String.hpp" #include "../platform/platform.h" +#include + class IniWriter final : public IIniWriter { private: - IStream * _stream; - bool _firstSection = true; + IStream* _stream; + bool _firstSection = true; public: - explicit IniWriter(IStream * stream) + explicit IniWriter(IStream* stream) : _stream(stream) { } - void WriteSection(const std::string &name) override + void WriteSection(const std::string& name) override { if (!_firstSection) { @@ -37,22 +38,22 @@ public: WriteLine("[" + name + "]"); } - void WriteBoolean(const std::string &name, bool value) override + void WriteBoolean(const std::string& name, bool value) override { WriteProperty(name, value ? "true" : "false"); } - void WriteInt32(const std::string &name, int32_t value) override + void WriteInt32(const std::string& name, int32_t value) override { WriteProperty(name, std::to_string(value)); } - void WriteFloat(const std::string &name, float value) override + void WriteFloat(const std::string& name, float value) override { WriteProperty(name, std::to_string(value)); } - void WriteString(const std::string &name, const std::string &value) override + void WriteString(const std::string& name, const std::string& value) override { std::ostringstream buffer; buffer << '"'; @@ -69,13 +70,13 @@ public: WriteProperty(name, buffer.str()); } - void WriteEnum(const std::string &name, const std::string &key) override + void WriteEnum(const std::string& name, const std::string& key) override { WriteProperty(name, key); } private: - void WriteProperty(const std::string &name, const std::string &value) + void WriteProperty(const std::string& name, const std::string& value) { WriteLine(name + " = " + value); } @@ -85,19 +86,19 @@ private: _stream->Write(PLATFORM_NEWLINE, String::SizeOf(PLATFORM_NEWLINE)); } - void WriteLine(const std::string &line) + void WriteLine(const std::string& line) { _stream->Write(line.c_str(), line.size()); WriteLine(); } }; -void IIniWriter::WriteString(const std::string &name, const utf8 * value) +void IIniWriter::WriteString(const std::string& name, const utf8* value) { WriteString(name, String::ToStd(value)); } -IIniWriter * CreateIniWriter(IStream * stream) +IIniWriter* CreateIniWriter(IStream* stream) { return new IniWriter(stream); } diff --git a/src/openrct2/config/IniWriter.hpp b/src/openrct2/config/IniWriter.hpp index f66a7bd2b7..c00a8308fd 100644 --- a/src/openrct2/config/IniWriter.hpp +++ b/src/openrct2/config/IniWriter.hpp @@ -9,26 +9,26 @@ #pragma once -#include #include "../common.h" +#include + interface IStream; -template struct IConfigEnum; +template struct IConfigEnum; interface IIniWriter { virtual ~IIniWriter() = default; - virtual void WriteSection(const std::string &name) abstract; + virtual void WriteSection(const std::string& name) abstract; - virtual void WriteBoolean(const std::string &name, bool value) abstract; - virtual void WriteInt32(const std::string &name, int32_t value) abstract; - virtual void WriteFloat(const std::string &name, float value) abstract; - virtual void WriteString(const std::string &name, const std::string &value) abstract; - virtual void WriteEnum(const std::string &name, const std::string &key) abstract; + virtual void WriteBoolean(const std::string& name, bool value) abstract; + virtual void WriteInt32(const std::string& name, int32_t value) abstract; + virtual void WriteFloat(const std::string& name, float value) abstract; + virtual void WriteString(const std::string& name, const std::string& value) abstract; + virtual void WriteEnum(const std::string& name, const std::string& key) abstract; - template - void WriteEnum(const std::string &name, T value, const IConfigEnum &configEnum) + template void WriteEnum(const std::string& name, T value, const IConfigEnum& configEnum) { std::string key = configEnum.GetName(value); if (key.empty()) @@ -41,7 +41,7 @@ interface IIniWriter } } - void WriteString(const std::string &name, const utf8 * value); + void WriteString(const std::string& name, const utf8* value); }; -IIniWriter * CreateIniWriter(IStream * stream); +IIniWriter* CreateIniWriter(IStream* stream);