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