From accdfe8f540d28911a56df946bee00d589778b2a Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong@codeweavers.com>
Date: Sat, 6 Jun 2015 09:24:00 +0800
Subject: kernel32: Init TimezoneInformation registry.

---
 dlls/kernel32/kernel_main.c    |  3 +++
 dlls/kernel32/kernel_private.h |  3 +++
 dlls/kernel32/time.c           | 48 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/dlls/kernel32/kernel_main.c b/dlls/kernel32/kernel_main.c
index e24100b..d3420ec 100644
--- a/dlls/kernel32/kernel_main.c
+++ b/dlls/kernel32/kernel_main.c
@@ -88,6 +88,9 @@ static BOOL process_attach( HMODULE module )
     /* Setup registry locale information */
     LOCALE_InitRegistry();
 
+    /* Setup registry timezone information */
+    TIMEZONE_InitRegistry();
+
     /* Setup computer name */
     COMPUTERNAME_Init();
 
diff --git a/dlls/kernel32/kernel_private.h b/dlls/kernel32/kernel_private.h
index 76611d7..2d4ba02 100644
--- a/dlls/kernel32/kernel_private.h
+++ b/dlls/kernel32/kernel_private.h
@@ -104,6 +104,9 @@ extern void COMPUTERNAME_Init(void) DECLSPEC_HIDDEN;
 extern void LOCALE_Init(void) DECLSPEC_HIDDEN;
 extern void LOCALE_InitRegistry(void) DECLSPEC_HIDDEN;
 
+/* time.c */
+extern void TIMEZONE_InitRegistry(void) DECLSPEC_HIDDEN;
+
 /* oldconfig.c */
 extern void convert_old_config(void) DECLSPEC_HIDDEN;
 
diff --git a/dlls/kernel32/time.c b/dlls/kernel32/time.c
index daafc7f..43c2f80 100644
--- a/dlls/kernel32/time.c
+++ b/dlls/kernel32/time.c
@@ -581,6 +581,54 @@ static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
     filetime->dwHighDateTime = (DWORD)(secs >> 32);
 }
 
+/***********************************************************************
+ *		TIMEZONE_InitRegistry
+ *
+ * Update registry contents on startup if the user timezone has changed.
+ * This simulates the action of the Windows control panel.
+ */
+void TIMEZONE_InitRegistry(void)
+{
+    static const WCHAR szTimezoneInformation[] = {
+        'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
+        'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+        'C','o','n','t','r','o','l','\\',
+        'T','i','m','e','Z','o','n','e','I','n','f','o','r','m','a','t','i','o','n','\0'
+    };
+    WCHAR standardnameW[] = {'S','t','a','n','d','a','r','d','N','a','m','e','\0'};
+    WCHAR timezonekeynameW[] = {'T','i','m','e','Z','o','n','e','K','e','y','N','a','m','e','\0'};
+    DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+    UNICODE_STRING keyName;
+    OBJECT_ATTRIBUTES attr;
+    HANDLE hkey;
+    DWORD tzid;
+
+    tzid = GetDynamicTimeZoneInformation(&tzinfo);
+    if (tzid == TIME_ZONE_ID_INVALID)
+    {
+        ERR("fail to get timezone information.\n");
+        return;
+    }
+
+    RtlInitUnicodeString(&keyName, szTimezoneInformation);
+    InitializeObjectAttributes(&attr, &keyName, 0, 0, NULL);
+    if (NtCreateKey(&hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL) != STATUS_SUCCESS)
+    {
+        ERR("fail to create timezone information key.\n");
+        return;
+    }
+
+    RtlInitUnicodeString(&keyName, standardnameW);
+    NtSetValueKey(hkey, &keyName, 0, REG_SZ, tzinfo.StandardName,
+                  (strlenW(tzinfo.StandardName) + 1) * sizeof(WCHAR));
+
+    RtlInitUnicodeString(&keyName, timezonekeynameW);
+    NtSetValueKey(hkey, &keyName, 0, REG_SZ, tzinfo.TimeZoneKeyName,
+                  (strlenW(tzinfo.TimeZoneKeyName) + 1) * sizeof(WCHAR));
+
+    NtClose( hkey );
+}
+
 /*********************************************************************
  *	GetProcessTimes				(KERNEL32.@)
  *
-- 
2.4.2

