⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cnewdiskwizard.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 4 页
字号:

void 
CNewDiskWizVolInfoPage::UpdateMinMaxSizeFromPath(const CPath& path)
{
	using namespace UCommonStrings;

	ImportValuesFromUI();

	// Get min/max possible PGPdisk sizes.
	mPlatformMaxKbSize = PGPdiskUIPriv::kDiskMaxGbSize;
	mPlatformMaxKbSize *= PFLConstants::kKbPerGb;	// stop C4307 woohoo!

	mPlatformMinKbSize = PGPdiskUIPriv::kDiskMinKbSize;

	// Get free space. Note if failed (which will happen on network volumes).
	PGPUInt64	bytesFree;

	try
	{
		bytesFree = path.GetFreeVolumeSpace();

		mAreWeFailingDiskFree = FALSE;
		mKbFree = bytesFree / PFLConstants::kBytesPerKb;
	}
	catch (CComboError&)
	{
		mAreWeFailingDiskFree = TRUE;
		mKbFree = mPlatformMaxKbSize;	// fake max amount of space
	}

	// Is user replacing an existing file? If so, add its size to free space.
	try
	{
		CPath	path2(path);
		path2.AddExtension(kPGPdiskFileExtension);

		CFile	existingFile;
		existingFile.Open(path2, CFile::kReadOnlyFlag);

		PGPUInt64	bytesFile	= existingFile.GetLength();

		mKbFree += bytesFile/PFLConstants::kBytesPerKb;
		existingFile.Close();
	}
	catch (CComboError&) { }

	// Calculate max and min PGPdisk sizes we can create.
	mLocalMaxKbSize	= pgpMin(mKbFree, mPlatformMaxKbSize);
	mLocalMinKbSize	= mPlatformMinKbSize;

	pgpAssert(mLocalMaxKbSize >= mLocalMinKbSize);

	// Update the contents of the free size message shown to the user.
	CString	freeSizeText;

	if (mAreWeFailingDiskFree)
	{
		freeSizeText = Get(kNewDiskFreeSpaceUnknownText);
	}
	else
	{
		CString freeSpaceStr;
		FormatSizeText(mKbFree, freeSpaceStr);

		freeSizeText.Format(Get(kNewDiskFreeSpaceKnownText), 
			freeSpaceStr.Get());
	}

	mFreeSizeText.SetWindowText(freeSizeText);
}

void 
CNewDiskWizVolInfoPage::InitControls()
{
	CPGPclPrefs	prefs(mPInfo->pContext->PGPclPrefs());

	mScaleCombo.Fill();
	mSizeUDCtrl.SetRange(1, UD_MAXVAL);

	// Get default path.
	mPathEdit.LimitText(MAX_PATH);
	mPathEdit.SetWindowText(mPInfo->path);

	// Get default root.
	prefs.GetString(kPGPPrefDiskLastCreateRoot, mPInfo->root);

	UMountPoint::FixWarnRoot(mPInfo->root, FALSE, TRUE, Handle());

	if (mPInfo->root.IsPlainLocalRoot() || 
		!UWinVersion::IsWin2000Compatible())
	{
		mDrive = mPInfo->root.GetDriveLet();
		mMountPoint.Empty();
		mChoseDrive = TRUE;
	}
	else
	{
		mDrive = CPath::kMaxDrives + 1;
		mMountPoint = mPInfo->root;
		mChoseDrive = FALSE;
	}

	// Get default size and scale.
	mSizeValue = prefs.GetNumber(kPGPPrefDiskLastCreateSize);

	mCreateScale = static_cast<PGPdiskUIPriv::CreateScale>(
		prefs.GetNumber(kPGPPrefDiskLastCreateScale));

	// Get default algorithm and fileSys.
	mPInfo->algorithm = static_cast<PGPdiskEncryptionAlgorithm>(
		prefs.GetNumber(kPGPPrefDiskLastAlgorithm));
	mPInfo->fileSys = static_cast<FileSys::Type>(
		prefs.GetNumber(kPGPPrefDiskLastFileSystem));

	// Get default mount at startup value.
	mPInfo->mountAtStartup = prefs.GetBoolean(
		kPGPPrefDiskDefaultMountAtStartup);

	ExportValuesToUI();

	// Calculate min/max size values.
	UpdateMinMaxSizeFromPath(mPInfo->path);

	// Legalize default values.
	FixWarnSizeAndScale(TRUE);
	FixWarnOptions(TRUE);

	// Output all values to the dialog.
	ExportValuesToUI();
}

