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

1.1.1.4 ! root        1: /* The source code contained in this file has been derived from the source code
        !             2:    of Encryption for the Masses 2.02a by Paul Le Roux. Modifications and
        !             3:    additions to that source code contained in this file are Copyright (c) 2004
        !             4:    TrueCrypt Team and Copyright (c) 2004 TrueCrypt Foundation. Unmodified
        !             5:    parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation
        !             6:    release. Please see the file license.txt for full license details. */
1.1       root        7: 
                      8: #include "TCdefs.h"
                      9: #include <SrRestorePtApi.h>
                     10: 
                     11: #define MAX_PASSWORD 
                     12: 
                     13: #include "apidrvr.h"
                     14: #include "dlgcode.h"
                     15: #include "../common/resource.h"
                     16: 
                     17: #include "resource.h"
                     18: 
                     19: #include "dir.h"
                     20: #include "setup.h"
                     21: 
                     22: #include <sys\types.h>
                     23: #include <sys\stat.h>
                     24: 
                     25: #pragma warning( disable : 4201 )
                     26: #pragma warning( disable : 4115 )
                     27: 
                     28: #include <shlobj.h>
                     29: 
                     30: #pragma warning( default : 4201 )
                     31: #pragma warning( default : 4115 )
                     32: 
                     33: char dlg_file_name[TC_MAX_PATH];
                     34: BOOL bUninstall = FALSE;
                     35: BOOL bDone = FALSE;
                     36: 
                     37: HMODULE SystemRestoreDll = 0;
                     38: 
                     39: BOOL
                     40: StatDeleteFile (char *lpszFile)
                     41: {
                     42:        struct __stat64 st;
                     43: 
                     44:        if (_stat64 (lpszFile, &st) == 0)
                     45:                return DeleteFile (lpszFile);
                     46:        else
                     47:                return TRUE;
                     48: }
                     49: 
                     50: BOOL
                     51: StatRemoveDirectory (char *lpszDir)
                     52: {
                     53:        struct __stat64 st;
                     54: 
                     55:        if (_stat64 (lpszDir, &st) == 0)
                     56:                return RemoveDirectory (lpszDir);
                     57:        else
                     58:                return TRUE;
                     59: }
                     60: 
                     61: HRESULT
                     62: CreateLink (char *lpszPathObj, char *lpszArguments,
                     63:            char *lpszPathLink)
                     64: {
                     65:        HRESULT hres;
                     66:        IShellLink *psl;
                     67: 
                     68:        /* Get a pointer to the IShellLink interface.  */
                     69:        hres = CoCreateInstance (&CLSID_ShellLink, NULL,
                     70:                               CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
                     71:        if (SUCCEEDED (hres))
                     72:        {
                     73:                IPersistFile *ppf;
                     74: 
                     75:                /* Set the path to the shortcut target, and add the
                     76:                   description.  */
                     77:                psl->lpVtbl->SetPath (psl, lpszPathObj);
                     78:                psl->lpVtbl->SetArguments (psl, lpszArguments);
                     79: 
                     80:                /* Query IShellLink for the IPersistFile interface for saving
                     81:                   the shortcut in persistent storage.  */
                     82:                hres = psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile,
                     83:                                                    &ppf);
                     84: 
                     85:                if (SUCCEEDED (hres))
                     86:                {
                     87:                        WORD wsz[TC_MAX_PATH];
                     88: 
                     89:                        /* Ensure that the string is ANSI.  */
                     90:                        MultiByteToWideChar (CP_ACP, 0, lpszPathLink, -1,
                     91:                                             wsz, TC_MAX_PATH);
                     92: 
                     93:                        /* Save the link by calling IPersistFile::Save.  */
                     94:                        hres = ppf->lpVtbl->Save (ppf, wsz, TRUE);
                     95:                        ppf->lpVtbl->Release (ppf);
                     96:                }
                     97:                psl->lpVtbl->Release (psl);
                     98:        }
                     99:        return hres;
                    100: }
                    101: 
                    102: void
                    103: GetProgramPath (HWND hwndDlg, char *path)
                    104: {
                    105:        ITEMIDLIST *i;
                    106:        HRESULT res;
                    107: 
                    108:        if (nCurrentOS == WIN_NT && IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
                    109:         res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_COMMON_PROGRAMS, &i);
                    110:        else
                    111:         res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAMS, &i);
                    112: 
                    113:        SHGetPathFromIDList (i, path);
                    114: }
                    115: 
                    116: 
                    117: void
                    118: StatusMessage (HWND hwndDlg, char *head, char *txt)
                    119: {
                    120:        char szTmp[TC_MAX_PATH];
                    121:        sprintf (szTmp, head, txt);
                    122:        SendMessage (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) szTmp);
                    123:                
                    124:        SendDlgItemMessage (hwndDlg, IDC_FILES, LB_SETTOPINDEX, 
                    125:                SendDlgItemMessage (hwndDlg, IDC_FILES, LB_GETCOUNT, 0, 0) - 1, 0);
                    126: }
                    127: 
                    128: void
                    129: RegMessage (HWND hwndDlg, char *txt)
                    130: {
                    131:        StatusMessage (hwndDlg, "Adding registry entry %s", txt);
                    132: }
                    133: 
                    134: void
                    135: CopyMessage (HWND hwndDlg, char *txt)
                    136: {
                    137:        StatusMessage (hwndDlg, "Copying %s", txt);
                    138: }
                    139: 
                    140: void
                    141: RemoveMessage (HWND hwndDlg, char *txt)
                    142: {
                    143:        StatusMessage (hwndDlg, "Removing %s", txt);
                    144: }
                    145: 
                    146: void
                    147: ServiceMessage (HWND hwndDlg, char *txt)
                    148: {
                    149:        StatusMessage (hwndDlg, "Service %s", txt);
                    150: }
                    151: 
                    152: void
                    153: IconMessage (HWND hwndDlg, char *txt)
                    154: {
                    155:        StatusMessage (hwndDlg, "Adding icon %s", txt);
                    156: }
                    157: 
                    158: int CALLBACK
                    159: BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData) 
                    160: {
                    161:        switch(uMsg) {
                    162:        case BFFM_INITIALIZED: 
                    163:        {
                    164:          /* WParam is TRUE since we are passing a path.
                    165:           It would be FALSE if we were passing a pidl. */
                    166:           SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)pData);
                    167:           break;
                    168:        }
                    169: 
                    170:        case BFFM_SELCHANGED: 
                    171:        {
                    172:                char szDir[TC_MAX_PATH];
                    173: 
                    174:           /* Set the status window to the currently selected path. */
                    175:           if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir)) 
                    176:           {
                    177:                  SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);
                    178:           }
                    179:           break;
                    180:        }
                    181: 
                    182:        default:
                    183:           break;
                    184:        }
                    185: 
                    186:        return 0;
                    187: }
                    188: 
                    189: BOOL
                    190: BrowseFiles2 (HWND hwndDlg, char* lpszTitle, char* lpszFileName)
                    191: {
                    192:        BROWSEINFO bi;
                    193:        LPITEMIDLIST pidl;
                    194:        LPMALLOC pMalloc;
                    195:        BOOL bOK  = FALSE;
                    196: 
                    197:        if (SUCCEEDED(SHGetMalloc(&pMalloc))) 
                    198:        {
                    199:                ZeroMemory(&bi,sizeof(bi));
                    200:                bi.hwndOwner = hwndDlg;
                    201:                bi.pszDisplayName = 0;
                    202:                bi.lpszTitle = lpszTitle;
                    203:                bi.pidlRoot = 0;
                    204:                bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT /*| BIF_EDITBOX*/;
                    205:                bi.lpfn = BrowseCallbackProc;
                    206:                bi.lParam = (LPARAM)lpszFileName;
                    207: 
                    208:                pidl = SHBrowseForFolder(&bi);
                    209:                if (pidl!=NULL) 
                    210:                {
                    211:                        if (SHGetPathFromIDList(pidl,lpszFileName)==TRUE) 
                    212:                        {
                    213:                                bOK = TRUE;
                    214:                        }
                    215: 
                    216:                        pMalloc->lpVtbl->Free(pMalloc,pidl);
                    217:                        pMalloc->lpVtbl->Release(pMalloc);
                    218:                }
                    219:        }
                    220: 
                    221:        return bOK;
                    222: }
                    223: 
                    224: 
                    225: void
                    226: LoadLicense (HWND hwndDlg)
                    227: {
                    228:        FILE *fp;
                    229: 
                    230:        fp = fopen ("Setup Files\\license.txt", "rb");
                    231: 
                    232:        if (fp == NULL)
                    233:                return;
                    234:        else
                    235:        {
                    236:                long x;
                    237: 
                    238:                fseek (fp, 0, SEEK_END);
                    239:                x = ftell (fp);
                    240:                rewind (fp);
                    241: 
                    242:                if (x > 0)
                    243:                {
                    244:                        char *tmp = malloc (x + 1);
                    245:                        long z;
                    246: 
                    247:                        if (tmp == NULL)
                    248:                                goto exit;
                    249:                        z = (long) fread (tmp, 1, x, fp);
                    250:                        if (z != x)
                    251:                        {
                    252:                                free (tmp);
                    253:                                goto exit;
                    254:                        }
                    255:                        else
                    256:                        {
                    257:                                int i;
                    258:                                tmp[x] = 0;
                    259: 
                    260:                                //// Remove single CRLFs
                    261:                                //for (i = 0; i < x - 3; i++)
                    262:                                //{
                    263:                                //      if (tmp[i] == 0xd && tmp[i+2] == 0xd)
                    264:                                //              i += 4;
                    265: 
                    266:                                //      if (tmp[i] == 0xd && tmp[i+2] != 0xd)
                    267:                                //      {
                    268:                                //              tmp[i] = tmp[i+1] = ' ';
                    269:                                //      }
                    270:                                //}
                    271: 
                    272:                                SendMessage (GetDlgItem (hwndDlg, IDC_LICENSE), WM_SETFONT, (WPARAM) hFixedFont, (LPARAM) 0);
                    273:                                SetWindowText (GetDlgItem (hwndDlg, IDC_LICENSE), tmp);
                    274: 
                    275:                                free (tmp);
                    276:                        }
                    277:                }
                    278:        }
                    279: 
                    280:       exit:
                    281:        fclose (fp);
                    282: }
                    283: 
                    284: BOOL
                    285: DoFilesInstall (HWND hwndDlg, char *szDestDir, BOOL bUninstallSupport)
                    286: {
                    287: 
                    288: 
                    289:        char *szFiles[]=
                    290:        {
                    291:                "ATrueCrypt.exe", "ATrueCrypt Format.exe",
                    292:                "Alicense.txt", "ATrueCrypt User Guide.pdf",
                    293:                "WTrueCrypt Setup.exe", "STrueCryptService.exe", "Dtruecrypt.sys",
                    294:        };
                    295: 
                    296:        char szTmp[TC_MAX_PATH];
                    297:        BOOL bOK = TRUE;
                    298:        int i;
                    299: 
                    300:        if (bUninstall == TRUE)
                    301:                bUninstallSupport = FALSE;
                    302: 
                    303:        for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
                    304:        {
                    305:                BOOL bResult, bSlash;
                    306:                char szDir[TC_MAX_PATH];
                    307:                int x;
                    308: 
                    309:                if (bUninstallSupport == FALSE && strstr (szFiles[i], "TrueCrypt Setup") != 0)
                    310:                        continue;
                    311: 
                    312:                if (*szFiles[i] == 'A')
                    313:                        strcpy (szDir, szDestDir);
                    314:                else if (*szFiles[i] == 'S')
                    315:                        GetSystemDirectory (szDir, sizeof (szDir));
                    316:                else if (*szFiles[i] == 'I')
                    317:                {
                    318:                        GetSystemDirectory (szDir, sizeof (szDir));
                    319: 
                    320:                        x = strlen (szDestDir);
                    321:                        if (szDestDir[x - 1] == '\\')
                    322:                                bSlash = TRUE;
                    323:                        else
                    324:                                bSlash = FALSE;
                    325: 
                    326:                        if (bSlash == FALSE)
                    327:                                strcat (szDir, "\\");
                    328: 
                    329:                        strcat (szDir, "IOSUBSYS");
                    330:                }
                    331:                else if (*szFiles[i] == 'D')
                    332:                {
                    333:                        GetSystemDirectory (szDir, sizeof (szDir));
                    334: 
                    335:                        x = strlen (szDestDir);
                    336:                        if (szDestDir[x - 1] == '\\')
                    337:                                bSlash = TRUE;
                    338:                        else
                    339:                                bSlash = FALSE;
                    340: 
                    341:                        if (bSlash == FALSE)
                    342:                                strcat (szDir, "\\");
                    343: 
                    344:                        strcat (szDir, "Drivers");
                    345:                }
                    346:                else if (*szFiles[i] == 'W')
                    347:                        GetWindowsDirectory (szDir, sizeof (szDir));
                    348: 
                    349:                x = strlen (szDestDir);
                    350:                if (szDestDir[x - 1] == '\\')
                    351:                        bSlash = TRUE;
                    352:                else
                    353:                        bSlash = FALSE;
                    354: 
                    355:                if (bSlash == FALSE)
                    356:                        strcat (szDir, "\\");
                    357: 
                    358:                if ((*szFiles[i] == 'D' || *szFiles[i] == 'S') && nCurrentOS != WIN_NT)
                    359:                        continue;
                    360: 
                    361:                if (*szFiles[i] == 'I' && nCurrentOS == WIN_NT)
                    362:                        continue;
                    363: 
                    364:                sprintf (szTmp, "%s%s", szDir, szFiles[i] + 1);
                    365: 
                    366:                if (bUninstall == FALSE)
                    367:                        CopyMessage (hwndDlg, szTmp);
                    368:                else
                    369:                        RemoveMessage (hwndDlg, szTmp);
                    370: 
                    371:                if (bUninstall == FALSE)
                    372:                {
                    373:                        bResult = CopyFile (szFiles[i] + 1, szTmp, FALSE);
                    374:                        if (!bResult)
                    375:                        {
                    376:                                char s[256];
                    377:                                sprintf (s, "Setup Files\\%s", szFiles[i] + 1);
                    378:                                bResult = CopyFile (s, szTmp, FALSE);
                    379:                        }
                    380:                }
                    381:                else
                    382:                {
                    383:                        bResult = StatDeleteFile (szTmp);
                    384:                }
                    385: 
                    386:                if (bResult == FALSE)
                    387:                {
                    388:                        LPVOID lpMsgBuf;
                    389:                        DWORD dwError = GetLastError ();
                    390:                        char szTmp2[700];
                    391: 
                    392:                        FormatMessage (
                    393:                                              FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                    394:                                              NULL,
                    395:                                              dwError,
                    396:                                 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),    /* Default language */
                    397:                                              (char *) &lpMsgBuf,
                    398:                                              0,
                    399:                                              NULL
                    400:                                );
                    401: 
                    402: 
                    403:                        if (bUninstall == FALSE)
                    404:                                sprintf (szTmp2, "The installation of '%s' has failed. %s Do you want to continue with the Install?",
                    405:                                         szTmp, lpMsgBuf);
                    406:                        else
                    407:                                sprintf (szTmp2, "The uninstallation of '%s' has failed. %s Do you want to continue with the Uninstall?",
                    408:                                         szTmp, lpMsgBuf);
                    409: 
                    410:                        LocalFree (lpMsgBuf);
                    411: 
                    412:                        if (MessageBox (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
                    413:                                return FALSE;
                    414:                }
                    415: 
                    416:        }
                    417: 
                    418:        return bOK;
                    419: }
                    420: 
                    421: BOOL
                    422: DoRegInstall (HWND hwndDlg, char *szDestDir, BOOL bInstallType, BOOL bUninstallSupport)
                    423: {
                    424:        char szDir[TC_MAX_PATH], *key;
                    425:        HKEY hkey = 0;
                    426:        BOOL bSlash, bOK = FALSE;
                    427:        DWORD dw;
                    428:        int x;
                    429: 
                    430:        strcpy (szDir, szDestDir);
                    431:        x = strlen (szDestDir);
                    432:        if (szDestDir[x - 1] == '\\')
                    433:                bSlash = TRUE;
                    434:        else
                    435:                bSlash = FALSE;
                    436: 
                    437:        if (bSlash == FALSE)
                    438:                strcat (szDir, "\\");
                    439: 
                    440:        if (nCurrentOS == WIN_NT)
                    441:        {
                    442:                /* 9/9/99 FIX This code should no longer be needed as we use
                    443:                   the "services" api to install the driver now, rather than
                    444:                   setting the registry by hand */
                    445: 
                    446:                /* Install device driver */
                    447:                key = "SYSTEM\\CurrentControlSet\\Services\\truecrypt";
                    448:                RegMessage (hwndDlg, key);
                    449:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    450:                                    key,
                    451:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    452:                        goto error;
                    453: 
                    454:                dw = 1;
                    455:                if (RegSetValueEx (hkey, "Type", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
                    456:                        goto error;
                    457: 
                    458:                dw = 1;
                    459:                if (RegSetValueEx (hkey, "Start", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
                    460:                        goto error;
                    461: 
                    462:                dw = 1;
                    463:                if (RegSetValueEx (hkey, "ErrorControl", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
                    464:                        goto error;
                    465: 
                    466:                if (RegSetValueEx (hkey, "Group", 0, REG_SZ, (BYTE *) "Primary disk", 13) != ERROR_SUCCESS)
                    467:                        goto error;
                    468: 
                    469:                RegCloseKey (hkey);
                    470:                hkey = 0;
                    471:        }
                    472: 
                    473:        if (bInstallType == TRUE)
                    474:        {
                    475:                char szTmp[TC_MAX_PATH];
                    476: 
                    477:                key = "SOFTWARE\\Classes\\TrueCryptVolume";
                    478:                RegMessage (hwndDlg, key);
                    479:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    480:                                    key,
                    481:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    482:                        goto error;
                    483: 
                    484:                sprintf (szTmp, "TrueCrypt Volume", szDir);
                    485:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    486:                        goto error;
                    487: 
                    488:                RegCloseKey (hkey);
                    489:                hkey = 0;
                    490: 
                    491:                key = "SOFTWARE\\Classes\\TrueCryptVolume\\DefaultIcon";
                    492:                RegMessage (hwndDlg, key);
                    493:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    494:                                    key,
                    495:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    496:                        goto error;
                    497: 
                    498:                sprintf (szTmp, "%sTrueCrypt.exe,1", szDir);
                    499:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    500:                        goto error;
                    501: 
                    502:                RegCloseKey (hkey);
                    503:                hkey = 0;
                    504: 
                    505:                key = "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open\\command";
                    506:                RegMessage (hwndDlg, key);
                    507:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    508:                                    key,
                    509:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    510:                        goto error;
                    511: 
                    512:                sprintf (szTmp, "\"%sTrueCrypt.exe\" /v \"%%1\"", szDir );
                    513:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    514:                        goto error;
                    515: 
                    516:                RegCloseKey (hkey);
                    517:                hkey = 0;
                    518: 
                    519:                key = "SOFTWARE\\Classes\\.tc";
                    520:                RegMessage (hwndDlg, key);
                    521:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    522:                                    key,
                    523:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    524:                        goto error;
                    525: 
                    526:                strcpy (szTmp, "TrueCryptVolume");
                    527:                if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    528:                        goto error;
                    529:        }
                    530: 
                    531: 
                    532:        if (bUninstallSupport == TRUE)
                    533:        {
                    534:                char szTmp[TC_MAX_PATH];
                    535: 
                    536:                key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt";
                    537:                RegMessage (hwndDlg, key);
                    538:                if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
                    539:                                    key,
                    540:                                    0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
                    541:                        goto error;
                    542: 
                    543:                GetWindowsDirectory (szDir, sizeof (szDir));
                    544: 
                    545:                x = strlen (szDir);
                    546:                if (szDir[x - 1] == '\\')
                    547:                        bSlash = TRUE;
                    548:                else
                    549:                        bSlash = FALSE;
                    550: 
                    551:                if (bSlash == FALSE)
                    552:                        strcat (szDir, "\\");
                    553: 
                    554:                sprintf (szTmp, "%sTrueCrypt Setup.exe /u", szDir);
                    555:                if (RegSetValueEx (hkey, "UninstallString", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    556:                        goto error;
                    557: 
                    558:                strcpy (szTmp, "TrueCrypt");
                    559:                if (RegSetValueEx (hkey, "DisplayName", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
                    560:                        goto error;
                    561:        }
                    562: 
                    563:        bOK = TRUE;
                    564: 
                    565:       error:
                    566:        if (hkey != 0)
                    567:                RegCloseKey (hkey);
                    568: 
                    569:        if (bOK == FALSE)
                    570:        {
                    571:                handleWin32Error (hwndDlg);
                    572:                MessageBox (hwndDlg, "The installation of the registry entries has failed", lpszTitle, MB_ICONHAND);
                    573:        }
                    574: 
                    575:        return bOK;
                    576: }
                    577: 
                    578: BOOL
                    579: DoRegUninstall (HWND hwndDlg)
                    580: {
                    581:        BOOL bOK = FALSE;
                    582: 
                    583:        StatusMessage (hwndDlg, "%s", "Removing registry entries");
                    584: 
                    585:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt");
                    586:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open\\command");
                    587:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open");
                    588:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell");
                    589:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\DefaultIcon");
                    590:        RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume");
                    591:        RegDeleteKey (HKEY_CURRENT_USER, "SOFTWARE\\TrueCrypt");
                    592:        if (RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\.tc") != ERROR_SUCCESS)
                    593:                goto error;
                    594: 
                    595:        bOK = TRUE;
                    596: 
                    597:       error:
                    598: 
                    599:        if (bOK == FALSE && GetLastError ()!= ERROR_NO_TOKEN && GetLastError ()!= ERROR_FILE_NOT_FOUND
                    600:            && GetLastError ()!= ERROR_PATH_NOT_FOUND)
                    601:        {
                    602:                handleWin32Error (hwndDlg);
                    603:                MessageBox (hwndDlg, "The uninstallation of the registry entries has failed", lpszTitle, MB_ICONHAND);
                    604:        }
                    605:        else
                    606:                bOK = TRUE;
                    607: 
                    608:        return bOK;
                    609: 
                    610: }
                    611: 
                    612: BOOL
                    613: DoServiceUninstall (HWND hwndDlg, char *lpszService)
                    614: {
                    615:        SC_HANDLE hManager, hService = NULL;
                    616:        BOOL bOK = FALSE, bRet;
                    617:        SERVICE_STATUS status;
                    618:        char szTmp[128];
                    619:        int x;
                    620: 
                    621:        if (nCurrentOS != WIN_NT)
                    622:                return TRUE;
                    623:        else
                    624:                memset (&status, 0, sizeof (status));   /* Keep VC6 quiet */
                    625: 
                    626:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    627:        if (hManager == NULL)
                    628:                goto error;
                    629: 
                    630:        hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
                    631:        if (hService == NULL)
                    632:                goto error;
                    633: 
                    634:        sprintf (szTmp, "stopping %s", lpszService);
                    635:        ServiceMessage (hwndDlg, szTmp);
                    636: 
                    637: #define WAIT_PERIOD 3
                    638: 
                    639:        for (x = 0; x < WAIT_PERIOD; x++)
                    640:        {
                    641:                bRet = QueryServiceStatus (hService, &status);
                    642:                if (bRet != TRUE)
                    643:                        goto error;
                    644: 
                    645:                if (status.dwCurrentState != SERVICE_START_PENDING &&
                    646:                    status.dwCurrentState != SERVICE_STOP_PENDING &&
                    647:                    status.dwCurrentState != SERVICE_CONTINUE_PENDING)
                    648:                        break;
                    649: 
                    650:                Sleep (1000);
                    651:        }
                    652: 
                    653:        if (status.dwCurrentState != SERVICE_STOPPED)
                    654:        {
                    655:                bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status);
                    656:                if (bRet == FALSE)
                    657:                        goto try_delete;
                    658: 
                    659:                for (x = 0; x < WAIT_PERIOD; x++)
                    660:                {
                    661:                        bRet = QueryServiceStatus (hService, &status);
                    662:                        if (bRet != TRUE)
                    663:                                goto error;
                    664: 
                    665:                        if (status.dwCurrentState != SERVICE_START_PENDING &&
                    666:                            status.dwCurrentState != SERVICE_STOP_PENDING &&
                    667:                          status.dwCurrentState != SERVICE_CONTINUE_PENDING)
                    668:                                break;
                    669: 
                    670:                        Sleep (1000);
                    671:                }
                    672: 
                    673:                if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
                    674:                        goto error;
                    675:        }
                    676: 
                    677:       try_delete:
                    678:        sprintf (szTmp, "deleting %s", lpszService);
                    679:        ServiceMessage (hwndDlg, szTmp);
                    680: 
                    681:        if (hService != NULL)
                    682:                CloseServiceHandle (hService);
                    683: 
                    684:        if (hManager != NULL)
                    685:                CloseServiceHandle (hManager);
                    686: 
                    687:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    688:        if (hManager == NULL)
                    689:                goto error;
                    690: 
                    691:        hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
                    692:        if (hService == NULL)
                    693:                goto error;
                    694: 
                    695:        bRet = DeleteService (hService);
                    696:        if (bRet == FALSE)
                    697:                goto error;
                    698: 
                    699:        bOK = TRUE;
                    700: 
                    701:       error:
                    702:        if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
                    703:        {
                    704:                handleWin32Error (hwndDlg);
                    705:                MessageBox (hwndDlg, "The uninstallation of the device driver has failed", lpszTitle, MB_ICONHAND);
                    706:        }
                    707:        else
                    708:                bOK = TRUE;
                    709: 
                    710:        if (hService != NULL)
                    711:                CloseServiceHandle (hService);
                    712: 
                    713:        if (hManager != NULL)
                    714:                CloseServiceHandle (hManager);
                    715: 
                    716:        return bOK;
                    717: }
                    718: 
                    719: BOOL
                    720: DoDriverUnload (HWND hwndDlg)
                    721: {
                    722:        BOOL bOK = TRUE;
                    723:        int status;
                    724: 
                    725:        status = DriverAttach ();
                    726:        if (status != 0)
                    727:        {
                    728:                if (status == ERR_OS_ERROR && GetLastError ()!= ERROR_FILE_NOT_FOUND)
                    729:                {
                    730:                        handleWin32Error (hwndDlg);
                    731:                        AbortProcess (IDS_NODRIVER);
                    732:                }
                    733: 
                    734:                if (status != ERR_OS_ERROR)
                    735:                {
                    736:                        handleError (NULL, status);
                    737:                        AbortProcess (IDS_NODRIVER);
                    738:                }
                    739:        }
                    740: 
                    741:        if (hDriver != INVALID_HANDLE_VALUE)
                    742:        {
1.1.1.3   root      743:                MOUNT_LIST_STRUCT driver;
                    744:                DWORD dwResult;
                    745:                BOOL bResult;
1.1       root      746: 
1.1.1.3   root      747:                bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver, sizeof (driver), &driver,
                    748:                        sizeof (driver), &dwResult, NULL);
1.1       root      749: 
1.1.1.3   root      750:                if (bResult == TRUE)
1.1       root      751:                {
1.1.1.3   root      752:                        if (driver.ulMountedDrives != 0)
1.1       root      753:                        {
                    754:                                bOK = FALSE;
1.1.1.3   root      755:                                MessageBox (hwndDlg, "Volumes are still mounted; all volumes must be dismounted before installation can continue.", lpszTitle, MB_ICONHAND);
1.1       root      756:                        }
                    757:                }
                    758:                else
                    759:                {
1.1.1.3   root      760:                        bOK = FALSE;
                    761:                        handleWin32Error (hwndDlg);
1.1       root      762:                }
                    763: 
                    764:                CloseHandle (hDriver);
                    765:                hDriver = INVALID_HANDLE_VALUE;
                    766: 
                    767:        }
                    768: 
                    769:        return bOK;
                    770: }
                    771: 
                    772: BOOL
                    773: DoServiceInstall (HWND hwndDlg)
                    774: {
                    775:        BOOL bOK = FALSE;
                    776: 
                    777:        if (nCurrentOS != WIN_NT)
                    778:                return TRUE;
                    779: 
                    780:        ServiceMessage (hwndDlg, "installing TrueCryptService");
                    781:        ServiceMessage (hwndDlg, "starting TrueCryptService");
                    782: 
                    783:        if (CheckService ()== FALSE)
                    784:                goto error;
                    785: 
                    786:        bOK = TRUE;
                    787: 
                    788:       error:
                    789:        if (bOK == FALSE)
                    790:        {
                    791:                MessageBox ((HWND) hwndDlg, "The installation of the service has failed", lpszTitle, MB_ICONHAND);
                    792:        }
                    793: 
                    794:        return bOK;
                    795: }
                    796: 
                    797: BOOL
                    798: DoDriverInstall (HWND hwndDlg)
                    799: {
                    800:        SC_HANDLE hManager, hService = NULL;
                    801:        BOOL bOK = FALSE, bRet, bSlash;
                    802:        char szDir[TC_MAX_PATH];
                    803:        int x;
                    804: 
                    805:        if (nCurrentOS != WIN_NT)
                    806:                return TRUE;
                    807: 
                    808:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
                    809:        if (hManager == NULL)
                    810:                goto error;
                    811: 
                    812:        GetSystemDirectory (szDir, sizeof (szDir));
                    813: 
                    814:        x = strlen (szDir);
                    815:        if (szDir[x - 1] == '\\')
                    816:                bSlash = TRUE;
                    817:        else
                    818:                bSlash = FALSE;
                    819: 
                    820:        if (bSlash == FALSE)
                    821:                strcat (szDir, "\\");
                    822: 
                    823:        strcat (szDir, "Drivers\\truecrypt.sys");
                    824: 
                    825:        ServiceMessage (hwndDlg, "installing TrueCrypt driver service");
                    826: 
                    827:        hService = CreateService (hManager, "truecrypt", "truecrypt",
                    828:                                  SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
                    829:                                  szDir, NULL, NULL, NULL, NULL, NULL
                    830:                );
                    831:        if (hService == NULL)
                    832:                goto error;
                    833:        else
                    834:                CloseServiceHandle (hService);
                    835: 
                    836:        hService = OpenService (hManager, "truecrypt", SERVICE_ALL_ACCESS);
                    837:        if (hService == NULL)
                    838:                goto error;
                    839: 
                    840:        ServiceMessage (hwndDlg, "starting TrueCrypt driver service");
                    841: 
                    842:        bRet = StartService (hService, 0, NULL);
                    843:        if (bRet == FALSE)
                    844:                goto error;
                    845: 
                    846:        bOK = TRUE;
                    847: 
                    848:       error:
                    849:        if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_ALREADY_RUNNING)
                    850:        {
                    851:                handleWin32Error (hwndDlg);
                    852:                MessageBox (hwndDlg, "The installation of the device driver has failed", lpszTitle, MB_ICONHAND);
                    853:        }
                    854:        else
                    855:                bOK = TRUE;
                    856: 
                    857:        if (hService != NULL)
                    858:                CloseServiceHandle (hService);
                    859: 
                    860:        if (hManager != NULL)
                    861:                CloseServiceHandle (hManager);
                    862: 
                    863:        return bOK;
                    864: }
                    865: 
                    866: BOOL
                    867: DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
                    868: {
                    869:        char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
                    870:        char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH];
                    871:        BOOL bSlash, bOK = FALSE;
                    872:        HRESULT hOle;
                    873:        int x;
                    874:        BOOL allUsers = FALSE;
                    875: 
                    876:        hOle = OleInitialize (NULL);
                    877: 
                    878:        // User start menu
                    879:     SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
                    880:        x = strlen (szLinkDir);
                    881:        if (szLinkDir[x - 1] == '\\')
                    882:                bSlash = TRUE;
                    883:        else
                    884:                bSlash = FALSE;
                    885: 
                    886:        if (bSlash == FALSE)
                    887:                strcat (szLinkDir, "\\");
                    888: 
                    889:        strcat (szLinkDir, "TrueCrypt");
                    890: 
                    891:        // Global start menu
                    892:        if (nCurrentOS == WIN_NT)
                    893:        {
                    894:                struct _stat st;
                    895:                char path[TC_MAX_PATH];
                    896: 
                    897:                SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
                    898:                strcat (path, "\\TrueCrypt");
                    899: 
                    900:                if (_stat (path, &st) == 0)
                    901:                {
                    902:                        strcpy (szLinkDir, path);
                    903:                        allUsers = TRUE;
                    904:                }
                    905:        }
                    906: 
                    907:        // Start menu entries
                    908:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                    909:        RemoveMessage (hwndDlg, szTmp2);
                    910:        if (StatDeleteFile (szTmp2) == FALSE)
                    911:                goto error;
                    912: 
                    913:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
                    914:        RemoveMessage (hwndDlg, szTmp2);
                    915:        if (StatDeleteFile (szTmp2) == FALSE)
                    916:                goto error;
                    917: 
                    918:        GetWindowsDirectory (szDir, sizeof (szDir));
                    919:        sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
                    920:        RemoveMessage (hwndDlg, szTmp2);
                    921:        if (StatDeleteFile (szTmp2) == FALSE)
                    922:                goto error;
                    923: 
                    924:        // Start menu group
                    925:        RemoveMessage ((HWND) hwndDlg, szLinkDir);
                    926:        if (StatRemoveDirectory (szLinkDir) == FALSE)
                    927:        {
                    928:                handleWin32Error ((HWND) hwndDlg);
                    929:                goto error;
                    930:        }
                    931: 
                    932:        // Desktop icon
                    933: 
                    934:        if (allUsers)
                    935:                SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
                    936:        else
                    937:                SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
                    938: 
                    939:        sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                    940: 
                    941:        RemoveMessage (hwndDlg, szTmp2);
                    942:        if (StatDeleteFile (szTmp2) == FALSE)
                    943:                goto error;
                    944: 
                    945:        bOK = TRUE;
                    946: 
                    947: error:
                    948:        OleUninitialize ();
                    949: 
                    950:        return bOK;
                    951: }
                    952: 
                    953: BOOL
                    954: DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
                    955: {
                    956:        char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
                    957:        char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH];
                    958:        BOOL bSlash, bOK = FALSE;
                    959:        HRESULT hOle;
                    960:        int x;
                    961: 
                    962:        if (bProgGroup == FALSE && bDesktopIcon == FALSE)
                    963:                return TRUE;
                    964: 
                    965:        hOle = OleInitialize (NULL);
                    966: 
                    967:        GetProgramPath (hwndDlg, szLinkDir);
                    968: 
                    969:        x = strlen (szLinkDir);
                    970:        if (szLinkDir[x - 1] == '\\')
                    971:                bSlash = TRUE;
                    972:        else
                    973:                bSlash = FALSE;
                    974: 
                    975:        if (bSlash == FALSE)
                    976:                strcat (szLinkDir, "\\");
                    977: 
                    978:        strcat (szLinkDir, "TrueCrypt");
                    979: 
                    980:        strcpy (szDir, szDestDir);
                    981:        x = strlen (szDestDir);
                    982:        if (szDestDir[x - 1] == '\\')
                    983:                bSlash = TRUE;
                    984:        else
                    985:                bSlash = FALSE;
                    986: 
                    987:        if (bSlash == FALSE)
                    988:                strcat (szDir, "\\");
                    989: 
                    990:        if (bProgGroup)
                    991:        {
                    992:                if (mkfulldir (szLinkDir, TRUE) != 0)
                    993:                {
                    994:                        char szTmp[TC_MAX_PATH];
                    995:                        int x;
                    996: 
                    997:                        //sprintf (szTmp, "The program folder '%s' does not exist. Do you want to create this folder?", szLinkDir);
                    998:                        //x = MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
                    999:                        //if (x == IDNO)
                   1000:                        //{
                   1001:                        //      goto error;
                   1002:                        //}
                   1003: 
                   1004:                        if (mkfulldir (szLinkDir, FALSE) != 0)
                   1005:                        {
                   1006:                                handleWin32Error (hwndDlg);
                   1007:                                sprintf (szTmp, "The folder '%s' could not be created", szLinkDir);
                   1008:                                MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
                   1009:                                goto error;
                   1010:                        }
                   1011:                }
                   1012: 
                   1013:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
                   1014:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                   1015: 
                   1016:                IconMessage (hwndDlg, szTmp2);
                   1017:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                   1018:                        goto error;
                   1019: 
                   1020: 
                   1021:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt User Guide.pdf");
                   1022:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
                   1023: 
                   1024:                IconMessage (hwndDlg, szTmp2);
                   1025:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                   1026:                        goto error;
                   1027: 
                   1028:                GetWindowsDirectory (szDir, sizeof (szDir));
                   1029:                x = strlen (szDir);
                   1030:                if (szDir[x - 1] == '\\')
                   1031:                        bSlash = TRUE;
                   1032:                else
                   1033:                        bSlash = FALSE;
                   1034: 
                   1035:                if (bSlash == FALSE)
                   1036:                        strcat (szDir, "\\");
                   1037: 
                   1038:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
                   1039:                sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
                   1040: 
                   1041:                IconMessage (hwndDlg, szTmp2);
                   1042:                if (CreateLink (szTmp, "/u", szTmp2) != S_OK)
                   1043:                        goto error;
                   1044: 
                   1045:        }
                   1046: 
                   1047:        if (bDesktopIcon)
                   1048:        {
                   1049:                strcpy (szDir, szDestDir);
                   1050:                x = strlen (szDestDir);
                   1051:                if (szDestDir[x - 1] == '\\')
                   1052:                        bSlash = TRUE;
                   1053:                else
                   1054:                        bSlash = FALSE;
                   1055: 
                   1056:                if (bSlash == FALSE)
                   1057:                        strcat (szDir, "\\");
                   1058: 
                   1059:                if (nCurrentOS == WIN_NT && IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
                   1060:                        SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
                   1061:                else
                   1062:                        SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
                   1063: 
                   1064:                sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
                   1065:                sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
                   1066: 
                   1067:                IconMessage (hwndDlg, szTmp2);
                   1068: 
                   1069:                if (CreateLink (szTmp, "", szTmp2) != S_OK)
                   1070:                        goto error;
                   1071:        }
                   1072: 
                   1073:        bOK = TRUE;
                   1074: 
                   1075: error:
                   1076:        OleUninitialize ();
                   1077: 
                   1078:        return bOK;
                   1079: }
                   1080: 
                   1081: 
                   1082: void
                   1083: RebootPrompt (HWND hwndDlg, BOOL bOK)
                   1084: {
                   1085:        if (bOK == TRUE)
                   1086:        {
                   1087:                SetWindowText (GetDlgItem ((HWND) hwndDlg, IDOK), "E&xit");
                   1088: 
                   1089:                EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
                   1090: 
                   1091:                bDone = TRUE;
                   1092: 
                   1093:                if (nCurrentOS == WIN_NT)
                   1094:                {
                   1095:                        if (bUninstall == FALSE)
                   1096:                                MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.", lpszTitle, MB_ICONINFORMATION);
                   1097:                        else
                   1098:                                MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.", lpszTitle, MB_ICONINFORMATION);
                   1099:                }
                   1100:                else
                   1101:                {
                   1102:                        int x;
                   1103: 
                   1104:                        if (bUninstall == FALSE)
                   1105:                                x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.\nTo use TrueCrypt your system must be restarted.", lpszTitle, MB_ICONINFORMATION);
                   1106:                        else
                   1107:                                x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.\nYour system must be restarted.", lpszTitle, MB_ICONINFORMATION);
                   1108:                }
                   1109:        }
                   1110:        else
                   1111:        {
                   1112:                if (bUninstall == FALSE)
                   1113:                        MessageBox ((HWND) hwndDlg, "The installation has failed!", lpszTitle, MB_ICONHAND);
                   1114:                else
                   1115:                        MessageBox ((HWND) hwndDlg, "The uninstall has failed!", lpszTitle, MB_ICONHAND);
                   1116:        }
                   1117: }
                   1118: 
                   1119: static void SetSystemRestorePoint (void *hwndDlg, BOOL finalize)
                   1120: {
                   1121:        static RESTOREPOINTINFO RestPtInfo;
                   1122:        static STATEMGRSTATUS SMgrStatus;
                   1123:        static BOOL failed = FALSE;
                   1124:        static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
                   1125:        
                   1126:        if (!SystemRestoreDll) return;
                   1127: 
                   1128:        _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA");
                   1129:        if (_SRSetRestorePoint == 0)
                   1130:        {
                   1131:                FreeLibrary (SystemRestoreDll);
                   1132:                SystemRestoreDll = 0;
                   1133:                return;
                   1134:        }
                   1135: 
                   1136:        if (!finalize)
                   1137:        {
                   1138:                StatusMessage (hwndDlg, "%s", "Creating system restore point");
                   1139: 
                   1140:                // Initialize the RESTOREPOINTINFO structure
                   1141:                RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
                   1142: 
                   1143:                // Notify the system that changes are about to be made.
                   1144:                // An application is to be installed.
                   1145:                RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;
                   1146: 
                   1147:                // Set RestPtInfo.llSequenceNumber.
                   1148:                RestPtInfo.llSequenceNumber = 0;
                   1149: 
                   1150:                // String to be displayed by System Restore for this restore point. 
                   1151:                strcpy(RestPtInfo.szDescription, "TrueCrypt installation");
                   1152: 
                   1153:                // Notify the system that changes are to be made and that
                   1154:                // the beginning of the restore point should be marked. 
                   1155:                if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus)) 
                   1156:                {
                   1157:                        StatusMessage (hwndDlg, "%s", "Failed to create System Restore point!");
                   1158:                        failed = TRUE;
                   1159:                }
                   1160: 
                   1161:                return;
                   1162:        }
                   1163: 
                   1164:        if (failed)     return;
                   1165: 
                   1166:        StatusMessage (hwndDlg, "%s", "Closing system restore point");
                   1167: 
                   1168:        // The application performs some installation operations here.
                   1169: 
                   1170:        // Re-initialize the RESTOREPOINTINFO structure to notify the 
                   1171:        // system that the operation is finished.
                   1172:        RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
                   1173: 
                   1174:        // End the system change by returning the sequence number 
                   1175:        // received from the first call to SRSetRestorePoint.
                   1176:        RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
                   1177: 
                   1178:        // Notify the system that the operation is done and that this
                   1179:        // is the end of the restore point.
                   1180:        if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus)) 
                   1181:        {
                   1182:                StatusMessage (hwndDlg, "%s", "Closing system restore point failed!");
                   1183:        }
                   1184:        else
                   1185:                StatusMessage (hwndDlg, "%s", "System restore point created");
                   1186: 
                   1187: }
                   1188: 
                   1189: void
                   1190: DoUninstall (void *hwndDlg)
                   1191: {
                   1192:        BOOL bOK = TRUE;
                   1193: 
                   1194:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);
                   1195: 
                   1196:        WaitCursor ();
                   1197: 
                   1198:        SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
                   1199: 
                   1200:        if (DoDriverUnload (hwndDlg) == FALSE)
                   1201:        {
                   1202:                bOK = FALSE;
                   1203:        }
                   1204:        else if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
                   1205:        {
                   1206:                bOK = FALSE;
                   1207:        }
                   1208:        else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
                   1209:        {
                   1210:                bOK = FALSE;
                   1211:        }
                   1212:        else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, FALSE) == FALSE)
                   1213:        {
                   1214:                bOK = FALSE;
                   1215:        }
                   1216:        else if (DoRegUninstall ((HWND) hwndDlg) == FALSE)
                   1217:        {
                   1218:                bOK = FALSE;
                   1219:        }
                   1220:        else if (DoShortcutsUninstall (hwndDlg, dlg_file_name) == FALSE)
                   1221:        {
                   1222:                bOK = FALSE;
                   1223:        }
                   1224:        else
                   1225:        {
                   1226:                RemoveMessage ((HWND) hwndDlg, dlg_file_name);
                   1227:                if (StatRemoveDirectory (dlg_file_name) == FALSE)
                   1228:                {
                   1229:                        handleWin32Error ((HWND) hwndDlg);
                   1230:                        bOK = FALSE;
                   1231:                }
                   1232:        }
                   1233: 
                   1234:        NormalCursor ();
                   1235: 
                   1236:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
                   1237: 
                   1238:        RebootPrompt (hwndDlg, bOK);
                   1239: 
                   1240: }
                   1241: 
                   1242: void
                   1243: DoInstall (void *hwndDlg)
                   1244: {
                   1245:        BOOL bOK = TRUE;
                   1246: 
                   1247:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);
                   1248: 
                   1249:        WaitCursor ();
                   1250: 
                   1251:        SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
                   1252: 
                   1253:        if (DoDriverUnload (hwndDlg) == FALSE)
                   1254:        {
1.1.1.4 ! root     1255:                NormalCursor ();
        !          1256:                EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
        !          1257:                return;
1.1       root     1258:        }
1.1.1.4 ! root     1259:        
        !          1260:        if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
        !          1261:        {
        !          1262:                SetSystemRestorePoint (hwndDlg, FALSE);
        !          1263:        }
        !          1264: 
        !          1265:        if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
1.1       root     1266:        {
                   1267:                bOK = FALSE;
                   1268:        }
                   1269:        else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
                   1270:        {
                   1271:                bOK = FALSE;
                   1272:        }
                   1273:        else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL))) == FALSE)
                   1274:        {
                   1275:                bOK = FALSE;
                   1276:        }
                   1277:        else if (DoRegInstall ((HWND) hwndDlg, dlg_file_name,
                   1278:                IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_FILE_TYPE)),
                   1279:                               IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL))) == FALSE)
                   1280:        {
                   1281:                bOK = FALSE;
                   1282:        }
                   1283:        else if (DoDriverInstall (hwndDlg) == FALSE)
                   1284:        {
                   1285:                bOK = FALSE;
                   1286:        }
                   1287:        else if (DoServiceInstall (hwndDlg) == FALSE)
                   1288:        {
                   1289:                bOK = FALSE;
                   1290:        }
                   1291:        else if (DoShortcutsInstall (hwndDlg, dlg_file_name,
                   1292:                                     IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_PROG_GROUP)),
                   1293:                                         IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_DESKTOP_ICON))) == FALSE)
                   1294:        {
                   1295:                bOK = FALSE;
                   1296:        }
                   1297: 
                   1298:        if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
                   1299:                SetSystemRestorePoint (hwndDlg, TRUE);
                   1300: 
                   1301:        if (bOK)
                   1302:                StatusMessage (hwndDlg, "%s", "Installation completed.");
                   1303: 
                   1304:        NormalCursor ();
                   1305: 
                   1306:        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
                   1307: 
                   1308:        RebootPrompt (hwndDlg, bOK);
                   1309: }
                   1310: 
                   1311: BOOL
                   1312: IsAdmin (void)
                   1313: {
                   1314:        HANDLE hAccessToken;
                   1315:        UCHAR InfoBuffer[1024];
                   1316:        PTOKEN_GROUPS ptgGroups = (PTOKEN_GROUPS) InfoBuffer;
                   1317:        DWORD dwInfoBufferSize;
                   1318:        PSID psidAdministrators;
                   1319:        SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
                   1320:        BOOL bSuccess;
                   1321:        UINT x;
                   1322: 
                   1323:        if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, TRUE,
                   1324:                              &hAccessToken))
                   1325:        {
                   1326:                if (GetLastError ()!= ERROR_NO_TOKEN)
                   1327:                        return FALSE;
                   1328: 
                   1329:                /* Retry against process token if no thread token exists */
                   1330:                if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY,
                   1331:                                       &hAccessToken))
                   1332:                        return FALSE;
                   1333:        }
                   1334: 
                   1335:        bSuccess = GetTokenInformation (hAccessToken, TokenGroups, InfoBuffer,
                   1336:                                        1024, &dwInfoBufferSize);
                   1337: 
                   1338:        CloseHandle (hAccessToken);
                   1339: 
                   1340:        if (!bSuccess)
                   1341:                return FALSE;
                   1342: 
                   1343:        if (!AllocateAndInitializeSid (&siaNtAuthority, 2,
                   1344:                                       SECURITY_BUILTIN_DOMAIN_RID,
                   1345:                                       DOMAIN_ALIAS_RID_ADMINS,
                   1346:                                       0, 0, 0, 0, 0, 0,
                   1347:                                       &psidAdministrators))
                   1348:                return FALSE;
                   1349: 
                   1350:        /* Assume that we don't find the admin SID. */
                   1351:        bSuccess = FALSE;
                   1352: 
                   1353:        for (x = 0; x < ptgGroups->GroupCount; x++)
                   1354:        {
                   1355:                if (EqualSid (psidAdministrators, ptgGroups->Groups[x].Sid))
                   1356:                {
                   1357:                        bSuccess = TRUE;
                   1358:                        break;
                   1359:                }
                   1360: 
                   1361:        }
                   1362: 
                   1363:        FreeSid (psidAdministrators);
                   1364:        return bSuccess;
                   1365: }
                   1366: 
                   1367: BOOL WINAPI
                   1368: InstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                   1369: {
                   1370:        WORD lw = LOWORD (wParam);
                   1371:        if (lParam);            /* remove warning */
                   1372: 
                   1373:        switch (msg)
                   1374:        {
                   1375:        case WM_INITDIALOG:
                   1376:                SetDefaultUserFont (hwndDlg);
                   1377:                InitDialog (hwndDlg);
                   1378: 
1.1.1.3   root     1379:                {
                   1380:                        char path[MAX_PATH+20];
                   1381:                        ITEMIDLIST *i;
                   1382:                        SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &i);
                   1383:                        SHGetPathFromIDList (i, path);
                   1384:                        strcat (path, "\\TrueCrypt");
                   1385:                        SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), path);
                   1386:                }
1.1       root     1387: 
                   1388:                if (bUninstall == FALSE)
                   1389:                {
                   1390:                        SendMessage (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) "By clicking 'Install', you accept the license agreement.");
                   1391: 
                   1392:                        LoadLicense (hwndDlg);
                   1393:                }
                   1394: 
                   1395:                SendMessage (GetDlgItem (hwndDlg, IDC_ALL_USERS), BM_SETCHECK, BST_CHECKED, 0);
                   1396:                if (nCurrentOS != WIN_NT)
                   1397:                        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_ALL_USERS), FALSE);
                   1398: 
                   1399:                SendMessage (GetDlgItem (hwndDlg, IDC_FILE_TYPE), BM_SETCHECK, BST_CHECKED, 0);
                   1400:                SendMessage (GetDlgItem (hwndDlg, IDC_UNINSTALL), BM_SETCHECK, BST_CHECKED, 0);
                   1401:                SendMessage (GetDlgItem (hwndDlg, IDC_PROG_GROUP), BM_SETCHECK, BST_CHECKED, 0);
                   1402:                SendMessage (GetDlgItem (hwndDlg, IDC_DESKTOP_ICON), BM_SETCHECK, BST_CHECKED, 0);
                   1403: 
                   1404:                // System Restore
                   1405:                SystemRestoreDll = LoadLibrary("srclient.dll");
                   1406: 
                   1407:                if (SystemRestoreDll != 0)
                   1408:                        SendMessage (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), BM_SETCHECK, BST_CHECKED, 0);
                   1409:                else
                   1410:                        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
                   1411: 
                   1412:                SetWindowText (hwndDlg, lpszTitle);
                   1413:                return 1;
                   1414: 
                   1415:        case WM_SYSCOMMAND:
                   1416:                if (lw == IDC_ABOUT)
                   1417:                {
                   1418:                        DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
                   1419:                        return 1;
                   1420:                }
                   1421:                return 0;
                   1422: 
                   1423:        case WM_COMMAND:
                   1424:                if (lw == IDOK)
                   1425:                {
                   1426:                        char szDirname[TC_MAX_PATH];
                   1427: 
                   1428:                        if (bDone == TRUE)
                   1429:                        {
                   1430:                                EndDialog (hwndDlg, IDOK);
                   1431:                                return 1;
                   1432:                        }
                   1433: 
                   1434:                        GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
                   1435: 
                   1436:                        if (bUninstall == FALSE)
                   1437:                        {
                   1438:                                if (mkfulldir (szDirname, TRUE) != 0)
                   1439:                                {
                   1440:                                        char szTmp[TC_MAX_PATH];
                   1441:                                        int x;
                   1442: 
                   1443:                                        //sprintf (szTmp, "The directory '%s' does not exist. Do you want to create this directory?", szDirname);
                   1444:                                        //x = MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
                   1445:                                        //if (x == IDNO)
                   1446:                                        //{
                   1447:                                        //      SetFocus (GetDlgItem (hwndDlg, IDC_DESTINATION));
                   1448:                                        //      return 1;
                   1449:                                        //}
                   1450: 
                   1451:                                        if (mkfulldir (szDirname, FALSE) != 0)
                   1452:                                        {
                   1453:                                                handleWin32Error (hwndDlg);
                   1454:                                                sprintf (szTmp, "The directory '%s' could not be created", szDirname);
                   1455:                                                MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
                   1456:                                                return 1;
                   1457:                                        }
                   1458: 
                   1459:                                }
                   1460:                        }
                   1461: 
                   1462:                        strcpy (dlg_file_name, szDirname);
                   1463: 
                   1464:                        if (bUninstall == FALSE)
                   1465:                                _beginthread (DoInstall, 16384, (void *) hwndDlg);
                   1466:                        else
                   1467:                                _beginthread (DoUninstall, 16384, (void *) hwndDlg);
                   1468: 
                   1469:                        return 1;
                   1470:                }
                   1471: 
                   1472:                if (lw == IDCANCEL)
                   1473:                {
                   1474:                        EndDialog (hwndDlg, IDCANCEL);
                   1475:                        return 1;
                   1476:                }
                   1477: 
                   1478:                if (lw == IDC_BROWSE)
                   1479:                {
                   1480:                        char szDirname[TC_MAX_PATH];
                   1481: 
                   1482:                        GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
                   1483: 
                   1484:                        if (BrowseFiles2 (hwndDlg, "Please select a folder", szDirname) == TRUE)
                   1485:                                SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname);
                   1486:                        
                   1487:                        return 1;
                   1488:                }
                   1489: 
                   1490:                if (lw == IDC_DESTINATION && HIWORD (wParam) == EN_CHANGE && bDone == FALSE)
                   1491:                {
                   1492:                        if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_DESTINATION)) <= 0)
                   1493:                                EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
                   1494:                        else
                   1495:                                EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
                   1496:                        return 1;
                   1497:                }
                   1498: 
                   1499:                return 0;
                   1500: 
                   1501:        case WM_CLOSE:
                   1502:                EndDialog (hwndDlg, IDCANCEL);
                   1503:                return 1;
                   1504:        }
                   1505: 
                   1506:        return 0;
                   1507: }
                   1508: 
                   1509: 
                   1510: int WINAPI
                   1511: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
                   1512:         int nCmdShow)
                   1513: {
                   1514:        if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
                   1515: 
                   1516:        lpszTitle = "TrueCrypt Setup";
                   1517: 
                   1518:        /* Call InitApp to initialize the common code */
                   1519:        InitApp (hInstance);
                   1520: 
1.1.1.2   root     1521:        if (CurrentOSMajor < 5)
                   1522:        {
                   1523:                MessageBox (NULL, "TrueCrypt requires at least Windows 2000 to run.", lpszTitle, MB_ICONSTOP);
                   1524:                return 0;
                   1525:        }
                   1526: 
1.1       root     1527:        if (nCurrentOS == WIN_NT && IsAdmin ()!= TRUE)
                   1528:                if (MessageBox (NULL, "To successfully install/uninstall TrueCrypt under Windows NT you must be running as an Administrator, "
                   1529:                                "do you still want to continue?", lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
                   1530:                        return 0;
                   1531: 
                   1532:        if (lpszCommandLine[0] == '/' && (lpszCommandLine[1] == 'u' || lpszCommandLine[1] == 'U'))
                   1533:        {
                   1534:                bUninstall = TRUE;
                   1535:        }
                   1536: 
                   1537:        if (bUninstall == FALSE)
                   1538:        {
1.1.1.4 ! root     1539:                if (CurrentOSMajor == 5 && CurrentOSMinor == 0)
        !          1540:                        MessageBox (NULL, "If you are upgrading from a previous version of TrueCrypt\nyou should first uninstall TrueCrypt and reboot system.", lpszTitle, MB_ICONINFORMATION);
        !          1541: 
1.1       root     1542:                /* Create the main dialog box */
                   1543:                DialogBox (hInstance, MAKEINTRESOURCE (IDD_INSTALL), NULL, (DLGPROC) InstallDlgProc);
                   1544:        }
                   1545:        else
                   1546:        {
                   1547:                /* Create the main dialog box */
                   1548:                DialogBox (hInstance, MAKEINTRESOURCE (IDD_UNINSTALL), NULL, (DLGPROC) InstallDlgProc);
                   1549:        }
                   1550: 
                   1551:        /* Terminate */
                   1552:        return 0;
                   1553: }

unix.superglobalmegacorp.com

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