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

1.1.1.7   root        1: /* Legal Notice: The source code contained in this file has been derived from
                      2:    the source code of Encryption for the Masses 2.02a, which is Copyright (c)
                      3:    1998-99 Paul Le Roux and which is covered by the 'License Agreement for
                      4:    Encryption for the Masses'. Modifications and additions to that source code
1.1.1.9 ! root        5:    contained in this file are Copyright (c) 2004-2006 TrueCrypt Foundation and
1.1.1.7   root        6:    Copyright (c) 2004 TrueCrypt Team, and are covered by TrueCrypt License 2.0
                      7:    the full text of which is contained in the file License.txt included in
                      8:    TrueCrypt binary and source code distribution archives.  */
1.1       root        9: 
1.1.1.7   root       10: #include "Tcdefs.h"
1.1       root       11: #include <SrRestorePtApi.h>
1.1.1.7   root       12: #include <sys/types.h>
                     13: #include <sys/stat.h>
1.1       root       14: 
1.1.1.7   root       15: #include "Apidrvr.h"
                     16: #include "Combo.h"
                     17: #include "Dlgcode.h"
                     18: #include "Language.h"
                     19: #include "Registry.h"
                     20: #include "Resource.h"
1.1       root       21: 
1.1.1.7   root       22: #include "Dir.h"
                     23: #include "Setup.h"
1.1       root       24: 
1.1.1.7   root       25: #include "../Common/Resource.h"
                     26: #include "../Mount/Mount.h"
1.1       root       27: 
                     28: #pragma warning( disable : 4201 )
                     29: #pragma warning( disable : 4115 )
                     30: 
                     31: #include <shlobj.h>
                     32: 
                     33: #pragma warning( default : 4201 )
                     34: #pragma warning( default : 4115 )
                     35: 
                     36: char dlg_file_name[TC_MAX_PATH];
1.1.1.8   root       37: char SetupFilesDir[TC_MAX_PATH];
                     38: 
1.1       root       39: BOOL bUninstall = FALSE;
                     40: BOOL bDone = FALSE;
1.1.1.7   root       41: char *UninstallPath;
1.1       root       42: 
                     43: HMODULE SystemRestoreDll = 0;
                     44: 
                     45: BOOL
                     46: StatDeleteFile (char *lpszFile)
                     47: {
                     48:        struct __stat64 st;
                     49: 
                     50:        if (_stat64 (lpszFile, &st) == 0)
                     51:                return DeleteFile (lpszFile);
                     52:        else
                     53:                return TRUE;
                     54: }
                     55: 
                     56: BOOL
                     57: StatRemoveDirectory (char *lpszDir)
                     58: {
                     59:        struct __stat64 st;
                     60: 
                     61:        if (_stat64 (lpszDir, &st) == 0)
                     62:                return RemoveDirectory (lpszDir);
                     63:        else
                     64:                return TRUE;
                     65: }
                     66: 
                     67: HRESULT
                     68: CreateLink (char *lpszPathObj, char *lpszArguments,
                     69:            char *lpszPathLink)
                     70: {
                     71:        HRESULT hres;
                     72:        IShellLink *psl;
                     73: 
                     74:        /* Get a pointer to the IShellLink interface.  */
                     75:        hres = CoCreateInstance (&CLSID_ShellLink, NULL,
                     76:                               CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
                     77:        if (SUCCEEDED (hres))
                     78:        {
                     79:                IPersistFile *ppf;
                     80: 
                     81:                /* Set the path to the shortcut target, and add the
                     82:                   description.  */
                     83:                psl->lpVtbl->SetPath (psl, lpszPathObj);
                     84:                psl->lpVtbl->SetArguments (psl, lpszArguments);
                     85: 
                     86:                /* Query IShellLink for the IPersistFile interface for saving
                     87:                   the shortcut in persistent storage.  */
                     88:                hres = psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile,
                     89:                                                    &ppf);
                     90: 
                     91:                if (SUCCEEDED (hres))
                     92:                {
                     93:                        WORD wsz[TC_MAX_PATH];
                     94: 
                     95:                        /* Ensure that the string is ANSI.  */
                     96:                        MultiByteToWideChar (CP_ACP, 0, lpszPathLink, -1,
                     97:                                             wsz, TC_MAX_PATH);
                     98: 
                     99:                        /* Save the link by calling IPersistFile::Save.  */
                    100:                        hres = ppf->lpVtbl->Save (ppf, wsz, TRUE);
                    101:                        ppf->lpVtbl->Release (ppf);
                    102:                }
                    103:                psl->lpVtbl->Release (psl);
                    104:        }
                    105:        return hres;
                    106: }
                    107: 
                    108: void
                    109: GetProgramPath (HWND hwndDlg, char *path)
                    110: {
                    111:        ITEMIDLIST *i;
                    112:        HRESULT res;
                    113: 
1.1.1.7   root      114:        if (IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
1.1       root      115:         res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_COMMON_PROGRAMS, &i);
                    116:        else
                    117:         res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAMS, &i);
                    118: 
                    119:        SHGetPathFromIDList (i, path);
                    120: }
                    121: 
                    122: void
1.1.1.7   root      123: StatusMessage (HWND hwndDlg , char *stringId)
1.1       root      124: {
1.1.1.7   root      125:        SendMessageW (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) GetString (stringId));
1.1       root      126:                
                    127:        SendDlgItemMessage (hwndDlg, IDC_FILES, LB_SETTOPINDEX, 
                    128:                SendDlgItemMessage (hwndDlg, IDC_FILES, LB_GETCOUNT, 0, 0) - 1, 0);
                    129: }
                    130: 
                    131: void
1.1.1.7   root      132: StatusMessageParam (HWND hwndDlg, char *stringId, char *param)
1.1       root      133: {
1.1.1.7   root      134:        wchar_t szTmp[1024];
                    135:        wsprintfW (szTmp, L"%s %hs", GetString (stringId), param);
                    136:        SendMessageW (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) szTmp);
                    137:                
                    138:        SendDlgItemMessage (hwndDlg, IDC_FILES, LB_SETTOPINDEX, 
                    139:                SendDlgItemMessage (hwndDlg, IDC_FILES, LB_GETCOUNT, 0, 0) - 1, 0);
1.1       root      140: }
                    141: 
                    142: void
1.1.1.7   root      143: RegMessage (HWND hwndDlg, char *txt)
1.1       root      144: {
1.1.1.7   root      145:        StatusMessageParam (hwndDlg, "ADDING_REG", txt);
1.1       root      146: }
                    147: 
                    148: void
1.1.1.7   root      149: CopyMessage (HWND hwndDlg, char *txt)
1.1       root      150: {
1.1.1.7   root      151:        StatusMessageParam (hwndDlg, "COPYING", txt);
1.1       root      152: }
                    153: 
                    154: void
1.1.1.7   root      155: RemoveMessage (HWND hwndDlg, char *txt)
1.1       root      156: {
1.1.1.7   root      157:        StatusMessageParam (hwndDlg, "REMOVING", txt);
1.1       root      158: }
                    159: 
                    160: void
                    161: IconMessage (HWND hwndDlg, char *txt)
                    162: {
1.1.1.7   root      163:        StatusMessageParam (hwndDlg, "ADDING_ICON", txt);
1.1       root      164: }
                    165: 
                    166: 
                    167: BOOL
                    168: DoFilesInstall (HWND hwndDlg, char *szDestDir, BOOL bUninstallSupport)
                    169: {
                    170:        char *szFiles[]=
                    171:        {
                    172:                "ATrueCrypt.exe", "ATrueCrypt Format.exe",
1.1.1.7   root      173:                "ALicense.txt", "ATrueCrypt User Guide.pdf",
                    174:                "WTrueCrypt Setup.exe", "Dtruecrypt.sys",
                    175:                "Atruecrypt.sys", "Atruecrypt-x64.sys"
1.1       root      176:        };
                    177: 
                    178:        char szTmp[TC_MAX_PATH];
                    179:        BOOL bOK = TRUE;
                    180:        int i;
                    181: 
1.1.1.7   root      182:        if (bUninstall)
1.1       root      183:                bUninstallSupport = FALSE;
                    184: 
                    185:        for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
                    186:        {
                    187:                BOOL bResult, bSlash;
                    188:                char szDir[TC_MAX_PATH];
                    189:                int x;
                    190: 
                    191:                if (bUninstallSupport == FALSE && strstr (szFiles[i], "TrueCrypt Setup") != 0)
                    192:                        continue;
                    193: 
                    194:                if (*szFiles[i] == 'A')
                    195:                        strcpy (szDir, szDestDir);
                    196:                else if (*szFiles[i] == 'D')
                    197:                {
1.1.1.7   root      198:                        if (!Is64BitOs ())
                    199:                                GetSystemDirectory (szDir, sizeof (szDir));
                    200:                        else
                    201:                                GetWindowsDirectory (szDir, sizeof (szDir));
1.1       root      202: 
                    203:                        x = strlen (szDestDir);
                    204:                        if (szDestDir[x - 1] == '\\')
                    205:                                bSlash = TRUE;
                    206:                        else
                    207:                                bSlash = FALSE;
                    208: 
                    209:                        if (bSlash == FALSE)
                    210:                                strcat (szDir, "\\");
                    211: 
1.1.1.7   root      212:                        strcat (szDir, !Is64BitOs () ? "Drivers" : "SysWOW64\\Drivers");
1.1       root      213:                }
                    214:                else if (*szFiles[i] == 'W')
                    215:                        GetWindowsDirectory (szDir, sizeof (szDir));
                    216: 
                    217:                x = strlen (szDestDir);
                    218:                if (szDestDir[x - 1] == '\\')
                    219:                        bSlash = TRUE;
                    220:                else
                    221:                        bSlash = FALSE;
                    222: 
                    223:                if (bSlash == FALSE)
                    224:                        strcat (szDir, "\\");
                    225: 
1.1.1.7   root      226:                if (*szFiles[i] == 'I')
1.1       root      227:                        continue;
                    228: 
                    229:                sprintf (szTmp, "%s%s", szDir, szFiles[i] + 1);
                    230: 
                    231:                if (bUninstall == FALSE)
                    232:                        CopyMessage (hwndDlg, szTmp);
                    233:                else
                    234:                        RemoveMessage (hwndDlg, szTmp);
                    235: 
                    236:                if (bUninstall == FALSE)
                    237:                {
1.1.1.8   root      238:                        SetCurrentDirectory (SetupFilesDir);
                    239: 
1.1.1.6   root      240:                        bResult = TCCopyFile (szFiles[i] + 1, szTmp);
1.1       root      241:                        if (!bResult)
                    242:                        {
                    243:                                char s[256];
1.1.1.7   root      244: 
                    245:                                sprintf (s, "Setup Files\\%s", 
                    246:                                        (strcmp (szFiles[i], "Dtruecrypt.sys") == 0 && Is64BitOs ()) ? 
                    247:                                        "truecrypt-x64.sys" : szFiles[i] + 1);
                    248: 
1.1.1.6   root      249:                                bResult = TCCopyFile (s, szTmp);
1.1       root      250:                        }
                    251:                }
                    252:                else
                    253:                {
                    254:                        bResult = StatDeleteFile (szTmp);
                    255:                }
                    256: 
                    257:                if (bResult == FALSE)
                    258:                {
                    259:                        LPVOID lpMsgBuf;
                    260:                        DWORD dwError = GetLastError ();
1.1.1.7   root      261:                        wchar_t szTmp2[700];
1.1       root      262: 
                    263:                        FormatMessage (
                    264:                                              FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                    265:                                              NULL,
                    266:                                              dwError,
                    267:                                 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),    /* Default language */
                    268:                                              (char *) &lpMsgBuf,
                    269:                                              0,
                    270:                                              NULL
                    271:                                );
                    272: 
                    273: 
                    274:                        if (bUninstall == FALSE)
1.1.1.7   root      275:                                wsprintfW (szTmp2, GetString ("INSTALL_OF_FAILED"), szTmp, lpMsgBuf);
1.1       root      276:                        else
1.1.1.7   root      277:                                wsprintfW (szTmp2, GetString ("UNINSTALL_OF_FAILED"), szTmp, lpMsgBuf);
1.1       root      278: 
                    279:                        LocalFree (lpMsgBuf);
                    280: 
1.1.1.7   root      281:                        if (MessageBoxW (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
1.1       root      282:                                return FALSE;
                    283:                }
1.1.1.7   root      284:        }
1.1       root      285: 
1.1.1.7   root      286:        // Language pack
                    287:        if (bUninstall == FALSE)
                    288:        {
                    289:                WIN32_FIND_DATA f;
1.1.1.8   root      290:                HANDLE h;
                    291:                
                    292:                SetCurrentDirectory (SetupFilesDir);
                    293:                h = FindFirstFile ("Language.*.xml", &f);
                    294: 
1.1.1.7   root      295:                if (h != INVALID_HANDLE_VALUE)
                    296:                {
                    297:                        char d[MAX_PATH*2];
                    298:                        sprintf (d, "%s\\%s", szDestDir, f.cFileName);
                    299:                        CopyMessage (hwndDlg, d);
                    300:                        TCCopyFile (f.cFileName, d);
                    301:                        FindClose (h);
                    302:                }
1.1.1.8   root      303: 
                    304:                SetCurrentDirectory (SetupFilesDir);
                    305:                SetCurrentDirectory ("Setup files");
                    306:                h = FindFirstFile ("TrueCrypt User Guide.*.pdf", &f);
                    307:                if (h != INVALID_HANDLE_VALUE)
                    308:                {
                    309:                        char d[MAX_PATH*2];
                    310:                        sprintf (d, "%s\\%s", szDestDir, f.cFileName);
                    311:                        CopyMessage (hwndDlg, d);
                    312:                        TCCopyFile (f.cFileName, d);
                    313:                        FindClose (h);
                    314:                }
                    315:                SetCurrentDirectory (SetupFilesDir);
1.1       root      316:        }
                    317: 
                    318:        return bOK;
                    319: }
                    320: 
                    321: BOOL
                    322: DoRegInstall (HWND hwndDlg, char *szDestDir, BOOL bInstallType, BOOL bUninstallSupport)
                    323: {
                    324:        char szDir[TC_MAX_PATH], *key;
                    325:        HKEY hkey = 0;
                    326:        BOOL bSlash, bOK = FALSE;
                    327:        DWORD dw;
                    328:        int x;
                    329: 
                    330:        strcpy (szDir, szDestDir);
                    331:        x = strlen (szDestDir);
                    332:        if (szDestDir[x - 1] == '\\')
                    333:                bSlash = TRUE;
                    334:        else
                    335:                bSlash = FALSE;
                    336: 
                    337:        if (bSlash == FALSE)
                    338:                strcat (szDir, "\\");
                    339: 
1.1.1.7   root      340:        if (bInstallType)
1.1       root      341:        {
                    342:                char szTmp[TC_MAX_PATH];
                    343: 
                    344:                key = "SOFTWARE\\Classes\\TrueCryptVolume";
                    345:                RegMessage (hwndDlg, key);
                    346:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    347:                                    key,
                    348:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    349:                        goto error;
                    350: 
                    351:                sprintf (szTmp, "TrueCrypt Volume", szDir);
                    352:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    353:                        goto error;
                    354: 
                    355:                RegCloseKey (hkey);
                    356:                hkey = 0;
                    357: 
                    358:                key = "SOFTWARE\\Classes\\TrueCryptVolume\\DefaultIcon";
                    359:                RegMessage (hwndDlg, key);
                    360:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    361:                                    key,
                    362:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    363:                        goto error;
                    364: 
                    365:                sprintf (szTmp, "%sTrueCrypt.exe,1", szDir);
                    366:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    367:                        goto error;
                    368: 
                    369:                RegCloseKey (hkey);
                    370:                hkey = 0;
                    371: 
                    372:                key = "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open\\command";
                    373:                RegMessage (hwndDlg, key);
                    374:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    375:                                    key,
                    376:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    377:                        goto error;
                    378: 
                    379:                sprintf (szTmp, "\"%sTrueCrypt.exe\" /v \"%%1\"", szDir );
                    380:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    381:                        goto error;
                    382: 
                    383:                RegCloseKey (hkey);
                    384:                hkey = 0;
                    385: 
                    386:                key = "SOFTWARE\\Classes\\.tc";
                    387:                RegMessage (hwndDlg, key);
                    388:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    389:                                    key,
                    390:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    391:                        goto error;
                    392: 
                    393:                strcpy (szTmp, "TrueCryptVolume");
                    394:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    395:                        goto error;
                    396:        }
                    397: 
                    398: 
1.1.1.7   root      399:        if (bUninstallSupport)
1.1       root      400:        {
                    401:                char szTmp[TC_MAX_PATH];
                    402: 
                    403:                key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt";
                    404:                RegMessage (hwndDlg, key);
                    405:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    406:                                    key,
                    407:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    408:                        goto error;
                    409: 
                    410:                GetWindowsDirectory (szDir, sizeof (szDir));
                    411: 
                    412:                x = strlen (szDir);
                    413:                if (szDir[x - 1] == '\\')
                    414:                        bSlash = TRUE;
                    415:                else
                    416:                        bSlash = FALSE;
                    417: 
                    418:                if (bSlash == FALSE)
                    419:                        strcat (szDir, "\\");
                    420: 
1.1.1.7   root      421:                sprintf (szTmp, "%sTrueCrypt Setup.exe /u %s", szDir, szDestDir);
1.1       root      422:                if (RegSetValueEx (hkey, "UninstallString", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    423:                        goto error;
                    424: 
                    425:                strcpy (szTmp, "TrueCrypt");
                    426:                if (RegSetValueEx (hkey, "DisplayName", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    427:                        goto error;
                    428:        }
                    429: 
                    430:        bOK = TRUE;
                    431: 
                    432:       error:
                    433:        if (hkey != 0)
                    434:                RegCloseKey (hkey);
                    435: 
                    436:        if (bOK == FALSE)
                    437:        {
                    438:                handleWin32Error (hwndDlg);
1.1.1.7   root      439:                MessageBoxW (hwndDlg, GetString ("REG_INSTALL_FAILED"), lpszTitle, MB_ICONHAND);
1.1       root      440:        }
                    441: 
                    442:        return bOK;
                    443: }
                    444: 
                    445: BOOL
1.1.1.7   root      446: DoApplicationDataUninstall (HWND hwndDlg)
                    447: {
                    448:        char path[MAX_PATH];
                    449:        char path2[MAX_PATH];
                    450:        BOOL bOK = TRUE;
                    451: 
                    452:        StatusMessage (hwndDlg, "REMOVING_APPDATA");
                    453: 
                    454:        SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
                    455:        strcat (path, "\\TrueCrypt\\");
                    456: 
                    457:        // Delete favorite volumes file
                    458:        sprintf (path2, "%s%s", path, FILE_FAVORITE_VOLUMES);
                    459:        RemoveMessage (hwndDlg, path2);
                    460:        StatDeleteFile (path2);
                    461: 
                    462:        // Delete keyfile defaults
                    463:        sprintf (path2, "%s%s", path, FILE_DEFAULT_KEYFILES);
                    464:        RemoveMessage (hwndDlg, path2);
                    465:        StatDeleteFile (path2);
                    466: 
                    467:        // Delete history file
                    468:        sprintf (path2, "%s%s", path, FILE_HISTORY);
                    469:        RemoveMessage (hwndDlg, path2);
                    470:        StatDeleteFile (path2);
                    471:        
                    472:        // Delete configuration file
                    473:        sprintf (path2, "%s%s", path, FILE_CONFIGURATION);
                    474:        RemoveMessage (hwndDlg, path2);
                    475:        StatDeleteFile (path2);
                    476: 
                    477:        SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
                    478:        strcat (path, "\\TrueCrypt");
                    479:        RemoveMessage (hwndDlg, path);
                    480:        if (!StatRemoveDirectory (path))
                    481:        {
                    482:                handleWin32Error (hwndDlg);
                    483:                bOK = FALSE;
                    484:        }
                    485: 
                    486:        return bOK;
                    487: }
                    488: 
                    489: BOOL
                    490: DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated)
1.1       root      491: {
                    492:        BOOL bOK = FALSE;
1.1.1.7   root      493:        char regk [64];
1.1       root      494: 
1.1.1.7   root      495:        StatusMessage (hwndDlg, bRemoveDeprecated ? "REMOVING_DEPRECATED_REG" : "REMOVING_REG");
1.1       root      496: 
                    497:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt");
                    498:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open\\command");
                    499:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open");
                    500:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell");
                    501:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\DefaultIcon");
                    502:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume");
                    503:        RegDeleteKey (HKEY_CURRENT_USER, "SOFTWARE\\TrueCrypt");
1.1.1.7   root      504: 
                    505:        if (!bRemoveDeprecated)
                    506:        {
                    507:                // Split the string in order to prevent some antivirus packages from falsely reporting  
                    508:                // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
                    509:                sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
                    510:                DeleteRegistryValue (regk, "TrueCrypt");
                    511: 
                    512:                if (RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\.tc") != ERROR_SUCCESS)
                    513:                        goto error;
                    514:        }
1.1       root      515: 
                    516:        bOK = TRUE;
                    517: 
                    518:       error:
                    519: 
                    520:        if (bOK == FALSE && GetLastError ()!= ERROR_NO_TOKEN && GetLastError ()!= ERROR_FILE_NOT_FOUND
                    521:            && GetLastError ()!= ERROR_PATH_NOT_FOUND)
                    522:        {
                    523:                handleWin32Error (hwndDlg);
                    524:        }
                    525:        else
                    526:                bOK = TRUE;
                    527: 
                    528:        return bOK;
                    529: 
                    530: }
                    531: 
                    532: BOOL
                    533: DoServiceUninstall (HWND hwndDlg, char *lpszService)
                    534: {
                    535:        SC_HANDLE hManager, hService = NULL;
                    536:        BOOL bOK = FALSE, bRet;
                    537:        SERVICE_STATUS status;
1.1.1.6   root      538:        BOOL firstTry = TRUE;
1.1       root      539:        int x;
                    540: 
1.1.1.6   root      541:        memset (&status, 0, sizeof (status));   /* Keep VC6 quiet */
                    542: 
                    543: retry:
1.1       root      544: 
                    545:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    546:        if (hManager == NULL)
                    547:                goto error;
                    548: 
                    549:        hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
                    550:        if (hService == NULL)
                    551:                goto error;
                    552: 
1.1.1.7   root      553:        if (strcmp ("truecrypt", lpszService) == 0)
                    554:                StatusMessage (hwndDlg, "STOPPING_DRIVER");
                    555:        else
                    556:                StatusMessageParam (hwndDlg, "STOPPING", lpszService);
1.1       root      557: 
                    558: #define WAIT_PERIOD 3
                    559: 
                    560:        for (x = 0; x < WAIT_PERIOD; x++)
                    561:        {
                    562:                bRet = QueryServiceStatus (hService, &status);
                    563:                if (bRet != TRUE)
                    564:                        goto error;
                    565: 
                    566:                if (status.dwCurrentState != SERVICE_START_PENDING &&
                    567:                    status.dwCurrentState != SERVICE_STOP_PENDING &&
                    568:                    status.dwCurrentState != SERVICE_CONTINUE_PENDING)
                    569:                        break;
                    570: 
                    571:                Sleep (1000);
                    572:        }
                    573: 
                    574:        if (status.dwCurrentState != SERVICE_STOPPED)
                    575:        {
                    576:                bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status);
                    577:                if (bRet == FALSE)
                    578:                        goto try_delete;
                    579: 
                    580:                for (x = 0; x < WAIT_PERIOD; x++)
                    581:                {
                    582:                        bRet = QueryServiceStatus (hService, &status);
                    583:                        if (bRet != TRUE)
                    584:                                goto error;
                    585: 
                    586:                        if (status.dwCurrentState != SERVICE_START_PENDING &&
                    587:                            status.dwCurrentState != SERVICE_STOP_PENDING &&
                    588:                          status.dwCurrentState != SERVICE_CONTINUE_PENDING)
                    589:                                break;
                    590: 
                    591:                        Sleep (1000);
                    592:                }
                    593: 
                    594:                if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
                    595:                        goto error;
                    596:        }
                    597: 
1.1.1.6   root      598: try_delete:
                    599: 
1.1.1.7   root      600:        if (strcmp ("truecrypt", lpszService) == 0)
                    601:                StatusMessage (hwndDlg, "REMOVING_DRIVER");
                    602:        else
                    603:                StatusMessageParam (hwndDlg, "REMOVING", lpszService);
1.1       root      604: 
                    605:        if (hService != NULL)
                    606:                CloseServiceHandle (hService);
                    607: 
                    608:        if (hManager != NULL)
                    609:                CloseServiceHandle (hManager);
                    610: 
                    611:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    612:        if (hManager == NULL)
                    613:                goto error;
                    614: 
                    615:        hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
                    616:        if (hService == NULL)
                    617:                goto error;
                    618: 
                    619:        bRet = DeleteService (hService);
                    620:        if (bRet == FALSE)
1.1.1.6   root      621:        {
                    622:                if (firstTry && GetLastError () == ERROR_SERVICE_MARKED_FOR_DELETE)
                    623:                {
                    624:                        // Second try for an eventual no-install driver instance
                    625:                        CloseServiceHandle (hService);
                    626:                        CloseServiceHandle (hManager);
                    627: 
                    628:                        Sleep(1000);
                    629:                        firstTry = FALSE;
                    630:                        goto retry;
                    631:                }
                    632: 
1.1       root      633:                goto error;
1.1.1.6   root      634:        }
1.1       root      635: 
                    636:        bOK = TRUE;
                    637: 
1.1.1.6   root      638: error:
                    639: 
1.1       root      640:        if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
                    641:        {
                    642:                handleWin32Error (hwndDlg);
1.1.1.7   root      643:                MessageBoxW (hwndDlg, GetString ("DRIVER_UINSTALL_FAILED"), lpszTitle, MB_ICONHAND);
1.1       root      644:        }
                    645:        else
                    646:                bOK = TRUE;
                    647: 
                    648:        if (hService != NULL)
                    649:                CloseServiceHandle (hService);
                    650: 
                    651:        if (hManager != NULL)
                    652:                CloseServiceHandle (hManager);
                    653: 
                    654:        return bOK;
                    655: }
                    656: 
1.1.1.7   root      657: 
1.1       root      658: BOOL
                    659: DoDriverUnload (HWND hwndDlg)
                    660: {
                    661:        BOOL bOK = TRUE;
                    662:        int status;
                    663: 
                    664:        status = DriverAttach ();
                    665:        if (status != 0)
                    666:        {
                    667:                if (status == ERR_OS_ERROR && GetLastError ()!= ERROR_FILE_NOT_FOUND)
                    668:                {
                    669:                        handleWin32Error (hwndDlg);
1.1.1.7   root      670:                        AbortProcess ("NODRIVER");
1.1       root      671:                }
                    672: 
                    673:                if (status != ERR_OS_ERROR)
                    674:                {
                    675:                        handleError (NULL, status);
1.1.1.7   root      676:                        AbortProcess ("NODRIVER");
1.1       root      677:                }
                    678:        }
                    679: 
                    680:        if (hDriver != INVALID_HANDLE_VALUE)
                    681:        {
1.1.1.3   root      682:                MOUNT_LIST_STRUCT driver;
1.1.1.7   root      683:                int refCount;
1.1.1.3   root      684:                DWORD dwResult;
                    685:                BOOL bResult;
1.1       root      686: 
1.1.1.3   root      687:                bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver, sizeof (driver), &driver,
                    688:                        sizeof (driver), &dwResult, NULL);
1.1       root      689: 
1.1.1.7   root      690:                if (bResult)
1.1       root      691:                {
1.1.1.3   root      692:                        if (driver.ulMountedDrives != 0)
1.1       root      693:                        {
                    694:                                bOK = FALSE;
1.1.1.7   root      695:                                MessageBoxW (hwndDlg, GetString ("DISMOUNT_ALL_FIRST"), lpszTitle, MB_ICONHAND);
1.1       root      696:                        }
                    697:                }
                    698:                else
                    699:                {
1.1.1.3   root      700:                        bOK = FALSE;
                    701:                        handleWin32Error (hwndDlg);
1.1       root      702:                }
1.1.1.7   root      703:                
                    704:                // Try to close all open TC windows
                    705:                {
                    706:                        BOOL TCWindowClosed = FALSE;
                    707:                        EnumWindows (CloseTCWindowsEnum, (LPARAM) &TCWindowClosed);
                    708:                        if (TCWindowClosed) Sleep (2000);
                    709:                }
                    710: 
                    711:                // Test for any applications attached to driver
                    712:                bResult = DeviceIoControl (hDriver, DEVICE_REFCOUNT, &refCount, sizeof (refCount), &refCount,
                    713:                        sizeof (refCount), &dwResult, NULL);
                    714: 
                    715:                if (bOK && bResult && refCount > 1)
                    716:                {
                    717:                        MessageBoxW (hwndDlg, GetString ("CLOSE_TC_FIRST"), lpszTitle, MB_ICONSTOP);
                    718:                        bOK = FALSE;
                    719:                }
1.1       root      720: 
                    721:                CloseHandle (hDriver);
                    722:                hDriver = INVALID_HANDLE_VALUE;
                    723:        }
                    724: 
                    725:        return bOK;
                    726: }
                    727: 
                    728: 
                    729: BOOL
                    730: DoDriverInstall (HWND hwndDlg)
                    731: {
                    732:        SC_HANDLE hManager, hService = NULL;
                    733:        BOOL bOK = FALSE, bRet, bSlash;
                    734:        char szDir[TC_MAX_PATH];
                    735:        int x;
                    736: 
                    737:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    738:        if (hManager == NULL)
                    739:                goto error;
                    740: 
1.1.1.7   root      741:        if (!Is64BitOs ())
                    742:                GetSystemDirectory (szDir, sizeof (szDir));
                    743:        else
                    744:                GetWindowsDirectory (szDir, sizeof (szDir));
1.1       root      745: 
                    746:        x = strlen (szDir);
                    747:        if (szDir[x - 1] == '\\')
                    748:                bSlash = TRUE;
                    749:        else
                    750:                bSlash = FALSE;
                    751: 
                    752:        if (bSlash == FALSE)
                    753:                strcat (szDir, "\\");
                    754: 
1.1.1.7   root      755:        strcat (szDir, !Is64BitOs () ? "Drivers\\truecrypt.sys" : "SysWOW64\\Drivers\\truecrypt.sys");
                    756:        StatusMessage (hwndDlg, "INSTALLING_DRIVER");
1.1       root      757: 
                    758:        hService = CreateService (hManager, "truecrypt", "truecrypt",
                    759:                                  SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
                    760:                                  szDir, NULL, NULL, NULL, NULL, NULL
                    761:                );
                    762:        if (hService == NULL)
                    763:                goto error;
                    764:        else
                    765:                CloseServiceHandle (hService);
                    766: 
                    767:        hService = OpenService (hManager, "truecrypt", SERVICE_ALL_ACCESS);
                    768:        if (hService == NULL)
                    769:                goto error;
                    770: 
1.1.1.7   root      771:        StatusMessage (hwndDlg, "STARTING_DRIVER");
1.1       root      772: 
                    773:        bRet = StartService (hService, 0, NULL);
                    774:        if (bRet == FALSE)
                    775:                goto error;
                    776: 
                    777:        bOK = TRUE;
                    778: 
                    779:       error:
                    780:        if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_ALREADY_RUNNING)
                    781:        {
                    782:                handleWin32Error (hwndDlg);
1.1.1.7   root      783:                MessageBoxW (hwndDlg, GetString ("DRIVER_INSTALL_FAILED"), lpszTitle, MB_ICONHAND);
1.1       root      784:        }
                    785:        else
                    786:                bOK = TRUE;
                    787: 
                    788:        if (hService != NULL)
                    789:                CloseServiceHandle (hService);
                    790: 
                    791:        if (hManager != NULL)
                    792:                CloseServiceHandle (hManager);
                    793: 
                    794:        return bOK;
                    795: }
                    796: 
                    797: BOOL
                    798: DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
                    799: {
                    800:        char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
1.1.1.7   root      801:        char szTmp2[TC_MAX_PATH];
1.1       root      802:        BOOL bSlash, bOK = FALSE;
                    803:        HRESULT hOle;
                    804:        int x;
                    805:        BOOL allUsers = FALSE;
                    806: 
                    807:        hOle = OleInitialize (NULL);
                    808: 
                    809:        // User start menu
                    810:     SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
                    811:        x = strlen (szLinkDir);
                    812:        if (szLinkDir[x - 1] == '\\')
                    813:                bSlash = TRUE;
                    814:        else
                    815:                bSlash = FALSE;
                    816: 
                    817:        if (bSlash == FALSE)
                    818:                strcat (szLinkDir, "\\");
                    819: 
                    820:        strcat (szLinkDir, "TrueCrypt");
                    821: 
                    822:        // Global start menu
                    823:        {
                    824:                struct _stat st;
                    825:                char path[TC_MAX_PATH];
                    826: 
                    827:                SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
                    828:                strcat (path, "\\TrueCrypt");
                    829: 
                    830:                if (_stat (path, &st) == 0)
                    831:                {
                    832:                        strcpy (szLinkDir, path);
                    833:                        allUsers = TRUE;
                    834:                }
                    835:        }
                    836: 
                    837:        // Start menu entries
                    838:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                    839:        RemoveMessage (hwndDlg, szTmp2);
                    840:        if (StatDeleteFile (szTmp2) == FALSE)
                    841:                goto error;
                    842: 
                    843:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
                    844:        RemoveMessage (hwndDlg, szTmp2);
                    845:        if (StatDeleteFile (szTmp2) == FALSE)
                    846:                goto error;
                    847: 
                    848:        GetWindowsDirectory (szDir, sizeof (szDir));
                    849:        sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
                    850:        RemoveMessage (hwndDlg, szTmp2);
                    851:        if (StatDeleteFile (szTmp2) == FALSE)
                    852:                goto error;
                    853: 
                    854:        // Start menu group
                    855:        RemoveMessage ((HWND) hwndDlg, szLinkDir);
                    856:        if (StatRemoveDirectory (szLinkDir) == FALSE)
                    857:        {
                    858:                handleWin32Error ((HWND) hwndDlg);
                    859:                goto error;
                    860:        }
                    861: 
                    862:        // Desktop icon
                    863: 
                    864:        if (allUsers)
                    865:                SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
                    866:        else
                    867:                SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
                    868: 
                    869:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                    870: 
                    871:        RemoveMessage (hwndDlg, szTmp2);
                    872:        if (StatDeleteFile (szTmp2) == FALSE)
                    873:                goto error;
                    874: 
                    875:        bOK = TRUE;
                    876: 
                    877: error:
                    878:        OleUninitialize ();
                    879: 
                    880:        return bOK;
                    881: }
                    882: 
                    883: BOOL
                    884: DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
                    885: {
                    886:        char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
1.1.1.7   root      887:        char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH], szTmp3[TC_MAX_PATH];
1.1       root      888:        BOOL bSlash, bOK = FALSE;
                    889:        HRESULT hOle;
                    890:        int x;
                    891: 
                    892:        if (bProgGroup == FALSE && bDesktopIcon == FALSE)
                    893:                return TRUE;
                    894: 
                    895:        hOle = OleInitialize (NULL);
                    896: 
                    897:        GetProgramPath (hwndDlg, szLinkDir);
                    898: 
                    899:        x = strlen (szLinkDir);
                    900:        if (szLinkDir[x - 1] == '\\')
                    901:                bSlash = TRUE;
                    902:        else
                    903:                bSlash = FALSE;
                    904: 
                    905:        if (bSlash == FALSE)
                    906:                strcat (szLinkDir, "\\");
                    907: 
                    908:        strcat (szLinkDir, "TrueCrypt");
                    909: 
                    910:        strcpy (szDir, szDestDir);
                    911:        x = strlen (szDestDir);
                    912:        if (szDestDir[x - 1] == '\\')
                    913:                bSlash = TRUE;
                    914:        else
                    915:                bSlash = FALSE;
                    916: 
                    917:        if (bSlash == FALSE)
                    918:                strcat (szDir, "\\");
                    919: 
                    920:        if (bProgGroup)
                    921:        {
                    922:                if (mkfulldir (szLinkDir, TRUE) != 0)
                    923:                {
1.1.1.7   root      924:                        wchar_t szTmp[TC_MAX_PATH];
1.1       root      925: 
                    926:                        if (mkfulldir (szLinkDir, FALSE) != 0)
                    927:                        {
                    928:                                handleWin32Error (hwndDlg);
1.1.1.7   root      929:                                wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), szLinkDir);
                    930:                                MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1.1       root      931:                                goto error;
                    932:                        }
                    933:                }
                    934: 
                    935:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
                    936:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                    937: 
                    938:                IconMessage (hwndDlg, szTmp2);
                    939:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                    940:                        goto error;
                    941: 
                    942:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt User Guide.pdf");
                    943:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
                    944: 
                    945:                IconMessage (hwndDlg, szTmp2);
                    946:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                    947:                        goto error;
                    948: 
                    949:                GetWindowsDirectory (szDir, sizeof (szDir));
                    950:                x = strlen (szDir);
                    951:                if (szDir[x - 1] == '\\')
                    952:                        bSlash = TRUE;
                    953:                else
                    954:                        bSlash = FALSE;
                    955: 
                    956:                if (bSlash == FALSE)
                    957:                        strcat (szDir, "\\");
                    958: 
                    959:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
                    960:                sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
1.1.1.7   root      961:                sprintf (szTmp3, "/u %s", szDestDir);
1.1       root      962: 
                    963:                IconMessage (hwndDlg, szTmp2);
1.1.1.7   root      964:                if (CreateLink (szTmp, szTmp3, szTmp2) != S_OK)
1.1       root      965:                        goto error;
                    966: 
                    967:        }
                    968: 
                    969:        if (bDesktopIcon)
                    970:        {
                    971:                strcpy (szDir, szDestDir);
                    972:                x = strlen (szDestDir);
                    973:                if (szDestDir[x - 1] == '\\')
                    974:                        bSlash = TRUE;
                    975:                else
                    976:                        bSlash = FALSE;
                    977: 
                    978:                if (bSlash == FALSE)
                    979:                        strcat (szDir, "\\");
                    980: 
1.1.1.7   root      981:                if (IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
1.1       root      982:                        SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
                    983:                else
                    984:                        SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
                    985: 
                    986:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
                    987:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                    988: 
                    989:                IconMessage (hwndDlg, szTmp2);
                    990: 
                    991:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                    992:                        goto error;
                    993:        }
                    994: 
                    995:        bOK = TRUE;
                    996: 
                    997: error:
                    998:        OleUninitialize ();
                    999: 
                   1000:        return bOK;
                   1001: }
                   1002: 
                   1003: 
                   1004: void
                   1005: RebootPrompt (HWND hwndDlg, BOOL bOK)
                   1006: {
1.1.1.7   root     1007:        if (bOK)
1.1       root     1008:        {
                   1009:                EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
                   1010: 
                   1011:                bDone = TRUE;
                   1012: 
1.1.1.7   root     1013:                if (bUninstall == FALSE)
                   1014:                        MessageBoxW ((HWND) hwndDlg, GetString ("INSTALL_OK"), lpszTitle, MB_ICONINFORMATION);
1.1       root     1015:                else
1.1.1.7   root     1016:                        MessageBoxW ((HWND) hwndDlg, GetString ("UNINSTALL_OK"), lpszTitle, MB_ICONINFORMATION);
1.1       root     1017:        }
                   1018:        else
                   1019:        {
                   1020:                if (bUninstall == FALSE)
1.1.1.7   root     1021:                        MessageBoxW ((HWND) hwndDlg, GetString ("INSTALL_FAILED"), lpszTitle, MB_ICONHAND);
1.1       root     1022:                else
1.1.1.7   root     1023:                        MessageBoxW ((HWND) hwndDlg, GetString ("UNINSTALL_FAILED"), lpszTitle, MB_ICONHAND);
1.1       root     1024:        }
                   1025: }
                   1026: 
                   1027: static void SetSystemRestorePoint (void *hwndDlg, BOOL finalize)
                   1028: {
                   1029:        static RESTOREPOINTINFO RestPtInfo;
                   1030:        static STATEMGRSTATUS SMgrStatus;
                   1031:        static BOOL failed = FALSE;
                   1032:        static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
                   1033:        
                   1034:        if (!SystemRestoreDll) return;
                   1035: 
                   1036:        _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA");
                   1037:        if (_SRSetRestorePoint == 0)
                   1038:        {
                   1039:                FreeLibrary (SystemRestoreDll);
                   1040:                SystemRestoreDll = 0;
                   1041:                return;
                   1042:        }
                   1043: 
                   1044:        if (!finalize)
                   1045:        {
1.1.1.7   root     1046:                StatusMessage (hwndDlg, "CREATING_SYS_RESTORE");
1.1       root     1047: 
                   1048:                // Initialize the RESTOREPOINTINFO structure
                   1049:                RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
                   1050: 
                   1051:                // Notify the system that changes are about to be made.
                   1052:                // An application is to be installed.
                   1053:                RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;
                   1054: 
                   1055:                // Set RestPtInfo.llSequenceNumber.
                   1056:                RestPtInfo.llSequenceNumber = 0;
                   1057: 
                   1058:                // String to be displayed by System Restore for this restore point. 
1.1.1.7   root     1059:                strcpy (RestPtInfo.szDescription, "TrueCrypt installation");
1.1       root     1060: 
                   1061:                // Notify the system that changes are to be made and that
                   1062:                // the beginning of the restore point should be marked. 
1.1.1.7   root     1063:                if(!_SRSetRestorePoint (&RestPtInfo, &SMgrStatus)) 
1.1       root     1064:                {
1.1.1.7   root     1065:                        StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
1.1       root     1066:                        failed = TRUE;
                   1067:                }
                   1068: 
                   1069:                return;
                   1070:        }
                   1071: 
                   1072:        if (failed)     return;
                   1073: 
                   1074:        // The application performs some installation operations here.
                   1075: 
                   1076:        // Re-initialize the RESTOREPOINTINFO structure to notify the 
                   1077:        // system that the operation is finished.
                   1078:        RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
                   1079: 
                   1080:        // End the system change by returning the sequence number 
                   1081:        // received from the first call to SRSetRestorePoint.
                   1082:        RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
                   1083: 
                   1084:        // Notify the system that the operation is done and that this
                   1085:        // is the end of the restore point.
                   1086:        if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus)) 
                   1087:        {
1.1.1.7   root     1088:                StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
1.1       root     1089:        }
                   1090:        else
1.1.1.7   root     1091:                StatusMessage (hwndDlg, "SYS_RESTORE_CREATED");
1.1       root     1092: }
                   1093: 
                   1094: void
                   1095: DoUninstall (void *hwndDlg)
                   1096: {
                   1097:        BOOL bOK = TRUE;
                   1098: 
1.1.1.7   root     1099:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), FALSE);
1.1       root     1100: 
                   1101:        WaitCursor ();
                   1102: 
                   1103:        SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
                   1104: 
                   1105:        if (DoDriverUnload (hwndDlg) == FALSE)
                   1106:        {
                   1107:                bOK = FALSE;
                   1108:        }
                   1109:        else if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
                   1110:        {
                   1111:                bOK = FALSE;
                   1112:        }
                   1113:        else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
                   1114:        {
                   1115:                bOK = FALSE;
                   1116:        }
                   1117:        else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, FALSE) == FALSE)
                   1118:        {
                   1119:                bOK = FALSE;
                   1120:        }
1.1.1.7   root     1121:        else if (DoRegUninstall ((HWND) hwndDlg, FALSE) == FALSE)
1.1       root     1122:        {
                   1123:                bOK = FALSE;
                   1124:        }
                   1125:        else if (DoShortcutsUninstall (hwndDlg, dlg_file_name) == FALSE)
                   1126:        {
                   1127:                bOK = FALSE;
                   1128:        }
1.1.1.7   root     1129:        else if (!DoApplicationDataUninstall (hwndDlg))
                   1130:        {
                   1131:                bOK = FALSE;
                   1132:        }
1.1       root     1133:        else
                   1134:        {
                   1135:                RemoveMessage ((HWND) hwndDlg, dlg_file_name);
                   1136:                if (StatRemoveDirectory (dlg_file_name) == FALSE)
                   1137:                {
1.1.1.7   root     1138:                        /* We're ignoring this error, because the user might have added his own files to the folder,
                   1139:                           which we cannot remove and therefore we can't remove the folder either. */
1.1       root     1140:                }
                   1141:        }
                   1142: 
                   1143:        NormalCursor ();
                   1144: 
1.1.1.7   root     1145:        if (bOK)
                   1146:                PostMessage (hwndDlg, WM_APP+2, 0, 0);
                   1147:                
                   1148:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), TRUE);
1.1       root     1149:        RebootPrompt (hwndDlg, bOK);
                   1150: }
                   1151: 
                   1152: void
                   1153: DoInstall (void *hwndDlg)
                   1154: {
                   1155:        BOOL bOK = TRUE;
                   1156: 
1.1.1.7   root     1157:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_INSTALL), FALSE);
1.1       root     1158: 
                   1159:        WaitCursor ();
                   1160: 
                   1161:        SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
                   1162: 
                   1163:        if (DoDriverUnload (hwndDlg) == FALSE)
                   1164:        {
1.1.1.4   root     1165:                NormalCursor ();
1.1.1.7   root     1166:                EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_INSTALL), TRUE);
1.1.1.4   root     1167:                return;
1.1       root     1168:        }
1.1.1.4   root     1169:        
                   1170:        if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
                   1171:        {
                   1172:                SetSystemRestorePoint (hwndDlg, FALSE);
                   1173:        }
                   1174: 
1.1.1.7   root     1175:        // Remove deprecated system service
                   1176:        DoServiceUninstall (hwndDlg, "TrueCryptService");
                   1177: 
                   1178:        // Remove deprecated TrueCrypt registry entries
                   1179:        DoRegUninstall ((HWND) hwndDlg, TRUE);
                   1180: 
                   1181:        if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1.1       root     1182:        {
                   1183:                bOK = FALSE;
                   1184:        }
1.1.1.7   root     1185:        else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, TRUE) == FALSE)
1.1       root     1186:        {
                   1187:                bOK = FALSE;
                   1188:        }
                   1189:        else if (DoRegInstall ((HWND) hwndDlg, dlg_file_name,
                   1190:                IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_FILE_TYPE)),
1.1.1.7   root     1191:                               TRUE) == FALSE)
1.1       root     1192:        {
                   1193:                bOK = FALSE;
                   1194:        }
                   1195:        else if (DoDriverInstall (hwndDlg) == FALSE)
                   1196:        {
                   1197:                bOK = FALSE;
                   1198:        }
                   1199:        else if (DoShortcutsInstall (hwndDlg, dlg_file_name,
                   1200:                                     IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_PROG_GROUP)),
                   1201:                                         IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_DESKTOP_ICON))) == FALSE)
                   1202:        {
                   1203:                bOK = FALSE;
                   1204:        }
                   1205: 
                   1206:        if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
                   1207:                SetSystemRestorePoint (hwndDlg, TRUE);
                   1208: 
                   1209:        NormalCursor ();
                   1210: 
1.1.1.7   root     1211:        if (bOK)
                   1212:        {
                   1213:                StatusMessage (hwndDlg, "INSTALL_COMPLETED");
                   1214:                PostMessage (hwndDlg,  WM_APP+1, 0, 0);
                   1215:        }
1.1       root     1216: 
1.1.1.7   root     1217:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_INSTALL), TRUE);
1.1       root     1218:        RebootPrompt (hwndDlg, bOK);
                   1219: }
                   1220: 
                   1221: 
                   1222: BOOL WINAPI
                   1223: InstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                   1224: {
                   1225:        WORD lw = LOWORD (wParam);
                   1226:        if (lParam);            /* remove warning */
                   1227: 
                   1228:        switch (msg)
                   1229:        {
1.1.1.7   root     1230: 
1.1       root     1231:        case WM_INITDIALOG:
1.1.1.7   root     1232:                MainDlg = hwndDlg;
1.1       root     1233:                InitDialog (hwndDlg);
1.1.1.7   root     1234:                LocalizeDialog (hwndDlg, NULL);
1.1       root     1235: 
1.1.1.7   root     1236:                if (UninstallPath == NULL)
1.1.1.3   root     1237:                {
                   1238:                        char path[MAX_PATH+20];
                   1239:                        ITEMIDLIST *i;
                   1240:                        SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &i);
                   1241:                        SHGetPathFromIDList (i, path);
                   1242:                        strcat (path, "\\TrueCrypt");
                   1243:                        SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), path);
                   1244:                }
1.1.1.7   root     1245:                else
                   1246:                        SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), UninstallPath);
1.1       root     1247: 
                   1248:                if (bUninstall == FALSE)
                   1249:                {
1.1.1.7   root     1250:                        SendMessage (GetDlgItem (hwndDlg, IDC_LICENSE), WM_SETFONT, (WPARAM) hFixedFont, (LPARAM) 0);
                   1251:                        SetWindowText (GetDlgItem (hwndDlg, IDC_LICENSE), GetLegalNotices ());
1.1       root     1252:                }
                   1253: 
                   1254:                SendMessage (GetDlgItem (hwndDlg, IDC_ALL_USERS), BM_SETCHECK, BST_CHECKED, 0);
                   1255:                SendMessage (GetDlgItem (hwndDlg, IDC_FILE_TYPE), BM_SETCHECK, BST_CHECKED, 0);
                   1256:                SendMessage (GetDlgItem (hwndDlg, IDC_PROG_GROUP), BM_SETCHECK, BST_CHECKED, 0);
                   1257:                SendMessage (GetDlgItem (hwndDlg, IDC_DESKTOP_ICON), BM_SETCHECK, BST_CHECKED, 0);
                   1258: 
                   1259:                // System Restore
1.1.1.7   root     1260:                SystemRestoreDll = LoadLibrary ("srclient.dll");
1.1       root     1261: 
                   1262:                if (SystemRestoreDll != 0)
                   1263:                        SendMessage (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), BM_SETCHECK, BST_CHECKED, 0);
                   1264:                else
                   1265:                        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
                   1266: 
1.1.1.7   root     1267:                SetWindowTextW (hwndDlg, lpszTitle);
1.1       root     1268:                return 1;
                   1269: 
                   1270:        case WM_SYSCOMMAND:
                   1271:                if (lw == IDC_ABOUT)
                   1272:                {
1.1.1.7   root     1273:                        DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1       root     1274:                        return 1;
                   1275:                }
                   1276:                return 0;
                   1277: 
                   1278:        case WM_COMMAND:
1.1.1.7   root     1279:                if (lw == IDC_INSTALL || lw == IDC_UNINSTALL)
1.1       root     1280:                {
                   1281:                        char szDirname[TC_MAX_PATH];
                   1282: 
1.1.1.7   root     1283:                        if (bDone)
1.1       root     1284:                        {
1.1.1.7   root     1285:                                EndDialog (hwndDlg, IDC_INSTALL);
1.1       root     1286:                                return 1;
                   1287:                        }
                   1288: 
                   1289:                        GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
                   1290: 
                   1291:                        if (bUninstall == FALSE)
                   1292:                        {
                   1293:                                if (mkfulldir (szDirname, TRUE) != 0)
                   1294:                                {
1.1.1.7   root     1295:                                        wchar_t szTmp[TC_MAX_PATH];
                   1296:                                        //int x;
1.1       root     1297: 
                   1298:                                        //sprintf (szTmp, "The directory '%s' does not exist. Do you want to create this directory?", szDirname);
1.1.1.7   root     1299:                                        //x = MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
1.1       root     1300:                                        //if (x == IDNO)
                   1301:                                        //{
                   1302:                                        //      SetFocus (GetDlgItem (hwndDlg, IDC_DESTINATION));
                   1303:                                        //      return 1;
                   1304:                                        //}
                   1305: 
                   1306:                                        if (mkfulldir (szDirname, FALSE) != 0)
                   1307:                                        {
                   1308:                                                handleWin32Error (hwndDlg);
1.1.1.7   root     1309:                                                wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), szDirname);
                   1310:                                                MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1.1       root     1311:                                                return 1;
                   1312:                                        }
                   1313:                                }
                   1314:                        }
                   1315: 
                   1316:                        strcpy (dlg_file_name, szDirname);
                   1317: 
                   1318:                        if (bUninstall == FALSE)
                   1319:                                _beginthread (DoInstall, 16384, (void *) hwndDlg);
                   1320:                        else
                   1321:                                _beginthread (DoUninstall, 16384, (void *) hwndDlg);
                   1322: 
                   1323:                        return 1;
                   1324:                }
                   1325: 
                   1326:                if (lw == IDCANCEL)
                   1327:                {
                   1328:                        EndDialog (hwndDlg, IDCANCEL);
                   1329:                        return 1;
                   1330:                }
                   1331: 
                   1332:                if (lw == IDC_BROWSE)
                   1333:                {
                   1334:                        char szDirname[TC_MAX_PATH];
                   1335: 
                   1336:                        GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
                   1337: 
1.1.1.7   root     1338:                        if (BrowseDirectories (hwndDlg, "SELECT_INSTALL_DIR", szDirname))
1.1       root     1339:                                SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname);
                   1340:                        
                   1341:                        return 1;
                   1342:                }
                   1343: 
                   1344:                if (lw == IDC_DESTINATION && HIWORD (wParam) == EN_CHANGE && bDone == FALSE)
                   1345:                {
                   1346:                        if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_DESTINATION)) <= 0)
1.1.1.7   root     1347:                                EnableWindow (GetDlgItem (hwndDlg, IDC_INSTALL), FALSE);
1.1       root     1348:                        else
1.1.1.7   root     1349:                                EnableWindow (GetDlgItem (hwndDlg, IDC_INSTALL), TRUE);
1.1       root     1350:                        return 1;
                   1351:                }
                   1352: 
                   1353:                return 0;
                   1354: 
1.1.1.7   root     1355:        case WM_APP+1:
                   1356:                SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_INSTALL), GetString ("EXIT"));
                   1357:                break;
                   1358: 
                   1359:        case WM_APP+2:
                   1360:                SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), GetString ("EXIT"));
                   1361:                break;
                   1362: 
1.1       root     1363:        case WM_CLOSE:
                   1364:                EndDialog (hwndDlg, IDCANCEL);
                   1365:                return 1;
                   1366:        }
                   1367: 
                   1368:        return 0;
                   1369: }
                   1370: 
                   1371: 
                   1372: int WINAPI
                   1373: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
                   1374:         int nCmdShow)
                   1375: {
                   1376:        if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
                   1377: 
1.1.1.7   root     1378:        lpszTitle = L"TrueCrypt Setup";
1.1       root     1379: 
                   1380:        /* Call InitApp to initialize the common code */
                   1381:        InitApp (hInstance);
                   1382: 
1.1.1.7   root     1383:        if (IsAdmin () != TRUE)
                   1384:                if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
1.1       root     1385:                        return 0;
                   1386: 
1.1.1.8   root     1387:        /* Setup directory */
                   1388:        {
                   1389:                char *s;
                   1390:                GetModuleFileName (NULL, SetupFilesDir, sizeof (SetupFilesDir));
                   1391:                s = strrchr (SetupFilesDir, '\\');
                   1392:                if (s)
                   1393:                        s[1] = 0;
                   1394:        }
                   1395: 
1.1.1.7   root     1396:        if (lpszCommandLine[0] == '/' && lpszCommandLine[1] == 'u')
1.1       root     1397:        {
                   1398:                bUninstall = TRUE;
1.1.1.7   root     1399:                if (lpszCommandLine[2] == ' ')
                   1400:                        UninstallPath = &lpszCommandLine[3];
1.1       root     1401:        }
                   1402: 
                   1403:        if (bUninstall == FALSE)
                   1404:        {
                   1405:                /* Create the main dialog box */
1.1.1.7   root     1406:                DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_INSTALL), NULL, (DLGPROC) InstallDlgProc);
1.1       root     1407:        }
                   1408:        else
                   1409:        {
                   1410:                /* Create the main dialog box */
1.1.1.7   root     1411:                DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_UNINSTALL), NULL, (DLGPROC) InstallDlgProc);
1.1       root     1412:        }
                   1413: 
                   1414:        /* Terminate */
                   1415:        return 0;
                   1416: }

unix.superglobalmegacorp.com

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