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

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

unix.superglobalmegacorp.com

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