[TIMEDATE]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 28 May 2016 00:12:02 +0000 (00:12 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 28 May 2016 00:12:02 +0000 (00:12 +0000)
Fixes and improvements to datetime CPL applet.
Patch by Carlo Bramini.
Replaced the original RegLocalQuery() by QueryTimezoneData() to simplify the error handling.
Modification by Eric Kohl.
CORE-11284 #resolve #comment Thanks a lot!

svn path=/trunk/; revision=71433

reactos/dll/cpl/timedate/timezone.c

index 8276c0e..d2a1276 100644 (file)
@@ -24,11 +24,10 @@ typedef struct _TIMEZONE_ENTRY
 {
     struct _TIMEZONE_ENTRY *Prev;
     struct _TIMEZONE_ENTRY *Next;
-    WCHAR Description[64];   /* 'Display' */
+    WCHAR Description[128];  /* 'Display' */
     WCHAR StandardName[33];  /* 'Std' */
     WCHAR DaylightName[33];  /* 'Dlt' */
     TZ_INFO TimezoneInfo;    /* 'TZI' */
-    ULONG Index;             /* 'Index ' */
 } TIMEZONE_ENTRY, *PTIMEZONE_ENTRY;
 
 
@@ -38,17 +37,26 @@ static int cxSource, cySource;
 PTIMEZONE_ENTRY TimeZoneListHead = NULL;
 PTIMEZONE_ENTRY TimeZoneListTail = NULL;
 
-static PTIMEZONE_ENTRY
-GetLargerTimeZoneEntry(DWORD Index)
+static
+PTIMEZONE_ENTRY
+GetLargerTimeZoneEntry(
+    LONG Bias,
+    LPWSTR lpDescription)
 {
     PTIMEZONE_ENTRY Entry;
 
     Entry = TimeZoneListHead;
     while (Entry != NULL)
     {
-        if (Entry->Index >= Index)
+        if (Entry->TimezoneInfo.Bias > Bias)
             return Entry;
 
+        if (Entry->TimezoneInfo.Bias == Bias)
+        {
+            if (_wcsicmp(Entry->Description, lpDescription) > 0)
+                return Entry;
+        }
+
         Entry = Entry->Next;
     }
 
@@ -56,17 +64,65 @@ GetLargerTimeZoneEntry(DWORD Index)
 }
 
 
+static
+LONG
+QueryTimezoneData(
+    HKEY hZoneKey,
+    PTIMEZONE_ENTRY Entry)
+{
+    DWORD dwValueSize;
+    LONG lError;
+
+    dwValueSize = 128 * sizeof(WCHAR);
+    lError = RegQueryValueExW(hZoneKey,
+                              L"Display",
+                              NULL,
+                              NULL,
+                              (LPBYTE)&Entry->Description,
+                              &dwValueSize);
+    if (lError != ERROR_SUCCESS)
+        return lError;
+
+    dwValueSize = 33 * sizeof(WCHAR);
+    lError = RegQueryValueExW(hZoneKey,
+                              L"Std",
+                              NULL,
+                              NULL,
+                              (LPBYTE)&Entry->StandardName,
+                              &dwValueSize);
+    if (lError != ERROR_SUCCESS)
+        return lError;
+
+    dwValueSize = 33 * sizeof(WCHAR);
+    lError = RegQueryValueExW(hZoneKey,
+                              L"Dlt",
+                              NULL,
+                              NULL,
+                              (LPBYTE)&Entry->DaylightName,
+                              &dwValueSize);
+    if (lError != ERROR_SUCCESS)
+        return lError;
+
+    dwValueSize = sizeof(TZ_INFO);
+    lError = RegQueryValueExW(hZoneKey,
+                              L"TZI",
+                              NULL,
+                              NULL,
+                              (LPBYTE)&Entry->TimezoneInfo,
+                              &dwValueSize);
+    return lError;
+}
+
+
 static VOID
 CreateTimeZoneList(VOID)
 {
     WCHAR szKeyName[256];
     DWORD dwIndex;
     DWORD dwNameSize;
-    DWORD dwValueSize;
     LONG lError;
     HKEY hZonesKey;
     HKEY hZoneKey;
-
     PTIMEZONE_ENTRY Entry;
     PTIMEZONE_ENTRY Current;
 
@@ -77,10 +133,9 @@ CreateTimeZoneList(VOID)
                       &hZonesKey))
         return;
 
-    dwIndex = 0;
-    while (TRUE)
+    for (dwIndex = 0; ; dwIndex++)
     {
-        dwNameSize = 256 * sizeof(WCHAR);
+        dwNameSize = sizeof(szKeyName);
         lError = RegEnumKeyExW(hZonesKey,
                                dwIndex,
                                szKeyName,
@@ -106,71 +161,17 @@ CreateTimeZoneList(VOID)
             break;
         }
 
-        dwValueSize = 64 * sizeof(WCHAR);
-        lError = RegQueryValueExW(hZoneKey,
-                             L"Display",
-                             NULL,
-                             NULL,
-                             (LPBYTE)&Entry->Description,
-                             &dwValueSize);
-        if (lError != ERROR_SUCCESS)
-        {
-            RegCloseKey(hZoneKey);
-            dwIndex++;
-            HeapFree(GetProcessHeap(), 0, Entry);
-            continue;
-        }
+        lError = QueryTimezoneData(hZoneKey,
+                                   Entry);
 
-        dwValueSize = 33 * sizeof(WCHAR);
-        if (RegQueryValueExW(hZoneKey,
-                             L"Std",
-                             NULL,
-                             NULL,
-                             (LPBYTE)&Entry->StandardName,
-                             &dwValueSize))
-        {
-            RegCloseKey(hZoneKey);
-            break;
-        }
-
-        dwValueSize = 33 * sizeof(WCHAR);
-        if (RegQueryValueExW(hZoneKey,
-                             L"Dlt",
-                             NULL,
-                             NULL,
-                             (LPBYTE)&Entry->DaylightName,
-                             &dwValueSize))
-        {
-            RegCloseKey(hZoneKey);
-            break;
-        }
-
-        dwValueSize = sizeof(DWORD);
-        if (RegQueryValueExW(hZoneKey,
-                             L"Index",
-                             NULL,
-                             NULL,
-                             (LPBYTE)&Entry->Index,
-                             &dwValueSize))
-        {
-            RegCloseKey(hZoneKey);
-            break;
-        }
+        RegCloseKey(hZoneKey);
 
-        dwValueSize = sizeof(TZ_INFO);
-        if (RegQueryValueExW(hZoneKey,
-                             L"TZI",
-                             NULL,
-                             NULL,
-                             (LPBYTE)&Entry->TimezoneInfo,
-                             &dwValueSize))
+        if (lError != ERROR_SUCCESS)
         {
-            RegCloseKey(hZoneKey);
+            HeapFree(GetProcessHeap(), 0, Entry);
             break;
         }
 
-        RegCloseKey(hZoneKey);
-
         if (TimeZoneListHead == NULL &&
             TimeZoneListTail == NULL)
         {
@@ -181,7 +182,7 @@ CreateTimeZoneList(VOID)
         }
         else
         {
-            Current = GetLargerTimeZoneEntry(Entry->Index);
+            Current = GetLargerTimeZoneEntry(Entry->TimezoneInfo.Bias, Entry->Description);
             if (Current != NULL)
             {
                 if (Current == TimeZoneListHead)
@@ -210,8 +211,6 @@ CreateTimeZoneList(VOID)
                 TimeZoneListTail = Entry;
             }
         }
-
-        dwIndex++;
     }
 
     RegCloseKey(hZonesKey);