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];  hDlgMessage = NULL;  DetermineOSVersion();  gdwWhatToDo = WTD_ASK;  /* load strings from setup.exe */  if(NS_LoadStringAlloc(hInst, IDS_ERROR_GLOBALALLOC, &szEGlobalAlloc, MAX_BUF))    return(1);  if(NS_LoadStringAlloc(hInst, IDS_ERROR_STRING_LOAD, &szEStringLoad,  MAX_BUF))    return(1);  if(NS_LoadStringAlloc(hInst, IDS_ERROR_DLL_LOAD,    &szEDllLoad,     MAX_BUF))    return(1);  if(NS_LoadStringAlloc(hInst, IDS_ERROR_STRING_NULL, &szEStringNull,  MAX_BUF))    return(1);  ZeroMemory(szBuf, sizeof(MAX_BUF));  if((szClassName = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  lstrcpy(szClassName, CLASS_NAME_UNINSTALL_DLG);  hAccelTable = LoadAccelerators(hInst, szClassName);  if((szUninstallDir = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  GetModuleFileName(NULL, szBuf, sizeof(szBuf));  ParsePath(szBuf, szUninstallDir, MAX_BUF, PP_PATH_ONLY);  if((szTempDir = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  if((szOSTempDir = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  if((szFileIniUninstall = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  lstrcpy(szFileIniUninstall, szUninstallDir);  AppendBackSlash(szFileIniUninstall, MAX_BUF);  lstrcat(szFileIniUninstall, FILE_INI_UNINSTALL);  if((szFileIniDefaultsInfo = NS_GlobalAlloc(MAX_BUF)) == NULL)    return(1);  lstrcpy(szFileIniDefaultsInfo, szUninstallDir);  AppendBackSlash(szFileIniDefaultsInfo, MAX_BUF);  GetPrivateProfileString("General", "Defaults Info Filename", "", szBuf, MAX_BUF, szFileIniUninstall);  lstrcat(szFileIniDefaultsInfo, szBuf);  // 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),                                 szFileIniUninstall))        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(szUninstallDir, szTempDir, dwLen) == 0)    {      lstrcpy(szTempDir, szUninstallDir);    }    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);    if(!FileExists(szTempDir))    {      char szECreateTempDir[MAX_BUF];      if(GetPrivateProfileString("Messages", "ERROR_CREATE_TEMP_DIR", "",                                 szECreateTempDir, sizeof(szECreateTempDir),                                  szFileIniUninstall))      {        wsprintf(szBuf, szECreateTempDir, szTempDir);        PrintError(szBuf, ERROR_CODE_HIDE);      }      return(1);    }    RemoveBackSlash(szTempDir);  }  ugUninstall.bVerbose = FALSE;  ugUninstall.bUninstallFiles = TRUE;  ugUninstall.bSharedInst = FALSE;  return(0);}