📄 mount.c
字号:
bAutoMount ? "Mount TrueCrypt Volume" : "Start TrueCrypt");
fprintf (af, "shell\\open\\command=%s\nshell\\open=TrueCrypt Start\n", openApp);
if (volName[0] != 0)
fprintf (af, "shell\\mount\\command=%s\nshell\\mount=TrueCrypt Mount\n", autoMount);
fprintf (af, "shell\\dismount\\command=TrueCrypt\\TrueCrypt.exe /q /d\nshell\\dismount=TrueCrypt Dismount All\n");
fclose (af);
}
strcpy (tmpMsg, getstr (IDS_TRAVELLER_DISK_CREATED));
strcat (tmpMsg, getstr (IDS_TRAVELLER_DISK_CREATED2));
MessageBox (hwndDlg, tmpMsg, lpszTitle, MB_ICONINFORMATION);
stop:
NormalCursor ();
EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), TRUE);
return 1;
}
return 0;
}
return 0;
}
void
BuildTree (HWND hTree)
{
HIMAGELIST hList;
HBITMAP hBitmap, hBitmapMask;
LVCOLUMN lvCol;
SendMessage(hTree,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
LVS_EX_FULLROWSELECT
|LVS_EX_HEADERDRAGDROP
//|LVS_EX_GRIDLINES
//|LVS_EX_TWOCLICKACTIVATE
);
memset(&lvCol,0,sizeof(lvCol));
lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
lvCol.pszText="Drive";
lvCol.cx=37;
lvCol.fmt = LVCFMT_COL_HAS_IMAGES|LVCFMT_LEFT ;
SendMessage (hTree,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
lvCol.pszText="Volume";
lvCol.cx=263;
lvCol.fmt = LVCFMT_LEFT;
SendMessage (hTree,LVM_INSERTCOLUMN,1,(LPARAM)&lvCol);
lvCol.pszText="Size";
lvCol.cx=55;
lvCol.fmt = LVCFMT_RIGHT;
SendMessage (hTree,LVM_INSERTCOLUMN,2,(LPARAM)&lvCol);
lvCol.pszText="Encryption Algorithm";
lvCol.cx=117;
lvCol.fmt = LVCFMT_LEFT;
SendMessage (hTree,LVM_INSERTCOLUMN,3,(LPARAM)&lvCol);
lvCol.pszText="Type";
lvCol.cx=47;
lvCol.fmt = LVCFMT_LEFT;
SendMessage (hTree,LVM_INSERTCOLUMN,4,(LPARAM)&lvCol);
hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON));
if (hBitmap == NULL)
return;
hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON_MASK));
hList = ImageList_Create (16, 12, ILC_COLOR8|ILC_MASK, 2, 2);
if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
{
DeleteObject (hBitmap);
return;
}
else
DeleteObject (hBitmap);
ListView_SetImageList (hTree, hList, LVSIL_NORMAL);
ListView_SetImageList (hTree, hList, LVSIL_SMALL);
LoadDriveLetters (hTree, 0);
}
LPARAM
GetSelectedLong (HWND hTree)
{
int hItem = ListView_GetSelectionMark (hTree);
LVITEM item;
if (nSelectedDriveIndex >= 0)
hItem = nSelectedDriveIndex;
memset(&item, 0, sizeof(LVITEM));
item.mask = LVIF_PARAM;
item.iItem = hItem;
if (ListView_GetItem (hTree, &item) == FALSE)
return MAKELONG (0xffff, 0xffff);
else
return item.lParam;
}
LPARAM
GetItemLong (HWND hTree, int itemNo)
{
LVITEM item;
memset(&item, 0, sizeof(LVITEM));
item.mask = LVIF_PARAM;
item.iItem = itemNo;
if (ListView_GetItem (hTree, &item) == FALSE)
return MAKELONG (0xffff, 0xffff);
else
return item.lParam;
}
static int AskUserPassword (HWND hwndDlg, char *password)
{
int result = DialogBoxParam (hInst,
MAKEINTRESOURCE (IDD_PASSWORD_DLG), hwndDlg,
(DLGPROC) PasswordDlgProc, (LPARAM) password);
if (result != IDOK)
*password = 0;
return result == IDOK;
}
// GUI actions
static void Mount (HWND hwndDlg)
{
char szPassword[MAX_PASSWORD + 1];
int mounted = 0;
int nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A';
burn (szPassword, sizeof (szPassword));
GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName,
sizeof (szFileName));
if (strlen(szFileName) == 0)
return;
if (IsMountedVolume (szFileName))
{
MessageBox(0, getstr (IDS_ALREADY_MOUNTED), lpszTitle, MB_ICONASTERISK);
return;
}
// First try cached passwords and if they fail ask user for a new one
ArrowWaitCursor ();
mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, "", bCacheInDriver, bForceMount, &mountOptions, FALSE);
NormalCursor ();
while (mounted == 0)
{
if (!AskUserPassword (hwndDlg, szPassword))
return;
ArrowWaitCursor ();
mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, szPassword, bCacheInDriver, bForceMount, &mountOptions, FALSE);
NormalCursor ();
}
if (mounted > 0)
{
if (bBeep == TRUE)
MessageBeep (-1);
RefreshMainDlg(hwndDlg);
if (bExplore == TRUE)
{
ArrowWaitCursor();
OpenVolumeExplorerWindow (nDosDriveNo);
NormalCursor();
}
}
burn (szPassword, sizeof (szPassword));
return;
}
static void Dismount (HWND hwndDlg, int nDosDriveNo)
{
ArrowWaitCursor ();
if (nDosDriveNo == 0)
nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A');
if (bCloseDismountedWindows)
{
CloseVolumeExplorerWindows (hwndDlg, nDosDriveNo);
}
if (UnmountVolume (hwndDlg, nDosDriveNo, bForceUnmount))
{
if (bBeep == TRUE)
MessageBeep (-1);
RefreshMainDlg (hwndDlg);
}
NormalCursor ();
return;
}
static void DismountAll (HWND hwndDlg, BOOL forceUnmount)
{
MOUNT_LIST_STRUCT mountList;
DWORD dwResult;
UNMOUNT_STRUCT unmount;
BOOL bResult;
unsigned __int32 prevMountedDrives = 0;
int dismountMaxRetries = UNMOUNT_MAX_AUTO_RETRIES;
int i;
retry:
ArrowWaitCursor();
DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
if (mountList.ulMountedDrives == 0)
{
NormalCursor();
return;
}
prevMountedDrives = mountList.ulMountedDrives;
for (i = 0; i < 26; i++)
{
if (mountList.ulMountedDrives & (1 << i))
{
if (bCloseDismountedWindows)
CloseVolumeExplorerWindows (hwndDlg, i);
}
}
unmount.nDosDriveNo = 0;
unmount.ignoreOpenFiles = forceUnmount;
do
{
bResult = DeviceIoControl (hDriver, UNMOUNT_ALL, &unmount,
sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
if (bResult == FALSE)
{
NormalCursor();
handleWin32Error (hwndDlg);
return;
}
if (unmount.nReturnCode == ERR_FILES_OPEN)
Sleep (UNMOUNT_AUTO_RETRY_DELAY);
else
break;
} while (--dismountMaxRetries > 0);
DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountedDrives & ~mountList.ulMountedDrives);
RefreshMainDlg(hwndDlg);
NormalCursor();
if (unmount.nReturnCode != 0)
{
if (unmount.nReturnCode == ERR_FILES_OPEN)
{
if (IDYES == MessageBox (hwndDlg, getstr (IDS_UNMOUNTALL_LOCK_FAILED),
lpszTitle, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION))
{
forceUnmount = TRUE;
goto retry;
}
return;
}
MessageBox (hwndDlg, getstr (IDS_UNMOUNT_FAILED), lpszTitle, MB_ICONERROR);
}
else
{
if (bBeep == TRUE)
MessageBeep (-1);
}
}
static void MountAllDevices (HWND hwndDlg)
{
HWND driveList = GetDlgItem (hwndDlg, IDC_DRIVELIST);
int i, n, selDrive = ListView_GetSelectionMark (driveList);
char szPassword[MAX_PASSWORD + 1];
BOOL shared = FALSE;
if (selDrive == -1) selDrive = 0;
mountOptions = defaultMountOptions;
// User is always asked for password as we can't tell
// for sure if it is needed or not
burn (szPassword, sizeof (szPassword));
if (!AskUserPassword (hwndDlg, szPassword))
return;
ArrowWaitCursor();
for (i = 0; i < 64; i++)
{
// Include partition 0 (whole disk)
for (n = 0; n <= 32; n++)
{
char szFileName[TC_MAX_PATH];
OPEN_TEST_STRUCT driver;
BOOL mounted;
sprintf (szFileName, "\\Device\\Harddisk%d\\Partition%d", i, n);
mounted = IsMountedVolume (szFileName);
// Skip other partitions of the disk if partition0 (whole disk) is mounted
if (n == 0 && mounted)
break;
if (!mounted && OpenDevice (szFileName, &driver) == TRUE)
{
int nDosDriveNo;
while (LOWORD (GetItemLong (driveList, selDrive)) != 0xffff)
{
if(LOWORD (GetItemLong (driveList, selDrive)) != VFREE)
{
selDrive++;
continue;
}
nDosDriveNo = HIWORD(GetItemLong (driveList, selDrive)) - 'A';
break;
}
if (LOWORD (GetItemLong (driveList, selDrive)) == 0xffff)
goto ret;
// First try user password then cached passwords
if ((mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, szPassword, bCacheInDriver, bForceMount, &mountOptions, TRUE)) > 0
|| (mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, "", bCacheInDriver, bForceMount, &mountOptions, TRUE)) > 0)
{
if (mounted == 2)
shared = TRUE;
LoadDriveLetters (driveList, (HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), selDrive))));
selDrive++;
if (bExplore == TRUE)
{
ArrowWaitCursor();
OpenVolumeExplorerWindow (nDosDriveNo);
NormalCursor();
}
// Skip other partitions of the disk if partition0 (whole disk) has been mounted
if (n == 0)
break;
}
}
else if (n == 0)
break;
}
}
if (shared)
MessageBox (hwndDlg, getstr (IDS_DEVICE_IN_USE_INFO), lpszTitle, MB_ICONEXCLAMATION);
ret:
burn (szPassword, sizeof (szPassword));
EnableDisableButtons (hwndDlg);
NormalCursor();
}
static void ChangePassword (HWND hwndDlg)
{
int result;
GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
if (IsMountedVolume (szFileName))
{
MessageBox (hwndDlg, getstr (IDS_MOUNTED_NOPWCHANGE), lpszTitle, MB_ICONEXCLAMATION);
return;
}
result = DialogBox (hInst, MAKEINTRESOURCE (IDD_PASSWORDCHANGE_DLG), hwndDlg,
(DLGPROC) PasswordChangeDlgProc);
if (result == IDOK)
{
HWND tmp = GetDlgItem (hwndDlg, IDC_PASSWORD);
MessageBox (hwndDlg, getstr (IDS_PASSWORD_CHANGED), lpszTitle, MB_ICONASTERISK);
SetFocus (tmp);
}
}
static void SelectContainer (HWND hwndDlg)
{
if (BrowseFiles (hwndDlg, IDS_OPEN_TITLE, szFileName, bHistory) == FALSE)
return;
AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
EnableDisableButtons (hwndDlg);
SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
}
static void SelectPartition (HWND hwndDlg)
{
int nResult = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_RAWDEVICES_DLG), hwndDlg,
(DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
if (nResult == IDOK)
{
AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
EnableDisableButtons (hwndDlg);
SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
}
}
static void WipeCache (HWND hwndDlg)
{
DWORD dwResult;
BOOL bResult;
bResult = DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
if (bResult == FALSE)
handleWin32Error (hwndDlg);
else
{
EnableDisableButtons (hwndDlg);
if (bQuiet == FALSE)
MessageBox (hwndDlg, getstr (IDS_WIPE_CACHE), lpszTitle, MB_ICONINFORMATION);
}
}
static void Benchmark (HWND hwndDlg)
{
int nResult = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_BENCHMARK_DLG), hwndDlg,
(DLGPROC) BenchmarkDlgProc, (LPARAM) NULL);
}
/* Except in response to the WM_INITDIALOG message, the dialog box procedure
should return nonzero if it processes the message, and zero if it does
not. - see DialogProc */
BOOL CALLBACK
MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
WORD lw = LOWORD (wParam);
WORD hw = HIWORD (wParam);
if (lParam); /* remove warning */
switch (uMsg)
{
case WM_INITDIALOG:
{
ExtractCommandLine (hwndDlg, (char *) lParam);
if (!bQuiet) LoadSettings (hwndDlg);
/* Call the common dialog init code */
InitDialog (hwndDlg);
SetDefaultUserFont (hwndDlg);
DragAcceptFiles (hwndDlg, TRUE);
SendMessage (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
SendMessage (GetDlgItem (hwndDlg, IDC_NO_DRIVES_STATIC), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
SetWindowText (hwndDlg, lpszTitle);
BuildTree (GetDlgItem (hwndDlg, IDC_DRIVELIST));
if (*szDriveLetter != 0)
{
SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2)
SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
}
SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
EnableMenuItem (GetMenu (hwndDlg), IDM_TRAVELLER, IsNonInstallMode() ? MF_GRAYED : MF_ENABLED);
EnableDisableButtons (hwndDlg);
if (bWipe == TRUE)
{
WipeCache (hwndDlg);
}
// Automount
if (bAuto == TRUE)
{
// No drive letter specified on command line
if (commandLineDrive == 0)
szDriveLetter[0] = GetFirstAvailableDrive () + 'A';
if (bAutoMountDevices)
{
defaultMountOptions = mountOptions;
MountAllDevices (hwndDlg);
}
else if (!IsMountedVolume (szFileName))
{
BOOL mounted;
// Cached password
mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, "", bCacheInDriver, bForceMount, &mountOptions, FALSE);
if (!mounted && commandLinePassword[0] != 0)
{
// Command line password
mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, commandLinePassword, bCacheInDriver, bForceMount, &mountOptions, TRUE);
burn (commandLinePassword, sizeof (commandLinePassword));
}
// Ask user for password
while (!mounted)
{
char szPassword[MAX_PASSWORD + 1];
if (!AskUserPassword (hwndDlg, szPassword))
break;
ArrowWaitCursor ();
mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, szPassword, bCacheInDriver, bForceMount, &mountOptions, FALSE);
burn (szPassword, sizeof (szPassword));
NormalCursor ();
}
if (mounted > 0)
{
if (bBeep == TRUE) MessageBeep (-1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -