📄 cnewdiskwizard.cpp
字号:
// Class CNewDiskWizDonePage member functions
PGPInt32
CNewDiskWizDonePage::OnPsnSetActive()
{
PGPInt32 result = CPGPdiskPage::OnPsnSetActive();
if (result != 0)
return result;
SetWizButtons(PSWIZB_FINISH);
return 0;
}
// Class CNewDiskWizIntroPage member functions
BOOL
CNewDiskWizIntroPage::OnInitDialog(HWND focusCtrl)
{
CPGPdiskPage::OnInitDialog(focusCtrl);
CWindow(GetParent()).Center();
return FALSE;
}
PGPInt32
CNewDiskWizIntroPage::OnPsnSetActive()
{
PGPInt32 result = CPGPdiskPage::OnPsnSetActive();
if (result != 0)
return result;
SetWizButtons(PSWIZB_NEXT);
return 0;
}
// Class CNewDiskWizVolInfoPage member functions
void
CNewDiskWizVolInfoPage::SavePrefs()
{
// Save prefs.
CPGPclPrefs prefs(mPInfo->pContext->PGPclPrefs());
prefs.SetNumber(kPGPPrefDiskLastCreateSize,
static_cast<PGPUInt32>(mSizeValue));
prefs.SetNumber(kPGPPrefDiskLastCreateScale, mCreateScale);
CPath newPrefDir;
mPInfo->path.GetDirPart(newPrefDir);
prefs.SetBoolean(kPGPPrefDiskDefaultMountAtStartup,
mPInfo->mountAtStartup);
prefs.SetBoolean(kPGPPrefDiskLastAlgorithm, mPInfo->algorithm);
prefs.SetNumber(kPGPPrefDiskLastAlgorithm, mPInfo->algorithm);
prefs.SetNumber(kPGPPrefDiskLastFileSystem, mPInfo->fileSys);
prefs.SetString(kPGPPrefDiskLastCreateRoot, mPInfo->root);
prefs.Flush();
}
void
CNewDiskWizVolInfoPage::FormatSizeText(PGPUInt64 kbSize, CString& text) const
{
CString numString;
if (kbSize < FudgeSizeValue(PFLConstants::kKbPerMb, TRUE))
{
_ui64toa(kbSize, numString.GetBuffer(33), 10);
numString.ReleaseBuffer();
text.Format("%s KB", numString.Get());
}
else if (kbSize < FudgeSizeValue(PFLConstants::kKbPerGb, TRUE))
{
_ui64toa(kbSize/PFLConstants::kKbPerMb, numString.GetBuffer(33), 10);
numString.ReleaseBuffer();
text.Format("%s MB", numString.Get());
}
else
{
_ui64toa(kbSize/PFLConstants::kKbPerGb, numString.GetBuffer(33), 10);
numString.ReleaseBuffer();
text.Format("%s GB", numString.Get());
}
}
PGPUInt32
CNewDiskWizVolInfoPage::FudgeSizeValue(PGPUInt32 size, PGPBoolean scale) const
{
if (scale)
{
return static_cast<PGPUInt32>(
(kScaleStepFactor-1 + kSizeFudgeFraction)*size);
}
else
{
return static_cast<PGPUInt32>(kSizeFudgeFraction*size);
}
}
void
CNewDiskWizVolInfoPage::SizeScaleToKb(
PGPUInt32 sizeValue,
PGPdiskUIPriv::CreateScale createScale,
PGPUInt64& kbSize)
{
switch (createScale)
{
case PGPdiskUIPriv::kKbScale:
kbSize = sizeValue;
break;
case PGPdiskUIPriv::kMbScale:
if ((mLocalMaxKbSize%PFLConstants::kKbPerMb >
FudgeSizeValue(PFLConstants::kKbPerMb)) &&
(sizeValue == mLocalMaxKbSize/PFLConstants::kKbPerMb + 1))
{
kbSize = mLocalMaxKbSize;
}
else
{
kbSize = sizeValue*PFLConstants::kKbPerMb;
}
break;
case PGPdiskUIPriv::kGbScale:
if ((mLocalMaxKbSize%PFLConstants::kKbPerGb >
FudgeSizeValue(PFLConstants::kKbPerGb)) &&
(sizeValue == mLocalMaxKbSize/PFLConstants::kKbPerGb + 1))
{
kbSize = mLocalMaxKbSize;
}
else
{
kbSize = sizeValue*PFLConstants::kKbPerGb;
}
break;
}
}
void
CNewDiskWizVolInfoPage::KbToSizeScale(PGPUInt64 kbSize)
{
if (kbSize < FudgeSizeValue(PFLConstants::kKbPerMb, TRUE))
{
mSizeValue = static_cast<PGPUInt32>(kbSize);
mCreateScale = PGPdiskUIPriv::kKbScale;
}
else if (kbSize < FudgeSizeValue(PFLConstants::kKbPerGb, TRUE))
{
mSizeValue = static_cast<PGPUInt32>(kbSize/PFLConstants::kKbPerMb);
mCreateScale = PGPdiskUIPriv::kMbScale;
}
else
{
mSizeValue = static_cast<PGPUInt32>(kbSize/PFLConstants::kKbPerGb);
mCreateScale = PGPdiskUIPriv::kGbScale;
}
}
PGPBoolean
CNewDiskWizVolInfoPage::SaveDialogValidateCallbackAux(const CPath& path)
{
using namespace UCommonStrings;
CPath root;
path.GetRootPart(root);
CommonString warnString;
PGPBoolean refuseChoice = FALSE;
if (!root.IsValidDirectory())
{
refuseChoice = TRUE;
warnString = kTellChoseInvalidVol;
}
else if (root.IsReadOnly())
{
refuseChoice = TRUE;
warnString = kTellChoseReadOnlyVol;
}
else if (path.IsValidFile() && path.IsReadOnly())
{
refuseChoice = TRUE;
warnString = kTellChoseReplaceFileInUseOrRO;
}
if (refuseChoice)
{
CMessageBox messageBox;
messageBox.Display(Get(warnString), Get(kNewDiskMsgBoxTitle),
Handle());
return FALSE;
}
else
{
return TRUE;
}
}
PGPBoolean
CNewDiskWizVolInfoPage::SaveDialogValidateCallback(
const CPath& path,
void *userVal)
{
CNewDiskWizVolInfoPage *pInfoPage = reinterpret_cast<
CNewDiskWizVolInfoPage *>(userVal);
pgpAssertAddrValid(pInfoPage, CNewDiskWizVolInfoPage);
return pInfoPage->SaveDialogValidateCallbackAux(path);
}
PGPBoolean
CNewDiskWizVolInfoPage::ValidateDiskPath()
{
using namespace UCommonStrings;
ImportValuesFromUI();
CMessageBox messageBox;
CMessageBox::Button result;
CPath root;
mPInfo->path.GetRootPart(root);
CPath dir;
mPInfo->path.GetDirPart(dir);
CPath fileName;
mPInfo->path.GetFileNamePart(fileName);
CPath pathWithExt(mPInfo->path);
pathWithExt.AddExtension(kPGPdiskFileExtension);
PGPBoolean shouldFail = FALSE;
if (!mPInfo->path.IsLegalPath())
{
messageBox.Display(Get(kTellIllegalPath), Get(kNewDiskMsgBoxTitle),
Handle());
shouldFail = TRUE;
}
if (fileName.IsEmpty())
{
messageBox.Display(Get(kTellEmptyFileName),
Get(kNewDiskMsgBoxTitle), Handle());
shouldFail = TRUE;
}
if (!shouldFail && !root.IsValidDirectory())
{
messageBox.Display(Get(kTellChoseInvalidVol),
Get(kNewDiskMsgBoxTitle), Handle());
shouldFail = TRUE;
}
if (!shouldFail && root.IsReadOnly())
{
messageBox.Display(Get(kTellChoseReadOnlyVol),
Get(kNewDiskMsgBoxTitle), Handle());
shouldFail = TRUE;
}
if (!shouldFail && pathWithExt.IsValidFile())
{
if (pathWithExt.IsReadOnly())
{
messageBox.Display(Get(kTellChoseReplaceFileInUseOrRO),
Get(kNewDiskMsgBoxTitle), Handle());
shouldFail = TRUE;
}
if (!shouldFail)
{
CString replaceFileStr;
replaceFileStr.Format(Get(kAskIfReplaceFile), mPInfo->path.Get());
result = messageBox.Display(replaceFileStr,
Get(kNewDiskMsgBoxTitle), Handle(),
CMessageBox::kWarningTone, CMessageBox::kYesNoStyle,
CMessageBox::kNoButton);
if (result == CMessageBox::kNoButton)
shouldFail = TRUE;
}
}
if (!shouldFail && !dir.IsValidDirectory())
{
CString replaceDirStr;
replaceDirStr.Format(Get(kAskIfCreateDir), dir.Get());
result = messageBox.Display(replaceDirStr,
Get(kNewDiskMsgBoxTitle), Handle(), CMessageBox::kWarningTone,
CMessageBox::kYesNoStyle, CMessageBox::kNoButton);
if (result == CMessageBox::kNoButton)
shouldFail = TRUE;
else
dir.RecurseCreateDir();
}
if (shouldFail)
{
mPathEdit.SetFocus();
mPathEdit.SetSel(0, -1);
return FALSE;
}
else
{
return TRUE;
}
}
void
CNewDiskWizVolInfoPage::ExportValuesToUI()
{
mPathEdit.SetWindowText(mPInfo->path);
mScaleCombo.Set(mCreateScale);
CString sizeText;
_ui64toa(mSizeValue, sizeText.GetBuffer(33), 10);
sizeText.ReleaseBuffer();
mSizeEdit.SetWindowText(sizeText);
}
void
CNewDiskWizVolInfoPage::ImportValuesFromUI()
{
mPathEdit.GetWindowText(mPInfo->path);
CString sizeText;
mSizeEdit.GetWindowText(sizeText);
mSizeValue = atoi(sizeText);
mCreateScale = mScaleCombo.Get();
SizeScaleToKb(mSizeValue, mCreateScale, mKbSize);
// Fudge a little bit on total blocks - need some for the headers.
mPInfo->blocks = ((mKbSize * PFLConstants::kBytesPerKb) /
kPGPdiskBlockSize) - kTypicalBlocksHeaders;
}
PGPBoolean
CNewDiskWizVolInfoPage::FixWarnOptions(PGPBoolean silently)
{
using namespace UCommonStrings;
PGPBoolean userWarned = FALSE;
// Make sure root is legal.
userWarned = UMountPoint::FixWarnRoot(mPInfo->root, FALSE,
silently, Handle(), Get(kNewDiskMsgBoxTitle));
// Make sure algorithm is legal.
CArray<PGPdiskEncryptionAlgorithm> algArray;
PGPUInt32 numAlgs;
CPGPdiskEngine::GetSupportedDiskAlgorithms(algArray, &numAlgs);
PGPBoolean isAlgoLegal = FALSE;
for (PGPUInt32 i = 0; i < numAlgs; i++)
{
if (algArray[i] == kPGPdiskOldCAST5Algorithm)
continue;
if (mPInfo->algorithm == algArray[i])
{
isAlgoLegal = TRUE;
break;
}
}
if (!isAlgoLegal)
mPInfo->algorithm = kPGPdiskOldCAST5Algorithm;
// Make sure filesystem is legal.
CArray<CPGPdiskFormatter::FileSysInfo> fsArray;
PGPUInt32 numFSes;
CPGPdiskFormatter::GetValidFilesystems(mPInfo->blocks, fsArray, numFSes);
PGPBoolean isFileSysLegal = FALSE;
for (i = 0; i < numFSes; i++)
{
if (fsArray[i].fsType == mPInfo->fileSys)
{
isFileSysLegal = TRUE;
break;
}
}
if (!isFileSysLegal)
{
// There has to be SOME legal filesystem.
pgpAssert(numFSes > 0);
mPInfo->fileSys = fsArray[0].fsType;
if (!silently)
{
CMessageBox messageBox;
messageBox.Display(Get(kTellInvalidFileSystem),
Get(kNewDiskMsgBoxTitle), Handle());
OnOptionsButton();
userWarned = TRUE;
}
}
return userWarned;
}
PGPBoolean
CNewDiskWizVolInfoPage::FixWarnSizeAndScale(PGPBoolean silently)
{
using namespace UCommonStrings;
CommonString failString;
PGPBoolean failThis = FALSE;
PGPBoolean userWarned = FALSE;
// Verify that the space being asked is not too big or small.
ImportValuesFromUI();
if (mKbSize < mLocalMinKbSize)
{
failThis = TRUE;
KbToSizeScale(mLocalMinKbSize);
failString = kNewDiskSizeTooSmall;
}
else if (mKbSize > mPlatformMaxKbSize)
{
failThis = TRUE;
KbToSizeScale(mLocalMaxKbSize);
failString = kNewDiskSizeTooBig;
}
else if (mKbSize > mLocalMaxKbSize)
{
failThis = TRUE;
KbToSizeScale(mLocalMaxKbSize);
failString = kNewDiskSizeNotEnoughSpace;
}
else
{
try
{
// check for files too big for Fat32
CString fileSys;
mPInfo->path.GetVolumeFileSys(fileSys);
PGPUInt64 maxFat32Kb =
FileSys::kMaxFat32FileMegs*PFLConstants::kKbPerMb;
// Added IsWin95Compatible for situations where we try to create 4 gig
// disks on an NTFS networked drive.
if ((
// FAT32 only allows 4 GB
(fileSys == FileSys::kFat32IdStr)||
// Win 9x can't support files over 4 GB
(UWinVersion::IsWin95Compatible())||
// NT4 can't id FAT32 networked volumes. No 4 GB unless NTFS.
((fileSys != FileSys::kNTFSIdStr)&&(UWinVersion::IsWinNT4Compatible())&&(!UWinVersion::IsWin2000Compatible()))
)
&& (mKbSize > maxFat32Kb))
{
failThis = TRUE;
KbToSizeScale(maxFat32Kb);
failString = kNewDiskSizeTooBigFat32;
}
}
catch (CComboError&) {}
}
// Handle case where we couldn't get free space of the drive.
if (mAreWeFailingDiskFree && !failThis)
{
try
{
if (!mPInfo->path.TestFreeVolumeSpace(mKbSize))
{
failThis = TRUE;
KbToSizeScale(mLocalMinKbSize);
failString = kNewDiskSizeNotEnoughSpace;
}
}
catch (CComboError&) { }
}
if (failThis)
{
if (!silently)
{
CMessageBox messageBox;
messageBox.Display(Get(failString), Get(kNewDiskMsgBoxTitle),
Handle());
userWarned = TRUE;
}
ExportValuesToUI();
if (!silently)
{
// Point out the incorrect size entered by the user.
mSizeEdit.SetFocus();
mSizeEdit.SetSel(0, -1);
}
}
return userWarned;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -