Annotation of truecrypt/setup/setup.c, revision 1.1.1.23

1.1.1.11  root        1: /*
1.1.1.13  root        2:  Legal Notice: Some portions of the source code contained in this file were
                      3:  derived from the source code of Encryption for the Masses 2.02a, which is
                      4:  Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
                      5:  Agreement for Encryption for the Masses'. Modifications and additions to
1.1.1.23! root        6:  the original source code (contained in this file) and all other portions
        !             7:  of this file are Copyright (c) 2003-2009 TrueCrypt Developers Association
        !             8:  and are governed by the TrueCrypt License 2.8 the full text of which is
        !             9:  contained in the file License.txt included in TrueCrypt binary and source
        !            10:  code distribution packages. */
1.1       root       11: 
1.1.1.7   root       12: #include "Tcdefs.h"
1.1       root       13: #include <SrRestorePtApi.h>
1.1.1.22  root       14: #include <propkey.h>
                     15: #include <propvarutil.h>
1.1.1.7   root       16: #include <sys/types.h>
                     17: #include <sys/stat.h>
1.1       root       18: 
1.1.1.7   root       19: #include "Apidrvr.h"
1.1.1.13  root       20: #include "BootEncryption.h"
1.1.1.22  root       21: #include "Boot/Windows/BootCommon.h"
1.1.1.7   root       22: #include "Combo.h"
1.1.1.11  root       23: #include "ComSetup.h"
1.1.1.7   root       24: #include "Dlgcode.h"
                     25: #include "Language.h"
                     26: #include "Registry.h"
                     27: #include "Resource.h"
1.1       root       28: 
1.1.1.7   root       29: #include "Dir.h"
                     30: #include "Setup.h"
1.1.1.13  root       31: #include "SelfExtract.h"
                     32: #include "Wizard.h"
1.1       root       33: 
1.1.1.7   root       34: #include "../Common/Resource.h"
1.1       root       35: 
1.1.1.13  root       36: using namespace TrueCrypt;
                     37: 
1.1       root       38: #pragma warning( disable : 4201 )
                     39: #pragma warning( disable : 4115 )
                     40: 
                     41: #include <shlobj.h>
                     42: 
                     43: #pragma warning( default : 4201 )
                     44: #pragma warning( default : 4115 )
                     45: 
1.1.1.13  root       46: char InstallationPath[TC_MAX_PATH];
1.1.1.8   root       47: char SetupFilesDir[TC_MAX_PATH];
1.1.1.11  root       48: char UninstallBatch[MAX_PATH];
1.1.1.8   root       49: 
1.1       root       50: BOOL bUninstall = FALSE;
1.1.1.18  root       51: BOOL bRestartRequired = FALSE; // If TRUE, the installer does not allow the user to exit it until he restarts the computer. This blocks the app setup mutex and the user cannot run TrueCrypt until he restarts.
1.1.1.13  root       52: BOOL bMakePackage = FALSE;
1.1       root       53: BOOL bDone = FALSE;
1.1.1.11  root       54: BOOL Rollback = FALSE;
                     55: BOOL bUpgrade = FALSE;
1.1.1.18  root       56: BOOL bDowngrade = FALSE;
1.1.1.14  root       57: BOOL SystemEncryptionUpgrade = FALSE;
1.1.1.13  root       58: BOOL bRepairMode = FALSE;
                     59: BOOL bChangeMode = FALSE;
                     60: BOOL bDevm = FALSE;
1.1.1.11  root       61: BOOL bFirstTimeInstall = FALSE;
1.1.1.13  root       62: BOOL bUninstallInProgress = FALSE;
1.1.1.22  root       63: BOOL UnloadDriver = TRUE;
1.1.1.13  root       64: 
                     65: BOOL bSystemRestore = TRUE;
1.1.1.18  root       66: BOOL bDisableSwapFiles = FALSE;
1.1.1.13  root       67: BOOL bForAllUsers = TRUE;
                     68: BOOL bRegisterFileExt = TRUE;
                     69: BOOL bAddToStartMenu = TRUE;
                     70: BOOL bDesktopIcon = TRUE;
1.1       root       71: 
1.1.1.23! root       72: BOOL bDesktopIconStatusDetermined = FALSE;
        !            73: 
1.1.1.13  root       74: HMODULE volatile SystemRestoreDll = 0;
1.1       root       75: 
1.1.1.17  root       76: void localcleanup (void)
                     77: {
                     78:        localcleanupwiz ();
                     79:        cleanup ();
                     80: 
                     81:        CloseAppSetupMutex ();
                     82: }
                     83: 
1.1.1.18  root       84: BOOL StatDeleteFile (char *lpszFile)
1.1       root       85: {
                     86:        struct __stat64 st;
                     87: 
                     88:        if (_stat64 (lpszFile, &st) == 0)
                     89:                return DeleteFile (lpszFile);
                     90:        else
                     91:                return TRUE;
                     92: }
                     93: 
1.1.1.18  root       94: BOOL StatRemoveDirectory (char *lpszDir)
1.1       root       95: {
                     96:        struct __stat64 st;
                     97: 
                     98:        if (_stat64 (lpszDir, &st) == 0)
                     99:                return RemoveDirectory (lpszDir);
                    100:        else
                    101:                return TRUE;
                    102: }
                    103: 
1.1.1.18  root      104: HRESULT CreateLink (char *lpszPathObj, char *lpszArguments,
1.1       root      105:            char *lpszPathLink)
                    106: {
                    107:        HRESULT hres;
                    108:        IShellLink *psl;
                    109: 
                    110:        /* Get a pointer to the IShellLink interface.  */
1.1.1.13  root      111:        hres = CoCreateInstance (CLSID_ShellLink, NULL,
                    112:                               CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
1.1       root      113:        if (SUCCEEDED (hres))
                    114:        {
                    115:                IPersistFile *ppf;
                    116: 
                    117:                /* Set the path to the shortcut target, and add the
                    118:                   description.  */
1.1.1.13  root      119:                psl->SetPath (lpszPathObj);
                    120:                psl->SetArguments (lpszArguments);
1.1       root      121: 
1.1.1.22  root      122:                // Application ID
                    123:                if (strstr (lpszPathObj, TC_APP_NAME ".exe"))
                    124:                {
                    125:                        IPropertyStore *propStore;
                    126: 
                    127:                        if (SUCCEEDED (psl->QueryInterface (IID_PPV_ARGS (&propStore))))
                    128:                        {
                    129:                                PROPVARIANT propVariant;
                    130:                                if (SUCCEEDED (InitPropVariantFromString (TC_APPLICATION_ID, &propVariant)))
                    131:                                {
                    132:                                        if (SUCCEEDED (propStore->SetValue (PKEY_AppUserModel_ID, propVariant)))
                    133:                                                propStore->Commit();
                    134: 
                    135:                                        PropVariantClear (&propVariant);
                    136:                                }
                    137: 
                    138:                                propStore->Release();
                    139:                        }
                    140:                }
                    141: 
1.1       root      142:                /* Query IShellLink for the IPersistFile interface for saving
                    143:                   the shortcut in persistent storage.  */
1.1.1.13  root      144:                hres = psl->QueryInterface (IID_IPersistFile,
                    145:                                                    (void **) &ppf);
1.1       root      146: 
                    147:                if (SUCCEEDED (hres))
                    148:                {
1.1.1.13  root      149:                        wchar_t wsz[TC_MAX_PATH];
1.1       root      150: 
                    151:                        /* Ensure that the string is ANSI.  */
                    152:                        MultiByteToWideChar (CP_ACP, 0, lpszPathLink, -1,
1.1.1.15  root      153:                                             wsz, sizeof(wsz) / sizeof(wsz[0]));
1.1       root      154: 
                    155:                        /* Save the link by calling IPersistFile::Save.  */
1.1.1.13  root      156:                        hres = ppf->Save (wsz, TRUE);
                    157:                        ppf->Release ();
1.1       root      158:                }
1.1.1.13  root      159:                psl->Release ();
1.1       root      160:        }
                    161:        return hres;
                    162: }
                    163: 
1.1.1.18  root      164: void GetProgramPath (HWND hwndDlg, char *path)
1.1       root      165: {
                    166:        ITEMIDLIST *i;
                    167:        HRESULT res;
                    168: 
1.1.1.13  root      169:        if (bForAllUsers)
1.1       root      170:         res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_COMMON_PROGRAMS, &i);
                    171:        else
                    172:         res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAMS, &i);
                    173: 
                    174:        SHGetPathFromIDList (i, path);
                    175: }
                    176: 
1.1.1.18  root      177: void StatusMessage (HWND hwndDlg, char *stringId)
1.1       root      178: {
1.1.1.11  root      179:        if (Rollback)
                    180:                return;
                    181: 
1.1.1.13  root      182:        SendMessageW (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_ADDSTRING, 0, (LPARAM) GetString (stringId));
1.1.1.11  root      183: 
1.1.1.13  root      184:        SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_SETTOPINDEX, 
                    185:                SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_GETCOUNT, 0, 0) - 1, 0);
1.1       root      186: }
                    187: 
1.1.1.18  root      188: void StatusMessageParam (HWND hwndDlg, char *stringId, char *param)
1.1       root      189: {
1.1.1.7   root      190:        wchar_t szTmp[1024];
1.1.1.11  root      191: 
                    192:        if (Rollback)
                    193:                return;
                    194: 
1.1.1.7   root      195:        wsprintfW (szTmp, L"%s %hs", GetString (stringId), param);
1.1.1.13  root      196:        SendMessageW (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_ADDSTRING, 0, (LPARAM) szTmp);
1.1.1.7   root      197:                
1.1.1.13  root      198:        SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_SETTOPINDEX, 
                    199:                SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_GETCOUNT, 0, 0) - 1, 0);
                    200: }
                    201: 
1.1.1.18  root      202: void ClearLogWindow (HWND hwndDlg)
1.1.1.13  root      203: {
                    204:        SendMessage (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_RESETCONTENT, 0, 0);
1.1       root      205: }
                    206: 
1.1.1.18  root      207: void RegMessage (HWND hwndDlg, char *txt)
1.1       root      208: {
1.1.1.7   root      209:        StatusMessageParam (hwndDlg, "ADDING_REG", txt);
1.1       root      210: }
                    211: 
1.1.1.18  root      212: void CopyMessage (HWND hwndDlg, char *txt)
1.1       root      213: {
1.1.1.11  root      214:        StatusMessageParam (hwndDlg, "INSTALLING", txt);
1.1       root      215: }
                    216: 
1.1.1.18  root      217: void RemoveMessage (HWND hwndDlg, char *txt)
1.1       root      218: {
1.1.1.11  root      219:        if (!Rollback)
                    220:                StatusMessageParam (hwndDlg, "REMOVING", txt);
1.1       root      221: }
                    222: 
1.1.1.18  root      223: void IconMessage (HWND hwndDlg, char *txt)
1.1       root      224: {
1.1.1.7   root      225:        StatusMessageParam (hwndDlg, "ADDING_ICON", txt);
1.1       root      226: }
                    227: 
1.1.1.22  root      228: void DetermineUpgradeDowngradeStatus (BOOL bCloseDriverHandle, LONG *driverVersionPtr)
                    229: {
                    230:        LONG driverVersion = VERSION_NUM;
                    231: 
                    232:        if (hDriver == INVALID_HANDLE_VALUE)
                    233:                DriverAttach();
                    234: 
                    235:        if (hDriver != INVALID_HANDLE_VALUE)
                    236:        {
                    237:                DWORD dwResult;
                    238:                BOOL bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
                    239: 
                    240:                if (!bResult)
                    241:                        bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
                    242: 
                    243:                bUpgrade = (bResult && driverVersion < VERSION_NUM);
                    244:                bDowngrade = (bResult && driverVersion > VERSION_NUM);
                    245: 
                    246:                if (bCloseDriverHandle)
                    247:                {
                    248:                        CloseHandle (hDriver);
                    249:                        hDriver = INVALID_HANDLE_VALUE;
                    250:                }
                    251:        }
                    252: 
                    253:        *driverVersionPtr = driverVersion;
                    254: }
1.1       root      255: 
1.1.1.23! root      256: 
        !           257: static BOOL IsFileInUse (const string &filePath)
        !           258: {
        !           259:        HANDLE useTestHandle = CreateFile (filePath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
        !           260: 
        !           261:        if (useTestHandle != INVALID_HANDLE_VALUE)
        !           262:                CloseHandle (useTestHandle);
        !           263:        else if (GetLastError() == ERROR_SHARING_VIOLATION)
        !           264:                return TRUE;
        !           265: 
        !           266:        return FALSE;
        !           267: }
        !           268: 
        !           269: 
1.1.1.13  root      270: BOOL DoFilesInstall (HWND hwndDlg, char *szDestDir)
1.1       root      271: {
1.1.1.13  root      272:        /* WARNING: Note that, despite its name, this function is used during UNinstallation as well. */
1.1       root      273: 
                    274:        char szTmp[TC_MAX_PATH];
                    275:        BOOL bOK = TRUE;
1.1.1.13  root      276:        int i, x, fileNo;
                    277:        char curFileName [TC_MAX_PATH] = {0};
                    278: 
                    279:        if (!bUninstall && !bDevm)
                    280:        {
                    281:                // Self-extract all files to memory
                    282: 
                    283:                GetModuleFileName (NULL, szTmp, sizeof (szTmp));
                    284: 
                    285:                if (!SelfExtractInMemory (szTmp))
                    286:                        return FALSE;
                    287:        }
1.1       root      288: 
1.1.1.11  root      289:        x = strlen (szDestDir);
1.1.1.13  root      290:        if (x < 2)
1.1.1.11  root      291:                return FALSE;
                    292: 
                    293:        if (szDestDir[x - 1] != '\\')
                    294:                strcat (szDestDir, "\\");
1.1       root      295: 
                    296:        for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
                    297:        {
1.1.1.11  root      298:                BOOL bResult;
1.1       root      299:                char szDir[TC_MAX_PATH];
                    300: 
1.1.1.13  root      301:                if (strstr (szFiles[i], "TrueCrypt Setup") != 0)
                    302:                {
                    303:                        if (bUninstall)
                    304:                                continue;       // Prevent 'access denied' error
                    305: 
                    306:                        if (bRepairMode)
                    307:                                continue;       // Destination = target
                    308:                }
1.1       root      309: 
                    310:                if (*szFiles[i] == 'A')
                    311:                        strcpy (szDir, szDestDir);
                    312:                else if (*szFiles[i] == 'D')
                    313:                {
1.1.1.10  root      314:                        GetSystemDirectory (szDir, sizeof (szDir));
1.1       root      315: 
1.1.1.11  root      316:                        x = strlen (szDir);
                    317:                        if (szDir[x - 1] != '\\')
1.1       root      318:                                strcat (szDir, "\\");
                    319: 
1.1.1.11  root      320:                        strcat (szDir, "Drivers\\");
1.1       root      321:                }
                    322:                else if (*szFiles[i] == 'W')
                    323:                        GetWindowsDirectory (szDir, sizeof (szDir));
                    324: 
1.1.1.7   root      325:                if (*szFiles[i] == 'I')
1.1       root      326:                        continue;
                    327: 
                    328:                sprintf (szTmp, "%s%s", szDir, szFiles[i] + 1);
                    329: 
                    330:                if (bUninstall == FALSE)
                    331:                        CopyMessage (hwndDlg, szTmp);
                    332:                else
                    333:                        RemoveMessage (hwndDlg, szTmp);
                    334: 
                    335:                if (bUninstall == FALSE)
                    336:                {
1.1.1.8   root      337:                        SetCurrentDirectory (SetupFilesDir);
                    338: 
1.1.1.13  root      339:                        if (strstr (szFiles[i], "TrueCrypt Setup") != 0)
1.1       root      340:                        {
1.1.1.13  root      341:                                // Copy ourselves (the distribution package) to the destination location as 'TrueCrypt Setup.exe'
1.1.1.7   root      342: 
1.1.1.13  root      343:                                char mp[MAX_PATH];
1.1.1.7   root      344: 
1.1.1.13  root      345:                                GetModuleFileName (NULL, mp, sizeof (mp));
                    346:                                bResult = TCCopyFile (mp, szTmp);
                    347:                        }
                    348:                        else
                    349:                        {
                    350:                                strncpy (curFileName, szFiles[i] + 1, strlen (szFiles[i]) - 1);
                    351:                                curFileName [strlen (szFiles[i]) - 1] = 0;
                    352: 
                    353:                                if (Is64BitOs ()
                    354:                                        && strcmp (szFiles[i], "Dtruecrypt.sys") == 0)
                    355:                                {
                    356:                                        strncpy (curFileName, FILENAME_64BIT_DRIVER, sizeof (FILENAME_64BIT_DRIVER));
                    357:                                }
                    358: 
                    359:                                if (!bDevm)
                    360:                                {
                    361:                                        bResult = FALSE;
                    362: 
                    363:                                        // Find the correct decompressed file in memory
                    364:                                        for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
                    365:                                        {
                    366:                                                // Write the file (stored in memory) directly to the destination location 
                    367:                                                // (there will be no temporary files).
                    368:                                                if (memcmp (
                    369:                                                        curFileName, 
                    370:                                                        Decompressed_Files[fileNo].fileName, 
                    371:                                                        min (strlen (curFileName), (size_t) Decompressed_Files[fileNo].fileNameLength)) == 0)
                    372:                                                {
                    373:                                                        bResult = SaveBufferToFile (
                    374:                                                                (char *) Decompressed_Files[fileNo].fileContent,
                    375:                                                                szTmp,
                    376:                                                                Decompressed_Files[fileNo].fileLength, 
                    377:                                                                FALSE);
                    378: 
                    379:                                                        break;
                    380:                                                }
                    381:                                        }
                    382:                                }
                    383:                                else
                    384:                                {
                    385:                                        bResult = TCCopyFile (curFileName, szTmp);
                    386:                                }
1.1.1.23! root      387: 
        !           388:                                if (bResult && strcmp (szFiles[i], "ATrueCrypt.exe") == 0)
        !           389:                                {
        !           390:                                        string servicePath = GetServiceConfigPath (TC_APP_NAME ".exe");
        !           391:                                        if (FileExists (servicePath.c_str()))
        !           392:                                        {
        !           393:                                                CopyMessage (hwndDlg, (char *) servicePath.c_str());
        !           394:                                                bResult = CopyFile (szTmp, servicePath.c_str(), FALSE);
        !           395:                                        }
        !           396:                                }
1.1       root      397:                        }
                    398:                }
                    399:                else
                    400:                {
                    401:                        bResult = StatDeleteFile (szTmp);
                    402:                }
                    403: 
                    404:                if (bResult == FALSE)
                    405:                {
                    406:                        LPVOID lpMsgBuf;
                    407:                        DWORD dwError = GetLastError ();
1.1.1.7   root      408:                        wchar_t szTmp2[700];
1.1       root      409: 
                    410:                        FormatMessage (
                    411:                                              FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                    412:                                              NULL,
                    413:                                              dwError,
                    414:                                 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),    /* Default language */
                    415:                                              (char *) &lpMsgBuf,
                    416:                                              0,
                    417:                                              NULL
                    418:                                );
                    419: 
                    420: 
                    421:                        if (bUninstall == FALSE)
1.1.1.7   root      422:                                wsprintfW (szTmp2, GetString ("INSTALL_OF_FAILED"), szTmp, lpMsgBuf);
1.1       root      423:                        else
1.1.1.7   root      424:                                wsprintfW (szTmp2, GetString ("UNINSTALL_OF_FAILED"), szTmp, lpMsgBuf);
1.1       root      425: 
                    426:                        LocalFree (lpMsgBuf);
                    427: 
1.1.1.11  root      428:                        if (!Silent && MessageBoxW (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
1.1       root      429:                                return FALSE;
                    430:                }
1.1.1.7   root      431:        }
1.1       root      432: 
1.1.1.7   root      433:        // Language pack
                    434:        if (bUninstall == FALSE)
                    435:        {
                    436:                WIN32_FIND_DATA f;
1.1.1.8   root      437:                HANDLE h;
                    438:                
                    439:                SetCurrentDirectory (SetupFilesDir);
                    440:                h = FindFirstFile ("Language.*.xml", &f);
                    441: 
1.1.1.7   root      442:                if (h != INVALID_HANDLE_VALUE)
                    443:                {
                    444:                        char d[MAX_PATH*2];
1.1.1.11  root      445:                        sprintf (d, "%s%s", szDestDir, f.cFileName);
1.1.1.7   root      446:                        CopyMessage (hwndDlg, d);
                    447:                        TCCopyFile (f.cFileName, d);
                    448:                        FindClose (h);
                    449:                }
1.1.1.8   root      450: 
                    451:                SetCurrentDirectory (SetupFilesDir);
                    452:                SetCurrentDirectory ("Setup files");
                    453:                h = FindFirstFile ("TrueCrypt User Guide.*.pdf", &f);
                    454:                if (h != INVALID_HANDLE_VALUE)
                    455:                {
                    456:                        char d[MAX_PATH*2];
1.1.1.11  root      457:                        sprintf (d, "%s%s", szDestDir, f.cFileName);
1.1.1.8   root      458:                        CopyMessage (hwndDlg, d);
                    459:                        TCCopyFile (f.cFileName, d);
                    460:                        FindClose (h);
                    461:                }
                    462:                SetCurrentDirectory (SetupFilesDir);
1.1       root      463:        }
                    464: 
                    465:        return bOK;
                    466: }
                    467: 
1.1.1.18  root      468: BOOL DoRegInstall (HWND hwndDlg, char *szDestDir, BOOL bInstallType)
1.1       root      469: {
                    470:        char szDir[TC_MAX_PATH], *key;
1.1.1.15  root      471:        char szTmp[TC_MAX_PATH*4];
1.1       root      472:        HKEY hkey = 0;
                    473:        BOOL bSlash, bOK = FALSE;
                    474:        DWORD dw;
                    475:        int x;
                    476: 
1.1.1.19  root      477:        if (SystemEncryptionUpgrade)
                    478:        {
                    479:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt",
                    480:                        0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) == ERROR_SUCCESS)
                    481:                {
                    482:                        strcpy (szTmp, VERSION_STRING);
                    483:                        RegSetValueEx (hkey, "DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1);
                    484: 
1.1.1.21  root      485:                        strcpy (szTmp, TC_HOMEPAGE);
                    486:                        RegSetValueEx (hkey, "URLInfoAbout", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1);
                    487: 
1.1.1.19  root      488:                        RegCloseKey (hkey);
                    489:                }
                    490: 
                    491:                return TRUE;
                    492:        }
                    493: 
1.1       root      494:        strcpy (szDir, szDestDir);
                    495:        x = strlen (szDestDir);
                    496:        if (szDestDir[x - 1] == '\\')
                    497:                bSlash = TRUE;
                    498:        else
                    499:                bSlash = FALSE;
                    500: 
                    501:        if (bSlash == FALSE)
                    502:                strcat (szDir, "\\");
                    503: 
1.1.1.7   root      504:        if (bInstallType)
1.1       root      505:        {
                    506: 
1.1.1.11  root      507:                key = "Software\\Classes\\TrueCryptVolume";
1.1       root      508:                RegMessage (hwndDlg, key);
                    509:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    510:                                    key,
                    511:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    512:                        goto error;
                    513: 
1.1.1.10  root      514:                strcpy (szTmp, "TrueCrypt Volume");
1.1       root      515:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    516:                        goto error;
                    517: 
1.1.1.22  root      518:                sprintf (szTmp, "%ws", TC_APPLICATION_ID);
                    519:                if (RegSetValueEx (hkey, "AppUserModelID", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    520:                        goto error;
                    521: 
1.1       root      522:                RegCloseKey (hkey);
                    523:                hkey = 0;
                    524: 
1.1.1.11  root      525:                key = "Software\\Classes\\TrueCryptVolume\\DefaultIcon";
1.1       root      526:                RegMessage (hwndDlg, key);
                    527:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    528:                                    key,
                    529:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    530:                        goto error;
                    531: 
                    532:                sprintf (szTmp, "%sTrueCrypt.exe,1", szDir);
                    533:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    534:                        goto error;
                    535: 
                    536:                RegCloseKey (hkey);
                    537:                hkey = 0;
                    538: 
1.1.1.11  root      539:                key = "Software\\Classes\\TrueCryptVolume\\Shell\\open\\command";
1.1       root      540:                RegMessage (hwndDlg, key);
                    541:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    542:                                    key,
                    543:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    544:                        goto error;
                    545: 
                    546:                sprintf (szTmp, "\"%sTrueCrypt.exe\" /v \"%%1\"", szDir );
                    547:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    548:                        goto error;
                    549: 
                    550:                RegCloseKey (hkey);
                    551:                hkey = 0;
                    552: 
1.1.1.11  root      553:                key = "Software\\Classes\\.tc";
1.1.1.20  root      554:                BOOL typeClassChanged = TRUE;
                    555:                char typeClass[256];
                    556:                DWORD typeClassSize = sizeof (typeClass);
                    557: 
                    558:                if (ReadLocalMachineRegistryString (key, "", typeClass, &typeClassSize) && typeClassSize > 0 && strcmp (typeClass, "TrueCryptVolume") == 0)
                    559:                        typeClassChanged = FALSE;
                    560: 
1.1       root      561:                RegMessage (hwndDlg, key);
                    562:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    563:                                    key,
                    564:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    565:                        goto error;
                    566: 
                    567:                strcpy (szTmp, "TrueCryptVolume");
                    568:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    569:                        goto error;
1.1.1.11  root      570:                
                    571:                RegCloseKey (hkey);
                    572:                hkey = 0;
1.1.1.20  root      573: 
                    574:                if (typeClassChanged)
                    575:                        SHChangeNotify (SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
1.1       root      576:        }
                    577: 
1.1.1.11  root      578:        key = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt";
                    579:        RegMessage (hwndDlg, key);
                    580:        if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    581:                key,
                    582:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    583:                goto error;
1.1       root      584: 
1.1.1.13  root      585:        /* IMPORTANT: IF YOU CHANGE THIS IN ANY WAY, REVISE AND UPDATE SetInstallationPath() ACCORDINGLY! */ 
                    586:        sprintf (szTmp, "\"%sTrueCrypt Setup.exe\" /u", szDir);
1.1.1.11  root      587:        if (RegSetValueEx (hkey, "UninstallString", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    588:                goto error;
1.1       root      589: 
1.1.1.13  root      590:        sprintf (szTmp, "\"%sTrueCrypt Setup.exe\" /c", szDir);
                    591:        if (RegSetValueEx (hkey, "ModifyPath", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    592:                goto error;
                    593: 
1.1.1.11  root      594:        sprintf (szTmp, "\"%sTrueCrypt Setup.exe\"", szDir);
                    595:        if (RegSetValueEx (hkey, "DisplayIcon", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    596:                goto error;
1.1       root      597: 
1.1.1.13  root      598:        strcpy (szTmp, VERSION_STRING);
                    599:        if (RegSetValueEx (hkey, "DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    600:                goto error;
                    601:                
1.1.1.11  root      602:        strcpy (szTmp, "TrueCrypt");
                    603:        if (RegSetValueEx (hkey, "DisplayName", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    604:                goto error;
1.1       root      605: 
1.1.1.11  root      606:        strcpy (szTmp, "TrueCrypt Foundation");
                    607:        if (RegSetValueEx (hkey, "Publisher", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    608:                goto error;
1.1       root      609: 
1.1.1.21  root      610:        strcpy (szTmp, TC_HOMEPAGE);
1.1.1.11  root      611:        if (RegSetValueEx (hkey, "URLInfoAbout", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    612:                goto error;
                    613:                
1.1       root      614:        bOK = TRUE;
                    615: 
1.1.1.11  root      616: error:
1.1       root      617:        if (hkey != 0)
                    618:                RegCloseKey (hkey);
                    619: 
                    620:        if (bOK == FALSE)
                    621:        {
                    622:                handleWin32Error (hwndDlg);
1.1.1.11  root      623:                Error ("REG_INSTALL_FAILED");
                    624:        }
                    625:        
                    626:        // Register COM servers for UAC
1.1.1.20  root      627:        if (IsOSAtLeast (WIN_VISTA))
1.1.1.11  root      628:        {
                    629:                if (!RegisterComServers (szDir))
                    630:                {
                    631:                        Error ("COM_REG_FAILED");
                    632:                        return FALSE;
                    633:                }
1.1       root      634:        }
                    635: 
                    636:        return bOK;
                    637: }
                    638: 
1.1.1.18  root      639: BOOL DoApplicationDataUninstall (HWND hwndDlg)
1.1.1.7   root      640: {
                    641:        char path[MAX_PATH];
                    642:        char path2[MAX_PATH];
                    643:        BOOL bOK = TRUE;
                    644: 
                    645:        StatusMessage (hwndDlg, "REMOVING_APPDATA");
                    646: 
                    647:        SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
                    648:        strcat (path, "\\TrueCrypt\\");
                    649: 
                    650:        // Delete favorite volumes file
1.1.1.18  root      651:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_FAVORITE_VOLUMES);
1.1.1.7   root      652:        RemoveMessage (hwndDlg, path2);
                    653:        StatDeleteFile (path2);
                    654: 
                    655:        // Delete keyfile defaults
1.1.1.18  root      656:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_DEFAULT_KEYFILES);
1.1.1.7   root      657:        RemoveMessage (hwndDlg, path2);
                    658:        StatDeleteFile (path2);
                    659: 
                    660:        // Delete history file
1.1.1.18  root      661:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_HISTORY);
1.1.1.7   root      662:        RemoveMessage (hwndDlg, path2);
                    663:        StatDeleteFile (path2);
                    664:        
                    665:        // Delete configuration file
1.1.1.18  root      666:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_CONFIGURATION);
1.1.1.7   root      667:        RemoveMessage (hwndDlg, path2);
                    668:        StatDeleteFile (path2);
                    669: 
1.1.1.13  root      670:        // Delete system encryption configuration file
1.1.1.18  root      671:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
1.1.1.13  root      672:        RemoveMessage (hwndDlg, path2);
                    673:        StatDeleteFile (path2);
                    674: 
1.1.1.7   root      675:        SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
                    676:        strcat (path, "\\TrueCrypt");
                    677:        RemoveMessage (hwndDlg, path);
                    678:        if (!StatRemoveDirectory (path))
                    679:        {
                    680:                handleWin32Error (hwndDlg);
                    681:                bOK = FALSE;
                    682:        }
                    683: 
                    684:        return bOK;
                    685: }
                    686: 
1.1.1.18  root      687: BOOL DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated)
1.1       root      688: {
                    689:        BOOL bOK = FALSE;
1.1.1.7   root      690:        char regk [64];
1.1       root      691: 
1.1.1.11  root      692:        // Unregister COM servers
1.1.1.20  root      693:        if (!bRemoveDeprecated && IsOSAtLeast (WIN_VISTA))
1.1.1.11  root      694:        {
1.1.1.13  root      695:                if (!UnregisterComServers (InstallationPath))
1.1.1.11  root      696:                        StatusMessage (hwndDlg, "COM_DEREG_FAILED");
                    697:        }
                    698: 
                    699:        if (!bRemoveDeprecated)
                    700:                StatusMessage (hwndDlg, "REMOVING_REG");
1.1       root      701: 
1.1.1.11  root      702:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt");
                    703:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell\\open\\command");
                    704:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell\\open");
                    705:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell");
                    706:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\DefaultIcon");
                    707:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume");
                    708:        RegDeleteKey (HKEY_CURRENT_USER, "Software\\TrueCrypt");
1.1.1.7   root      709: 
                    710:        if (!bRemoveDeprecated)
                    711:        {
                    712:                // Split the string in order to prevent some antivirus packages from falsely reporting  
                    713:                // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
                    714:                sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
                    715:                DeleteRegistryValue (regk, "TrueCrypt");
                    716: 
1.1.1.11  root      717:                RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\.tc");
1.1.1.20  root      718:                SHChangeNotify (SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
1.1.1.7   root      719:        }
1.1       root      720: 
                    721:        bOK = TRUE;
                    722: 
                    723:        if (bOK == FALSE && GetLastError ()!= ERROR_NO_TOKEN && GetLastError ()!= ERROR_FILE_NOT_FOUND
                    724:            && GetLastError ()!= ERROR_PATH_NOT_FOUND)
                    725:        {
                    726:                handleWin32Error (hwndDlg);
                    727:        }
                    728:        else
                    729:                bOK = TRUE;
                    730: 
                    731:        return bOK;
                    732: }
                    733: 
1.1.1.11  root      734: 
1.1.1.18  root      735: BOOL DoServiceUninstall (HWND hwndDlg, char *lpszService)
1.1       root      736: {
                    737:        SC_HANDLE hManager, hService = NULL;
                    738:        BOOL bOK = FALSE, bRet;
                    739:        SERVICE_STATUS status;
1.1.1.6   root      740:        BOOL firstTry = TRUE;
1.1       root      741:        int x;
                    742: 
1.1.1.6   root      743:        memset (&status, 0, sizeof (status));   /* Keep VC6 quiet */
                    744: 
                    745: retry:
1.1       root      746: 
                    747:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    748:        if (hManager == NULL)
                    749:                goto error;
                    750: 
                    751:        hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
                    752:        if (hService == NULL)
                    753:                goto error;
                    754: 
1.1.1.7   root      755:        if (strcmp ("truecrypt", lpszService) == 0)
1.1.1.19  root      756:        {
1.1.1.20  root      757:                try
1.1.1.19  root      758:                {
1.1.1.20  root      759:                        BootEncryption bootEnc (hwndDlg);
                    760:                        if (bootEnc.GetDriverServiceStartType() == SERVICE_BOOT_START)
                    761:                        {
                    762:                                bootEnc.RegisterFilterDriver (false, false);
                    763:                                bootEnc.RegisterFilterDriver (false, true);
                    764:                        }
1.1.1.19  root      765:                }
1.1.1.20  root      766:                catch (...) { }
1.1.1.19  root      767: 
1.1.1.7   root      768:                StatusMessage (hwndDlg, "STOPPING_DRIVER");
1.1.1.19  root      769:        }
1.1.1.7   root      770:        else
                    771:                StatusMessageParam (hwndDlg, "STOPPING", lpszService);
1.1       root      772: 
                    773: #define WAIT_PERIOD 3
                    774: 
                    775:        for (x = 0; x < WAIT_PERIOD; x++)
                    776:        {
                    777:                bRet = QueryServiceStatus (hService, &status);
                    778:                if (bRet != TRUE)
                    779:                        goto error;
                    780: 
                    781:                if (status.dwCurrentState != SERVICE_START_PENDING &&
                    782:                    status.dwCurrentState != SERVICE_STOP_PENDING &&
                    783:                    status.dwCurrentState != SERVICE_CONTINUE_PENDING)
                    784:                        break;
                    785: 
                    786:                Sleep (1000);
                    787:        }
                    788: 
                    789:        if (status.dwCurrentState != SERVICE_STOPPED)
                    790:        {
                    791:                bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status);
                    792:                if (bRet == FALSE)
                    793:                        goto try_delete;
                    794: 
                    795:                for (x = 0; x < WAIT_PERIOD; x++)
                    796:                {
                    797:                        bRet = QueryServiceStatus (hService, &status);
                    798:                        if (bRet != TRUE)
                    799:                                goto error;
                    800: 
                    801:                        if (status.dwCurrentState != SERVICE_START_PENDING &&
                    802:                            status.dwCurrentState != SERVICE_STOP_PENDING &&
                    803:                          status.dwCurrentState != SERVICE_CONTINUE_PENDING)
                    804:                                break;
                    805: 
                    806:                        Sleep (1000);
                    807:                }
                    808: 
                    809:                if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
                    810:                        goto error;
                    811:        }
                    812: 
1.1.1.6   root      813: try_delete:
                    814: 
1.1.1.7   root      815:        if (strcmp ("truecrypt", lpszService) == 0)
                    816:                StatusMessage (hwndDlg, "REMOVING_DRIVER");
                    817:        else
                    818:                StatusMessageParam (hwndDlg, "REMOVING", lpszService);
1.1       root      819: 
                    820:        if (hService != NULL)
                    821:                CloseServiceHandle (hService);
                    822: 
                    823:        if (hManager != NULL)
                    824:                CloseServiceHandle (hManager);
                    825: 
                    826:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    827:        if (hManager == NULL)
                    828:                goto error;
                    829: 
                    830:        hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
                    831:        if (hService == NULL)
                    832:                goto error;
                    833: 
                    834:        bRet = DeleteService (hService);
                    835:        if (bRet == FALSE)
1.1.1.6   root      836:        {
                    837:                if (firstTry && GetLastError () == ERROR_SERVICE_MARKED_FOR_DELETE)
                    838:                {
                    839:                        // Second try for an eventual no-install driver instance
                    840:                        CloseServiceHandle (hService);
                    841:                        CloseServiceHandle (hManager);
                    842: 
                    843:                        Sleep(1000);
                    844:                        firstTry = FALSE;
                    845:                        goto retry;
                    846:                }
                    847: 
1.1       root      848:                goto error;
1.1.1.6   root      849:        }
1.1       root      850: 
                    851:        bOK = TRUE;
                    852: 
1.1.1.6   root      853: error:
                    854: 
1.1       root      855:        if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
                    856:        {
                    857:                handleWin32Error (hwndDlg);
1.1.1.7   root      858:                MessageBoxW (hwndDlg, GetString ("DRIVER_UINSTALL_FAILED"), lpszTitle, MB_ICONHAND);
1.1       root      859:        }
                    860:        else
                    861:                bOK = TRUE;
                    862: 
                    863:        if (hService != NULL)
                    864:                CloseServiceHandle (hService);
                    865: 
                    866:        if (hManager != NULL)
                    867:                CloseServiceHandle (hManager);
                    868: 
                    869:        return bOK;
                    870: }
                    871: 
1.1.1.7   root      872: 
1.1.1.15  root      873: BOOL DoDriverUnload (HWND hwndDlg)
1.1       root      874: {
                    875:        BOOL bOK = TRUE;
                    876:        int status;
                    877: 
                    878:        status = DriverAttach ();
                    879:        if (status != 0)
                    880:        {
1.1.1.11  root      881:                if (status == ERR_OS_ERROR && GetLastError () != ERROR_FILE_NOT_FOUND)
1.1       root      882:                {
                    883:                        handleWin32Error (hwndDlg);
1.1.1.7   root      884:                        AbortProcess ("NODRIVER");
1.1       root      885:                }
                    886: 
                    887:                if (status != ERR_OS_ERROR)
                    888:                {
                    889:                        handleError (NULL, status);
1.1.1.7   root      890:                        AbortProcess ("NODRIVER");
1.1       root      891:                }
                    892:        }
                    893: 
                    894:        if (hDriver != INVALID_HANDLE_VALUE)
                    895:        {
1.1.1.3   root      896:                MOUNT_LIST_STRUCT driver;
1.1.1.11  root      897:                LONG driverVersion = VERSION_NUM;
1.1.1.7   root      898:                int refCount;
1.1.1.3   root      899:                DWORD dwResult;
                    900:                BOOL bResult;
1.1.1.13  root      901: 
1.1.1.14  root      902:                // Try to determine if it's upgrade (and not reinstall, downgrade, or first-time install).
1.1.1.22  root      903:                DetermineUpgradeDowngradeStatus (FALSE, &driverVersion);
1.1.1.14  root      904: 
1.1.1.13  root      905:                // Test for encrypted boot drive
                    906:                try
                    907:                {
                    908:                        BootEncryption bootEnc (hwndDlg);
                    909:                        if (bootEnc.GetDriverServiceStartType() == SERVICE_BOOT_START)
                    910:                        {
1.1.1.17  root      911:                                try
                    912:                                {
                    913:                                        // Check hidden OS update consistency
                    914:                                        if (IsHiddenOSRunning())
                    915:                                        {
                    916:                                                if (bootEnc.GetInstalledBootLoaderVersion() != VERSION_NUM)
                    917:                                                {
                    918:                                                        if (AskWarnNoYes ("UPDATE_TC_IN_DECOY_OS_FIRST") == IDNO)
                    919:                                                                AbortProcessSilent ();
                    920:                                                }
                    921:                                        }
                    922:                                }
                    923:                                catch (...) { }
                    924: 
1.1.1.19  root      925:                                if (bUninstallInProgress && driverVersion >= 0x500 && !bootEnc.GetStatus().DriveMounted)
1.1.1.15  root      926:                                {
1.1.1.17  root      927:                                        bootEnc.RegisterFilterDriver (false, false);
                    928:                                        bootEnc.RegisterFilterDriver (false, true);
1.1.1.15  root      929:                                        bootEnc.SetDriverServiceStartType (SERVICE_SYSTEM_START);
                    930:                                }
1.1.1.19  root      931:                                else if (bUninstallInProgress || bDowngrade)
1.1.1.14  root      932:                                {
1.1.1.22  root      933:                                        Error (bDowngrade ? "SETUP_FAILED_BOOT_DRIVE_ENCRYPTED_DOWNGRADE" : "SETUP_FAILED_BOOT_DRIVE_ENCRYPTED");
1.1.1.14  root      934:                                        return FALSE;
                    935:                                }
1.1.1.15  root      936:                                else
                    937:                                {
1.1.1.20  root      938:                                        if (CurrentOSMajor == 6 && CurrentOSMinor == 0 && CurrentOSServicePack < 1
                    939:                                                && AskWarnNoYes ("SYS_ENCRYPTION_VISTA_SP1_RECOMMENDED") == IDNO)
                    940:                                        {
                    941:                                                AbortProcessSilent();
                    942:                                        }
                    943: 
1.1.1.15  root      944:                                        SystemEncryptionUpgrade = TRUE;
                    945:                                }
1.1.1.13  root      946:                        }
                    947:                }
                    948:                catch (...)     { }
1.1       root      949: 
1.1.1.22  root      950:                if (!bUninstall
                    951:                        && (bUpgrade || SystemEncryptionUpgrade)
                    952:                        && (!bDevm || SystemEncryptionUpgrade))
                    953:                {
                    954:                        UnloadDriver = FALSE;
                    955:                }
                    956: 
                    957:                if (UnloadDriver)
1.1.1.14  root      958:                {
1.1.1.20  root      959:                        int volumesMounted = 0;
                    960: 
1.1.1.14  root      961:                        // Check mounted volumes
                    962:                        bResult = DeviceIoControl (hDriver, TC_IOCTL_IS_ANY_VOLUME_MOUNTED, NULL, 0, &volumesMounted, sizeof (volumesMounted), &dwResult, NULL);
1.1.1.13  root      963: 
1.1.1.14  root      964:                        if (!bResult)
                    965:                        {
                    966:                                bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES, NULL, 0, &driver, sizeof (driver), &dwResult, NULL);
                    967:                                if (bResult)
                    968:                                        volumesMounted = driver.ulMountedDrives;
                    969:                        }
1.1.1.13  root      970: 
                    971:                        if (bResult)
1.1.1.14  root      972:                        {
                    973:                                if (volumesMounted != 0)
                    974:                                {
                    975:                                        bOK = FALSE;
                    976:                                        MessageBoxW (hwndDlg, GetString ("DISMOUNT_ALL_FIRST"), lpszTitle, MB_ICONHAND);
                    977:                                }
                    978:                        }
                    979:                        else
1.1       root      980:                        {
                    981:                                bOK = FALSE;
1.1.1.14  root      982:                                handleWin32Error (hwndDlg);
1.1       root      983:                        }
                    984:                }
1.1.1.14  root      985: 
1.1.1.7   root      986:                // Try to close all open TC windows
1.1.1.11  root      987:                if (bOK)
1.1.1.7   root      988:                {
                    989:                        BOOL TCWindowClosed = FALSE;
1.1.1.11  root      990: 
1.1.1.7   root      991:                        EnumWindows (CloseTCWindowsEnum, (LPARAM) &TCWindowClosed);
1.1.1.11  root      992: 
                    993:                        if (TCWindowClosed) 
                    994:                                Sleep (2000);
1.1.1.7   root      995:                }
                    996: 
                    997:                // Test for any applications attached to driver
1.1.1.23! root      998:                if (!bUpgrade)
1.1.1.7   root      999:                {
1.1.1.23! root     1000:                        bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DEVICE_REFCOUNT, &refCount, sizeof (refCount), &refCount,
        !          1001:                                sizeof (refCount), &dwResult, NULL);
        !          1002: 
        !          1003:                        if (bOK && bResult && refCount > 1)
        !          1004:                        {
        !          1005:                                MessageBoxW (hwndDlg, GetString ("CLOSE_TC_FIRST"), lpszTitle, MB_ICONSTOP);
        !          1006:                                bOK = FALSE;
        !          1007:                        }
1.1.1.7   root     1008:                }
1.1       root     1009: 
1.1.1.22  root     1010:                if (!bOK || UnloadDriver)
1.1.1.14  root     1011:                {
                   1012:                        CloseHandle (hDriver);
                   1013:                        hDriver = INVALID_HANDLE_VALUE;
                   1014:                }
1.1       root     1015:        }
1.1.1.11  root     1016:        else
                   1017:        {
                   1018:                bFirstTimeInstall = TRUE;
                   1019:        }
1.1       root     1020: 
                   1021:        return bOK;
                   1022: }
                   1023: 
                   1024: 
1.1.1.14  root     1025: BOOL UpgradeBootLoader (HWND hwndDlg)
                   1026: {
                   1027:        if (!SystemEncryptionUpgrade)
                   1028:                return TRUE;
                   1029: 
                   1030:        try
                   1031:        {
                   1032:                BootEncryption bootEnc (hwndDlg);
                   1033:                if (bootEnc.GetInstalledBootLoaderVersion() < VERSION_NUM)
                   1034:                {
1.1.1.17  root     1035:                        StatusMessage (hwndDlg, "INSTALLER_UPDATING_BOOT_LOADER");
                   1036: 
1.1.1.18  root     1037:                        bootEnc.InstallBootLoader (true);
1.1.1.22  root     1038: 
                   1039:                        if (bootEnc.GetInstalledBootLoaderVersion() <= TC_RESCUE_DISK_UPGRADE_NOTICE_MAX_VERSION)
                   1040:                                Info (IsHiddenOSRunning() ? "BOOT_LOADER_UPGRADE_OK_HIDDEN_OS" : "BOOT_LOADER_UPGRADE_OK");
1.1.1.14  root     1041:                }
                   1042:                return TRUE;
                   1043:        }
                   1044:        catch (Exception &e)
                   1045:        {
                   1046:                e.Show (hwndDlg);
                   1047:        }
                   1048:        catch (...) { }
                   1049: 
                   1050:        Error ("BOOT_LOADER_UPGRADE_FAILED");
                   1051:        return FALSE;
                   1052: }
                   1053: 
                   1054: 
1.1.1.15  root     1055: BOOL DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
1.1       root     1056: {
1.1.1.11  root     1057:        char szLinkDir[TC_MAX_PATH];
1.1.1.7   root     1058:        char szTmp2[TC_MAX_PATH];
1.1       root     1059:        BOOL bSlash, bOK = FALSE;
                   1060:        HRESULT hOle;
                   1061:        int x;
                   1062:        BOOL allUsers = FALSE;
                   1063: 
                   1064:        hOle = OleInitialize (NULL);
                   1065: 
                   1066:        // User start menu
                   1067:     SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
                   1068:        x = strlen (szLinkDir);
                   1069:        if (szLinkDir[x - 1] == '\\')
                   1070:                bSlash = TRUE;
                   1071:        else
                   1072:                bSlash = FALSE;
                   1073: 
                   1074:        if (bSlash == FALSE)
                   1075:                strcat (szLinkDir, "\\");
                   1076: 
                   1077:        strcat (szLinkDir, "TrueCrypt");
                   1078: 
                   1079:        // Global start menu
                   1080:        {
                   1081:                struct _stat st;
                   1082:                char path[TC_MAX_PATH];
                   1083: 
                   1084:                SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
                   1085:                strcat (path, "\\TrueCrypt");
                   1086: 
                   1087:                if (_stat (path, &st) == 0)
                   1088:                {
                   1089:                        strcpy (szLinkDir, path);
                   1090:                        allUsers = TRUE;
                   1091:                }
                   1092:        }
                   1093: 
                   1094:        // Start menu entries
                   1095:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                   1096:        RemoveMessage (hwndDlg, szTmp2);
                   1097:        if (StatDeleteFile (szTmp2) == FALSE)
                   1098:                goto error;
                   1099: 
1.1.1.11  root     1100:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url");
1.1       root     1101:        RemoveMessage (hwndDlg, szTmp2);
                   1102:        if (StatDeleteFile (szTmp2) == FALSE)
                   1103:                goto error;
                   1104: 
                   1105:        sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
                   1106:        RemoveMessage (hwndDlg, szTmp2);
                   1107:        if (StatDeleteFile (szTmp2) == FALSE)
                   1108:                goto error;
1.1.1.11  root     1109:        
                   1110:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
                   1111:        DeleteFile (szTmp2);
1.1       root     1112: 
                   1113:        // Start menu group
                   1114:        RemoveMessage ((HWND) hwndDlg, szLinkDir);
                   1115:        if (StatRemoveDirectory (szLinkDir) == FALSE)
                   1116:                handleWin32Error ((HWND) hwndDlg);
                   1117: 
                   1118:        // Desktop icon
                   1119: 
                   1120:        if (allUsers)
                   1121:                SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
                   1122:        else
                   1123:                SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
                   1124: 
                   1125:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                   1126: 
                   1127:        RemoveMessage (hwndDlg, szTmp2);
                   1128:        if (StatDeleteFile (szTmp2) == FALSE)
                   1129:                goto error;
                   1130: 
                   1131:        bOK = TRUE;
                   1132: 
                   1133: error:
                   1134:        OleUninitialize ();
                   1135: 
                   1136:        return bOK;
                   1137: }
                   1138: 
1.1.1.18  root     1139: BOOL DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
1.1       root     1140: {
                   1141:        char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
1.1.1.7   root     1142:        char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH], szTmp3[TC_MAX_PATH];
1.1       root     1143:        BOOL bSlash, bOK = FALSE;
                   1144:        HRESULT hOle;
                   1145:        int x;
                   1146: 
                   1147:        if (bProgGroup == FALSE && bDesktopIcon == FALSE)
                   1148:                return TRUE;
                   1149: 
                   1150:        hOle = OleInitialize (NULL);
                   1151: 
                   1152:        GetProgramPath (hwndDlg, szLinkDir);
                   1153: 
                   1154:        x = strlen (szLinkDir);
                   1155:        if (szLinkDir[x - 1] == '\\')
                   1156:                bSlash = TRUE;
                   1157:        else
                   1158:                bSlash = FALSE;
                   1159: 
                   1160:        if (bSlash == FALSE)
                   1161:                strcat (szLinkDir, "\\");
                   1162: 
                   1163:        strcat (szLinkDir, "TrueCrypt");
                   1164: 
                   1165:        strcpy (szDir, szDestDir);
                   1166:        x = strlen (szDestDir);
                   1167:        if (szDestDir[x - 1] == '\\')
                   1168:                bSlash = TRUE;
                   1169:        else
                   1170:                bSlash = FALSE;
                   1171: 
                   1172:        if (bSlash == FALSE)
                   1173:                strcat (szDir, "\\");
                   1174: 
                   1175:        if (bProgGroup)
                   1176:        {
1.1.1.11  root     1177:                FILE *f;
                   1178: 
1.1       root     1179:                if (mkfulldir (szLinkDir, TRUE) != 0)
                   1180:                {
                   1181:                        if (mkfulldir (szLinkDir, FALSE) != 0)
                   1182:                        {
1.1.1.13  root     1183:                                wchar_t szTmp[TC_MAX_PATH];
                   1184: 
1.1       root     1185:                                handleWin32Error (hwndDlg);
1.1.1.7   root     1186:                                wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), szLinkDir);
                   1187:                                MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1.1       root     1188:                                goto error;
                   1189:                        }
                   1190:                }
                   1191: 
                   1192:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
                   1193:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                   1194: 
                   1195:                IconMessage (hwndDlg, szTmp2);
                   1196:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                   1197:                        goto error;
                   1198: 
1.1.1.11  root     1199:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url");
1.1       root     1200:                IconMessage (hwndDlg, szTmp2);
1.1.1.11  root     1201:                f = fopen (szTmp2, "w");
                   1202:                if (f)
                   1203:                {
1.1.1.21  root     1204:                        fprintf (f, "[InternetShortcut]\nURL=%s\n", TC_HOMEPAGE);
1.1.1.11  root     1205:                        fclose (f);
                   1206:                }
1.1       root     1207:                else
1.1.1.11  root     1208:                        goto error;
1.1       root     1209: 
                   1210:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
                   1211:                sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
1.1.1.13  root     1212:                strcpy (szTmp3, "/u");
1.1       root     1213: 
                   1214:                IconMessage (hwndDlg, szTmp2);
1.1.1.7   root     1215:                if (CreateLink (szTmp, szTmp3, szTmp2) != S_OK)
1.1       root     1216:                        goto error;
                   1217: 
1.1.1.11  root     1218:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
                   1219:                DeleteFile (szTmp2);
1.1       root     1220:        }
                   1221: 
                   1222:        if (bDesktopIcon)
                   1223:        {
                   1224:                strcpy (szDir, szDestDir);
                   1225:                x = strlen (szDestDir);
                   1226:                if (szDestDir[x - 1] == '\\')
                   1227:                        bSlash = TRUE;
                   1228:                else
                   1229:                        bSlash = FALSE;
                   1230: 
                   1231:                if (bSlash == FALSE)
                   1232:                        strcat (szDir, "\\");
                   1233: 
1.1.1.13  root     1234:                if (bForAllUsers)
1.1       root     1235:                        SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
                   1236:                else
                   1237:                        SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
                   1238: 
                   1239:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
                   1240:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                   1241: 
                   1242:                IconMessage (hwndDlg, szTmp2);
                   1243: 
                   1244:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                   1245:                        goto error;
                   1246:        }
                   1247: 
                   1248:        bOK = TRUE;
                   1249: 
                   1250: error:
                   1251:        OleUninitialize ();
                   1252: 
                   1253:        return bOK;
                   1254: }
                   1255: 
                   1256: 
1.1.1.18  root     1257: void OutcomePrompt (HWND hwndDlg, BOOL bOK)
1.1       root     1258: {
1.1.1.7   root     1259:        if (bOK)
1.1       root     1260:        {
                   1261:                EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
                   1262: 
                   1263:                bDone = TRUE;
                   1264: 
1.1.1.7   root     1265:                if (bUninstall == FALSE)
1.1.1.13  root     1266:                {
                   1267:                        if (bDevm)
                   1268:                                PostMessage (MainDlg, WM_CLOSE, 0, 0);
1.1.1.18  root     1269:                        else if (bFirstTimeInstall && !SystemEncryptionUpgrade && !bUpgrade && !bDowngrade && !bRepairMode)
1.1.1.13  root     1270:                                Info ("INSTALL_OK");
1.1.1.22  root     1271:                        else if (!bRestartRequired)
1.1.1.18  root     1272:                                Info ("SETUP_UPDATE_OK");
1.1.1.13  root     1273:                }
1.1       root     1274:                else
1.1.1.11  root     1275:                {
                   1276:                        wchar_t str[4096];
                   1277: 
1.1.1.13  root     1278:                        swprintf (str, GetString ("UNINSTALL_OK"), InstallationPath);
1.1.1.11  root     1279:                        MessageBoxW (hwndDlg, str, lpszTitle, MB_ICONASTERISK);
                   1280:                }
1.1       root     1281:        }
                   1282:        else
                   1283:        {
                   1284:                if (bUninstall == FALSE)
1.1.1.11  root     1285:                        Error ("INSTALL_FAILED");
1.1       root     1286:                else
1.1.1.11  root     1287:                        Error ("UNINSTALL_FAILED");
1.1       root     1288:        }
                   1289: }
                   1290: 
1.1.1.13  root     1291: static void SetSystemRestorePoint (HWND hwndDlg, BOOL finalize)
1.1       root     1292: {
                   1293:        static RESTOREPOINTINFO RestPtInfo;
                   1294:        static STATEMGRSTATUS SMgrStatus;
                   1295:        static BOOL failed = FALSE;
                   1296:        static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
                   1297:        
                   1298:        if (!SystemRestoreDll) return;
                   1299: 
                   1300:        _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA");
                   1301:        if (_SRSetRestorePoint == 0)
                   1302:        {
                   1303:                FreeLibrary (SystemRestoreDll);
                   1304:                SystemRestoreDll = 0;
                   1305:                return;
                   1306:        }
                   1307: 
                   1308:        if (!finalize)
                   1309:        {
1.1.1.7   root     1310:                StatusMessage (hwndDlg, "CREATING_SYS_RESTORE");
1.1       root     1311: 
                   1312:                RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
                   1313:                RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;
                   1314:                RestPtInfo.llSequenceNumber = 0;
1.1.1.13  root     1315:                strcpy (RestPtInfo.szDescription, bUninstall ? "TrueCrypt uninstallation" : "TrueCrypt installation");
1.1       root     1316: 
1.1.1.7   root     1317:                if(!_SRSetRestorePoint (&RestPtInfo, &SMgrStatus)) 
1.1       root     1318:                {
1.1.1.7   root     1319:                        StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
1.1       root     1320:                        failed = TRUE;
                   1321:                }
                   1322:        }
1.1.1.11  root     1323:        else if (!failed)
1.1       root     1324:        {
1.1.1.11  root     1325:                RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
                   1326:                RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
                   1327: 
                   1328:                if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus)) 
                   1329:                {
                   1330:                        StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
                   1331:                }
1.1       root     1332:        }
                   1333: }
                   1334: 
1.1.1.18  root     1335: void DoUninstall (void *arg)
1.1       root     1336: {
1.1.1.13  root     1337:        HWND hwndDlg = (HWND) arg;
1.1       root     1338:        BOOL bOK = TRUE;
1.1.1.13  root     1339:        BOOL bTempSkipSysRestore = FALSE;
1.1       root     1340: 
1.1.1.11  root     1341:        if (!Rollback)
                   1342:                EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), FALSE);
1.1       root     1343: 
                   1344:        WaitCursor ();
                   1345: 
1.1.1.11  root     1346:        if (!Rollback)
1.1       root     1347:        {
1.1.1.13  root     1348:                ClearLogWindow (hwndDlg);
1.1       root     1349:        }
1.1.1.13  root     1350: 
                   1351:        if (DoDriverUnload (hwndDlg) == FALSE)
1.1.1.7   root     1352:        {
                   1353:                bOK = FALSE;
1.1.1.13  root     1354:                bTempSkipSysRestore = TRUE;             // Volumes are possibly mounted; defer System Restore point creation for this uninstall attempt.
1.1.1.7   root     1355:        }
1.1       root     1356:        else
                   1357:        {
1.1.1.13  root     1358:                if (!Rollback && bSystemRestore && !bTempSkipSysRestore)
                   1359:                        SetSystemRestorePoint (hwndDlg, FALSE);
1.1.1.11  root     1360: 
1.1.1.13  root     1361:                if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
                   1362:                {
1.1.1.11  root     1363:                        bOK = FALSE;
1.1.1.13  root     1364:                }
                   1365:                else if (DoRegUninstall ((HWND) hwndDlg, FALSE) == FALSE)
                   1366:                {
                   1367:                        bOK = FALSE;
                   1368:                }
                   1369:                else if (DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
                   1370:                {
                   1371:                        bOK = FALSE;
                   1372:                }
                   1373:                else if (DoShortcutsUninstall (hwndDlg, InstallationPath) == FALSE)
                   1374:                {
                   1375:                        bOK = FALSE;
                   1376:                }
                   1377:                else if (!DoApplicationDataUninstall (hwndDlg))
                   1378:                {
                   1379:                        bOK = FALSE;
                   1380:                }
1.1.1.11  root     1381:                else
1.1       root     1382:                {
1.1.1.13  root     1383:                        char temp[MAX_PATH];
                   1384:                        FILE *f;
                   1385: 
                   1386:                        // Deprecated service
                   1387:                        DoServiceUninstall (hwndDlg, "TrueCryptService");
                   1388: 
                   1389:                        GetTempPath (sizeof (temp), temp);
                   1390:                        _snprintf (UninstallBatch, sizeof (UninstallBatch), "%s\\TrueCrypt-Uninstall.bat", temp);
                   1391: 
1.1.1.15  root     1392:                        UninstallBatch [sizeof(UninstallBatch)-1] = 0;
                   1393: 
1.1.1.13  root     1394:                        // Create uninstall batch
                   1395:                        f = fopen (UninstallBatch, "w");
                   1396:                        if (!f)
                   1397:                                bOK = FALSE;
                   1398:                        else
                   1399:                        {
                   1400:                                fprintf (f, ":loop\n"
                   1401:                                        "del \"%s%s\"\n"
                   1402:                                        "if exist \"%s%s\" goto loop\n"
                   1403:                                        "rmdir \"%s\"\n"
                   1404:                                        "del \"%s\"",
                   1405:                                        InstallationPath, "TrueCrypt Setup.exe",
                   1406:                                        InstallationPath, "TrueCrypt Setup.exe",
                   1407:                                        InstallationPath,
                   1408:                                        UninstallBatch
                   1409:                                        );
                   1410:                                fclose (f);
                   1411:                        }
1.1       root     1412:                }
                   1413:        }
                   1414: 
                   1415:        NormalCursor ();
                   1416: 
1.1.1.11  root     1417:        if (Rollback)
                   1418:                return;
                   1419: 
1.1.1.13  root     1420:        if (bSystemRestore && !bTempSkipSysRestore)
                   1421:                SetSystemRestorePoint (hwndDlg, TRUE);
                   1422: 
1.1.1.7   root     1423:        if (bOK)
1.1.1.13  root     1424:                PostMessage (hwndDlg, TC_APPMSG_UNINSTALL_SUCCESS, 0, 0);
                   1425:        else
                   1426:                bUninstallInProgress = FALSE;
                   1427: 
1.1.1.7   root     1428:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), TRUE);
1.1.1.11  root     1429:        OutcomePrompt (hwndDlg, bOK);
1.1       root     1430: }
                   1431: 
1.1.1.18  root     1432: void DoInstall (void *arg)
1.1       root     1433: {
1.1.1.13  root     1434:        HWND hwndDlg = (HWND) arg;
1.1       root     1435:        BOOL bOK = TRUE;
1.1.1.11  root     1436:        char path[MAX_PATH];
1.1       root     1437: 
1.1.1.17  root     1438:        BootEncryption bootEnc (hwndDlg);
                   1439: 
1.1.1.13  root     1440:        // Refresh the main GUI (wizard thread)
                   1441:        InvalidateRect (GetDlgItem (MainDlg, IDD_INSTL_DLG), NULL, TRUE);
                   1442: 
                   1443:        ClearLogWindow(hwndDlg);
                   1444: 
                   1445:        if (mkfulldir (InstallationPath, TRUE) != 0)
                   1446:        {
                   1447:                if (mkfulldir (InstallationPath, FALSE) != 0)
                   1448:                {
                   1449:                        wchar_t szTmp[TC_MAX_PATH];
                   1450: 
                   1451:                        handleWin32Error (hwndDlg);
                   1452:                        wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), InstallationPath);
                   1453:                        MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
                   1454:                        Error ("INSTALL_FAILED");
                   1455:                        PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
                   1456:                        return;
                   1457:                }
                   1458:        }
                   1459: 
                   1460:        UpdateProgressBarProc(2);
1.1       root     1461: 
                   1462:        if (DoDriverUnload (hwndDlg) == FALSE)
                   1463:        {
1.1.1.4   root     1464:                NormalCursor ();
1.1.1.13  root     1465:                PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
1.1.1.4   root     1466:                return;
1.1       root     1467:        }
1.1.1.13  root     1468: 
1.1.1.23! root     1469:        if (bUpgrade
        !          1470:                && (IsFileInUse (string (InstallationPath) + '\\' + TC_APP_NAME ".exe")
        !          1471:                        || IsFileInUse (string (InstallationPath) + '\\' + TC_APP_NAME " Format.exe")
        !          1472:                        || IsFileInUse (string (InstallationPath) + '\\' + TC_APP_NAME " Setup.exe")
        !          1473:                        )
        !          1474:                )
        !          1475:        {
        !          1476:                NormalCursor ();
        !          1477:                Error ("CLOSE_TC_FIRST");
        !          1478:                PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
        !          1479:                return;
        !          1480:        }
        !          1481: 
1.1.1.13  root     1482:        UpdateProgressBarProc(12);
1.1.1.4   root     1483:        
1.1.1.13  root     1484:        if (bSystemRestore)
1.1.1.4   root     1485:                SetSystemRestorePoint (hwndDlg, FALSE);
                   1486: 
1.1.1.17  root     1487:        UpdateProgressBarProc(48);
                   1488:        
                   1489:        if (bDisableSwapFiles
1.1.1.18  root     1490:                && IsPagingFileActive (FALSE))
1.1.1.17  root     1491:        {
                   1492:                if (!DisablePagingFile())
                   1493:                {
                   1494:                        handleWin32Error (hwndDlg);
                   1495:                        Error ("FAILED_TO_DISABLE_PAGING_FILES");
                   1496:                }
                   1497:                else
                   1498:                        bRestartRequired = TRUE;
                   1499:        }
                   1500: 
1.1.1.13  root     1501:        UpdateProgressBarProc(50);
                   1502: 
1.1.1.11  root     1503:        // Remove deprecated
1.1.1.7   root     1504:        DoServiceUninstall (hwndDlg, "TrueCryptService");
1.1.1.11  root     1505:        
1.1.1.13  root     1506:        UpdateProgressBarProc(55);
                   1507: 
1.1.1.14  root     1508:        if (!SystemEncryptionUpgrade)
                   1509:                DoRegUninstall ((HWND) hwndDlg, TRUE);
1.1.1.7   root     1510: 
1.1.1.13  root     1511:        UpdateProgressBarProc(62);
                   1512: 
1.1.1.11  root     1513:        GetWindowsDirectory (path, sizeof (path));
                   1514:        strcat_s (path, sizeof (path), "\\TrueCrypt Setup.exe");
                   1515:        DeleteFile (path);
                   1516: 
1.1.1.22  root     1517:        if (UpdateProgressBarProc(63) && UnloadDriver && DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1.1       root     1518:        {
                   1519:                bOK = FALSE;
                   1520:        }
1.1.1.13  root     1521:        else if (UpdateProgressBarProc(72) && DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
1.1       root     1522:        {
                   1523:                bOK = FALSE;
                   1524:        }
1.1.1.19  root     1525:        else if (UpdateProgressBarProc(80) && DoRegInstall ((HWND) hwndDlg, InstallationPath, bRegisterFileExt) == FALSE)
1.1       root     1526:        {
                   1527:                bOK = FALSE;
                   1528:        }
1.1.1.22  root     1529:        else if (UpdateProgressBarProc(85) && UnloadDriver && DoDriverInstall (hwndDlg) == FALSE)
1.1.1.14  root     1530:        {
                   1531:                bOK = FALSE;
                   1532:        }
1.1.1.17  root     1533:        else if (UpdateProgressBarProc(90) && SystemEncryptionUpgrade && UpgradeBootLoader (hwndDlg) == FALSE)
1.1       root     1534:        {
                   1535:                bOK = FALSE;
                   1536:        }
1.1.1.13  root     1537:        else if (UpdateProgressBarProc(93) && DoShortcutsInstall (hwndDlg, InstallationPath, bAddToStartMenu, bDesktopIcon) == FALSE)
1.1       root     1538:        {
                   1539:                bOK = FALSE;
                   1540:        }
                   1541: 
1.1.1.22  root     1542:        if (!UnloadDriver)
                   1543:                bRestartRequired = TRUE;
                   1544: 
1.1.1.17  root     1545:        try
                   1546:        {
                   1547:                bootEnc.RenameDeprecatedSystemLoaderBackup();
                   1548:        }
                   1549:        catch (...)     { }
                   1550: 
1.1.1.23! root     1551:        string sysFavorites = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES);
        !          1552:        string legacySysFavorites = GetProgramConfigPath ("System Favorite Volumes.xml");
        !          1553: 
        !          1554:        if (FileExists (legacySysFavorites.c_str()) && !FileExists (sysFavorites.c_str()))
        !          1555:                MoveFile (legacySysFavorites.c_str(), sysFavorites.c_str());
1.1.1.17  root     1556: 
1.1.1.13  root     1557:        if (bOK)
                   1558:                UpdateProgressBarProc(97);
                   1559: 
                   1560:        if (bSystemRestore)
1.1       root     1561:                SetSystemRestorePoint (hwndDlg, TRUE);
                   1562: 
1.1.1.7   root     1563:        if (bOK)
                   1564:        {
1.1.1.13  root     1565:                UpdateProgressBarProc(100);
1.1.1.11  root     1566:                UninstallBatch[0] = 0;
1.1.1.7   root     1567:                StatusMessage (hwndDlg, "INSTALL_COMPLETED");
1.1.1.13  root     1568:                PostMessage (MainDlg, TC_APPMSG_INSTALL_SUCCESS, 0, 0);
1.1.1.11  root     1569:        }
                   1570:        else
                   1571:        {
1.1.1.13  root     1572:                UpdateProgressBarProc(0);
1.1.1.11  root     1573:                bUninstall = TRUE;
                   1574:                Rollback = TRUE;
                   1575:                Silent = TRUE;
                   1576: 
1.1.1.14  root     1577:                if (!SystemEncryptionUpgrade)
                   1578:                        DoUninstall (hwndDlg);
1.1.1.11  root     1579: 
                   1580:                bUninstall = FALSE;
                   1581:                Rollback = FALSE;
                   1582:                Silent = FALSE;
                   1583: 
                   1584:                StatusMessage (hwndDlg, "ROLLBACK");
1.1.1.7   root     1585:        }
1.1       root     1586: 
1.1.1.11  root     1587:        OutcomePrompt (hwndDlg, bOK);
                   1588: 
1.1.1.13  root     1589:        if (!bOK)
                   1590:        {
                   1591:                PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
                   1592:        }
                   1593:        else if (!bUninstall && !bDevm)
1.1.1.11  root     1594:        {
1.1.1.17  root     1595:                if (!IsHiddenOSRunning())       // A hidden OS user should not see the post-install notes twice (on decoy OS and then on hidden OS).
1.1.1.11  root     1596:                {
1.1.1.17  root     1597:                        if (bUpgrade)
1.1.1.14  root     1598:                        {
1.1.1.18  root     1599:                                if (bRestartRequired || SystemEncryptionUpgrade)
                   1600:                                {
                   1601:                                        SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_RELEASE_NOTES);
                   1602:                                }
                   1603:                                else if (AskYesNo ("AFTER_UPGRADE_RELEASE_NOTES") == IDYES)
                   1604:                                {
                   1605:                                        Applink ("releasenotes", TRUE, "");
                   1606:                                }
1.1.1.14  root     1607:                        }
1.1.1.17  root     1608:                        else if (bFirstTimeInstall)
1.1.1.14  root     1609:                        {
1.1.1.18  root     1610:                                if (bRestartRequired || SystemEncryptionUpgrade)
                   1611:                                {
                   1612:                                        SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_TUTORIAL);
                   1613:                                }
                   1614:                                else if (AskYesNo ("AFTER_INSTALL_TUTORIAL") == IDYES)
                   1615:                                {
                   1616:                                        Applink ("beginnerstutorial", TRUE, "");
                   1617:                                }
1.1.1.14  root     1618:                        }
1.1.1.11  root     1619:                }
1.1.1.22  root     1620:        }
1.1.1.17  root     1621: 
1.1.1.22  root     1622:        if (bOK && bRestartRequired)
                   1623:        {
                   1624:                if (AskYesNo (bUpgrade ? "UPGRADE_OK_REBOOT_REQUIRED" : "CONFIRM_RESTART") == IDYES)
                   1625:                        RestartComputer();
1.1.1.11  root     1626:        }
1.1       root     1627: }
                   1628: 
                   1629: 
1.1.1.13  root     1630: void SetInstallationPath (HWND hwndDlg)
                   1631: {
                   1632:        HKEY hkey;
                   1633:        BOOL bInstallPathDetermined = FALSE;
                   1634:        char path[MAX_PATH+20];
                   1635:        ITEMIDLIST *itemList;
                   1636: 
                   1637:        memset (InstallationPath, 0, sizeof (InstallationPath));
                   1638: 
                   1639:        // Determine if TrueCrypt is already installed and try to determine its "Program Files" location
                   1640:        if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
                   1641:        {
                   1642:                /* Default 'UninstallString' registry strings written by past versions of TrueCrypt:
                   1643:                ------------------------------------------------------------------------------------
                   1644:                1.0             C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1645:                1.0a    C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1646:                2.0             C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1647:                2.1             C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1648:                2.1a    C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1649:                3.0             C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1650:                3.0a    C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1651:                3.1             The UninstallString was NEVER written (fortunately, 3.1a replaced 3.1 after 2 weeks)
                   1652:                3.1a    C:\WINDOWS\TrueCrypt Setup.exe /u
                   1653:                4.0             C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
                   1654:                4.1             C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
                   1655:                4.2             C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
                   1656:                4.2a    C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
                   1657:                4.3             "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u C:\Program Files\TrueCrypt\
                   1658:                4.3a    "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u C:\Program Files\TrueCrypt\
1.1.1.15  root     1659:                5.0+    "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u
1.1.1.13  root     1660: 
                   1661:                Note: In versions 1.0-3.0a the user was able to choose whether to install the uninstaller.
                   1662:                          The default was to install it. If it wasn't installed, there was no UninstallString.
                   1663:                */
                   1664: 
                   1665:                char rv[MAX_PATH*4];
                   1666:                DWORD size = sizeof (rv);
1.1.1.17  root     1667:                if (RegQueryValueEx (hkey, "UninstallString", 0, 0, (LPBYTE) &rv, &size) == ERROR_SUCCESS && strrchr (rv, '/'))
1.1.1.13  root     1668:                {
                   1669:                        size_t len = 0;
                   1670: 
                   1671:                        // Cut and paste the location (path) where TrueCrypt is installed to InstallationPath
                   1672:                        if (rv[0] == '"')
                   1673:                        {
                   1674:                                // 4.3 or later
                   1675: 
                   1676:                                len = strrchr (rv, '/') - rv - 2;
                   1677:                                strncpy (InstallationPath, rv + 1, len);
                   1678:                                InstallationPath [len] = 0;
                   1679:                                bInstallPathDetermined = TRUE;
                   1680: 
                   1681:                                if (InstallationPath [strlen (InstallationPath) - 1] != '\\')
                   1682:                                {
                   1683:                                        len = strrchr (InstallationPath, '\\') - InstallationPath;
                   1684:                                        InstallationPath [len] = 0;
                   1685:                                }
                   1686:                        }
                   1687:                        else
                   1688:                        {
                   1689:                                // 1.0-4.2a (except 3.1)
                   1690: 
                   1691:                                len = strrchr (rv, '/') - rv;
                   1692:                                if (rv[len+2] == ' ')
                   1693:                                {
                   1694:                                        // 4.0-4.2a
                   1695: 
                   1696:                                        strncpy (InstallationPath, rv + len + 3, strlen (rv) - len - 3);
                   1697:                                        InstallationPath [strlen (rv) - len - 3] = 0;
                   1698:                                        bInstallPathDetermined = TRUE;
                   1699:                                }
                   1700:                                else
                   1701:                                {
                   1702:                                        // 1.0-3.1a (except 3.1)
                   1703: 
                   1704:                                        // We know that TrueCrypt is installed but don't know where. It's not safe to continue installing
                   1705:                                        // over the old version.
                   1706: 
                   1707:                                        Error ("UNINSTALL_OLD_VERSION_FIRST");
                   1708: 
                   1709:                                        len = strrchr (rv, '/') - rv - 1;
                   1710:                                        strncpy (InstallationPath, rv, len);    // Path and filename of the uninstaller
                   1711:                                        InstallationPath [len] = 0;
                   1712:                                        bInstallPathDetermined = FALSE;
                   1713: 
                   1714:                                        ShellExecute (NULL, "open", InstallationPath, "/u", NULL, SW_SHOWNORMAL);
                   1715:                                        RegCloseKey (hkey);
                   1716:                                        exit (1);
                   1717:                                }
                   1718:                        }
                   1719: 
                   1720:                }
                   1721:                RegCloseKey (hkey);
                   1722:        }
                   1723: 
                   1724:        if (bInstallPathDetermined)
                   1725:        {
                   1726:                char mp[MAX_PATH];
                   1727: 
                   1728:                // Determine whether we were launched from the folder where TrueCrypt is installed
                   1729:                GetModuleFileName (NULL, mp, sizeof (mp));
                   1730:                if (strncmp (InstallationPath, mp, min (strlen(InstallationPath), strlen(mp))) == 0)
                   1731:                {
                   1732:                        // We were launched from the folder where TrueCrypt is installed
                   1733: 
                   1734:                        if (!IsNonInstallMode() && !bDevm)
                   1735:                                bChangeMode = TRUE;
                   1736:                }
                   1737:        }
                   1738:        else
                   1739:        {
                   1740:                /* TrueCypt is not installed or it wasn't possible to determine where it is installed. */
                   1741: 
                   1742:                // Default "Program Files" path. 
                   1743:                SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &itemList);
                   1744:                SHGetPathFromIDList (itemList, path);
1.1.1.15  root     1745:                strncat (path, "\\TrueCrypt\\", min (strlen("\\TrueCrypt\\"), sizeof(path)-strlen(path)-1));
                   1746:                strncpy (InstallationPath, path, sizeof(InstallationPath)-1);
1.1.1.13  root     1747:        }
                   1748: 
                   1749:        // Make sure the path ends with a backslash
                   1750:        if (InstallationPath [strlen (InstallationPath) - 1] != '\\')
                   1751:        {
                   1752:                strcat (InstallationPath, "\\");
                   1753:        }
                   1754: }
                   1755: 
                   1756: 
                   1757: // Handler for uninstall only (install is handled by the wizard)
1.1.1.18  root     1758: BOOL CALLBACK UninstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1       root     1759: {
                   1760:        WORD lw = LOWORD (wParam);
                   1761: 
                   1762:        switch (msg)
                   1763:        {
                   1764:        case WM_INITDIALOG:
1.1.1.17  root     1765: 
1.1.1.7   root     1766:                MainDlg = hwndDlg;
1.1.1.17  root     1767: 
                   1768:                if (!CreateAppSetupMutex ())
                   1769:                        AbortProcess ("TC_INSTALLER_IS_RUNNING");
                   1770: 
1.1       root     1771:                InitDialog (hwndDlg);
1.1.1.7   root     1772:                LocalizeDialog (hwndDlg, NULL);
1.1       root     1773: 
1.1.1.13  root     1774:                SetWindowTextW (hwndDlg, lpszTitle);
1.1       root     1775: 
1.1.1.13  root     1776:                // System Restore
                   1777:                SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore);
                   1778:                if (SystemRestoreDll == 0)
1.1       root     1779:                {
1.1.1.13  root     1780:                        SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE);
                   1781:                        EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
1.1       root     1782:                }
                   1783: 
1.1.1.13  root     1784:                SetFocus (GetDlgItem (hwndDlg, IDC_UNINSTALL));
1.1.1.11  root     1785: 
1.1       root     1786:                return 1;
                   1787: 
                   1788:        case WM_SYSCOMMAND:
                   1789:                if (lw == IDC_ABOUT)
                   1790:                {
1.1.1.7   root     1791:                        DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1       root     1792:                        return 1;
                   1793:                }
                   1794:                return 0;
                   1795: 
                   1796:        case WM_COMMAND:
1.1.1.13  root     1797:                if (lw == IDC_UNINSTALL)
1.1       root     1798:                {
1.1.1.7   root     1799:                        if (bDone)
1.1       root     1800:                        {
1.1.1.13  root     1801:                                bUninstallInProgress = FALSE;
                   1802:                                PostMessage (hwndDlg, WM_CLOSE, 0, 0);
1.1       root     1803:                                return 1;
                   1804:                        }
                   1805: 
1.1.1.13  root     1806:                        bUninstallInProgress = TRUE;
1.1       root     1807: 
1.1.1.11  root     1808:                        WaitCursor ();
                   1809: 
1.1.1.13  root     1810:                        if (bUninstall)
1.1.1.18  root     1811:                                _beginthread (DoUninstall, 0, (void *) hwndDlg);
1.1       root     1812: 
                   1813:                        return 1;
                   1814:                }
                   1815: 
1.1.1.13  root     1816:                if (lw == IDC_SYSTEM_RESTORE)
1.1       root     1817:                {
1.1.1.13  root     1818:                        bSystemRestore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE));
1.1       root     1819:                        return 1;
                   1820:                }
                   1821: 
1.1.1.13  root     1822:                if (lw == IDCANCEL)
1.1       root     1823:                {
1.1.1.13  root     1824:                        PostMessage (hwndDlg, WM_CLOSE, 0, 0);
1.1       root     1825:                        return 1;
                   1826:                }
                   1827: 
                   1828:                return 0;
                   1829: 