void 
CNewDiskWizVolInfoPage::OnOptionsButton()
{
	ImportValuesFromUI();

	if (!ValidateDiskPath())
		return;

	UpdateMinMaxSizeFromPath(mPInfo->path);

	if (FixWarnSizeAndScale())
		return;

	try
	{
		CNewDiskOptionsDialog	optionsDlg;

		optionsDlg.Display(Handle(), mPInfo->blocks, mPInfo->algorithm, 
			mPInfo->fileSys, mDrive, mMountPoint, mChoseDrive, 
			mPInfo->mountAtStartup);

		if (mChoseDrive)
			mPInfo->root.MakePlainLocalRoot(mDrive);
		else
			mPInfo->root = mMountPoint;

		mUserChangedOptions = TRUE;
	}
	catch (CComboError& error)
	{
		if (error.pgpErr != kPGPError_UserAbort)
			throw;
	}
}

void 
CNewDiskWizVolInfoPage::OnBrowseButton()
{
	ImportValuesFromUI();

	try
	{
		CPath	defaultPath(mPInfo->path);

		CSaveFileDialog	saveDialog;

		saveDialog.Choose(Handle(), mPInfo->path, defaultPath, 
			UCommonStrings::Get(UCommonStrings::kNewDiskSaveDialogTitle), 
			PGPdiskUIPriv::kDiskFileFilter, 
			kPGPdiskFileExtension, 
			SaveDialogValidateCallback, this);

		if (CPath::AreShowingExtensions())
			mPInfo->path.AddExtension(kPGPdiskFileExtension);
		else
			mPInfo->path.RemoveExtension();

		ExportValuesToUI();
		UpdateMinMaxSizeFromPath(mPInfo->path);
	}
	catch (CComboError& error)
	{
		if (error.pgpErr != kPGPError_UserAbort)
			throw;
	}
}

BOOL 
CNewDiskWizVolInfoPage::OnCommand(
	PGPUInt16	notifyCode, 
	PGPUInt16	itemId, 
	HWND		ctrl)
{
	switch (notifyCode)
	{
	case BN_CLICKED:
		switch (itemId)
		{
			case IDC_OPTIONS_BUTTON:
				OnOptionsButton();
				return TRUE;

			case IDC_BROWSE_BUTTON:
				OnBrowseButton();
				return TRUE;
		}
		break;
	}

	return CPGPdiskPage::OnCommand(notifyCode, itemId, ctrl);
}

BOOL 
CNewDiskWizVolInfoPage::OnInitDialog(HWND focusCtrl)
{
	CPGPdiskPage::OnInitDialog(focusCtrl);

	mOptionsButton.Subclass(GetDlgItem(IDC_OPTIONS_BUTTON));
	mScaleCombo.Subclass(GetDlgItem(IDC_SCALE_COMBO));
	mPathEdit.Subclass(GetDlgItem(IDC_PATH_EDIT));
	mSizeEdit.Subclass(GetDlgItem(IDC_SIZE_EDIT));
	mFreeSizeText.Subclass(GetDlgItem(IDC_FREESIZE_TEXT));
	mSizeUDCtrl.Subclass(GetDlgItem(IDC_SIZE_UDCTRL));

	InitControls();

	return FALSE;
}

PGPInt32 
CNewDiskWizVolInfoPage::OnPsnSetActive()
{
	PGPInt32	result	= CPGPdiskPage::OnPsnSetActive();

	if (result != 0)
		return result;

	mUserChangedOptions = FALSE;
	SetWizButtons(PSWIZB_BACK | PSWIZB_NEXT);

	return 0;
}

PGPInt32 
CNewDiskWizVolInfoPage::OnPsnWizNext()
{
	PGPInt32	result	= CPGPdiskPage::OnPsnWizNext();

	if (result != 0)
		return result;

	ImportValuesFromUI();

	if (!ValidateDiskPath())
		return -1;

	UpdateMinMaxSizeFromPath(mPInfo->path);

	if (FixWarnSizeAndScale())
		return -1;

	if (FixWarnOptions(!mUserChangedOptions))
	{
		OnOptionsButton();
		return -1;
	}

	if (USecurity::IsRemoteSession() && 
		UWinVersion::IsWin2000Compatible())
	{
		using namespace UCommonStrings;

		UMountPoint::FixWarnRoot(mPInfo->root, TRUE, TRUE, 
			Handle());

		if (mPInfo->root.IsPlainLocalRoot())
		{
			CMessageBox	messageBox;
			messageBox.Display(Get(kTellChoseDriveInWin2kTerm), 
				Get(kNewDiskMsgBoxTitle), Handle());

			mDrive = mPInfo->root.GetDriveLet();
			mChoseDrive = FALSE;
			mMountPoint.Empty();

			OnOptionsButton();
			return -1;
		}
	}

	mPInfo->path.AddExtension(kPGPdiskFileExtension);
	SavePrefs();

	return 0;
}

BOOL IsWindowsXPOrGreater()
{
    OSVERSIONINFOEXA osvi = {0};

    osvi.dwOSVersionInfoSize = sizeof(osvi);

    if (!GetVersionExA((OSVERSIONINFOA*)&osvi))
    {
        // If it failed, it must be a down level platform
        osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
        GetVersionExA((OSVERSIONINFOA*)&osvi);
    }
    
    return (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId &&
        ((osvi.dwMajorVersion > 5) ||
        (osvi.dwMajorVersion == 5 && (osvi.dwMinorVersion > 0 ||
        (osvi.dwMinorVersion == 0 && LOWORD(osvi.dwBuildNumber) > 2195)))));
}

// Class CNewDiskWizard member functions

void 
CNewDiskWizard::Display(
	const CPGPdiskContext&	context, 
	const char				*defaultPath, 
	HWND					parentWnd)
{
	using namespace UCommonStrings;
	pgpAssert(CWindow(parentWnd).IsWindow());

	// Get a valid default path.
	CPath	cDefaultPath;

	if (IsntNull(defaultPath))
		cDefaultPath = defaultPath;

	ConstructValidDefaultPath(context, cDefaultPath);

	// Create the wizard pages.
	CNewUserPages			newUserPages;
	CPGPGlobalRandomPool	randomPool(context.PGPContext());
	DiskWizardInfo			diInfo;
	const char				*title	= Get(kNewDiskTitle);

	diInfo.pNewUserPages	= &newUserPages;
	diInfo.pContext			= &context;
	diInfo.pRandomPool		= &randomPool;
	diInfo.path				= cDefaultPath;
	diInfo.blocks			= 0;
	diInfo.fileCreated		= FALSE;

	CPGPdiskUserSet	diskUsers;	// empty
	newUserPages.Create(&context, &diskUsers, title, 
		Get(kNewDiskMsgBoxTitle), TRUE, TRUE, TRUE);

	CNewDiskWizADKPage		adkPage(&diInfo);
	CNewDiskWizCreationPage	creationPage(&diInfo);
	CNewDiskWizDonePage		donePage(&diInfo);
	CNewDiskWizIntroPage	introPage(&diInfo);
	CNewDiskWizVolInfoPage	volInfoPage(&diInfo);
	CRandomDataPage			randomPage(&diInfo.algorithm, 
		diInfo.pRandomPool);

	LoadSidebar();

	adkPage.Create(title);
	creationPage.Create(title);
	donePage.Create(title, FALSE, &mSidebarBitmap, &mSidebarPalette);
	introPage.Create(title, FALSE, &mSidebarBitmap, &mSidebarPalette);
	randomPage.Create(title);
	volInfoPage.Create(title);

	AddPage(&introPage);
	AddPage(&volInfoPage);
	AddPage(&adkPage);
	AddPage(newUserPages.GetAskChoicePage());
	AddPage(newUserPages.GetAskPassPage());
	AddPage(newUserPages.GetBadPassPage());
	AddPage(newUserPages.GetAskPubKeyPage());
	AddPage(&randomPage);
	AddPage(&creationPage);
	AddPage(&donePage);

	// Show the wizard.
	try
	{
		CPropertySheet::Create(parentWnd, TRUE);

		// We can't browse after creation with XP. The shell pukes.
//		if(!IsWindowsXPOrGreater())
//			diInfo.root.Browse();
	}
	catch (CComboError&)
	{
		try
		{
			// "I can make you all go away, any time I want to..."
			if (diInfo.fileCreated)
			{
				CPGPdiskDiskSet		diskSet(context);
				CPGPdiskDiskIter	diskIter(diskSet);
				CPGPdiskDisk		disk;

				if (diskIter.SearchOnPath(diInfo.path, disk))
					diskSet.Unmount(disk);

				// work around warn on delete
				CString temp(diInfo.path);
				temp += "not";

				CFile	deleter;

				deleter.Move(diInfo.path, temp);
				deleter.Delete(temp);
			}
		}
		catch (CComboError&) { }

		throw;
	}

	// flush prefs
	try
	{
		CPGPclPrefs	prefs(context.PGPclPrefs());
		prefs.Flush();
	}
	catch (CComboError&) { }
}

