📄 umountpoint.cpp
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: UMountPoint.cpp,v 1.10 2002/11/13 23:16:02 wjb Exp $
____________________________________________________________________________*/
#include "pgpClassesConfig.h"
#include "UString.h"
#include "CChooseDirDialog.h"
#include "CMessageBox.h"
#include "CPath.h"
#include "UDynLink.h"
#include "UWinVersion.h"
#include "pgpClientErrors.h"
#include "FileSys.h"
#include "UCommonStrings.h"
#include "UMountPoint.h"
#include "shlwapi.h"
_USING_PGP
// UMountPoint functions
void
UMountPoint::AskChooseMountPoint(
HWND parentWnd,
const char *warnDlgTitle,
CPath& root)
{
do
{
CChooseDirDialog chooseDirDlg;
chooseDirDlg.Choose(parentWnd, UCommonStrings::Get(
UCommonStrings::kMountPointChooseText), root);
}
while (FixWarnRoot(root, TRUE, FALSE, parentWnd, warnDlgTitle));
}
typedef BOOL (WINAPI *PATHISNETWORKPATH)(LPCSTR);
PGPBoolean
UMountPoint::FixWarnRoot(
CPath& root,
PGPBoolean mustBeMP,
PGPBoolean silently,
HWND parentWnd,
const char *warnDlgTitle)
{
using namespace UCommonStrings;
// Validate passed-in root.
CommonString warnString;
CPath croot(root);
PGPBoolean rootBad = FALSE;
PGPBoolean weWarned = FALSE;
PGPUInt32 freeDrives = CPath::GetFreeDrives();
croot.EndInSlash();
if (!croot.IsLegalPath())
{
rootBad = TRUE;
warnString = kTellIllegalPath;
}
else if (croot.IsPlainLocalRoot())
{
if (mustBeMP)
{
rootBad = TRUE;
warnString = kTellBadMointPointDir;
}
else if (!(freeDrives & (1 << croot.GetDriveNum())))
{
rootBad = TRUE;
warnString = kTellPLRootInUse;
}
}
else
{
if (UWinVersion::IsWin2000Compatible())
{
try
{
CPath volRoot;
HINSTANCE hShlwapi;
PATHISNETWORKPATH PathIsNetworkPathProc;
croot.GetVolumeRoot(volRoot);
CString fileSys;
volRoot.GetVolumeFileSys(fileSys);
hShlwapi=LoadLibrary("shlwapi.dll");
if(hShlwapi!=NULL)
{
PathIsNetworkPathProc=
(PATHISNETWORKPATH)GetProcAddress(hShlwapi,"PathIsNetworkPathA");
if(PathIsNetworkPathProc!=NULL)
{
const char *path;
path=NULL;
path=croot.Get();
if(path!=NULL)
{
if((PathIsNetworkPathProc)(path))
{
rootBad = TRUE;
warnString = kTellMountPointNetworked;
}
}
}
FreeLibrary(hShlwapi);
}
if (croot == volRoot)
{
rootBad = TRUE;
warnString = kTellMountPointDirInUse;
}
else if ((fileSys != FileSys::kNTFSIdStr) ||
(croot.IsValidDirectory() &&
!croot.IsDirectoryEmpty()))
{
rootBad = TRUE;
warnString = kTellBadMointPointDir;
}
else if (!croot.IsValidDirectory())
{
if (!silently)
{
CMessageBox messageBox;
CString createWarn;
createWarn.Format(Get(kAskIfCreateDir), croot);
CMessageBox::Button result = messageBox.Display(
createWarn, warnDlgTitle, parentWnd,
CMessageBox::kWarningTone,
CMessageBox::kYesNoStyle,
CMessageBox::kYesButton);
if (result == CMessageBox::kYesButton)
croot.RecurseCreateDir();
else
return TRUE;
}
else
{
rootBad = TRUE;
warnString = kTellBadMointPointDir;
}
}
}
catch (CComboError&)
{
rootBad = TRUE;
warnString = kTellIllegalPath;
}
}
else
{
rootBad = TRUE;
warnString = kTellInvalidPLRoot;
}
}
// Find valid root if need to.
if (rootBad)
{
if (!silently)
{
weWarned = TRUE;
CMessageBox msgBox;
msgBox.Display(Get(warnString), warnDlgTitle);
}
PGPBoolean foundRoot = FALSE;
PGPUInt8 i;
for (i = 2; i < CPath::kMaxDrives; i++)
{
if (freeDrives & (1 << i))
{
root.Format("%c:\\", UString::NumberToLetter(i));
foundRoot = TRUE;
break;
}
}
if (!foundRoot)
THROW_PGPERROR(kPGPClientError_DiskNoDrivesFree);
}
return weWarned;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -