Ignore:
Timestamp:
Jan 8, 2003, 3:25:40 PM (23 years ago)
Author:
sandervl
Message:

Get/SetTimeZoneInformation changes; RegQueryValue(Ex)W length fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/time.cpp

    r9593 r9647  
    1 /* $Id: time.cpp,v 1.24 2003-01-03 11:26:43 sandervl Exp $ */
     1/* $Id: time.cpp,v 1.25 2003-01-08 14:25:40 sandervl Exp $ */
    22
    33/*
     
    183183}
    184184//******************************************************************************
    185 //******************************************************************************
    186 DWORD TimeZoneName(LPSTR name, LPWSTR text, BOOL read)
    187 {
    188     CHAR  AsciiText_1[32];
    189     CHAR  AsciiText_2[32];
    190     HKEY  hKeyOptions;
    191     DWORD dwKeyType;
    192     DWORD dwDataLength = sizeof(AsciiText_1);
    193     DWORD dwDataLength_2;
    194     BOOL  Set = FALSE;
    195 
    196     if (read) {
    197        ZeroMemory(text, 2*sizeof(AsciiText_1));
    198     }
    199     else {
    200        UnicodeToAscii(text, &AsciiText_2[0]);
    201        dwDataLength_2 = strlen(AsciiText_2);
    202     }
    203     DWORD rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
    204                              "SOFTWARE\\TIME\\TIME_SETTING",
    205                              0,
    206                              (read) ? KEY_READ : KEY_ALL_ACCESS,
    207                              &hKeyOptions);
    208     if (rc == ERROR_SUCCESS)
    209     {
    210         rc = RegQueryValueExA(hKeyOptions,
    211                               name,
    212                               0,
    213                               &dwKeyType,
    214                               (LPBYTE)AsciiText_1,
    215                               &dwDataLength);
    216         if (rc == ERROR_SUCCESS) {
    217             if (read) AsciiToUnicode(&AsciiText_1[0], text);
    218             else Set = (strcmp(AsciiText_1,AsciiText_2) != 0);
    219         }
    220         else Set = (!read);
    221     }
    222     else {
    223         if (!read) {
    224             rc = RegCreateKeyA(HKEY_LOCAL_MACHINE,
    225                                "SOFTWARE\\TIME\\TIME_SETTING",
    226                                &hKeyOptions);
    227             Set = (rc == ERROR_SUCCESS);
    228         }
    229     }
    230     if (Set) rc = RegSetValueExA(hKeyOptions,
    231                                  name,
    232                                  0,
    233                                  REG_SZ,
    234                                  (LPBYTE)AsciiText_2,
    235                                  dwDataLength_2);
    236 
    237     RegCloseKey(hKeyOptions);
    238     return rc;
    239 }
     185static const LPSTR szTZBias           = "Bias";
     186static const LPSTR szTZActiveTimeBias = "ActiveTimeBias";
     187
     188static const LPWSTR szTZStandardName  = (LPWSTR)L"StandardName";
     189static const LPSTR szTZStandardBias   = "StandardBias";
     190static const LPSTR szTZStandardStart  = "StandardStart";
     191
     192static const LPWSTR szTZDaylightName  = (LPWSTR)L"DaylightName";
     193static const LPSTR szTZDaylightBias   = "DaylightBias";
     194static const LPSTR szTZDaylightStart  = "DaylightStart";
     195static const LPSTR KEY_WINDOWS_TZ     = "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation";
    240196//******************************************************************************
    241197DWORD WIN32API GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZone)
    242198{
    243     DWORD ret = O32_GetTimeZoneInformation(lpTimeZone);
    244 
    245     //Convert timezone names to unicode as WGSS (wrongly) returns ascii strings
    246     TimeZoneName("STANDARD_NAME", &lpTimeZone->StandardName[0], TRUE);
    247     TimeZoneName("DAYLIGHT_NAME", &lpTimeZone->DaylightName[0], TRUE);
    248     return ret;
     199    TIME_ZONE_INFORMATION tzone;
     200    int len;
     201
     202    HKEY hkey;
     203
     204    if(RegCreateKeyA(HKEY_LOCAL_MACHINE, KEY_WINDOWS_TZ, &hkey) == ERROR_SUCCESS)
     205    {
     206        DWORD type, size;
     207        DWORD rc;
     208
     209        size = sizeof(lpTimeZone->Bias);
     210        rc = RegQueryValueExA(hkey, szTZBias,0,&type, (LPBYTE)&lpTimeZone->Bias, &size);
     211        if(rc || type != REG_DWORD) {
     212            goto fail;
     213        }
     214        size = sizeof(lpTimeZone->StandardName);
     215        rc = RegQueryValueExW(hkey, szTZStandardName, 0, &type, (LPBYTE)lpTimeZone->StandardName, &size);
     216        if(rc || type != REG_SZ) {
     217            goto fail;
     218        }
     219        size = sizeof(lpTimeZone->StandardBias);
     220        rc = RegQueryValueExA(hkey, szTZStandardBias,0,&type, (LPBYTE)&lpTimeZone->StandardBias, &size);
     221        if(rc || type != REG_DWORD) {
     222            goto fail;
     223        }
     224        size = sizeof(lpTimeZone->StandardDate);
     225        rc = RegQueryValueExA(hkey, szTZStandardStart,0,&type, (LPBYTE)&lpTimeZone->StandardDate, &size);
     226        if(rc || type != REG_BINARY) {
     227            goto fail;
     228        }
     229
     230        size = sizeof(lpTimeZone->DaylightName);
     231        rc = RegQueryValueExW(hkey, szTZDaylightName, 0, &type, (LPBYTE)lpTimeZone->DaylightName, &size);
     232        if(rc || type != REG_SZ) {
     233            goto fail;
     234        }
     235        size = sizeof(lpTimeZone->DaylightBias);
     236        rc = RegQueryValueExA(hkey, szTZDaylightBias,0,&type, (LPBYTE)&lpTimeZone->DaylightBias, &size);
     237        if(rc || type != REG_DWORD) {
     238            goto fail;
     239        }
     240        size = sizeof(lpTimeZone->DaylightDate);
     241        rc = RegQueryValueExA(hkey, szTZDaylightStart,0,&type, (LPBYTE)&lpTimeZone->DaylightDate, &size);
     242        if(rc || type != REG_BINARY) {
     243            goto fail;
     244        }
     245        RegCloseKey(hkey);
     246
     247        //TODO: we should return whether or we are in standard or daylight time
     248        return TIME_ZONE_ID_STANDARD;
     249    }
     250    else
     251    {//get it from WGSS
     252fail:
     253        DWORD ret = O32_GetTimeZoneInformation(&tzone);
     254
     255        *lpTimeZone = tzone;
     256
     257        //Convert timezone names to unicode as WGSS (wrongly) returns ascii strings
     258        len = sizeof(tzone.StandardName)/sizeof(WCHAR);
     259        lstrcpynAtoW(lpTimeZone->StandardName, (LPSTR)tzone.StandardName, len);
     260        lpTimeZone->StandardName[len] = 0;
     261
     262        lstrcpynAtoW(lpTimeZone->DaylightName, (LPSTR)tzone.DaylightName, len);
     263        lpTimeZone->DaylightName[len] = 0;
     264        return ret;
     265    }
    249266}
    250267//******************************************************************************
     
    252269BOOL WIN32API SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION lpTimeZone)
    253270{
     271    TIME_ZONE_INFORMATION tzone = *lpTimeZone;
     272    int len;
     273    HKEY hkey;
     274
     275    if(RegCreateKeyA(HKEY_LOCAL_MACHINE, KEY_WINDOWS_TZ, &hkey) != ERROR_SUCCESS)
     276    {
     277        dprintf(("ERROR: SetTimeZoneInformation: Unable to create key"));
     278        return FALSE;
     279    }
     280    RegSetValueExA(hkey, szTZBias,0,REG_DWORD, (LPBYTE)&lpTimeZone->Bias, sizeof(lpTimeZone->Bias));
     281    RegSetValueExA(hkey, szTZActiveTimeBias,0,REG_DWORD, (LPBYTE)&lpTimeZone->Bias, sizeof(lpTimeZone->Bias));
     282
     283    RegSetValueExW(hkey, szTZStandardName, 0, REG_SZ, (LPBYTE)lpTimeZone->StandardName, lstrlenW(lpTimeZone->StandardName));
     284    RegSetValueExA(hkey, szTZStandardBias,0,REG_DWORD, (LPBYTE)&lpTimeZone->StandardBias, sizeof(lpTimeZone->StandardBias));
     285    RegSetValueExA(hkey, szTZStandardStart,0,REG_BINARY, (LPBYTE)&lpTimeZone->StandardDate, sizeof(lpTimeZone->StandardDate));
     286
     287    RegSetValueExW(hkey, szTZDaylightName, 0, REG_SZ, (LPBYTE)lpTimeZone->DaylightName, lstrlenW(lpTimeZone->DaylightName));
     288    RegSetValueExA(hkey, szTZDaylightBias,0,REG_DWORD, (LPBYTE)&lpTimeZone->DaylightBias, sizeof(lpTimeZone->DaylightBias));
     289    RegSetValueExA(hkey, szTZDaylightStart,0,REG_BINARY, (LPBYTE)&lpTimeZone->DaylightDate, sizeof(lpTimeZone->DaylightDate));
     290    RegCloseKey(hkey);
     291
    254292    //Convert timezone names to ascii as WGSS (wrongly) expects that
    255     TimeZoneName("STANDARD_NAME", &lpTimeZone->StandardName[0], FALSE);
    256     TimeZoneName("DAYLIGHT_NAME", &lpTimeZone->DaylightName[0], FALSE);
    257 
    258     return O32_SetTimeZoneInformation(lpTimeZone);
     293    len = sizeof(tzone.StandardName)/sizeof(WCHAR);
     294    lstrcpynWtoA((LPSTR)tzone.StandardName, lpTimeZone->StandardName, len);
     295    tzone.StandardName[len] = 0;
     296
     297    lstrcpynWtoA((LPSTR)tzone.DaylightName, lpTimeZone->DaylightName, len);
     298    tzone.DaylightName[len] = 0;
     299
     300    return O32_SetTimeZoneInformation(&tzone);
    259301}
    260302/*****************************************************************************
Note: See TracChangeset for help on using the changeset viewer.