|
|
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
1.1.1.5 ! root 4: TrueCrypt Foundation and Copyright (c) 2004 TrueCrypt Team. Unmodified
1.1.1.3 root 5: parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation
6: release. Please see the file license.txt for full license details. */
1.1 root 7:
8: #include "TCdefs.h"
1.1.1.5 ! root 9: #include <time.h>
! 10: #include <dbt.h>
1.1 root 11: #include "crypto.h"
12: #include "apidrvr.h"
13: #include "dlgcode.h"
14: #include "combo.h"
15: #include "registry.h"
16: #include "resource.h"
17: #include "cmdline.h"
18: #include "Mount.h"
19: #include "Password.h"
1.1.1.5 ! root 20: #include "../common/resource.h"
1.1 root 21:
22: BOOL bExplore = FALSE; /* Display explorer window after mount */
23: BOOL bBeep = FALSE; /* Donot beep after mount */
24: char szFileName[TC_MAX_PATH]; /* Volume to mount */
25: char szDriveLetter[3]; /* Drive Letter to mount */
1.1.1.5 ! root 26: char commandLineDrive = 0;
1.1 root 27: BOOL bCacheInDriver = FALSE; /* Cache any passwords we see */
28: BOOL bHistory = FALSE; /* Don't save history */
29: BOOL bHistoryCmdLine = FALSE; /* History control is always disabled */
30: BOOL bCloseDismountedWindows=TRUE; /* Close all open explorer windows of dismounted volume */
31: BOOL bWipeCacheOnExit = FALSE; /* Wipe password from chace on exit */
32:
1.1.1.5 ! root 33: BOOL bForceMount = FALSE; /* Mount volume even if host file/device already in use */
! 34: BOOL bForceUnmount = FALSE; /* Unmount volume even if it cannot be locked */
! 35:
1.1 root 36: BOOL bWipe = FALSE; /* Wipe driver passwords */
37: BOOL bAuto = FALSE; /* Do everything without user input */
38:
39: BOOL bQuiet = FALSE; /* No dialogs/messages */
1.1.1.3 root 40:
1.1.1.2 root 41: char commandLinePassword[MAX_PASSWORD + 1] = {0}; /* Password passed from command line */
1.1.1.5 ! root 42: int cmdUnmountDrive = 0; /* Volume drive letter to unmount (-1 = all) */
1.1 root 43:
44: #define VMOUNTED 1
45: #define VFREE 0
46:
47: int nCurrentShowType = 0; /* current display mode, mount, unmount etc */
1.1.1.5 ! root 48: int nSelectedDriveIndex = -1; /* Item number of selected drive */
1.1 root 49:
50: void
51: localcleanup (void)
52: {
53: /* Free the application title */
54: if (lpszTitle != NULL)
55: free (lpszTitle);
56:
57: /* Cleanup common code resources */
58: cleanup ();
59: }
60:
61: void
62: RefreshMainDlg (HWND hwndDlg)
63: {
64: int drive = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))));
65:
66: MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
67: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
68: EnableDisableButtons (hwndDlg);
69: }
70:
71: void
72: EndMainDlg (HWND hwndDlg)
73: {
74: MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.2 root 75: if (!bQuiet) SaveSettings (hwndDlg);
1.1 root 76:
77: if (bWipeCacheOnExit)
78: {
79: DWORD dwResult;
80: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
81: }
82:
83: EndDialog (hwndDlg, 0);
84: }
85:
86: void
87: EnableDisableButtons (HWND hwndDlg)
88: {
89: HWND hOKButton = GetDlgItem (hwndDlg, IDOK);
90: HWND hChangeButton = GetDlgItem (hwndDlg, IDC_CHANGE_PASSWORD);
91: HWND hVolume = GetDlgItem (hwndDlg, IDC_VOLUME);
92: BOOL bEnable = TRUE;
93: WORD x;
94:
95: x = LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST)));
96:
97: if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_VOLUME)) > 0)
98: {
99: EnableWindow (hOKButton, TRUE);
100: EnableMenuItem (GetMenu (hwndDlg), ID_MOUNT_VOLUME, MF_ENABLED);
101:
102: EnableWindow (hChangeButton, TRUE);
103: EnableMenuItem (GetMenu (hwndDlg), IDC_CHANGE_PASSWORD, MF_ENABLED);
104: }
105: else
106: {
107: EnableWindow (hOKButton, FALSE);
108: EnableMenuItem (GetMenu (hwndDlg), ID_MOUNT_VOLUME, MF_GRAYED);
109:
110: EnableWindow (hChangeButton, FALSE);
111: EnableMenuItem (GetMenu (hwndDlg), IDC_CHANGE_PASSWORD, MF_GRAYED);
112: }
113:
114: if (x == VFREE)
115: {
116: SetWindowText (hOKButton, getstr (IDS_MOUNT_BUTTON));
117:
118: EnableMenuItem (GetMenu (hwndDlg), ID_UNMOUNT_VOLUME, MF_GRAYED);
119: }
120:
121: if (x == VMOUNTED)
122: {
123: SetWindowText (hOKButton, getstr (IDS_UNMOUNT_BUTTON));
124: EnableWindow (hOKButton, TRUE);
125:
126: EnableMenuItem (GetMenu (hwndDlg), ID_MOUNT_VOLUME, MF_GRAYED);
127: EnableMenuItem (GetMenu (hwndDlg), ID_UNMOUNT_VOLUME, MF_ENABLED);
128:
129: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), TRUE);
130: EnableMenuItem (GetMenu (hwndDlg), IDC_VOLUME_PROPERTIES, MF_ENABLED);
131: }
132: else
133: {
134: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), FALSE);
135: EnableMenuItem (GetMenu (hwndDlg), IDC_VOLUME_PROPERTIES, MF_GRAYED);
136: }
137:
138: EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
139: EnableMenuItem (GetMenu (hwndDlg), IDC_WIPE_CACHE, IsPasswordCacheEmpty() ? MF_GRAYED:MF_ENABLED);
140: EnableMenuItem (GetMenu (hwndDlg), IDC_CLEAR_HISTORY, IsComboEmpty (GetDlgItem (hwndDlg, IDC_VOLUME)) ? MF_GRAYED:MF_ENABLED);
141: }
142:
143: void
144: OpenPageHelp (HWND hwndDlg)
145: {
146: int r = (int)ShellExecute (NULL, "open", szHelpFile, NULL, NULL, SW_SHOWNORMAL);
147:
148: if (r == ERROR_FILE_NOT_FOUND)
149: MessageBox (hwndDlg, getstr (IDS_HELP_ERROR), lpszTitle, MB_ICONERROR);
150:
151: if (r == SE_ERR_NOASSOC)
152: MessageBox (hwndDlg, getstr (IDS_HELP_READER_ERROR), lpszTitle, MB_ICONERROR);
153: }
154:
155: void
156: LoadSettings (HWND hwndDlg)
157: {
158:
159: // Options
160: bCacheInDriver = ReadRegistryInt ("CachePasswordsInDriver", FALSE);
161: bExplore = ReadRegistryInt ("OpenExplorerWindowAfterMount", FALSE);
162: bCloseDismountedWindows = ReadRegistryInt ("CloseExplorerWindowsOnDismount", TRUE);
163: bHistory = ReadRegistryInt ("SaveMountedVolumesHistory", FALSE);
164: bWipeCacheOnExit = ReadRegistryInt ("WipePasswordCacheOnExit", FALSE);
165:
1.1.1.5 ! root 166: // Drive letter - command line arg overrides registry
! 167: if (szDriveLetter[0] == 0)
! 168: ReadRegistryString ("LastSelectedDrive", "", szDriveLetter, sizeof (szDriveLetter));
1.1 root 169:
170: // History
171: if (bHistoryCmdLine != TRUE)
172: LoadCombo (GetDlgItem (hwndDlg, IDC_VOLUME), "LastMountedVolume");
173: }
174:
175: void
176: SaveSettings (HWND hwndDlg)
177: {
178: char szTmp[32] = {0};
179: LPARAM lLetter;
180:
181: // Options
182: WriteRegistryInt ("CachePasswordsInDriver", bCacheInDriver);
183: WriteRegistryInt ("OpenExplorerWindowAfterMount", bExplore);
184: WriteRegistryInt ("CloseExplorerWindowsOnDismount", bCloseDismountedWindows);
185: WriteRegistryInt ("SaveMountedVolumesHistory", !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
186: WriteRegistryInt ("WipePasswordCacheOnExit", bWipeCacheOnExit);
187:
188: // Drive Letter
189: lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
190: if (LOWORD (lLetter) != 0xffff)
191: sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
192: WriteRegistryString ("LastSelectedDrive", szTmp);
193:
194: // History
195: DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), "LastMountedVolume", IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
196: }
197:
198: BOOL
199: SelectItem (HWND hTree, char nLetter)
200: {
201: int i;
202: LVITEM item;
203:
204: for (i = 0; i < ListView_GetItemCount(hTree); i++)
205: {
206: memset(&item, 0, sizeof(LVITEM));
207: item.mask = LVIF_PARAM;
208: item.iItem = i;
209:
210: if (ListView_GetItem (hTree, &item) == FALSE)
211: return FALSE;
212: else
213: {
214: if (HIWORD (item.lParam) == nLetter)
215: {
216: memset(&item, 0, sizeof(LVITEM));
217: item.state = LVIS_FOCUSED|LVIS_SELECTED;
218: item.stateMask = LVIS_FOCUSED|LVIS_SELECTED;
219: item.mask = LVIF_STATE;
220: item.iItem = i;
221: SendMessage(hTree, LVM_SETITEMSTATE, i, (LPARAM) &item);
222: return TRUE;
223: }
224: }
225:
226: }
227:
228: return TRUE;
229: }
230:
231:
232: // Fills drive list
233: // drive>0 = update only the corresponding drive subitems
234: void
235: LoadDriveLetters (HWND hTree, int drive)
236: {
237: char *szDriveLetters[]=
238: {"A:", "B:", "C:", "D:",
239: "E:", "F:", "G:", "H:", "I:", "J:", "K:",
240: "L:", "M:", "N:", "O:", "P:", "Q:", "R:",
241: "S:", "T:", "U:", "V:", "W:", "X:", "Y:",
242: "Z:"};
243:
244: DWORD dwResult;
245: BOOL bResult;
246: DWORD dwUsedDrives;
247: MOUNT_LIST_STRUCT driver;
248:
249: LVITEM listItem;
250: int item = 0;
251: char i;
252:
253: bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver,
254: sizeof (driver), &driver, sizeof (driver), &dwResult,
255: NULL);
256:
257: if (bResult == FALSE)
258: {
259: handleWin32Error (hTree);
260: driver.ulMountedDrives = 0;
261: }
262:
263: dwUsedDrives = GetLogicalDrives();
264: if (dwUsedDrives == 0 && bQuiet == FALSE)
265: MessageBox (hTree, getstr (IDS_DRIVELETTERS), lpszTitle, ICON_HAND);
266:
267: if(drive == 0)
268: ListView_DeleteAllItems(hTree);
269:
270: for (i = 2; i < 26; i++)
271: {
272: int curDrive = 0;
273:
274: if(drive > 0)
275: {
276: LVITEM tmp;
277: memset(&tmp, 0, sizeof(LVITEM));
278: tmp.mask = LVIF_PARAM;
279: tmp.iItem = item;
280: if (ListView_GetItem (hTree, &tmp) != FALSE)
281: curDrive = HIWORD(tmp.lParam);
282: }
283:
284: if ( driver.ulMountedDrives & (1 << i) )
285: {
286: char szTmp[256];
287:
288: memset(&listItem, 0, sizeof(listItem));
289:
290: listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
291: listItem.iImage = 1;
292: listItem.iItem = item++;
293:
294: if(drive > 0 && drive != curDrive)
295: continue;
296:
297: if (nCurrentOS == WIN_NT)
298: ToSBCS ((void *) driver.wszVolume[i]);
299:
300: if (memcmp (driver.wszVolume[i], "\\Device", 7) == 0)
301: sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]));
302: else
303: {
304: if (nCurrentOS == WIN_NT)
305: sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]) + 4);
306: else
307: sprintf (szTmp, "%s", (char *) driver.wszVolume[i]);
308: }
309:
310: listItem.pszText = szDriveLetters[i];
311: listItem.lParam = MAKELONG (VMOUNTED, i + 'A');
312:
313: if(drive == 0)
314: ListView_InsertItem (hTree, &listItem);
315: else
316: ListView_SetItem (hTree, &listItem);
317:
318: listItem.mask=LVIF_TEXT;
319: listItem.pszText = szTmp;
320:
321: listItem.iSubItem = 1;
1.1.1.5 ! root 322: ListView_SetItem (hTree, &listItem);
1.1 root 323:
1.1.1.5 ! root 324: if(driver.diskLength[i] > 1024I64*1024*1024*1024*1024*99)
! 325: sprintf (szTmp,"%I64d PB",driver.diskLength[i]/1024/1024/1024/1024/1024);
! 326: if(driver.diskLength[i] > 1024I64*1024*1024*1024*1024)
! 327: sprintf (szTmp,"%.1f PB",(double)(driver.diskLength[i]/1024.0/1024/1024/1024/1024));
! 328: else if(driver.diskLength[i] > 1024I64*1024*1024*1024*99)
! 329: sprintf (szTmp,"%I64d TB",driver.diskLength[i]/1024/1024/1024/1024);
! 330: else if(driver.diskLength[i] > 1024I64*1024*1024*1024)
! 331: sprintf (szTmp,"%.1f TB",(double)(driver.diskLength[i]/1024.0/1024/1024/1024));
! 332: else if(driver.diskLength[i] > 1024I64*1024*1024*99)
! 333: sprintf (szTmp,"%I64d GB",driver.diskLength[i]/1024/1024/1024);
! 334: else if(driver.diskLength[i] > 1024I64*1024*1024)
1.1 root 335: sprintf (szTmp,"%.1f GB",(double)(driver.diskLength[i]/1024.0/1024/1024));
336: else if(driver.diskLength[i] > 1024I64*1024)
337: sprintf (szTmp, "%I64d MB", driver.diskLength[i]/1024/1024);
338: else if(driver.diskLength[i] > 0)
339: sprintf (szTmp, "%I64d KB", driver.diskLength[i]/1024);
340: else
341: szTmp[0] = 0;
342:
343: listItem.iSubItem = 2;
1.1.1.5 ! root 344: ListView_SetItem (hTree, &listItem);
1.1 root 345:
1.1.1.5 ! root 346: EAGetName (szTmp, driver.ea[i]);
1.1 root 347: listItem.iSubItem = 3;
1.1.1.5 ! root 348: ListView_SetItem (hTree, &listItem);
1.1 root 349:
1.1.1.5 ! root 350: if (driver.hiddenVol[i] == FALSE)
! 351: sprintf (szTmp, "Normal");
! 352: else
! 353: sprintf (szTmp, "Hidden");
! 354: listItem.iSubItem = 4;
! 355: ListView_SetItem (hTree, &listItem);
1.1 root 356: }
357: else
358: {
359: if (!(dwUsedDrives & 1 << i))
360: {
361: if(drive > 0 && drive != HIWORD (GetSelectedLong (hTree)))
362: {
363: item++;
364: continue;
365: }
366:
367: memset(&listItem,0,sizeof(listItem));
368:
369: listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
370: listItem.iImage = 0;
371: listItem.iItem = item++;
372: listItem.pszText = szDriveLetters[i];
373: listItem.lParam = MAKELONG (VFREE, i + 'A');
374:
375: if(drive == 0)
376: ListView_InsertItem (hTree, &listItem);
377: else
378: ListView_SetItem (hTree, &listItem);
379:
380: listItem.mask=LVIF_TEXT;
381: listItem.pszText = "";
382: listItem.iSubItem = 1;
1.1.1.5 ! root 383: ListView_SetItem (hTree, &listItem);
1.1 root 384: listItem.iSubItem = 2;
1.1.1.5 ! root 385: ListView_SetItem (hTree, &listItem);
1.1 root 386: listItem.iSubItem = 3;
1.1.1.5 ! root 387: ListView_SetItem (hTree, &listItem);
! 388: listItem.iSubItem = 4;
! 389: ListView_SetItem (hTree, &listItem);
1.1 root 390:
391: }
392: }
393: }
394: }
395:
396:
397: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
398: should return nonzero if it processes the message, and zero if it does
399: not. - see DialogProc */
400: BOOL WINAPI
401: PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
402: {
403:
404: WORD lw = LOWORD (wParam);
405: WORD hw = HIWORD (wParam);
406:
407: if (lParam); /* remove warning */
408: if (hw); /* remove warning */
409:
410: switch (msg)
411: {
412: case WM_INITDIALOG:
413: {
414: UINT nID[4];
1.1.1.3 root 415: LPARAM nIndex;
416: HWND hComboBox = GetDlgItem (hwndDlg, IDC_HASH_CHANGE);
417: int i;
1.1 root 418:
1.1.1.5 ! root 419: nID[0] = IDS_PASSWORD_HELP1;
! 420: nID[1] = IDS_PASSWORD_HELP2;
! 421: nID[2] = IDS_PASSWORD_HELP3;
! 422: nID[3] = IDS_PASSWORD_HELP0;
1.1 root 423:
424: SetDefaultUserFont (hwndDlg);
425:
426: SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
427: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
428: SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
429: SetWindowText (GetDlgItem (hwndDlg, IDC_BOX_HELP), getmultilinestr (nID));
430: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
431:
1.1.1.3 root 432: SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
433:
434: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) "Unchanged");
435: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0);
436:
437: for (i = 1; i <= LAST_PRF_ID; i++)
438: {
439: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_hash_name(i));
440: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i);
441: }
442:
443: SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
444:
1.1.1.5 ! root 445: CheckCapsLock (hwndDlg, FALSE);
! 446:
1.1 root 447: return 1;
448: }
449:
450: case WM_COMMAND:
451: if (lw == IDCANCEL)
452: {
453: // Attempt to wipe passwords stored in the input field buffers
454: char tmp[MAX_PASSWORD+1];
455: memset (tmp, 'X', MAX_PASSWORD);
456: tmp[MAX_PASSWORD] = 0;
457:
458: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
459: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
460: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
461:
462: EndDialog (hwndDlg, IDCANCEL);
463: return 1;
464: }
465: if (hw == EN_CHANGE)
466: {
467: VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (hwndDlg, IDOK), GetDlgItem (hwndDlg, IDC_PASSWORD),
468: GetDlgItem (hwndDlg, IDC_VERIFY), NULL, NULL);
469: return 1;
470: }
471: if (lw == IDOK)
472: {
473: HWND hParent = GetParent (hwndDlg);
474: char szOldPassword[MAX_PASSWORD + 1];
475: char szPassword[MAX_PASSWORD + 1];
476: int nStatus;
1.1.1.3 root 477: int pkcs5 = SendMessage (GetDlgItem (hwndDlg, IDC_HASH_CHANGE), CB_GETITEMDATA,
478: SendMessage (GetDlgItem (hwndDlg, IDC_HASH_CHANGE), CB_GETCURSEL, 0, 0), 0);
1.1 root 479:
1.1.1.5 ! root 480: if (!CheckPasswordLength (hwndDlg, GetDlgItem (hwndDlg, IDC_PASSWORD)))
! 481: return 0;
! 482:
1.1 root 483: GetWindowText (GetDlgItem (hParent, IDC_VOLUME), szFileName, sizeof (szFileName));
484:
485: GetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), szOldPassword, sizeof (szOldPassword));
486:
487: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szPassword, sizeof (szPassword));
488:
1.1.1.5 ! root 489: nStatus = ChangePwd (szFileName, szOldPassword, szPassword, pkcs5, hwndDlg);
1.1 root 490:
491: burn (szOldPassword, sizeof (szOldPassword));
492: burn (szPassword, sizeof (szPassword));
493:
494: if (nStatus != 0)
495: handleError (hwndDlg, nStatus);
496: else
497: {
498: // Attempt to wipe passwords stored in the input field buffers
499: char tmp[MAX_PASSWORD+1];
500: memset (tmp, 'X', MAX_PASSWORD);
501: tmp[MAX_PASSWORD] = 0;
502: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
503: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
504: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
505:
506: EndDialog (hwndDlg, IDOK);
507: }
508:
509: return 1;
510: }
511: return 0;
512: }
513:
514: return 0;
515: }
516:
517: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
518: should return nonzero if it processes the message, and zero if it does
519: not. - see DialogProc */
520: BOOL WINAPI
521: PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
522: {
523: WORD lw = LOWORD (wParam);
524: static char* szXPwd;
525:
526: switch (msg)
527: {
528: case WM_INITDIALOG:
529: {
530: szXPwd = (char*) lParam;
531: SetDefaultUserFont (hwndDlg);
532: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
533: SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
534: return 1;
535: }
536:
537: case WM_COMMAND:
538:
539: if (lw == IDCANCEL || lw == IDOK)
540: {
541: char tmp[MAX_PASSWORD+1];
542:
543: if (lw == IDOK)
544: {
545: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szXPwd, MAX_PASSWORD + 1);
546: bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_CACHE));
547: }
548:
549: // Attempt to wipe password stored in the input field buffer
550: memset (tmp, 'X', MAX_PASSWORD);
551: tmp[MAX_PASSWORD] = 0;
552: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
553: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), 0);
554:
555: EndDialog (hwndDlg, lw);
556: return 1;
557: }
558: return 0;
559: }
560:
561: return 0;
562: }
563:
564: BOOL WINAPI
565: PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
566: {
567: WORD lw = LOWORD (wParam);
568:
569: switch (msg)
570: {
571: case WM_INITDIALOG:
572: {
573: SetDefaultUserFont (hwndDlg);
574:
575: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER), BM_SETCHECK,
576: bExplore ? BST_CHECKED:BST_UNCHECKED, 0);
577:
578: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS), BM_SETCHECK,
579: bCloseDismountedWindows ? BST_CHECKED:BST_UNCHECKED, 0);
580:
581: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT), BM_SETCHECK,
582: bWipeCacheOnExit ? BST_CHECKED:BST_UNCHECKED, 0);
583:
584: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS), BM_SETCHECK,
585: bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
586:
587:
588: return 1;
589: }
590:
591: case WM_COMMAND:
592:
593: if (lw == IDCANCEL)
594: {
595: EndDialog (hwndDlg, lw);
596: return 1;
597: }
598:
599: if (lw == IDOK)
600: {
601: bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER));
602: bCloseDismountedWindows = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS));
603: bWipeCacheOnExit = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT));
604: bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS));
605:
606: EndDialog (hwndDlg, lw);
607: return 1;
608: }
609: return 0;
610: }
611:
612: return 0;
613: }
614:
615: BOOL WINAPI
616: VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
617: {
618: WORD lw = LOWORD (wParam);
619:
620: switch (msg)
621: {
622: case WM_INITDIALOG:
623: {
624: VOLUME_PROPERTIES_STRUCT prop;
625: DWORD dwResult;
626: BOOL bResult;
627:
628: LVCOLUMN lvCol;
629: LVITEM listItem;
630: HWND list = GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES_LIST);
631: char szTmp[128];
632:
633: SetDefaultUserFont (hwndDlg);
634:
635: SendMessage (list,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
636: LVS_EX_FULLROWSELECT
637: |LVS_EX_HEADERDRAGDROP
638: //|LVS_EX_GRIDLINES
639: //|LVS_EX_TWOCLICKACTIVATE
640: );
641:
642: memset (&lvCol,0,sizeof(lvCol));
643: lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
644: lvCol.pszText = "Value";
1.1.1.5 ! root 645: lvCol.cx = 213;
1.1 root 646: lvCol.fmt = LVCFMT_LEFT ;
647: SendMessage (list,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
648:
649: lvCol.pszText = "Property";
1.1.1.5 ! root 650: lvCol.cx = 107;
1.1 root 651: lvCol.fmt = LVCFMT_LEFT;
652: SendMessage (list,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
653:
654:
655: memset (&prop, 0, sizeof(prop));
656: prop.driveNo = HIWORD (GetSelectedLong (GetDlgItem (GetParent(hwndDlg), IDC_DRIVELIST))) - 'A';
657:
658: bResult = DeviceIoControl (hDriver, VOLUME_PROPERTIES, &prop,
659: sizeof (prop), &prop, sizeof (prop), &dwResult,
660: NULL);
661:
662: memset (&listItem, 0, sizeof(listItem));
663:
664: listItem.mask = LVIF_TEXT;
665: listItem.iItem = -1;
666:
667: listItem.pszText = "Volume Location";
668: listItem.iItem++;
669: listItem.iSubItem = 0;
1.1.1.5 ! root 670: ListView_InsertItem (list, &listItem);
1.1 root 671: listItem.iSubItem++;
672: listItem.pszText = (LPSTR)prop.wszVolume;
673: if (nCurrentOS == WIN_NT)
674: {
675: ToSBCS (prop.wszVolume);
676: if (prop.wszVolume[0] == '?\\')
677: listItem.pszText = (LPSTR)prop.wszVolume + 4;
678: }
1.1.1.5 ! root 679: ListView_SetItem (list, &listItem);
1.1 root 680:
681: listItem.pszText = "Volume Size";
682: listItem.iItem++;
683: listItem.iSubItem = 0;
1.1.1.5 ! root 684: ListView_InsertItem (list, &listItem);
1.1 root 685: listItem.iSubItem++;
1.1.1.5 ! root 686: sprintf (szTmp, "%I64u bytes", prop.diskLength);
1.1 root 687: listItem.pszText = szTmp;
688: ListView_SetItem (list, &listItem);
689:
1.1.1.5 ! root 690: listItem.pszText = "Encryption Algorithm";
1.1 root 691: listItem.iItem++;
692: listItem.iSubItem = 0;
1.1.1.5 ! root 693: ListView_InsertItem (list, &listItem);
1.1 root 694: listItem.iSubItem++;
1.1.1.5 ! root 695: EAGetName (szTmp, prop.ea);
! 696: listItem.pszText = szTmp;
1.1 root 697: ListView_SetItem (list, &listItem);
698:
699: listItem.pszText = "Key Size";
700: listItem.iItem++;
701: listItem.iSubItem = 0;
1.1.1.5 ! root 702: ListView_InsertItem (list, &listItem);
1.1 root 703: listItem.iSubItem++;
1.1.1.5 ! root 704: sprintf (szTmp, "%d bits", EAGetKeySize (prop.ea)*8);
! 705: listItem.pszText = szTmp;
! 706: ListView_SetItem (list, &listItem);
! 707:
! 708: listItem.pszText = "Block Size";
! 709: listItem.iItem++;
! 710: listItem.iSubItem = 0;
! 711: ListView_InsertItem (list, &listItem);
! 712: listItem.iSubItem++;
! 713:
! 714: if (EAGetMode (prop.ea) == INNER_CBC)
! 715: {
! 716: // Cascaded ciphers with non-equal block sizes
! 717: char tmpstr[20];
! 718: int i = EAGetLastCipher(prop.ea);
! 719:
! 720: sprintf (tmpstr, "%d", CipherGetBlockSize(i)*8);
! 721: strcpy (szTmp, tmpstr);
! 722:
! 723: while (i = EAGetPreviousCipher(prop.ea, i))
! 724: {
! 725: sprintf (tmpstr, "/%d", CipherGetBlockSize(i)*8);
! 726: strcat (szTmp, tmpstr);
! 727: }
! 728: strcat (szTmp, " bits");
! 729: }
! 730: else
! 731: {
! 732: sprintf (szTmp, "%d bits", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8);
! 733: }
! 734: listItem.pszText = szTmp;
! 735: ListView_SetItem (list, &listItem);
! 736:
! 737: listItem.pszText = "Mode";
! 738: listItem.iItem++;
! 739: listItem.iSubItem = 0;
! 740: ListView_InsertItem (list, &listItem);
! 741: listItem.iSubItem++;
! 742: EAGetModeName (szTmp, prop.ea, TRUE);
1.1 root 743: listItem.pszText = szTmp;
744: ListView_SetItem (list, &listItem);
745:
746: listItem.pszText = "PKCS5 PRF";
747: listItem.iItem++;
748: listItem.iSubItem = 0;
1.1.1.5 ! root 749: ListView_InsertItem (list, &listItem);
1.1 root 750: listItem.iSubItem++;
751: listItem.pszText = get_hash_name (prop.pkcs5);
752: ListView_SetItem (list, &listItem);
753:
754: listItem.pszText = "PKCS5 Iterations";
755: listItem.iItem++;
756: listItem.iSubItem = 0;
1.1.1.5 ! root 757: ListView_InsertItem (list, &listItem);
1.1 root 758: listItem.iSubItem++;
759: sprintf (szTmp, "%d", prop.pkcs5Iterations);
760: listItem.pszText = szTmp;
761: ListView_SetItem (list, &listItem);
762:
763: {
764: FILETIME ft, curFt;
765: SYSTEMTIME st;
766: char date[128];
767: memset (date, 0, sizeof (date));
768:
769: listItem.pszText = "Volume Created";
770: listItem.iItem++;
771: listItem.iSubItem = 0;
772: ListView_InsertItem (list, &listItem);
773:
774: listItem.iSubItem++;
775: *(unsigned __int64 *)(&ft) = prop.volumeCreationTime;
776: FileTimeToSystemTime (&ft, &st);
777: GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
778: sprintf (date, "%s ", szTmp);
779: GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
780: strcat (date, szTmp);
781: listItem.pszText = date;
782: ListView_SetItem (list, &listItem);
783:
784: listItem.pszText = "Password Changed";
785: listItem.iItem++;
786: listItem.iSubItem = 0;
787: ListView_InsertItem (list, &listItem);
788:
789: listItem.iSubItem++;
790: *(unsigned __int64 *)(&ft) = prop.headerCreationTime;
791: FileTimeToSystemTime (&ft, &st);
792: GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
793: sprintf (date, "%s ", szTmp);
794: GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
795: strcat (date, szTmp);
796:
797: GetLocalTime (&st);
798: SystemTimeToFileTime (&st, &curFt);
799: sprintf (date + strlen (date), " (%I64d days ago)"
800: , (*(__int64 *)&curFt - *(__int64 *)&ft)/1000000000000 );
801: listItem.pszText = date;
802: ListView_SetItem (list, &listItem);
803: }
804:
1.1.1.5 ! root 805: listItem.pszText = "Volume Type";
! 806: listItem.iItem++;
! 807: listItem.iSubItem = 0;
! 808: ListView_InsertItem (list, &listItem);
! 809: listItem.iSubItem++;
! 810: if (prop.hiddenVolume == TRUE)
! 811: sprintf (szTmp, "Hidden");
! 812: else
! 813: sprintf (szTmp, "Normal");
! 814: listItem.pszText = szTmp;
! 815: ListView_SetItem (list, &listItem);
! 816:
1.1 root 817: return 1;
818: }
819:
820: case WM_COMMAND:
821:
822: if (lw == IDCANCEL)
823: {
824: EndDialog (hwndDlg, lw);
825: return 1;
826: }
827:
828: if (lw == IDOK)
829: {
830: EndDialog (hwndDlg, lw);
831: return 1;
832: }
833: return 0;
834: }
835:
836: return 0;
837: }
838:
839: void
840: BuildTree (HWND hTree)
841: {
842: HIMAGELIST hList;
843: HBITMAP hBitmap, hBitmapMask;
844: LVCOLUMN lvCol;
845: SendMessage(hTree,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
846: LVS_EX_FULLROWSELECT
847: |LVS_EX_HEADERDRAGDROP
848: //|LVS_EX_GRIDLINES
849: //|LVS_EX_TWOCLICKACTIVATE
850: );
851:
852: memset(&lvCol,0,sizeof(lvCol));
853:
854: lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
855: lvCol.pszText="Drive";
1.1.1.5 ! root 856: lvCol.cx=37;
1.1 root 857: lvCol.fmt = LVCFMT_COL_HAS_IMAGES|LVCFMT_LEFT ;
858: SendMessage (hTree,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
859:
860: lvCol.pszText="Volume";
1.1.1.5 ! root 861: lvCol.cx=263;
1.1 root 862: lvCol.fmt = LVCFMT_LEFT;
863: SendMessage (hTree,LVM_INSERTCOLUMN,1,(LPARAM)&lvCol);
864:
865: lvCol.pszText="Size";
1.1.1.5 ! root 866: lvCol.cx=55;
1.1 root 867: lvCol.fmt = LVCFMT_RIGHT;
868: SendMessage (hTree,LVM_INSERTCOLUMN,2,(LPARAM)&lvCol);
869:
1.1.1.5 ! root 870: lvCol.pszText="Encryption Algorithm";
! 871: lvCol.cx=117;
1.1 root 872: lvCol.fmt = LVCFMT_LEFT;
873: SendMessage (hTree,LVM_INSERTCOLUMN,3,(LPARAM)&lvCol);
874:
1.1.1.5 ! root 875: lvCol.pszText="Type";
! 876: lvCol.cx=47;
! 877: lvCol.fmt = LVCFMT_LEFT;
! 878: SendMessage (hTree,LVM_INSERTCOLUMN,4,(LPARAM)&lvCol);
! 879:
1.1 root 880: hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON));
881: if (hBitmap == NULL)
882: return;
883: hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON_MASK));
884:
885: hList = ImageList_Create (16, 12, ILC_COLOR8|ILC_MASK, 2, 2);
886: if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
887: {
888: DeleteObject (hBitmap);
889: return;
890: }
891: else
892: DeleteObject (hBitmap);
893:
894: ListView_SetImageList (hTree, hList, LVSIL_NORMAL);
895: ListView_SetImageList (hTree, hList, LVSIL_SMALL);
896:
897: LoadDriveLetters (hTree, 0);
898: }
899:
900: LPARAM
901: GetSelectedLong (HWND hTree)
902: {
903: int hItem = ListView_GetSelectionMark (hTree);
904: LVITEM item;
905:
1.1.1.5 ! root 906: if (nSelectedDriveIndex >= 0)
1.1 root 907: hItem = nSelectedDriveIndex;
908:
909: memset(&item, 0, sizeof(LVITEM));
910: item.mask = LVIF_PARAM;
911: item.iItem = hItem;
912:
913: if (ListView_GetItem (hTree, &item) == FALSE)
914: return MAKELONG (0xffff, 0xffff);
915: else
916: return item.lParam;
917: }
918:
919: LPARAM
920: GetItemLong (HWND hTree, int itemNo)
921: {
922: LVITEM item;
923:
924: memset(&item, 0, sizeof(LVITEM));
925: item.mask = LVIF_PARAM;
926: item.iItem = itemNo;
927:
928: if (ListView_GetItem (hTree, &item) == FALSE)
929: return MAKELONG (0xffff, 0xffff);
930: else
931: return item.lParam;
932: }
933:
934: static int AskUserPassword (HWND hwndDlg, char *password)
935: {
936: int result = DialogBoxParam (hInst,
937: MAKEINTRESOURCE (IDD_PASSWORD_DLG), hwndDlg,
938: (DLGPROC) PasswordDlgProc, (LPARAM) password);
939:
940: if (result != IDOK)
941: *password = 0;
942:
943: return result == IDOK;
944: }
945:
946: // GUI actions
947:
948: static void Mount (HWND hwndDlg)
949: {
950: char szPassword[MAX_PASSWORD + 1];
951: int mounted = 0;
952: int nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A';
953:
954: burn (szPassword, sizeof (szPassword));
955: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName,
956: sizeof (szFileName));
957:
958: if (strlen(szFileName) == 0)
959: return;
960:
961: if (IsMountedVolume (szFileName))
962: {
963: MessageBox(0, getstr (IDS_ALREADY_MOUNTED), lpszTitle, MB_ICONASTERISK);
964: return;
965: }
966:
967: // First try cached passwords and if they fail ask user for a new one
968: ArrowWaitCursor ();
1.1.1.5 ! root 969: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, "", bCacheInDriver, bForceMount, FALSE);
1.1 root 970: NormalCursor ();
971:
1.1.1.5 ! root 972: while (mounted == 0)
1.1 root 973: {
974: if (!AskUserPassword (hwndDlg, szPassword))
975: return;
976:
977: ArrowWaitCursor ();
1.1.1.5 ! root 978: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, szPassword, bCacheInDriver, bForceMount, FALSE);
1.1 root 979: NormalCursor ();
980: }
981:
1.1.1.5 ! root 982: if (mounted > 0)
1.1 root 983: {
984: if (bBeep == TRUE)
985: MessageBeep (MB_OK);
986:
987: RefreshMainDlg(hwndDlg);
988:
989: if (bExplore == TRUE)
990: {
991: ArrowWaitCursor();
992: OpenVolumeExplorerWindow (nDosDriveNo);
993: NormalCursor();
994: }
995: }
996:
997: burn (szPassword, sizeof (szPassword));
998: return;
999: }
1000:
1001:
1.1.1.2 root 1002: static void Dismount (HWND hwndDlg, int nDosDriveNo)
1.1 root 1003: {
1.1.1.5 ! root 1004: ArrowWaitCursor ();
1.1 root 1005:
1.1.1.2 root 1006: if (nDosDriveNo == 0)
1007: nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A');
1.1 root 1008:
1.1.1.5 ! root 1009: if (bCloseDismountedWindows)
1.1 root 1010: {
1.1.1.5 ! root 1011: if (CloseVolumeExplorerWindows (hwndDlg, nDosDriveNo))
! 1012: Sleep (UNMOUNT_WAIT);
1.1 root 1013: }
1014:
1.1.1.5 ! root 1015: if (UnmountVolume (hwndDlg, nDosDriveNo, bForceUnmount))
! 1016: {
! 1017: //if (bBeep == TRUE)
! 1018: // MessageBeep (MB_OK);
! 1019: RefreshMainDlg (hwndDlg);
1.1 root 1020: }
1021:
1.1.1.5 ! root 1022: NormalCursor ();
1.1 root 1023: return;
1024: }
1025:
1026:
1.1.1.5 ! root 1027: static void DismountAll (HWND hwndDlg, BOOL forceUnmount)
1.1 root 1028: {
1.1.1.5 ! root 1029: MOUNT_LIST_STRUCT mountList;
! 1030: DWORD dwResult;
! 1031: UNMOUNT_STRUCT unmount;
1.1 root 1032: BOOL bResult;
1.1.1.5 ! root 1033: BOOL shouldWait;
! 1034: unsigned __int32 prevMountedDrives = 0;
! 1035: int i;
1.1 root 1036:
1.1.1.5 ! root 1037: retry:
1.1 root 1038: ArrowWaitCursor();
1039:
1.1.1.5 ! root 1040: DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
! 1041: prevMountedDrives = mountList.ulMountedDrives;
! 1042:
! 1043: shouldWait = FALSE;
! 1044:
! 1045: for (i = 0; i < 26; i++)
1.1 root 1046: {
1.1.1.5 ! root 1047: if (mountList.ulMountedDrives & (1 << i))
1.1 root 1048: {
1.1.1.5 ! root 1049: if (bCloseDismountedWindows)
! 1050: shouldWait = CloseVolumeExplorerWindows (hwndDlg, i) ? TRUE : shouldWait;
1.1 root 1051:
1.1.1.5 ! root 1052: BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, i);
1.1 root 1053: }
1.1.1.5 ! root 1054: }
1.1 root 1055:
1.1.1.5 ! root 1056: if (shouldWait)
! 1057: Sleep (UNMOUNT_WAIT);
1.1 root 1058:
1.1.1.5 ! root 1059: unmount.nDosDriveNo = 0;
! 1060: unmount.ignoreOpenFiles = forceUnmount;
1.1 root 1061:
1.1.1.5 ! root 1062: bResult = DeviceIoControl (hDriver, UNMOUNT_ALL, &unmount,
! 1063: sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
1.1 root 1064:
1065:
1.1.1.5 ! root 1066: if (bResult == FALSE)
! 1067: {
! 1068: NormalCursor();
! 1069: handleWin32Error (hwndDlg);
! 1070: return;
! 1071: }
1.1 root 1072:
1.1.1.5 ! root 1073: DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
! 1074: for (i = 0; i < 26; i++)
! 1075: {
! 1076: if ((prevMountedDrives & ~mountList.ulMountedDrives) & (1 << i))
! 1077: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, i);
! 1078: }
1.1 root 1079:
1.1.1.5 ! root 1080: RefreshMainDlg(hwndDlg);
! 1081: NormalCursor();
1.1 root 1082:
1.1.1.5 ! root 1083: if (unmount.nReturnCode != 0)
! 1084: {
! 1085: if (unmount.nReturnCode == ERR_FILES_OPEN)
! 1086: {
! 1087: if (IDYES == MessageBox (hwndDlg, getstr (IDS_UNMOUNTALL_LOCK_FAILED),
! 1088: lpszTitle, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION))
1.1 root 1089: {
1.1.1.5 ! root 1090: forceUnmount = TRUE;
! 1091: goto retry;
1.1 root 1092: }
1.1.1.5 ! root 1093:
! 1094: return;
1.1 root 1095: }
1.1.1.5 ! root 1096:
! 1097: MessageBox (hwndDlg, getstr (IDS_UNMOUNT_FAILED), lpszTitle, MB_ICONERROR);
1.1 root 1098: }
1099: else
1100: {
1.1.1.5 ! root 1101: if (bBeep == TRUE)
! 1102: MessageBeep (MB_OK);
1.1 root 1103: }
1104: }
1105:
1106: static void MountAllPartitions (HWND hwndDlg)
1107: {
1108: HWND driveList = GetDlgItem (hwndDlg, IDC_DRIVELIST);
1109: int i, n, selDrive = ListView_GetSelectionMark (driveList);
1110: char szPassword[MAX_PASSWORD + 1];
1.1.1.5 ! root 1111: int mounted;
! 1112: BOOL shared = FALSE;
1.1 root 1113:
1114: // User is always asked for password as we can't tell
1115: // for sure if it is needed or not
1116: burn (szPassword, sizeof (szPassword));
1117: if (!AskUserPassword (hwndDlg, szPassword))
1118: return;
1119:
1120: ArrowWaitCursor();
1121:
1122: for (i = 0; i < 64; i++)
1123: {
1124: BOOL drivePresent = FALSE;
1125:
1.1.1.5 ! root 1126: // Include partition 0 (whole disk)
! 1127: for (n = 0; n <= 32; n++)
1.1 root 1128: {
1129: char szFileName[TC_MAX_PATH];
1130: OPEN_TEST_STRUCT driver;
1131:
1132: sprintf (szFileName, "\\Device\\Harddisk%d\\Partition%d", i, n);
1133: if (OpenDevice (szFileName, &driver) == TRUE && !IsMountedVolume (szFileName))
1134: {
1135: int nDosDriveNo;
1136:
1137: while (LOWORD (GetItemLong (driveList, selDrive)) != 0xffff)
1138: {
1139: if(LOWORD (GetItemLong (driveList, selDrive)) != VFREE)
1140: {
1141: selDrive++;
1142: continue;
1143: }
1144: nDosDriveNo = HIWORD(GetItemLong (driveList, selDrive)) - 'A';
1145: break;
1146: }
1147:
1148: if (LOWORD (GetItemLong (driveList, selDrive)) == 0xffff)
1149: goto ret;
1150:
1151: // First try user password then cached passwords
1.1.1.5 ! root 1152: if ((mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, szPassword, bCacheInDriver, bForceMount, TRUE)) > 0
! 1153: || (mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, "", bCacheInDriver, bForceMount, TRUE)) > 0)
1.1 root 1154: {
1.1.1.5 ! root 1155: if (mounted == 2)
! 1156: shared = TRUE;
! 1157:
1.1 root 1158: LoadDriveLetters (driveList, (HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), selDrive))));
1159: selDrive++;
1160:
1161: if (bExplore == TRUE)
1162: {
1163: ArrowWaitCursor();
1164: OpenVolumeExplorerWindow (nDosDriveNo);
1165: NormalCursor();
1166: }
1167: }
1168: }
1169: }
1170: }
1171:
1.1.1.5 ! root 1172: if (shared)
! 1173: MessageBox (hwndDlg, getstr (IDS_DEVICE_IN_USE_INFO), lpszTitle, MB_ICONEXCLAMATION);
! 1174:
1.1 root 1175: ret:
1176: burn (szPassword, sizeof (szPassword));
1177: EnableDisableButtons (hwndDlg);
1178: NormalCursor();
1179: }
1180:
1181: static void ChangePassword (HWND hwndDlg)
1182: {
1183: int result;
1184:
1185: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
1186: if (IsMountedVolume (szFileName))
1187: {
1188: MessageBox (hwndDlg, getstr (IDS_MOUNTED_NOPWCHANGE), lpszTitle, MB_ICONEXCLAMATION);
1189: return;
1190: }
1191:
1192: result = DialogBox (hInst, MAKEINTRESOURCE (IDD_PASSWORDCHANGE_DLG), hwndDlg,
1193: (DLGPROC) PasswordChangeDlgProc);
1194:
1195: if (result == IDOK)
1196: {
1197: HWND tmp = GetDlgItem (hwndDlg, IDC_PASSWORD);
1198: MessageBox (hwndDlg, getstr (IDS_PASSWORD_CHANGED), lpszTitle, MB_ICONASTERISK);
1199: SetFocus (tmp);
1200: }
1201: }
1202:
1203: static void SelectContainer (HWND hwndDlg)
1204: {
1.1.1.5 ! root 1205: if (BrowseFiles (hwndDlg, IDS_OPEN_TITLE, szFileName, bHistory) == FALSE)
1.1 root 1206: return;
1207:
1208: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
1209: EnableDisableButtons (hwndDlg);
1210: SetFocus (GetDlgItem (hwndDlg, IDC_PASSWORD));
1211: }
1212:
1213: static void SelectPartition (HWND hwndDlg)
1214: {
1215: int nResult = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_RAWDEVICES_DLG), hwndDlg,
1216: (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
1217: if (nResult == IDOK)
1218: {
1219: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
1220: EnableDisableButtons (hwndDlg);
1221: SetFocus (GetDlgItem (hwndDlg, IDC_PASSWORD));
1222: }
1223: }
1224:
1225: static void WipeCache (HWND hwndDlg)
1226: {
1227: DWORD dwResult;
1228: BOOL bResult;
1229:
1230: bResult = DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1231:
1232: if (bResult == FALSE)
1233: handleWin32Error (hwndDlg);
1234: else
1235: {
1236: EnableDisableButtons (hwndDlg);
1237:
1238: if (bQuiet == FALSE)
1239: MessageBox (hwndDlg, getstr (IDS_WIPE_CACHE), lpszTitle, MB_ICONINFORMATION);
1240: }
1241: }
1242:
1.1.1.5 ! root 1243: static void Benchmark (HWND hwndDlg)
! 1244: {
! 1245: int nResult = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_BENCHMARK_DLG), hwndDlg,
! 1246: (DLGPROC) BenchmarkDlgProc, (LPARAM) NULL);
! 1247: }
1.1 root 1248:
1249: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
1250: should return nonzero if it processes the message, and zero if it does
1251: not. - see DialogProc */
1252: BOOL CALLBACK
1253: MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1254: {
1255: WORD lw = LOWORD (wParam);
1256: WORD hw = HIWORD (wParam);
1257: if (lParam); /* remove warning */
1258:
1259: switch (uMsg)
1260: {
1261:
1262: case WM_INITDIALOG:
1263: {
1.1.1.2 root 1264: ExtractCommandLine (hwndDlg, (char *) lParam);
1265:
1266: if (!bQuiet) LoadSettings (hwndDlg);
1.1 root 1267:
1268: /* Call the common dialog init code */
1269: InitDialog (hwndDlg);
1270: SetDefaultUserFont (hwndDlg);
1271:
1272: SendMessage (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
1273:
1274: SendMessage (GetDlgItem (hwndDlg, IDC_NO_DRIVES_STATIC), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
1275: SetWindowText (hwndDlg, lpszTitle);
1276:
1277: BuildTree (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1278:
1279: if (*szDriveLetter != 0)
1280: {
1281: SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
1282:
1283: if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2)
1284: SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
1285: }
1286:
1287: SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
1288:
1289: EnableDisableButtons (hwndDlg);
1290:
1291: if (bWipe == TRUE)
1292: {
1.1.1.2 root 1293: WipeCache (hwndDlg);
1.1 root 1294: }
1295:
1.1.1.2 root 1296: // Automount
1.1 root 1297: if (bAuto == TRUE && IsWindowEnabled (GetDlgItem (hwndDlg, IDOK)))
1298: {
1.1.1.5 ! root 1299: // No drive letter specified on command line
! 1300: if (commandLineDrive == 0)
! 1301: szDriveLetter[0] = GetFirstAvailableDrive () + 'A';
! 1302:
1.1.1.2 root 1303: if (!IsMountedVolume (szFileName))
1304: {
1305: BOOL mounted;
1306:
1307: // Cached password
1.1.1.5 ! root 1308: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, "", bCacheInDriver, bForceMount, FALSE);
1.1.1.2 root 1309:
1310: if (!mounted && commandLinePassword[0] != 0)
1311: {
1312: // Command line password
1.1.1.5 ! root 1313: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, commandLinePassword, bCacheInDriver, bForceMount, TRUE);
1.1.1.2 root 1314: burn (commandLinePassword, sizeof (commandLinePassword));
1315: }
1316:
1317: // Ask user for password
1318: while (!mounted)
1319: {
1320: char szPassword[MAX_PASSWORD + 1];
1321:
1322: if (!AskUserPassword (hwndDlg, szPassword))
1323: break;
1324:
1325: ArrowWaitCursor ();
1.1.1.5 ! root 1326: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, szPassword, bCacheInDriver, bForceMount, FALSE);
1.1.1.2 root 1327: burn (szPassword, sizeof (szPassword));
1328: NormalCursor ();
1329: }
1330:
1.1.1.5 ! root 1331: if (mounted > 0)
1.1.1.2 root 1332: {
1333: if (bBeep == TRUE) MessageBeep (MB_OK);
1334: if (bExplore == TRUE) OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
1335: if (bQuiet) ExitProcess (0);
1336: }
1337: else if (bQuiet) ExitProcess (1);
1338:
1339: RefreshMainDlg(hwndDlg);
1340: }
1.1.1.5 ! root 1341: else if (bExplore == TRUE) OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
1.1 root 1342: }
1343:
1.1.1.5 ! root 1344: if (cmdUnmountDrive > 0)
! 1345: Dismount (hwndDlg, (char)toupper(szDriveLetter[0]) - 'A');
! 1346: else if (cmdUnmountDrive == -1)
! 1347: DismountAll (hwndDlg, bForceUnmount);
! 1348:
1.1.1.3 root 1349: if (bQuiet) ExitProcess (0);
1350:
1.1 root 1351: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1352: }
1353: return 0;
1354:
1355: case WM_SYSCOMMAND:
1356: if (lw == IDC_ABOUT)
1357: {
1358: DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1359: return 1;
1360: }
1361: return 0;
1362:
1363: case WM_HELP:
1364: OpenPageHelp (hwndDlg);
1365: return 1;
1366:
1367: case WM_NOTIFY:
1368: // Single click in drive list
1369: if (((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
1370: {
1371: nSelectedDriveIndex = ((LPNMLISTVIEW) lParam)->iItem;
1372: EnableDisableButtons (hwndDlg);
1373:
1374: return 1;
1375: }
1376:
1377: // Double click in drive list
1378: if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE)
1379: {
1380: int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
1381: nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
1382: if (LOWORD(state) == VMOUNTED)
1383: {
1384: // Open explorer window for mounted volume
1385: ArrowWaitCursor ();
1386: OpenVolumeExplorerWindow (HIWORD(state) - 'A');
1387: NormalCursor ();
1388: }
1389: else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
1390: {
1391: Mount (hwndDlg);
1392: }
1393: }
1394: return 0;
1395:
1396: case WM_ERASEBKGND:
1397: return 0;
1398:
1399: case WM_COMMAND:
1400:
1401: if (lw == IDCANCEL)
1402: {
1403: EndMainDlg (hwndDlg);
1404: return 1;
1405: }
1406:
1407: if (lw == IDHELP || lw == IDM_HELP)
1408: {
1409: OpenPageHelp (hwndDlg);
1410: return 1;
1411: }
1412:
1413: if (lw == IDM_ABOUT || lw == IDB_LOGO)
1414: {
1415: DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1416: return 1;
1417: }
1418:
1419: if ((lw == IDOK || lw == ID_MOUNT_VOLUME)
1420: && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
1421: {
1422:
1423: Mount (hwndDlg);
1424: return 1;
1425: }
1426:
1427: if ((lw == IDOK || lw == ID_MOUNT_VOLUME || lw == IDC_MOUNTALL)
1428: && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == 0xffff)
1429: {
1.1.1.5 ! root 1430: MessageBox (hwndDlg, "Please select a free drive letter from the list.","TrueCrypt", MB_ICONEXCLAMATION);
1.1 root 1431: return 1;
1432: }
1433:
1434: if (lw == IDOK && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VMOUNTED
1435: || lw == ID_UNMOUNT_VOLUME)
1436: {
1.1.1.2 root 1437: Dismount (hwndDlg, 0);
1.1 root 1438: return 1;
1439: }
1440:
1441: if (lw == IDUNMOUNTALL)
1442: {
1.1.1.5 ! root 1443: DismountAll (hwndDlg, bForceUnmount);
1.1 root 1444: return 1;
1445: }
1446:
1447: if (lw == IDC_MOUNTALL)
1448: {
1449: MountAllPartitions (hwndDlg);
1450: return 1;
1451: }
1452:
1453: if (lw == IDC_BROWSE_FILES)
1454: {
1455: SelectContainer (hwndDlg);
1456: return 1;
1457: }
1458:
1459: if (lw == IDC_BROWSE_DEVICES)
1460: {
1461: SelectPartition (hwndDlg);
1462: return 1;
1463: }
1464:
1465: if (lw == IDC_CHANGE_PASSWORD)
1466: {
1467: ChangePassword (hwndDlg);
1468: return 1;
1469: }
1470:
1471: if (lw == IDC_WIPE_CACHE)
1472: {
1473: WipeCache (hwndDlg);
1474: return 1;
1475: }
1476:
1477: if (lw == IDC_CLEAR_HISTORY)
1478: {
1479: ClearCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
1480: DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), "LastMountedVolume", TRUE);
1481: EnableDisableButtons (hwndDlg);
1482: return 1;
1483: }
1484:
1485: if (lw == IDC_CREATE_VOLUME)
1486: {
1487: char t[TC_MAX_PATH];
1488: char *tmp;
1489:
1490: GetModuleFileName (NULL, t, sizeof (t));
1491: tmp = strrchr (t, '\\');
1492: if (tmp)
1493: {
1494: strcpy (++tmp, "TrueCrypt Format.exe");
1495: ShellExecute (NULL, "open", t, NULL, NULL, SW_SHOWNORMAL);
1496: }
1497: return 1;
1498: }
1499:
1.1.1.3 root 1500: if (lw == ID_LICENSE)
1501: {
1502: char t[TC_MAX_PATH];
1503: char *tmp;
1504:
1505: GetModuleFileName (NULL, t, sizeof (t));
1506: tmp = strrchr (t, '\\');
1507: if (tmp)
1508: {
1509: strcpy (++tmp, "license.txt");
1510: ShellExecute (NULL, "open", t, NULL, NULL, SW_SHOWNORMAL);
1511: }
1512: return 1;
1513: }
1514:
1.1 root 1515: if (lw == ID_WEBSITE)
1516: {
1.1.1.5 ! root 1517: char tmpstr [256];
! 1518:
! 1519: sprintf (tmpstr, "http://truecrypt.sourceforge.net/applink.php?version=%s", VERSION_STRING);
! 1520: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
! 1521: return 1;
! 1522: }
! 1523:
! 1524: if (lw == ID_FORUMS)
! 1525: {
! 1526: char tmpstr [256];
! 1527:
! 1528: sprintf (tmpstr, "http://truecrypt.sourceforge.net/applink.php?version=%s&dest=forum", VERSION_STRING);
! 1529: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
1.1 root 1530: return 1;
1531: }
1.1.1.3 root 1532:
1.1 root 1533: if (lw == ID_PREFERENCES)
1534: {
1535: DialogBoxParam (hInst,
1536: MAKEINTRESOURCE (IDD_PREFERENCES_DLG), hwndDlg,
1537: (DLGPROC) PreferencesDlgProc, (LPARAM) 0);
1538: return 1;
1539: }
1540:
1.1.1.5 ! root 1541: if (lw == ID_BENCHMARK)
! 1542: {
! 1543: Benchmark (hwndDlg);
! 1544: return 1;
! 1545: }
! 1546:
! 1547:
1.1 root 1548: if (lw == IDC_VOLUME_PROPERTIES)
1549: {
1550: DialogBoxParam (hInst,
1551: MAKEINTRESOURCE (IDD_VOLUME_PROPERTIES), hwndDlg,
1552: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
1553: return 1;
1554: }
1555:
1556: if (lw == IDC_VOLUME && hw == CBN_EDITCHANGE)
1557: {
1.1.1.5 ! root 1558: EnableDisableButtons (hwndDlg);
1.1 root 1559: return 1;
1560: }
1561:
1562: if (lw == IDC_VOLUME && hw == CBN_SELCHANGE)
1563: {
1564: UpdateComboOrder (GetDlgItem (hwndDlg, IDC_VOLUME));
1565: MoveEditToCombo ((HWND) lParam);
1.1.1.5 ! root 1566: PostMessage (hwndDlg, WM_USER+100, 0, 0);
! 1567: return 1;
! 1568: }
! 1569:
! 1570: if (lw == IDC_NO_HISTORY)
! 1571: {
! 1572: bHistory = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY));
1.1 root 1573: return 1;
1574: }
1575:
1576: return 0;
1577:
1.1.1.5 ! root 1578: case WM_USER+100:
1.1 root 1579: EnableDisableButtons (hwndDlg);
1580: return 1;
1581:
1582: case WM_CLOSE:
1583: EndMainDlg (hwndDlg);
1584: return 1;
1585: }
1586:
1587: return 0;
1588: }
1589:
1590: void
1591: ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
1592: {
1593: char **lpszCommandLineArgs; /* Array of command line arguments */
1594: int nNoCommandLineArgs; /* The number of arguments in the array */
1595:
1596: /* Extract command line arguments */
1597: nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
1598: if (nNoCommandLineArgs > 0)
1599: {
1600: int i;
1601:
1602: for (i = 0; i < nNoCommandLineArgs; i++)
1603: {
1604: argument args[]=
1605: {
1606: {"/auto", "/a"},
1.1.1.5 ! root 1607: {"/beep", "/b"},
1.1 root 1608: {"/cache", "/c"},
1.1.1.5 ! root 1609: {"/dismount", "/d"},
! 1610: {"/explore", "/e"},
! 1611: {"/force", "/f"},
! 1612: {"/help", "/?"},
1.1 root 1613: {"/history", "/h"},
1.1.1.5 ! root 1614: {"/letter", "/l"},
! 1615: {"/password", "/p"},
1.1 root 1616: {"/quiet", "/q"},
1.1.1.5 ! root 1617: {"/volume", "/v"},
! 1618: {"/wipecache", "/w"}
1.1 root 1619: };
1620:
1621: argumentspec as;
1622:
1623: int nArgPos;
1624: int x;
1625:
1626: as.args = args;
1627: as.arg_cnt = sizeof(args)/ sizeof(args[0]);
1628:
1629: x = GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos);
1630:
1631: switch (x)
1632: {
1633: case 'd':
1.1.1.2 root 1634:
1635: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1636: szDriveLetter, sizeof (szDriveLetter)))
1.1.1.5 ! root 1637: cmdUnmountDrive = toupper(szDriveLetter[0]) - 'A';
1.1.1.2 root 1638: else
1.1.1.5 ! root 1639: cmdUnmountDrive = -1;
1.1.1.2 root 1640:
1.1 root 1641: break;
1642:
1643: case 'v':
1644: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
1645: nNoCommandLineArgs, szFileName, sizeof (szFileName)))
1.1.1.2 root 1646: {
1647: // Relative path must be converted to absolute
1648: if (szFileName[0] != '\\' && strchr (szFileName, ':') == 0)
1649: {
1650: char path[MAX_PATH*2];
1651: GetCurrentDirectory (MAX_PATH, path);
1652: strcat (path, "\\");
1653: strcat (path, szFileName);
1654: strncpy (szFileName, path, MAX_PATH-1);
1655: }
1.1 root 1656: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
1.1.1.2 root 1657: }
1.1 root 1658: break;
1659:
1660: case 'l':
1661: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1662: szDriveLetter, sizeof (szDriveLetter));
1.1.1.5 ! root 1663: commandLineDrive = *szDriveLetter = (char) toupper (*szDriveLetter);
1.1 root 1664: break;
1665:
1666: case 'e':
1667: bExplore = TRUE;
1668: break;
1669:
1670: case 'b':
1671: bBeep = TRUE;
1672: break;
1673:
1.1.1.5 ! root 1674: case 'f':
! 1675: bForceMount = TRUE;
! 1676: bForceUnmount = TRUE;
! 1677: break;
! 1678:
1.1 root 1679: case 'p':
1.1.1.2 root 1680: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1681: commandLinePassword, sizeof (commandLinePassword));
1.1 root 1682: break;
1683:
1684: case 'a':
1685: bAuto = TRUE;
1686: break;
1687:
1688: case 'c':
1689: {
1690: char szTmp[8];
1691: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1692: szTmp, sizeof (szTmp));
1693: if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes"))
1694: bCacheInDriver = TRUE;
1695: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
1696: bCacheInDriver = FALSE;
1697: }
1698: break;
1699:
1700: case 'h':
1701: {
1702: char szTmp[8];
1703: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1704: szTmp, sizeof (szTmp));
1705: if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes"))
1706: {
1707: bHistory = TRUE;
1708: bHistoryCmdLine = TRUE;
1709: }
1710:
1711: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
1712: {
1713: bHistory = FALSE;
1714: bHistoryCmdLine = TRUE;
1715: }
1716: }
1717: break;
1718:
1719: case 'w':
1720: bWipe = TRUE;
1721: break;
1722:
1723: case 'q':
1724: bQuiet = TRUE;
1725: break;
1726:
1727: case '?':
1728: DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
1729: CommandHelpDlgProc, (LPARAM) &as);
1730: exit(0);
1731: break;
1732:
1733: // no option = file name
1734: default:
1.1.1.2 root 1735: {
1736: strncpy (szFileName, lpszCommandLineArgs[0], MAX_PATH-1);
1737: if (szFileName[0] != '\\' && strchr (szFileName, ':') == 0)
1738: {
1739: char path[MAX_PATH*2];
1740: GetCurrentDirectory (MAX_PATH, path);
1741: strcat (path, "\\");
1742: strcat (path, szFileName);
1743: strncpy (szFileName, path, MAX_PATH-1);
1744: }
1745: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
1746: }
1.1 root 1747: }
1748: }
1749: }
1750:
1751: /* Free up the command line arguments */
1752: while (--nNoCommandLineArgs >= 0)
1753: {
1754: free (lpszCommandLineArgs[nNoCommandLineArgs]);
1755: }
1756: }
1757:
1758: int WINAPI
1759: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
1760: int nCmdShow)
1761: {
1762: int status;
1763:
1764: if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
1765:
1766: atexit (localcleanup);
1767:
1768: /* Allocate, dup, then store away the application title */
1769: lpszTitle = err_strdup (getstr (IDS_TITLE));
1770:
1771: /* Call InitApp to initialize the common code */
1772: InitApp (hInstance);
1773:
1774: status = DriverAttach ();
1775: if (status != 0)
1776: {
1777: if (status == ERR_OS_ERROR)
1778: handleWin32Error (NULL);
1779: else
1780: handleError (NULL, status);
1781:
1782: AbortProcess (IDS_NODRIVER);
1783: }
1784:
1785: /* Create the main dialog box */
1786: DialogBoxParam (hInstance, MAKEINTRESOURCE (IDD_MOUNT_DLG), NULL, (DLGPROC) MainDialogProc,
1787: (LPARAM) lpszCommandLine);
1788:
1789: /* Terminate */
1790: return 0;
1791: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.