Changeset 21535 for trunk/tools


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.

Location:
trunk/tools
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/install/makefile

    r21458 r21535  
    2929#
    3030OBJS = \
    31 $(OBJDIR)\odininst.obj
    32 
     31$(OBJDIR)\odininst.obj \
     32$(OBJDIR)\regapi.obj \
     33$(OBJDIR)\tz.obj
    3334
    3435#
  • 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//******************************************************************************
  • trunk/tools/regedit/regapi.c

    r21534 r21535  
    475475  memset(buf, 0, bufLen);
    476476
     477#ifndef ODININST
    477478  /*
    478479   * warn the user if we are here with a string longer than 2 bytes that does
     
    482483    printf("regapi: WARNING converting CSV hex stream with no comma, "
    483484           "input data seems invalid.\n");
     485#endif
    484486
    485487  while (strPos < strLen)
     
    681683
    682684  hRes = setValue(argv);
     685#ifndef ODININST
    683686  if ( hRes == ERROR_SUCCESS )
    684687    printf(
     
    700703      argv[0],
    701704      argv[1]);
     705#endif
    702706}
    703707
     
    814818
    815819
     820#ifndef ODININST
    816821  if ( hRes == ERROR_SUCCESS )
    817822    printf(
     
    825830      keyValue,
    826831      currentKeyName);
     832#endif
    827833
    828834  /*
     
    878884      closeKey();                    /* Close the previous key before */
    879885
    880     if ( openKey(stdInput) != ERROR_SUCCESS )
     886    if ( openKey(stdInput) != ERROR_SUCCESS ) {
     887#ifndef ODININST
    881888      printf ("regapi: doSetValue failed to open key %s\n", stdInput);
     889#endif
     890    }
    882891  }
    883892  else if( ( bTheKeyIsOpen ) &&
     
    918927      closeKey();                    /* Close the previous key before */
    919928
    920     if ( openKey(stdInput) != ERROR_SUCCESS )
     929    if ( openKey(stdInput) != ERROR_SUCCESS ) {
     930#ifndef ODININST
    921931      printf ("regapi: doSetValue failed to open key %s\n", stdInput);
     932#endif
     933    }
    922934  }
    923935  else if( ( bTheKeyIsOpen ) &&
     
    978990    if (lpfnDLLRegProc)
    979991      retVal = lpfnDLLRegProc();
     992#ifndef ODININST
    980993    else
    981994      printf("regapi: Couldn't find DllRegisterServer proc in '%s'.\n", stdInput);
     
    983996    if (retVal != S_OK)
    984997      printf("regapi: DLLRegisterServer error 0x%x in '%s'.\n", retVal, stdInput);
     998#endif
    985999
    9861000    FreeLibrary(theLib);
    9871001  }
     1002#ifndef ODININST
    9881003  else
    9891004  {
    9901005    printf("regapi: Could not load DLL '%s'.\n", stdInput);
    9911006  }
     1007#endif
    9921008}
    9931009
     
    10111027    if (lpfnDLLRegProc)
    10121028      retVal = lpfnDLLRegProc();
     1029#ifndef ODININST
    10131030    else
    10141031      printf("regapi: Couldn't find DllUnregisterServer proc in '%s'.\n", stdInput);
     
    10161033    if (retVal != S_OK)
    10171034      printf("regapi: DLLUnregisterServer error 0x%x in '%s'.\n", retVal, stdInput);
     1035#endif
    10181036
    10191037    FreeLibrary(theLib);
    10201038  }
     1039#ifndef ODININST
    10211040  else
    10221041  {
    10231042    printf("regapi: Could not load DLL '%s'.\n", stdInput);
    10241043  }
    1025 }
     1044#endif
     1045}
     1046
     1047#ifndef ODININST
    10261048
    10271049/******************************************************************************
     
    11441166  return SUCCESS;
    11451167}
     1168
     1169#else /* !ODININST */
     1170
     1171/******************************************************************************
     1172 * Treats the given data string as an embedded text file and executes the
     1173 * setValue command on it. The function expects '\n' as line separators.
     1174 */
     1175int ProcessEmbeddedFile(const char *data, BOOL force)
     1176{
     1177    LPSTR  curLine      = NULL;  /* line read from data */
     1178    ULONG  curSize      = STDIN_MAX_LEN;
     1179    const char *curData = data;
     1180    INT cmdIndex;
     1181
     1182    bForce = force;
     1183
     1184    curLine = HeapAlloc(GetProcessHeap(), 0, STDIN_MAX_LEN);
     1185    if (curLine == NULL)
     1186      return NOT_ENOUGH_MEMORY;
     1187
     1188    cmdIndex = getCommand("setValue");
     1189
     1190    while (TRUE)
     1191    {
     1192        /*
     1193         * read a line
     1194         */
     1195        const char *eol;
     1196        int len, lastLen = 0;
     1197
     1198        while (TRUE)
     1199        {
     1200
     1201            eol = strchr(curData, '\n');
     1202            if (!eol)
     1203                eol = curData + strlen(curData);
     1204            if (!*eol)
     1205                break; // EOF
     1206
     1207            len = eol - curData + 1;
     1208            if (lastLen + len > curSize) {
     1209                curSize = lastLen + len;
     1210                curLine = HeapReAlloc(GetProcessHeap(), 0, curLine, curSize);
     1211                if (curLine == NULL)
     1212                    return NOT_ENOUGH_MEMORY;
     1213            }
     1214
     1215            memcpy(curLine + lastLen, curData, len - 1);
     1216            curLine[lastLen+len-1] = '\0';
     1217            lastLen += len;
     1218            curData += len;
     1219
     1220            if (curLine[lastLen-2] == '\\') {
     1221                // concatenate with the next string
     1222                curLine[lastLen-2] == '\0';
     1223                lastLen -= 2;
     1224            } else {
     1225                break;
     1226            }
     1227        }
     1228
     1229        /*
     1230         * Make some handy generic stuff here...
     1231         */
     1232        if (curLine[0] == '#')
     1233            continue;
     1234
     1235        /*
     1236         * We process every lines even the NULL (last) line, to indicate the
     1237         * end of the processing to the specific process.
     1238         */
     1239        if (!*eol) { /* EOF? */
     1240            commandAPIs[cmdIndex](NULL);
     1241            break;
     1242        } else {
     1243            commandAPIs[cmdIndex](curLine);
     1244        }
     1245    }
     1246
     1247    HeapFree(GetProcessHeap(), 0, curLine);
     1248
     1249    return SUCCESS;
     1250}
     1251
     1252#endif /* !ODININST */
Note: See TracChangeset for help on using the changeset viewer.