Ignore:
Timestamp:
Jan 3, 2003, 12:26:43 PM (23 years ago)
Author:
sandervl
Message:

DT: Convert timezone names in Set/GetTimeZoneInformation as WGSS expects/returns ascii strings instead of unicode

File:
1 edited

Legend:

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

    r9561 r9593  
    1 /* $Id: time.cpp,v 1.23 2002-12-29 14:11:23 sandervl Exp $ */
     1/* $Id: time.cpp,v 1.24 2003-01-03 11:26:43 sandervl Exp $ */
    22
    33/*
     
    3030#include "unicode.h"
    3131#include "oslibtime.h"
     32#include "winreg.h"
    3233
    3334#define DBG_LOCALLOG    DBG_time
     
    183184//******************************************************************************
    184185//******************************************************************************
     186DWORD 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}
     240//******************************************************************************
    185241DWORD WIN32API GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZone)
    186242{
    187     return O32_GetTimeZoneInformation(lpTimeZone);
     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;
    188249}
    189250//******************************************************************************
     
    191252BOOL WIN32API SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION lpTimeZone)
    192253{
     254    //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
    193258    return O32_SetTimeZoneInformation(lpTimeZone);
    194259}
     
    216281//******************************************************************************
    217282
     283
Note: See TracChangeset for help on using the changeset viewer.