📄 cpgpdiskunmounterimpwin32.cpp
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: CPGPdiskUnmounterImpWin32.cpp,v 1.6 2002/08/06 20:09:24 dallen Exp $
____________________________________________________________________________*/
#include "pgpClassesConfig.h"
#include "CMessageBox.h"
#include "CWindow.h"
#include "pgpClientErrors.h"
#include "UCommonStrings.h"
#include "CPGPclPrefs.h"
#include "CPGPdiskEngine.h"
#include "CPGPdiskUnmounterImpWin32.h"
#include "SClaimedCommand.h"
_USING_PGP
// Class CPGPdiskUnmounterImpWin32 member functions
void
CPGPdiskUnmounterImpWin32::AskUnmount(
const CPGPdiskContext& context,
const char *pathOrRoot,
void *parentWnd,
PGPUInt32 flags)
{
using namespace UCommonStrings;
// Need valid parentWnd window.
HWND hwndParent = static_cast<HWND>(parentWnd);
if (IsNull(hwndParent))
hwndParent = CWindow::GetDesktopWindow();
// Check uniqueness of current command.
SClaimedCommand command(CCommandClaimer::kUnmountDisk, pathOrRoot);
// get disk set and disk
CPGPdiskDiskSet diskSet(context);
CPGPdiskDiskIter diskIter(diskSet);
CPGPdiskDisk disk;
if (!diskIter.SearchOnPath(pathOrRoot, disk) &&
!diskIter.SearchOnRoot(pathOrRoot, disk))
{
THROW_PGPERROR(kPGPClientError_DiskNotMounted);
}
// get unmount prefs
PGPBoolean forceIt = (flags & CPGPdiskUnmounter::kForceUnmountFlag);
PGPBoolean silently = (flags & CPGPdiskUnmounter::kSilentUnmountFlag);
CPGPclPrefs clPrefs(context.PGPclPrefs());
PGPBoolean allowForcible = clPrefs.GetBoolean(
kPGPPrefDiskAllowForcibleUnmounts);
PGPBoolean alwaysForce = clPrefs.GetBoolean(
kPGPPrefDiskAlwaysForceUnmounts);
if (allowForcible && alwaysForce)
forceIt = TRUE;
// put it all together for the right kind of unmount
try
{
diskSet.Unmount(disk, forceIt);
}
catch (CComboError& caughtErr)
{
PGPBoolean userSaidForce = FALSE;
if (!(forceIt || silently) && allowForcible &&
(caughtErr.pgpErr == kPGPClientError_FilesOpenOnDisk))
{
CMessageBox messageBox;
CMessageBox::Button result = messageBox.Display(
Get(kAskIfForceUnmount), Get(kGenericMsgBoxTitle), NULL,
CMessageBox::kWarningTone, CMessageBox::kYesNoStyle,
CMessageBox::kNoButton);
userSaidForce = (result == CMessageBox::kYesButton);
if (userSaidForce)
diskSet.Unmount(disk, TRUE);
else
THROW_PGPERROR(kPGPError_UserAbort);
}
else
{
throw;
}
}
}
void
CPGPdiskUnmounterImpWin32::AskUnmountAll(
const CPGPdiskContext& context,
void *parentWnd,
PGPUInt32 flags)
{
using namespace UCommonStrings;
// Need valid parentWnd window.
HWND hwndParent = static_cast<HWND>(parentWnd);
if (IsNull(hwndParent))
hwndParent = CWindow::GetDesktopWindow();
// Check uniqueness of current command.
SClaimedCommand command(CCommandClaimer::kUnmountAllDisks);
// get disk set
CPGPdiskDiskSet diskSet(context);
// get unmount prefs
PGPBoolean forceIt = (flags &
CPGPdiskUnmounter::kForceUnmountFlag);
PGPBoolean silently = (flags &
CPGPdiskUnmounter::kSilentUnmountFlag);
PGPBoolean timedOut = (flags &
CPGPdiskUnmounter::kTimedOutUnmountAllFlag);
PGPBoolean shutDown = (flags &
CPGPdiskUnmounter::kShutdown);
CPGPclPrefs clPrefs(context.PGPclPrefs());
PGPBoolean allowForcible;
PGPBoolean alwaysForce;
// In case we are shutting down, force the unmount (why
// not. The user is shutting down after all) This fixes
// the problem of PGPtray crashing on shutdown with NULL
// prefRef -wjb
allowForcible=alwaysForce=TRUE;
if(!shutDown)
{
if(clPrefs.IsAttached())
{
allowForcible = clPrefs.GetBoolean(
kPGPPrefDiskAllowForcibleUnmounts);
alwaysForce = clPrefs.GetBoolean(
kPGPPrefDiskAlwaysForceUnmounts);
}
}
// End wjb changes
if (allowForcible && alwaysForce)
forceIt = TRUE;
// put it all together for the right kind of unmountall
try
{
if (timedOut)
diskSet.UnmountTimedOut(forceIt);
else
diskSet.UnmountAll(forceIt);
}
catch (CComboError& caughtErr)
{
PGPBoolean userSaidForce = FALSE;
if(!(silently) && (caughtErr.pgpErr == kPGPClientError_DiskNotMounted))
{
CMessageBox messageBox;
messageBox.Display(
Get(kNoPGPdisksToUnmount), Get(kGenericMsgBoxTitle), NULL,
CMessageBox::kWarningTone);
THROW_PGPERROR(kPGPError_UserAbort);
}
if (!(forceIt || silently) && allowForcible &&
(caughtErr.pgpErr == kPGPClientError_FilesOpenOnDisk))
{
CMessageBox messageBox;
CMessageBox::Button result = messageBox.Display(
Get(kAskIfForceUnmountAll), Get(kGenericMsgBoxTitle), NULL,
CMessageBox::kWarningTone, CMessageBox::kYesNoStyle,
CMessageBox::kNoButton);
userSaidForce = (result == CMessageBox::kYesButton);
if (userSaidForce)
{
if (timedOut)
diskSet.UnmountTimedOut(TRUE);
else
diskSet.UnmountAll(TRUE);
}
else
{
THROW_PGPERROR(kPGPError_UserAbort);
}
}
else
{
throw;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -