From e730f2a5b8d4088442dab5a902dc7932f22fd5c2 Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Tue, 19 Nov 2024 01:13:50 +0000 Subject: [PATCH] Refactoring --- far/exception_handler.cpp | 21 +++++++++++++-------- far/platform.clipboard.cpp | 15 ++++----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/far/exception_handler.cpp b/far/exception_handler.cpp index f114913b48..8a96c272b5 100644 --- a/far/exception_handler.cpp +++ b/far/exception_handler.cpp @@ -956,18 +956,23 @@ static handler_result ExcConsole(bool const CanContinue, string const& ReportLoc static string get_locale() { - wchar_t NameBuffer[LOCALE_NAME_MAX_LENGTH]; - string_view Name; - - if (size_t const SizeWith0 = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SNAME, NameBuffer, static_cast(std::size(NameBuffer)))) - Name = { NameBuffer, SizeWith0 - 1 }; - else - Name = L"Unknown"sv; + string LocaleName; + if (!os::get_locale_value(LOCALE_SYSTEM_DEFAULT, LOCALE_SNAME, LocaleName)) + { + string LangName, CountryName; + if ( + os::get_locale_value(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, LangName) && + os::get_locale_value(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, CountryName) + ) + LocaleName = concat(LangName, L'-', CountryName); + else + LocaleName = L"Unknown"sv; + } const auto LocaleId = GetUserDefaultLCID(); const auto LanguageId = LANGIDFROMLCID(LocaleId); return far::format(L"{} | LCID={:08X} (Lang={:04X} (Primary={:03X} Sub={:02X}) Sort={:X} SortVersion={:X}) | ANSI={} OEM={}"sv, - Name, + LocaleName, LocaleId, LanguageId, PRIMARYLANGID(LanguageId), diff --git a/far/platform.clipboard.cpp b/far/platform.clipboard.cpp index f4749a1ec4..2845a695b0 100644 --- a/far/platform.clipboard.cpp +++ b/far/platform.clipboard.cpp @@ -463,18 +463,11 @@ namespace os::clipboard static unsigned get_locale_codepage(LCID const Locale) { - unsigned Acp; - const int SizeInChars = sizeof(Acp) / sizeof(wchar_t); - - if (GetLocaleInfo( - Locale, - LOCALE_IDEFAULTANSICODEPAGE | - LOCALE_RETURN_NUMBER, - std::bit_cast(&Acp), - SizeInChars - ) != SizeInChars) + int Acp; + + if (!get_locale_value(Locale, LOCALE_IDEFAULTANSICODEPAGE, Acp)) { - LOGWARNING(L"GetLocaleInfo(LOCALE_IDEFAULTANSICODEPAGE): {}"sv, last_error()); + LOGWARNING(L"get_locale_value(LOCALE_IDEFAULTANSICODEPAGE): {}"sv, last_error()); return 0; }