Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357/* * PROJECT: ReactOS TimeZone Utilities Library * LICENSE: GPL-2.0 (https://spdx.org/licenses/GPL-2.0) * PURPOSE: Provides time-zone utility wrappers around Win32 functions, * that are used by different ReactOS modules such as * timedate.cpl, syssetup.dll. * COPYRIGHT: Copyright 2004-2005 Eric Kohl * Copyright 2016 Carlo Bramini * Copyright 2020 Hermes Belusca-Maito */
#include <stdlib.h>#include <windef.h>#include <winbase.h>#include <winreg.h>
#include "tzlib.h"
BOOLGetTimeZoneListIndex( IN OUT PULONG pIndex){ LONG lError; HKEY hKey; DWORD dwType; DWORD dwValueSize; DWORD Length; LPWSTR Buffer; LPWSTR Ptr, End; BOOL bFound = FALSE; unsigned long iLanguageID; WCHAR szLanguageIdString[9];
if (*pIndex == -1) { *pIndex = 85; /* fallback to GMT time zone */
lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language", 0, KEY_QUERY_VALUE, &hKey); if (lError != ERROR_SUCCESS) { return FALSE; }
dwValueSize = sizeof(szLanguageIdString); lError = RegQueryValueExW(hKey, L"Default", NULL, NULL, (LPBYTE)szLanguageIdString, &dwValueSize); if (lError != ERROR_SUCCESS) { RegCloseKey(hKey); return FALSE; }
iLanguageID = wcstoul(szLanguageIdString, NULL, 16); RegCloseKey(hKey); } else { iLanguageID = *pIndex; }
lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_QUERY_VALUE, &hKey); if (lError != ERROR_SUCCESS) { return FALSE; }
dwValueSize = 0; lError = RegQueryValueExW(hKey, L"IndexMapping", NULL, &dwType, NULL, &dwValueSize); if ((lError != ERROR_SUCCESS) || (dwType != REG_MULTI_SZ)) { RegCloseKey(hKey); return FALSE; }
Buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize); if (Buffer == NULL) { RegCloseKey(hKey); return FALSE; }
lError = RegQueryValueExW(hKey, L"IndexMapping", NULL, &dwType, (LPBYTE)Buffer, &dwValueSize);
RegCloseKey(hKey);
if ((lError != ERROR_SUCCESS) || (dwType != REG_MULTI_SZ)) { HeapFree(GetProcessHeap(), 0, Buffer); return FALSE; }
Ptr = Buffer; while (*Ptr != 0) { Length = wcslen(Ptr); if (wcstoul(Ptr, NULL, 16) == iLanguageID) bFound = TRUE;
Ptr = Ptr + Length + 1; if (*Ptr == 0) break;
if (bFound) { *pIndex = wcstoul(Ptr, &End, 10); HeapFree(GetProcessHeap(), 0, Buffer); return TRUE; }
Length = wcslen(Ptr); Ptr = Ptr + Length + 1; }
HeapFree(GetProcessHeap(), 0, Buffer); return FALSE;}
LONGQueryTimeZoneData( IN HKEY hZoneKey, OUT PULONG Index OPTIONAL, OUT PREG_TZI_FORMAT TimeZoneInfo, OUT PWCHAR Description OPTIONAL, IN OUT PULONG DescriptionSize OPTIONAL, OUT PWCHAR StandardName OPTIONAL, IN OUT PULONG StandardNameSize OPTIONAL, OUT PWCHAR DaylightName OPTIONAL, IN OUT PULONG DaylightNameSize OPTIONAL){ LONG lError; DWORD dwValueSize;
if (Index) { dwValueSize = sizeof(*Index); lError = RegQueryValueExW(hZoneKey, L"Index", NULL, NULL, (LPBYTE)Index, &dwValueSize); if (lError != ERROR_SUCCESS) *Index = 0; }
/* The time zone information structure is mandatory for a valid time zone */ dwValueSize = sizeof(*TimeZoneInfo); lError = RegQueryValueExW(hZoneKey, L"TZI", NULL, NULL, (LPBYTE)TimeZoneInfo, &dwValueSize); if (lError != ERROR_SUCCESS) return lError;
if (Description && DescriptionSize && *DescriptionSize > 0) { lError = RegQueryValueExW(hZoneKey, L"Display", NULL, NULL, (LPBYTE)Description, DescriptionSize); if (lError != ERROR_SUCCESS) *Description = 0; }
if (StandardName && StandardNameSize && *StandardNameSize > 0) { lError = RegQueryValueExW(hZoneKey, L"Std", NULL, NULL, (LPBYTE)StandardName, StandardNameSize); if (lError != ERROR_SUCCESS) *StandardName = 0; }
if (DaylightName && DaylightNameSize && *DaylightNameSize > 0) { lError = RegQueryValueExW(hZoneKey, L"Dlt", NULL, NULL, (LPBYTE)DaylightName, DaylightNameSize); if (lError != ERROR_SUCCESS) *DaylightName = 0; }
return ERROR_SUCCESS;}
//// NOTE: Very similar to the EnumDynamicTimeZoneInformation() function// introduced in Windows 8.//VOIDEnumerateTimeZoneList( IN PENUM_TIMEZONE_CALLBACK Callback, IN PVOID Context OPTIONAL){ LONG lError; HKEY hZonesKey; HKEY hZoneKey; DWORD dwIndex; DWORD dwNameSize; WCHAR szKeyName[256];
/* Open the registry key containing the list of time zones */ lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_ENUMERATE_SUB_KEYS, &hZonesKey); if (lError != ERROR_SUCCESS) return;
/* Enumerate it */ for (dwIndex = 0; ; dwIndex++) { dwNameSize = sizeof(szKeyName); lError = RegEnumKeyExW(hZonesKey, dwIndex, szKeyName, &dwNameSize, NULL, NULL, NULL, NULL); // if (lError != ERROR_SUCCESS && lError != ERROR_MORE_DATA) if (lError == ERROR_NO_MORE_ITEMS) break;
/* Open the time zone sub-key */ if (RegOpenKeyExW(hZonesKey, szKeyName, 0, KEY_QUERY_VALUE, &hZoneKey)) { /* We failed, continue with another sub-key */ continue; }
/* Call the user-provided callback */ lError = Callback(hZoneKey, Context); // lError = QueryTimeZoneData(hZoneKey, Context);
RegCloseKey(hZoneKey); }
RegCloseKey(hZonesKey);}
// Returns TRUE if AutoDaylight is ON.// Returns FALSE if AutoDaylight is OFF.BOOLGetAutoDaylight(VOID){ LONG lError; HKEY hKey; DWORD dwType; DWORD dwDisabled; DWORD dwValueSize;
lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", 0, KEY_QUERY_VALUE, &hKey); if (lError != ERROR_SUCCESS) return FALSE;
// NOTE: On Vista+: REG_DWORD "DynamicDaylightTimeDisabled" dwValueSize = sizeof(dwDisabled); lError = RegQueryValueExW(hKey, L"DisableAutoDaylightTimeSet", NULL, &dwType, (LPBYTE)&dwDisabled, &dwValueSize);
RegCloseKey(hKey);
if ((lError != ERROR_SUCCESS) || (dwType != REG_DWORD) || (dwValueSize != sizeof(dwDisabled))) { /* * The call failed (non zero) because the registry value isn't available, * which means auto-daylight shouldn't be disabled. */ dwDisabled = FALSE; }
return !dwDisabled;}
VOIDSetAutoDaylight( IN BOOL EnableAutoDaylightTime){ LONG lError; HKEY hKey; DWORD dwDisabled = TRUE;
lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", 0, KEY_SET_VALUE, &hKey); if (lError != ERROR_SUCCESS) return;
if (!EnableAutoDaylightTime) { /* Auto-Daylight disabled: set the value to TRUE */ // NOTE: On Vista+: REG_DWORD "DynamicDaylightTimeDisabled" RegSetValueExW(hKey, L"DisableAutoDaylightTimeSet", 0, REG_DWORD, (LPBYTE)&dwDisabled, sizeof(dwDisabled)); } else { /* Auto-Daylight enabled: just delete the value */ RegDeleteValueW(hKey, L"DisableAutoDaylightTimeSet"); }
RegCloseKey(hKey);}