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

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

unix.superglobalmegacorp.com

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