Ignore:
Timestamp:
Jan 7, 2003, 9:01:47 PM (23 years ago)
Author:
sandervl
Message:

Parse TZ environment variable and save timezone information to the registry. (default is CET if not found)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/install/odininst.cpp

    r8683 r9645  
    1 /* $Id: odininst.cpp,v 1.12 2002-06-15 12:33:46 sandervl Exp $ */
     1/* $Id: odininst.cpp,v 1.13 2003-01-07 20:01:47 sandervl Exp $ */
    22/*
    33 * Odin WarpIn installation app
     
    3636#include <string.h>
    3737#include <stdio.h>
     38#include <heapstring.h>
    3839#include <ctype.h>
    3940#include "winreg.h"
     
    5253BOOL SetupControlPanelKeys();
    5354BOOL InitSystemAndRegistry();
     55void SetupTimeZoneInfo();
    5456
    5557//******************************************************************************
     
    8183  CreateSystemDirectories();
    8284  SetupControlPanelKeys();
     85
     86  SetupTimeZoneInfo();
    8387  return 0;
    8488}
     
    10771081    return TRUE;
    10781082}
     1083//******************************************************************************
     1084//[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
     1085//"Bias"=dword:ffffffc4
     1086//"StandardName"="Romance Standard Time"
     1087//"StandardBias"=dword:00000000
     1088//"StandardStart"=hex:00,00,0a,00,05,00,03,00,00,00,00,00,00,00,00,00
     1089// typedef struct _SYSTEMTIME {
     1090//  WORD wYear;
     1091//  WORD wMonth;
     1092//  WORD wDayOfWeek;
     1093//  WORD wDay;
     1094//  WORD wHour;
     1095//  WORD wMinute;
     1096//  WORD wSecond;
     1097//  WORD wMilliseconds;
     1098//} SYSTEMTIME, *PSYSTEMTIME;
     1099//"DaylightName"="Romance Daylight Time"
     1100//"DaylightBias"=dword:ffffffc4
     1101//"DaylightStart"=hex:00,00,03,00,05,00,02,00,00,00,00,00,00,00,00,00
     1102//"ActiveTimeBias"=dword:ffffffc4
     1103//******************************************************************************
     1104void SetupTimeZoneInfo()
     1105{
     1106    HKEY hkey;
     1107    DWORD val = 0;
     1108    char szTimeZoneStd[4];
     1109    char szTimeZoneDay[4];
     1110    int  sign = FALSE;
     1111    int  bias;
     1112    char *pszTZ = NULL;
     1113    SYSTEMTIME stime = {0};
     1114    SYSTEMTIME dtime = {0};
     1115
     1116    if (RegCreateKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", &hkey) != ERROR_SUCCESS)
     1117    {
     1118        dprintf(("SetupTimeZoneInfo: Unable to create key"));
     1119        return;
     1120    }
     1121    //Little bit difficult to map the 3 letter timezone to a name
     1122    //(duplicate values for different regions)
     1123    //So we just copy that timezone string and hope the apps don't really
     1124    //on hardcoded timezone names.
     1125
     1126    //parse TZ environment variable
     1127    pszTZ = getenv("TZ");
     1128    if(pszTZ == NULL) {
     1129        //default is Central European Time
     1130        pszTZ = "CET-1CDT";
     1131    }
     1132    strncpy(szTimeZoneStd, pszTZ, 3);
     1133    szTimeZoneStd[3] = 0;
     1134    if(pszTZ[3] == '-') {
     1135         sign   = TRUE;
     1136         pszTZ += 4;
     1137    }
     1138    else pszTZ += 3;
     1139
     1140    if(isdigit(*pszTZ)) {
     1141        bias = (int)(*pszTZ - '0') * 60;
     1142        pszTZ++;
     1143        if(isdigit(*pszTZ)) {//double digit hour difference
     1144            bias *= 10;
     1145            bias += (int)(*pszTZ - '0') * 60;
     1146            pszTZ++;
     1147        }
     1148    }
     1149    else bias = 0;
     1150
     1151    if(sign) bias = -bias;
     1152
     1153    if(isalpha(*pszTZ)) {//daylight timezone name follows
     1154         strncpy(szTimeZoneDay, pszTZ, 3);
     1155         szTimeZoneDay[3] = 0;
     1156    }
     1157    else szTimeZoneDay[0] = 0;
     1158
     1159    RegSetValueEx(hkey, "Bias",0,REG_DWORD, (LPBYTE)&bias, sizeof(bias));
     1160    RegSetValueEx(hkey, "ActiveTimeBias",0,REG_DWORD, (LPBYTE)&bias, sizeof(bias));
     1161
     1162    RegSetValueEx(hkey, "StandardName", 0, REG_SZ, (LPBYTE)szTimeZoneStd, strlen(szTimeZoneStd));
     1163    RegSetValueEx(hkey, "StandardBias",0,REG_DWORD, (LPBYTE)&bias, sizeof(bias));
     1164    RegSetValueEx(hkey, "StandardStart",0,REG_BINARY, (LPBYTE)&stime, sizeof(stime));
     1165    RegSetValueEx(hkey, "DaylightName", 0, REG_SZ, (LPBYTE)szTimeZoneDay, strlen(szTimeZoneDay));
     1166    RegSetValueEx(hkey, "DaylightBias",0,REG_DWORD, (LPBYTE)&bias, sizeof(bias));
     1167    RegSetValueEx(hkey, "DaylightStart",0,REG_BINARY, (LPBYTE)&dtime, sizeof(dtime));
     1168    RegCloseKey(hkey);
     1169
     1170    TIME_ZONE_INFORMATION tzinfo;
     1171
     1172    tzinfo.Bias         = bias;
     1173    lstrcpynAtoW(tzinfo.StandardName, szTimeZoneStd, sizeof(tzinfo.StandardName)/sizeof(WCHAR));
     1174    tzinfo.StandardDate = stime;
     1175    tzinfo.StandardBias = bias;
     1176    lstrcpynAtoW(tzinfo.DaylightName, szTimeZoneDay, sizeof(tzinfo.StandardName)/sizeof(WCHAR));
     1177    tzinfo.DaylightDate = dtime;
     1178    tzinfo.DaylightBias = bias;
     1179
     1180    SetTimeZoneInformation(&tzinfo);
     1181}
     1182//******************************************************************************
     1183//******************************************************************************
     1184
Note: See TracChangeset for help on using the changeset viewer.