📄 ueditmount.cpp
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: UEditMount.cpp,v 1.20 2002/11/13 15:34:05 pbj Exp $
____________________________________________________________________________*/
#include "pgpClassesConfig.h"
#include <shlobj.h>
#include "CFile.h"
#include "CComLibrary.h"
#include "CComObject.h"
#include "CMessageBox.h"
#include "CPath.h"
#include "CRegistryKey.h"
#include "UUnicode.h"
#include "UWinVersion.h"
#include "pgpClientLib.h"
#include "UCommonStrings.h"
#include "CPGPdiskEngine.h"
#include "CPGPclPrefs.h"
#include "PGPdiskUIPriv.h"
#include "CEditorWindow.h"
#include "CReEncryptWizard.h"
#include "UEditMount.h"
#include "pgplnlib.h"
_USING_PGP
_UNNAMED_BEGIN
const char kPathSepChar = '|';
_UNNAMED_END
// Class UEditMount member functions
PGPBoolean
UEditMount::ShouldWeForceReadOnly(
const CPath& path,
HWND parentWnd)
{
PGPBoolean forceReadOnly;
if (IsPGPError (PGPlnIsExpired(NULL, kPGPlnOperationGraceExpiration)))
THROW_PGPERROR(kPGPError_UserAbort);
// Sanity checks.
forceReadOnly = CFile::IsFileInUse(path) || path.IsReadOnly() ||
IsPGPError (PGPlnIsExpired(parentWnd, kPGPlnDiskWriteExpiration));
return forceReadOnly;
}
void
UEditMount::GetStartupPathArray(
const char *pathGlob,
CArray<CPath>& pathArray,
PGPUInt32& numPaths)
{
pgpAssertStrValid(pathGlob);
numPaths = 0;
// extract the paths from the glob
CString curPath;
PGPUInt32 i, length = strlen(pathGlob);
for (i = 0; i < length; i++)
{
if (pathGlob[i] == kPathSepChar)
{
pathArray.Resize(numPaths + 1);
pathArray[numPaths++] = curPath;
curPath.Empty();
}
else
{
curPath.Append(pathGlob[i]);
}
}
}
void
UEditMount::MakeStartupPathGlob(
const CArray<CPath>& pathArray,
PGPUInt32 numPaths,
CString& pathGlob)
{
// make the glob
pathGlob.Empty();
PGPUInt32 i;
for (i = 0; i < numPaths; i++)
{
pathGlob += pathArray[i];
pathGlob += kPathSepChar;
}
}
PGPBoolean
UEditMount::IsDiskMarkedForStartup(
const CPGPdiskContext& context,
const char *path)
{
pgpAssertStrValid(path);
try
{
CPath cpath(path);
cpath.Canonicalize(kPGPdiskFileExtension);
// get startup paths
CPGPclPrefs clPrefs(context.PGPclPrefs());
CString pathGlob;
clPrefs.GetString(kPGPPrefDiskMountAtStartupPaths, pathGlob);
CArray<CPath> pathArray;
PGPUInt32 numPaths;
GetStartupPathArray(pathGlob, pathArray, numPaths);
// look for the PGPdisk
PGPUInt32 i;
for (i = 0; i < numPaths; i++)
{
if (cpath.CompareNoCase(pathArray[i]))
return TRUE;
}
return FALSE;
}
catch (CComboError&) {return FALSE;}
}
void
UEditMount::MarkDiskForStartup(
const CPGPdiskContext& context,
const char *path)
{
pgpAssertStrValid(path);
CPath cpath(path);
cpath.Canonicalize(kPGPdiskFileExtension);
// remove duplicates
UnmarkDiskForStartup(context, path);
// get startup paths
CPGPclPrefs clPrefs(context.PGPclPrefs());
CString pathGlob;
clPrefs.GetString(kPGPPrefDiskMountAtStartupPaths, pathGlob);
CArray<CPath> pathArray;
PGPUInt32 numPaths;
GetStartupPathArray(pathGlob, pathArray, numPaths);
// add us
pathArray.Resize(numPaths + 1);
pathArray[numPaths++] = cpath;
// reglob
MakeStartupPathGlob(pathArray, numPaths, pathGlob);
// update the pref
clPrefs.SetString(kPGPPrefDiskMountAtStartupPaths, pathGlob);
}
void
UEditMount::UnmarkDiskForStartup(
const CPGPdiskContext& context,
const char *path)
{
pgpAssertStrValid(path);
CPath cpath(path);
cpath.Canonicalize(kPGPdiskFileExtension);
// get startup paths
CPGPclPrefs clPrefs(context.PGPclPrefs());
CString pathGlob;
clPrefs.GetString(kPGPPrefDiskMountAtStartupPaths, pathGlob);
CArray<CPath> pathArray;
PGPUInt32 numPaths;
GetStartupPathArray(pathGlob, pathArray, numPaths);
// constuct new path array without this PGPdisk
CArray<CPath> newPathArray;
PGPUInt32 i, newNumPaths = 0;
for (i = 0; i < numPaths; i++)
{
if (!cpath.CompareNoCase(pathArray[i]))
{
newPathArray.Resize(newNumPaths + 1);
newPathArray[newNumPaths++] = pathArray[i];
}
}
// reglob
MakeStartupPathGlob(newPathArray, newNumPaths, pathGlob);
// update the pref
clPrefs.SetString(kPGPPrefDiskMountAtStartupPaths, pathGlob);
}
PGPBoolean
UEditMount::CheckWarnCanModifyDisk(
const CPGPdiskContext& context,
const CPath& path,
HWND parentWnd,
const char *msgBoxTitle)
{
PGPBoolean forceReadOnly = ShouldWeForceReadOnly(path, parentWnd);
CPGPdiskDisk disk;
disk.Open(context, path, TRUE);
forceReadOnly = forceReadOnly | disk.AreUsersWiped();
DetectAndHandleOldPGPdisks(context, disk, path, parentWnd, forceReadOnly);
disk.Close();
if (forceReadOnly)
{
using namespace UCommonStrings;
CMessageBox messageBox;
messageBox.Display(Get(kTellCantModifyDisk), msgBoxTitle, parentWnd);
}
return !forceReadOnly;
}
void
UEditMount::DetectAndHandleInProgressReEncrypts(
const CPGPdiskContext& context,
CPGPdiskDisk& disk,
const CPath& path,
HWND parentWnd)
{
pgpAssert(disk.IsOpened());
if (disk.IsBeingReEncrypted())
{
using namespace UCommonStrings;
// Ask user to continue re-encryption.
CMessageBox messageBox;
CMessageBox::Button result = messageBox.Display(
Get(kAskIfContinueReEncrypt), Get(kReEncryptMsgBoxTitle),
parentWnd, CMessageBox::kQuestionTone, CMessageBox::kYesNoStyle,
CMessageBox::kYesButton);
if (result == CMessageBox::kYesButton)
{
disk.Close();
CReEncryptWizard reEncryptWiz;
reEncryptWiz.Display(context, path, parentWnd);
disk.Open(context, path);
}
else
{
THROW_PGPERROR(kPGPError_UserAbort);
}
}
}
void
UEditMount::DetectAndHandleOldPGPdisks(
const CPGPdiskContext& context,
CPGPdiskDisk& disk,
const CPath& path,
HWND parentWnd,
PGPBoolean& forceReadOnly)
{
using namespace UCommonStrings;
pgpAssert(disk.IsOpened());
if (disk.Algorithm() == kPGPdiskOldCAST5Algorithm)
{
CMessageBox messageBox;
// If uses old 'broken' CAST algorithm, warn or ask if re-encrypt.
if (forceReadOnly)
{
messageBox.Display(Get(kTellCantReEncryptOldCASTAlgorithm),
Get(kReEncryptMsgBoxTitle), parentWnd);
}
else
{
CMessageBox::Button result = messageBox.Display(
Get(kAskIfReEncryptOldCASTAlgorithm),
Get(kReEncryptMsgBoxTitle), parentWnd,
CMessageBox::kWarningTone, CMessageBox::kYesNoStyle,
CMessageBox::kYesButton);
if (result == CMessageBox::kYesButton)
{
disk.Close();
// Ask the user to re-encrypt.
CReEncryptWizard reEncryptWiz;
reEncryptWiz.Display(context, path, parentWnd);
disk.Open(context, path);
}
else
{
forceReadOnly = TRUE;
}
}
}
else if (!forceReadOnly && disk.HasOldHeaders())
{
// If older versions of headers, ask if convert.
CMessageBox messageBox;
CMessageBox::Button result = messageBox.Display(
Get(kAskIfConvertOldHeaders), Get(kReEncryptMsgBoxTitle),
parentWnd, CMessageBox::kWarningTone, CMessageBox::kYesNoStyle,
CMessageBox::kYesButton);
if (result == CMessageBox::kYesButton)
{
// Open in read/write mode, when closed new headers written.
disk.Close();
disk.Open(context, path);
}
else
{
forceReadOnly = TRUE;
}
}
}
void
UEditMount::DetectAndHandleWipedPGPdisks(
const CPGPdiskContext& context,
CPGPdiskDisk& disk,
const CPath& path,
HWND parentWnd)
{
using namespace UCommonStrings;
if (disk.AreUsersWiped())
{
CMessageBox messageBox;
CMessageBox::Button result = messageBox.Display(
Get(kTellUsersWiped), Get(kGenericMsgBoxTitle),
parentWnd, CMessageBox::kWarningTone);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -