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



commit 11d922d56bc13ca4962bda2c29efe7edc874499f
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 88c676162..14e04ccd8 100644
--- a/glib/gtimezone.c
+++ b/glib/gtimezone.c
@@ -727,8 +727,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);
 
@@ -756,18 +760,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]