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

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
        !             3:    additions to that source code contained in this file are Copyright (c) 2004
        !             4:    TrueCrypt Team and Copyright (c) 2004 TrueCrypt Foundation. Unmodified
        !             5:    parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation
        !             6:    release. Please see the file license.txt for full license details. */
1.1       root        7: 
                      8: #include "TCdefs.h"
                      9: 
                     10: #include <stdlib.h>
                     11: 
                     12: #include "resource.h"
                     13: #include "crypto.h"
                     14: #include "apidrvr.h"
                     15: #include "dlgcode.h"
                     16: 
                     17: char szHelpFile[TC_MAX_PATH];
                     18: HFONT hSmallFont = NULL;
                     19: HFONT hBoldFont = NULL;
                     20: HFONT hSmallBoldFont = NULL;
                     21: HFONT hTitleFont = NULL;
                     22: HFONT hFixedFont = NULL;
                     23: 
                     24: HFONT hUserFont = NULL;
                     25: HFONT hUserUnderlineFont = NULL;
                     26: HFONT hUserBoldFont = NULL;
                     27: 
                     28: char *lpszTitle = NULL;
                     29: int nCurrentOS = 0;
                     30: int CurrentOSMajor = 0;
                     31: int CurrentOSMinor = 0;
                     32: 
                     33: /* Handle to the device driver */
                     34: HANDLE hDriver = INVALID_HANDLE_VALUE;
                     35: HINSTANCE hInst = NULL;
                     36: HANDLE hMutex = NULL;
                     37: HCURSOR hCursor = NULL;
                     38: 
                     39: ATOM hDlgClass, hSplashClass;
                     40: 
                     41: /* Windows dialog class */
                     42: #define WINDOWS_DIALOG_CLASS "#32770"
                     43: 
                     44: /* Custom class names */
                     45: #define TC_DLG_CLASS "CustomDlg"
                     46: #define TC_SPLASH_CLASS "SplashDlg"
                     47: 
                     48: void
                     49: cleanup ()
                     50: {
                     51:        /* Cleanup the GDI fonts */
                     52:        if (hFixedFont != NULL)
                     53:                DeleteObject (hFixedFont);
                     54:        if (hSmallFont != NULL)
                     55:                DeleteObject (hSmallFont);
                     56:        if (hBoldFont != NULL)
                     57:                DeleteObject (hBoldFont);
                     58:        if (hSmallBoldFont != NULL)
                     59:                DeleteObject (hSmallBoldFont);
                     60:        if (hTitleFont != NULL)
                     61:                DeleteObject (hTitleFont);
                     62:        if (hUserFont != NULL)
                     63:                DeleteObject (hUserFont);
                     64:        if (hUserUnderlineFont != NULL)
                     65:                DeleteObject (hUserUnderlineFont);
                     66:        if (hUserBoldFont != NULL)
                     67:                DeleteObject (hUserBoldFont);
                     68:        /* Cleanup our dialog class */
                     69:        if (hDlgClass)
                     70:                UnregisterClass (TC_DLG_CLASS, hInst);
                     71:        if (hSplashClass)
                     72:                UnregisterClass (TC_SPLASH_CLASS, hInst);
                     73:        /* Close the device driver handle */
                     74:        if (hDriver != INVALID_HANDLE_VALUE)
                     75:        {
                     76:                CloseHandle (hDriver);
                     77:        }
                     78: 
                     79:        if (hMutex != NULL)
                     80:        {
                     81:                CloseHandle (hMutex);
                     82:        }
                     83: }
                     84: 
                     85: void
                     86: LowerCaseCopy (char *lpszDest, char *lpszSource)
                     87: {
                     88:        int i = strlen (lpszSource);
                     89: 
                     90:        lpszDest[i] = 0;
                     91:        while (--i >= 0)
                     92:        {
                     93:                lpszDest[i] = (char) tolower (lpszSource[i]);
                     94:        }
                     95: 
                     96: }
                     97: 
                     98: void
                     99: UpperCaseCopy (char *lpszDest, char *lpszSource)
                    100: {
                    101:        int i = strlen (lpszSource);
                    102: 
                    103:        lpszDest[i] = 0;
                    104:        while (--i >= 0)
                    105:        {
                    106:                lpszDest[i] = (char) toupper (lpszSource[i]);
                    107:        }
                    108: }
                    109: 
                    110: void
                    111: CreateFullVolumePath (char *lpszDiskFile, char *lpszFileName, BOOL * bDevice)
                    112: {
                    113:        if (strcmp (lpszFileName, "Floppy (A:)") == 0)
                    114:                strcpy (lpszFileName, "\\Device\\Floppy0");
                    115:        else if (strcmp (lpszFileName, "Floppy (B:)") == 0)
                    116:                strcpy (lpszFileName, "\\Device\\Floppy1");
                    117: 
                    118:        UpperCaseCopy (lpszDiskFile, lpszFileName);
                    119: 
                    120:        *bDevice = FALSE;
                    121: 
                    122:        if (memcmp (lpszDiskFile, "\\DEVICE", sizeof (char) * 7) == 0)
                    123:        {
                    124:                *bDevice = TRUE;
                    125:        }
                    126: 
                    127:        strcpy (lpszDiskFile, lpszFileName);
                    128: 
                    129: #if _DEBUG
                    130:        OutputDebugString ("CreateFullVolumePath: ");
                    131:        OutputDebugString (lpszDiskFile);
                    132:        OutputDebugString ("\n");
                    133: #endif
                    134: 
                    135: }
                    136: 
                    137: int
                    138: FakeDosNameForDevice (char *lpszDiskFile, char *lpszDosDevice, char *lpszCFDevice, BOOL bNameOnly)
                    139: {
                    140:        BOOL bDosLinkCreated = TRUE;
                    141:        sprintf (lpszDosDevice, "truecrypt%lu", GetCurrentProcessId ());
                    142: 
                    143:        if (bNameOnly == FALSE)
                    144:                bDosLinkCreated = DefineDosDevice (DDD_RAW_TARGET_PATH, lpszDosDevice, lpszDiskFile);
                    145: 
                    146:        if (bDosLinkCreated == FALSE)
                    147:        {
                    148:                return ERR_OS_ERROR;
                    149:        }
                    150:        else
                    151:                sprintf (lpszCFDevice, "\\\\.\\%s", lpszDosDevice);
                    152: 
                    153:        return 0;
                    154: }
                    155: 
                    156: int
                    157: RemoveFakeDosName (char *lpszDiskFile, char *lpszDosDevice)
                    158: {
                    159:        BOOL bDosLinkRemoved = DefineDosDevice (DDD_RAW_TARGET_PATH | DDD_EXACT_MATCH_ON_REMOVE |
                    160:                        DDD_REMOVE_DEFINITION, lpszDosDevice, lpszDiskFile);
                    161:        if (bDosLinkRemoved == FALSE)
                    162:        {
                    163:                return ERR_OS_ERROR;
                    164:        }
                    165: 
                    166:        return 0;
                    167: }
                    168: 
                    169: char *
                    170: getstr (UINT nID)
                    171: {
                    172:        static char szMsg[256];
                    173:        if (LoadString (hInst, nID, szMsg, sizeof (szMsg)) == 0)
                    174:                return "";
                    175:        else
                    176:                return szMsg;
                    177: }
                    178: 
                    179: char *
                    180: getmultilinestr (UINT nID[4])
                    181: {
                    182:        static char szMsg[1024];
                    183:        if (nID[0])
                    184:                strcpy (szMsg, getstr (nID[0]));
                    185:        if (nID[1])
                    186:                strcat (szMsg, getstr (nID[1]));
                    187:        if (nID[2])
                    188:                strcat (szMsg, getstr (nID[2]));
                    189:        if (nID[3])
                    190:                strcat (szMsg, getstr (nID[3]));
                    191:        return szMsg;
                    192: 
                    193: }
                    194: 
                    195: void
                    196: AbortProcess (UINT nID)
                    197: {
                    198:        MessageBeep (MB_ICONEXCLAMATION);
                    199:        MessageBox (NULL, getstr (nID), lpszTitle, ICON_HAND);
                    200:        exit (1);
                    201: }
                    202: 
                    203: void *
                    204: err_malloc (size_t size)
                    205: {
                    206:        void *z = (void *) TCalloc (size);
                    207:        if (z)
                    208:                return z;
                    209:        AbortProcess (IDS_OUTOFMEMORY);
                    210:        return 0;
                    211: }
                    212: 
                    213: char *
                    214: err_strdup (char *lpszText)
                    215: {
                    216:        int j = (strlen (lpszText) + 1) * sizeof (char);
                    217:        char *z = (char *) err_malloc (j);
                    218:        memmove (z, lpszText, j);
                    219:        return z;
                    220: }
                    221: 
                    222: void
                    223: handleWin32Error (HWND hwndDlg)
                    224: {
                    225:        LPVOID lpMsgBuf;
                    226:        DWORD dwError = GetLastError ();
                    227: 
                    228:        FormatMessage (
                    229:                FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                    230:                              NULL,
                    231:                              dwError,
                    232:                              MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),       /* Default language */
                    233:                              (char *) &lpMsgBuf,
                    234:                              0,
                    235:                              NULL
                    236:            );
                    237: 
                    238:        MessageBox (hwndDlg, lpMsgBuf, lpszTitle, ICON_HAND);
                    239:        LocalFree (lpMsgBuf);
                    240: }
                    241: 
                    242: BOOL
                    243: translateWin32Error (char *lpszMsgBuf, int nSizeOfBuf)
                    244: {
                    245:        DWORD dwError = GetLastError ();
                    246: 
                    247:        if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
                    248:                           MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),  /* Default language */
                    249:                           lpszMsgBuf, nSizeOfBuf, NULL))
                    250:                return TRUE;
                    251:        else
                    252:                return FALSE;
                    253: }
                    254: 
                    255: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
                    256:    should return nonzero if it processes the message, and zero if it does
                    257:    not. - see DialogProc */
                    258: BOOL WINAPI
                    259: AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                    260: {
                    261:        WORD lw = LOWORD (wParam);
                    262:        if (lParam);            /* remove warning */
                    263: 
                    264:        switch (msg)
                    265:        {
                    266: 
                    267:        case WM_INITDIALOG:
                    268:                {
                    269:                        char szTmp[32];
                    270: 
                    271:                        SetDefaultUserFont (hwndDlg);
                    272:                        SendMessage (GetDlgItem (hwndDlg, ID_WEBSITE), WM_SETFONT, (WPARAM) hUserUnderlineFont, 0);
                    273:                        SendMessage (GetDlgItem (hwndDlg, IDT_ABOUT_VERSION), WM_SETFONT, (WPARAM) hUserBoldFont, 0);
                    274: 
                    275:                        sprintf (szTmp, "TrueCrypt %s", VERSION_STRING);
                    276:                        SetDlgItemText (hwndDlg, IDT_ABOUT_VERSION, szTmp);
                    277:                        return 1;
                    278:                }
                    279: 
                    280:        case WM_COMMAND:
                    281:                if (lw == IDOK || lw == IDCANCEL)
                    282:                {
                    283:                        EndDialog (hwndDlg, 0);
                    284:                        return 1;
                    285:                }
                    286: 
                    287:                if (lw == ID_WEBSITE)
                    288:                {
                    289:                        ArrowWaitCursor ();
1.1.1.2   root      290:                        ShellExecute (NULL, "open", "http://www.google.com/search?q=truecrypt", NULL, NULL, SW_SHOWNORMAL);
1.1       root      291:                        Sleep (200);
                    292:                        NormalCursor ();
                    293:                        return 1;
                    294:                }
                    295:                return 0;
                    296: 
                    297:        case WM_CLOSE:
                    298:                EndDialog (hwndDlg, 0);
                    299:                return 1;
                    300:        }
                    301: 
                    302:        return 0;
                    303: }
                    304: 
                    305: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
                    306:    should return nonzero if it processes the message, and zero if it does
                    307:    not. - see DialogProc */
                    308: BOOL WINAPI
                    309: WarningDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                    310: {
                    311:        WORD lw = LOWORD (wParam);
                    312:        if (lParam);            /* remove warning */
                    313: 
                    314:        switch (msg)
                    315:        {
                    316:        case WM_INITDIALOG:
                    317:                SetDefaultUserFont (hwndDlg);
                    318:                SetWindowText (GetDlgItem (hwndDlg, IDC_WARNING_TEXT), (char*) lParam);
                    319:                return 1;
                    320:        case WM_COMMAND:
                    321:                if (lw == IDOK || lw == IDCANCEL)
                    322:                {
                    323:                        BOOL x = IsButtonChecked (GetDlgItem (hwndDlg, IDC_NEVER_SHOW));
                    324:                        if (x == TRUE)
                    325:                                EndDialog (hwndDlg, IDOK);
                    326:                        else
                    327:                                EndDialog (hwndDlg, IDCANCEL);
                    328:                        return 1;
                    329:                }
                    330:                return 0;
                    331:        case WM_CLOSE:
                    332:                EndDialog (hwndDlg, 0);
                    333:                return 1;
                    334:        }
                    335: 
                    336:        return 0;
                    337: }
                    338: 
                    339: BOOL
                    340: IsButtonChecked (HWND hButton)
                    341: {
                    342:        if (SendMessage (hButton, BM_GETCHECK, 0, 0) == BST_CHECKED)
                    343:                return TRUE;
                    344:        else
                    345:                return FALSE;
                    346: }
                    347: 
                    348: void
                    349: CheckButton (HWND hButton)
                    350: {
                    351:        SendMessage (hButton, BM_SETCHECK, BST_CHECKED, 0);
                    352: }
                    353: 
                    354: 
                    355: /*****************************************************************************
                    356:   ToSBCS: converts a unicode string to Single Byte Character String (SBCS).
                    357:   ***************************************************************************/
                    358: 
                    359: void
                    360: ToSBCS (LPWSTR lpszText)
                    361: {
                    362:        int j = wcslen (lpszText);
                    363:        if (j == 0)
                    364:        {
                    365:                strcpy ((char *) lpszText, "");
                    366:                return;
                    367:        }
                    368:        else
                    369:        {
                    370:                char *lpszNewText = (char *) err_malloc (j + 1);
                    371:                j = WideCharToMultiByte (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1, NULL, NULL);
                    372:                if (j > 0)
                    373:                        strcpy ((char *) lpszText, lpszNewText);
                    374:                else
                    375:                        strcpy ((char *) lpszText, "");
                    376:                free (lpszNewText);
                    377:        }
                    378: }
                    379: 
                    380: /*****************************************************************************
                    381:   ToUNICODE: converts a SBCS string to a UNICODE string.
                    382:   ***************************************************************************/
                    383: 
                    384: void
                    385: ToUNICODE (char *lpszText)
                    386: {
                    387:        int j = strlen (lpszText);
                    388:        if (j == 0)
                    389:        {
                    390:                wcscpy ((LPWSTR) lpszText, (LPWSTR) WIDE (""));
                    391:                return;
                    392:        }
                    393:        else
                    394:        {
                    395:                LPWSTR lpszNewText = (LPWSTR) err_malloc ((j + 1) * 2);
                    396:                j = MultiByteToWideChar (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1);
                    397:                if (j > 0)
                    398:                        wcscpy ((LPWSTR) lpszText, lpszNewText);
                    399:                else
                    400:                        wcscpy ((LPWSTR) lpszText, (LPWSTR) "");
                    401:                free (lpszNewText);
                    402:        }
                    403: }
                    404: 
                    405: /* InitDialog - initialize the applications main dialog, this function should
                    406:    be called only once in the dialogs WM_INITDIALOG message handler */
                    407: void
                    408: InitDialog (HWND hwndDlg)
                    409: {
                    410:        HDC hDC;
                    411:        int nHeight;
                    412:        LOGFONT lf;
                    413:        HMENU hMenu;
                    414: 
                    415:        hDC = GetDC (hwndDlg);
                    416: 
                    417:        nHeight = -((8 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    418:        lf.lfHeight = nHeight;
                    419:        lf.lfWidth = 0;
                    420:        lf.lfEscapement = 0;
                    421:        lf.lfOrientation = 0;
                    422:        lf.lfWeight = FW_LIGHT;
                    423:        lf.lfItalic = FALSE;
                    424:        lf.lfUnderline = FALSE;
                    425:        lf.lfStrikeOut = FALSE;
                    426:        lf.lfCharSet = DEFAULT_CHARSET;
                    427:        lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
                    428:        lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
                    429:        lf.lfQuality = PROOF_QUALITY;
                    430:        lf.lfPitchAndFamily = FF_DONTCARE;
                    431:        strcpy (lf.lfFaceName, "Courier");
                    432:        hSmallFont = CreateFontIndirect (&lf);
                    433:        if (hSmallFont == NULL)
                    434:        {
                    435:                handleWin32Error (hwndDlg);
                    436:                AbortProcess (IDS_NOFONT);
                    437:        }
                    438: 
                    439:        nHeight = -((10 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    440:        lf.lfHeight = nHeight;
                    441:        lf.lfWeight = FW_BLACK;
                    442:        strcpy (lf.lfFaceName, "Arial");
                    443:        hSmallBoldFont = CreateFontIndirect (&lf);
                    444:        if (hSmallBoldFont == NULL)
                    445:        {
                    446:                handleWin32Error (hwndDlg);
                    447:                AbortProcess (IDS_NOFONT);
                    448:        }
                    449: 
                    450:        nHeight = -((16 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    451:        lf.lfHeight = nHeight;
                    452:        lf.lfWeight = FW_BOLD;
                    453:        strcpy (lf.lfFaceName, "Times");
                    454:        hBoldFont = CreateFontIndirect (&lf);
                    455:        if (hBoldFont == NULL)
                    456:        {
                    457:                handleWin32Error (hwndDlg);
                    458:                AbortProcess (IDS_NOFONT);
                    459:        }
                    460: 
                    461:        nHeight = -((16 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    462:        lf.lfHeight = nHeight;
                    463:        lf.lfWeight = FW_REGULAR;
                    464:        hTitleFont = CreateFontIndirect (&lf);
                    465:        if (hTitleFont == NULL)
                    466:        {
                    467:                handleWin32Error (hwndDlg);
                    468:                AbortProcess (IDS_NOFONT);
                    469:        }
                    470: 
                    471:        nHeight = -((9 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
                    472:        lf.lfHeight = nHeight;
                    473:        lf.lfWidth = 0;
                    474:        lf.lfEscapement = 0;
                    475:        lf.lfOrientation = 0;
                    476:        lf.lfWeight = FW_NORMAL;
                    477:        lf.lfItalic = FALSE;
                    478:        lf.lfUnderline = FALSE;
                    479:        lf.lfStrikeOut = FALSE;
                    480:        lf.lfCharSet = DEFAULT_CHARSET;
                    481:        lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
                    482:        lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
                    483:        lf.lfQuality = PROOF_QUALITY;
                    484:        lf.lfPitchAndFamily = FF_DONTCARE;
                    485:        strcpy (lf.lfFaceName, "Lucida Console");
                    486:        hFixedFont = CreateFontIndirect (&lf);
                    487:        if (hFixedFont == NULL)
                    488:        {
                    489:                handleWin32Error (hwndDlg);
                    490:                AbortProcess (IDS_NOFONT);
                    491:        }
                    492: 
                    493:        hMenu = GetSystemMenu (hwndDlg, FALSE);
                    494:        AppendMenu (hMenu, MF_SEPARATOR, 0, NULL);
                    495:        AppendMenu (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, getstr (IDS_ABOUTBOX));
                    496: }
                    497: 
                    498: HDC
                    499: CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, char *resource)
                    500: {
                    501:        HBITMAP picture = LoadBitmap (hInstance, resource);
                    502:        HDC viewDC = GetDC (hwnd), dcMem;
                    503: 
                    504:        dcMem = CreateCompatibleDC (viewDC);
                    505: 
                    506:        SetMapMode (dcMem, MM_TEXT);
                    507: 
                    508:        SelectObject (dcMem, picture);
                    509: 
                    510:        ReleaseDC (hwnd, viewDC);
                    511: 
                    512:        return dcMem;
                    513: }
                    514: 
                    515: /* Draw the specified bitmap at the specified location - Stretch to fit. */
                    516: void
                    517: PaintBitmap (HDC pdcMem, int x, int y, int nWidth, int nHeight, HDC hDC)
                    518: {
                    519:        HGDIOBJ picture = GetCurrentObject (pdcMem, OBJ_BITMAP);
                    520: 
                    521:        BITMAP bitmap;
                    522:        GetObject (picture, sizeof (BITMAP), &bitmap);
                    523: 
                    524:        BitBlt (hDC, x, y, nWidth, nHeight, pdcMem, 0, 0, SRCCOPY);
                    525: }
                    526: 
                    527: LRESULT CALLBACK
                    528: SplashDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                    529: {
                    530: 
                    531:        //if (uMsg == WM_ERASEBKGND)
                    532:        //{
                    533:        //      NONCLIENTMETRICS metric;
                    534:        //      HFONT font;
                    535: 
                    536: 
                    537:        //      HDC hDC = (HDC) wParam;
                    538:        //      char szTmp[64];
                    539:        //      HGDIOBJ obj;
                    540:        //      WORD bx = LOWORD (GetDialogBaseUnits ());
                    541:        //      WORD by = HIWORD (GetDialogBaseUnits ());
                    542: 
                    543: 
                    544:        //      DefDlgProc (hwnd, uMsg, wParam, lParam);
                    545: 
                    546:        //      SetBkMode (hDC, TRANSPARENT);
                    547:        //      SetTextColor (hDC, RGB (0, 0, 100));
                    548:        //      obj = SelectObject (hDC, hTitleFont);
                    549: 
                    550:        //      metric.cbSize = sizeof (NONCLIENTMETRICS);
                    551:        //      SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &metric, 0);
                    552:        //      font = CreateFontIndirect (&metric.lfMessageFont);
                    553:        //      obj = SelectObject (hDC, font);
                    554: 
                    555:        //      TextOut (hDC, (12 * bx) / 4, (70 * by) / 8, szTmp, strlen (szTmp));
                    556: 
                    557:        //      SelectObject (hDC, obj);
                    558:        //      return TRUE;
                    559:        //}
                    560: 
                    561:        return DefDlgProc (hwnd, uMsg, wParam, lParam);
                    562: }
                    563: 
                    564: void
                    565: WaitCursor ()
                    566: {
                    567:        static HCURSOR hcWait;
                    568:        if (hcWait == NULL)
                    569:                hcWait = LoadCursor (NULL, IDC_WAIT);
                    570:        SetCursor (hcWait);
                    571:        hCursor = hcWait;
                    572: }
                    573: 
                    574: void
                    575: NormalCursor ()
                    576: {
                    577:        static HCURSOR hcArrow;
                    578:        if (hcArrow == NULL)
                    579:                hcArrow = LoadCursor (NULL, IDC_ARROW);
                    580:        SetCursor (hcArrow);
                    581:        hCursor = NULL;
                    582: }
                    583: 
                    584: void
                    585: ArrowWaitCursor ()
                    586: {
                    587:        static HCURSOR hcArrowWait;
                    588:        if (hcArrowWait == NULL)
                    589:                hcArrowWait = LoadCursor (NULL, IDC_APPSTARTING);
                    590:        SetCursor (hcArrowWait);
                    591:        hCursor = hcArrowWait;
                    592: }
                    593: 
                    594: LRESULT CALLBACK
                    595: CustomDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                    596: {
                    597:        if (uMsg == WM_SETCURSOR && hCursor != NULL)
                    598:        {
                    599:                SetCursor (hCursor);
                    600:                return TRUE;
                    601:        }
                    602: 
                    603:        return DefDlgProc (hwnd, uMsg, wParam, lParam);
                    604: }
                    605: 
                    606: /* InitApp - initialize the application, this function is called once in the
                    607:    applications WinMain function, but before the main dialog has been created */
                    608: void
                    609: InitApp (HINSTANCE hInstance)
                    610: {
                    611:        WNDCLASS wc;
                    612:        char *lpszTmp;
                    613:        OSVERSIONINFO os;
                    614: 
                    615:        /* Save the instance handle for later */
                    616:        hInst = hInstance;
                    617: 
                    618:        /* Pull down the windows version */
                    619:        os.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
                    620:        if (GetVersionEx (&os) == FALSE)
                    621:                AbortProcess (IDS_NO_OS_VER);
                    622:        else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)
                    623:                nCurrentOS = WIN_NT;
                    624:        else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 0)
                    625:                nCurrentOS = WIN_95;
                    626:        else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 10)
                    627:                nCurrentOS = WIN_98;
                    628:        else {
                    629:        /*      AbortProcess (IDS_NO_OS_VER); */
                    630:                nCurrentOS = WIN_98;
                    631:        }
                    632: 
                    633:        CurrentOSMajor = os.dwMajorVersion;
                    634:        CurrentOSMinor = os.dwMinorVersion;
                    635: 
                    636:        /* Get the attributes for the standard dialog class */
                    637:        if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0)
                    638:                AbortProcess (IDS_INIT_REGISTER);
                    639: 
                    640: #ifndef SETUP
                    641:        wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON));
                    642: #else
                    643: #include "../setup/resource.h"
                    644:        wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_SETUP));
                    645: #endif
                    646:        wc.lpszClassName = TC_DLG_CLASS;
                    647:        wc.lpfnWndProc = &CustomDlgProc;
                    648:        wc.hCursor = LoadCursor (NULL, IDC_ARROW);
                    649:        wc.cbWndExtra = DLGWINDOWEXTRA;
                    650: 
                    651:        hDlgClass = RegisterClass (&wc);
                    652:        if (hDlgClass == 0)
                    653:                AbortProcess (IDS_INIT_REGISTER);
                    654: 
                    655:        wc.lpszClassName = TC_SPLASH_CLASS;
                    656:        wc.lpfnWndProc = &SplashDlgProc;
                    657:        wc.hCursor = LoadCursor (NULL, IDC_ARROW);
                    658:        wc.cbWndExtra = DLGWINDOWEXTRA;
                    659: 
                    660:        hSplashClass = RegisterClass (&wc);
                    661:        if (hSplashClass == 0)
                    662:                AbortProcess (IDS_INIT_REGISTER);
                    663: 
                    664:        GetModuleFileName (NULL, szHelpFile, sizeof (szHelpFile));
                    665:        lpszTmp = strrchr (szHelpFile, '\\');
                    666:        if (lpszTmp)
                    667:        {
                    668:                strcpy (++lpszTmp, "TrueCrypt User Guide.pdf");
                    669:        }
                    670: 
                    671:        hMutex = CreateMutex (NULL, TRUE, lpszTitle);
                    672:        if (hMutex == NULL)
                    673:        {
                    674:                handleWin32Error (NULL);
                    675:                AbortProcess (IDS_INIT_MUTEX);
                    676:        }
                    677: 
                    678:        if (GetLastError ()== ERROR_ALREADY_EXISTS)
                    679:        {
                    680:                // If executed twice, just top the first instance and exit
                    681:                HWND h = FindWindow (0, lpszTitle);
                    682:                if (h != 0)
                    683:                {
                    684:                        ShowWindow (h, SW_SHOWNORMAL);
                    685:                        SetForegroundWindow (h);
                    686:                        exit (1);
                    687:                }
                    688:                else
                    689:                        AbortProcess (IDS_TWO_INSTANCES);
                    690:        }
                    691: 
                    692: #ifndef SETUP
                    693:        /* Setup the service if it's not present */
                    694:        if (CheckService ()== FALSE)
                    695:                AbortProcess (IDS_NOSERVICE);
                    696: #endif
                    697: 
                    698: }
                    699: 
                    700: BOOL
                    701: InstallService (SC_HANDLE schSCManager, char *SZSERVICENAME, char *SZSERVICEDISPLAYNAME)
                    702: {
                    703:        SC_HANDLE schService;
                    704: 
                    705:        schService = CreateService (
                    706:                                           schSCManager,        /* SCManager database */
                    707:                                           SZSERVICENAME,       /* name of service */
                    708:                                           SZSERVICEDISPLAYNAME,        /* name to display */
                    709:                                           SERVICE_ALL_ACCESS,  /* desired access */
                    710:                                           SERVICE_WIN32_OWN_PROCESS,   /* service type */
                    711:                                           SERVICE_AUTO_START,  /* start type */
                    712:                                           SERVICE_ERROR_NORMAL,        /* error control type */
                    713:                                           "TrueCryptService.exe",      /* service's binary */
                    714:                                           NULL,        /* no load ordering
                    715:                                                           group */
                    716:                                           NULL,        /* no tag identifier */
                    717:                                           "",  /* dependencies */
                    718:                                           NULL,        /* LocalSystem account */
                    719:                                           NULL);       /* no password */
                    720: 
                    721:        if (schService != NULL)
                    722:        {
                    723:                CloseServiceHandle (schService);
                    724:                return TRUE;
                    725:        }
                    726: 
                    727:        return FALSE;
                    728: }
                    729: 
                    730: BOOL
                    731: CheckService ()
                    732: {
                    733: 
                    734:        SC_HANDLE schService = NULL;
                    735:        SC_HANDLE schSCManager = NULL;
                    736:        BOOL bInstall = FALSE;
                    737:        BOOL bAdmin = TRUE;
                    738:        BOOL bResult = TRUE;
                    739: 
                    740:        if (nCurrentOS != WIN_NT)
                    741:                return TRUE;
                    742: 
                    743:        schSCManager = OpenSCManager (
                    744:                                             NULL,      /* machine (NULL ==
                    745:                                                           local) */
                    746:                                             NULL,      /* database (NULL ==
                    747:                                                           default) */
                    748:                                             SC_MANAGER_ALL_ACCESS      /* access required */
                    749:            );
                    750: 
                    751:        if (schSCManager == NULL)
                    752:        {
                    753:                schSCManager = OpenSCManager (
                    754:                                                     NULL,      /* machine (NULL ==
                    755:                                                                   local) */
                    756:                                                     NULL,      /* database (NULL ==
                    757:                                                                   default) */
                    758:                                                     SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS   /* access required */
                    759:                    );
                    760: 
                    761:                bAdmin = FALSE;
                    762:        }
                    763: 
                    764:        if (schSCManager == NULL)
                    765:                goto error;
                    766: 
                    767:        if (bAdmin == TRUE)
                    768:                schService = OpenService (schSCManager, "TrueCryptService", SERVICE_ALL_ACCESS);
                    769:        else
                    770:                schService = OpenService (schSCManager, "TrueCryptService", SERVICE_QUERY_STATUS);
                    771: 
                    772:        if (schService == NULL)
                    773:        {
                    774:                BOOL bOK;
                    775: 
                    776:                if (bAdmin == FALSE)
                    777:                {
                    778:                        handleWin32Error (NULL);
                    779:                        CloseServiceHandle (schSCManager);
                    780: #ifndef SETUP
                    781:                        AbortProcess (IDS_NOSERVICE);
                    782: #else
                    783:                        return FALSE;
                    784: #endif
                    785:                }
                    786: 
                    787:                if (bInstall == TRUE)
                    788:                        goto error;
                    789: 
                    790:                bInstall = TRUE;
                    791: 
                    792:                bOK = InstallService (schSCManager, "TrueCryptService", "TrueCrypt Service");
                    793: 
                    794:                if (bOK == FALSE)
                    795:                        goto error;
                    796: 
                    797:                schService = OpenService (schSCManager, "TrueCryptService", SERVICE_ALL_ACCESS);
                    798:        }
                    799: 
                    800:        if (schService != NULL)
                    801:        {
                    802:                SERVICE_STATUS status;
                    803:                BOOL bOK;
                    804:                int i;
                    805: 
                    806:                bOK = QueryServiceStatus (schService, &status);
                    807: 
                    808:                if (bOK == FALSE)
                    809:                        goto error;
                    810: 
                    811:                if (status.dwCurrentState == SERVICE_RUNNING || status.dwCurrentState == SERVICE_START_PENDING)
                    812:                        goto success;
                    813: 
                    814:                if (bAdmin == FALSE)
                    815:                {
                    816:                        CloseServiceHandle (schService);
                    817:                        CloseServiceHandle (schSCManager);
                    818: #ifndef SETUP
                    819:                        AbortProcess (IDS_SERVICE_NOT_RUNNING);
                    820: #else
                    821:                        return FALSE;
                    822: #endif
                    823: 
                    824:                }
                    825: 
                    826:                bOK = StartService (schService, 0, NULL);
                    827: 
                    828:                if (bOK == FALSE)
                    829:                        goto error;
                    830: 
                    831: #define WAIT_PERIOD 3
                    832: 
                    833:                for (i = 0; i < WAIT_PERIOD; i++)
                    834:                {
                    835:                        Sleep (1000);
                    836:                        bOK = QueryServiceStatus (schService, &status);
                    837: 
                    838:                        if (bOK == FALSE)
                    839:                                goto error;
                    840: 
                    841: 
                    842:                        if (status.dwCurrentState == SERVICE_RUNNING)
                    843:                                break;
                    844:                }
                    845: 
                    846:                if (i == WAIT_PERIOD)
                    847:                        bOK = FALSE;
                    848: 
                    849:                if (bOK == FALSE)
                    850:                        goto error;
                    851:                else
                    852:                        goto success;
                    853:        }
                    854: 
                    855: 
                    856:       error:
                    857:        if (GetLastError ()!= 0)
                    858:                handleWin32Error (NULL);
                    859: 
                    860:        bResult = FALSE;
                    861: 
                    862:       success:
                    863:        if (schService != NULL)
                    864:                CloseServiceHandle (schService);
                    865: 
                    866:        if (schSCManager != NULL)
                    867:                CloseServiceHandle (schSCManager);
                    868: 
                    869:        return bResult;
                    870: }
                    871: 
                    872: BOOL
                    873: OpenDevice (char *lpszPath, OPEN_TEST_STRUCT * driver)
                    874: {
                    875:        DWORD dwResult;
                    876:        BOOL bResult;
                    877: 
                    878:        strcpy ((char *) &driver->wszFileName[0], lpszPath);
                    879: 
                    880:        if (nCurrentOS == WIN_NT)
                    881:                ToUNICODE ((char *) &driver->wszFileName[0]);
                    882: 
                    883:        bResult = DeviceIoControl (hDriver, OPEN_TEST,
                    884:                                   driver, sizeof (OPEN_TEST_STRUCT),
                    885:                                   &driver, sizeof (OPEN_TEST_STRUCT),
                    886:                                   &dwResult, NULL);
                    887: 
                    888:        if (bResult == FALSE)
                    889:        {
                    890:                dwResult = GetLastError ();
                    891:                if (dwResult == ERROR_SHARING_VIOLATION)
                    892:                        return TRUE;
                    893:                else
                    894:                        return FALSE;
                    895:        }
                    896:        else
                    897:        {
                    898:                if (nCurrentOS == WIN_NT)
                    899:                        return TRUE;
                    900:                else if (driver->nReturnCode == 0)
                    901:                        return TRUE;
                    902:                else
                    903:                {
                    904:                        SetLastError (ERROR_FILE_NOT_FOUND);
                    905:                        return FALSE;
                    906:                }
                    907:        }
                    908: }
                    909: 
                    910: UINT _stdcall
                    911: win9x_io (HFILE hFile, char *lpBuffer, UINT uBytes)
                    912: {
                    913:        DISKIO_STRUCT *win9x_r0 = (DISKIO_STRUCT *) hFile;
                    914:        DWORD dwResult;
                    915:        BOOL bResult;
                    916:        LONG secs;
                    917: 
                    918:        win9x_r0->bufferad = (void *) lpBuffer;
                    919: 
                    920:        secs = uBytes / SECTOR_SIZE;
                    921: 
                    922:        win9x_r0->sectorlen = secs;
                    923: 
                    924:        bResult = DeviceIoControl (hDriver, DISKIO, win9x_r0, sizeof (DISKIO_STRUCT), win9x_r0,
                    925:                                   sizeof (DISKIO_STRUCT), &dwResult, NULL);
                    926: 
                    927:        if (bResult == FALSE || win9x_r0->nReturnCode != 0)
                    928:                return (UINT) HFILE_ERROR;
                    929: 
                    930:        win9x_r0->sectorstart += secs;
                    931: 
                    932:        return uBytes;
                    933: }
                    934: 
                    935: int
                    936: GetAvailableFixedDisks (HWND hComboBox, char *lpszRootPath)
                    937: {
                    938:        int i, n;
                    939:        int line = 0;
                    940: 
                    941:        for (i = 0; i < 64; i++)
                    942:        {
                    943:                BOOL drivePresent = FALSE;
                    944: 
                    945:                for (n = 1; n <= 32; n++)
                    946:                {
                    947:                        char szTmp[TC_MAX_PATH], item1[100]={0}, item2[100]={0};
                    948:                        OPEN_TEST_STRUCT driver;
                    949: 
                    950:                        sprintf (szTmp, lpszRootPath, i, n);
                    951:                        if (OpenDevice (szTmp, &driver) == TRUE)
                    952:                        {
                    953:                                int nDosLinkCreated;
                    954:                                HANDLE dev;
                    955:                                DWORD dwResult;
                    956:                                BOOL bResult;
                    957:                                PARTITION_INFORMATION diskInfo;
                    958:                                
                    959:                                LVITEM LvItem;
                    960: 
                    961:                                char szDosDevice[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
                    962: 
                    963:                                if(!drivePresent)
                    964:                                {
                    965:                                        LVITEM LvItem;
                    966:                                        memset(&LvItem,0,sizeof(LvItem));
                    967:                                        LvItem.mask=LVIF_TEXT;
                    968:                                        LvItem.iItem= line++;
                    969: 
                    970:                                        sprintf(szDosDevice, " Harddisk %d:", i);
                    971:                                        LvItem.pszText = szDosDevice;
                    972:                                        SendMessage(hComboBox, LVM_INSERTITEM, 0, (LPARAM)&LvItem);
                    973:                                }
                    974:                                drivePresent = TRUE;
                    975: 
                    976:                                if (nCurrentOS == WIN_NT)
                    977:                                {
                    978:                                        nDosLinkCreated = FakeDosNameForDevice (szTmp, szDosDevice,
                    979:                                                szCFDevice, FALSE);
                    980: 
                    981:                                        dev = CreateFile (szCFDevice, GENERIC_READ, FILE_SHARE_WRITE , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
                    982: 
                    983:                                        bResult = DeviceIoControl (dev, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0,
                    984:                                                &diskInfo, sizeof (diskInfo), &dwResult, NULL);
                    985: 
                    986:                                        RemoveFakeDosName(szTmp, szDosDevice);
                    987:                                        CloseHandle(dev);
                    988: 
                    989:                                        if (bResult == TRUE)
                    990:                                        {
                    991:                                                char partType[100];
                    992: 
                    993:                                                switch(diskInfo.PartitionType)
                    994:                                                {
                    995:                                                case PARTITION_ENTRY_UNUSED:    strcpy(partType, "Empty"); break;
                    996:                                                case PARTITION_EXTENDED:                strcpy(partType, "Extended"); break;
                    997:                                                case PARTITION_HUGE:                    strcpy(partType, "FAT"); break;
                    998:                                                case PARTITION_FAT_12:                  strcpy(partType, "FAT12"); break;
                    999:                                                case PARTITION_FAT_16:                  strcpy(partType, "FAT16"); break;
                   1000:                                                case PARTITION_FAT32:           
                   1001:                                                case PARTITION_FAT32_XINT13:    strcpy(partType, "FAT32"); break;
                   1002:                                                case 0x11:
                   1003:                                                case 0x14:
                   1004:                                                case 0x16:
                   1005:                                                case 0x1b:
                   1006:                                                case 0x1c:
                   1007:                                                case 0x1e:                                              strcpy(partType, "Hidden FAT"); break;
                   1008:                                                case PARTITION_IFS:                             strcpy(partType, "NTFS"); break;
                   1009:                                                case 0x17:                                              strcpy(partType, "Hidden NTFS"); break;
                   1010:                                                case PARTITION_LDM:                             strcpy(partType, "LDM"); break;
                   1011:                                                case PARTITION_UNIX:                    strcpy(partType, "UNIX"); break;
                   1012:                                                case 0x83:                                              strcpy(partType, "Linux"); break;
                   1013:                                                case 0x82:                                              strcpy(partType, "Linux Swap"); break;
                   1014: 
                   1015:                                                default:                                                sprintf(partType, "Unknown (0x%02x)", diskInfo.PartitionType); break;
                   1016:                                                }
                   1017: 
                   1018:                                                if(diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024)
                   1019:                                                        sprintf (item1,"%.1f GB",(double)(diskInfo.PartitionLength.QuadPart/1024.0/1024/1024));
                   1020:                                                else
                   1021:                                                        sprintf (item1,"%d MB", diskInfo.PartitionLength.QuadPart/1024/1024);
                   1022: 
                   1023:                                                strcpy (item2, partType);
                   1024:                                        }
                   1025:                                }
                   1026: 
                   1027:                                memset(&LvItem,0,sizeof(LvItem));
                   1028:                                LvItem.mask=LVIF_TEXT;   
                   1029:                                LvItem.iItem= line++;   
                   1030: 
                   1031:                                LvItem.pszText=szTmp;
                   1032:                                SendMessage(hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
                   1033: 
                   1034:                                LvItem.iSubItem=1;
                   1035:                                LvItem.pszText=item1;
                   1036:                                SendMessage(hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem); 
                   1037: 
                   1038:                                LvItem.iSubItem=2;
                   1039:                                LvItem.pszText=item2;
                   1040:                                SendMessage(hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem); 
                   1041:                        }
                   1042: 
                   1043: 
1.1.1.2   root     1044:                }
                   1045: 
                   1046:                if(drivePresent)
                   1047:                {
                   1048:                        LVITEM LvItem;
                   1049:                        memset(&LvItem,0,sizeof(LvItem));
                   1050:                        LvItem.mask=LVIF_TEXT;   
                   1051:                        LvItem.iItem= line++;   
                   1052: 
                   1053:                        LvItem.pszText="";
                   1054:                        SendMessage(hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
1.1       root     1055:                }
                   1056:        }
                   1057: 
                   1058:        i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0);
                   1059:        if (i != CB_ERR)
                   1060:                return i;
                   1061:        else
                   1062:                return 0;
                   1063: }
                   1064: 
                   1065: int
                   1066: GetAvailableRemovables (HWND hComboBox, char *lpszRootPath)
                   1067: {
                   1068:        char szTmp[TC_MAX_PATH];
                   1069:        int i;
                   1070:        LVITEM LvItem;
                   1071: 
                   1072:        if (lpszRootPath);      /* Remove unused parameter warning */
                   1073: 
                   1074:        if (nCurrentOS != WIN_NT)
                   1075:                return 0;
                   1076: 
                   1077:        memset(&LvItem,0,sizeof(LvItem));
                   1078:        LvItem.mask = LVIF_TEXT;   
                   1079:        LvItem.iItem = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0)+1;   
                   1080: 
                   1081:        if (QueryDosDevice ("A:", szTmp, sizeof (szTmp)) != 0)
                   1082:        {
                   1083:                LvItem.pszText="Floppy (A:)";
                   1084:                SendMessage(hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
                   1085:        }
                   1086:        if (QueryDosDevice ("B:", szTmp, sizeof (szTmp)) != 0)
                   1087:        {
                   1088:                LvItem.pszText="Floppy (B:)";
                   1089:                SendMessage(hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
                   1090:        }
                   1091: 
                   1092:        i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0);
                   1093:        if (i != CB_ERR)
                   1094:                return i;
                   1095:        else
                   1096:                return 0;
                   1097: }
                   1098: 
                   1099: BOOL WINAPI
                   1100: RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
                   1101: {
                   1102:        static char *lpszFileName;
                   1103:        WORD lw = LOWORD (wParam);
                   1104: 
                   1105:        if (lParam);            /* remove warning */
                   1106: 
                   1107:        switch (msg)
                   1108:        {
                   1109:        case WM_INITDIALOG:
                   1110:                {
                   1111:                        int nCount;
                   1112:                        LVCOLUMN LvCol;
                   1113:                        HWND hList = GetDlgItem (hwndDlg, IDC_DEVICELIST);
                   1114: 
                   1115:                        SetDefaultUserFont (hwndDlg);
                   1116: 
                   1117:                        SendMessage(hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
                   1118:                                LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_TWOCLICKACTIVATE 
                   1119:                                ); 
                   1120: 
                   1121:                        memset(&LvCol,0,sizeof(LvCol));               
                   1122:                        LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;  
                   1123:                        LvCol.pszText = "Device";                           
                   1124:                        LvCol.cx =160;
                   1125:                        LvCol.fmt = LVCFMT_LEFT;
                   1126:                        SendMessage(hList,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol);
                   1127: 
                   1128:                        LvCol.pszText = "Size";  
                   1129:                        LvCol.cx = 64;           
                   1130:                        LvCol.fmt = LVCFMT_RIGHT;
                   1131:                        SendMessage(hList,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol);
                   1132: 
                   1133:                        LvCol.pszText = "Type";  
                   1134:                        LvCol.cx = 92;
                   1135:                        LvCol.fmt = LVCFMT_LEFT;
                   1136:                        SendMessage(hList,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol);
                   1137: 
                   1138:                        nCount = GetAvailableFixedDisks (hList, "\\Device\\Harddisk%d\\Partition%d");
                   1139:                        nCount += GetAvailableRemovables (hList, "\\Device\\Floppy%d");
                   1140: 
                   1141:                        if (nCount == 0)
                   1142:                        {
                   1143:                                handleWin32Error (hwndDlg);
                   1144:                                MessageBox (hwndDlg, getstr (IDS_RAWDEVICES), lpszTitle, ICON_HAND);
                   1145:                                EndDialog (hwndDlg, IDCANCEL);
                   1146:                        }
                   1147: 
                   1148:                        lpszFileName = (char *) lParam;
                   1149:                        return 1;
                   1150:                }
                   1151: 
                   1152:        case WM_COMMAND:
                   1153:        case WM_NOTIFY:
                   1154: 
                   1155:                // catch non-device line selected
                   1156:                if (msg == WM_NOTIFY && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
                   1157:                {
                   1158:                        LVITEM LvItem;
                   1159:                        memset(&LvItem,0,sizeof(LvItem));
                   1160:                        LvItem.mask = LVIF_TEXT;   
                   1161:                        LvItem.iItem = ((LPNMLISTVIEW) lParam)->iItem;
                   1162:                        LvItem.pszText = lpszFileName;
                   1163:                        LvItem.cchTextMax = TC_MAX_PATH;
                   1164: 
                   1165:                        SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
                   1166:                        EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), lpszFileName[0] != 0 && lpszFileName[0] != ' ');
                   1167:                        return 1;
                   1168:                }
                   1169: 
                   1170:                if (msg == WM_COMMAND && lw == IDOK || msg == WM_NOTIFY && ((NMHDR *)lParam)->code == LVN_ITEMACTIVATE)
                   1171:                {
                   1172:                        LVITEM LvItem;
                   1173:                        memset(&LvItem,0,sizeof(LvItem));
                   1174:                        LvItem.mask = LVIF_TEXT;   
                   1175:                        LvItem.iItem =  SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETSELECTIONMARK, 0, 0);
                   1176:                        LvItem.pszText = lpszFileName;
                   1177:                        LvItem.cchTextMax = TC_MAX_PATH;
                   1178: 
                   1179:                        SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
                   1180: 
                   1181:                        if(lpszFileName[0]==0 || lpszFileName[0]==' ')
                   1182:                                break; // non-device line selected
                   1183: 
                   1184:                        EndDialog (hwndDlg, IDOK);
                   1185:                        return 0;
                   1186:                }
                   1187: 
                   1188:                if (lw == IDCANCEL)
                   1189:                {
                   1190:                        EndDialog (hwndDlg, IDCANCEL);
                   1191:                        return 0;
                   1192:                }
                   1193:                return 0;
                   1194:        }
                   1195: 
                   1196:        return 0;
                   1197: }
                   1198: 
                   1199: int
                   1200: DriverAttach (void)
                   1201: {
                   1202:        /* Try to open a handle to the device driver. It will be closed
                   1203:           later. */
                   1204: 
                   1205:        if (nCurrentOS == WIN_NT)
                   1206:                hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
                   1207:        else
                   1208:                hDriver = CreateFile (WIN9X_DRIVER_NAME, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
                   1209: 
                   1210:        if (hDriver == INVALID_HANDLE_VALUE)
                   1211:        {
                   1212:                return ERR_OS_ERROR;
                   1213:        }
                   1214: #ifndef SETUP // Don't check version during setup to allow removal of older version
                   1215:        else
                   1216:        {
                   1217:                LONG driver = 0;
                   1218:                DWORD dwResult;
                   1219: 
                   1220:                BOOL bResult = DeviceIoControl (hDriver, DRIVER_VERSION,
                   1221:                                   &driver, 4, &driver, 4, &dwResult, NULL);
                   1222: 
                   1223:                if (bResult == FALSE)
                   1224:                        return ERR_OS_ERROR;
                   1225:                else if (driver != VERSION_NUM)
                   1226:                        return ERR_DRIVER_VERSION;
                   1227:        }
                   1228: #endif
                   1229: 
                   1230:        if (nCurrentOS == WIN_98)
                   1231:        {
                   1232:                DWORD dwResult;
                   1233:                DeviceIoControl (hDriver, ALLOW_FAST_SHUTDOWN, NULL, 0, NULL, 0, &dwResult, NULL);
                   1234:        }
                   1235: 
                   1236:        return 0;
                   1237: }
                   1238: 
                   1239: BOOL
                   1240: BrowseFiles (HWND hwndDlg, UINT nTitleID, char *lpszFileName)
                   1241: {
                   1242:        OPENFILENAME ofn;
                   1243:        char szFileTitle[TC_MAX_PATH];
                   1244:        ZeroMemory (&ofn, sizeof (OPENFILENAME));
                   1245: 
                   1246:        *szFileTitle = *lpszFileName = 0;
                   1247:        ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; //sizeof (OPENFILENAME);
                   1248:        ofn.hwndOwner = hwndDlg;
                   1249:        ofn.lpstrFilter = "All Files (*.*)\0*.*\0TrueCrypt Volumes (*.tc)\0*.tc\0";
                   1250:        ofn.lpstrCustomFilter = NULL;
                   1251:        ofn.nFilterIndex = 1;
                   1252:        ofn.lpstrFile = lpszFileName;
                   1253:        ofn.nMaxFile = TC_MAX_PATH;
                   1254:        ofn.lpstrFileTitle = szFileTitle;
                   1255:        ofn.nMaxFileTitle = TC_MAX_PATH;
                   1256:        ofn.lpstrInitialDir = NULL;
                   1257:        ofn.lpstrTitle = getstr (nTitleID);
                   1258:        ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
                   1259:        //ofn.lpstrDefExt = "tc";
                   1260: 
                   1261:        if (!GetOpenFileName (&ofn))
                   1262:                return FALSE;
                   1263:        else
                   1264:                return TRUE;
                   1265: }
                   1266: 
                   1267: 
                   1268: void
                   1269: handleError (HWND hwndDlg, int code)
                   1270: {
                   1271:        char szTmp[512];
                   1272: 
                   1273:        switch (code)
                   1274:        {
                   1275:        case ERR_OS_ERROR:
                   1276:                handleWin32Error (hwndDlg);
                   1277:                break;
                   1278:        case ERR_OUTOFMEMORY:
                   1279:                MessageBox (hwndDlg, getstr (IDS_OUTOFMEMORY), lpszTitle, ICON_HAND);
                   1280:                break;
                   1281:        case ERR_PASSWORD_WRONG:
                   1282:                MessageBox (hwndDlg, getstr (IDS_PASSWORD_WRONG), lpszTitle, MB_ICONEXCLAMATION);
                   1283:                break;
                   1284:        case ERR_VOL_FORMAT_BAD:
                   1285:                MessageBox (hwndDlg, getstr (IDS_VOL_FORMAT_BAD), lpszTitle, ICON_HAND);
                   1286:                break;
                   1287:        case ERR_BAD_DRIVE_LETTER:
                   1288:                MessageBox (hwndDlg, getstr (IDS_BAD_DRIVE_LETTER), lpszTitle, ICON_HAND);
                   1289:                break;
                   1290:        case ERR_DRIVE_NOT_FOUND:
                   1291:                MessageBox (hwndDlg, getstr (IDS_NOT_FOUND), lpszTitle, ICON_HAND);
                   1292:                break;
                   1293:        case ERR_FILES_OPEN:
                   1294:                MessageBox (hwndDlg, getstr (IDS_OPENFILES_DRIVER), lpszTitle, ICON_HAND);
                   1295:                break;
                   1296:        case ERR_FILES_OPEN_LOCK:
                   1297:                MessageBox (hwndDlg, getstr (IDS_OPENFILES_LOCK), lpszTitle, ICON_HAND);
                   1298:                break;
                   1299:        case ERR_VOL_SIZE_WRONG:
                   1300:                MessageBox (hwndDlg, getstr (IDS_VOL_SIZE_WRONG), lpszTitle, ICON_HAND);
                   1301:                break;
                   1302:        case ERR_COMPRESSION_NOT_SUPPORTED:
                   1303:                MessageBox (hwndDlg, getstr (IDS_COMPRESSION_NOT_SUPPORTED), lpszTitle, ICON_HAND);
                   1304:                break;
                   1305:        case ERR_PASSWORD_CHANGE_VOL_TYPE:
                   1306:                MessageBox (hwndDlg, getstr (IDS_WRONG_VOL_TYPE), lpszTitle, ICON_HAND);
                   1307:                break;
                   1308:        case ERR_PASSWORD_CHANGE_VOL_VERSION:
                   1309:                MessageBox (hwndDlg, getstr (IDS_WRONG_VOL_VERSION), lpszTitle, ICON_HAND);
                   1310:                break;
                   1311:        case ERR_VOL_SEEKING:
                   1312:                MessageBox (hwndDlg, getstr (IDS_VOL_SEEKING), lpszTitle, ICON_HAND);
                   1313:                break;
                   1314:        case ERR_VOL_WRITING:
                   1315:                MessageBox (hwndDlg, getstr (IDS_VOL_WRITING), lpszTitle, ICON_HAND);
                   1316:                break;
                   1317:        case ERR_VOL_READING:
                   1318:                MessageBox (hwndDlg, getstr (IDS_VOL_READING), lpszTitle, ICON_HAND);
                   1319:                break;
                   1320:        case ERR_VOL_ALREADY_MOUNTED:
                   1321:                MessageBox (hwndDlg, getstr (IDS_VOL_ALREADY_MOUNTED), lpszTitle, ICON_HAND);
                   1322:                break;
                   1323:        case ERR_FILE_OPEN_FAILED:
                   1324:                MessageBox (hwndDlg, getstr (IDS_FILE_OPEN_FAILED), lpszTitle, ICON_HAND);
                   1325:                break;
                   1326:        case ERR_VOL_MOUNT_FAILED:
                   1327:                MessageBox (hwndDlg, getstr (IDS_VOL_MOUNT_FAILED), lpszTitle, MB_ICONEXCLAMATION);
                   1328:                break;
                   1329:        case ERR_NO_FREE_SLOTS:
                   1330:                MessageBox (hwndDlg, getstr (IDS_NO_FREE_SLOTS), lpszTitle, ICON_HAND);
                   1331:                break;
                   1332:        case ERR_NO_FREE_DRIVES:
                   1333:                MessageBox (hwndDlg, getstr (IDS_NO_FREE_DRIVES), lpszTitle, ICON_HAND);
                   1334:                break;
                   1335:        case ERR_INVALID_DEVICE:
                   1336:                MessageBox (hwndDlg, getstr (IDS_INVALID_DEVICE), lpszTitle, ICON_HAND);
                   1337:                break;
                   1338:        case ERR_ACCESS_DENIED:
                   1339:                MessageBox (hwndDlg, getstr (IDS_ACCESS_DENIED), lpszTitle, ICON_HAND);
                   1340:                break;
                   1341: 
                   1342:        case ERR_DRIVER_VERSION:
                   1343:                sprintf (szTmp, getstr (IDS_DRIVER_VERSION), VERSION_STRING);
                   1344:                MessageBox (hwndDlg, szTmp, lpszTitle, ICON_HAND);
                   1345:                break;
                   1346: 
                   1347:        case ERR_NEW_VERSION_REQUIRED:
                   1348:                MessageBox (hwndDlg, getstr (IDS_NEW_VERSION_REQUIRED), lpszTitle, ICON_HAND);
                   1349:                break;
                   1350: 
                   1351:        default:
                   1352:                sprintf (szTmp, getstr (IDS_UNKNOWN), code);
                   1353:                MessageBox (hwndDlg, szTmp, lpszTitle, ICON_HAND);
                   1354: 
                   1355:        }
                   1356: }
                   1357: 
                   1358: static BOOL CALLBACK SetDefaultUserFontEnum( HWND hwnd, LPARAM font)
                   1359: {
                   1360:        SendMessage (hwnd, WM_SETFONT, (WPARAM) font, 0);
                   1361:        return TRUE;
                   1362: }
                   1363: 
                   1364: void SetDefaultUserFont (HWND hwnd)
                   1365: {
                   1366:        NONCLIENTMETRICS metric;
                   1367: 
                   1368:        if (hUserFont == 0)
                   1369:        {
                   1370:                metric.cbSize = sizeof (NONCLIENTMETRICS);
                   1371:                SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &metric, 0);
                   1372: 
                   1373:                hUserFont = CreateFontIndirect (&metric.lfMessageFont);
                   1374: 
                   1375:                metric.lfMessageFont.lfUnderline = TRUE;
                   1376:                hUserUnderlineFont = CreateFontIndirect (&metric.lfMessageFont);
                   1377: 
                   1378:                metric.lfMessageFont.lfUnderline = FALSE;
                   1379:                metric.lfMessageFont.lfWeight = FW_BOLD;
                   1380:                hUserBoldFont = CreateFontIndirect (&metric.lfMessageFont);
                   1381:        }
                   1382: 
                   1383:        EnumChildWindows (hwnd, SetDefaultUserFontEnum, (LPARAM) hUserFont);
                   1384: }

unix.superglobalmegacorp.com

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