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

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

unix.superglobalmegacorp.com

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