📄 appmain.cpp
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: AppMain.cpp,v 1.13 2002/11/20 16:49:24 pbj Exp $
____________________________________________________________________________*/
#include "pgpClassesConfig.h"
#include "CPath.h"
#include "CPFLImpFactoryWin32.h"
#include "CRegistryKey.h"
#include "UModuleInstance.h"
#include "UCommonStrings.h"
#include "CPGPdiskEngine.h"
#include "CPGPdiskUI.h"
#include "CPGPdiskCmdLine.h"
#include "pgpClientLib.h"
#include "CMessageBox.h"
#include "pgplnlib.h"
_USING_PGP
_UNNAMED_BEGIN
// Constants
const HKEY kRegistryAppPathRoot = HKEY_LOCAL_MACHINE;
const HKEY kRegistryShellNewRoot = HKEY_CLASSES_ROOT;
const HKEY kRegistryIconRoot = HKEY_CLASSES_ROOT;
const HKEY kRegistryShellOpenRoot = HKEY_CLASSES_ROOT;
const char *kRegistryAppPathSection =
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\PGPdisk.exe";
const char *kRegistryShellNewSection =
".pgd\\ShellNew";
const char *kRegistryIconSection =
"PGPdisk Volume\\DefaultIcon";
const char *kRegistryShellOpenSection =
"PGPdisk Volume\\shell\\open\\command";
const char *kRegistryAppPathKeyName = "";
const char *kRegistryShellNewKeyName = "Command";
const char *kRegistryIconKeyName = NULL;
const char *kRegistryShellOpenKeyName = NULL;
const char *kRegistryAppPathKeyValue = "%s";
const char *kRegistryShellNewKeyValue = "%s create \"%%2\"";
const char *kRegistryIconKeyValue = "%s,-129";
const char *kRegistryShellOpenKeyValue = "%s open \"%%1\"";
// Statics
PGPBoolean EngineInitialized = FALSE;
PGPBoolean UIInitialized = FALSE;
// Main application loop
void
ProcessCommandLine(const char *cmdLine)
{
try
{
CPGPdiskCmdLine::Invoke(cmdLine);
}
catch (CComboError& error)
{
using namespace UCommonStrings;
ReportError(kAppExecuteCommandFailed, kGenericMsgBoxTitle, error);
}
}
void
UpdateSzKey(
HKEY root,
const char *section,
const char *keyName,
const char *keyValue)
{
CRegistryKey regKey;
regKey.Create(root, section);
regKey.SetValue(keyName, reinterpret_cast<const PGPByte *>(keyValue),
strlen(keyValue) + 1, REG_SZ);
regKey.Close();
}
void
UpdateRegistryPaths()
{
try
{
CPath appPath;
// Get the pathname of the application.
PGPUInt32 result = GetModuleFileName(NULL, appPath.GetBuffer(
kPGPdiskMaxPathLength), kPGPdiskMaxPathLength);
appPath.ReleaseBuffer();
if (result == 0)
THROW_PGPERROR(kPGPError_UserAbort);
// Must change the path to "short" form.
appPath.ConvertPathToShort();
// Update the application path key.
CString keyValue;
keyValue.Format(kRegistryAppPathKeyValue, appPath.Get());
UpdateSzKey(kRegistryAppPathRoot, kRegistryAppPathSection,
kRegistryAppPathKeyName, keyValue);
// Update the "ShellNew" key.
keyValue.Format(kRegistryShellNewKeyValue, appPath.Get());
UpdateSzKey(kRegistryShellNewRoot, kRegistryShellNewSection,
kRegistryShellNewKeyName, keyValue);
// Update the "DefaultIcon" key.
keyValue.Format(kRegistryIconKeyValue, appPath.Get());
UpdateSzKey(kRegistryIconRoot, kRegistryIconSection,
kRegistryIconKeyName, keyValue);
// Update the "ShellOpen" key.
keyValue.Format(kRegistryShellOpenKeyValue, appPath.Get());
UpdateSzKey(kRegistryShellOpenRoot, kRegistryShellOpenSection,
kRegistryShellOpenKeyName, keyValue);
}
catch (CComboError&) { }
}
_UNNAMED_END
void
InitInstance()
{
CPGPdiskEngine::InitLibrary();
EngineInitialized = TRUE;
CPGPdiskUI::InitLibrary();
UIInitialized = TRUE;
CPFLImpFactoryWin32::CreateInstance();
}
void
ExitInstance()
{
CPFLImpFactoryWin32::DestroyInstance();
if (UIInitialized)
{
CPGPdiskUI::CleanupLibrary();
UIInitialized = TRUE;
}
if (EngineInitialized)
{
CPGPdiskEngine::CleanupLibrary();
EngineInitialized = FALSE;
}
}
int
APIENTRY
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR lpCmdLine,
int nCmdShow)
{
try
{
InitInstance();
if (!PGPlnPGPdiskEnabled())
{
// using namespace UCommonStrings;
// CMessageBox messageBox;
// messageBox.Display(Get(kTellNoDiskLicense),
// Get(kGenericMsgBoxTitle), NULL);
PGPclNoLicense(NULL,kPGPclPGPdisk);
THROW_PGPERROR(kPGPError_UserAbort);
}
UpdateRegistryPaths();
ProcessCommandLine(lpCmdLine);
ExitInstance();
return TRUE;
}
catch (CComboError& error)
{
using namespace UCommonStrings;
ReportError(kAppInitFailed, kGenericMsgBoxTitle, error);
ExitInstance();
return FALSE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -