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

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
                      7:  this file are Copyright (c) 2003-2008 TrueCrypt Foundation and are governed
1.1.1.18! root        8:  by the TrueCrypt License 2.6 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: 
                    401:        strcpy (szDir, szDestDir);
                    402:        x = strlen (szDestDir);
                    403:        if (szDestDir[x - 1] == '\\')
                    404:                bSlash = TRUE;
                    405:        else
                    406:                bSlash = FALSE;
                    407: 
                    408:        if (bSlash == FALSE)
                    409:                strcat (szDir, "\\");
                    410: 
1.1.1.7   root      411:        if (bInstallType)
1.1       root      412:        {
                    413: 
1.1.1.11  root      414:                key = "Software\\Classes\\TrueCryptVolume";
1.1       root      415:                RegMessage (hwndDlg, key);
                    416:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    417:                                    key,
                    418:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    419:                        goto error;
                    420: 
1.1.1.10  root      421:                strcpy (szTmp, "TrueCrypt Volume");
1.1       root      422:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    423:                        goto error;
                    424: 
                    425:                RegCloseKey (hkey);
                    426:                hkey = 0;
                    427: 
1.1.1.11  root      428:                key = "Software\\Classes\\TrueCryptVolume\\DefaultIcon";
1.1       root      429:                RegMessage (hwndDlg, key);
                    430:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    431:                                    key,
                    432:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    433:                        goto error;
                    434: 
                    435:                sprintf (szTmp, "%sTrueCrypt.exe,1", szDir);
                    436:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    437:                        goto error;
                    438: 
                    439:                RegCloseKey (hkey);
                    440:                hkey = 0;
                    441: 
1.1.1.11  root      442:                key = "Software\\Classes\\TrueCryptVolume\\Shell\\open\\command";
1.1       root      443:                RegMessage (hwndDlg, key);
                    444:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    445:                                    key,
                    446:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    447:                        goto error;
                    448: 
                    449:                sprintf (szTmp, "\"%sTrueCrypt.exe\" /v \"%%1\"", szDir );
                    450:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    451:                        goto error;
                    452: 
                    453:                RegCloseKey (hkey);
                    454:                hkey = 0;
                    455: 
1.1.1.11  root      456:                key = "Software\\Classes\\.tc";
1.1       root      457:                RegMessage (hwndDlg, key);
                    458:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    459:                                    key,
                    460:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    461:                        goto error;
                    462: 
                    463:                strcpy (szTmp, "TrueCryptVolume");
                    464:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    465:                        goto error;
1.1.1.11  root      466:                
                    467:                RegCloseKey (hkey);
                    468:                hkey = 0;
1.1       root      469:        }
                    470: 
1.1.1.11  root      471:        key = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt";
                    472:        RegMessage (hwndDlg, key);
                    473:        if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    474:                key,
                    475:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    476:                goto error;
1.1       root      477: 
1.1.1.13  root      478:        /* IMPORTANT: IF YOU CHANGE THIS IN ANY WAY, REVISE AND UPDATE SetInstallationPath() ACCORDINGLY! */ 
                    479:        sprintf (szTmp, "\"%sTrueCrypt Setup.exe\" /u", szDir);
1.1.1.11  root      480:        if (RegSetValueEx (hkey, "UninstallString", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    481:                goto error;
1.1       root      482: 
1.1.1.13  root      483:        sprintf (szTmp, "\"%sTrueCrypt Setup.exe\" /c", szDir);
                    484:        if (RegSetValueEx (hkey, "ModifyPath", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    485:                goto error;
                    486: 
1.1.1.11  root      487:        sprintf (szTmp, "\"%sTrueCrypt Setup.exe\"", szDir);
                    488:        if (RegSetValueEx (hkey, "DisplayIcon", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    489:                goto error;
1.1       root      490: 
1.1.1.13  root      491:        strcpy (szTmp, VERSION_STRING);
                    492:        if (RegSetValueEx (hkey, "DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    493:                goto error;
                    494:                
1.1.1.11  root      495:        strcpy (szTmp, "TrueCrypt");
                    496:        if (RegSetValueEx (hkey, "DisplayName", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    497:                goto error;
1.1       root      498: 
1.1.1.11  root      499:        strcpy (szTmp, "TrueCrypt Foundation");
                    500:        if (RegSetValueEx (hkey, "Publisher", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    501:                goto error;
1.1       root      502: 
1.1.1.17  root      503:        sprintf (szTmp, "%s&dest=index", TC_APPLINK);
1.1.1.11  root      504:        if (RegSetValueEx (hkey, "URLInfoAbout", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    505:                goto error;
                    506:                
1.1       root      507:        bOK = TRUE;
                    508: 
1.1.1.11  root      509: error:
1.1       root      510:        if (hkey != 0)
                    511:                RegCloseKey (hkey);
                    512: 
                    513:        if (bOK == FALSE)
                    514:        {
                    515:                handleWin32Error (hwndDlg);
1.1.1.11  root      516:                Error ("REG_INSTALL_FAILED");
                    517:        }
                    518:        
                    519:        // Register COM servers for UAC
                    520:        if (nCurrentOS == WIN_VISTA_OR_LATER)
                    521:        {
                    522:                if (!RegisterComServers (szDir))
                    523:                {
                    524:                        Error ("COM_REG_FAILED");
                    525:                        return FALSE;
                    526:                }
1.1       root      527:        }
                    528: 
                    529:        return bOK;
                    530: }
                    531: 
1.1.1.18! root      532: BOOL DoApplicationDataUninstall (HWND hwndDlg)
1.1.1.7   root      533: {
                    534:        char path[MAX_PATH];
                    535:        char path2[MAX_PATH];
                    536:        BOOL bOK = TRUE;
                    537: 
                    538:        StatusMessage (hwndDlg, "REMOVING_APPDATA");
                    539: 
                    540:        SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
                    541:        strcat (path, "\\TrueCrypt\\");
                    542: 
                    543:        // Delete favorite volumes file
1.1.1.18! root      544:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_FAVORITE_VOLUMES);
1.1.1.7   root      545:        RemoveMessage (hwndDlg, path2);
                    546:        StatDeleteFile (path2);
                    547: 
                    548:        // Delete keyfile defaults
1.1.1.18! root      549:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_DEFAULT_KEYFILES);
1.1.1.7   root      550:        RemoveMessage (hwndDlg, path2);
                    551:        StatDeleteFile (path2);
                    552: 
                    553:        // Delete history file
1.1.1.18! root      554:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_HISTORY);
1.1.1.7   root      555:        RemoveMessage (hwndDlg, path2);
                    556:        StatDeleteFile (path2);
                    557:        
                    558:        // Delete configuration file
1.1.1.18! root      559:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_CONFIGURATION);
1.1.1.7   root      560:        RemoveMessage (hwndDlg, path2);
                    561:        StatDeleteFile (path2);
                    562: 
1.1.1.13  root      563:        // Delete system encryption configuration file
1.1.1.18! root      564:        sprintf (path2, "%s%s", path, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
1.1.1.13  root      565:        RemoveMessage (hwndDlg, path2);
                    566:        StatDeleteFile (path2);
                    567: 
1.1.1.7   root      568:        SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
                    569:        strcat (path, "\\TrueCrypt");
                    570:        RemoveMessage (hwndDlg, path);
                    571:        if (!StatRemoveDirectory (path))
                    572:        {
                    573:                handleWin32Error (hwndDlg);
                    574:                bOK = FALSE;
                    575:        }
                    576: 
                    577:        return bOK;
                    578: }
                    579: 
1.1.1.18! root      580: BOOL DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated)
1.1       root      581: {
                    582:        BOOL bOK = FALSE;
1.1.1.7   root      583:        char regk [64];
1.1       root      584: 
1.1.1.11  root      585:        // Unregister COM servers
                    586:        if (!bRemoveDeprecated && nCurrentOS == WIN_VISTA_OR_LATER)
                    587:        {
1.1.1.13  root      588:                if (!UnregisterComServers (InstallationPath))
1.1.1.11  root      589:                        StatusMessage (hwndDlg, "COM_DEREG_FAILED");
                    590:        }
                    591: 
                    592:        if (!bRemoveDeprecated)
                    593:                StatusMessage (hwndDlg, "REMOVING_REG");
1.1       root      594: 
1.1.1.11  root      595:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt");
                    596:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell\\open\\command");
                    597:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell\\open");
                    598:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell");
                    599:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\DefaultIcon");
                    600:        RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume");
                    601:        RegDeleteKey (HKEY_CURRENT_USER, "Software\\TrueCrypt");
1.1.1.7   root      602: 
                    603:        if (!bRemoveDeprecated)
                    604:        {
                    605:                // Split the string in order to prevent some antivirus packages from falsely reporting  
                    606:                // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
                    607:                sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
                    608:                DeleteRegistryValue (regk, "TrueCrypt");
                    609: 
1.1.1.11  root      610:                RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\.tc");
1.1.1.7   root      611:        }
1.1       root      612: 
                    613:        bOK = TRUE;
                    614: 
                    615:        if (bOK == FALSE && GetLastError ()!= ERROR_NO_TOKEN && GetLastError ()!= ERROR_FILE_NOT_FOUND
                    616:            && GetLastError ()!= ERROR_PATH_NOT_FOUND)
                    617:        {
                    618:                handleWin32Error (hwndDlg);
                    619:        }
                    620:        else
                    621:                bOK = TRUE;
                    622: 
                    623:        return bOK;
                    624: }
                    625: 
1.1.1.11  root      626: 
1.1.1.18! root      627: BOOL DoServiceUninstall (HWND hwndDlg, char *lpszService)
1.1       root      628: {
                    629:        SC_HANDLE hManager, hService = NULL;
                    630:        BOOL bOK = FALSE, bRet;
                    631:        SERVICE_STATUS status;
1.1.1.6   root      632:        BOOL firstTry = TRUE;
1.1       root      633:        int x;
                    634: 
1.1.1.6   root      635:        memset (&status, 0, sizeof (status));   /* Keep VC6 quiet */
                    636: 
                    637: retry:
1.1       root      638: 
                    639:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    640:        if (hManager == NULL)
                    641:                goto error;
                    642: 
                    643:        hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
                    644:        if (hService == NULL)
                    645:                goto error;
                    646: 
1.1.1.7   root      647:        if (strcmp ("truecrypt", lpszService) == 0)
                    648:                StatusMessage (hwndDlg, "STOPPING_DRIVER");
                    649:        else
                    650:                StatusMessageParam (hwndDlg, "STOPPING", lpszService);
1.1       root      651: 
                    652: #define WAIT_PERIOD 3
                    653: 
                    654:        for (x = 0; x < WAIT_PERIOD; x++)
                    655:        {
                    656:                bRet = QueryServiceStatus (hService, &status);
                    657:                if (bRet != TRUE)
                    658:                        goto error;
                    659: 
                    660:                if (status.dwCurrentState != SERVICE_START_PENDING &&
                    661:                    status.dwCurrentState != SERVICE_STOP_PENDING &&
                    662:                    status.dwCurrentState != SERVICE_CONTINUE_PENDING)
                    663:                        break;
                    664: 
                    665:                Sleep (1000);
                    666:        }
                    667: 
                    668:        if (status.dwCurrentState != SERVICE_STOPPED)
                    669:        {
                    670:                bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status);
                    671:                if (bRet == FALSE)
                    672:                        goto try_delete;
                    673: 
                    674:                for (x = 0; x < WAIT_PERIOD; x++)
                    675:                {
                    676:                        bRet = QueryServiceStatus (hService, &status);
                    677:                        if (bRet != TRUE)
                    678:                                goto error;
                    679: 
                    680:                        if (status.dwCurrentState != SERVICE_START_PENDING &&
                    681:                            status.dwCurrentState != SERVICE_STOP_PENDING &&
                    682:                          status.dwCurrentState != SERVICE_CONTINUE_PENDING)
                    683:                                break;
                    684: 
                    685:                        Sleep (1000);
                    686:                }
                    687: 
                    688:                if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
                    689:                        goto error;
                    690:        }
                    691: 
1.1.1.6   root      692: try_delete:
                    693: 
1.1.1.7   root      694:        if (strcmp ("truecrypt", lpszService) == 0)
                    695:                StatusMessage (hwndDlg, "REMOVING_DRIVER");
                    696:        else
                    697:                StatusMessageParam (hwndDlg, "REMOVING", lpszService);
1.1       root      698: 
                    699:        if (hService != NULL)
                    700:                CloseServiceHandle (hService);
                    701: 
                    702:        if (hManager != NULL)
                    703:                CloseServiceHandle (hManager);
                    704: 
                    705:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    706:        if (hManager == NULL)
                    707:                goto error;
                    708: 
                    709:        hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
                    710:        if (hService == NULL)
                    711:                goto error;
                    712: 
                    713:        bRet = DeleteService (hService);
                    714:        if (bRet == FALSE)
1.1.1.6   root      715:        {
                    716:                if (firstTry && GetLastError () == ERROR_SERVICE_MARKED_FOR_DELETE)
                    717:                {
                    718:                        // Second try for an eventual no-install driver instance
                    719:                        CloseServiceHandle (hService);
                    720:                        CloseServiceHandle (hManager);
                    721: 
                    722:                        Sleep(1000);
                    723:                        firstTry = FALSE;
                    724:                        goto retry;
                    725:                }
                    726: 
1.1       root      727:                goto error;
1.1.1.6   root      728:        }
1.1       root      729: 
                    730:        bOK = TRUE;
                    731: 
1.1.1.6   root      732: error:
                    733: 
1.1       root      734:        if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
                    735:        {
                    736:                handleWin32Error (hwndDlg);
1.1.1.7   root      737:                MessageBoxW (hwndDlg, GetString ("DRIVER_UINSTALL_FAILED"), lpszTitle, MB_ICONHAND);
1.1       root      738:        }
                    739:        else
                    740:                bOK = TRUE;
                    741: 
                    742:        if (hService != NULL)
                    743:                CloseServiceHandle (hService);
                    744: 
                    745:        if (hManager != NULL)
                    746:                CloseServiceHandle (hManager);
                    747: 
                    748:        return bOK;
                    749: }
                    750: 
1.1.1.7   root      751: 
1.1.1.15  root      752: BOOL DoDriverUnload (HWND hwndDlg)
1.1       root      753: {
                    754:        BOOL bOK = TRUE;
                    755:        int status;
                    756: 
                    757:        status = DriverAttach ();
                    758:        if (status != 0)
                    759:        {
1.1.1.11  root      760:                if (status == ERR_OS_ERROR && GetLastError () != ERROR_FILE_NOT_FOUND)
1.1       root      761:                {
                    762:                        handleWin32Error (hwndDlg);
1.1.1.7   root      763:                        AbortProcess ("NODRIVER");
1.1       root      764:                }
                    765: 
                    766:                if (status != ERR_OS_ERROR)
                    767:                {
                    768:                        handleError (NULL, status);
1.1.1.7   root      769:                        AbortProcess ("NODRIVER");
1.1       root      770:                }
                    771:        }
                    772: 
                    773:        if (hDriver != INVALID_HANDLE_VALUE)
                    774:        {
1.1.1.3   root      775:                MOUNT_LIST_STRUCT driver;
1.1.1.11  root      776:                LONG driverVersion = VERSION_NUM;
1.1.1.7   root      777:                int refCount;
1.1.1.3   root      778:                DWORD dwResult;
                    779:                BOOL bResult;
1.1.1.13  root      780:                int volumesMounted;
                    781: 
1.1.1.14  root      782:                // Try to determine if it's upgrade (and not reinstall, downgrade, or first-time install).
                    783:                bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
                    784: 
                    785:                if (!bResult)
                    786:                        bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
                    787: 
                    788:                bUpgrade = bResult && driverVersion < VERSION_NUM;
1.1.1.18! root      789:                bDowngrade = bResult && driverVersion > VERSION_NUM;
1.1.1.14  root      790: 
1.1.1.13  root      791:                // Test for encrypted boot drive
                    792:                try
                    793:                {
                    794:                        BootEncryption bootEnc (hwndDlg);
                    795:                        if (bootEnc.GetDriverServiceStartType() == SERVICE_BOOT_START)
                    796:                        {
1.1.1.17  root      797:                                try
                    798:                                {
                    799:                                        // Check hidden OS update consistency
                    800:                                        if (IsHiddenOSRunning())
                    801:                                        {
                    802:                                                if (bootEnc.GetInstalledBootLoaderVersion() != VERSION_NUM)
                    803:                                                {
                    804:                                                        if (AskWarnNoYes ("UPDATE_TC_IN_DECOY_OS_FIRST") == IDNO)
                    805:                                                                AbortProcessSilent ();
                    806:                                                }
                    807:                                        }
                    808:                                }
                    809:                                catch (...) { }
                    810: 
1.1.1.15  root      811:                                if (bUninstallInProgress && driverVersion >= 0x500 && !bootEnc.GetStatus().DeviceFilterActive)
                    812:                                {
1.1.1.17  root      813:                                        bootEnc.RegisterFilterDriver (false, false);
                    814:                                        bootEnc.RegisterFilterDriver (false, true);
1.1.1.15  root      815:                                        bootEnc.SetDriverServiceStartType (SERVICE_SYSTEM_START);
                    816:                                }
1.1.1.18! root      817:                                else if (bDowngrade || driverVersion < 0x500)
1.1.1.14  root      818:                                {
                    819:                                        Error ("SETUP_FAILED_BOOT_DRIVE_ENCRYPTED");
                    820:                                        return FALSE;
                    821:                                }
1.1.1.15  root      822:                                else
                    823:                                {
                    824:                                        SystemEncryptionUpgrade = TRUE;
                    825:                                }
1.1.1.13  root      826:                        }
                    827:                }
                    828:                catch (...)     { }
1.1       root      829: 
1.1.1.14  root      830:                if (!SystemEncryptionUpgrade)
                    831:                {
                    832:                        // Check mounted volumes
                    833:                        bResult = DeviceIoControl (hDriver, TC_IOCTL_IS_ANY_VOLUME_MOUNTED, NULL, 0, &volumesMounted, sizeof (volumesMounted), &dwResult, NULL);
1.1.1.13  root      834: 
1.1.1.14  root      835:                        if (!bResult)
                    836:                        {
                    837:                                bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES, NULL, 0, &driver, sizeof (driver), &dwResult, NULL);
                    838:                                if (bResult)
                    839:                                        volumesMounted = driver.ulMountedDrives;
                    840:                        }
1.1.1.13  root      841: 
                    842:                        if (bResult)
1.1.1.14  root      843:                        {
                    844:                                if (volumesMounted != 0)
                    845:                                {
                    846:                                        bOK = FALSE;
                    847:                                        MessageBoxW (hwndDlg, GetString ("DISMOUNT_ALL_FIRST"), lpszTitle, MB_ICONHAND);
                    848:                                }
                    849:                        }
                    850:                        else
1.1       root      851:                        {
                    852:                                bOK = FALSE;
1.1.1.14  root      853:                                handleWin32Error (hwndDlg);
1.1       root      854:                        }
                    855:                }
1.1.1.14  root      856: 
1.1.1.7   root      857:                // Try to close all open TC windows
1.1.1.11  root      858:                if (bOK)
1.1.1.7   root      859:                {
                    860:                        BOOL TCWindowClosed = FALSE;
1.1.1.11  root      861: 
1.1.1.7   root      862:                        EnumWindows (CloseTCWindowsEnum, (LPARAM) &TCWindowClosed);
1.1.1.11  root      863: 
                    864:                        if (TCWindowClosed) 
                    865:                                Sleep (2000);
1.1.1.7   root      866:                }
                    867: 
                    868:                // Test for any applications attached to driver
1.1.1.13  root      869:                bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DEVICE_REFCOUNT, &refCount, sizeof (refCount), &refCount,
1.1.1.7   root      870:                        sizeof (refCount), &dwResult, NULL);
                    871: 
                    872:                if (bOK && bResult && refCount > 1)
                    873:                {
                    874:                        MessageBoxW (hwndDlg, GetString ("CLOSE_TC_FIRST"), lpszTitle, MB_ICONSTOP);
                    875:                        bOK = FALSE;
                    876:                }
1.1       root      877: 
1.1.1.14  root      878:                if (!bOK || !SystemEncryptionUpgrade)
                    879:                {
                    880:                        CloseHandle (hDriver);
                    881:                        hDriver = INVALID_HANDLE_VALUE;
                    882:                }
1.1       root      883:        }
1.1.1.11  root      884:        else
                    885:        {
                    886:                bFirstTimeInstall = TRUE;
                    887:        }
1.1       root      888: 
                    889:        return bOK;
                    890: }
                    891: 
                    892: 
1.1.1.14  root      893: BOOL UpgradeBootLoader (HWND hwndDlg)
                    894: {
                    895:        if (!SystemEncryptionUpgrade)
                    896:                return TRUE;
                    897: 
                    898:        try
                    899:        {
                    900:                BootEncryption bootEnc (hwndDlg);
                    901:                if (bootEnc.GetInstalledBootLoaderVersion() < VERSION_NUM)
                    902:                {
1.1.1.17  root      903:                        StatusMessage (hwndDlg, "INSTALLER_UPDATING_BOOT_LOADER");
                    904: 
1.1.1.18! root      905:                        bootEnc.InstallBootLoader (true);
1.1.1.17  root      906:                        Info (IsHiddenOSRunning () ? "BOOT_LOADER_UPGRADE_OK_HIDDEN_OS" : "BOOT_LOADER_UPGRADE_OK");
1.1.1.14  root      907:                }
                    908:                return TRUE;
                    909:        }
                    910:        catch (Exception &e)
                    911:        {
                    912:                e.Show (hwndDlg);
                    913:        }
                    914:        catch (...) { }
                    915: 
                    916:        Error ("BOOT_LOADER_UPGRADE_FAILED");
                    917:        return FALSE;
                    918: }
                    919: 
                    920: 
1.1.1.15  root      921: BOOL DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
1.1       root      922: {
1.1.1.11  root      923:        char szLinkDir[TC_MAX_PATH];
1.1.1.7   root      924:        char szTmp2[TC_MAX_PATH];
1.1       root      925:        BOOL bSlash, bOK = FALSE;
                    926:        HRESULT hOle;
                    927:        int x;
                    928:        BOOL allUsers = FALSE;
                    929: 
                    930:        hOle = OleInitialize (NULL);
                    931: 
                    932:        // User start menu
                    933:     SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
                    934:        x = strlen (szLinkDir);
                    935:        if (szLinkDir[x - 1] == '\\')
                    936:                bSlash = TRUE;
                    937:        else
                    938:                bSlash = FALSE;
                    939: 
                    940:        if (bSlash == FALSE)
                    941:                strcat (szLinkDir, "\\");
                    942: 
                    943:        strcat (szLinkDir, "TrueCrypt");
                    944: 
                    945:        // Global start menu
                    946:        {
                    947:                struct _stat st;
                    948:                char path[TC_MAX_PATH];
                    949: 
                    950:                SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
                    951:                strcat (path, "\\TrueCrypt");
                    952: 
                    953:                if (_stat (path, &st) == 0)
                    954:                {
                    955:                        strcpy (szLinkDir, path);
                    956:                        allUsers = TRUE;
                    957:                }
                    958:        }
                    959: 
                    960:        // Start menu entries
                    961:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                    962:        RemoveMessage (hwndDlg, szTmp2);
                    963:        if (StatDeleteFile (szTmp2) == FALSE)
                    964:                goto error;
                    965: 
1.1.1.11  root      966:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url");
1.1       root      967:        RemoveMessage (hwndDlg, szTmp2);
                    968:        if (StatDeleteFile (szTmp2) == FALSE)
                    969:                goto error;
                    970: 
                    971:        sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
                    972:        RemoveMessage (hwndDlg, szTmp2);
                    973:        if (StatDeleteFile (szTmp2) == FALSE)
                    974:                goto error;
1.1.1.11  root      975:        
                    976:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
                    977:        DeleteFile (szTmp2);
1.1       root      978: 
                    979:        // Start menu group
                    980:        RemoveMessage ((HWND) hwndDlg, szLinkDir);
                    981:        if (StatRemoveDirectory (szLinkDir) == FALSE)
                    982:                handleWin32Error ((HWND) hwndDlg);
                    983: 
                    984:        // Desktop icon
                    985: 
                    986:        if (allUsers)
                    987:                SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
                    988:        else
                    989:                SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
                    990: 
                    991:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                    992: 
                    993:        RemoveMessage (hwndDlg, szTmp2);
                    994:        if (StatDeleteFile (szTmp2) == FALSE)
                    995:                goto error;
                    996: 
                    997:        bOK = TRUE;
                    998: 
                    999: error:
                   1000:        OleUninitialize ();
                   1001: 
                   1002:        return bOK;
                   1003: }
                   1004: 
1.1.1.18! root     1005: BOOL DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
1.1       root     1006: {
                   1007:        char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
1.1.1.7   root     1008:        char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH], szTmp3[TC_MAX_PATH];
1.1       root     1009:        BOOL bSlash, bOK = FALSE;
                   1010:        HRESULT hOle;
                   1011:        int x;
                   1012: 
                   1013:        if (bProgGroup == FALSE && bDesktopIcon == FALSE)
                   1014:                return TRUE;
                   1015: 
                   1016:        hOle = OleInitialize (NULL);
                   1017: 
                   1018:        GetProgramPath (hwndDlg, szLinkDir);
                   1019: 
                   1020:        x = strlen (szLinkDir);
                   1021:        if (szLinkDir[x - 1] == '\\')
                   1022:                bSlash = TRUE;
                   1023:        else
                   1024:                bSlash = FALSE;
                   1025: 
                   1026:        if (bSlash == FALSE)
                   1027:                strcat (szLinkDir, "\\");
                   1028: 
                   1029:        strcat (szLinkDir, "TrueCrypt");
                   1030: 
                   1031:        strcpy (szDir, szDestDir);
                   1032:        x = strlen (szDestDir);
                   1033:        if (szDestDir[x - 1] == '\\')
                   1034:                bSlash = TRUE;
                   1035:        else
                   1036:                bSlash = FALSE;
                   1037: 
                   1038:        if (bSlash == FALSE)
                   1039:                strcat (szDir, "\\");
                   1040: 
                   1041:        if (bProgGroup)
                   1042:        {
1.1.1.11  root     1043:                FILE *f;
                   1044: 
1.1       root     1045:                if (mkfulldir (szLinkDir, TRUE) != 0)
                   1046:                {
                   1047:                        if (mkfulldir (szLinkDir, FALSE) != 0)
                   1048:                        {
1.1.1.13  root     1049:                                wchar_t szTmp[TC_MAX_PATH];
                   1050: 
1.1       root     1051:                                handleWin32Error (hwndDlg);
1.1.1.7   root     1052:                                wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), szLinkDir);
                   1053:                                MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1.1       root     1054:                                goto error;
                   1055:                        }
                   1056:                }
                   1057: 
                   1058:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
                   1059:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                   1060: 
                   1061:                IconMessage (hwndDlg, szTmp2);
                   1062:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                   1063:                        goto error;
                   1064: 
1.1.1.11  root     1065:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url");
1.1       root     1066:                IconMessage (hwndDlg, szTmp2);
1.1.1.11  root     1067:                f = fopen (szTmp2, "w");
                   1068:                if (f)
                   1069:                {
                   1070:                        fprintf (f, "[InternetShortcut]\nURL=%s&dest=index\n", TC_APPLINK);
                   1071:                        fclose (f);
                   1072:                }
1.1       root     1073:                else
1.1.1.11  root     1074:                        goto error;
1.1       root     1075: 
                   1076:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
                   1077:                sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
1.1.1.13  root     1078:                strcpy (szTmp3, "/u");
1.1       root     1079: 
                   1080:                IconMessage (hwndDlg, szTmp2);
1.1.1.7   root     1081:                if (CreateLink (szTmp, szTmp3, szTmp2) != S_OK)
1.1       root     1082:                        goto error;
                   1083: 
1.1.1.11  root     1084:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
                   1085:                DeleteFile (szTmp2);
1.1       root     1086:        }
                   1087: 
                   1088:        if (bDesktopIcon)
                   1089:        {
                   1090:                strcpy (szDir, szDestDir);
                   1091:                x = strlen (szDestDir);
                   1092:                if (szDestDir[x - 1] == '\\')
                   1093:                        bSlash = TRUE;
                   1094:                else
                   1095:                        bSlash = FALSE;
                   1096: 
                   1097:                if (bSlash == FALSE)
                   1098:                        strcat (szDir, "\\");
                   1099: 
1.1.1.13  root     1100:                if (bForAllUsers)
1.1       root     1101:                        SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
                   1102:                else
                   1103:                        SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
                   1104: 
                   1105:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
                   1106:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                   1107: 
                   1108:                IconMessage (hwndDlg, szTmp2);
                   1109: 
                   1110:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                   1111:                        goto error;
                   1112:        }
                   1113: 
                   1114:        bOK = TRUE;
                   1115: 
                   1116: error:
                   1117:        OleUninitialize ();
                   1118: 
                   1119:        return bOK;
                   1120: }
                   1121: 
                   1122: 
1.1.1.18! root     1123: void OutcomePrompt (HWND hwndDlg, BOOL bOK)
1.1       root     1124: {
1.1.1.7   root     1125:        if (bOK)
1.1       root     1126:        {
                   1127:                EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
                   1128: 
                   1129:                bDone = TRUE;
                   1130: 
1.1.1.7   root     1131:                if (bUninstall == FALSE)
1.1.1.13  root     1132:                {
                   1133:                        if (bDevm)
                   1134:                                PostMessage (MainDlg, WM_CLOSE, 0, 0);
1.1.1.18! root     1135:                        else if (bFirstTimeInstall && !SystemEncryptionUpgrade && !bUpgrade && !bDowngrade && !bRepairMode)
1.1.1.13  root     1136:                                Info ("INSTALL_OK");
1.1.1.18! root     1137:                        else
        !          1138:                                Info ("SETUP_UPDATE_OK");
1.1.1.13  root     1139:                }
1.1       root     1140:                else
1.1.1.11  root     1141:                {
                   1142:                        wchar_t str[4096];
                   1143: 
1.1.1.13  root     1144:                        swprintf (str, GetString ("UNINSTALL_OK"), InstallationPath);
1.1.1.11  root     1145:                        MessageBoxW (hwndDlg, str, lpszTitle, MB_ICONASTERISK);
                   1146:                }
1.1       root     1147:        }
                   1148:        else
                   1149:        {
                   1150:                if (bUninstall == FALSE)
1.1.1.11  root     1151:                        Error ("INSTALL_FAILED");
1.1       root     1152:                else
1.1.1.11  root     1153:                        Error ("UNINSTALL_FAILED");
1.1       root     1154:        }
                   1155: }
                   1156: 
1.1.1.13  root     1157: static void SetSystemRestorePoint (HWND hwndDlg, BOOL finalize)
1.1       root     1158: {
                   1159:        static RESTOREPOINTINFO RestPtInfo;
                   1160:        static STATEMGRSTATUS SMgrStatus;
                   1161:        static BOOL failed = FALSE;
                   1162:        static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
                   1163:        
                   1164:        if (!SystemRestoreDll) return;
                   1165: 
                   1166:        _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA");
                   1167:        if (_SRSetRestorePoint == 0)
                   1168:        {
                   1169:                FreeLibrary (SystemRestoreDll);
                   1170:                SystemRestoreDll = 0;
                   1171:                return;
                   1172:        }
                   1173: 
                   1174:        if (!finalize)
                   1175:        {
1.1.1.7   root     1176:                StatusMessage (hwndDlg, "CREATING_SYS_RESTORE");
1.1       root     1177: 
                   1178:                RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
                   1179:                RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;
                   1180:                RestPtInfo.llSequenceNumber = 0;
1.1.1.13  root     1181:                strcpy (RestPtInfo.szDescription, bUninstall ? "TrueCrypt uninstallation" : "TrueCrypt installation");
1.1       root     1182: 
1.1.1.7   root     1183:                if(!_SRSetRestorePoint (&RestPtInfo, &SMgrStatus)) 
1.1       root     1184:                {
1.1.1.7   root     1185:                        StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
1.1       root     1186:                        failed = TRUE;
                   1187:                }
                   1188:        }
1.1.1.11  root     1189:        else if (!failed)
1.1       root     1190:        {
1.1.1.11  root     1191:                RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
                   1192:                RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
                   1193: 
                   1194:                if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus)) 
                   1195:                {
                   1196:                        StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
                   1197:                }
                   1198:                else
                   1199:                        StatusMessage (hwndDlg, "SYS_RESTORE_CREATED");
1.1       root     1200:        }
                   1201: }
                   1202: 
1.1.1.18! root     1203: void DoUninstall (void *arg)
1.1       root     1204: {
1.1.1.13  root     1205:        HWND hwndDlg = (HWND) arg;
1.1       root     1206:        BOOL bOK = TRUE;
1.1.1.13  root     1207:        BOOL bTempSkipSysRestore = FALSE;
1.1       root     1208: 
1.1.1.11  root     1209:        if (!Rollback)
                   1210:                EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), FALSE);
1.1       root     1211: 
                   1212:        WaitCursor ();
                   1213: 
1.1.1.11  root     1214:        if (!Rollback)
1.1       root     1215:        {
1.1.1.13  root     1216:                ClearLogWindow (hwndDlg);
1.1       root     1217:        }
1.1.1.13  root     1218: 
                   1219:        if (DoDriverUnload (hwndDlg) == FALSE)
1.1.1.7   root     1220:        {
                   1221:                bOK = FALSE;
1.1.1.13  root     1222:                bTempSkipSysRestore = TRUE;             // Volumes are possibly mounted; defer System Restore point creation for this uninstall attempt.
1.1.1.7   root     1223:        }
1.1       root     1224:        else
                   1225:        {
1.1.1.13  root     1226:                if (!Rollback && bSystemRestore && !bTempSkipSysRestore)
                   1227:                        SetSystemRestorePoint (hwndDlg, FALSE);
1.1.1.11  root     1228: 
1.1.1.13  root     1229:                if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
                   1230:                {
1.1.1.11  root     1231:                        bOK = FALSE;
1.1.1.13  root     1232:                }
                   1233:                else if (DoRegUninstall ((HWND) hwndDlg, FALSE) == FALSE)
                   1234:                {
                   1235:                        bOK = FALSE;
                   1236:                }
                   1237:                else if (DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
                   1238:                {
                   1239:                        bOK = FALSE;
                   1240:                }
                   1241:                else if (DoShortcutsUninstall (hwndDlg, InstallationPath) == FALSE)
                   1242:                {
                   1243:                        bOK = FALSE;
                   1244:                }
                   1245:                else if (!DoApplicationDataUninstall (hwndDlg))
                   1246:                {
                   1247:                        bOK = FALSE;
                   1248:                }
1.1.1.11  root     1249:                else
1.1       root     1250:                {
1.1.1.13  root     1251:                        char temp[MAX_PATH];
                   1252:                        FILE *f;
                   1253: 
                   1254:                        // Deprecated service
                   1255:                        DoServiceUninstall (hwndDlg, "TrueCryptService");
                   1256: 
                   1257:                        GetTempPath (sizeof (temp), temp);
                   1258:                        _snprintf (UninstallBatch, sizeof (UninstallBatch), "%s\\TrueCrypt-Uninstall.bat", temp);
                   1259: 
1.1.1.15  root     1260:                        UninstallBatch [sizeof(UninstallBatch)-1] = 0;
                   1261: 
1.1.1.13  root     1262:                        // Create uninstall batch
                   1263:                        f = fopen (UninstallBatch, "w");
                   1264:                        if (!f)
                   1265:                                bOK = FALSE;
                   1266:                        else
                   1267:                        {
                   1268:                                fprintf (f, ":loop\n"
                   1269:                                        "del \"%s%s\"\n"
                   1270:                                        "if exist \"%s%s\" goto loop\n"
                   1271:                                        "rmdir \"%s\"\n"
                   1272:                                        "del \"%s\"",
                   1273:                                        InstallationPath, "TrueCrypt Setup.exe",
                   1274:                                        InstallationPath, "TrueCrypt Setup.exe",
                   1275:                                        InstallationPath,
                   1276:                                        UninstallBatch
                   1277:                                        );
                   1278:                                fclose (f);
                   1279:                        }
1.1       root     1280:                }
                   1281:        }
                   1282: 
                   1283:        NormalCursor ();
                   1284: 
1.1.1.11  root     1285:        if (Rollback)
                   1286:                return;
                   1287: 
1.1.1.13  root     1288:        if (bSystemRestore && !bTempSkipSysRestore)
                   1289:                SetSystemRestorePoint (hwndDlg, TRUE);
                   1290: 
1.1.1.7   root     1291:        if (bOK)
1.1.1.13  root     1292:                PostMessage (hwndDlg, TC_APPMSG_UNINSTALL_SUCCESS, 0, 0);
                   1293:        else
                   1294:                bUninstallInProgress = FALSE;
                   1295: 
1.1.1.7   root     1296:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), TRUE);
1.1.1.11  root     1297:        OutcomePrompt (hwndDlg, bOK);
1.1       root     1298: }
                   1299: 
1.1.1.18! root     1300: void DoInstall (void *arg)
1.1       root     1301: {
1.1.1.13  root     1302:        HWND hwndDlg = (HWND) arg;
1.1       root     1303:        BOOL bOK = TRUE;
1.1.1.11  root     1304:        char path[MAX_PATH];
1.1       root     1305: 
1.1.1.17  root     1306:        BootEncryption bootEnc (hwndDlg);
                   1307: 
1.1.1.13  root     1308:        // Refresh the main GUI (wizard thread)
                   1309:        InvalidateRect (GetDlgItem (MainDlg, IDD_INSTL_DLG), NULL, TRUE);
                   1310: 
                   1311:        ClearLogWindow(hwndDlg);
                   1312: 
                   1313:        if (mkfulldir (InstallationPath, TRUE) != 0)
                   1314:        {
                   1315:                if (mkfulldir (InstallationPath, FALSE) != 0)
                   1316:                {
                   1317:                        wchar_t szTmp[TC_MAX_PATH];
                   1318: 
                   1319:                        handleWin32Error (hwndDlg);
                   1320:                        wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), InstallationPath);
                   1321:                        MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
                   1322:                        Error ("INSTALL_FAILED");
                   1323:                        PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
                   1324:                        return;
                   1325:                }
                   1326:        }
                   1327: 
                   1328:        UpdateProgressBarProc(2);
1.1       root     1329: 
                   1330:        if (DoDriverUnload (hwndDlg) == FALSE)
                   1331:        {
1.1.1.4   root     1332:                NormalCursor ();
1.1.1.13  root     1333:                PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
1.1.1.4   root     1334:                return;
1.1       root     1335:        }
1.1.1.13  root     1336: 
                   1337:        UpdateProgressBarProc(12);
1.1.1.4   root     1338:        
1.1.1.13  root     1339:        if (bSystemRestore)
1.1.1.4   root     1340:                SetSystemRestorePoint (hwndDlg, FALSE);
                   1341: 
1.1.1.17  root     1342:        UpdateProgressBarProc(48);
                   1343:        
                   1344:        if (bDisableSwapFiles
1.1.1.18! root     1345:                && IsPagingFileActive (FALSE))
1.1.1.17  root     1346:        {
                   1347:                if (!DisablePagingFile())
                   1348:                {
                   1349:                        handleWin32Error (hwndDlg);
                   1350:                        Error ("FAILED_TO_DISABLE_PAGING_FILES");
                   1351:                }
                   1352:                else
                   1353:                        bRestartRequired = TRUE;
                   1354:        }
                   1355: 
1.1.1.13  root     1356:        UpdateProgressBarProc(50);
                   1357: 
1.1.1.11  root     1358:        // Remove deprecated
1.1.1.7   root     1359:        DoServiceUninstall (hwndDlg, "TrueCryptService");
1.1.1.11  root     1360:        
1.1.1.13  root     1361:        UpdateProgressBarProc(55);
                   1362: 
1.1.1.14  root     1363:        if (!SystemEncryptionUpgrade)
                   1364:                DoRegUninstall ((HWND) hwndDlg, TRUE);
1.1.1.7   root     1365: 
1.1.1.13  root     1366:        UpdateProgressBarProc(62);
                   1367: 
1.1.1.11  root     1368:        GetWindowsDirectory (path, sizeof (path));
                   1369:        strcat_s (path, sizeof (path), "\\TrueCrypt Setup.exe");
                   1370:        DeleteFile (path);
                   1371: 
1.1.1.14  root     1372:        if (UpdateProgressBarProc(63) && !SystemEncryptionUpgrade && DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1.1       root     1373:        {
                   1374:                bOK = FALSE;
                   1375:        }
1.1.1.13  root     1376:        else if (UpdateProgressBarProc(72) && DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
1.1       root     1377:        {
                   1378:                bOK = FALSE;
                   1379:        }
1.1.1.14  root     1380:        else if (UpdateProgressBarProc(80) && !SystemEncryptionUpgrade && DoRegInstall ((HWND) hwndDlg, InstallationPath, bRegisterFileExt ) == FALSE)
1.1       root     1381:        {
                   1382:                bOK = FALSE;
                   1383:        }
1.1.1.14  root     1384:        else if (UpdateProgressBarProc(85) && !SystemEncryptionUpgrade && DoDriverInstall (hwndDlg) == FALSE)
                   1385:        {
                   1386:                bOK = FALSE;
                   1387:        }
1.1.1.17  root     1388:        else if (UpdateProgressBarProc(90) && SystemEncryptionUpgrade && UpgradeBootLoader (hwndDlg) == FALSE)
1.1       root     1389:        {
                   1390:                bOK = FALSE;
                   1391:        }
1.1.1.13  root     1392:        else if (UpdateProgressBarProc(93) && DoShortcutsInstall (hwndDlg, InstallationPath, bAddToStartMenu, bDesktopIcon) == FALSE)
1.1       root     1393:        {
                   1394:                bOK = FALSE;
                   1395:        }
                   1396: 
1.1.1.17  root     1397:        try
                   1398:        {
                   1399:                bootEnc.RenameDeprecatedSystemLoaderBackup();
                   1400:        }
                   1401:        catch (...)     { }
                   1402: 
                   1403: 
1.1.1.13  root     1404:        if (bOK)
                   1405:                UpdateProgressBarProc(97);
                   1406: 
                   1407:        if (bSystemRestore)
1.1       root     1408:                SetSystemRestorePoint (hwndDlg, TRUE);
                   1409: 
1.1.1.7   root     1410:        if (bOK)
                   1411:        {
1.1.1.13  root     1412:                UpdateProgressBarProc(100);
1.1.1.11  root     1413:                UninstallBatch[0] = 0;
1.1.1.7   root     1414:                StatusMessage (hwndDlg, "INSTALL_COMPLETED");
1.1.1.13  root     1415:                PostMessage (MainDlg, TC_APPMSG_INSTALL_SUCCESS, 0, 0);
1.1.1.11  root     1416:        }
                   1417:        else
                   1418:        {
1.1.1.13  root     1419:                UpdateProgressBarProc(0);
1.1.1.11  root     1420:                bUninstall = TRUE;
                   1421:                Rollback = TRUE;
                   1422:                Silent = TRUE;
                   1423: 
1.1.1.14  root     1424:                if (!SystemEncryptionUpgrade)
                   1425:                        DoUninstall (hwndDlg);
1.1.1.11  root     1426: 
                   1427:                bUninstall = FALSE;
                   1428:                Rollback = FALSE;
                   1429:                Silent = FALSE;
                   1430: 
                   1431:                StatusMessage (hwndDlg, "ROLLBACK");
1.1.1.7   root     1432:        }
1.1       root     1433: 
1.1.1.11  root     1434:        OutcomePrompt (hwndDlg, bOK);
                   1435: 
1.1.1.13  root     1436:        if (!bOK)
                   1437:        {
                   1438:                PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
                   1439:        }
                   1440:        else if (!bUninstall && !bDevm)
1.1.1.11  root     1441:        {
1.1.1.17  root     1442:                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     1443:                {
1.1.1.17  root     1444:                        if (bUpgrade)
1.1.1.14  root     1445:                        {
1.1.1.18! root     1446:                                if (bRestartRequired || SystemEncryptionUpgrade)
        !          1447:                                {
        !          1448:                                        SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_RELEASE_NOTES);
        !          1449:                                }
        !          1450:                                else if (AskYesNo ("AFTER_UPGRADE_RELEASE_NOTES") == IDYES)
        !          1451:                                {
        !          1452:                                        Applink ("releasenotes", TRUE, "");
        !          1453:                                }
1.1.1.14  root     1454:                        }
1.1.1.17  root     1455:                        else if (bFirstTimeInstall)
1.1.1.14  root     1456:                        {
1.1.1.18! root     1457:                                if (bRestartRequired || SystemEncryptionUpgrade)
        !          1458:                                {
        !          1459:                                        SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_TUTORIAL);
        !          1460:                                }
        !          1461:                                else if (AskYesNo ("AFTER_INSTALL_TUTORIAL") == IDYES)
        !          1462:                                {
        !          1463:                                        Applink ("beginnerstutorial", TRUE, "");
        !          1464:                                }
1.1.1.14  root     1465:                        }
1.1.1.11  root     1466:                }
1.1.1.17  root     1467: 
1.1.1.18! root     1468:                if (bRestartRequired || (SystemEncryptionUpgrade && bUpgrade))
1.1.1.17  root     1469:                {
                   1470:                        if (AskYesNo (SystemEncryptionUpgrade ? "UPGRADE_OK_REBOOT_REQUIRED" : "CONFIRM_RESTART") == IDYES)
                   1471:                                RestartComputer();
                   1472:                }
1.1.1.11  root     1473:        }
1.1       root     1474: }
                   1475: 
                   1476: 
1.1.1.13  root     1477: void SetInstallationPath (HWND hwndDlg)
                   1478: {
                   1479:        HKEY hkey;
                   1480:        BOOL bInstallPathDetermined = FALSE;
                   1481:        char path[MAX_PATH+20];
                   1482:        ITEMIDLIST *itemList;
                   1483: 
                   1484:        memset (InstallationPath, 0, sizeof (InstallationPath));
                   1485: 
                   1486:        // Determine if TrueCrypt is already installed and try to determine its "Program Files" location
                   1487:        if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
                   1488:        {
                   1489:                /* Default 'UninstallString' registry strings written by past versions of TrueCrypt:
                   1490:                ------------------------------------------------------------------------------------
                   1491:                1.0             C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1492:                1.0a    C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1493:                2.0             C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1494:                2.1             C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1495:                2.1a    C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1496:                3.0             C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1497:                3.0a    C:\WINDOWS\TrueCrypt Setup.exe /u                       [optional]
                   1498:                3.1             The UninstallString was NEVER written (fortunately, 3.1a replaced 3.1 after 2 weeks)
                   1499:                3.1a    C:\WINDOWS\TrueCrypt Setup.exe /u
                   1500:                4.0             C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
                   1501:                4.1             C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
                   1502:                4.2             C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
                   1503:                4.2a    C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
                   1504:                4.3             "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u C:\Program Files\TrueCrypt\
                   1505:                4.3a    "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u C:\Program Files\TrueCrypt\
1.1.1.15  root     1506:                5.0+    "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u
1.1.1.13  root     1507: 
                   1508:                Note: In versions 1.0-3.0a the user was able to choose whether to install the uninstaller.
                   1509:                          The default was to install it. If it wasn't installed, there was no UninstallString.
                   1510:                */
                   1511: 
                   1512:                char rv[MAX_PATH*4];
                   1513:                DWORD size = sizeof (rv);
1.1.1.17  root     1514:                if (RegQueryValueEx (hkey, "UninstallString", 0, 0, (LPBYTE) &rv, &size) == ERROR_SUCCESS && strrchr (rv, '/'))
1.1.1.13  root     1515:                {
                   1516:                        size_t len = 0;
                   1517: 
                   1518:                        // Cut and paste the location (path) where TrueCrypt is installed to InstallationPath
                   1519:                        if (rv[0] == '"')
                   1520:                        {
                   1521:                                // 4.3 or later
                   1522: 
                   1523:                                len = strrchr (rv, '/') - rv - 2;
                   1524:                                strncpy (InstallationPath, rv + 1, len);
                   1525:                                InstallationPath [len] = 0;
                   1526:                                bInstallPathDetermined = TRUE;
                   1527: 
                   1528:                                if (InstallationPath [strlen (InstallationPath) - 1] != '\\')
                   1529:                                {
                   1530:                                        len = strrchr (InstallationPath, '\\') - InstallationPath;
                   1531:                                        InstallationPath [len] = 0;
                   1532:                                }
                   1533:                        }
                   1534:                        else
                   1535:                        {
                   1536:                                // 1.0-4.2a (except 3.1)
                   1537: 
                   1538:                                len = strrchr (rv, '/') - rv;
                   1539:                                if (rv[len+2] == ' ')
                   1540:                                {
                   1541:                                        // 4.0-4.2a
                   1542: 
                   1543:                                        strncpy (InstallationPath, rv + len + 3, strlen (rv) - len - 3);
                   1544:                                        InstallationPath [strlen (rv) - len - 3] = 0;
                   1545:                                        bInstallPathDetermined = TRUE;
                   1546:                                }
                   1547:                                else
                   1548:                                {
                   1549:                                        // 1.0-3.1a (except 3.1)
                   1550: 
                   1551:                                        // We know that TrueCrypt is installed but don't know where. It's not safe to continue installing
                   1552:                                        // over the old version.
                   1553: 
                   1554:                                        Error ("UNINSTALL_OLD_VERSION_FIRST");
                   1555: 
                   1556:                                        len = strrchr (rv, '/') - rv - 1;
                   1557:                                        strncpy (InstallationPath, rv, len);    // Path and filename of the uninstaller
                   1558:                                        InstallationPath [len] = 0;
                   1559:                                        bInstallPathDetermined = FALSE;
                   1560: 
                   1561:                                        ShellExecute (NULL, "open", InstallationPath, "/u", NULL, SW_SHOWNORMAL);
                   1562:                                        RegCloseKey (hkey);
                   1563:                                        exit (1);
                   1564:                                }
                   1565:                        }
                   1566: 
                   1567:                }
                   1568:                RegCloseKey (hkey);
                   1569:        }
                   1570: 
                   1571:        if (bInstallPathDetermined)
                   1572:        {
                   1573:                char mp[MAX_PATH];
                   1574: 
                   1575:                // Determine whether we were launched from the folder where TrueCrypt is installed
                   1576:                GetModuleFileName (NULL, mp, sizeof (mp));
                   1577:                if (strncmp (InstallationPath, mp, min (strlen(InstallationPath), strlen(mp))) == 0)
                   1578:                {
                   1579:                        // We were launched from the folder where TrueCrypt is installed
                   1580: 
                   1581:                        if (!IsNonInstallMode() && !bDevm)
                   1582:                                bChangeMode = TRUE;
                   1583:                }
                   1584:        }
                   1585:        else
                   1586:        {
                   1587:                /* TrueCypt is not installed or it wasn't possible to determine where it is installed. */
                   1588: 
                   1589:                // Default "Program Files" path. 
                   1590:                SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &itemList);
                   1591:                SHGetPathFromIDList (itemList, path);
1.1.1.15  root     1592:                strncat (path, "\\TrueCrypt\\", min (strlen("\\TrueCrypt\\"), sizeof(path)-strlen(path)-1));
                   1593:                strncpy (InstallationPath, path, sizeof(InstallationPath)-1);
1.1.1.13  root     1594:        }
                   1595: 
                   1596:        // Make sure the path ends with a backslash
                   1597:        if (InstallationPath [strlen (InstallationPath) - 1] != '\\')
                   1598:        {
                   1599:                strcat (InstallationPath, "\\");
                   1600:        }
                   1601: }
                   1602: 
                   1603: 
                   1604: // Handler for uninstall only (install is handled by the wizard)
1.1.1.18! root     1605: BOOL CALLBACK UninstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1       root     1606: {
                   1607:        WORD lw = LOWORD (wParam);
                   1608: 
                   1609:        switch (msg)
                   1610:        {
                   1611:        case WM_INITDIALOG:
1.1.1.17  root     1612: 
1.1.1.7   root     1613:                MainDlg = hwndDlg;
1.1.1.17  root     1614: 
                   1615:                if (!CreateAppSetupMutex ())
                   1616:                        AbortProcess ("TC_INSTALLER_IS_RUNNING");
                   1617: 
1.1       root     1618:                InitDialog (hwndDlg);
1.1.1.7   root     1619:                LocalizeDialog (hwndDlg, NULL);
1.1       root     1620: 
1.1.1.13  root     1621:                SetWindowTextW (hwndDlg, lpszTitle);
1.1       root     1622: 
1.1.1.13  root     1623:                // System Restore
                   1624:                SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore);
                   1625:                if (SystemRestoreDll == 0)
1.1       root     1626:                {
1.1.1.13  root     1627:                        SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE);
                   1628:                        EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
1.1       root     1629:                }
                   1630: 
1.1.1.13  root     1631:                SetFocus (GetDlgItem (hwndDlg, IDC_UNINSTALL));
1.1.1.11  root     1632: 
1.1       root     1633:                return 1;
                   1634: 
                   1635:        case WM_SYSCOMMAND:
                   1636:                if (lw == IDC_ABOUT)
                   1637:                {
1.1.1.7   root     1638:                        DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1       root     1639:                        return 1;
                   1640:                }
                   1641:                return 0;
                   1642: 
                   1643:        case WM_COMMAND:
1.1.1.13  root     1644:                if (lw == IDC_UNINSTALL)
1.1       root     1645:                {
1.1.1.7   root     1646:                        if (bDone)
1.1       root     1647:                        {
1.1.1.13  root     1648:                                bUninstallInProgress = FALSE;
                   1649:                                PostMessage (hwndDlg, WM_CLOSE, 0, 0);
1.1       root     1650:                                return 1;
                   1651:                        }
                   1652: 
1.1.1.13  root     1653:                        bUninstallInProgress = TRUE;
1.1       root     1654: 
1.1.1.11  root     1655:                        WaitCursor ();
                   1656: 
1.1.1.13  root     1657:                        if (bUninstall)
1.1.1.18! root     1658:                                _beginthread (DoUninstall, 0, (void *) hwndDlg);
1.1       root     1659: 
                   1660:                        return 1;
                   1661:                }
                   1662: 
1.1.1.13  root     1663:                if (lw == IDC_SYSTEM_RESTORE)
1.1       root     1664:                {
1.1.1.13  root     1665:                        bSystemRestore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE));
1.1       root     1666:                        return 1;
                   1667:                }
                   1668: 
1.1.1.13  root     1669:                if (lw == IDCANCEL)
1.1       root     1670:                {
1.1.1.13  root     1671:                        PostMessage (hwndDlg, WM_CLOSE, 0, 0);
1.1       root     1672:                        return 1;
                   1673:                }
                   1674: 
                   1675:                return 0;
                   1676: 
1.1.1.13  root     1677:        case TC_APPMSG_UNINSTALL_SUCCESS:
1.1.1.11  root     1678:                SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), GetString ("FINALIZE"));
                   1679:                NormalCursor ();
1.1.1.13  root     1680:                return 1;
1.1.1.7   root     1681: 
1.1       root     1682:        case WM_CLOSE:
1.1.1.13  root     1683:                if (bUninstallInProgress)
                   1684:                {
                   1685:                        NormalCursor();
                   1686:                        if (AskNoYes("CONFIRM_EXIT_UNIVERSAL") == IDNO)
                   1687:                        {
                   1688:                                return 1;
                   1689:                        }
                   1690:                        WaitCursor ();
                   1691:                }
1.1       root     1692:                EndDialog (hwndDlg, IDCANCEL);
                   1693:                return 1;
                   1694:        }
                   1695: 
                   1696:        return 0;
                   1697: }
                   1698: 
                   1699: 
1.1.1.15  root     1700: int WINAPI WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, int nCmdShow)
1.1       root     1701: {
1.1.1.17  root     1702:        atexit (localcleanup);
                   1703: 
1.1.1.13  root     1704:        SelfExtractStartupInit();
1.1       root     1705: 
1.1.1.7   root     1706:        lpszTitle = L"TrueCrypt Setup";
1.1       root     1707: 
1.1.1.18! root     1708:        InitCommonControls ();
        !          1709: 
1.1       root     1710:        /* Call InitApp to initialize the common code */
1.1.1.11  root     1711:        InitApp (hInstance, NULL);
1.1       root     1712: 
1.1.1.7   root     1713:        if (IsAdmin () != TRUE)
                   1714:                if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
1.1.1.13  root     1715:                {
1.1.1.11  root     1716:                        exit (1);
1.1.1.13  root     1717:                }
1.1       root     1718: 
1.1.1.8   root     1719:        /* Setup directory */
                   1720:        {
                   1721:                char *s;
                   1722:                GetModuleFileName (NULL, SetupFilesDir, sizeof (SetupFilesDir));
                   1723:                s = strrchr (SetupFilesDir, '\\');
                   1724:                if (s)
                   1725:                        s[1] = 0;
                   1726:        }
                   1727: 
1.1.1.13  root     1728:        /* Parse command line arguments */
                   1729: 
                   1730:        if (lpszCommandLine[0] == '/')
1.1       root     1731:        {
1.1.1.13  root     1732:                if (lpszCommandLine[1] == 'u')
                   1733:                {
                   1734:                        // Uninstall:   /u
                   1735: 
                   1736:                        bUninstall = TRUE;
                   1737:                }
                   1738:                else if (lpszCommandLine[1] == 'c')
                   1739:                {
                   1740:                        // Change:      /c
1.1       root     1741: 
1.1.1.13  root     1742:                        bChangeMode = TRUE;
                   1743:                }
                   1744:                else if (lpszCommandLine[1] == 'p')
                   1745:                {
                   1746:                        // Create self-extracting package:      /p
                   1747: 
                   1748:                        bMakePackage = TRUE;
                   1749:                }
                   1750:                else if (lpszCommandLine[1] == 'd')
                   1751:                {
                   1752:                        // Dev mode:    /d
                   1753:                        bDevm = TRUE;
                   1754:                }
                   1755:        }
                   1756:  
                   1757:        if (bMakePackage)
1.1.1.11  root     1758:        {
1.1.1.13  root     1759:                /* Create self-extracting package */
1.1.1.11  root     1760: 
1.1.1.13  root     1761:                MakeSelfExtractingPackage (NULL, SetupFilesDir);
                   1762:        }
                   1763:        else
                   1764:        {
                   1765:                SetInstallationPath (NULL);
1.1.1.11  root     1766: 
1.1.1.13  root     1767:                if (!bUninstall)
1.1.1.11  root     1768:                {
1.1.1.13  root     1769:                        if (IsSelfExtractingPackage())
1.1.1.11  root     1770:                        {
1.1.1.13  root     1771:                                if (!VerifyPackageIntegrity())
1.1.1.12  root     1772:                                {
1.1.1.13  root     1773:                                        // Package corrupted 
                   1774:                                        exit (1);
1.1.1.12  root     1775:                                }
1.1.1.13  root     1776:                                bDevm = FALSE;
1.1.1.11  root     1777:                        }
1.1.1.13  root     1778:                        else if (!bDevm)
1.1.1.11  root     1779:                        {
1.1.1.18! root     1780:                                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     1781:                                exit (1);
1.1.1.11  root     1782:                        }
1.1.1.13  root     1783: 
                   1784:                        if (bChangeMode)
                   1785:                        {
                   1786:                                /* TrueCrypt is already installed on this system and we were launched from the Program Files folder */
                   1787: 
                   1788:                                char *tmpStr[] = {0, "SELECT_AN_ACTION", "REPAIR_REINSTALL", "UNINSTALL", "EXIT", 0};
                   1789: 
                   1790:                                // Ask the user to select either Repair or Unistallation
1.1.1.18! root     1791:                                switch (AskMultiChoice ((void **) tmpStr, FALSE))
1.1.1.13  root     1792:                                {
                   1793:                                case 1:
                   1794:                                        bRepairMode = TRUE;
                   1795:                                        break;
                   1796:                                case 2:
                   1797:                                        bUninstall = TRUE;
                   1798:                                        break;
                   1799:                                default:
                   1800:                                        exit (1);
                   1801:                                }
                   1802:                        }
1.1.1.11  root     1803:                }
                   1804: 
1.1.1.13  root     1805:                // System Restore
                   1806:                SystemRestoreDll = LoadLibrary ("srclient.dll");
                   1807: 
                   1808:                if (!bUninstall)
1.1.1.11  root     1809:                {
1.1.1.13  root     1810:                        /* Create the main dialog for install */
1.1.1.11  root     1811: 
1.1.1.13  root     1812:                        DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_INSTL_DLG), NULL, (DLGPROC) MainDialogProc, 
                   1813:                                (LPARAM)lpszCommandLine);
                   1814:                }
                   1815:                else
                   1816:                {
                   1817:                        /* Create the main dialog for uninstall  */
                   1818: 
                   1819:                        DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_UNINSTALL), NULL, (DLGPROC) UninstallDlgProc);
1.1.1.11  root     1820: 
1.1.1.13  root     1821:                        if (UninstallBatch[0])
                   1822:                        {
                   1823:                                STARTUPINFO si;
                   1824:                                PROCESS_INFORMATION pi;
                   1825: 
                   1826:                                ZeroMemory (&si, sizeof (si));
                   1827:                                si.cb = sizeof (si);
                   1828:                                si.dwFlags = STARTF_USESHOWWINDOW;
                   1829:                                si.wShowWindow = SW_HIDE;
                   1830: 
                   1831:                                if (!CreateProcess (UninstallBatch, NULL, NULL, NULL, FALSE, IDLE_PRIORITY_CLASS, NULL, NULL, &si, &pi))
                   1832:                                        DeleteFile (UninstallBatch);
1.1.1.15  root     1833:                                else
                   1834:                                {
                   1835:                                        CloseHandle (pi.hProcess);
                   1836:                                        CloseHandle (pi.hThread);
                   1837:                                }
1.1.1.13  root     1838:                        }
1.1.1.11  root     1839:                }
1.1       root     1840:        }
                   1841: 
                   1842:        return 0;
                   1843: }

unix.superglobalmegacorp.com

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