1736
1774
- (id) initWithName: (NSString*)name data: (NSData*)data
1739
BOOL isNT = NO,regFound=NO;
1741
/* Open the key in the local machine hive where the time zone data is stored. */
1742
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_READ, ®DirKey))
1780
/* Open the key in the local machine hive where
1781
* the time zone data is stored. */
1782
if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1783
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1749
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_READ, ®DirKey))
1793
if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1794
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1757
/* Iterate over all subKeys in the registry to find the right one.
1758
Unfortunately name is a localized value. The keys in the registry are
1759
unlocalized names. */
1760
CHAR achKey[255]; // buffer for subkey name
1761
DWORD cbName; // size of name string
1762
CHAR achClass[MAX_PATH] = ""; // buffer for class name
1763
DWORD cchClassName = MAX_PATH; // size of class string
1764
DWORD cSubKeys=0; // number of subkeys
1765
DWORD cbMaxSubKey; // longest subkey size
1766
DWORD cchMaxClass; // longest class string
1767
DWORD cValues; // number of values for key
1768
DWORD cchMaxValue; // longest value name
1769
DWORD cbMaxValueData; // longest value data
1770
DWORD cbSecurityDescriptor; // size of security descriptor
1771
FILETIME ftLastWriteTime; // last write time
1776
/* Get the class name and the value count. */
1777
retCode = RegQueryInfoKey(
1778
regDirKey, // key handle
1779
achClass, // buffer for class name
1780
&cchClassName, // size of class string
1782
&cSubKeys, // number of subkeys
1783
&cbMaxSubKey, // longest subkey size
1784
&cchMaxClass, // longest class string
1785
&cValues, // number of values for this key
1786
&cchMaxValue, // longest value name
1787
&cbMaxValueData, // longest value data
1788
&cbSecurityDescriptor, // security descriptor
1789
&ftLastWriteTime); // last write time
1791
if (cSubKeys && (retCode == ERROR_SUCCESS))
1793
const char *cName = [name cString];
1795
for (i=0; i<cSubKeys && !tzFound; i++)
1799
retCode = RegEnumKeyEx(regDirKey, i, achKey, &cbName, NULL, NULL, NULL, &ftLastWriteTime);
1800
if (retCode == ERROR_SUCCESS)
1802
char keyBuffer[16384];
1806
sprintf(keyBuffer,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s",achKey);
1808
sprintf(keyBuffer,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones\\%s",achKey);
1810
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyBuffer, 0, KEY_READ, ®Key))
1813
char standardName[256];
1814
char daylightName[256];
1818
/* check standardname */
1819
standardName[0]='\0';
1820
bufsize=sizeof(buf);
1821
if (ERROR_SUCCESS==RegQueryValueEx(regKey, "Std", 0, &type, buf, &bufsize))
1823
strcpy(standardName,buf);
1824
if (strcmp(standardName,cName) == 0)
1828
/* check daylightname */
1829
daylightName[0]='\0';
1830
bufsize=sizeof(buf);
1831
if (ERROR_SUCCESS==RegQueryValueEx(regKey, "Dlt", 0, &type, buf, &bufsize))
1833
strcpy(daylightName,buf);
1834
if (strcmp(daylightName,cName) == 0)
1840
/* Read in the time zone data */
1841
bufsize=sizeof(buf);
1842
if (ERROR_SUCCESS==RegQueryValueEx(regKey, "TZI", 0, &type, buf, &bufsize))
1844
TZI *tzi = (void*)buf;
1846
StandardBias = tzi->StandardBias;
1847
DaylightBias = tzi->DaylightBias;
1848
StandardDate = tzi->StandardDate;
1849
DaylightDate = tzi->DaylightDate;
1852
/* Set the standard name for the time zone. */
1853
if (strlen(standardName))
1856
[timeZoneName release];
1857
timeZoneName = [[NSString stringWithCString:standardName] retain];
1859
/* Abbr generated here is IMHO a bit suspicous but I kept it */
1860
for (a=0,b=0;standardName[a];a++)
1862
if (isupper(standardName[a]))
1863
standardName[b++]=standardName[a];
1866
[timeZoneNameAbbr release];
1867
timeZoneNameAbbr = [[NSString stringWithCString:standardName] retain];
1870
/* Set the daylight savings name for the time zone. */
1871
if (strlen(daylightName))
1874
[daylightZoneName release];
1875
daylightZoneName = [[NSString stringWithCString:daylightName] retain];
1877
/* Abbr generated here is IMHO a bit suspicous but I kept it */
1878
for (a=0,b=0;daylightName[a];a++)
1880
if (isupper(daylightName[a]))
1881
daylightName[b++]=daylightName[a];
1884
[daylightZoneNameAbbr release];
1885
daylightZoneNameAbbr = [[NSString stringWithCString:daylightName] retain];
1888
RegCloseKey(regKey);
1805
/* Iterate over all subKeys in the registry to find the right one.
1806
Unfortunately name is a localized value. The keys in the registry are
1807
unlocalized names. */
1808
CHAR achKey[255]; // buffer for subkey name
1809
DWORD cbName; // size of name string
1810
CHAR achClass[MAX_PATH] = ""; // buffer for class name
1811
DWORD cchClassName = MAX_PATH; // size of class string
1812
DWORD cSubKeys=0; // number of subkeys
1813
DWORD cbMaxSubKey; // longest subkey size
1814
DWORD cchMaxClass; // longest class string
1815
DWORD cValues; // number of values for key
1816
DWORD cchMaxValue; // longest value name
1817
DWORD cbMaxValueData; // longest value data
1818
DWORD cbSecurityDescriptor; // size of security descriptor
1819
FILETIME ftLastWriteTime; // last write time
1824
/* Get the class name and the value count. */
1825
retCode = RegQueryInfoKeyA(
1826
regDirKey, // key handle
1827
achClass, // buffer for class name
1828
&cchClassName, // size of class string
1830
&cSubKeys, // number of subkeys
1831
&cbMaxSubKey, // longest subkey size
1832
&cchMaxClass, // longest class string
1833
&cValues, // number of values for this key
1834
&cchMaxValue, // longest value name
1835
&cbMaxValueData, // longest value data
1836
&cbSecurityDescriptor, // security descriptor
1837
&ftLastWriteTime); // last write time
1839
if (cSubKeys && (retCode == ERROR_SUCCESS))
1841
const char *cName = [name cString];
1843
for (i = 0; i < cSubKeys && !tzFound; i++)
1847
retCode = RegEnumKeyExA(regDirKey,
1855
if (retCode == ERROR_SUCCESS)
1857
char keyBuffer[16384];
1862
sprintf(keyBuffer, "SOFTWARE\\Microsoft\\Windows NT"
1863
"\\CurrentVersion\\Time Zones\\%s", achKey);
1867
sprintf(keyBuffer, "SOFTWARE\\Microsoft\\Windows"
1868
"\\CurrentVersion\\Time Zones\\%s", achKey);
1871
if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1878
char standardName[256];
1879
char daylightName[256];
1883
/* check standardname */
1884
standardName[0]='\0';
1885
bufsize=sizeof(buf);
1886
if (ERROR_SUCCESS == RegQueryValueExA(regKey,
1893
strcpy(standardName, buf);
1894
if (strcmp(standardName, cName) == 0)
1898
/* check daylightname */
1899
daylightName[0]='\0';
1900
bufsize = sizeof(buf);
1901
if (ERROR_SUCCESS == RegQueryValueExA(regKey,
1908
strcpy(daylightName, buf);
1909
if (strcmp(daylightName, cName) == 0)
1915
/* Read in the time zone data */
1916
bufsize = sizeof(buf);
1917
if (ERROR_SUCCESS == RegQueryValueExA(regKey,
1924
TZI *tzi = (void*)buf;
1926
StandardBias = tzi->StandardBias;
1927
DaylightBias = tzi->DaylightBias;
1928
StandardDate = tzi->StandardDate;
1929
DaylightDate = tzi->DaylightDate;
1932
/* Set the standard name for the time zone. */
1933
if (strlen(standardName))
1937
ASSIGN(timeZoneName,
1938
[NSString stringWithCString: standardName]);
1940
/* Abbr generated here is IMHO a
1941
* bit suspicous but I kept it */
1942
for (a = 0, b = 0; standardName[a]; a++)
1944
if (isupper(standardName[a]))
1945
standardName[b++] = standardName[a];
1947
standardName[b] = 0;
1948
ASSIGN(timeZoneNameAbbr,
1949
[NSString stringWithCString: standardName]);
1952
/* Set the daylight savings name for the time zone. */
1953
if (strlen(daylightName))
1957
ASSIGN(daylightZoneName,
1958
[NSString stringWithCString: daylightName]);
1960
/* Abbr generated here is IMHO
1961
* a bit suspicous but I kept it */
1962
for (a = 0, b = 0; daylightName[a]; a++)
1964
if (isupper(daylightName[a]))
1965
daylightName[b++] = daylightName[a];
1967
daylightName[b] = 0;
1968
ASSIGN(daylightZoneNameAbbr,
1969
[NSString stringWithCString: daylightName]);
1972
RegCloseKey(regKey);
1893
1977
RegCloseKey(regDirKey);