else {    DWORD dwLen; char tempDirToCleanup[MAX_BUF]; int i = 1;  lstrcpy(tempDirToCleanup, szTempDir); dwLen = lstrlen(tempDirToCleanup); itoa(i, (tempDirToCleanup + dwLen), 10); for(i = 2; i <= 100 && (FileExists(tempDirToCleanup)); i++) { DirectoryRemove(tempDirToCleanup, TRUE); itoa(i, (tempDirToCleanup + dwLen), 10); } }
HRESULT Initialize(HINSTANCE hInstance){  char szBuf[MAX_BUF];  char szCurrentProcessDir[MAX_BUF];  bSDUserCanceled        = FALSE;  hDlgMessage            = NULL;  /* load strings from setup.exe */  if(NS_LoadStringAlloc(hInstance, IDS_ERROR_GLOBALALLOC, &szEGlobalAlloc, MAX_BUF))    return(1);  if(NS_LoadStringAlloc(hInstance, IDS_ERROR_STRING_LOAD, &szEStringLoad,  MAX_BUF))    return(1);  if(NS_LoadStringAlloc(hInstance, IDS_ERROR_DLL_LOAD,    &szEDllLoad,     MAX_BUF))    return(1);  if(NS_LoadStringAlloc(hInstance, IDS_ERROR_STRING_NULL, &szEStringNull,  MAX_BUF))    return(1);  if(NS_LoadStringAlloc(hInstance, IDS_ERROR_OUTOFMEMORY, &szEOutOfMemory, MAX_BUF))    return(1);  GetModuleFileName(NULL, szBuf, sizeof(szBuf));  ParsePath(szBuf, szCurrentProcessDir,            sizeof(szCurrentProcessDir),            FALSE,            PP_PATH_ONLY);  hAccelTable = LoadAccelerators(hInstance, CLASS_NAME_SETUP_DLG);  if((hSetupRscInst = LoadLibraryEx("Setuprsc.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) == NULL)  {    char szFullFilename[MAX_BUF];    lstrcpy(szFullFilename, szCurrentProcessDir);    AppendBackSlash(szFullFilename, sizeof(szFullFilename));    lstrcat(szFullFilename, "Setuprsc.dll");    if((hSetupRscInst = LoadLibraryEx(szFullFilename, NULL, 0)) == NULL)    {      wsprintf(szBuf, szEDllLoad, szFullFilename);      PrintError(szBuf, ERROR_CODE_HIDE);      return(WIZ_ERROR_LOADING_RESOURCE_LIB);    }  }  dwWizardState          = DLG_NONE;  dwTempSetupType        = dwWizardState;  siComponents           = NULL;  bCreateDestinationDir  = FALSE;  bReboot                = FALSE;  gdwUpgradeValue        = UG_NONE;  gdwSiteSelectorStatus  = SS_SHOW;  gbILUseTemp            = TRUE;  gbIgnoreRunAppX        = FALSE;  gbIgnoreProgramFolderX = FALSE;  if((szSetupDir = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  lstrcpy(szSetupDir, szCurrentProcessDir);  if((szTempDir = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  if((szOSTempDir = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  if((szProxyDLLPath = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  if((szFileIniConfig = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  if((szFileIniInstall = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  // determine the system's TEMP path  if(GetTempPath(MAX_BUF, szTempDir) == 0)  {    if(GetWindowsDirectory(szTempDir, MAX_BUF) == 0)    {      char szEGetWinDirFailed[MAX_BUF];      if(GetPrivateProfileString("Messages", "ERROR_GET_WINDOWS_DIRECTORY_FAILED", "", szEGetWinDirFailed, sizeof(szEGetWinDirFailed), szFileIniInstall))        PrintError(szEGetWinDirFailed, ERROR_CODE_SHOW);      return(1);    }    AppendBackSlash(szTempDir, MAX_BUF);    lstrcat(szTempDir, "TEMP");  }  lstrcpy(szOSTempDir, szTempDir);  AppendBackSlash(szTempDir, MAX_BUF);  lstrcat(szTempDir, WIZ_TEMP_DIR);  /*  if multiple installer instances are allowed;       each instance requires a unique temp directory   */  if(gbAllowMultipleInstalls)  {    DWORD dwLen = lstrlen(szTempDir);    if (strncmp(szSetupDir, szTempDir, dwLen) == 0)    {      lstrcpy(szTempDir, szSetupDir);    }    else    {      int i;      for(i = 1; i <= 100 && (FileExists(szTempDir) != FALSE); i++)      {        itoa(i, (szTempDir + dwLen), 10);      }          if (FileExists(szTempDir) != FALSE)      {        MessageBox(hWndMain, "Cannot create temp directory", NULL, MB_OK | MB_ICONEXCLAMATION);        exit(1);      }    }  }  if(!FileExists(szTempDir))  {    AppendBackSlash(szTempDir, MAX_BUF);    CreateDirectoriesAll(szTempDir, DO_NOT_ADD_TO_UNINSTALL_LOG);    if(!FileExists(szTempDir))    {      char szECreateTempDir[MAX_BUF];      if(GetPrivateProfileString("Messages", "ERROR_CREATE_TEMP_DIR", "", szECreateTempDir, sizeof(szECreateTempDir), szFileIniInstall))      {        wsprintf(szBuf, szECreateTempDir, szTempDir);        PrintError(szBuf, ERROR_CODE_HIDE);      }      return(1);    }    RemoveBackSlash(szTempDir);  }  /* Check if we need to load GRE App installer proxy DLL;     this DLL lives in the Windows temp directory when the      external GRE app installer is running. If found, it      will be loaded and fed with incremental progress updates.  */    GetTempPath(MAX_BUF, szProxyDLLPath);  AppendBackSlash(szProxyDLLPath, MAX_BUF);  strcat(szProxyDLLPath, GRE_APP_INSTALLER_PROXY_DLL);    if (FileExists(szProxyDLLPath) != FALSE)    hGREAppInstallerProxyDLL = LoadLibrary(szProxyDLLPath);    if (hGREAppInstallerProxyDLL != NULL)    lpfnProgressUpd = (LPFNDLLFUNC) GetProcAddress(hGREAppInstallerProxyDLL, GRE_PROXY_UPD_FUNC);                               hbmpBoxChecked         = LoadBitmap(hSetupRscInst, MAKEINTRESOURCE(IDB_BOX_CHECKED));  hbmpBoxCheckedDisabled = LoadBitmap(hSetupRscInst, MAKEINTRESOURCE(IDB_BOX_CHECKED_DISABLED));  hbmpBoxUnChecked       = LoadBitmap(hSetupRscInst, MAKEINTRESOURCE(IDB_BOX_UNCHECKED));  DeleteIdiGetConfigIni();  bIdiArchivesExists = DeleteIdiGetArchives();  DeleteIdiGetRedirect();  DeleteInstallLogFile(FILE_INSTALL_LOG);  DeleteInstallLogFile(FILE_INSTALL_STATUS_LOG);  LogISTime(W_START);  DetermineOSVersionEx();  SystemParametersInfo(SPI_GETSCREENREADER, 0, &(gSystemInfo.bScreenReader), 0);  return(0);}