📄 cdiskwizdisksizepage.cpp
字号:
//////////////////////////////////////////////////////////////////////////////
// CDiskWizDiskSizePage.cpp
//
// Implementation of class CDiskWizDiskSizePage
//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 1998 by Network Associates, Inc.
// All rights reserved.
#include "StdAfx.h"
#include <math.h>
#include "PGPdiskPfl.h"
#include "PGPdiskPrefs.h"
#include "UtilityFunctions.h"
#include "CDiskWizardSheet.h"
#include "CDiskWizDiskSizePage.h"
#include "File.h"
#include "Globals.h"
#include "PGPdiskHelpIds.h"
////////////
// Constants
////////////
const PGPUInt32 kMaxSliderTicks = 40;
static LPCSTR kFreeSize1MsgString =
"You have %s of free space available, but the largest size PGPdisk you "
"can create here will be slightly smaller.";
static LPCSTR kFreeSize2MsgString =
"You have %s of free space available, but the largest size PGPdisk you "
"can create here will be %s.";
static LPCSTR kFreeSize3MsgString =
"PGPdisk was unable to determine the amount of available free space. "
"The maximum possible size for a PGPdisk is %s.";
/////////////////////
// Context help array
/////////////////////
static PGPUInt32 HelpIds[] =
{
IDC_SIZE_EDIT, IDH_PGPDISKAPP_DISKWIZSIZESIZEEDIT,
IDC_SIZE_SPIN, IDH_PGPDISKAPP_DISKWIZSIZESIZESPIN,
IDC_MB_CHECK, IDH_PGPDISKAPP_DISKWIZSIZEMBCHECK,
IDC_KB_CHECK, IDH_PGPDISKAPP_DISKWIZSIZEKBCHECK,
IDC_SIZE_SLIDER, IDH_PGPDISKAPP_DISKWIZSIZESLIDER,
IDC_MINSIZE, IDH_PGPDISKAPP_DISKWIZSIZEMINTEXT,
IDC_MAXSIZE, IDH_PGPDISKAPP_DISKWIZSIZEMAXTEXT,
IDC_FREESIZE_TEXT, ((PGPUInt32) -1),
IDC_SIDEBAR, ((PGPUInt32) -1),
0,0
};
///////////////////////////
// MFC specific definitions
///////////////////////////
BEGIN_MESSAGE_MAP(CDiskWizDiskSizePage, CPropertyPage)
//{{AFX_MSG_MAP(CDiskWizDiskSizePage)
ON_WM_HELPINFO()
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_KB_CHECK, OnKbCheck)
ON_BN_CLICKED(IDC_MB_CHECK, OnMbCheck)
ON_EN_CHANGE(IDC_SIZE_EDIT, OnChangeSizeEdit)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////
// CDiskWizDiskSizePage public custom functions and non-default handlers
////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(CDiskWizDiskSizePage, CPropertyPage)
// The CDiskWizDiskSizePage default constructor.
CDiskWizDiskSizePage::CDiskWizDiskSizePage()
: CPropertyPage(CDiskWizDiskSizePage::IDD)
{
//{{AFX_DATA_INIT(CDiskWizDiskSizePage)
mSizeValue = 0;
mMaxSizeText = _T("");
mMinSizeText = _T("");
mFreeSizeText = _T("");
//}}AFX_DATA_INIT
mParentDiskWiz = NULL;
// Exorcise the big help button.
m_psp.dwFlags &= ~PSP_HASHELP;
}
// The CDiskWizDiskSizePage destructor.
CDiskWizDiskSizePage::~CDiskWizDiskSizePage()
{
}
// PreTranslateMessage sees all messages before MFC filters them. We switch
// the up and down arrows in the slider.
BOOL
CDiskWizDiskSizePage::PreTranslateMessage(MSG* pMsg)
{
switch (pMsg->message)
{
case WM_KEYDOWN:
case WM_KEYUP:
if (GetFocus()->GetSafeHwnd() == mSizeSlider.GetSafeHwnd())
{
PGPUInt8 vCode = pMsg->wParam & 0x7F;
switch (vCode)
{
case VK_UP:
pMsg->wParam = VK_DOWN;
break;
case VK_DOWN:
pMsg->wParam = VK_UP;
break;
}
}
break;
}
return CPropertyPage::PreTranslateMessage(pMsg);
}
///////////////////////////////////////////////////////
// CDiskWizDiskSizePage public default message handlers
///////////////////////////////////////////////////////
// OnSetActive is called when this page is made active. We make sure the
// correct buttons are enabled/disabled.
BOOL
CDiskWizDiskSizePage::OnSetActive()
{
pgpAssertAddrValid(mParentDiskWiz, CDiskWizardSheet);
mParentDiskWiz->SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
return CPropertyPage::OnSetActive();
}
// OnWizardNext is called when the 'Next' button is pressed. We perform
// data validation.
LRESULT
CDiskWizDiskSizePage::OnWizardNext()
{
try
{
PGPBoolean failThis = FALSE;
PGPUInt32 kbData;
if (CPropertyPage::OnWizardNext() == -1)
return -1;
// Get the size value in kilobytes.
if (mIsSizeInMb)
kbData = mSizeValue*kKbPerMeg;
else
kbData = mSizeValue;
// Verify that the space being asked is not too big or small.
if (kbData < kMinPGPdiskKbSize)
{
SetPGPdiskSize(kMinPGPdiskKbSize);
App->ReportError(kPGDMajorError_PGPdiskTooSmall);
failThis = TRUE;
}
else if (kbData > kMaxPGPdiskKbSize)
{
SetPGPdiskSize(mLocalMaxKbSize);
App->ReportError(kPGDMajorError_PGPdiskTooBig);
failThis = TRUE;
}
else if (kbData > mLocalMaxKbSize)
{
SetPGPdiskSize(mLocalMaxKbSize);
App->ReportError(kPGDMajorError_NotEnoughDiskSpace);
failThis = TRUE;
}
// Handle special case where we can't be sure of the amount of free
// space on the host drive.
if (mAreWeFailingDiskFree && !failThis)
{
CString dir;
DualErr dummyErr;
PGPBoolean isEnoughSpace;
// Get the directory to test.
dummyErr = App->GetDirectory(mParentDiskWiz->mPath, &dir);
// Test if there really is enough space available. If we can't
// tell then don't fail.
if (dummyErr.IsntError())
{
dummyErr = App->BruteForceTestIfEnoughSpace(dir,
EstimateDiskSizeFromDataSize(kbData), &isEnoughSpace);
}
if (dummyErr.IsntError())
{
if (!isEnoughSpace)
{
App->ReportError(kPGDMajorError_NotEnoughDiskSpace);
failThis = TRUE;
}
}
}
if (failThis)
{
CString text;
// Point out the incorrect size entered by the user.
mSizeEditBox.SetFocus();
mSizeEditBox.GetWindowText(text);
mSizeEditBox.SetSel(0, text.GetLength(), FALSE);
return -1;
}
else
{
// Remember disk size.
SetPGPdiskSizeInRegistry();
mBlocksData = kbData*kBytesPerKb/kDefaultBlockSize;
return 0;
}
}
catch (CMemoryException *ex)
{
ex->Delete();
return 0;
}
}
///////////////////////////////////////////////////////////////////////////
// CDiskWizDiskSizePage protected custom functions and non-default handlers
///////////////////////////////////////////////////////////////////////////
// ConvertControlsToKb prepares the controls to show KB sizes.
void
CDiskWizDiskSizePage::ConvertControlsToKb()
{
PGPUInt32 nMin, nMax, numTicks;
mKbButton.SetCheck(1);
mMbButton.SetCheck(0);
mIsSizeInMb = FALSE;
nMin = kMinPGPdiskKbSize;
nMax = min(kKbPerMeg, mLocalMaxKbSize);
// If current size is out of range, change it.
UpdateData(TRUE);
if (mSizeValue < nMin)
{
mSizeValue = nMin;
}
else if (mSizeValue >nMax)
{
mSizeValue = nMax;
}
UpdateData(FALSE);
// Set the slider range.
numTicks = min(kMaxSliderTicks, nMax - nMin);
mUnitsPerTick = (double) (nMax - nMin)/numTicks;
mSizeSlider.SetRange(0, numTicks);
// Set the spinner range.
mSizeSpin.SetRange(nMin, nMax);
// Reposition the slider.
UpdateSliderFromSize();
// Update the min/max static fields.
try
{
mMinSizeText.Format("%dK", nMin);
mMaxSizeText.Format("%dK", nMax);
UpdateData(FALSE);
}
catch (CMemoryException *ex)
{
ex->Delete();
}
}
// ConvertControlsToMb prepares the controls to show MB sizes.
void
CDiskWizDiskSizePage::ConvertControlsToMb()
{
PGPUInt32 nMin, nMax, numTicks;
mKbButton.SetCheck(0);
mMbButton.SetCheck(1);
mIsSizeInMb = TRUE;
nMin = 1;
nMax = min(kMaxPGPdiskKbSize/kKbPerMeg, mLocalMaxKbSize/kKbPerMeg);
// If current size is out of range, change it.
UpdateData(TRUE);
if (mSizeValue < nMin)
{
mSizeValue = nMin;
}
else if (mSizeValue >nMax)
{
mSizeValue = nMax;
}
UpdateData(FALSE);
// Set the slider range.
numTicks = min(kMaxSliderTicks, nMax - nMin);
mUnitsPerTick = (double) (nMax - nMin)/numTicks;
mSizeSlider.SetRange(0, numTicks);
// Set the spinner range.
mSizeSpin.SetRange(nMin, nMax);
// Reposition the slider.
UpdateSliderFromSize();
// Update the min/max static fields.
try
{
mMinSizeText.Format("%dMB", nMin);
mMaxSizeText.Format("%dMB", nMax);
UpdateData(FALSE);
}
catch (CMemoryException *ex)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -