Annotation of truecrypt/common/dlgcode.c, revision 1.1.1.6

1.1.1.3   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
1.1.1.6 ! root        3:    additions to that source code contained in this file are Copyright (c) 2004-2005
1.1.1.5   root        4:    TrueCrypt Foundation and Copyright (c) 2004 TrueCrypt Team. Unmodified
1.1.1.3   root        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: 
                     10: #include <stdlib.h>
1.1.1.5   root       11: #include <time.h>
                     12: #include <shlobj.h>
                     13: #include <dbt.h>
1.1       root       14: 
                     15: #include "resource.h"
                     16: #include "crypto.h"
                     17: #include "apidrvr.h"
                     18: #include "dlgcode.h"
1.1.1.5   root       19: #include "volumes.h"
                     20: 
1.1       root       21: char szHelpFile[TC_MAX_PATH];
                     22: HFONT hSmallFont = NULL;
                     23: HFONT hBoldFont = NULL;
                     24: HFONT hSmallBoldFont = NULL;
                     25: HFONT hTitleFont = NULL;
                     26: HFONT hFixedFont = NULL;
                     27: 
                     28: HFONT hUserFont = NULL;
                     29: HFONT hUserUnderlineFont = NULL;
                     30: HFONT hUserBoldFont = NULL;
1.1.1.5   root       31: HFONT hUserUnderlineBoldFont = NULL;
1.1       root       32: 
                     33: char *lpszTitle = NULL;
                     34: int nCurrentOS = 0;
                     35: int CurrentOSMajor = 0;
                     36: int CurrentOSMinor = 0;
                     37: 
                     38: /* Handle to the device driver */
                     39: HANDLE hDriver = INVALID_HANDLE_VALUE;
                     40: HINSTANCE hInst = NULL;
                     41: HANDLE hMutex = NULL;
                     42: HCURSOR hCursor = NULL;
                     43: 
                     44: ATOM hDlgClass, hSplashClass;
                     45: 
                     46: /* Windows dialog class */
                     47: #define WINDOWS_DIALOG_CLASS "#32770"
                     48: 
                     49: /* Custom class names */
                     50: #define TC_DLG_CLASS "CustomDlg"
                     51: #define TC_SPLASH_CLASS "SplashDlg"
                     52: 
1.1.1.5   root       53: /* Benchmark */
                     54: #ifndef SETUP
                     55: #define BENCHMARK_MAX_ITEMS 100
                     56: #define BENCHMARK_DEFAULT_BUF_SIZE (1*BYTES_PER_MB)
                     57: 
                     58: enum 
                     59: {
                     60:        BENCHMARK_SORT_BY_NAME = 0,
                     61:        BENCHMARK_SORT_BY_SPEED
                     62: };
                     63: 
                     64: typedef struct 
                     65: {
                     66:        int id;
                     67:        char name[100];
                     68:        unsigned __int64 encSpeed;
                     69:        unsigned __int64 decSpeed;
                     70:        unsigned __int64 meanBytesPerSec;
                     71: } BENCHMARK_REC;
                     72: 
                     73: BENCHMARK_REC benchmarkTable [BENCHMARK_MAX_ITEMS];
                     74: int benchmarkTotalItems = 0;
                     75: int benchmarkBufferSize = BENCHMARK_DEFAULT_BUF_SIZE;
                     76: int benchmarkLastBufferSize = BENCHMARK_DEFAULT_BUF_SIZE;
                     77: int benchmarkSortMethod = BENCHMARK_SORT_BY_SPEED;
                     78: LARGE_INTEGER benchmarkPerformanceFrequency;
                     79: #endif // #ifndef SETUP
                     80: 
                     81: 
1.1       root       82: void
                     83: cleanup ()
                     84: {
                     85:        /* Cleanup the GDI fonts */
                     86:        if (hFixedFont != NULL)
                     87:                DeleteObject (hFixedFont);
                     88:        if (hSmallFont != NULL)
                     89:                DeleteObject (hSmallFont);
                     90:        if (hBoldFont != NULL)
                     91:                DeleteObject (hBoldFont);
                     92:        if (hSmallBoldFont != NULL)
                     93:                DeleteObject (hSmallBoldFont);
                     94:        if (hTitleFont != NULL)
                     95:                DeleteObject (hTitleFont);
                     96:        if (hUserFont != NULL)
                     97:                DeleteObject (hUserFont);
                     98:        if (hUserUnderlineFont != NULL)
                     99:                DeleteObject (hUserUnderlineFont);
                    100:        if (hUserBoldFont != NULL)
                    101:                DeleteObject (hUserBoldFont);
1.1.1.5   root      102:        if (hUserUnderlineBoldFont != NULL)
                    103:                DeleteObject (hUserUnderlineBoldFont);
1.1       root      104:        /* Cleanup our dialog class */
                    105:        if (hDlgClass)
                    106:                UnregisterClass (TC_DLG_CLASS, hInst);
                    107:        if (hSplashClass)
                    108:                UnregisterClass (TC_SPLASH_CLASS, hInst);
                    109:        /* Close the device driver handle */
                    110:        if (hDriver != INVALID_HANDLE_VALUE)
                    111:        {
                    112:                CloseHandle (hDriver);
                    113:        }
                    114: 
                    115:        if (hMutex != NULL)
                    116:        {
                    117:                CloseHandle (hMutex);
                    118:        }
                    119: }
                    120: 
                    121: void
                    122: LowerCaseCopy (char *lpszDest, char *lpszSource)
                    123: {
                    124:        int i = strlen (lpszSource);
                    125: 
                    126:        lpszDest[i] = 0;
                    127:        while (--i >= 0)
                    128:        {
                    129:                lpszDest[i] = (char) tolower (lpszSource[i]);
                    130:        }
                    131: 
                    132: }
                    133: 
                    134: void
                    135: UpperCaseCopy (char *lpszDest, char *lpszSource)
                    136: {
                    137:        int i = strlen (lpszSource);
                    138: 
                    139:        lpszDest[i] = 0;
                    140:        while (--i >= 0)
                    141:        {
                    142:                lpszDest[i] = (char) toupper (lpszSource[i]);
                    143:        }
                    144: }
                    145: 
                    146: void
                    147: CreateFullVolumePath (char *lpszDiskFile, char *lpszFileName, BOOL * bDevice)
                    148: {
                    149:        if (strcmp (lpszFileName, "Floppy (A:)") == 0)
                    150:                strcpy (lpszFileName, "\\Device\\Floppy0");
                    151:        else if (strcmp (lpszFileName, "Floppy (B:)") == 0)
                    152:                strcpy (lpszFileName, "\\Device\\Floppy1");
                    153: 
                    154:        UpperCaseCopy (lpszDiskFile, lpszFileName);
                    155: 
                    156:        *bDevice = FALSE;
                    157: 
                    158:        if (memcmp (lpszDiskFile, "\\DEVICE", sizeof (char) * 7) == 0)
                    159:        {
                    160:                *bDevice = TRUE;
                    161:        }
                    162: 
                    163:        strcpy (lpszDiskFile, lpszFileName);
                    164: 
                    165: #if _DEBUG
                    166:        OutputDebugString ("CreateFullVolumePath: ");
                    167:        OutputDebugString (lpszDiskFile);
                    168:        OutputDebugString ("\n");
                    169: #endif
                    170: 
                    171: }
                    172: 
                    173: int
                    174: FakeDosNameForDevice (char *lpszDiskFile, char *lpszDosDevice, char *lpszCFDevice, BOOL bNameOnly)
                    175: {
                    176:        BOOL bDosLinkCreated = TRUE;
                    177:        sprintf (lpszDosDevice, "truecrypt%lu", GetCurrentProcessId ());
                    178: 
                    179:        if (bNameOnly == FALSE)
                    180:                bDosLinkCreated = DefineDosDevice (DDD_RAW_TARGET_PATH, lpszDosDevice, lpszDiskFile);
                    181: 
                    182:        if (bDosLinkCreated == FALSE)
                    183:        {
                    184:                return ERR_OS_ERROR;
                    185:        }
                    186:        else
                    187:                sprintf (lpszCFDevice, "\\\\.\\%s", lpszDosDevice);
                    188: 
                    189:        return 0;
                    190: }
                    191: 
                    192: int
                    193: RemoveFakeDosName (char *lpszDiskFile, char *lpszDosDevice)
                    194: {
                    195:        BOOL bDosLinkRemoved = DefineDosDevice (DDD_RAW_TARGET_PATH | DDD_EXACT_MATCH_ON_REMOVE |
                    196:                        DDD_REMOVE_DEFINITION, lpszDosDevice, lpszDiskFile);
                    197:        if (bDosLinkRemoved == FALSE)
                    198:        {
                    199:                return ERR_OS_ERROR;
                    200:        }
                    201: 
                    202:        return 0;
                    203: }
                    204: 
                    205: char *
                    206: getstr (UINT nID)
                    207: {
                    208:        static char szMsg[256];
                    209:        if (LoadString (hInst, nID, szMsg, sizeof (szMsg)) == 0)
                    210:                return "";
                    211:        else
                    212:                return szMsg;
                    213: }
                    214: 
                    215: char *
                    216: getmultilinestr (UINT nID[4])
                    217: {
                    218:        static char szMsg[1024];
                    219:        if (nID[0])
                    220:                strcpy (szMsg, getstr (nID[0]));
                    221:        if (nID[1])
                    222:                strcat (szMsg, getstr (nID[1]));
                    223:        if (nID[2])
                    224:                strcat (szMsg, getstr (nID[2]));
                    225:        if (nID[3])
                    226:                strcat (szMsg, getstr (nID[3]));
                    227:        return szMsg;
                    228: 
                    229: }
                    230: 
                    231: void
                    232: AbortProcess (UINT nID)
                    233: {
                    234:        MessageBeep (MB_ICONEXCLAMATION);
                    235:        MessageBox (NULL, getstr (nID), lpszTitle, ICON_HAND);
                    236:        exit (1);
                    237: }
                    238: 
1.1.1.5   root      239: void
                    240: AbortProcessSilent (void)
                    241: {
                    242:        exit (1);
                    243: }
                    244: 
1.1       root      245: void *
                    246: err_malloc (size_t size)
                    247: {
                    248:        void *z = (void *) TCalloc (size);
                    249:        if (z)
                    250:                return z;
                    251:        AbortProcess (IDS_OUTOFMEMORY);
                    252:        return 0;
                    253: }
                    254: 
                    255: char *
                    256: err_strdup (char *lpszText)
                    257: {
                    258:        int j = (strlen (lpszText) + 1) * sizeof (char);
                    259:        char *z = (char *) err_malloc (j);
                    260:        memmove (z, lpszText, j);
                    261:        return z;
                    262: }
                    263: 
1.1.1.5   root      264: DWORD
1.1       root      265: handleWin32Error (HWND hwndDlg)
                    266: {
                    267:        LPVOID lpMsgBuf;
                    268:        DWORD dwError = GetLastError ();
                    269: 
                    270:        FormatMessage (
                    271:                FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                    272:                              NULL,
                    273:                              dwError,
                    274:                              MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),       /* Default language */
                    275:                              (char *) &lpMsgBuf,
                    276:                              0,
                    277:                              NULL
                    278:            );
                    279: 
                    280:        MessageBox (hwndDlg, lpMsgBuf, lpszTitle, ICON_HAND);
                    281:        LocalFree (lpMsgBuf);
1.1.1.5   root      282: 
                    283:        return dwError;
1.1       root      284: }
                    285: 
                    286: BOOL
                    287: translateWin32Error (char *lpszMsgBuf, int nSizeOfBuf)
                    288: {
                    289:        DWORD dwError = GetLastError ();
                    290: 
                    291:        if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
                    292:                           MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),  /* Default language */
                    293:                           lpszMsgBuf, nSizeOfBuf, NULL))
                    294:                return TRUE;
                    295:        else
                    296:                return FALSE;
                    297: }
                    298: 
                    299: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
                    300:    should return nonzero if it processes the message, and zero if it does
                    301:    not. - see DialogProc */
                    302: BOOL WINAPI
                    303: AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                    304: {
                    305:        WORD lw = LOWORD (wParam);
                    306:        if (lParam);            /* remove warning */
                    307: 
                    308:        switch (msg)
                    309:        {
                    310: 
                    311:        case WM_INITDIALOG:
                    312:                {
                    313:                        char szTmp[32];
1.1.1.5   root      314:                        char credits[5000];
1.1       root      315: 
                    316:                        SetDefaultUserFont (hwndDlg);
                    317: 
1.1.1.5   root      318:                        SendMessage (GetDlgItem (hwndDlg, IDC_HOMEPAGE), WM_SETFONT, (WPARAM) hUserUnderlineFont, 0);
                    319:                        SendMessage (GetDlgItem (hwndDlg, IDC_FORUMS), WM_SETFONT, (WPARAM) hUserUnderlineFont, 0);
                    320: 
                    321:                        // Version
                    322:                        SendMessage (GetDlgItem (hwndDlg, IDT_ABOUT_VERSION), WM_SETFONT, (WPARAM) hUserBoldFont, 0);
1.1       root      323:                        sprintf (szTmp, "TrueCrypt %s", VERSION_STRING);
                    324:                        SetDlgItemText (hwndDlg, IDT_ABOUT_VERSION, szTmp);
1.1.1.5   root      325: 
                    326:                        // Credits
                    327:                        SendMessage (GetDlgItem (hwndDlg, IDC_ABOUT_CREDITS), WM_SETFONT, (WPARAM) hUserFont, (LPARAM) 0);
                    328:                        sprintf (credits,"\
                    329: Based on E4M by Paul Le Roux.\r\n\
                    330: Portions of this software are based in part on the works of the following people: \
                    331: Bruce Schneier, \
                    332: Horst Feistel, Don Coppersmith, \
                    333: Whitfield Diffie, Martin Hellman, Walt Tuchmann, \
                    334: Joan Daemen, Vincent Rijmen, \
                    335: Lars Knudsen, Ross Anderson, Eli Biham, \
                    336: David Wagner, John Kelsey, Niels Ferguson, Doug Whiting, Chris Hall, \
                    337: Carlisle Adams, Stafford Tavares, \
                    338: Hans Dobbertin, Antoon Bosselaers, Bart Preneel, \
                    339: Peter Gutmann, and many others.\r\n\r\n\
                    340: Portions of this software:\r\n\
1.1.1.6 ! root      341: Copyright \xA9 2004-2005 TrueCrypt Foundation. All Rights Reserved.\r\n\
1.1.1.5   root      342: Copyright \xA9 1998-2000 Paul Le Roux. All Rights Reserved.\r\n\
                    343: Copyright \xA9 2004 TrueCrypt Team. All Rights Reserved.\r\n\
                    344: Copyright \xA9 1995-1997 Eric Young. All Rights Reserved.\r\n\
                    345: Copyright \xA9 1999-2004 Dr. Brian Gladman. All Rights Reserved.\r\n\
                    346: Copyright \xA9 2001 Markus Friedl. All Rights Reserved.\r\n\
                    347: Copyright \xA9 2000 Dag Arne Osvik. All Rights Reserved.\r\n\r\n\
                    348: A TrueCrypt Foundation Release");
                    349:                        SetWindowText (GetDlgItem (hwndDlg, IDC_ABOUT_CREDITS), credits);
                    350: 
1.1       root      351:                        return 1;
                    352:                }
                    353: 
                    354:        case WM_COMMAND:
                    355:                if (lw == IDOK || lw == IDCANCEL)
                    356:                {
                    357:                        EndDialog (hwndDlg, 0);
                    358:                        return 1;
                    359:                }
                    360: 
1.1.1.5   root      361:                if (lw == IDC_HOMEPAGE)
                    362:                {
                    363:                        char tmpstr [256];
                    364: 
                    365:                        ArrowWaitCursor ();
                    366:                        sprintf (tmpstr, "http://truecrypt.sourceforge.net/applink.php?version=%s", VERSION_STRING);
                    367:                        ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
                    368:                        Sleep (200);
                    369:                        NormalCursor ();
                    370:                        return 1;
                    371:                }
                    372: 
                    373:                if (lw == IDC_FORUMS)
                    374:                {
                    375:                        char tmpstr [256];
                    376: 
                    377:                        ArrowWaitCursor ();
                    378:                        sprintf (tmpstr, "http://truecrypt.sourceforge.net/applink.php?version=%s&dest=forum", VERSION_STRING);
                    379:                        ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
                    380:                        Sleep (200);
                    381:                        NormalCursor ();
                    382:                        return 1;
                    383:                }
                    384: 
                    385:                // Disallow modification of credits
                    386:                if (HIWORD (wParam) == EN_UPDATE)
                    387:                {
                    388:                        SendMessage (hwndDlg, WM_INITDIALOG, 0, 0);
                    389:                        return 1;
                    390:                }
                    391: 
1.1       root      392:                return 0;
                    393: 
                    394:        case WM_CLOSE:
                    395:                EndDialog (hwndDlg, 0);
                    396:                return 1;
                    397:        }
                    398: 
                    399:        return 0;
                    400: }
                    401: 
                    402: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
                    403:    should return nonzero if it processes the message, and zero if it does
                    404:    not. - see DialogProc */
                    405: BOOL WINAPI
                    406: WarningDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                    407: {
                    408:        WORD lw = LOWORD (wParam);
                    409:        if (lParam);            /* remove warning */
                    410: 
                    411:        switch (msg)
                    412:        {
                    413:        case WM_INITDIALOG:
                    414:                SetDefaultUserFont (hwndDlg);
                    415:                SetWindowText (GetDlgItem (hwndDlg, IDC_WARNING_TEXT), (char*) lParam);
                    416:                return 1;
                    417:        case WM_COMMAND:
                    418:                if (lw == IDOK || lw == IDCANCEL)
                    419:                {
                    420:                        BOOL x = IsButtonChecked (GetDlgItem (hwndDlg, IDC_NEVER_SHOW));
                    421:                        if (x == TRUE)
                    422:                                EndDialog (hwndDlg, IDOK);
                    423:                        else
                    424:                                EndDialog (hwndDlg, IDCANCEL);
                    425:                        return 1;
                    426:                }
                    427:                return 0;
                    428:        case WM_CLOSE:
                    429:                EndDialog (hwndDlg, 0);
                    430:                return 1;
                    431:        }
                    432: 
                    433:        return 0;
                    434: }
                    435: 
                    436: BOOL
                    437: IsButtonChecked (HWND hButton)
                    438: {
                    439:        if (SendMessage (hButton, BM_GETCHECK, 0, 0) == BST_CHECKED)
                    440:                return TRUE;
                    441:        else
                    442:                return FALSE;
                    443: }
                    444: 
                    445: void
                    446: CheckButton (HWND hButton)
                    447: {
                    448:        SendMessage (hButton, BM_SETCHECK, BST_CHECKED, 0);
                    449: }
                    450: 
                    451: 
                    452: /*****************************************************************************
                    453:   ToSBCS: converts a unicode string to Single Byte Character String (SBCS).
                    454:   ***************************************************************************/
                    455: 
                    456: void
                    457: ToSBCS (LPWSTR lpszText)
                    458: {
                    459:        int j = wcslen (lpszText);
                    460:        if (j == 0)
                    461:        {
                    462:                strcpy ((char *) lpszText, "");
                    463:                return;
                    464:        }
                    465:        else
                    466:        {
                    467:                char *lpszNewText = (char *) err_malloc (j + 1);
                    468:                j = WideCharToMultiByte (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1, NULL, NULL);
                    469:                if (j > 0)
                    470:                        strcpy ((char *) lpszText, lpszNewText);
                    471:                else
                    472:                        strcpy ((char *) lpszText, "");
                    473:                free (lpszNewText);
                    474:        }
                    475: }
                    476: 
                    477: /*****************************************************************************
                    478:   ToUNICODE: converts a SBCS string to a UNICODE string.
                    479:   ***************************************************************************/
                    480: 
                    481: void
                    482: ToUNICODE (char *lpszText)
                    483: {
                    484:        int j = strlen (lpszText);
                    485:        if (j == 0)
                    486:        {
                    487:                wcscpy ((LPWSTR) lpszText, (LPWSTR) WIDE (""));
                    488:                return;
                    489:        }
                    490:        else
                    491:        {
                    492:                LPWSTR lpszNewText = (LPWSTR) err_malloc ((j + 1) * 2);
                    493:                j = MultiByteToWideChar (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1);
                    494:                if (j > 0)
                    495:                        wcscpy ((LPWSTR) lpszText, lpszNewText);
                    496:                else
                    497:                        wcscpy ((LPWSTR) lpszText, (LPWSTR) "");
                    498:                free (lpszNewText);
                    499:        }
                    500: }
                    501: 
                    502: /* InitDialog - initialize the applications main dialog, this function should
                    503:    be called only once in the dialogs WM_INITDIALOG message handler */
                    504: void
                    505: InitDialog (HWND hwndDlg)
                    506: {
                    507:        HDC hDC;
                    508:        int nHeight;
                    509:        LOGFONT lf;
                    510:        HMENU hMenu;
                    511: 
                    512:        hDC = GetDC (hwndDlg);
                    513: 
                    514:        nHeight = -((8 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    515:        lf.lfHeight = nHeight;
                    516:        lf.lfWidth = 0;
                    517:        lf.lfEscapement = 0;
                    518:        lf.lfOrientation = 0;
                    519:        lf.lfWeight = FW_LIGHT;
                    520:        lf.lfItalic = FALSE;
                    521:        lf.lfUnderline = FALSE;
                    522:        lf.lfStrikeOut = FALSE;
                    523:        lf.lfCharSet = DEFAULT_CHARSET;
                    524:        lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
                    525:        lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
                    526:        lf.lfQuality = PROOF_QUALITY;
                    527:        lf.lfPitchAndFamily = FF_DONTCARE;
                    528:        strcpy (lf.lfFaceName, "Courier");
                    529:        hSmallFont = CreateFontIndirect (&lf);
                    530:        if (hSmallFont == NULL)
                    531:        {
                    532:                handleWin32Error (hwndDlg);
                    533:                AbortProcess (IDS_NOFONT);
                    534:        }
                    535: 
                    536:        nHeight = -((10 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    537:        lf.lfHeight = nHeight;
                    538:        lf.lfWeight = FW_BLACK;
                    539:        strcpy (lf.lfFaceName, "Arial");
                    540:        hSmallBoldFont = CreateFontIndirect (&lf);
                    541:        if (hSmallBoldFont == NULL)
                    542:        {
                    543:                handleWin32Error (hwndDlg);
                    544:                AbortProcess (IDS_NOFONT);
                    545:        }
                    546: 
                    547:        nHeight = -((16 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    548:        lf.lfHeight = nHeight;
                    549:        lf.lfWeight = FW_BOLD;
                    550:        strcpy (lf.lfFaceName, "Times");
                    551:        hBoldFont = CreateFontIndirect (&lf);
                    552:        if (hBoldFont == NULL)
                    553:        {
                    554:                handleWin32Error (hwndDlg);
                    555:                AbortProcess (IDS_NOFONT);
                    556:        }
                    557: 
                    558:        nHeight = -((16 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    559:        lf.lfHeight = nHeight;
                    560:        lf.lfWeight = FW_REGULAR;
                    561:        hTitleFont = CreateFontIndirect (&lf);
                    562:        if (hTitleFont == NULL)
                    563:        {
                    564:                handleWin32Error (hwndDlg);
                    565:                AbortProcess (IDS_NOFONT);
                    566:        }
                    567: 
                    568:        nHeight = -((9 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    569:        lf.lfHeight = nHeight;
                    570:        lf.lfWidth = 0;
                    571:        lf.lfEscapement = 0;
                    572:        lf.lfOrientation = 0;
                    573:        lf.lfWeight = FW_NORMAL;
                    574:        lf.lfItalic = FALSE;
                    575:        lf.lfUnderline = FALSE;
                    576:        lf.lfStrikeOut = FALSE;
                    577:        lf.lfCharSet = DEFAULT_CHARSET;
                    578:        lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
                    579:        lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
                    580:        lf.lfQuality = PROOF_QUALITY;
                    581:        lf.lfPitchAndFamily = FF_DONTCARE;
                    582:        strcpy (lf.lfFaceName, "Lucida Console");
                    583:        hFixedFont = CreateFontIndirect (&lf);
                    584:        if (hFixedFont == NULL)
                    585:        {
                    586:                handleWin32Error (hwndDlg);
                    587:                AbortProcess (IDS_NOFONT);
                    588:        }
                    589: 
                    590:        hMenu = GetSystemMenu (hwndDlg, FALSE);
                    591:        AppendMenu (hMenu, MF_SEPARATOR, 0, NULL);
                    592:        AppendMenu (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, getstr (IDS_ABOUTBOX));
1.1.1.5   root      593: 
                    594:        SetDefaultUserFont(hwndDlg);
1.1       root      595: }
                    596: 
                    597: HDC
                    598: CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, char *resource)
                    599: {
                    600:        HBITMAP picture = LoadBitmap (hInstance, resource);
                    601:        HDC viewDC = GetDC (hwnd), dcMem;
                    602: 
                    603:        dcMem = CreateCompatibleDC (viewDC);
                    604: 
                    605:        SetMapMode (dcMem, MM_TEXT);
                    606: 
                    607:        SelectObject (dcMem, picture);
                    608: 
                    609:        ReleaseDC (hwnd, viewDC);
                    610: 
                    611:        return dcMem;
                    612: }
                    613: 
                    614: /* Draw the specified bitmap at the specified location - Stretch to fit. */
                    615: void
                    616: PaintBitmap (HDC pdcMem, int x, int y, int nWidth, int nHeight, HDC hDC)
                    617: {
                    618:        HGDIOBJ picture = GetCurrentObject (pdcMem, OBJ_BITMAP);
                    619: 
                    620:        BITMAP bitmap;
                    621:        GetObject (picture, sizeof (BITMAP), &bitmap);
                    622: 
                    623:        BitBlt (hDC, x, y, nWidth, nHeight, pdcMem, 0, 0, SRCCOPY);
                    624: }
                    625: 
                    626: LRESULT CALLBACK
                    627: SplashDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                    628: {
                    629: 
                    630:        //if (uMsg == WM_ERASEBKGND)
                    631:        //{
                    632:        //      NONCLIENTMETRICS metric;
                    633:        //      HFONT font;
                    634: 
                    635: 
                    636:        //      HDC hDC = (HDC) wParam;
                    637:        //      char szTmp[64];
                    638:        //      HGDIOBJ obj;
                    639:        //      WORD bx = LOWORD (GetDialogBaseUnits ());
                    640:        //      WORD by = HIWORD (GetDialogBaseUnits ());
                    641: 
                    642: 
                    643:        //      DefDlgProc (hwnd, uMsg, wParam, lParam);
                    644: 
                    645:        //      SetBkMode (hDC, TRANSPARENT);
                    646:        //      SetTextColor (hDC, RGB (0, 0, 100));
                    647:        //      obj = SelectObject (hDC, hTitleFont);
                    648: 
                    649:        //      metric.cbSize = sizeof (NONCLIENTMETRICS);
                    650:        //      SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &metric, 0);
                    651:        //      font = CreateFontIndirect (&metric.lfMessageFont);
                    652:        //      obj = SelectObject (hDC, font);
                    653: 
                    654:        //      TextOut (hDC, (12 * bx) / 4, (70 * by) / 8, szTmp, strlen (szTmp));
                    655: 
                    656:        //      SelectObject (hDC, obj);
                    657:        //      return TRUE;
                    658:        //}
                    659: 
                    660:        return DefDlgProc (hwnd, uMsg, wParam, lParam);
                    661: }
                    662: 
                    663: void
                    664: WaitCursor ()
                    665: {
                    666:        static HCURSOR hcWait;
                    667:        if (hcWait == NULL)
                    668:                hcWait = LoadCursor (NULL, IDC_WAIT);
                    669:        SetCursor (hcWait);
                    670:        hCursor = hcWait;
                    671: }
                    672: 
                    673: void
                    674: NormalCursor ()
                    675: {
                    676:        static HCURSOR hcArrow;
                    677:        if (hcArrow == NULL)
                    678:                hcArrow = LoadCursor (NULL, IDC_ARROW);
                    679:        SetCursor (hcArrow);
                    680:        hCursor = NULL;
                    681: }
                    682: 
                    683: void
                    684: ArrowWaitCursor ()
                    685: {
                    686:        static HCURSOR hcArrowWait;
                    687:        if (hcArrowWait == NULL)
                    688:                hcArrowWait = LoadCursor (NULL, IDC_APPSTARTING);
                    689:        SetCursor (hcArrowWait);
                    690:        hCursor = hcArrowWait;
                    691: }
                    692: 
                    693: LRESULT CALLBACK
                    694: CustomDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                    695: {
                    696:        if (uMsg == WM_SETCURSOR && hCursor != NULL)
                    697:        {
                    698:                SetCursor (hCursor);
                    699:                return TRUE;
                    700:        }
                    701: 
                    702:        return DefDlgProc (hwnd, uMsg, wParam, lParam);
                    703: }
                    704: 
                    705: /* InitApp - initialize the application, this function is called once in the
                    706:    applications WinMain function, but before the main dialog has been created */
                    707: void
                    708: InitApp (HINSTANCE hInstance)
                    709: {
                    710:        WNDCLASS wc;
                    711:        char *lpszTmp;
                    712:        OSVERSIONINFO os;
                    713: 
                    714:        /* Save the instance handle for later */
                    715:        hInst = hInstance;
                    716: 
                    717:        /* Pull down the windows version */
                    718:        os.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
                    719:        if (GetVersionEx (&os) == FALSE)
                    720:                AbortProcess (IDS_NO_OS_VER);
                    721:        else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)
                    722:                nCurrentOS = WIN_NT;
                    723:        else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 0)
                    724:                nCurrentOS = WIN_95;
                    725:        else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 10)
                    726:                nCurrentOS = WIN_98;
                    727:        else {
                    728:        /*      AbortProcess (IDS_NO_OS_VER); */
                    729:                nCurrentOS = WIN_98;
                    730:        }
                    731: 
                    732:        CurrentOSMajor = os.dwMajorVersion;
                    733:        CurrentOSMinor = os.dwMinorVersion;
1.1.1.6 ! root      734:        
        !           735:        // OS version check
        !           736:        if (CurrentOSMajor < 5)
        !           737:        {
        !           738:                MessageBox (NULL, "TrueCrypt requires at least Windows 2000 operating system to run.", lpszTitle, MB_ICONSTOP);
        !           739:                exit (1);
        !           740:        }
1.1       root      741: 
                    742:        /* Get the attributes for the standard dialog class */
                    743:        if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0)
                    744:                AbortProcess (IDS_INIT_REGISTER);
                    745: 
                    746: #ifndef SETUP
                    747:        wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON));
                    748: #else
                    749: #include "../setup/resource.h"
                    750:        wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_SETUP));
                    751: #endif
                    752:        wc.lpszClassName = TC_DLG_CLASS;
                    753:        wc.lpfnWndProc = &CustomDlgProc;
                    754:        wc.hCursor = LoadCursor (NULL, IDC_ARROW);
                    755:        wc.cbWndExtra = DLGWINDOWEXTRA;
                    756: 
                    757:        hDlgClass = RegisterClass (&wc);
                    758:        if (hDlgClass == 0)
                    759:                AbortProcess (IDS_INIT_REGISTER);
                    760: 
                    761:        wc.lpszClassName = TC_SPLASH_CLASS;
                    762:        wc.lpfnWndProc = &SplashDlgProc;
                    763:        wc.hCursor = LoadCursor (NULL, IDC_ARROW);
                    764:        wc.cbWndExtra = DLGWINDOWEXTRA;
                    765: 
                    766:        hSplashClass = RegisterClass (&wc);
                    767:        if (hSplashClass == 0)
                    768:                AbortProcess (IDS_INIT_REGISTER);
                    769: 
                    770:        GetModuleFileName (NULL, szHelpFile, sizeof (szHelpFile));
                    771:        lpszTmp = strrchr (szHelpFile, '\\');
                    772:        if (lpszTmp)
                    773:        {
                    774:                strcpy (++lpszTmp, "TrueCrypt User Guide.pdf");
                    775:        }
                    776: 
1.1.1.6 ! root      777: #ifndef VOLFORMAT
1.1       root      778:        hMutex = CreateMutex (NULL, TRUE, lpszTitle);
                    779:        if (hMutex == NULL)
                    780:        {
                    781:                handleWin32Error (NULL);
                    782:                AbortProcess (IDS_INIT_MUTEX);
                    783:        }
                    784: 
                    785:        if (GetLastError ()== ERROR_ALREADY_EXISTS)
                    786:        {
                    787:                // If executed twice, just top the first instance and exit
                    788:                HWND h = FindWindow (0, lpszTitle);
                    789:                if (h != 0)
                    790:                {
                    791:                        ShowWindow (h, SW_SHOWNORMAL);
                    792:                        SetForegroundWindow (h);
                    793:                        exit (1);
                    794:                }
                    795:                else
                    796:                        AbortProcess (IDS_TWO_INSTANCES);
                    797:        }
1.1.1.6 ! root      798: #endif
1.1       root      799: }
                    800: 
                    801: 
                    802: BOOL
                    803: OpenDevice (char *lpszPath, OPEN_TEST_STRUCT * driver)
                    804: {
                    805:        DWORD dwResult;
                    806:        BOOL bResult;
                    807: 
                    808:        strcpy ((char *) &driver->wszFileName[0], lpszPath);
                    809: 
                    810:        if (nCurrentOS == WIN_NT)
                    811:                ToUNICODE ((char *) &driver->wszFileName[0]);
                    812: 
                    813:        bResult = DeviceIoControl (hDriver, OPEN_TEST,
                    814:                                   driver, sizeof (OPEN_TEST_STRUCT),
                    815:                                   &driver, sizeof (OPEN_TEST_STRUCT),
                    816:                                   &dwResult, NULL);
                    817: 
                    818:        if (bResult == FALSE)
                    819:        {
                    820:                dwResult = GetLastError ();
                    821:                if (dwResult == ERROR_SHARING_VIOLATION)
                    822:                        return TRUE;
                    823:                else
                    824:                        return FALSE;
                    825:        }
                    826:        else
                    827:        {
                    828:                if (nCurrentOS == WIN_NT)
                    829:                        return TRUE;
                    830:                else if (driver->nReturnCode == 0)
                    831:                        return TRUE;
                    832:                else
                    833:                {
                    834:                        SetLastError (ERROR_FILE_NOT_FOUND);
                    835:                        return FALSE;
                    836:                }
                    837:        }
                    838: }
                    839: 
                    840: UINT _stdcall
                    841: win9x_io (HFILE hFile, char *lpBuffer, UINT uBytes)
                    842: {
                    843:        DISKIO_STRUCT *win9x_r0 = (DISKIO_STRUCT *) hFile;
                    844:        DWORD dwResult;
                    845:        BOOL bResult;
                    846:        LONG secs;
                    847: 
                    848:        win9x_r0->bufferad = (void *) lpBuffer;
                    849: 
                    850:        secs = uBytes / SECTOR_SIZE;
                    851: 
                    852:        win9x_r0->sectorlen = secs;
                    853: 
                    854:        bResult = DeviceIoControl (hDriver, DISKIO, win9x_r0, sizeof (DISKIO_STRUCT), win9x_r0,
                    855:                                   sizeof (DISKIO_STRUCT), &dwResult, NULL);
                    856: 
                    857:        if (bResult == FALSE || win9x_r0->nReturnCode != 0)
                    858:                return (UINT) HFILE_ERROR;
                    859: 
                    860:        win9x_r0->sectorstart += secs;
                    861: 
                    862:        return uBytes;
                    863: }
                    864: 
                    865: int
                    866: GetAvailableFixedDisks (HWND hComboBox, char *lpszRootPath)
                    867: {
                    868:        int i, n;
                    869:        int line = 0;
1.1.1.5   root      870:        LVITEM LvItem;
1.1.1.6 ! root      871:        __int64 deviceSize = 0;
1.1       root      872: 
                    873:        for (i = 0; i < 64; i++)
                    874:        {
                    875:                BOOL drivePresent = FALSE;
1.1.1.6 ! root      876:                BOOL removable = FALSE;
1.1       root      877: 
1.1.1.5   root      878:                for (n = 0; n <= 32; n++)
1.1       root      879:                {
                    880:                        char szTmp[TC_MAX_PATH], item1[100]={0}, item2[100]={0};
                    881:                        OPEN_TEST_STRUCT driver;
                    882: 
                    883:                        sprintf (szTmp, lpszRootPath, i, n);
                    884:                        if (OpenDevice (szTmp, &driver) == TRUE)
                    885:                        {
                    886:                                int nDosLinkCreated;
                    887:                                HANDLE dev;
                    888:                                DWORD dwResult;
                    889:                                BOOL bResult;
                    890:                                PARTITION_INFORMATION diskInfo;
1.1.1.6 ! root      891:                                DISK_GEOMETRY driveInfo;
1.1       root      892:                                char szDosDevice[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
                    893: 
                    894:                                drivePresent = TRUE;
                    895: 
                    896:                                if (nCurrentOS == WIN_NT)
                    897:                                {
                    898:                                        nDosLinkCreated = FakeDosNameForDevice (szTmp, szDosDevice,
                    899:                                                szCFDevice, FALSE);
                    900: 
1.1.1.5   root      901:                                        dev = CreateFile (szCFDevice, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
1.1       root      902: 
                    903:                                        bResult = DeviceIoControl (dev, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0,
                    904:                                                &diskInfo, sizeof (diskInfo), &dwResult, NULL);
                    905: 
1.1.1.6 ! root      906:                                        // Test if device is removable
        !           907:                                        if (n == 0 && DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
        !           908:                                                &driveInfo, sizeof (driveInfo), &dwResult, NULL))
        !           909:                                                removable = driveInfo.MediaType == RemovableMedia;
        !           910: 
1.1       root      911:                                        RemoveFakeDosName(szTmp, szDosDevice);
                    912:                                        CloseHandle(dev);
                    913: 
                    914:                                        if (bResult == TRUE)
                    915:                                        {
                    916:                                                char partType[100];
                    917: 
1.1.1.6 ! root      918:                                                // System creates a virtual partition1 for some storage devices without
        !           919:                                                // partition table. We try to detect this case by comparing sizes of
        !           920:                                                // partition0 and partition1. If they match, no partition of the device
        !           921:                                                // is displayed to the user to avoid confusion. Drive letter assigned by
        !           922:                                                // system to partition1 is displayed as subitem of partition0
        !           923: 
        !           924:                                                if (n == 1 && diskInfo.PartitionLength.QuadPart == deviceSize)
        !           925:                                                {
        !           926:                                                        char drive[] = { 0, ':', 0 };
        !           927:                                                        char device[MAX_PATH * 2];
        !           928:                                                        int driveNo;
        !           929: 
        !           930:                                                        // Drive letter
        !           931:                                                        strcpy (device, szTmp);
        !           932:                                                        ToUNICODE (device);
        !           933:                                                        driveNo = GetDiskDeviceDriveLetter ((PWSTR) device);
        !           934:                                                        drive[0] = driveNo == -1 ? 0 : 'A' + driveNo;
        !           935: 
        !           936:                                                        LvItem.iSubItem = 1;
        !           937:                                                        LvItem.pszText = drive;
        !           938:                                                        SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
        !           939: 
        !           940:                                                        break;
        !           941:                                                }
        !           942: 
1.1       root      943:                                                switch(diskInfo.PartitionType)
                    944:                                                {
1.1.1.5   root      945:                                                case PARTITION_ENTRY_UNUSED:    strcpy(partType, "Empty/unused"); break;
                    946:                                                case PARTITION_XINT13_EXTENDED:
1.1       root      947:                                                case PARTITION_EXTENDED:                strcpy(partType, "Extended"); break;
1.1.1.5   root      948:                                                case PARTITION_HUGE:                    sprintf(partType, "Unformatted (0x%02X)", diskInfo.PartitionType); break;
1.1       root      949:                                                case PARTITION_FAT_12:                  strcpy(partType, "FAT12"); break;
                    950:                                                case PARTITION_FAT_16:                  strcpy(partType, "FAT16"); break;
                    951:                                                case PARTITION_FAT32:           
                    952:                                                case PARTITION_FAT32_XINT13:    strcpy(partType, "FAT32"); break;
1.1.1.5   root      953:                                                case 0x08:                                              strcpy(partType, "DELL (spanning)"); break;
                    954:                                                case 0x12:                                              strcpy(partType, "Config/diagnostics"); break;
1.1       root      955:                                                case 0x11:
                    956:                                                case 0x14:
                    957:                                                case 0x16:
                    958:                                                case 0x1b:
                    959:                                                case 0x1c:
                    960:                                                case 0x1e:                                              strcpy(partType, "Hidden FAT"); break;
                    961:                                                case PARTITION_IFS:                             strcpy(partType, "NTFS"); break;
                    962:                                                case 0x17:                                              strcpy(partType, "Hidden NTFS"); break;
1.1.1.5   root      963:                                                case 0x3c:                                              strcpy(partType, "PMagic recovery"); break;
                    964:                                                case 0x3d:                                              strcpy(partType, "Hidden NetWare"); break;
                    965:                                                case 0x41:                                              strcpy(partType, "Linux/MINIX"); break;
                    966:                                                case 0x42:                                              strcpy(partType, "SFS/LDM/Linux Swap"); break;
                    967:                                                case 0x51:
                    968:                                                case 0x64:
                    969:                                                case 0x65:
                    970:                                                case 0x66:
                    971:                                                case 0x67:
                    972:                                                case 0x68:
                    973:                                                case 0x69:                                              strcpy(partType, "Novell"); break;
                    974:                                                case 0x55:                                              strcpy(partType, "EZ-Drive"); break;
                    975:                                                case PARTITION_OS2BOOTMGR:              strcpy(partType, "OS/2 BM"); break;
                    976:                                                case PARTITION_XENIX_1:
                    977:                                                case PARTITION_XENIX_2:                 strcpy(partType, "Xenix"); break;
1.1       root      978:                                                case PARTITION_UNIX:                    strcpy(partType, "UNIX"); break;
1.1.1.5   root      979:                                                case 0x74:                                              strcpy(partType, "Scramdisk"); break;
                    980:                                                case 0x78:                                              strcpy(partType, "XOSL FS"); break;
                    981:                                                case 0x80:
                    982:                                                case 0x81:                                              strcpy(partType, "MINIX"); break;
1.1       root      983:                                                case 0x82:                                              strcpy(partType, "Linux Swap"); break;
1.1.1.5   root      984:                                                case 0x43:
                    985:                                                case 0x83:                                              strcpy(partType, "Linux"); break;
                    986:                                                case 0xc2:
                    987:                                                case 0x93:                                              strcpy(partType, "Hidden Linux"); break;
                    988:                                                case 0x86:
                    989:                                                case 0x87:                                              strcpy(partType, "NTFS volume set"); break;
                    990:                                                case 0x9f:                                              strcpy(partType, "BSD/OS"); break;
                    991:                                                case 0xa0:
                    992:                                                case 0xa1:                                              strcpy(partType, "Hibernation"); break;
                    993:                                                case 0xa5:                                              strcpy(partType, "BSD"); break;
                    994:                                                case 0xa8:                                              strcpy(partType, "Mac OS-X"); break;
                    995:                                                case 0xa9:                                              strcpy(partType, "NetBSD"); break;
                    996:                                                case 0xab:                                              strcpy(partType, "Mac OS-X Boot"); break;
                    997:                                                case 0xb8:                                              strcpy(partType, "BSDI BSD/386 swap"); break;
                    998:                                                case 0xc3:                                              strcpy(partType, "Hidden Linux swap"); break;
                    999:                                                case 0xfb:                                              strcpy(partType, "VMware"); break;
                   1000:                                                case 0xfc:                                              strcpy(partType, "VMware swap"); break;
                   1001:                                                case 0xfd:                                              strcpy(partType, "Linux RAID"); break;
                   1002:                                                case 0xfe:                                              strcpy(partType, "WinNT hidden"); break;
                   1003:                                                default:                                                sprintf(partType, "0x%02X", diskInfo.PartitionType); break;
1.1       root     1004:                                                }
                   1005: 
1.1.1.5   root     1006:                                                if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*1024*1024*99)
                   1007:                                                        sprintf (item1,"%d PB", diskInfo.PartitionLength.QuadPart/1024/1024/1024/1024/1024);
                   1008:                                                else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*1024*1024)
                   1009:                                                        sprintf (item1,"%.1f PB",(double)(diskInfo.PartitionLength.QuadPart/1024.0/1024/1024/1024/1024));
                   1010:                                                else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*1024*99)
                   1011:                                                        sprintf (item1,"%d TB",diskInfo.PartitionLength.QuadPart/1024.0/1024/1024/1024);
                   1012:                                                else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*1024)
                   1013:                                                        sprintf (item1,"%.1f TB",(double)(diskInfo.PartitionLength.QuadPart/1024.0/1024/1024/1024));
                   1014:                                                else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*99)
                   1015:                                                        sprintf (item1,"%d GB",diskInfo.PartitionLength.QuadPart/1024/1024/1024);
                   1016:                                                else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024)
1.1       root     1017:                                                        sprintf (item1,"%.1f GB",(double)(diskInfo.PartitionLength.QuadPart/1024.0/1024/1024));
                   1018:                                                else
                   1019:                                                        sprintf (item1,"%d MB", diskInfo.PartitionLength.QuadPart/1024/1024);
                   1020: 
                   1021:                                                strcpy (item2, partType);
                   1022:                                        }
                   1023:                                }
                   1024: 
1.1.1.5   root     1025:                                if (n == 0)
1.1.1.6 ! root     1026:                                {
        !          1027:                                        deviceSize = diskInfo.PartitionLength.QuadPart;
1.1.1.5   root     1028:                                        sprintf (szTmp, "Harddisk %d:", i);
1.1.1.6 ! root     1029:                                }
1.1.1.5   root     1030: 
                   1031:                                memset (&LvItem,0,sizeof(LvItem));
                   1032:                                LvItem.mask = LVIF_TEXT;   
                   1033:                                LvItem.iItem = line++;   
                   1034: 
                   1035:                                // Device Name
                   1036:                                LvItem.pszText = szTmp;
                   1037:                                SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
                   1038: 
                   1039:                                // Size
                   1040:                                LvItem.iSubItem = 2;
                   1041:                                LvItem.pszText = item1;
                   1042:                                SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem); 
                   1043: 
1.1.1.6 ! root     1044:                                // Device type removable
        !          1045:                                if (n == 0 && removable)
        !          1046:                                {
        !          1047:                                        LvItem.iSubItem = 3;
        !          1048:                                        LvItem.pszText = "Removable";
        !          1049:                                        SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
        !          1050:                                }
        !          1051: 
1.1.1.5   root     1052:                                if (n > 0)
                   1053:                                {
                   1054:                                        char drive[] = { 0, ':', 0 };
                   1055:                                        char device[MAX_PATH * 2];
                   1056:                                        int driveNo;
                   1057: 
                   1058:                                        // Drive letter
                   1059:                                        strcpy (device, szTmp);
                   1060:                                        ToUNICODE (device);
                   1061:                                        driveNo = GetDiskDeviceDriveLetter ((PWSTR) device);
                   1062:                                        drive[0] = driveNo == -1 ? 0 : 'A' + driveNo;
                   1063: 
                   1064:                                        LvItem.iSubItem = 1;
                   1065:                                        LvItem.pszText = drive;
                   1066:                                        SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
                   1067: 
                   1068:                                        // Partition type
                   1069:                                        LvItem.iSubItem = 3;
                   1070:                                        LvItem.pszText = item2;
                   1071:                                        SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
                   1072:                                }
1.1       root     1073: 
1.1.1.6 ! root     1074:                                // Mark device with partitions, removable drives are not marked to allow
        !          1075:                                // users silent overwrite of existing partitions as system does not
        !          1076:                                // support partition management of removable drives
        !          1077: 
        !          1078:                                if (n == 1 && !removable)
1.1.1.5   root     1079:                                {
                   1080:                                        LvItem.iItem = line - 2;
                   1081:                                        LvItem.iSubItem = 3;
                   1082:                                        LvItem.pszText = " ";
                   1083:                                        SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
                   1084:                                }
                   1085:                        }
1.1.1.6 ! root     1086:                        else if (n == 0)
        !          1087:                                break;
1.1.1.2   root     1088:                }
                   1089: 
1.1.1.5   root     1090:                if (drivePresent)
1.1.1.2   root     1091:                {
1.1.1.5   root     1092:                        memset (&LvItem,0,sizeof(LvItem));
                   1093:                        LvItem.mask = LVIF_TEXT;   
                   1094:                        LvItem.iItem = line++;   
1.1.1.2   root     1095: 
1.1.1.5   root     1096:                        LvItem.pszText = "";
                   1097:                        SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
1.1       root     1098:                }
                   1099:        }
                   1100: 
                   1101:        i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0);
                   1102:        if (i != CB_ERR)
                   1103:                return i;
                   1104:        else
                   1105:                return 0;
                   1106: }
                   1107: 
                   1108: int
                   1109: GetAvailableRemovables (HWND hComboBox, char *lpszRootPath)
                   1110: {
                   1111:        char szTmp[TC_MAX_PATH];
                   1112:        int i;
                   1113:        LVITEM LvItem;
                   1114: 
                   1115:        if (lpszRootPath);      /* Remove unused parameter warning */
                   1116: 
                   1117:        if (nCurrentOS != WIN_NT)
                   1118:                return 0;
                   1119: 
1.1.1.5   root     1120:        memset (&LvItem,0,sizeof(LvItem));
1.1       root     1121:        LvItem.mask = LVIF_TEXT;   
                   1122:        LvItem.iItem = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0)+1;   
                   1123: 
                   1124:        if (QueryDosDevice ("A:", szTmp, sizeof (szTmp)) != 0)
                   1125:        {
1.1.1.5   root     1126:                LvItem.pszText = "\\Device\\Floppy0";
                   1127:                LvItem.iItem = SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
                   1128: 
                   1129:                LvItem.iSubItem = 1;
                   1130:                LvItem.pszText = "A:";
                   1131:                SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
                   1132: 
1.1       root     1133:        }
                   1134:        if (QueryDosDevice ("B:", szTmp, sizeof (szTmp)) != 0)
                   1135:        {
1.1.1.5   root     1136:                LvItem.pszText = "\\Device\\Floppy1";
                   1137:                LvItem.iSubItem = 0;
                   1138:                LvItem.iItem = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0)+1;   
                   1139:                LvItem.iItem = SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
                   1140: 
                   1141:                LvItem.iSubItem = 1;
                   1142:                LvItem.pszText = "B:";
                   1143:                SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
1.1       root     1144:        }
                   1145: 
                   1146:        i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0);
                   1147:        if (i != CB_ERR)
                   1148:                return i;
                   1149:        else
                   1150:                return 0;
                   1151: }
                   1152: 
                   1153: BOOL WINAPI
                   1154: RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                   1155: {
                   1156:        static char *lpszFileName;
                   1157:        WORD lw = LOWORD (wParam);
                   1158: 
                   1159:        if (lParam);            /* remove warning */
                   1160: 
                   1161:        switch (msg)
                   1162:        {
                   1163:        case WM_INITDIALOG:
                   1164:                {
                   1165:                        int nCount;
                   1166:                        LVCOLUMN LvCol;
                   1167:                        HWND hList = GetDlgItem (hwndDlg, IDC_DEVICELIST);
                   1168: 
                   1169:                        SetDefaultUserFont (hwndDlg);
                   1170: 
1.1.1.5   root     1171:                        SendMessage (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
1.1       root     1172:                                LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_TWOCLICKACTIVATE 
                   1173:                                ); 
                   1174: 
1.1.1.5   root     1175:                        memset (&LvCol,0,sizeof(LvCol));               
1.1       root     1176:                        LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;  
                   1177:                        LvCol.pszText = "Device";                           
1.1.1.5   root     1178:                        LvCol.cx =154;
                   1179:                        LvCol.fmt = LVCFMT_LEFT;
                   1180:                        SendMessage (hList,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol);
                   1181: 
                   1182:                        LvCol.pszText = "Drive";  
                   1183:                        LvCol.cx = 38;           
1.1       root     1184:                        LvCol.fmt = LVCFMT_LEFT;
1.1.1.5   root     1185:                        SendMessage (hList,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol);
1.1       root     1186: 
                   1187:                        LvCol.pszText = "Size";  
1.1.1.5   root     1188:                        LvCol.cx = 62;           
1.1       root     1189:                        LvCol.fmt = LVCFMT_RIGHT;
1.1.1.5   root     1190:                        SendMessage (hList,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol);
1.1       root     1191: 
                   1192:                        LvCol.pszText = "Type";  
1.1.1.5   root     1193:                        LvCol.cx = 112;
1.1       root     1194:                        LvCol.fmt = LVCFMT_LEFT;
1.1.1.5   root     1195:                        SendMessage (hList,LVM_INSERTCOLUMN,3,(LPARAM)&LvCol);
1.1       root     1196: 
                   1197:                        nCount = GetAvailableFixedDisks (hList, "\\Device\\Harddisk%d\\Partition%d");
                   1198:                        nCount += GetAvailableRemovables (hList, "\\Device\\Floppy%d");
                   1199: 
                   1200:                        if (nCount == 0)
                   1201:                        {
                   1202:                                handleWin32Error (hwndDlg);
                   1203:                                MessageBox (hwndDlg, getstr (IDS_RAWDEVICES), lpszTitle, ICON_HAND);
                   1204:                                EndDialog (hwndDlg, IDCANCEL);
                   1205:                        }
                   1206: 
                   1207:                        lpszFileName = (char *) lParam;
                   1208:                        return 1;
                   1209:                }
                   1210: 
                   1211:        case WM_COMMAND:
                   1212:        case WM_NOTIFY:
                   1213:                // catch non-device line selected
                   1214:                if (msg == WM_NOTIFY && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
                   1215:                {
                   1216:                        LVITEM LvItem;
                   1217:                        memset(&LvItem,0,sizeof(LvItem));
                   1218:                        LvItem.mask = LVIF_TEXT;   
                   1219:                        LvItem.iItem = ((LPNMLISTVIEW) lParam)->iItem;
                   1220:                        LvItem.pszText = lpszFileName;
                   1221:                        LvItem.cchTextMax = TC_MAX_PATH;
                   1222: 
                   1223:                        SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
                   1224:                        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), lpszFileName[0] != 0 && lpszFileName[0] != ' ');
                   1225:                        return 1;
                   1226:                }
                   1227: 
                   1228:                if (msg == WM_COMMAND && lw == IDOK || msg == WM_NOTIFY && ((NMHDR *)lParam)->code == LVN_ITEMACTIVATE)
                   1229:                {
                   1230:                        LVITEM LvItem;
1.1.1.5   root     1231:                        memset (&LvItem,0,sizeof(LvItem));
1.1       root     1232:                        LvItem.mask = LVIF_TEXT;   
                   1233:                        LvItem.iItem =  SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETSELECTIONMARK, 0, 0);
                   1234:                        LvItem.pszText = lpszFileName;
                   1235:                        LvItem.cchTextMax = TC_MAX_PATH;
                   1236: 
                   1237:                        SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
                   1238: 
1.1.1.5   root     1239:                        if (lpszFileName[0] == 'H')
                   1240:                        {
                   1241:                                // Whole device selected
                   1242:                                int driveNo;
                   1243:                                char tmp[10];
                   1244: 
                   1245:                                sscanf (lpszFileName, "Harddisk %d", &driveNo);
                   1246:                                sprintf (lpszFileName, "\\Device\\Harddisk%d\\Partition0", driveNo);
                   1247: 
                   1248: #ifdef VOLFORMAT
                   1249:                                // Warn if device contains partitions
                   1250:                                LvItem.iSubItem = 3;
                   1251:                                LvItem.pszText = tmp;
                   1252:                                SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
                   1253:                                if (tmp[0] == ' ')
                   1254:                                {
1.1.1.6 ! root     1255:                                        if (IDNO == MessageBox (hwndDlg, getstr (IDS_DEVICE_PARTITIONS_WARN),
        !          1256:                                                lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2))
        !          1257:                                                break;
1.1.1.5   root     1258:                                }
                   1259: #endif
                   1260:                        }
                   1261: 
                   1262:                        if (lpszFileName[0] == 0)
1.1       root     1263:                                break; // non-device line selected
                   1264: 
                   1265:                        EndDialog (hwndDlg, IDOK);
                   1266:                        return 0;
                   1267:                }
                   1268: 
                   1269:                if (lw == IDCANCEL)
                   1270:                {
                   1271:                        EndDialog (hwndDlg, IDCANCEL);
                   1272:                        return 0;
                   1273:                }
                   1274:                return 0;
                   1275:        }
                   1276: 
                   1277:        return 0;
                   1278: }
                   1279: 
1.1.1.6 ! root     1280: 
        !          1281: // Install and start driver service and mark it for removal (non-install mode)
        !          1282: static int DriverLoad ()
        !          1283: {
        !          1284:        HANDLE file;
        !          1285:        WIN32_FIND_DATA find;
        !          1286:        SC_HANDLE hManager, hService = NULL;
        !          1287:        char driverPath[TC_MAX_PATH*2];
        !          1288:        BOOL res;
        !          1289:        char *tmp;
        !          1290:        
        !          1291:        if (!IsAdmin ())
        !          1292:        {
        !          1293:                MessageBox (0, getstr (IDS_ADMIN_PRIVILEGES_DRIVER), lpszTitle, ICON_HAND);
        !          1294:                return ERR_DONT_REPORT;
        !          1295:        }
        !          1296: 
        !          1297:        GetModuleFileName (NULL, driverPath, sizeof (driverPath));
        !          1298:        tmp = strrchr (driverPath, '\\');
        !          1299:        if (!tmp)
        !          1300:        {
        !          1301:                strcpy (driverPath, ".");
        !          1302:                tmp = driverPath + 1;
        !          1303:        }
        !          1304: 
        !          1305:        strcpy (tmp, "\\truecrypt.sys");
        !          1306: 
        !          1307:        file = FindFirstFile (driverPath, &find);
        !          1308: 
        !          1309:        if (file == INVALID_HANDLE_VALUE)
        !          1310:        {
        !          1311:                MessageBox (0, getstr (IDS_DRIVER_NOT_FOUND), lpszTitle, ICON_HAND);
        !          1312:                return ERR_DONT_REPORT;
        !          1313:        }
        !          1314: 
        !          1315:        FindClose (file);
        !          1316: 
        !          1317:        hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
        !          1318:        if (hManager == NULL)
        !          1319:                return ERR_OS_ERROR;
        !          1320: 
        !          1321:        hService = CreateService (hManager, "truecrypt", "truecrypt",
        !          1322:                SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
        !          1323:                driverPath, NULL, NULL, NULL, NULL, NULL);
        !          1324: 
        !          1325:        if (hService == NULL)
        !          1326:        {
        !          1327:                CloseServiceHandle (hManager);
        !          1328:                return ERR_OS_ERROR;
        !          1329:        }
        !          1330: 
        !          1331:        res = StartService (hService, 0, NULL);
        !          1332: 
        !          1333:        DeleteService (hService);
        !          1334:        CloseServiceHandle (hManager);
        !          1335:        CloseServiceHandle (hService);
        !          1336: 
        !          1337:        return !res ? ERR_OS_ERROR : ERROR_SUCCESS;
        !          1338: }
        !          1339: 
        !          1340: 
1.1       root     1341: int
                   1342: DriverAttach (void)
                   1343: {
1.1.1.6 ! root     1344:        /* Try to open a handle to the device driver. It will be closed later. */
1.1       root     1345: 
1.1.1.6 ! root     1346:        hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
1.1       root     1347: 
                   1348:        if (hDriver == INVALID_HANDLE_VALUE)
                   1349:        {
1.1.1.6 ! root     1350: #ifndef SETUP
        !          1351:                // Attempt to load driver (non-install mode)
        !          1352:                BOOL res = DriverLoad ();
        !          1353: 
        !          1354:                if (res != ERROR_SUCCESS)
        !          1355:                        return res;
        !          1356: 
        !          1357:                hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
        !          1358: #endif
        !          1359:                if (hDriver == INVALID_HANDLE_VALUE)
        !          1360:                        return ERR_OS_ERROR;
1.1       root     1361:        }
                   1362: #ifndef SETUP // Don't check version during setup to allow removal of older version
                   1363:        else
                   1364:        {
                   1365:                LONG driver = 0;
                   1366:                DWORD dwResult;
                   1367: 
                   1368:                BOOL bResult = DeviceIoControl (hDriver, DRIVER_VERSION,
                   1369:                                   &driver, 4, &driver, 4, &dwResult, NULL);
                   1370: 
                   1371:                if (bResult == FALSE)
                   1372:                        return ERR_OS_ERROR;
                   1373:                else if (driver != VERSION_NUM)
                   1374:                        return ERR_DRIVER_VERSION;
                   1375:        }
                   1376: #endif
                   1377: 
                   1378:        return 0;
                   1379: }
                   1380: 
1.1.1.5   root     1381: 
                   1382: // Sets file pointer to hidden volume header
                   1383: BOOL SeekHiddenVolHeader (HFILE dev, unsigned __int64 volSize, BOOL deviceFlag)
                   1384: {
                   1385:        LARGE_INTEGER offset, offsetNew;
                   1386: 
                   1387:        if (deviceFlag)
                   1388:        {
                   1389:                // Partition/device
                   1390: 
                   1391:                offset.QuadPart = volSize - HIDDEN_VOL_HEADER_OFFSET;
                   1392: 
                   1393:                if (SetFilePointerEx ((HANDLE) dev, offset, &offsetNew, FILE_BEGIN) == 0)
                   1394:                        return FALSE;
                   1395: 
                   1396:                if (offsetNew.QuadPart != offset.QuadPart)
                   1397:                        return FALSE;
                   1398:        }
                   1399:        else
                   1400:        {
                   1401:                // File-hosted volume
                   1402: 
                   1403:                offset.QuadPart = - HIDDEN_VOL_HEADER_OFFSET;
                   1404: 
                   1405:                if (SetFilePointerEx ((HANDLE) dev, offset, &offsetNew, FILE_END) == 0)
                   1406:                        return FALSE;
                   1407:        }
                   1408: 
                   1409:        return TRUE;
                   1410: }
                   1411: 
                   1412: 
1.1       root     1413: BOOL
1.1.1.5   root     1414: BrowseFiles (HWND hwndDlg, UINT nTitleID, char *lpszFileName, BOOL keepHistory)
1.1       root     1415: {
                   1416:        OPENFILENAME ofn;
                   1417:        char szFileTitle[TC_MAX_PATH];
                   1418:        ZeroMemory (&ofn, sizeof (OPENFILENAME));
                   1419: 
                   1420:        *szFileTitle = *lpszFileName = 0;
                   1421:        ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; //sizeof (OPENFILENAME);
                   1422:        ofn.hwndOwner = hwndDlg;
                   1423:        ofn.lpstrFilter = "All Files (*.*)\0*.*\0TrueCrypt Volumes (*.tc)\0*.tc\0";
                   1424:        ofn.lpstrCustomFilter = NULL;
                   1425:        ofn.nFilterIndex = 1;
                   1426:        ofn.lpstrFile = lpszFileName;
                   1427:        ofn.nMaxFile = TC_MAX_PATH;
                   1428:        ofn.lpstrFileTitle = szFileTitle;
                   1429:        ofn.nMaxFileTitle = TC_MAX_PATH;
                   1430:        ofn.lpstrInitialDir = NULL;
                   1431:        ofn.lpstrTitle = getstr (nTitleID);
1.1.1.5   root     1432:        ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | (keepHistory ? 0 : OFN_DONTADDTORECENT);
1.1       root     1433:        //ofn.lpstrDefExt = "tc";
                   1434: 
                   1435:        if (!GetOpenFileName (&ofn))
                   1436:                return FALSE;
                   1437:        else
                   1438:                return TRUE;
                   1439: }
                   1440: 
                   1441: 
1.1.1.6 ! root     1442: BOOL
        !          1443: BrowseDirectories (HWND hWnd, UINT nTitleID, char *dirName)
        !          1444: {
        !          1445:        BROWSEINFO bi;
        !          1446:        LPITEMIDLIST pidl;
        !          1447: 
        !          1448:        ZeroMemory (&bi, sizeof (bi));
        !          1449:        bi.hwndOwner = hWnd;
        !          1450:        bi.lpszTitle = getstr (nTitleID);
        !          1451: 
        !          1452:        pidl = SHBrowseForFolder (&bi);
        !          1453: 
        !          1454:        if (pidl != 0)
        !          1455:        {
        !          1456:                SHGetPathFromIDList (pidl, dirName);
        !          1457:                GlobalFree (pidl);
        !          1458: 
        !          1459:                return TRUE;
        !          1460:        }
        !          1461: 
        !          1462:        return FALSE;
        !          1463: }
        !          1464: 
        !          1465: 
1.1       root     1466: void
                   1467: handleError (HWND hwndDlg, int code)
                   1468: {
                   1469:        char szTmp[512];
                   1470: 
                   1471:        switch (code)
                   1472:        {
                   1473:        case ERR_OS_ERROR:
                   1474:                handleWin32Error (hwndDlg);
                   1475:                break;
                   1476:        case ERR_OUTOFMEMORY:
                   1477:                MessageBox (hwndDlg, getstr (IDS_OUTOFMEMORY), lpszTitle, ICON_HAND);
                   1478:                break;
                   1479:        case ERR_PASSWORD_WRONG:
1.1.1.5   root     1480:                MessageBox (hwndDlg, getstr (CheckCapsLock (NULL, TRUE) ? IDS_PASSWORD_WRONG_CAPSLOCK_ON : IDS_PASSWORD_WRONG), lpszTitle, MB_ICONEXCLAMATION);
1.1       root     1481:                break;
                   1482:        case ERR_VOL_FORMAT_BAD:
                   1483:                MessageBox (hwndDlg, getstr (IDS_VOL_FORMAT_BAD), lpszTitle, ICON_HAND);
                   1484:                break;
                   1485:        case ERR_BAD_DRIVE_LETTER:
                   1486:                MessageBox (hwndDlg, getstr (IDS_BAD_DRIVE_LETTER), lpszTitle, ICON_HAND);
                   1487:                break;
                   1488:        case ERR_DRIVE_NOT_FOUND:
                   1489:                MessageBox (hwndDlg, getstr (IDS_NOT_FOUND), lpszTitle, ICON_HAND);
                   1490:                break;
                   1491:        case ERR_FILES_OPEN:
                   1492:                MessageBox (hwndDlg, getstr (IDS_OPENFILES_DRIVER), lpszTitle, ICON_HAND);
                   1493:                break;
                   1494:        case ERR_FILES_OPEN_LOCK:
                   1495:                MessageBox (hwndDlg, getstr (IDS_OPENFILES_LOCK), lpszTitle, ICON_HAND);
                   1496:                break;
                   1497:        case ERR_VOL_SIZE_WRONG:
                   1498:                MessageBox (hwndDlg, getstr (IDS_VOL_SIZE_WRONG), lpszTitle, ICON_HAND);
                   1499:                break;
                   1500:        case ERR_COMPRESSION_NOT_SUPPORTED:
                   1501:                MessageBox (hwndDlg, getstr (IDS_COMPRESSION_NOT_SUPPORTED), lpszTitle, ICON_HAND);
                   1502:                break;
                   1503:        case ERR_PASSWORD_CHANGE_VOL_TYPE:
                   1504:                MessageBox (hwndDlg, getstr (IDS_WRONG_VOL_TYPE), lpszTitle, ICON_HAND);
                   1505:                break;
                   1506:        case ERR_PASSWORD_CHANGE_VOL_VERSION:
                   1507:                MessageBox (hwndDlg, getstr (IDS_WRONG_VOL_VERSION), lpszTitle, ICON_HAND);
                   1508:                break;
                   1509:        case ERR_VOL_SEEKING:
                   1510:                MessageBox (hwndDlg, getstr (IDS_VOL_SEEKING), lpszTitle, ICON_HAND);
                   1511:                break;
                   1512:        case ERR_VOL_WRITING:
                   1513:                MessageBox (hwndDlg, getstr (IDS_VOL_WRITING), lpszTitle, ICON_HAND);
                   1514:                break;
                   1515:        case ERR_VOL_READING:
                   1516:                MessageBox (hwndDlg, getstr (IDS_VOL_READING), lpszTitle, ICON_HAND);
                   1517:                break;
                   1518:        case ERR_VOL_ALREADY_MOUNTED:
                   1519:                MessageBox (hwndDlg, getstr (IDS_VOL_ALREADY_MOUNTED), lpszTitle, ICON_HAND);
                   1520:                break;
                   1521:        case ERR_FILE_OPEN_FAILED:
                   1522:                MessageBox (hwndDlg, getstr (IDS_FILE_OPEN_FAILED), lpszTitle, ICON_HAND);
                   1523:                break;
                   1524:        case ERR_VOL_MOUNT_FAILED:
1.1.1.5   root     1525:                MessageBox (hwndDlg, getstr (CheckCapsLock (NULL, TRUE) ? IDS_VOL_MOUNT_FAILED_CAPSLOCK_ON : IDS_VOL_MOUNT_FAILED), lpszTitle, MB_ICONEXCLAMATION);
1.1       root     1526:                break;
                   1527:        case ERR_NO_FREE_SLOTS:
                   1528:                MessageBox (hwndDlg, getstr (IDS_NO_FREE_SLOTS), lpszTitle, ICON_HAND);
                   1529:                break;
                   1530:        case ERR_NO_FREE_DRIVES:
                   1531:                MessageBox (hwndDlg, getstr (IDS_NO_FREE_DRIVES), lpszTitle, ICON_HAND);
                   1532:                break;
                   1533:        case ERR_INVALID_DEVICE:
                   1534:                MessageBox (hwndDlg, getstr (IDS_INVALID_DEVICE), lpszTitle, ICON_HAND);
                   1535:                break;
                   1536:        case ERR_ACCESS_DENIED:
                   1537:                MessageBox (hwndDlg, getstr (IDS_ACCESS_DENIED), lpszTitle, ICON_HAND);
                   1538:                break;
                   1539: 
                   1540:        case ERR_DRIVER_VERSION:
                   1541:                sprintf (szTmp, getstr (IDS_DRIVER_VERSION), VERSION_STRING);
                   1542:                MessageBox (hwndDlg, szTmp, lpszTitle, ICON_HAND);
                   1543:                break;
                   1544: 
                   1545:        case ERR_NEW_VERSION_REQUIRED:
                   1546:                MessageBox (hwndDlg, getstr (IDS_NEW_VERSION_REQUIRED), lpszTitle, ICON_HAND);
                   1547:                break;
                   1548: 
1.1.1.6 ! root     1549:        case ERR_DONT_REPORT:
        !          1550:                break;
        !          1551: 
1.1       root     1552:        default:
                   1553:                sprintf (szTmp, getstr (IDS_UNKNOWN), code);
                   1554:                MessageBox (hwndDlg, szTmp, lpszTitle, ICON_HAND);
                   1555: 
                   1556:        }
                   1557: }
                   1558: 
                   1559: static BOOL CALLBACK SetDefaultUserFontEnum( HWND hwnd, LPARAM font)
                   1560: {
                   1561:        SendMessage (hwnd, WM_SETFONT, (WPARAM) font, 0);
                   1562:        return TRUE;
                   1563: }
                   1564: 
                   1565: void SetDefaultUserFont (HWND hwnd)
                   1566: {
                   1567:        NONCLIENTMETRICS metric;
                   1568: 
                   1569:        if (hUserFont == 0)
                   1570:        {
                   1571:                metric.cbSize = sizeof (NONCLIENTMETRICS);
                   1572:                SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &metric, 0);
                   1573: 
1.1.1.5   root     1574:                metric.lfMessageFont.lfHeight = -11;
                   1575:                metric.lfMessageFont.lfWidth = 0;
                   1576: 
1.1       root     1577:                hUserFont = CreateFontIndirect (&metric.lfMessageFont);
                   1578: 
                   1579:                metric.lfMessageFont.lfUnderline = TRUE;
                   1580:                hUserUnderlineFont = CreateFontIndirect (&metric.lfMessageFont);
                   1581: 
                   1582:                metric.lfMessageFont.lfUnderline = FALSE;
                   1583:                metric.lfMessageFont.lfWeight = FW_BOLD;
                   1584:                hUserBoldFont = CreateFontIndirect (&metric.lfMessageFont);
1.1.1.5   root     1585: 
                   1586:                metric.lfMessageFont.lfUnderline = TRUE;
                   1587:                metric.lfMessageFont.lfWeight = FW_BOLD;
                   1588:                hUserUnderlineBoldFont = CreateFontIndirect (&metric.lfMessageFont);
1.1       root     1589:        }
                   1590: 
                   1591:        EnumChildWindows (hwnd, SetDefaultUserFontEnum, (LPARAM) hUserFont);
1.1.1.5   root     1592: }
                   1593: 
                   1594: void OpenVolumeExplorerWindow (int driveNo)
                   1595: {
                   1596:        char dosName[5];
                   1597:        SHFILEINFO fInfo;
                   1598: 
                   1599:        sprintf (dosName, "%c:\\", (char) driveNo + 'A');
                   1600: 
                   1601:        // Force explorer to discover the drive
                   1602:        SHGetFileInfo (dosName, 0, &fInfo, sizeof (fInfo), 0);
                   1603: 
                   1604:        ShellExecute (NULL, "open", dosName, NULL, NULL, SW_SHOWNORMAL);
                   1605: }
                   1606: 
                   1607: static BOOL explorerCloseSent;
                   1608: 
                   1609: static BOOL CALLBACK CloseVolumeExplorerWindowsEnum( HWND hwnd, LPARAM driveNo)
                   1610: {
                   1611:        char get[128], driveStr[10];
                   1612:        HWND h;
                   1613: 
                   1614:        GetClassName (hwnd, get, sizeof get);
                   1615: 
                   1616:        if (strcmp (get, "CabinetWClass") == 0)
                   1617:        {
                   1618:                sprintf (driveStr, "%c:\\", driveNo + 'A');
                   1619: 
                   1620:                // Title bar
                   1621:                GetWindowText (hwnd, get, sizeof get);
                   1622:                if (strstr (get, driveStr) == get)
                   1623:                {
                   1624:                        PostMessage (hwnd, WM_CLOSE, 0, 0);
                   1625:                        explorerCloseSent = TRUE;
                   1626:                        return TRUE;
                   1627:                }
                   1628: 
                   1629:                // URL edit box
                   1630:                h = FindWindowEx (hwnd, 0, "WorkerW", 0);
                   1631:                if (!h) return TRUE;
                   1632:                h = FindWindowEx (h, 0, "ReBarWindow32", 0);
                   1633:                if (!h) return TRUE;
                   1634:                h = FindWindowEx (h, 0, "ComboBoxEx32", 0);
                   1635:                if (h)
                   1636:                {
                   1637:                        SendMessage (h, WM_GETTEXT, sizeof get, (LPARAM) get);
                   1638:                        if (strstr (get, driveStr) == get)
                   1639:                        {
                   1640:                                PostMessage (hwnd, WM_CLOSE, 0, 0);
                   1641:                                explorerCloseSent = TRUE;
                   1642:                        }
                   1643:                }
                   1644:        }
                   1645:        return TRUE;
                   1646: }
                   1647: 
                   1648: BOOL CloseVolumeExplorerWindows (HWND hwnd, int driveNo)
                   1649: {
                   1650:        explorerCloseSent = FALSE;
                   1651:        EnumWindows (CloseVolumeExplorerWindowsEnum, (LPARAM) driveNo);
                   1652: 
                   1653:        return explorerCloseSent;
                   1654: }
                   1655: 
                   1656: 
                   1657: #ifndef SETUP
                   1658: void GetSpeedString (unsigned __int64 speed, char *str)
                   1659: {
                   1660:        if (speed > 1024I64*1024*1024*1024*1024*99)
                   1661:                sprintf (str,"%d PB/s", speed/1024/1024/1024/1024/1024);
                   1662:        else if (speed > 1024I64*1024*1024*1024*1024)
                   1663:                sprintf (str,"%.1f PB/s",(double)(speed/1024.0/1024/1024/1024/1024));
                   1664:        else if (speed > 1024I64*1024*1024*1024*99)
                   1665:                sprintf (str,"%d TB/s",speed/1024/1024/1024/1024);
                   1666:        else if (speed > 1024I64*1024*1024*1024)
                   1667:                sprintf (str,"%.1f TB/s",(double)(speed/1024.0/1024/1024/1024));
                   1668:        else if (speed > 1024I64*1024*1024*99)
                   1669:                sprintf (str,"%d GB/s",speed/1024/1024/1024);
                   1670:        else if (speed > 1024I64*1024*1024)
                   1671:                sprintf (str,"%.1f GB/s",(double)(speed/1024.0/1024/1024));
                   1672:        else if (speed > 1024I64*1024*99)
                   1673:                sprintf (str,"%d MB/s", speed/1024/1024);
                   1674:        else if (speed > 1024I64*1024)
                   1675:                sprintf (str,"%.1f MB/s",(double)(speed/1024.0/1024));
                   1676:        else
                   1677:                sprintf (str,"%d KB/s", speed/1024);
                   1678: }
                   1679: 
                   1680: static void DisplayBenchmarkResults (HWND hwndDlg)
                   1681: {
                   1682:        BENCHMARK_REC tmp_line;
                   1683:        char item1[100]={0};
                   1684:        int line = 0;
                   1685:        LVITEM LvItem;
                   1686:        HWND hList = GetDlgItem (hwndDlg, IDC_RESULTS);
                   1687:        int ea, i;
                   1688:        BOOL unsorted = TRUE;
                   1689:        unsigned __int64 encBytesPerSec;
                   1690:        unsigned __int64 decBytesPerSec;
                   1691: 
                   1692:        /* Sort the list */
                   1693: 
                   1694:        switch (benchmarkSortMethod)
                   1695:        {
                   1696:        case BENCHMARK_SORT_BY_SPEED:
                   1697: 
                   1698:                while (unsorted)
                   1699:                {
                   1700:                        unsorted = FALSE;
                   1701:                        for (i = 0; i < benchmarkTotalItems - 1; i++)
                   1702:                        {
                   1703:                                if (benchmarkTable[i].meanBytesPerSec < benchmarkTable[i+1].meanBytesPerSec)
                   1704:                                {
                   1705:                                        unsorted = TRUE;
                   1706:                                        memcpy (&tmp_line, &benchmarkTable[i], sizeof(BENCHMARK_REC));
                   1707:                                        memcpy (&benchmarkTable[i], &benchmarkTable[i+1], sizeof(BENCHMARK_REC));
                   1708:                                        memcpy (&benchmarkTable[i+1], &tmp_line, sizeof(BENCHMARK_REC));
                   1709:                                }
                   1710:                        }
                   1711:                }
                   1712:                break;
                   1713: 
                   1714:        case BENCHMARK_SORT_BY_NAME:
                   1715: 
                   1716:                while (unsorted)
                   1717:                {
                   1718:                        unsorted = FALSE;
                   1719:                        for (i = 0; i < benchmarkTotalItems - 1; i++)
                   1720:                        {
                   1721:                                if (benchmarkTable[i].id > benchmarkTable[i+1].id)
                   1722:                                {
                   1723:                                        unsorted = TRUE;
                   1724:                                        memcpy (&tmp_line, &benchmarkTable[i], sizeof(BENCHMARK_REC));
                   1725:                                        memcpy (&benchmarkTable[i], &benchmarkTable[i+1], sizeof(BENCHMARK_REC));
                   1726:                                        memcpy (&benchmarkTable[i+1], &tmp_line, sizeof(BENCHMARK_REC));
                   1727:                                }
                   1728:                        }
                   1729:                }
                   1730:                break;
                   1731:        }
                   1732:   
                   1733:        /* Render the results */
                   1734: 
                   1735:        SendMessage (hList,LVM_DELETEALLITEMS,0,(LPARAM)&LvItem);
                   1736: 
                   1737:        for (i = 0; i < benchmarkTotalItems; i++)
                   1738:        {
                   1739:                ea = benchmarkTable[i].id;
                   1740: 
                   1741:                memset (&LvItem,0,sizeof(LvItem));
                   1742:                LvItem.mask = LVIF_TEXT;
                   1743:                LvItem.iItem = line++;
                   1744:                LvItem.iSubItem = 0;
                   1745:                LvItem.pszText = benchmarkTable[i].name;
                   1746: 
                   1747:                SendMessage (hList,LVM_INSERTITEM,0,(LPARAM)&LvItem);
                   1748: 
                   1749:                GetSpeedString((unsigned __int64) (benchmarkLastBufferSize / ((float) benchmarkTable[i].encSpeed / benchmarkPerformanceFrequency.QuadPart)), item1);
                   1750:                LvItem.iSubItem = 1;
                   1751:                LvItem.pszText = item1;
                   1752: 
                   1753:                SendMessage (hList,LVM_SETITEM,0,(LPARAM)&LvItem); 
                   1754:                GetSpeedString((unsigned __int64) (benchmarkLastBufferSize / ((float) benchmarkTable[i].decSpeed / benchmarkPerformanceFrequency.QuadPart)), item1);
                   1755:                LvItem.iSubItem = 2;
                   1756:                LvItem.pszText = item1;
                   1757: 
                   1758:                SendMessage (hList,LVM_SETITEM,0,(LPARAM)&LvItem); 
                   1759: 
                   1760:                GetSpeedString(benchmarkTable[i].meanBytesPerSec, item1);
                   1761:                LvItem.iSubItem = 3;
                   1762:                LvItem.pszText = item1;
                   1763: 
                   1764:                SendMessage (hList,LVM_SETITEM,0,(LPARAM)&LvItem); 
                   1765:        }
                   1766: }
                   1767: 
                   1768: static BOOL PerformBenchmark(HWND hwndDlg)
                   1769: {
                   1770:     LARGE_INTEGER performanceCountStart, performanceCountEnd;
                   1771:        BYTE *lpTestBuffer;
                   1772:        HWND hList = GetDlgItem (hwndDlg, IDC_RESULTS);
                   1773:        LVITEM LvItem;
                   1774:        int ea, i;
                   1775:        unsigned char iv[DISK_IV_SIZE];
                   1776:        unsigned char ks[MAX_EXPANDED_KEY];
                   1777:        unsigned char key[DISKKEY_SIZE];
                   1778: 
                   1779:        if (QueryPerformanceFrequency (&benchmarkPerformanceFrequency) == 0)
                   1780:        {
                   1781:                MessageBox (hwndDlg, "Error: Your hardware does not support a high-resolution performance counter.", lpszTitle, ICON_HAND);
                   1782:                return FALSE;
                   1783:        }
                   1784: 
                   1785:        ArrowWaitCursor ();
                   1786: 
                   1787:        lpTestBuffer = malloc(benchmarkBufferSize - (benchmarkBufferSize % 16));
                   1788:        if (lpTestBuffer == NULL)
                   1789:        {
                   1790:                NormalCursor ();
                   1791:                MessageBox (hwndDlg, "Error: Cannot allocate memory.", lpszTitle, ICON_HAND);
                   1792:                return FALSE;
                   1793:        }
                   1794:        VirtualLock (lpTestBuffer, benchmarkBufferSize - (benchmarkBufferSize % 16));
                   1795: 
                   1796:        benchmarkTotalItems = 0;
                   1797:        
                   1798:        for (ea = EAGetFirst(); ea != 0; ea = EAGetNext(ea))
                   1799:        {
                   1800:                EAInit (ea, key, ks);
                   1801:         
                   1802:                if (QueryPerformanceCounter (&performanceCountStart) == 0)
                   1803:                        goto counter_error;
                   1804: 
                   1805:                EncryptBuffer ((unsigned long *) lpTestBuffer, (unsigned __int64) benchmarkBufferSize, ks, iv, iv, ea);
                   1806: 
                   1807:                if (QueryPerformanceCounter (&performanceCountEnd) == 0)
                   1808:                        goto counter_error;
                   1809: 
                   1810:                benchmarkTable[benchmarkTotalItems].encSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart;
                   1811: 
                   1812:                if (QueryPerformanceCounter (&performanceCountStart) == 0)
                   1813:                        goto counter_error;
                   1814: 
                   1815:                DecryptBuffer ((unsigned long *) lpTestBuffer, (unsigned __int64) benchmarkBufferSize, ks, iv, iv, ea);
                   1816:                
                   1817:                if (QueryPerformanceCounter (&performanceCountEnd) == 0)
                   1818:                        goto counter_error;
                   1819: 
                   1820:                benchmarkTable[benchmarkTotalItems].decSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart;
                   1821:                benchmarkTable[benchmarkTotalItems].id = ea;
                   1822:                benchmarkTable[benchmarkTotalItems].meanBytesPerSec = ((unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].encSpeed / benchmarkPerformanceFrequency.QuadPart)) + (unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].decSpeed / benchmarkPerformanceFrequency.QuadPart))) / 2;
                   1823:                EAGetName (benchmarkTable[benchmarkTotalItems].name, ea);
                   1824: 
                   1825:                benchmarkTotalItems++;
                   1826: 
                   1827:        }
                   1828: 
                   1829:        VirtualUnlock (lpTestBuffer, benchmarkBufferSize - (benchmarkBufferSize % 16));
                   1830: 
                   1831:        free(lpTestBuffer);
                   1832: 
                   1833:        benchmarkLastBufferSize = benchmarkBufferSize;
                   1834: 
                   1835:        DisplayBenchmarkResults(hwndDlg);
                   1836: 
                   1837:        EnableWindow (GetDlgItem (hwndDlg, ID_PERFORM_BENCHMARK), TRUE);
                   1838:        EnableWindow (GetDlgItem (hwndDlg, IDCLOSE), TRUE);
                   1839: 
                   1840:        NormalCursor ();
                   1841:        return TRUE;
                   1842: 
                   1843: counter_error:
                   1844: 
                   1845:        VirtualUnlock (lpTestBuffer, benchmarkBufferSize - (benchmarkBufferSize % 16));
                   1846: 
                   1847:        free(lpTestBuffer);
                   1848: 
                   1849:        NormalCursor ();
                   1850: 
                   1851:        EnableWindow (GetDlgItem (hwndDlg, ID_PERFORM_BENCHMARK), TRUE);
                   1852:        EnableWindow (GetDlgItem (hwndDlg, IDCLOSE), TRUE);
                   1853: 
                   1854:        MessageBox (hwndDlg, "Error: Could not retrieve value of performance counter.", lpszTitle, ICON_HAND);
                   1855:        return FALSE;
                   1856: }
                   1857: 
                   1858: 
                   1859: BOOL WINAPI BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                   1860: {
                   1861:        WORD lw = LOWORD (wParam);
                   1862:        LPARAM nIndex;
                   1863:        HWND hCboxSortMethod = GetDlgItem (hwndDlg, IDC_BENCHMARK_SORT_METHOD);
                   1864:        HWND hCboxBufferSize = GetDlgItem (hwndDlg, IDC_BENCHMARK_BUFFER_SIZE);
                   1865: 
                   1866:        switch (msg)
                   1867:        {
                   1868:        case WM_INITDIALOG:
                   1869:                {
                   1870:                        LVCOLUMN LvCol;
                   1871:                        HWND hList = GetDlgItem (hwndDlg, IDC_RESULTS);
                   1872:                        char buf[100];
                   1873: 
                   1874:                        SetDefaultUserFont (hwndDlg);
                   1875: 
                   1876:                        benchmarkBufferSize = BENCHMARK_DEFAULT_BUF_SIZE;
                   1877:                        benchmarkSortMethod = BENCHMARK_SORT_BY_SPEED;
                   1878: 
                   1879:                        SendMessage (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
                   1880:                                LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_TWOCLICKACTIVATE 
                   1881:                                ); 
                   1882: 
                   1883:                        memset (&LvCol,0,sizeof(LvCol));               
                   1884:                        LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;  
                   1885:                        LvCol.pszText = "Algorithm";                           
                   1886:                        LvCol.cx =114;
                   1887:                        LvCol.fmt = LVCFMT_LEFT;
                   1888:                        SendMessage (hList,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol);
                   1889: 
                   1890:                        LvCol.pszText = "Encryption";  
                   1891:                        LvCol.cx = 80;           
                   1892:                        LvCol.fmt = LVCFMT_RIGHT;
                   1893:                        SendMessage (hList,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol);
                   1894: 
                   1895:                        LvCol.pszText = "Decryption";  
                   1896:                        LvCol.cx = 80;
                   1897:                        LvCol.fmt = LVCFMT_RIGHT;
                   1898:                        SendMessage (hList,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol);
                   1899: 
                   1900:                        LvCol.pszText = "Mean";  
                   1901:                        LvCol.cx = 80;
                   1902:                        LvCol.fmt = LVCFMT_RIGHT;
                   1903:                        SendMessage (hList,LVM_INSERTCOLUMN,3,(LPARAM)&LvCol);
                   1904: 
                   1905:                        /* Combo boxes */
                   1906: 
                   1907:                        // Sort method
                   1908: 
                   1909:                        SendMessage (hCboxSortMethod, CB_RESETCONTENT, 0, 0);
                   1910: 
                   1911:                        nIndex = SendMessage (hCboxSortMethod, CB_ADDSTRING, 0, (LPARAM) "Alphabetical/Categorized");
                   1912:                        SendMessage (hCboxSortMethod, CB_SETITEMDATA, nIndex, (LPARAM) 0);
                   1913: 
                   1914:                        nIndex = SendMessage (hCboxSortMethod, CB_ADDSTRING, 0, (LPARAM) "Mean Speed (Descending)");
                   1915:                        SendMessage (hCboxSortMethod, CB_SETITEMDATA, nIndex, (LPARAM) 0);
                   1916: 
                   1917:                        SendMessage (hCboxSortMethod, CB_SETCURSEL, 1, 0);              // Default sort method
                   1918: 
                   1919:                        // Buffer size
                   1920: 
                   1921:                        SendMessage (hCboxBufferSize, CB_RESETCONTENT, 0, 0);
                   1922: 
                   1923:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "5 KB");
                   1924:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 5 * BYTES_PER_KB);
                   1925: 
                   1926:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "100 KB");
                   1927:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 100 * BYTES_PER_KB);
                   1928: 
                   1929:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "500 KB");
                   1930:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 500 * BYTES_PER_KB);
                   1931: 
                   1932:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "1 MB");
                   1933:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 1 * BYTES_PER_MB);
                   1934: 
                   1935:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "5 MB");
                   1936:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 5 * BYTES_PER_MB);
                   1937: 
                   1938:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "10 MB");
                   1939:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 10 * BYTES_PER_MB);
                   1940: 
                   1941:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "50 MB");
                   1942:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 50 * BYTES_PER_MB);
                   1943: 
                   1944:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "100 MB");
                   1945:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 100 * BYTES_PER_MB);
                   1946: 
                   1947:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "200 MB");
                   1948:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 200 * BYTES_PER_MB);
                   1949: 
                   1950:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "500 MB");
                   1951:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 500 * BYTES_PER_MB);
                   1952: 
                   1953:                        nIndex = SendMessage (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) "1 GB");
                   1954:                        SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 1 * BYTES_PER_GB);
                   1955: 
                   1956:                        SendMessage (hCboxBufferSize, CB_SETCURSEL, 3, 0);              // Default size
                   1957: 
                   1958:                        return 1;
                   1959:                }
                   1960:                break;
                   1961: 
                   1962:        case WM_COMMAND:
                   1963:        case WM_NOTIFY:
                   1964: 
                   1965:                if (lw == IDC_BENCHMARK_SORT_METHOD)
                   1966:                {
                   1967:                        nIndex = SendMessage (hCboxSortMethod, CB_GETCURSEL, 0, 0);
                   1968:                        if (nIndex != benchmarkSortMethod)
                   1969:                        {
                   1970:                                benchmarkSortMethod = nIndex;
                   1971:                                DisplayBenchmarkResults (hwndDlg);
                   1972:                        }
                   1973:                }
                   1974: 
                   1975:                if (lw == ID_PERFORM_BENCHMARK)
                   1976:                {
                   1977:                        nIndex = SendMessage (hCboxBufferSize, CB_GETCURSEL, 0, 0);
                   1978:                        benchmarkBufferSize = SendMessage (hCboxBufferSize, CB_GETITEMDATA, nIndex, 0);
                   1979: 
                   1980:                        if (PerformBenchmark(hwndDlg) == FALSE)
                   1981:                        {
                   1982:                                EndDialog (hwndDlg, IDCLOSE);
                   1983:                        }
                   1984:                        return 0;
                   1985:                }
                   1986:                if (lw == IDCLOSE)
                   1987:                {
                   1988:                        EndDialog (hwndDlg, IDCLOSE);
                   1989:                        return 0;
                   1990:                }
                   1991:                return 0;
                   1992: 
                   1993:                break;
                   1994: 
                   1995:        case WM_CLOSE:
                   1996:                EndDialog (hwndDlg, IDCLOSE);
                   1997:                return 0;
                   1998: 
                   1999:                break;
                   2000: 
                   2001:        }
                   2002: 
                   2003:        return 0;
                   2004: }
                   2005: #endif // #ifndef SETUP
                   2006: 
                   2007: 
                   2008: BOOL CheckCapsLock (HWND hwnd, BOOL quiet)
                   2009: {
                   2010:        if ((GetKeyState(VK_CAPITAL) & 1) != 0) 
                   2011:        {
                   2012:                if (!quiet)
                   2013:                {
                   2014:                        MessageBox (hwnd, getstr (IDS_CAPSLOCK_ON), lpszTitle, MB_ICONEXCLAMATION);
                   2015:                }
                   2016:                return TRUE;
                   2017:        }
                   2018:        return FALSE;
                   2019: }
                   2020: 
                   2021: 
                   2022: BOOL CheckPasswordLength (HWND hwndDlg, HWND hwndItem)                 
                   2023: {
                   2024:        if (GetWindowTextLength (hwndItem) < PASSWORD_LEN_WARNING)
                   2025:        {
                   2026:                if (MessageBox (hwndDlg, getstr (IDS_PASSWORD_LENGTH_WARNING), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2) != IDYES)
                   2027:                        return FALSE;
                   2028:        }
                   2029:        return TRUE;
                   2030: }
                   2031: 
                   2032: 
                   2033: int GetFirstAvailableDrive ()
                   2034: {
                   2035:        DWORD dwUsedDrives = GetLogicalDrives();
                   2036:        int i;
                   2037: 
                   2038:        for (i = 3; i < 26; i++)
                   2039:        {
                   2040:                if (!(dwUsedDrives & 1 << i))
                   2041:                        return i;
                   2042:        }
                   2043: 
                   2044:        return -1;
                   2045: }
                   2046: 
                   2047: 
                   2048: int GetLastAvailableDrive ()
                   2049: {
                   2050:        DWORD dwUsedDrives = GetLogicalDrives();
                   2051:        int i;
                   2052: 
                   2053:        for (i = 25; i > 2; i--)
                   2054:        {
                   2055:                if (!(dwUsedDrives & 1 << i))
                   2056:                        return i;
                   2057:        }
                   2058: 
                   2059:        return -1;
                   2060: }
                   2061: 
                   2062: 
                   2063: BOOL IsDriveAvailable (int driveNo)
                   2064: {
                   2065:        return (GetLogicalDrives() & (1 << driveNo)) == 0;
                   2066: }
                   2067: 
                   2068: 
                   2069: int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced)
                   2070: {
                   2071:        UNMOUNT_STRUCT unmount;
                   2072:        DWORD dwResult;
                   2073: 
                   2074:        BOOL bResult;
                   2075:        
                   2076:        unmount.nDosDriveNo = nDosDriveNo;
                   2077:        unmount.ignoreOpenFiles = forced;
                   2078: 
                   2079:        bResult = DeviceIoControl (hDriver, UNMOUNT, &unmount,
                   2080:                sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
                   2081: 
                   2082:        if (bResult == FALSE)
                   2083:        {
                   2084:                handleWin32Error (hwndDlg);
                   2085:                return 1;
                   2086:        }
                   2087: 
                   2088:        return unmount.nReturnCode;
                   2089: }
                   2090: 
                   2091: 
1.1.1.6 ! root     2092: void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap)
1.1.1.5   root     2093: {
                   2094:        DEV_BROADCAST_VOLUME dbv;
                   2095:        char root[] = {nDosDriveNo + 'A', ':', '\\', 0 };
1.1.1.6 ! root     2096:        DWORD dwResult;
        !          2097: 
        !          2098:        if (message == DBT_DEVICEARRIVAL)
        !          2099:                SHChangeNotify(SHCNE_DRIVEADD, SHCNF_PATH, root, NULL);
1.1.1.5   root     2100: 
                   2101:        if (message == DBT_DEVICEREMOVECOMPLETE)
                   2102:                SHChangeNotify(SHCNE_DRIVEREMOVED, SHCNF_PATH, root, NULL);
                   2103: 
                   2104:        dbv.dbcv_size = sizeof(dbv); 
                   2105:        dbv.dbcv_devicetype = DBT_DEVTYP_VOLUME; 
                   2106:        dbv.dbcv_reserved = 0;
1.1.1.6 ! root     2107:        dbv.dbcv_unitmask = (driveMap != 0) ? driveMap : (1 << nDosDriveNo);
1.1.1.5   root     2108:        dbv.dbcv_flags = 0; 
                   2109: 
1.1.1.6 ! root     2110:        SendMessageTimeout (HWND_BROADCAST, WM_DEVICECHANGE, message, (LPARAM)(&dbv), 0, 500, &dwResult);
1.1.1.5   root     2111: }
                   2112: 
                   2113: 
                   2114: // Returns:
                   2115: // -1 = user aborted mount / error
                   2116: // 0  = mount failed
                   2117: // 1  = mount OK
                   2118: // 2  = mount OK in shared mode
                   2119: 
                   2120: int MountVolume (HWND hwndDlg,
                   2121:                                 int driveNo,
                   2122:                                 char *volumePath,
                   2123:                                 char *szPassword,
                   2124:                                 BOOL cachePassword,
                   2125:                                 BOOL sharedAccess,
1.1.1.6 ! root     2126:                                 MountOptions *mountOptions,
1.1.1.5   root     2127:                                 BOOL quiet)
                   2128: {
                   2129:        MOUNT_STRUCT driver;
                   2130:        DWORD dwResult;
                   2131:        BOOL bResult, bDevice;
                   2132: 
                   2133:        if (IsMountedVolume (volumePath))
                   2134:        {
                   2135:                if (!quiet)
                   2136:                        MessageBox(0, getstr (IDS_ALREADY_MOUNTED), lpszTitle, MB_ICONASTERISK);
                   2137:                return -1;
                   2138:        }
                   2139: 
                   2140:        if (!IsDriveAvailable (driveNo))
                   2141:                return -1;
                   2142: 
                   2143:        // If using cached passwords, check cache status first
                   2144:        if (szPassword[0] == 0 && IsPasswordCacheEmpty ())
                   2145:                return 0;
                   2146: 
                   2147:        ZeroMemory (&driver, sizeof (driver));
                   2148:        driver.bExclusiveAccess = sharedAccess ? FALSE : TRUE;
                   2149: retry:
                   2150:        driver.nDosDriveNo = driveNo;
                   2151:        driver.bCache = cachePassword;
                   2152:        driver.time = time (NULL);
                   2153:        driver.nPasswordLen = strlen (szPassword);
                   2154:        strcpy (driver.szPassword, szPassword);
1.1.1.6 ! root     2155:        driver.bMountReadOnly = mountOptions->ReadOnly;
        !          2156:        driver.bMountRemovable = mountOptions->Removable;
1.1.1.5   root     2157:        driver.bMountManager = TRUE;
                   2158: 
                   2159:        // Windows 2000 mount manager causes problems with remounted volumes
                   2160:        if (CurrentOSMajor == 5 && CurrentOSMinor == 0)
                   2161:                driver.bMountManager = FALSE;
                   2162: 
                   2163:        CreateFullVolumePath ((char *) driver.wszVolume, volumePath, &bDevice);
                   2164: 
                   2165:        if (nCurrentOS == WIN_NT)
                   2166:                ToUNICODE ((char *) driver.wszVolume);
                   2167: 
                   2168:        bResult = DeviceIoControl (hDriver, MOUNT, &driver,
                   2169:                sizeof (driver), &driver, sizeof (driver), &dwResult, NULL);
                   2170: 
                   2171:        burn (&driver.szPassword, sizeof (driver.szPassword));
                   2172: 
                   2173:        if (bResult == FALSE)
                   2174:        {
                   2175:                // Volume already open by another process
                   2176:                if (GetLastError() == ERROR_SHARING_VIOLATION)
                   2177:                {
                   2178:                        if (driver.bExclusiveAccess == FALSE)
                   2179:                        {
                   2180:                                if (!quiet)
                   2181:                                        MessageBox (hwndDlg, getstr (bDevice ? IDS_DEVICE_IN_USE_FAILED : IDS_FILE_IN_USE_FAILED),
                   2182:                                                lpszTitle, MB_ICONSTOP);
                   2183: 
                   2184:                                return -1;
                   2185:                        }
                   2186:                        else
                   2187:                        {
                   2188:                                if (quiet)
                   2189:                                {
                   2190:                                        driver.bExclusiveAccess = FALSE;
                   2191:                                        goto retry;
                   2192:                                }
                   2193: 
                   2194:                                // Ask user 
                   2195:                                if (IDYES == MessageBox (hwndDlg, getstr (bDevice ? IDS_DEVICE_IN_USE : IDS_FILE_IN_USE),
                   2196:                                        lpszTitle, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION))
                   2197:                                {
                   2198:                                        driver.bExclusiveAccess = FALSE;
                   2199:                                        goto retry;
                   2200:                                }
                   2201:                        }
                   2202: 
                   2203:                        return -1;
                   2204:                }
                   2205: 
                   2206:                if (!quiet)
                   2207:                        handleWin32Error (hwndDlg);
                   2208: 
                   2209:                return -1;
                   2210:        }
                   2211: 
                   2212:        if (driver.nReturnCode != 0)
                   2213:        {
                   2214:                // If using cached passwords, do not report wrong password
                   2215:                if (szPassword[0] == 0 && driver.nReturnCode == ERR_PASSWORD_WRONG)
                   2216:                        return 0;
                   2217: 
                   2218:                if (!quiet)     handleError (hwndDlg, driver.nReturnCode);
                   2219: 
                   2220:                return 0;
                   2221:        }
                   2222: 
1.1.1.6 ! root     2223:        BroadcastDeviceChange (DBT_DEVICEARRIVAL, driveNo, 0);
1.1.1.5   root     2224: 
                   2225:        if (driver.bExclusiveAccess == FALSE)
                   2226:                return 2;
                   2227: 
                   2228:        return 1;
                   2229: }
                   2230: 
                   2231: 
                   2232: BOOL UnmountVolume (HWND hwndDlg , int nDosDriveNo, BOOL forceUnmount)
                   2233: {
                   2234:        int result;
                   2235:        BOOL bResult;
                   2236:        BOOL forced = forceUnmount;
1.1.1.6 ! root     2237:        int dismountMaxRetries = UNMOUNT_MAX_AUTO_RETRIES;
1.1.1.5   root     2238: 
1.1.1.6 ! root     2239:        //BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, nDosDriveNo);
1.1.1.5   root     2240: 
                   2241: retry:
1.1.1.6 ! root     2242:        do
        !          2243:        {
        !          2244:                result = DriverUnmountVolume (hwndDlg, nDosDriveNo, forced);
        !          2245: 
        !          2246:                if (result == ERR_FILES_OPEN)
        !          2247:                        Sleep (UNMOUNT_AUTO_RETRY_DELAY);
        !          2248:                else
        !          2249:                        break;
        !          2250: 
        !          2251:        } while (--dismountMaxRetries > 0);
1.1.1.5   root     2252: 
                   2253:        if (result != 0)
                   2254:        {
                   2255:                if (result == ERR_FILES_OPEN)
                   2256:                {
                   2257:                        if (IDYES == MessageBox (hwndDlg, getstr (IDS_UNMOUNT_LOCK_FAILED),
                   2258:                                lpszTitle, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION))
                   2259:                        {
                   2260:                                forced = TRUE;
                   2261:                                goto retry;
                   2262:                        }
                   2263: 
                   2264:                        return FALSE;
                   2265:                }
                   2266: 
                   2267:                MessageBox (hwndDlg, getstr (IDS_UNMOUNT_FAILED),
                   2268:                                lpszTitle, MB_ICONERROR);
                   2269: 
                   2270:                return FALSE;
                   2271:        } 
                   2272:        
1.1.1.6 ! root     2273:        BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, nDosDriveNo, 0);
1.1.1.5   root     2274: 
                   2275:        return TRUE;
                   2276: }
                   2277: 
                   2278: 
                   2279: BOOL IsPasswordCacheEmpty (void)
                   2280: {
                   2281:        DWORD dw;
                   2282:        return !DeviceIoControl (hDriver, CACHE_STATUS, 0, 0, 0, 0, &dw, 0);
                   2283: }
                   2284: 
                   2285: BOOL IsMountedVolume (char *volname)
                   2286: {
                   2287:        MOUNT_LIST_STRUCT mlist;
                   2288:        DWORD dwResult;
                   2289:        int i;
                   2290:        char volume[TC_MAX_PATH*2+16];
                   2291: 
                   2292:        strcpy (volume, volname);
                   2293:        if (nCurrentOS == WIN_NT) 
                   2294:        {
                   2295:                if (strstr (volname, "\\Device\\") != volname)
                   2296:                        sprintf(volume, "\\??\\%s", volname);
                   2297:                ToUNICODE (volume);
                   2298:        }
                   2299: 
                   2300:        memset (&mlist, 0, sizeof (mlist));
                   2301:        DeviceIoControl (hDriver, MOUNT_LIST, &mlist,
                   2302:                sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
                   2303:                NULL);
                   2304: 
                   2305:        for (i=0 ; i<26; i++)
                   2306:                if (nCurrentOS != WIN_NT && 0 == strcmp ((char *)mlist.wszVolume[i], volume) 
                   2307:                        || nCurrentOS == WIN_NT && 0 == wcscmp (mlist.wszVolume[i], (WCHAR *)volume))
                   2308:                        return TRUE;
                   2309: 
                   2310:        return FALSE;
                   2311: }
                   2312: 
                   2313: 
                   2314: BOOL IsAdmin (void)
                   2315: {
                   2316:        HANDLE hAccessToken;
                   2317:        UCHAR InfoBuffer[1024];
                   2318:        PTOKEN_GROUPS ptgGroups = (PTOKEN_GROUPS) InfoBuffer;
                   2319:        DWORD dwInfoBufferSize;
                   2320:        PSID psidAdministrators;
                   2321:        SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
                   2322:        BOOL bSuccess;
                   2323:        UINT x;
                   2324: 
                   2325:        if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, TRUE,
                   2326:                              &hAccessToken))
                   2327:        {
                   2328:                if (GetLastError ()!= ERROR_NO_TOKEN)
                   2329:                        return FALSE;
                   2330: 
                   2331:                /* Retry against process token if no thread token exists */
                   2332:                if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY,
                   2333:                                       &hAccessToken))
                   2334:                        return FALSE;
                   2335:        }
                   2336: 
                   2337:        bSuccess = GetTokenInformation (hAccessToken, TokenGroups, InfoBuffer,
                   2338:                                        1024, &dwInfoBufferSize);
                   2339: 
                   2340:        CloseHandle (hAccessToken);
                   2341: 
                   2342:        if (!bSuccess)
                   2343:                return FALSE;
                   2344: 
                   2345:        if (!AllocateAndInitializeSid (&siaNtAuthority, 2,
                   2346:                                       SECURITY_BUILTIN_DOMAIN_RID,
                   2347:                                       DOMAIN_ALIAS_RID_ADMINS,
                   2348:                                       0, 0, 0, 0, 0, 0,
                   2349:                                       &psidAdministrators))
                   2350:                return FALSE;
                   2351:  
                   2352:        /* Assume that we don't find the admin SID. */
                   2353:        bSuccess = FALSE;
                   2354: 
                   2355:        for (x = 0; x < ptgGroups->GroupCount; x++)
                   2356:        {
                   2357:                if (EqualSid (psidAdministrators, ptgGroups->Groups[x].Sid))
                   2358:                {
                   2359:                        bSuccess = TRUE;
                   2360:                        break;
                   2361:                }
                   2362: 
                   2363:        }
                   2364: 
                   2365:        FreeSid (psidAdministrators);
                   2366:        return bSuccess;
                   2367: }
                   2368: 
                   2369: 
                   2370: BOOL ResolveSymbolicLink (PWSTR symLinkName, PWSTR targetName)
                   2371: {
                   2372:        BOOL bResult;
                   2373:        DWORD dwResult;
                   2374:        RESOLVE_SYMLINK_STRUCT resolve;
                   2375: 
                   2376:        memset (&resolve, 0, sizeof(resolve));
                   2377:        wcscpy ((PWSTR) &resolve.symLinkName, symLinkName);
                   2378: 
                   2379:        bResult = DeviceIoControl (hDriver, RESOLVE_SYMLINK, &resolve,
                   2380:                sizeof (resolve), &resolve, sizeof (resolve), &dwResult,
                   2381:                NULL);
                   2382: 
                   2383:        wcscpy (targetName, (PWSTR) &resolve.targetName);
                   2384: 
                   2385:        return bResult;
                   2386: }
                   2387: 
                   2388: 
                   2389: // Returns drive letter number assigned to device (-1 if none)
                   2390: int GetDiskDeviceDriveLetter (PWSTR deviceName)
                   2391: {
                   2392:        int i;
                   2393:        WCHAR link[MAX_PATH];
                   2394:        WCHAR target[MAX_PATH];
                   2395:        WCHAR device[MAX_PATH];
                   2396:        char msg[100];
                   2397: 
                   2398:        if (!ResolveSymbolicLink (deviceName, device))
                   2399:                wcscpy (device, deviceName);
                   2400: 
                   2401:        for (i = 0; i < 26; i++)
                   2402:        {
                   2403:                WCHAR drive[] = { i + 'A', ':', 0 };
                   2404: 
                   2405:                wcscpy (link, L"\\DosDevices\\");
                   2406:                wcscat (link, drive);
                   2407: 
                   2408:                ResolveSymbolicLink (link, target);
                   2409: 
                   2410:                if (wcscmp (device, target) == 0)
                   2411:                        return i;
                   2412:        }
                   2413: 
                   2414:        return -1;
                   2415: }
                   2416: 
                   2417: 
                   2418: HANDLE DismountDrive (int driveNo)
                   2419: {
                   2420:        char volMountName[32];
                   2421:        char dosName[3];
                   2422:        DWORD dwResult;
                   2423:        BOOL bResult;
                   2424:        HANDLE hVolume;
                   2425: 
                   2426:        dosName[0] = (char) (driveNo + 'A');
                   2427:        dosName[1] = ':';
                   2428:        dosName[2] = 0;
                   2429: 
                   2430:        sprintf (volMountName, "\\\\.\\%s", dosName);
                   2431: 
                   2432:        hVolume = CreateFile (volMountName, GENERIC_READ | GENERIC_WRITE,
                   2433:                FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
                   2434: 
                   2435:        bResult = DeviceIoControl (hVolume, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &dwResult, NULL);
                   2436:        bResult = DeviceIoControl (hVolume, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &dwResult, NULL);
                   2437: 
                   2438:        return hVolume;
1.1.1.6 ! root     2439: }
        !          2440: 
        !          2441: // System CopyFile() copies source file attributes (like FILE_ATTRIBUTE_ENCRYPTED)
        !          2442: // so we need to use our own copy function
        !          2443: BOOL TCCopyFile (char *sourceFileName, char *destinationFile)
        !          2444: {
        !          2445:        __int8 *buffer;
        !          2446:        HANDLE src, dst;
        !          2447:        FILETIME fileTime;
        !          2448:        DWORD bytesRead, bytesWritten;
        !          2449:        BOOL res;
        !          2450: 
        !          2451:        src = CreateFile (sourceFileName,
        !          2452:                GENERIC_READ,
        !          2453:                FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
        !          2454: 
        !          2455:        if (src == INVALID_HANDLE_VALUE)
        !          2456:                return FALSE;
        !          2457: 
        !          2458:        dst = CreateFile (destinationFile,
        !          2459:                GENERIC_WRITE,
        !          2460:                0, NULL, CREATE_ALWAYS, 0, NULL);
        !          2461: 
        !          2462:        if (dst == INVALID_HANDLE_VALUE)
        !          2463:        {
        !          2464:                CloseHandle (src);
        !          2465:                return FALSE;
        !          2466:        }
        !          2467: 
        !          2468:        buffer = malloc (64 * 1024);
        !          2469:        if (!buffer)
        !          2470:        {
        !          2471:                CloseHandle (src);
        !          2472:                CloseHandle (dst);
        !          2473:                return FALSE;
        !          2474:        }
        !          2475: 
        !          2476:        while (res = ReadFile (src, buffer, 64 * 1024, &bytesRead, NULL))
        !          2477:        {
        !          2478:                if (bytesRead == 0)
        !          2479:                {
        !          2480:                        res = 1;
        !          2481:                        break;
        !          2482:                }
        !          2483: 
        !          2484:                if (!WriteFile (dst, buffer, bytesRead, &bytesWritten, NULL)
        !          2485:                        || bytesRead != bytesWritten)
        !          2486:                {
        !          2487:                        res = 0;
        !          2488:                        break;
        !          2489:                }
        !          2490:        }
        !          2491: 
        !          2492:        GetFileTime (src, NULL, NULL, &fileTime);
        !          2493:        SetFileTime (dst, NULL, NULL, &fileTime);
        !          2494: 
        !          2495:        CloseHandle (src);
        !          2496:        CloseHandle (dst);
        !          2497: 
        !          2498:        free (buffer);
        !          2499:        return res != 0;
        !          2500: }
        !          2501: 
        !          2502: 
        !          2503: BOOL IsNonInstallMode ()
        !          2504: {
        !          2505:        HANDLE fh;
        !          2506:        WIN32_FIND_DATA fd;
        !          2507:        char fileName[TC_MAX_PATH];
        !          2508: 
        !          2509:        GetSystemDirectory (fileName, sizeof (fileName));
        !          2510:        strcat (fileName, "\\Drivers\\truecrypt.sys");
        !          2511: 
        !          2512:        fh = FindFirstFile (fileName, &fd);
        !          2513: 
        !          2514:        if (fh == INVALID_HANDLE_VALUE)
        !          2515:                return TRUE;
        !          2516: 
        !          2517:        FindClose (fh);
        !          2518:        return FALSE;
        !          2519: }
        !          2520: 
        !          2521: 
        !          2522: BOOL WINAPI
        !          2523: MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
        !          2524: {
        !          2525:        static MountOptions *mountOptions;
        !          2526:        WORD lw = LOWORD (wParam);
        !          2527: 
        !          2528:        switch (msg)
        !          2529:        {
        !          2530:        case WM_INITDIALOG:
        !          2531:                {
        !          2532:                        mountOptions = (MountOptions *) lParam;
        !          2533: 
        !          2534:                        SetDefaultUserFont (hwndDlg);
        !          2535:                
        !          2536:                        SendDlgItemMessage (hwndDlg, IDC_MOUNT_READONLY, BM_SETCHECK,
        !          2537:                                mountOptions->ReadOnly ? BST_CHECKED : BST_UNCHECKED, 0);
        !          2538:                        SendDlgItemMessage (hwndDlg, IDC_MOUNT_REMOVABLE, BM_SETCHECK,
        !          2539:                                mountOptions->Removable ? BST_CHECKED : BST_UNCHECKED, 0);
        !          2540: 
        !          2541:                        return 1;
        !          2542:                }
        !          2543: 
        !          2544:        case WM_COMMAND:
        !          2545: 
        !          2546:                if (lw == IDCANCEL)
        !          2547:                {
        !          2548:                        EndDialog (hwndDlg, lw);
        !          2549:                        return 1;
        !          2550:                }
        !          2551: 
        !          2552:                if (lw == IDOK)
        !          2553:                {
        !          2554:                        mountOptions->ReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
        !          2555:                        mountOptions->Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_REMOVABLE));
        !          2556: 
        !          2557:                        EndDialog (hwndDlg, lw);
        !          2558:                        return 1;
        !          2559:                }
        !          2560:                return 0;
        !          2561:        }
        !          2562: 
        !          2563:        return 0;
        !          2564: }

unix.superglobalmegacorp.com

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