📄 main.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: main.c,v 1.16 2002/11/20 16:48:03 pbj Exp $
____________________________________________________________________________*/
#include <windows.h>
#include "PGPadmin.h"
#include <htmlhelp.h>
#include "PGPadminRes.h"
#include "pgpUtilities.h"
#include "pgpClientPrefs.h"
#include "pgpNetPrefs.h"
#include "pgpClientLib.h"
#include "pgpLnLib.h"
#include "pgpFileSpec.h"
#include "pgpHashPrefs.h"
HINSTANCE g_hInstance = NULL;
HWND g_hCurrentDlgWnd = NULL;
static PGPContextRef g_pgpContext = NULL;
static HBITMAP g_hBitmap = NULL;
static HPALETTE g_hPalette = NULL;
static pgpConfigInfo Config;
LRESULT CALLBACK MainDlgProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
static HPALETTE
CreateDIBPalette (LPBITMAPINFO lpbmi,
LPINT lpiNumColors);
static HBITMAP
LoadResourceBitmap (HINSTANCE hInstance,
LPSTR lpString,
HPALETTE FAR* lphPalette);
static void sNewPrefs(void);
static void sSavePrefs(HWND hwndMain);
static void sFreeData(void);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
int nResult;
PGPError err;
char szTitle[255];
char szMsg[255];
UNREFERENCED_PARAMETER(lpCmdLine);
g_hInstance = hInstance; /* save instance handle */
#if PGP_DEBUG
if (kPGPPrefBoolLast != 51)
{
wsprintf(szMsg, "Client boolean prefs have changed!\r\nNew value is %d",
kPGPPrefBoolLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPPrefNumberLast != 225)
{
wsprintf(szMsg, "Client number prefs have changed!\r\nNew value is %d",
kPGPPrefNumberLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPPrefStringLast != 413)
{
wsprintf(szMsg, "Client string prefs have changed!\r\nNew value is %d",
kPGPPrefStringLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPPrefByteLast != 621)
{
wsprintf(szMsg, "Client byte prefs have changed!\r\nNew value is %d",
kPGPPrefByteLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPPrefStructLast != 801)
{
wsprintf(szMsg, "Client struct prefs have changed!\r\nNew value is %d",
kPGPPrefStructLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPPrefArrayLast != 1002)
{
wsprintf(szMsg, "Client array prefs have changed!\r\nNew value is %d",
kPGPPrefArrayLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPAdminPrefBoolLast != 3049)
{
wsprintf(szMsg, "Admin boolean prefs have changed!\r\nNew value is %d",
kPGPAdminPrefBoolLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPAdminPrefNumberLast != 3212)
{
wsprintf(szMsg, "Admin number prefs have changed!\r\nNew value is %d",
kPGPAdminPrefNumberLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPAdminPrefStringLast != 3404)
{
wsprintf(szMsg, "Admin string prefs have changed!\r\nNew value is %d",
kPGPAdminPrefStringLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPAdminPrefByteLast != 3606)
{
wsprintf(szMsg, "Admin byte prefs have changed!\r\nNew value is %d",
kPGPAdminPrefByteLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPAdminPrefStructLast != 3801)
{
wsprintf(szMsg, "Admin struct prefs have changed!\r\nNew value is %d",
kPGPAdminPrefStructLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPAdminPrefArrayLast != 4001)
{
wsprintf(szMsg, "Admin array prefs have changed!\r\nNew value is %d",
kPGPAdminPrefArrayLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPNetPrefBoolLast != 11035)
{
wsprintf(szMsg, "Net boolean prefs have changed!\r\nNew value is %d",
kPGPNetPrefBoolLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPNetPrefNumberLast != 11210)
{
wsprintf(szMsg, "Net number prefs have changed!\r\nNew value is %d",
kPGPNetPrefNumberLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPNetPrefStringLast != 11406)
{
wsprintf(szMsg, "Net string prefs have changed!\r\nNew value is %d",
kPGPNetPrefStringLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPNetPrefByteLast != 11605)
{
wsprintf(szMsg, "Net byte prefs have changed!\r\nNew value is %d",
kPGPNetPrefByteLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPNetPrefStructLast != 12001)
{
wsprintf(szMsg, "Net struct prefs have changed!\r\nNew value is %d",
kPGPNetPrefStructLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
if (kPGPNetPrefArrayLast != 11805)
{
wsprintf(szMsg, "Net array prefs have changed!\r\nNew value is %d",
kPGPNetPrefArrayLast);
MessageBox(NULL, szMsg, "DEBUG", MB_OK);
}
#endif /* PGP_DEBUG */
// Make sure SDK isn't expired
err = PGPclInitLibrary(&g_pgpContext,
kPGPclEnableNewUserWizard | kPGPclForceNewUserWizard);
if (IsPGPError(err))
{
if (err == kPGPError_FeatureNotAvailable)
{
LoadString(g_hInstance, IDS_E_EXPIRED, szMsg, 254);
LoadString(g_hInstance, IDS_TITLE, szTitle, 254);
MessageBox(NULL, szMsg, szTitle, MB_ICONWARNING);
}
else
PGPclErrorBox(NULL, err);
PGPclCloseLibrary();
return 0;
}
// Check for beta/demo expiration
PGPlnLicenseCheck (g_pgpContext);
if (!PGPlnEnterprise())
{
PGPclNoLicense(NULL, kPGPclPGPadmin);
PGPclCloseLibrary();
return 0;
}
if (PGPlnIsExpired(NULL, kPGPlnModuleGraceExpiration) != kPGPError_NoErr)
{
PGPclCloseLibrary();
return 0;
}
if(!PGPclIsAdminInstall())
{
LoadString(g_hInstance, IDS_NOTADMIN, szMsg, 254);
LoadString(g_hInstance, IDS_TITLE, szTitle, 254);
MessageBox(NULL, szMsg, szTitle, MB_ICONWARNING);
PGPclCloseLibrary();
return 0;
}
/* Show the main dialog */
nResult = DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL,
MainDlgProc);
if (g_hBitmap != NULL)
DeleteObject(g_hBitmap);
sFreeData();
PGPclCloseLibrary();
return nResult;
}
LRESULT CALLBACK MainDlgProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
HICON hPGPOptions;
HICON hAdminOptions;
int iNumBits;
int iBitmap;
HDC hDC;
BOOL bReturn = FALSE;
PGPUInt32 panelFlags;
PGPError err;
switch (uMsg)
{
case WM_INITDIALOG:
hPGPOptions = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_PGPKEYS),
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
hAdminOptions = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ADMIN),
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
SendMessage(GetDlgItem(hwndDlg, IDC_PGPOPTIONS), BM_SETIMAGE,
IMAGE_ICON, (LPARAM) hPGPOptions);
SendMessage(GetDlgItem(hwndDlg, IDC_ADMINOPTIONS), BM_SETIMAGE,
IMAGE_ICON, (LPARAM) hAdminOptions);
PostMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) hAdminOptions);
PostMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) hAdminOptions);
/* Determine which bitmap will be displayed */
hDC = GetDC (NULL); // DC for desktop
iNumBits = GetDeviceCaps (hDC, BITSPIXEL) *
GetDeviceCaps (hDC, PLANES);
ReleaseDC (NULL, hDC);
if (iNumBits <= 1)
iBitmap = IDB_ADMINWIZ1;
else if (iNumBits <= 4)
iBitmap = IDB_ADMINWIZ4;
else
iBitmap = IDB_ADMINWIZ8;
g_hBitmap = LoadResourceBitmap(g_hInstance, MAKEINTRESOURCE(iBitmap),
&g_hPalette);
SendDlgItemMessage(hwndDlg, IDC_MAINPIC, STM_SETIMAGE,
IMAGE_BITMAP, (LPARAM) g_hBitmap);
PGPclCenterWindowOnMonitor(hwndDlg, kPGPclPrimaryMonitor);
if (1)
{
PGPPrefRef prefRef = NULL;
PGPPrefRef prefRefNet = NULL;
sNewPrefs();
PGPclPeekClientLibPrefRefs(&prefRef, &prefRefNet);
PGPAddPrefs(prefRef, Config.prefRef);
if (prefRefNet != NULL)
PGPAddPrefs(prefRefNet, Config.prefRefNet);
LoadAdminOptions(&Config);
}
EnableWindow(GetDlgItem(hwndDlg, IDC_UPDATESERVER), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CREATEINSTALL), FALSE);
bReturn = TRUE;
break;
case WM_PAINT:
if (g_hPalette)
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint (hwndDlg, &ps);
SelectPalette (hDC, g_hPalette, FALSE);
RealizePalette (hDC);
EndPaint (hwndDlg, &ps);
bReturn = TRUE;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_PGPOPTIONS:
panelFlags = 0;
if (PGPclIsComponentInstalled (kPGPclPGPkeys))
panelFlags |= ADMINKEYSPREFSPAGES;
if (PGPclIsComponentInstalled (kPGPclPGPtools))
panelFlags |= ADMINMAILPREFSPAGES;
if (PGPclIsComponentInstalled(kPGPclPGPdisk))
panelFlags |= ADMINDISKPREFSPAGES;
if (PGPclIsComponentInstalled (kPGPclPFIDS))
panelFlags |= ADMINFIREPREFSPAGES;
if (PGPclIsComponentInstalled(kPGPclVPN))
panelFlags |= ADMINVPNPREFSPAGES;
err = PGPclAdminPreferences(g_pgpContext, hwndDlg, Config.prefRef,
Config.prefRefNet, kPGPclRespectDisableFlags,
panelFlags, 0, Config.keyDB);
if (IsntPGPError(err))
Config.bCopyClientPrefs = TRUE;
else if (err != kPGPError_UserAbort)
PGPclErrorBox(hwndDlg, err);
bReturn = TRUE;
break;
case IDC_ADMINOPTIONS:
{
void *pCurrentPrefs;
void *pCurrentNetPrefs;
PGPSize currentSize;
PGPSize currentNetSize;
PGPExportPrefsToBuffer(Config.prefRef, ¤tSize,
&pCurrentPrefs);
PGPExportPrefsToBuffer(Config.prefRefNet, ¤tNetSize,
&pCurrentNetPrefs);
AdminOptions(hwndDlg, &Config);
if (Config.bCancel)
{
PGPPrefRef prefRef;
PGPPrefRef prefRefNet;
sFreeData();
sNewPrefs();
PGPImportBufferToMemoryPrefs(Config.memoryMgr,
pCurrentPrefs, currentSize, clientDefaults,
clientDefaultsSize, &prefRef);
PGPImportBufferToMemoryPrefs(Config.memoryMgr,
pCurrentNetPrefs, currentNetSize, netDefaults,
netDefaultsSize, &prefRefNet);
PGPAddPrefs(prefRef, Config.prefRef);
PGPAddPrefs(prefRefNet, Config.prefRefNet);
PGPFreePrefs(prefRef);
PGPFreePrefs(prefRefNet);
LoadAdminOptions(&Config);
}
else
{
EnableWindow(GetDlgItem(hwndDlg, IDC_UPDATESERVER), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CREATEINSTALL), TRUE);
}
PGPFreeData(pCurrentPrefs);
PGPFreeData(pCurrentNetPrefs);
bReturn = TRUE;
break;
}
case IDC_RETRIEVESERVER:
{
char szTitle[255];
char szMsg[255];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -