Ignore:
Timestamp:
Dec 23, 2010, 6:54:11 AM (15 years ago)
Author:
dmik
Message:

Deduce Windows Time Zone information from the TZ environment variable.

File:
1 edited

Legend:

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

    r10169 r21535  
    10881088}
    10891089//******************************************************************************
    1090 //[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
    1091 //"Bias"=dword:ffffffc4
    1092 //"StandardName"="Romance Standard Time"
    1093 //"StandardBias"=dword:00000000
    1094 //"StandardStart"=hex:00,00,0a,00,05,00,03,00,00,00,00,00,00,00,00,00
    1095 // typedef struct _SYSTEMTIME {
    1096 //  WORD wYear;
    1097 //  WORD wMonth;
    1098 //  WORD wDayOfWeek;
    1099 //  WORD wDay;
    1100 //  WORD wHour;
    1101 //  WORD wMinute;
    1102 //  WORD wSecond;
    1103 //  WORD wMilliseconds;
    1104 //} SYSTEMTIME, *PSYSTEMTIME;
    1105 //"DaylightName"="Romance Daylight Time"
    1106 //"DaylightBias"=dword:ffffffc4
    1107 //"DaylightStart"=hex:00,00,03,00,05,00,02,00,00,00,00,00,00,00,00,00
    1108 //"ActiveTimeBias"=dword:ffffffc4
    1109 //******************************************************************************
     1090//******************************************************************************
     1091extern "C" const char *TimeZones;
     1092extern "C" int ProcessEmbeddedFile(const char *data, BOOL force);
    11101093void SetupTimeZoneInfo()
    11111094{
    1112     HKEY hkey;
    1113     DWORD val = 0;
    1114     char szTimeZoneStd[4];
    1115     char szTimeZoneDay[4];
    1116     int  sign = FALSE;
    1117     int  bias;
    1118     char *pszTZ = NULL;
    1119     SYSTEMTIME stime = {0};
    1120     SYSTEMTIME dtime = {0};
    1121 
    1122     if (RegCreateKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", &hkey) != ERROR_SUCCESS)
    1123     {
    1124         dprintf(("SetupTimeZoneInfo: Unable to create key"));
    1125         return;
    1126     }
    1127     //Little bit difficult to map the 3 letter timezone to a name
    1128     //(duplicate values for different regions)
    1129     //So we just copy that timezone string and hope the apps don't really
    1130     //on hardcoded timezone names.
    1131 
    1132     //parse TZ environment variable
    1133     pszTZ = getenv("TZ");
    1134     if(pszTZ == NULL) {
    1135         //default is Central European Time
    1136         pszTZ = "CET-1CDT";
    1137     }
    1138     strncpy(szTimeZoneStd, pszTZ, 3);
    1139     szTimeZoneStd[3] = 0;
    1140     if(pszTZ[3] == '-') {
    1141          sign   = TRUE;
    1142          pszTZ += 4;
    1143     }
    1144     else pszTZ += 3;
    1145 
    1146     if(isdigit(*pszTZ)) {
    1147         bias = (int)(*pszTZ - '0') * 60;
    1148         pszTZ++;
    1149         if(isdigit(*pszTZ)) {//double digit hour difference
    1150             bias *= 10;
    1151             bias += (int)(*pszTZ - '0') * 60;
    1152             pszTZ++;
    1153         }
    1154     }
    1155     else bias = 0;
    1156 
    1157     if(sign) bias = -bias;
    1158 
    1159     if(isalpha(*pszTZ)) {//daylight timezone name follows
    1160          strncpy(szTimeZoneDay, pszTZ, 3);
    1161          szTimeZoneDay[3] = 0;
    1162     }
    1163     else szTimeZoneDay[0] = 0;
    1164 
    1165     RegSetValueEx(hkey, "Bias",0,REG_DWORD, (LPBYTE)&bias, sizeof(bias));
    1166     RegSetValueEx(hkey, "ActiveTimeBias",0,REG_DWORD, (LPBYTE)&bias, sizeof(bias));
    1167 
    1168     RegSetValueEx(hkey, "StandardName", 0, REG_SZ, (LPBYTE)szTimeZoneStd, strlen(szTimeZoneStd));
    1169     RegSetValueEx(hkey, "StandardBias",0,REG_DWORD, (LPBYTE)&bias, sizeof(bias));
    1170     RegSetValueEx(hkey, "StandardStart",0,REG_BINARY, (LPBYTE)&stime, sizeof(stime));
    1171     RegSetValueEx(hkey, "DaylightName", 0, REG_SZ, (LPBYTE)szTimeZoneDay, strlen(szTimeZoneDay));
    1172     RegSetValueEx(hkey, "DaylightBias",0,REG_DWORD, (LPBYTE)&bias, sizeof(bias));
    1173     RegSetValueEx(hkey, "DaylightStart",0,REG_BINARY, (LPBYTE)&dtime, sizeof(dtime));
    1174     RegCloseKey(hkey);
    1175 
    1176     TIME_ZONE_INFORMATION tzinfo;
    1177 
    1178     tzinfo.Bias         = bias;
    1179     lstrcpynAtoW(tzinfo.StandardName, szTimeZoneStd, sizeof(tzinfo.StandardName)/sizeof(WCHAR));
    1180     tzinfo.StandardDate = stime;
    1181     tzinfo.StandardBias = bias;
    1182     lstrcpynAtoW(tzinfo.DaylightName, szTimeZoneDay, sizeof(tzinfo.StandardName)/sizeof(WCHAR));
    1183     tzinfo.DaylightDate = dtime;
    1184     tzinfo.DaylightBias = bias;
    1185 
    1186     SetTimeZoneInformation(&tzinfo);
     1095        ProcessEmbeddedFile(TimeZones, TRUE);
    11871096}
    11881097//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.