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

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

unix.superglobalmegacorp.com

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