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

📄 cpgpdiskappvolumes.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	return derr;
}

// ConvertPGPdisk attempts to convert a PGPdisk with bad CAST to one
// with good CAST.

DualErr 
CPGPdiskApp::ConvertPGPdisk(LPCSTR path)
{
	DualErr derr;

	pgpAssertStrValid(path);

	if (IsFileReadOnly(path))
	{
		DisplayMessage(kPGPdiskBadCASTReadOnly);
	}
	else
	{
		PGPBoolean		restartingConversion;
		UserResponse	response;

		// Is this PGPdisk partially converted already?
		restartingConversion = WasPGPdiskConversionInterrupted(path);

		if (restartingConversion)
		{
			response = DisplayMessage(kPGPdiskBadCASTAskContinuePNM, 
				kPMBS_YesNo, kPMBF_YesButton);
		}
		else
		{
			response = DisplayMessage(kPGPdiskBadCASTAskConvertPNM, 
				kPMBS_YesNo, kPMBF_YesButton);
		}

		// Do what the user wants in regards to conversion.
		switch (response)
		{
			case kUR_Yes:
				{
					CConvertWizardSheet convertPGPdiskSheet;

					derr = convertPGPdiskSheet.mInitErr;

					if (derr.IsntError())
					{
						derr = convertPGPdiskSheet.ExecuteWizard(path, 
							restartingConversion);
					}
				}
				break;

			case kUR_No:
				derr = kPGDMinorError_UserAbort;
				break;
		}
	}

	return derr;
}

// CreatePGPdisk asks the user to specify a location for a new PGPdisk and
// then displays the wizard.

DualErr 
CPGPdiskApp::CreatePGPdisk(LPCSTR defaultPath)
{
	CDiskWizardSheet	newPGPdiskWizard;
	DualErr				derr;
	PGPBoolean			wasMainEnabled;

	// Forcibly disable main window so it doesn't flicker between dialogs.
	if (mMainDialog)
		wasMainEnabled = !mMainDialog->EnableWindow(FALSE);

	// Did our wizard initialize correctly?
	derr = newPGPdiskWizard.mInitErr;

	// Any drive letters free?
	if (derr.IsntError())
	{
		if (!AreAnyDriveLettersFree())
		{
			derr = DualErr(kPGDMinorError_NoDriveLettersFree);
		}
	}

	// Fire up the wizard.
	if (derr.IsntError())
	{
		derr = newPGPdiskWizard.ExecuteWizard(defaultPath);
	}

	// Re-enable main dialog if it was disabled.
	if (mMainDialog && wasMainEnabled)
		mMainDialog->EnableWindow(TRUE);

	return derr;
}

// MountPGPdisk first determines if we can mount the PGPdisk specified by
// 'path', and then creates an associated PGPdisk object and asks it to mount
// itself.

DualErr 
CPGPdiskApp::MountPGPdisk(
	LPCSTR			path, 
	PGPBoolean		forceReadOnly, 
	PGPBoolean		useDialog, 
	PGPBoolean		needMaster, 
	PGPUInt8		drive, 
	SecureString	*passphrase)
{
	CSinglePassphraseDialog	mountPassDlg(kSPDT_Mount);
	DualErr					derr;
	PGPBoolean				createdPGPdiskObject	= FALSE;
	PGPdisk					*pPGD;

	if (useDialog)
	{
		// Make sure our passphrase dialog initialized correctly.
		derr = mountPassDlg.mInitErr;
	}
	else
	{
		pgpAssert(IsLegalDriveNumber(drive));
		pgpAssertAddrValid(passphrase, SecureString);
	}

	// If the PGPdisk file is mounted already, show its window.
	if (derr.IsntError())
	{
		pPGD = mPGPdisks.FindPGPdisk(path);

		if (IsntNull(pPGD))
		{
			pPGD->BrowseToVolume();
			derr = DualErr(kPGDMinorError_FailSilently);
		}
	}

	// Validate the PGPdisk.
	if (derr.IsntError())
	{
		derr = ValidatePGPdisk(path);
	}

	// If the PGPdisk is opened by someone else with write access, fail.
	if (derr.IsntError())
	{
		if (IsFileInUseByWriter(path))
			derr = DualErr(kPGDMinorError_PGPdiskAlreadyInUse);
	}

	// Any drive letters free?
	if (derr.IsntError())
	{
		if (!AreAnyDriveLettersFree())
		{
			derr = DualErr(kPGDMinorError_NoDriveLettersFree);
		}
	}

	// Check if there is room to mount another volume.
	if (derr.IsntError())
	{
		if (mPGPdisks.GetNumPGPdisks() >= kMaxMountedPGPdisks)
			derr = DualErr(kPGDMinorError_MaxPGPdisksMounted);
	}

	// Create a new PGPdisk object.
	if (derr.IsntError())
	{
		try
		{
			pPGD = new PGPdisk();
		}
		catch (CMemoryException *ex)
		{
			derr = DualErr(kPGDMinorError_OutOfMemory);
			ex->Delete();
		}

		createdPGPdiskObject = derr.IsntError();
	}

	if (derr.IsntError())
	{
		derr = pPGD->mInitErr;
	}

	// Get the passphrase.
	if (derr.IsntError() && useDialog)
	{
		derr = mountPassDlg.AskForPassphrase(path, forceReadOnly, needMaster);
	}

	if (derr.IsntError())
	{
		// If the PGPdisk is marked as being mounted, warn.
//		if (GetPGPdiskMountedFlag(path))
//			DisplayMessage(kPGPdiskNotifyMountMaybeCorrupt);

		// Attempt the actual mount.
		if (useDialog)
		{
			passphrase = mountPassDlg.mPassphraseEdit.mContents;
			drive = mountPassDlg.mDriveCombo.mDriveNumber;

			if (!forceReadOnly)
				forceReadOnly = mountPassDlg.mReadOnlyValue;
		}

		derr = pPGD->Mount(path, passphrase, drive, forceReadOnly);
	}

#if PGPDISK_DEMOVERSION

	if (derr.IsntError())
	{
		// Set demo timeout after (first) successful mount.
		SetPGPdiskDemoTimeout();
	}

#endif // PGPDISK_DEMOVERSION

	if (derr.IsntError())
	{
		CString				dir;
		PGPdiskWin32Prefs	prefs;

		// Add the PGPdisk to the global list.
		mPGPdisks.AddPGPdisk(pPGD);

		// Update the last used directory registy key.
		GetDirectory(path, &dir);

		if (GetPGPdiskWin32Prefs(prefs).IsntError())
		{
			strcpy(prefs.lastOpenDir, dir);
			SetPGPdiskWin32Prefs(prefs);
		}

		// If not formatted, offer user chance to format.
		if (useDialog && !IsVolumeFormatted(pPGD->GetDrive()))
		{
			UserResponse button;

			button = DisplayMessage(kPGPdiskConfirmFormat, kPMBS_YesNo, 
				kPMBF_YesButton);

			if (button == kUR_Yes)
				pPGD->HighLevelFormatPGPdisk();
		}
	}

	// Cleanup if error.
	if (derr.IsError())
	{
		if (createdPGPdiskObject)
		{
			delete pPGD;
		}
	}
	
	return derr;
}

// UnmountPGPdisk unmounts the specified PGPdisk volume.

DualErr 
CPGPdiskApp::UnmountPGPdisk(PGPUInt8 drive, PGPBoolean isThisEmergency)
{
	DualErr		afterFact, derr;
	PGPBoolean	removedPGPdisk, unmountedChildren;
	PGPUInt32	i	= 0;
	PGPdisk		*pPGD;

	removedPGPdisk = unmountedChildren = FALSE;

	pgpAssert(IsLegalDriveNumber(drive));

	// Find the associated PGPdisk object.
	pPGD = mPGPdisks.FindPGPdisk(drive);

	if (IsNull(pPGD))
		derr = DualErr(kPGDMinorError_PGPdiskNotMounted);

	// If this PGPdisk has other PGPdisks mounted on it, we must perform a
	// depth-first unmount of all those PGPdisks first.

	while (derr.IsntError())
	{
		PGPdisk *pClient;

		pClient = mPGPdisks.EnumPGPdisks(i++);

		if (IsNull(pClient))
			break;

		if (!pClient->IsHostNetworked() && 
			(pClient->GetLocalHostDrive() == drive))
		{
			i = 0;
			derr = UnmountPGPdisk(pClient->GetDrive(), isThisEmergency);

			if (isThisEmergency)
				derr = DualErr::NoError;

			unmountedChildren = derr.IsntError();
		}
	}

	// Check if the PGPdisk has open files.
	if (derr.IsntError())
	{
		// If we unmounted any children, we may have to wait a little while
		// for the system to flush its cache. Try about 10 times.

		if (unmountedChildren)
		{
			i = 0;

			while (pPGD->HasOpenFiles() && (i++ < kMaxCheckOpenFilesAttempts))
				Sleep(500);
		}

		if (pPGD->HasOpenFiles())
			derr = DualErr(kPGDMinorError_FilesOpenOnDrive);

		if (isThisEmergency)
			derr = DualErr::NoError;
	}

	// Now we are safe to unmount. Remove it from the global list and unmount.
	if (derr.IsntError())
	{
		mPGPdisks.RemovePGPdisk(pPGD);
		removedPGPdisk = TRUE;

		derr = pPGD->Unmount(isThisEmergency);

		if (isThisEmergency)
			derr = DualErr::NoError;
	}

	// Delete the PGPdisk object.
	if (derr.IsntError())
	{
		delete pPGD;
	}

	// Cleanup if error.
	if (derr.IsError())
	{
		if (removedPGPdisk && pPGD->Mounted())
			mPGPdisks.AddPGPdisk(pPGD);
	}

	return derr;
}

// UnmountAllPGPdisks unmounts all mounted PGPdisks on the system.

DualErr 
CPGPdiskApp::UnmountAllPGPdisks(PGPBoolean isThisEmergency)
{
	DualErr		derr, storedDerr;
	PGPUInt32	i	= 0;
	PGPdisk		*pPGD;

	// Note how we enumerate on position 0, and increase this only when we
	// find a drive we can't unmount for whatever reason. This is because
	// if a drive can't be unmounted it won't be removed, and thus 'sticks'
	// at position 0, 1, etc.

	pPGD = mPGPdisks.EnumPGPdisks(i);

	while (IsntNull(pPGD))
	{
		PGPUInt8 drive;

		pgpAssert(pPGD->Mounted());
		drive = pPGD->GetDrive();

		// Now attempt the unmount.
		derr = UnmountPGPdisk(drive, isThisEmergency);

		if (isThisEmergency)
			derr = DualErr::NoError;

		// If there is an error, note that we saw an error and continue
		// unmounting.

		if (derr.IsError())
		{
			if (storedDerr.IsntError())
				storedDerr = derr;

			derr = DualErr::NoError;
			i++;
		}

		pPGD = mPGPdisks.EnumPGPdisks(i);
	}

	return storedDerr;
}

⌨️ 快捷键说明

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