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

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

unix.superglobalmegacorp.com

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