[glib/win32-enhance-gtimezone: 6/9] glib/gtimezone.c: Use RegLoadMUIStringW() to query Std/Dlt strings



commit 2e5d3aa91114ebc930393b74ff5a1af474c745bb
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Jun 20 11:05:19 2019 +0800

    glib/gtimezone.c: Use RegLoadMUIStringW() to query Std/Dlt strings
    
    The existing method of using RegQueryValueExW() to query the Std/Dlt
    strings can only retrive the localized versions of those strings, so
    that means they will vary by the language version of Windows.  Instead,
    use RegQueryValueExW() only as a fallback when RegLoadMUIStringW() fails,
    as RegLoadMUIStringW() can query for the Std and Dlt strings in
    whatever language we need by setting the locale stuff programatically on
    the fly.

 glib/gtimezone.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/glib/gtimezone.c b/glib/gtimezone.c
index 751a925a1..4cc2d8d7f 100644
--- a/glib/gtimezone.c
+++ b/glib/gtimezone.c
@@ -729,8 +729,12 @@ rules_from_windows_time_zone (const gchar   *identifier,
   DWORD size;
   guint rules_num = 0;
   RegTZI regtzi, regtzi_prev;
+  WCHAR winsyspath[MAX_PATH];
   gunichar2 *subkey_w, *subkey_dynamic_w;
 
+  if (GetSystemDirectoryW (winsyspath, MAX_PATH) == 0)
+    return 0;
+
   g_assert (out_identifier != NULL);
   g_assert (rules != NULL);
 
@@ -758,18 +762,33 @@ rules_from_windows_time_zone (const gchar   *identifier,
 
   if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, subkey_w, 0,
                      KEY_QUERY_VALUE, &key) != ERROR_SUCCESS)
-      return 0;
+      goto utf16_conv_failed;
 
   size = sizeof tzi.StandardName;
-  if (RegQueryValueExW (key, L"Std", NULL, NULL,
-                        (LPBYTE)&(tzi.StandardName), &size) != ERROR_SUCCESS)
-    goto registry_failed;
+
+  /* use RegLoadMUIStringW() to query MUI_Std from the registry if possible, otherwise
+     fallback to querying Std */
+  if (RegLoadMUIStringW (key, L"MUI_Std", tzi.StandardName,
+                         size, &size, 0, winsyspath) != ERROR_SUCCESS)
+    {
+      size = sizeof tzi.StandardName;
+      if (RegQueryValueExW (key, L"Std", NULL, NULL,
+                            (LPBYTE)&(tzi.StandardName), &size) != ERROR_SUCCESS)
+        goto registry_failed;
+    }
 
   size = sizeof tzi.DaylightName;
 
-  if (RegQueryValueExW (key, L"Dlt", NULL, NULL,
-                        (LPBYTE)&(tzi.DaylightName), &size) != ERROR_SUCCESS)
-    goto registry_failed;
+  /* use RegLoadMUIStringW() to query MUI_Dlt from the registry if possible, otherwise
+     fallback to querying Dlt */
+  if (RegLoadMUIStringW (key, L"MUI_Dlt", tzi.DaylightName,
+                         size, &size, 0, winsyspath) != ERROR_SUCCESS)
+    {
+      size = sizeof tzi.DaylightName;
+      if (RegQueryValueExW (key, L"Dlt", NULL, NULL,
+                            (LPBYTE)&(tzi.DaylightName), &size) != ERROR_SUCCESS)
+        goto registry_failed;
+    }
 
   RegCloseKey (key);
   if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, subkey_dynamic_w, 0,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]