| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
| 2 | |
| 3 #include "PluginSystem.h" | 2 #include "PluginSystem.h" |
| 4 #include "PluginClient.h" | 3 #include "PluginClient.h" |
| 4 #include <array> | |
| 5 | 5 |
| 6 std::wstring GetBrowserLanguage() | 6 std::wstring GetBrowserLanguage() |
| 7 { | 7 { |
| 8 LANGID lcid = GetUserDefaultLangID(); | 8 LANGID lcid = GetUserDefaultLangID(); |
| 9 wchar_t language[128]; | |
| 10 memset(language, 0, sizeof(language)); | |
| 11 wchar_t country[128]; | |
| 12 memset(language, 0, sizeof(country)); | |
| 13 | |
| 14 std::wstring lang; | 9 std::wstring lang; |
| 15 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, language, 127); | 10 // According to http://msdn.microsoft.com/en-us/library/windows/desktop/dd3738 48(v=vs.85).aspx |
| 16 if (res == 0) | 11 // The maximum number of characters allowed for this string is nine, including a terminating null character. |
| 17 { | 12 { |
| 18 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO _BROWSER_LANGUAGE, "System::GetBrowserLang - Failed"); | 13 std::array<wchar_t, 9> localeLanguage; |
|
Eric
2014/10/09 13:49:57
I think that page means that you have nine charact
| |
| 19 } | 14 localeLanguage.fill(L'\0'); |
| 20 else | 15 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, localeLanguage.data() , localeLanguage.size()); |
| 21 { | 16 if (res == 0) |
| 22 lang += language; | 17 { |
| 18 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed"); | |
| 19 } | |
| 20 else | |
| 21 { | |
| 22 lang += localeLanguage.data(); | |
| 23 } | |
| 23 } | 24 } |
| 24 lang += L"-"; | 25 lang += L"-"; |
| 25 res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, country, 127); | |
| 26 if (res == 0) | |
| 27 { | 26 { |
| 28 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO _BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country"); | 27 std::array<wchar_t, 9> localeCountry; |
| 29 } | 28 localeCountry.fill(L'\0'); |
|
Eric
2014/10/09 13:49:57
Also here.
| |
| 30 else | 29 int res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, localeCountry.data() , localeCountry.size()); |
| 31 { | 30 if (res == 0) |
| 32 lang += country; | 31 { |
| 32 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country"); | |
| 33 } | |
| 34 else | |
| 35 { | |
| 36 lang += localeCountry.data(); | |
| 37 } | |
| 33 } | 38 } |
| 34 return lang; | 39 return lang; |
| 35 } | 40 } |
| OLD | NEW |