1.1.1.13  root     1830:        case TC_APPMSG_UNINSTALL_SUCCESS:
1.1.1.11  root     1831:                SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), GetString ("FINALIZE"));
                   1832:                NormalCursor ();
1.1.1.13  root     1833:                return 1;
1.1.1.7   root     1834: 
1.1       root     1835:        case WM_CLOSE:
1.1.1.13  root     1836:                if (bUninstallInProgress)
                   1837:                {
                   1838:                        NormalCursor();
                   1839:                        if (AskNoYes("CONFIRM_EXIT_UNIVERSAL") == IDNO)
                   1840:                        {
                   1841:                                return 1;
                   1842:                        }
                   1843:                        WaitCursor ();
                   1844:                }
1.1       root     1845:                EndDialog (hwndDlg, IDCANCEL);
                   1846:                return 1;
                   1847:        }
                   1848: 
                   1849:        return 0;
                   1850: }
                   1851: 
                   1852: 
1.1.1.22  root     1853: int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, int nCmdShow)
1.1       root     1854: {
1.1.1.17  root     1855:        atexit (localcleanup);
                   1856: 
1.1.1.13  root     1857:        SelfExtractStartupInit();
1.1       root     1858: 
1.1.1.7   root     1859:        lpszTitle = L"TrueCrypt Setup";
1.1       root     1860: 
1.1.1.18  root     1861:        InitCommonControls ();
                   1862: 
1.1       root     1863:        /* Call InitApp to initialize the common code */
1.1.1.11  root     1864:        InitApp (hInstance, NULL);
1.1       root     1865: 
1.1.1.7   root     1866:        if (IsAdmin () != TRUE)
                   1867:                if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
1.1.1.13  root     1868:                {
1.1.1.11  root     1869:                        exit (1);
1.1.1.13  root     1870:                }
1.1       root     1871: 
1.1.1.8   root     1872:        /* Setup directory */
                   1873:        {
                   1874:                char *s;
                   1875:                GetModuleFileName (NULL, SetupFilesDir, sizeof (SetupFilesDir));
                   1876:                s = strrchr (SetupFilesDir, '\\');
                   1877:                if (s)
                   1878:                        s[1] = 0;
                   1879:        }
                   1880: 
1.1.1.13  root     1881:        /* Parse command line arguments */
                   1882: 
                   1883:        if (lpszCommandLine[0] == '/')
1.1       root     1884:        {
1.1.1.13  root     1885:                if (lpszCommandLine[1] == 'u')
                   1886:                {
                   1887:                        // Uninstall:   /u
                   1888: 
                   1889:                        bUninstall = TRUE;
                   1890:                }
                   1891:                else if (lpszCommandLine[1] == 'c')
                   1892:                {
                   1893:                        // Change:      /c
1.1       root     1894: 
1.1.1.13  root     1895:                        bChangeMode = TRUE;
                   1896:                }
                   1897:                else if (lpszCommandLine[1] == 'p')
                   1898:                {
                   1899:                        // Create self-extracting package:      /p
                   1900: 
                   1901:                        bMakePackage = TRUE;
                   1902:                }
                   1903:                else if (lpszCommandLine[1] == 'd')
                   1904:                {
                   1905:                        // Dev mode:    /d
                   1906:                        bDevm = TRUE;
                   1907:                }
                   1908:        }
                   1909:  
                   1910:        if (bMakePackage)
1.1.1.11  root     1911:        {
1.1.1.13  root     1912:                /* Create self-extracting package */
1.1.1.11  root     1913: 
1.1.1.13  root     1914:                MakeSelfExtractingPackage (NULL, SetupFilesDir);
                   1915:        }
                   1916:        else
                   1917:        {
                   1918:                SetInstallationPath (NULL);
1.1.1.11  root     1919: 
1.1.1.13  root     1920:                if (!bUninstall)
1.1.1.11  root     1921:                {
1.1.1.13  root     1922:                        if (IsSelfExtractingPackage())
1.1.1.11  root     1923:                        {
1.1.1.13  root     1924:                                if (!VerifyPackageIntegrity())
1.1.1.12  root     1925:                                {
1.1.1.13  root     1926:                                        // Package corrupted 
                   1927:                                        exit (1);
1.1.1.12  root     1928:                                }
1.1.1.13  root     1929:                                bDevm = FALSE;
1.1.1.11  root     1930:                        }
1.1.1.13  root     1931:                        else if (!bDevm)
1.1.1.11  root     1932:                        {
1.1.1.18  root     1933:                                MessageBox (NULL, "Error: This installer file does not contain any compressed files.\n\nTo create a self-extracting installation package (with embedded compressed files), run:\n\"TrueCrypt Setup.exe\" /p", "TrueCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
1.1.1.12  root     1934:                                exit (1);
1.1.1.11  root     1935:                        }
1.1.1.13  root     1936: 
                   1937:                        if (bChangeMode)
                   1938:                        {
                   1939:                                /* TrueCrypt is already installed on this system and we were launched from the Program Files folder */
                   1940: 
                   1941:                                char *tmpStr[] = {0, "SELECT_AN_ACTION", "REPAIR_REINSTALL", "UNINSTALL", "EXIT", 0};
                   1942: 
                   1943:                                // Ask the user to select either Repair or Unistallation
1.1.1.18  root     1944:                                switch (AskMultiChoice ((void **) tmpStr, FALSE))
1.1.1.13  root     1945:                                {
                   1946:                                case 1:
                   1947:                                        bRepairMode = TRUE;
                   1948:                                        break;
                   1949:                                case 2:
                   1950:                                        bUninstall = TRUE;
                   1951:                                        break;
                   1952:                                default:
                   1953:                                        exit (1);
                   1954:                                }
                   1955:                        }
1.1.1.11  root     1956:                }
                   1957: 
1.1.1.13  root     1958:                // System Restore
                   1959:                SystemRestoreDll = LoadLibrary ("srclient.dll");
                   1960: 
                   1961:                if (!bUninstall)
1.1.1.11  root     1962:                {
1.1.1.13  root     1963:                        /* Create the main dialog for install */
1.1.1.11  root     1964: 
1.1.1.13  root     1965:                        DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_INSTL_DLG), NULL, (DLGPROC) MainDialogProc, 
                   1966:                                (LPARAM)lpszCommandLine);
                   1967:                }
                   1968:                else
                   1969:                {
                   1970:                        /* Create the main dialog for uninstall  */
                   1971: 
                   1972:                        DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_UNINSTALL), NULL, (DLGPROC) UninstallDlgProc);
1.1.1.11  root     1973: 
1.1.1.13  root     1974:                        if (UninstallBatch[0])
                   1975:                        {
                   1976:                                STARTUPINFO si;
                   1977:                                PROCESS_INFORMATION pi;
                   1978: 
                   1979:                                ZeroMemory (&si, sizeof (si));
                   1980:                                si.cb = sizeof (si);
                   1981:                                si.dwFlags = STARTF_USESHOWWINDOW;
                   1982:                                si.wShowWindow = SW_HIDE;
                   1983: 
                   1984:                                if (!CreateProcess (UninstallBatch, NULL, NULL, NULL, FALSE, IDLE_PRIORITY_CLASS, NULL, NULL, &si, &pi))
                   1985:                                        DeleteFile (UninstallBatch);
1.1.1.15  root     1986:                                else
                   1987:                                {
                   1988:                                        CloseHandle (pi.hProcess);
                   1989:                                        CloseHandle (pi.hThread);
                   1990:                                }
1.1.1.13  root     1991:                        }
1.1.1.11  root     1992:                }
1.1       root     1993:        }
                   1994: 
                   1995:        return 0;
                   1996: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.