void 
CNewDiskWizard::ConstructValidDefaultPath(
	const CPGPdiskContext&	context, 
	CPath&					defaultPath)
{
	CPath	dir;
	defaultPath.GetDirPart(dir);

	// Get valid dir.
	if (dir.IsEmpty())
	{
		try
		{
			CPGPclPrefs	prefs(context.PGPclPrefs());
			prefs.GetString(kPGPPrefDiskLastSaveDir, dir);

			if (!dir.IsValidDirectory() || dir.IsReadOnly())
			{
				PGPclGetPath(kPGPclDefaultSaveAsFolder, 
					dir.GetBuffer(kPGPdiskMaxPathLength), 
					kPGPdiskMaxPathLength);
				dir.ReleaseBuffer();
			}
		}
		catch (CComboError&)
		{
			dir.ReleaseBuffer();
		}
	}
	else
	{
		// If default path specified, FAIL if it isn't valid for use.
		if (!dir.IsValidDirectory())
			THROW_PGPERROR(kPGPClientError_DiskDirNotFound);
		else if (dir.IsReadOnly())
			THROW_PGPERROR(kPGPClientError_DiskDirWriteProtected);
	}

	// Get a valid default filename.
	CPath	fileName;

	defaultPath.GetFileNamePart(fileName);
	fileName.RemoveExtension();

	if (fileName.IsEmpty())
	{
		fileName = UCommonStrings::Get(
			UCommonStrings::kNewDiskDefaultFilename);
	}

	// Find a filename that isn't taken.
	CString		suffix;
	PGPUInt32	i	= 1;

	while (TRUE)
	{
		CPath	curFilename(fileName);

		curFilename.Append(suffix);
		curFilename.AddExtension(kPGPdiskFileExtension);

		CPath	curPath(dir);
		curPath.EndInSlash();
		curPath.Append(curFilename);

		if (!curPath.IsValidPath())
		{
			defaultPath = curPath;
			break;
		}

		suffix.Format("%d", i++);
	}

	if (CPath::AreShowingExtensions())
		defaultPath.AddExtension(kPGPdiskFileExtension);
}

void 
CNewDiskWizard::LoadSidebar()
{
	CDC	dc;
	dc.AttachFromWindow(NULL);

	PGPUInt32	numBits	= dc.GetDeviceCaps(BITSPIXEL) * 
		dc.GetDeviceCaps(PLANES);

	PGPUInt32	uintRsrc;

	if (numBits <= 1)
		uintRsrc = IDB_SIDEBAR1;
	else if (numBits <= 4)
		uintRsrc = IDB_SIDEBAR4;
	else
		uintRsrc = IDB_SIDEBAR8;

	mSidebarBitmap.CreateWithPalette(UModuleInstance::Get(), 
		MAKEINTRESOURCE(uintRsrc), mSidebarPalette);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -