1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#if ENABLE_WINRT
using Internal.Runtime.Augments;
#endif
namespace System.Globalization
{
public partial class CultureInfo : IFormatProvider
{
/// <summary>
/// Gets the default user culture from WinRT, if available.
/// </summary>
/// <remarks>
/// This method may return null, if there is no default user culture or if WinRT isn't available.
/// </remarks>
private static CultureInfo GetUserDefaultCultureCacheOverride()
{
#if ENABLE_WINRT
WinRTInteropCallbacks callbacks = WinRTInterop.UnsafeCallbacks;
if (callbacks != null && callbacks.IsAppxModel())
{
return (CultureInfo)callbacks.GetUserDefaultCulture();
}
#endif
return null;
}
internal static CultureInfo GetUserDefaultCulture()
{
if (GlobalizationMode.Invariant)
return CultureInfo.InvariantCulture;
const uint LOCALE_SNAME = 0x0000005c;
const string LOCALE_NAME_USER_DEFAULT = null;
const string LOCALE_NAME_SYSTEM_DEFAULT = "!x-sys-default-locale";
string strDefault = CultureData.GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SNAME);
if (strDefault == null)
{
strDefault = CultureData.GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SNAME);
if (strDefault == null)
{
// If system default doesn't work, use invariant
return CultureInfo.InvariantCulture;
}
}
CultureInfo temp = GetCultureByName(strDefault, true);
temp._isReadOnly = true;
return temp;
}
private static CultureInfo GetUserDefaultUICulture()
{
#if !ENABLE_WINRT
if (GlobalizationMode.Invariant)
return CultureInfo.InvariantCulture;
const uint MUI_LANGUAGE_NAME = 0x8; // Use ISO language (culture) name convention
uint langCount = 0;
uint bufLen = 0;
if (Interop.Kernel32.GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, out langCount, null, ref bufLen))
{
char[] languages = new char[bufLen];
if (Interop.Kernel32.GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, out langCount, languages, ref bufLen))
{
int index = 0;
while (languages[index] != (char)0 && index < languages.Length)
{
index++;
}
CultureInfo temp = GetCultureByName(new string(languages, 0, index), true);
temp._isReadOnly = true;
return temp;
}
}
#endif
return s_userDefaultCulture ?? InitializeUserDefaultCulture();
}
}
}
|