Alexandre Julliard : ntdll: Move user/system locale initialization to ntdll.

Alexandre Julliard julliard at winehq.org
Wed Mar 23 17:03:54 CDT 2022


Module: wine
Branch: master
Commit: 8ccb24b15162e15ad3bad993c8800365d02714fe
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=8ccb24b15162e15ad3bad993c8800365d02714fe

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Mar 23 11:02:19 2022 +0100

ntdll: Move user/system locale initialization to ntdll.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernelbase/locale.c | 34 ++--------------------------------
 dlls/ntdll/locale.c      | 24 +++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/dlls/kernelbase/locale.c b/dlls/kernelbase/locale.c
index 2f2154a0e7c..9ef8fbe8f44 100644
--- a/dlls/kernelbase/locale.c
+++ b/dlls/kernelbase/locale.c
@@ -699,27 +699,6 @@ done:
 }
 
 
-static LCID locale_to_lcid( WCHAR *win_name )
-{
-    WCHAR *p;
-    LCID lcid;
-
-    if (!RtlLocaleNameToLcid( win_name, &lcid, 0 )) return lcid;
-
-    /* try neutral name */
-    if ((p = wcsrchr( win_name, '-' )))
-    {
-        *p = 0;
-        if (!RtlLocaleNameToLcid( win_name, &lcid, 2 ))
-        {
-            if (SUBLANGID(lcid) == SUBLANG_NEUTRAL)
-                lcid = MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_DEFAULT );
-            return lcid;
-        }
-    }
-    return 0;
-}
-
 /***********************************************************************
  *		init_locale
  */
@@ -728,7 +707,7 @@ void init_locale(void)
     UINT ansi_cp = 0, oem_cp = 0;
     USHORT *ansi_ptr, *oem_ptr;
     void *sort_ptr;
-    LCID user_lcid = 0, system_lcid = 0;
+    LCID user_lcid;
     WCHAR bufferW[LOCALE_NAME_MAX_LENGTH];
     DYNAMIC_TIME_ZONE_INFORMATION timezone;
     GEOID geoid = GEOID_NOT_AVAILABLE;
@@ -738,16 +717,6 @@ void init_locale(void)
 
     if (GetEnvironmentVariableW( L"WINEUNIXCP", bufferW, ARRAY_SIZE(bufferW) ))
         unix_cp = wcstoul( bufferW, NULL, 10 );
-    if (GetEnvironmentVariableW( L"WINELOCALE", bufferW, ARRAY_SIZE(bufferW) ))
-        system_lcid = locale_to_lcid( bufferW );
-    if (GetEnvironmentVariableW( L"WINEUSERLOCALE", bufferW, ARRAY_SIZE(bufferW) ))
-        user_lcid = locale_to_lcid( bufferW );
-    if (!system_lcid) system_lcid = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT );
-    if (!user_lcid) user_lcid = system_lcid;
-
-    NtSetDefaultUILanguage( LANGIDFROMLCID(user_lcid) );
-    NtSetDefaultLocale( TRUE, user_lcid );
-    NtSetDefaultLocale( FALSE, system_lcid );
 
     kernel32_handle = GetModuleHandleW( L"kernel32.dll" );
 
@@ -806,6 +775,7 @@ void init_locale(void)
     /* Update registry contents if the user locale has changed.
      * This simulates the action of the Windows control panel. */
 
+    user_lcid = GetUserDefaultLCID();
     count = sizeof(bufferW);
     if (!RegQueryValueExW( intl_key, L"Locale", NULL, NULL, (BYTE *)bufferW, &count ))
     {
diff --git a/dlls/ntdll/locale.c b/dlls/ntdll/locale.c
index 158f068b03d..b4a14c0d68f 100644
--- a/dlls/ntdll/locale.c
+++ b/dlls/ntdll/locale.c
@@ -273,8 +273,10 @@ static const NLS_LOCALE_DATA *get_locale_data( UINT idx )
 
 void locale_init(void)
 {
+    WCHAR locale[LOCALE_NAME_MAX_LENGTH];
+    UNICODE_STRING name, value;
     LARGE_INTEGER unused;
-    LCID system_lcid;
+    LCID system_lcid, user_lcid = 0;
     NTSTATUS status;
     struct
     {
@@ -298,6 +300,26 @@ void locale_init(void)
     lcids_index = (const NLS_LOCALE_LCID_INDEX *)((char *)locale_table + locale_table->lcids_offset);
     lcnames_index = (const NLS_LOCALE_LCNAME_INDEX *)((char *)locale_table + locale_table->lcnames_offset);
     locale_strings = (const WCHAR *)((char *)locale_table + locale_table->strings_offset);
+
+    value.Buffer = locale;
+    value.MaximumLength = sizeof(locale);
+    RtlInitUnicodeString( &name, L"WINELOCALE" );
+    if (!RtlQueryEnvironmentVariable_U( NULL, &name, &value ))
+    {
+        const NLS_LOCALE_LCNAME_INDEX *entry = find_lcname_entry( locale );
+        if (entry) system_lcid = get_locale_data( entry->idx )->idefaultlanguage;
+    }
+    RtlInitUnicodeString( &name, L"WINEUSERLOCALE" );
+    if (!RtlQueryEnvironmentVariable_U( NULL, &name, &value ))
+    {
+        const NLS_LOCALE_LCNAME_INDEX *entry = find_lcname_entry( locale );
+        if (entry) user_lcid = get_locale_data( entry->idx )->idefaultlanguage;
+    }
+    if (!system_lcid) system_lcid = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
+    if (!user_lcid) user_lcid = system_lcid;
+    NtSetDefaultUILanguage( user_lcid );
+    NtSetDefaultLocale( TRUE, user_lcid );
+    NtSetDefaultLocale( FALSE, system_lcid );
 }
 
 




More information about the wine-cvs mailing list