private static string GetUserPreferredUILangs() { long pulNumLanguages = 0; int pcchLanguagesBuffer = 0; string str = ""; if (!NativeCultureResolver.SetThreadPreferredUILanguages(NativeCultureResolver.MUI_CONSOLE_FILTER, (StringBuilder)null, IntPtr.Zero) || !NativeCultureResolver.GetThreadPreferredUILanguages(NativeCultureResolver.MUI_LANGUAGE_NAME | NativeCultureResolver.MUI_MERGE_SYSTEM_FALLBACK | NativeCultureResolver.MUI_MERGE_USER_FALLBACK, out pulNumLanguages, (byte[])null, out pcchLanguagesBuffer)) { return(str); } byte[] numArray = new byte[pcchLanguagesBuffer * 2]; if (!NativeCultureResolver.GetThreadPreferredUILanguages(NativeCultureResolver.MUI_LANGUAGE_NAME | NativeCultureResolver.MUI_MERGE_SYSTEM_FALLBACK | NativeCultureResolver.MUI_MERGE_USER_FALLBACK, out pulNumLanguages, numArray, out pcchLanguagesBuffer)) { return(str); } try { return(Encoding.Unicode.GetString(numArray).Trim().ToLowerInvariant()); } catch (ArgumentNullException ex) { } catch (DecoderFallbackException ex) { } return(str); }
private static CultureInfo EmulateDownLevel() { // GetConsoleFallbackUICulture is not required. // This is retained in order not to break existing code. ushort langId = NativeCultureResolver.GetUserDefaultUILanguage(); CultureInfo ci = new CultureInfo((int)langId); return(ci.GetConsoleFallbackUICulture()); }
private static CultureInfo EmulateDownLevel() => new CultureInfo((int)NativeCultureResolver.GetUserDefaultUILanguage()).GetConsoleFallbackUICulture();