From 3f22b60f94fea32b64d8aa82fd4dd95b280b56f3 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 8 Jan 2022 12:24:57 +0100 Subject: [PATCH] Upgrade platform_get_locale_currency() --- src/openrct2/config/Config.cpp | 2 +- src/openrct2/platform/Android.cpp | 5 --- src/openrct2/platform/Linux.cpp | 14 --------- src/openrct2/platform/Platform.Android.cpp | 5 +++ src/openrct2/platform/Platform.Linux.cpp | 14 +++++++++ src/openrct2/platform/Platform.Win32.cpp | 11 +++++++ src/openrct2/platform/Platform.macOS.mm | 9 ++++++ src/openrct2/platform/Platform2.h | 2 ++ src/openrct2/platform/Shared.cpp | 36 +++++++++++----------- src/openrct2/platform/Windows.cpp | 11 ------- src/openrct2/platform/macos.mm | 9 ------ src/openrct2/platform/platform.h | 2 -- 12 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 774511bbc6..d8a4dfd097 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -151,7 +151,7 @@ namespace Config model->autosave_amount = reader->GetInt32("autosave_amount", DEFAULT_NUM_AUTOSAVES_TO_KEEP); model->confirmation_prompt = reader->GetBoolean("confirmation_prompt", false); model->currency_format = reader->GetEnum( - "currency_format", platform_get_locale_currency(), Enum_Currency); + "currency_format", Platform::GetLocaleCurrency(), Enum_Currency); model->custom_currency_rate = reader->GetInt32("custom_currency_rate", 10); model->custom_currency_affix = reader->GetEnum( "custom_currency_affix", CurrencyAffix::Suffix, Enum_CurrencySymbolAffix); diff --git a/src/openrct2/platform/Android.cpp b/src/openrct2/platform/Android.cpp index 6f7124bf08..a3e93557d5 100644 --- a/src/openrct2/platform/Android.cpp +++ b/src/openrct2/platform/Android.cpp @@ -26,11 +26,6 @@ bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size) } # endif -CurrencyType platform_get_locale_currency() -{ - return platform_get_currency_value(NULL); -} - MeasurementFormat platform_get_locale_measurement_format() { return MeasurementFormat::Metric; diff --git a/src/openrct2/platform/Linux.cpp b/src/openrct2/platform/Linux.cpp index 47b4d3fdd7..0301ab8330 100644 --- a/src/openrct2/platform/Linux.cpp +++ b/src/openrct2/platform/Linux.cpp @@ -34,20 +34,6 @@ # include # include -CurrencyType platform_get_locale_currency() -{ - char* langstring = setlocale(LC_MONETARY, ""); - - if (langstring == nullptr) - { - return platform_get_currency_value(NULL); - } - - struct lconv* lc = localeconv(); - - return platform_get_currency_value(lc->int_curr_symbol); -} - MeasurementFormat platform_get_locale_measurement_format() { // LC_MEASUREMENT is GNU specific. diff --git a/src/openrct2/platform/Platform.Android.cpp b/src/openrct2/platform/Platform.Android.cpp index f332f43206..e626828354 100644 --- a/src/openrct2/platform/Platform.Android.cpp +++ b/src/openrct2/platform/Platform.Android.cpp @@ -60,6 +60,11 @@ namespace Platform { return LANGUAGE_ENGLISH_UK; } + + CurrencyType GetLocaleCurrency() + { + return Platform::GetCurrencyValue(NULL); + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform.Linux.cpp b/src/openrct2/platform/Platform.Linux.cpp index 839c0d1104..74dd7ecc4e 100644 --- a/src/openrct2/platform/Platform.Linux.cpp +++ b/src/openrct2/platform/Platform.Linux.cpp @@ -236,6 +236,20 @@ namespace Platform } return LANGUAGE_ENGLISH_UK; } + + CurrencyType GetLocaleCurrency() + { + char* langstring = setlocale(LC_MONETARY, ""); + + if (langstring == nullptr) + { + return Platform::GetCurrencyValue(NULL); + } + + struct lconv* lc = localeconv(); + + return Platform::GetCurrencyValue(lc->int_curr_symbol); + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index ddd02a8400..459b5d1da7 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -696,6 +696,17 @@ namespace Platform } return LANGUAGE_UNDEFINED; } + + CurrencyType GetLocaleCurrency() + { + CHAR currCode[4]; + if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, reinterpret_cast(&currCode), sizeof(currCode)) == 0) + { + return Platform::GetCurrencyValue(nullptr); + } + + return Platform::GetCurrencyValue(currCode); + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform.macOS.mm b/src/openrct2/platform/Platform.macOS.mm index d82984d1a0..dbd8060208 100644 --- a/src/openrct2/platform/Platform.macOS.mm +++ b/src/openrct2/platform/Platform.macOS.mm @@ -207,6 +207,15 @@ namespace Platform return LANGUAGE_ENGLISH_UK; } } + + CurrencyType GetLocaleCurrency() + { + @autoreleasepool + { + NSString* currencyCode = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencyCode]; + return Platform::GetCurrencyValue(currencyCode.UTF8String); + } + } } #endif diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index 7c9c0b8721..fc913ff659 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -43,6 +43,8 @@ namespace Platform std::string ResolveCasing(const std::string& path, bool fileExists); uint16_t GetLocaleLanguage(); + CurrencyType GetLocaleCurrency(); + CurrencyType GetCurrencyValue(const char* currCode); rct2_time GetTimeLocal(); rct2_date GetDateLocal(); diff --git a/src/openrct2/platform/Shared.cpp b/src/openrct2/platform/Shared.cpp index 7dc3e0b8b7..ee5f3ee8d5 100644 --- a/src/openrct2/platform/Shared.cpp +++ b/src/openrct2/platform/Shared.cpp @@ -70,6 +70,24 @@ static LARGE_INTEGER _entryTimestamp; namespace Platform { + CurrencyType GetCurrencyValue(const char* currCode) + { + if (currCode == nullptr || strlen(currCode) < 3) + { + return CurrencyType::Pounds; + } + + for (int32_t currency = 0; currency < EnumValue(CurrencyType::Count); ++currency) + { + if (strncmp(currCode, CurrencyDescriptors[currency].isoCode, 3) == 0) + { + return static_cast(currency); + } + } + + return CurrencyType::Pounds; + } + rct2_date GetDateLocal() { auto time = std::time(nullptr); @@ -242,24 +260,6 @@ void platform_sleep(uint32_t ms) #endif } -CurrencyType platform_get_currency_value(const char* currCode) -{ - if (currCode == nullptr || strlen(currCode) < 3) - { - return CurrencyType::Pounds; - } - - for (int32_t currency = 0; currency < EnumValue(CurrencyType::Count); ++currency) - { - if (strncmp(currCode, CurrencyDescriptors[currency].isoCode, 3) == 0) - { - return static_cast(currency); - } - } - - return CurrencyType::Pounds; -} - #ifndef __ANDROID__ float platform_get_default_scale() { diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index bf76477ee8..e9172e41e9 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -205,17 +205,6 @@ time_t platform_file_get_modified_time(const utf8* path) return 0; } -CurrencyType platform_get_locale_currency() -{ - CHAR currCode[4]; - if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, reinterpret_cast(&currCode), sizeof(currCode)) == 0) - { - return platform_get_currency_value(nullptr); - } - - return platform_get_currency_value(currCode); -} - MeasurementFormat platform_get_locale_measurement_format() { UINT measurement_system; diff --git a/src/openrct2/platform/macos.mm b/src/openrct2/platform/macos.mm index 7ae60532d5..64d7b14451 100644 --- a/src/openrct2/platform/macos.mm +++ b/src/openrct2/platform/macos.mm @@ -45,15 +45,6 @@ bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size) } # endif // NO_TTF -CurrencyType platform_get_locale_currency() -{ - @autoreleasepool - { - NSString* currencyCode = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencyCode]; - return platform_get_currency_value(currencyCode.UTF8String); - } -} - MeasurementFormat platform_get_locale_measurement_format() { @autoreleasepool diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index 14984bd440..42e7283772 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -105,8 +105,6 @@ void platform_sleep(uint32_t ms); void platform_get_user_directory(utf8* outPath, const utf8* subDirectory, size_t outSize); bool platform_open_common_file_dialog(utf8* outFilename, file_dialog_desc* desc, size_t outSize); utf8* platform_open_directory_browser(const utf8* title); -CurrencyType platform_get_locale_currency(); -CurrencyType platform_get_currency_value(const char* currencyCode); MeasurementFormat platform_get_locale_measurement_format(); TemperatureUnit platform_get_locale_temperature_format(); uint8_t platform_get_locale_date_format();