Core: use more recent api in ComputeDefaultCountryCode on Windows

Co-authored-by: Shawn Hoffman <godisgovernment@gmail.com>
This commit is contained in:
iwubcode
2025-03-16 00:29:34 -05:00
parent 373a1a5dc0
commit 452cd1c261

View File

@ -90,13 +90,15 @@ static std::string ComputeDefaultCountryCode()
#ifdef _WIN32 #ifdef _WIN32
// Windows codepath: Check the regional information. // Windows codepath: Check the regional information.
// More likely to match the user's physical location than locales are. // More likely to match the user's physical location than locales are.
// TODO: Can we use GetUserDefaultGeoName? (It was added in a Windows 10 update) const int buffer_size = GetUserDefaultGeoName(nullptr, 0);
GEOID geo = GetUserGeoID(GEOCLASS_NATION); if (buffer_size == 3)
const int buffer_size = GetGeoInfoW(geo, GEO_ISO2, nullptr, 0, 0); {
std::vector<wchar_t> buffer(buffer_size); std::wstring buffer(buffer_size, L'\0');
const int result = GetGeoInfoW(geo, GEO_ISO2, buffer.data(), buffer_size, 0); const int result = GetUserDefaultGeoName(buffer.data(), buffer_size);
if (result != 0) buffer.resize(2);
return TStrToUTF8(buffer.data()); if (result > 0)
return WStringToUTF8(buffer);
}
#endif #endif
// Generic codepath: Check the locales. // Generic codepath: Check the locales.