📄 pnoption.c
字号:
hwnd, IDC_ENABLEIPSECTIMEEXPIRE) == BST_CHECKED);
g_AOS.pnconfig.bIpsecKByteExpiration =
(IsDlgButtonChecked (
hwnd, IDC_ENABLEIPSECBYTEEXPIRE) == BST_CHECKED);
g_AOS.pnconfig.uIpsecKByteExpiration =
GetDlgItemInt (hwnd, IDC_IPSECBYTES, NULL, FALSE) * 1024;
SetWindowLong (hwnd, DWL_MSGRESULT, PSNRET_NOERROR);
return TRUE;
}
case PSN_KILLACTIVE :
g_AOS.pnconfig.bExpertMode =
(IsDlgButtonChecked (
hwnd, IDC_EXPERTMODE) == BST_CHECKED);
SetWindowLong (hwnd, DWL_MSGRESULT, PSNRET_NOERROR);
return TRUE;
case PSN_RESET :
pos = (POPTIONSSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
pos->bUserCancel = TRUE;
break;
}
break;
}
}
return FALSE;
}
// ____________________________________
//
// put name of key into listview
static VOID
sSetKeyLists (
HWND hwnd,
POPTIONSSTRUCT pos)
{
LV_ITEM lvi;
CHAR sz[kPGPMaxUserIDSize +1];
CHAR szID[kPGPMaxKeyIDStringSize +1];
UINT u;
PGPKeyID keyid;
PGPKeyRef keyPGP;
PGPKeyRef keyX509;
PGPSigRef sigX509;
PGPError err;
BOOL bEnableClear;
#if !PGP_FREEWARE
PGPSize size;
HICON hIcon;
#endif // !PGP_FREEWARE
ListView_DeleteAllItems (pos->hwndPGPKeyList);
SetDlgItemText (hwnd, IDC_X509KEYEDIT, "");
PGPnetGetConfiguredAuthKeys (g_context, &pos->pnconfig,
g_AOS.keysetMain, &keyPGP, &keyX509, &sigX509);
lvi.mask = LVIF_TEXT|LVIF_IMAGE;
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText = sz;
sz[0] = '\0';
// PGP Authentication key
bEnableClear = FALSE;
pos->bPGPKey = FALSE;
if (pos->pnconfig.uPGPAuthKeyAlg != kPGPPublicKeyAlgorithm_Invalid)
{
if (PGPKeyRefIsValid (keyPGP))
{
lvi.iImage = PNDetermineKeyIcon (keyPGP, NULL);
sz[0] = '\0';
PGPGetPrimaryUserIDNameBuffer (keyPGP, sizeof(sz), sz, &u);
pos->bPGPKey = TRUE;
}
else
{
lvi.iImage = IDX_NONE;
err = PGPImportKeyID (pos->pnconfig.expkeyidPGPAuthKey, &keyid);
if (IsntPGPError (err))
{
LoadString (g_hinst, IDS_UNKNOWNKEY, sz, sizeof(sz));
PGPGetKeyIDString (&keyid,
kPGPKeyIDString_Abbreviated, szID);
lstrcat (sz, szID);
}
}
ListView_InsertItem (pos->hwndPGPKeyList, &lvi);
InvalidateRect (pos->hwndPGPKeyList, NULL, FALSE);
bEnableClear = TRUE;
}
EnableWindow (GetDlgItem (hwnd, IDC_CLEARPGPKEY), bEnableClear);
// then get X509 auth key
bEnableClear = FALSE;
pos->bX509Key = FALSE;
#if !PGP_FREEWARE
if (pos->pnconfig.uX509AuthKeyAlg != kPGPPublicKeyAlgorithm_Invalid)
{
if (PGPKeyRefIsValid (keyX509) &&
PGPSigRefIsValid (sigX509))
{
sz[0] = '\0';
PGPGetSigPropertyBuffer (sigX509,
kPGPSigPropX509LongName, sizeof(sz), sz, &size);
SetDlgItemText (hwnd, IDC_X509KEYEDIT, sz);
u = PNDetermineCertIcon (sigX509, NULL);
hIcon = ImageList_GetIcon (pos->hil, u, ILD_TRANSPARENT);
SendDlgItemMessage (
hwnd, IDC_X509ICON, STM_SETICON, (WPARAM)hIcon, 0);
bEnableClear = TRUE;
pos->bX509Key = TRUE;
}
else
{
err = PGPImportKeyID (pos->pnconfig.expkeyidX509AuthKey, &keyid);
if (IsntPGPError (err))
{
LoadString (g_hinst, IDS_UNKNOWNCERT, sz, sizeof(sz));
PGPGetKeyIDString (&keyid,
kPGPKeyIDString_Abbreviated, szID);
lstrcat (sz, szID);
SetDlgItemText (hwnd, IDC_X509KEYEDIT, sz);
bEnableClear = TRUE;
}
}
}
if (!pos->bX509Key)
SendDlgItemMessage (hwnd, IDC_X509ICON, STM_SETICON, 0, 0);
EnableWindow (GetDlgItem (hwnd, IDC_CLEARX509KEY), bEnableClear);
#endif // !PGP_FREEWARE
}
// ____________________________________
//
// initialize the list view control
static VOID
sInitKeyLists (
POPTIONSSTRUCT pos)
{
HBITMAP hBmp;
HDC hDC;
INT iNumBits;
LV_COLUMN lvc;
RECT rc;
// Initialize the tree view window.
// First create imagelist and load the appropriate bitmaps based on
// current display capabilities.
hDC = GetDC (NULL); // DC for desktop
iNumBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES);
ReleaseDC (NULL, hDC);
if (iNumBits <= 8) {
pos->hil = ImageList_Create (16, 16, ILC_COLOR|ILC_MASK,
NUM_KEY_BITMAPS, 0);
hBmp = LoadBitmap (g_hinst, MAKEINTRESOURCE (IDB_KEYIMG4));
ImageList_AddMasked (pos->hil, hBmp, RGB(255, 0, 255));
DeleteObject (hBmp);
}
else {
pos->hil = ImageList_Create (16, 16, ILC_COLOR24|ILC_MASK,
NUM_KEY_BITMAPS, 0);
hBmp = LoadBitmap (g_hinst, MAKEINTRESOURCE (IDB_KEYIMG24));
ImageList_AddMasked (pos->hil, hBmp, RGB(255, 0, 255));
DeleteObject (hBmp);
}
// Associate the image list with the tree view control.
ListView_SetImageList (pos->hwndPGPKeyList, pos->hil, LVSIL_SMALL);
// add columns
GetClientRect (pos->hwndPGPKeyList, &rc);
lvc.mask = LVCF_WIDTH;
lvc.cx = rc.right - rc.left;
ListView_InsertColumn (pos->hwndPGPKeyList, 0, &lvc);
}
// ____________________________________
//
// clear the PGP authentication key
static BOOL
sClearPGPAuthKey (
HWND hwnd,
POPTIONSSTRUCT pos)
{
if (pos->pnconfig.uPGPAuthKeyAlg == kPGPPublicKeyAlgorithm_Invalid)
return FALSE;
if (PNMessageBox (hwnd, IDS_CAPTION, IDS_CLEARPGPKEYPROMPT,
MB_YESNO|MB_ICONEXCLAMATION) == IDNO)
return FALSE;
pos->pnconfig.uPGPAuthKeyAlg = kPGPPublicKeyAlgorithm_Invalid;
return TRUE;
}
// ____________________________________
//
// clear the X.509 authentication key
static BOOL
sClearX509AuthKey (
HWND hwnd,
POPTIONSSTRUCT pos)
{
if (pos->pnconfig.uX509AuthKeyAlg == kPGPPublicKeyAlgorithm_Invalid)
return FALSE;
if (PNMessageBox (hwnd, IDS_CAPTION, IDS_CLEARX509KEYPROMPT,
MB_YESNO|MB_ICONEXCLAMATION) == IDNO)
return FALSE;
pos->pnconfig.uX509AuthKeyAlg = kPGPPublicKeyAlgorithm_Invalid;
return TRUE;
}
// ____________________________________
//
// prompt user for keyrings
static BOOL
sSelectKeyring (
HWND hwnd,
BOOL bSecretRing,
POPTIONSSTRUCT pos)
{
CHAR szFile[MAX_PATH];
CHAR szFilter[128];
CHAR szTitle[128];
CHAR szDefExt[8];
LPSTR p;
OPENFILENAME ofn;
if (bSecretRing)
{
GetDlgItemText (hwnd, IDC_SECRING, szFile, sizeof(szFile));
LoadString (g_hinst, IDS_SECRINGFILTER, szFilter, sizeof(szFilter));
LoadString (g_hinst, IDS_SECRINGCAPTION, szTitle, sizeof(szTitle));
LoadString (g_hinst, IDS_DEFSECRINGEXT, szDefExt, sizeof(szDefExt));
}
else
{
GetDlgItemText (hwnd, IDC_PUBRING, szFile, sizeof(szFile));
LoadString (g_hinst, IDS_PUBRINGFILTER, szFilter, sizeof(szFilter));
LoadString (g_hinst, IDS_PUBRINGCAPTION, szTitle, sizeof(szTitle));
LoadString (g_hinst, IDS_DEFPUBRINGEXT, szDefExt, sizeof(szDefExt));
}
while (p = strrchr (szFilter, '@')) *p = '\0';
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.hInstance = g_hinst;
ofn.lpstrFilter = szFilter;
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0L;
ofn.nFilterIndex = 1L;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = szTitle;
ofn.Flags = OFN_HIDEREADONLY|OFN_FILEMUSTEXIST;
ofn.nFileOffset = 0;
ofn.nFileExtension = 0;
ofn.lpstrDefExt = szDefExt;
ofn.lCustData = 0;
if (GetOpenFileName (&ofn))
{
if (bSecretRing)
SetDlgItemText (hwnd, IDC_SECRING, szFile);
else
SetDlgItemText (hwnd, IDC_PUBRING, szFile);
return TRUE;
}
else
return FALSE;
}
// ____________________________________
//
// compare set keyrings to current user's and enable button accordingly
static VOID
sCompareToCurrent (
HWND hwnd)
{
BOOL bSameAsCurrentUser = TRUE;
PGPContextRef context;
PGPFileSpecRef fileRef;
CHAR sz[MAX_PATH];
LPSTR pszCurrent;
PGPNewContext (kPGPsdkAPIVersion, &context);
if (PGPContextRefIsValid (context))
{
PGPsdkLoadDefaultPrefs (context);
GetDlgItemText (hwnd, IDC_PUBRING, sz, sizeof(sz));
pszCurrent = NULL;
PGPsdkPrefGetFileSpec (
context, kPGPsdkPref_PublicKeyring, &fileRef);
PGPGetFullPathFromFileSpec (fileRef, &pszCurrent);
if (PGPFileSpecRefIsValid (fileRef))
{
if (pszCurrent)
{
if (strcmpi (sz, pszCurrent))
bSameAsCurrentUser = FALSE;
PGPFreeData (pszCurrent);
}
PGPFreeFileSpec (fileRef);
}
GetDlgItemText (hwnd, IDC_SECRING, sz, sizeof(sz));
pszCurrent = NULL;
PGPsdkPrefGetFileSpec (
context, kPGPsdkPref_PrivateKeyring, &fileRef);
PGPGetFullPathFromFileSpec (fileRef, &pszCurrent);
if (PGPFileSpecRefIsValid (fileRef))
{
if (pszCurrent)
{
if (strcmpi (sz, pszCurrent))
bSameAsCurrentUser = FALSE;
PGPFreeData (pszCurrent);
}
PGPFreeFileSpec (fileRef);
}
PGPFreeContext (context);
}
if (bSameAsCurrentUser)
EnableWindow (GetDlgItem (hwnd, IDC_SETTOCURRENT), FALSE);
else
EnableWindow (GetDlgItem (hwnd, IDC_SETTOCURRENT), TRUE);
}
// ____________________________________
//
// fill-in the keyring controls
static VOID
sGetKeyringPrefs (
HWND hwnd,
POPTIONSSTRUCT pos)
{
PGPFileSpecRef fileRef;
PGPError err;
LPSTR psz;
err = PGPsdkPrefGetFileSpec (
g_context, kPGPsdkPref_PublicKeyring, &fileRef);
if (IsntPGPError (err) && fileRef)
{
PGPGetFullPathFromFileSpec (fileRef, &psz);
SetDlgItemText (hwnd, IDC_PUBRING, psz);
PGPFreeFileSpec (fileRef);
PGPFreeData (psz);
}
err = PGPsdkPrefGetFileSpec (
g_context, kPGPsdkPref_PrivateKeyring, &fileRef);
if (IsntPGPError (err) && fileRef)
{
PGPGetFullPathFromFileSpec (fileRef, &psz);
SetDlgItemText (hwnd, IDC_SECRING, psz);
PGPFreeFileSpec (fileRef);
PGPFreeData (psz);
}
sCompareToCurrent (hwnd);
}
// ____________________________________
//
// get keyrings from controls and set sdk prefs
static VOID
sSetKeyringPrefs (
HWND hwnd,
BOOL bSecretRing,
POPTIONSSTRUCT pos)
{
PGPFileSpecRef fileRef;
PGPFileSpecRef fileRefOrig;
PGPError err;
CHAR szFile[MAX_PATH];
if (bSecretRing)
{
PGPsdkPrefGetFileSpec (
g_context, kPGPsdkPref_PrivateKeyring, &fileRefOrig);
GetDlgItemText (hwnd, IDC_SECRING, szFile, sizeof(szFile));
err = PGPNewFileSpecFromFullPath (g_context, szFile, &fileRef);
if (!PGPclErrorBox (hwnd, err))
{
err = PGPsdkPrefSetFileSpec (g_context,
kPGPsdkPref_PrivateKeyring, fileRef);
PGPclErrorBox (hwnd, err);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -