Author: ekohl
Date: Sat May 28 00:12:02 2016
New Revision: 71433
URL:
http://svn.reactos.org/svn/reactos?rev=71433&view=rev
Log:
[TIMEDATE]
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!
Modified:
trunk/reactos/dll/cpl/timedate/timezone.c
Modified: trunk/reactos/dll/cpl/timedate/timezone.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/timedate/timezone.…
==============================================================================
--- trunk/reactos/dll/cpl/timedate/timezone.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/timedate/timezone.c [iso-8859-1] Sat May 28 00:12:02 2016
@@ -24,11 +24,10 @@
{
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,21 +37,80 @@
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;
}
return NULL;
+}
+
+
+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;
}
@@ -62,11 +120,9 @@
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 @@
&hZonesKey))
return;
- dwIndex = 0;
- while (TRUE)
- {
- dwNameSize = 256 * sizeof(WCHAR);
+ for (dwIndex = 0; ; dwIndex++)
+ {
+ dwNameSize = sizeof(szKeyName);
lError = RegEnumKeyExW(hZonesKey,
dwIndex,
szKeyName,
@@ -106,70 +161,16 @@
break;
}
- dwValueSize = 64 * sizeof(WCHAR);
- lError = RegQueryValueExW(hZoneKey,
- L"Display",
- NULL,
- NULL,
- (LPBYTE)&Entry->Description,
- &dwValueSize);
+ lError = QueryTimezoneData(hZoneKey,
+ Entry);
+
+ RegCloseKey(hZoneKey);
+
if (lError != ERROR_SUCCESS)
{
- RegCloseKey(hZoneKey);
- dwIndex++;
HeapFree(GetProcessHeap(), 0, Entry);
- continue;
- }
-
- 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;
- }
-
- dwValueSize = sizeof(TZ_INFO);
- if (RegQueryValueExW(hZoneKey,
- L"TZI",
- NULL,
- NULL,
- (LPBYTE)&Entry->TimezoneInfo,
- &dwValueSize))
- {
- RegCloseKey(hZoneKey);
- break;
- }
-
- RegCloseKey(hZoneKey);
+ break;
+ }
if (TimeZoneListHead == NULL &&
TimeZoneListTail == NULL)
@@ -181,7 +182,7 @@
}
else
{
- Current = GetLargerTimeZoneEntry(Entry->Index);
+ Current = GetLargerTimeZoneEntry(Entry->TimezoneInfo.Bias,
Entry->Description);
if (Current != NULL)
{
if (Current == TimeZoneListHead)
@@ -210,8 +211,6 @@
TimeZoneListTail = Entry;
}
}
-
- dwIndex++;
}
RegCloseKey(hZonesKey);