📄 cpgpdiskcmdline.cpp
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: CPGPdiskCmdLine.cpp,v 1.16 2002/11/12 18:56:09 pbj Exp $
____________________________________________________________________________*/
#include "pgpClassesConfig.h"
#include "CMessageBox.h"
#include "CPath.h"
#include "pgpClientLib.h"
#include "pgpClientErrors.h"
#include "UCommonStrings.h"
#include "CPGPdiskEngine.h"
#include "CPGPdiskUI.h"
#include "CCommandLine.h"
#include "CPGPdiskCmdLine.h"
#include "pgplnlib.h"
_USING_PGP
_UNNAMED_BEGIN
// Constants
const char *kMountCommand = "mount";
const char *kOpenCommand = "open";
const char *kUnmountCommand = "unmount";
const char *kUnmountAllCommand = "unmountall";
const char *kEditCommand = "edit";
const char *kCreateCommand = "create";
const char *kOptionsCommand = "options";
const char *kWipeCommand = "wipe";
const char *kWipeAllCommand = "wipeall";
CCommandLine::Rule kPGPdiskRules[] =
{
{kMountCommand, "", 1, 0xFFFFFFFF},
{kOpenCommand, "", 1, 0xFFFFFFFF},
{kUnmountCommand, "fs", 1, 0xFFFFFFFF},
{kUnmountAllCommand, "fst", 0, 0},
{kEditCommand, "", 1, 0xFFFFFFFF},
{kCreateCommand, "", 0, 1},
{kWipeCommand, "s", 1, 0xFFFFFFFF},
{kWipeAllCommand, "s", 0, 0}
};
CCommandLine::Rule kCatchAllRule = {kMountCommand, "", 1, 0xFFFFFFFF};
_UNNAMED_END
// Class CPGPdiskCmdLine member functions
void
CPGPdiskCmdLine::Invoke(const char *cmdLine)
{
using namespace UCommonStrings;
pgpAssertStrValid(cmdLine);
CPGPdiskContext context;
context.Create();
CPGPdiskDiskSet diskSet(context);
CPGPdiskDiskIter diskIter(diskSet);
// Gather the command line.
CCommandLine ccmdLine(cmdLine, kPGPdiskRules, sizeof(kPGPdiskRules) /
sizeof(CCommandLine::Rule));
ccmdLine.AllowCatchAll(TRUE, kCatchAllRule);
// Process command line.
CArray<char> options;
CArray<const char *> args;
const char *command;
PGPUInt32 numArgs, numOptions;
if (!ccmdLine.Parse(command, options, numOptions, args, numArgs))
{
command = kCreateCommand;
numArgs = numOptions = 0;
}
CString curCommand(command);
PGPUInt32 i;
if (curCommand.CompareNoCase(kMountCommand) ||
curCommand.CompareNoCase(kOpenCommand))
{
// Mount the PGPdisks.
for (i = 0; i < numArgs; i++)
{
try
{
CPGPdiskUI::AskMountDisk(context, args[i]);
}
catch (CComboError& error)
{
ReportError(kTellDiskMountFailed, kGenericMsgBoxTitle, error);
}
}
}
else if (curCommand.CompareNoCase(kUnmountCommand))
{
// Unmount the PGPdisks.
PGPUInt32 flags = kPGPdiskNoUnmountFlags;
for (PGPUInt32 i = 0; i < numOptions; i++)
{
switch (options[i])
{
case 'f':
flags |= kPGPdiskForceUnmountFlag;
break;
case 's':
flags |= kPGPdiskSilentUnmountFlag;
break;
}
}
for (i = 0; i < numArgs; i++)
{
try
{
CPGPdiskUI::AskUnmountDisk(context, args[i], NULL, flags);
}
catch (CComboError& error)
{
if (!(flags & kPGPdiskSilentUnmountFlag))
{
ReportError(kTellDiskUnmountFailed, kGenericMsgBoxTitle,
error);
}
}
}
}
else if (curCommand.CompareNoCase(kUnmountAllCommand))
{
// Unmount all PGPdisks.
PGPUInt32 flags = kPGPdiskNoUnmountFlags;
for (PGPUInt32 i = 0; i < numOptions; i++)
{
switch (options[i])
{
case 'f':
flags |= kPGPdiskForceUnmountFlag;
break;
case 's':
flags |= kPGPdiskSilentUnmountFlag;
break;
}
}
try
{
CPGPdiskUI::AskUnmountAllDisks(context, NULL, flags);
}
catch (CComboError& error)
{
if (!(flags & kPGPdiskSilentUnmountFlag))
{
ReportError(kTellDiskUnmountAllFailed, kGenericMsgBoxTitle,
error);
}
}
}
else if (curCommand.CompareNoCase(kEditCommand))
{
if (IsPGPError (PGPlnIsExpired(NULL, kPGPlnOperationGraceExpiration)))
THROW_PGPERROR(kPGPError_UserAbort);
// Edit the PGPdisks.
for (i = 0; i < numArgs; i++)
{
try
{
CPGPdiskUI::AskEditDisk(context, args[i]);
}
catch (CComboError& error)
{
ReportError(kTellDiskEditFailed, kGenericMsgBoxTitle, error);
}
}
}
else if (curCommand.CompareNoCase(kCreateCommand))
{
if (IsPGPError (PGPlnIsExpired(NULL, kPGPlnOperationStandardExpiration)))
THROW_PGPERROR(kPGPError_UserAbort);
// Invoke the new disk wizard.
try
{
if (numArgs == 0)
CPGPdiskUI::AskCreateNewDisk(context);
else if (numArgs == 1)
CPGPdiskUI::AskCreateNewDisk(context, args[0]);
}
catch (CComboError& error)
{
ReportError(kTellDiskCreateFailed, kGenericMsgBoxTitle, error);
}
}
else if (curCommand.CompareNoCase(kWipeCommand))
{
// Wipe the PGPdisks.
PGPBoolean silently = FALSE;
for (PGPUInt32 i = 0; i < numOptions; i++)
{
switch (options[i])
{
case 's':
silently = TRUE;
break;
}
}
for (i = 0; i < numArgs; i++)
{
try
{
CPath path(args[i]);
path.Canonicalize(kPGPdiskFileExtension);
CPGPdiskDisk disk;
if (diskIter.SearchOnPath(path, disk) ||
diskIter.SearchOnRoot(path, disk))
{
diskSet.Unmount(disk, TRUE);
}
if (!silently)
{
if (!ConfirmWipeDisk(path))
continue;
}
disk.Open(context, path);
disk.WipeUsers();
}
catch (CComboError& error)
{
if (!silently)
{
ReportError(kTellDiskWipeUsersFailed,
kGenericMsgBoxTitle, error);
}
}
}
}
else if (curCommand.CompareNoCase(kWipeAllCommand))
{
// Wipe all PGPdisks.
PGPBoolean silently = FALSE;
for (PGPUInt32 i = 0; i < numOptions; i++)
{
switch (options[i])
{
case 's':
silently = TRUE;
break;
}
}
try
{
if (!silently)
{
if (!ConfirmWipeAllDisks())
return;
}
diskSet.WipeAllUsers();
}
catch (CComboError& error)
{
if (!silently)
{
ReportError(kTellDiskWipeUsersFailed, kGenericMsgBoxTitle,
error);
}
}
}
}
PGPBoolean
CPGPdiskCmdLine::ConfirmWipeAllDisks()
{
using namespace UCommonStrings;
CMessageBox messageBox;
CMessageBox::Button result = messageBox.Display(
Get(kAskIfWipeAllDisks), Get(kGenericMsgBoxTitle), NULL,
CMessageBox::kWarningTone, CMessageBox::kYesNoStyle,
CMessageBox::kNoButton);
return (result == CMessageBox::kYesButton);
}
PGPBoolean
CPGPdiskCmdLine::ConfirmWipeDisk(const char *path)
{
using namespace UCommonStrings;
CString message;
message.Format(Get(kAskIfWipeDisk), path);
CMessageBox messageBox;
CMessageBox::Button result = messageBox.Display(message,
Get(kGenericMsgBoxTitle), NULL, CMessageBox::kWarningTone,
CMessageBox::kYesNoStyle, CMessageBox::kNoButton);
return (result == CMessageBox::kYesButton);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -