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

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

unix.superglobalmegacorp.com

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