clmisc.c
来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C语言 代码 · 共 2,781 行 · 第 1/5 页
C
2,781 行
GetWindowRect (hwnd, &rcWnd);
switch (uMonitor) {
case kPGPclWindowMonitor :
hmonitor = MonitorFromWindow (hwnd, MONITOR_DEFAULTTONEAREST);
break;
default :
pt.x = 0;
pt.y = 0;
hmonitor = MonitorFromPoint (pt, MONITOR_DEFAULTTOPRIMARY);
break;
}
mi.cbSize = sizeof(mi);
GetMonitorInfo (hmonitor, &mi);
rcMon = mi.rcWork;
rcWnd.left = rcMon.left +
((rcMon.right - rcMon.left) - (rcWnd.right - rcWnd.left)) / 2;
rcWnd.top = rcMon.top +
((rcMon.bottom - rcMon.top) - (rcWnd.bottom - rcWnd.top)) / 2;
SetWindowPos (hwnd, NULL, rcWnd.left, rcWnd.top, 0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
return kPGPError_NoErr;
}
// ____________________________________
//
// Make sure that window is visible on multimonitor system
PGPError PGPclExport
PGPclEnsureWindowIsOnMonitor (
HWND hwndToMove,
HWND hwndParent)
{
BOOL bMoveWindow = FALSE;
RECT rcWin;
RECT rcMon;
HDC hdc;
INT iX, iY;
GetWindowRect (hwndToMove, &rcWin);
iX = rcWin.right - rcWin.left;
iY = rcWin.bottom - rcWin.top;
if (IsntNull (hwndParent))
{
RECT rc;
PGPclGetMonitorRect (hwndParent, kPGPclWindowMonitor, &rcMon);
if (!IntersectRect (&rc, &rcWin, &rcMon))
bMoveWindow = TRUE;
}
else
{
hdc = GetDC (NULL);
if (!RectVisible (hdc, &rcWin))
{
PGPclGetMonitorRect (hwndToMove, kPGPclWindowMonitor, &rcMon);
bMoveWindow = TRUE;
}
ReleaseDC (NULL, hdc);
}
if (bMoveWindow)
{
rcWin.left = max (rcMon.left, min (rcMon.right-iX, rcWin.left));
rcWin.top = max (rcMon.top, min (rcMon.bottom-iY, rcWin.top));
SetWindowPos (hwndToMove, NULL, rcWin.left, rcWin.top, 0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}
return kPGPError_NoErr;
}
// ____________________________________
//
// get service pack info from registry
static DWORD
sGetServicePackNumber (void)
{
HKEY hkey;
LRESULT lResult;
DWORD dwValueType, dwSize, dwServicePack;
dwServicePack = 0;
lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
"System\\CurrentControlSet\\Control\\Windows",
0, KEY_READ, &hkey);
if (lResult == ERROR_SUCCESS)
{
// see if component is installed
dwSize = sizeof(dwServicePack);
RegQueryValueEx (hkey, "CSDVersion",
0, &dwValueType, (LPBYTE)&dwServicePack, &dwSize);
RegCloseKey (hkey);
}
return dwServicePack;
}
// ____________________________________
//
// Determine the Windows version
PGPError PGPclExport
PGPclGetWindowsVersion (
PGPclWindowsFamily* pFamily,
PGPclWindowsGenus* pGenus,
PGPclWindowsSpecies* pSpecies)
{
OSVERSIONINFO osi;
PGPclWindowsFamily family = kPGPclWindowsFamilyUnknown;
PGPclWindowsGenus genus = kPGPclWindowsGenusUnknown;
PGPclWindowsSpecies species = kPGPclWindowsSpeciesUnknown;
osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osi))
{
switch (osi.dwPlatformId) {
case VER_PLATFORM_WIN32_WINDOWS:
family = kPGPclWindowsFamily9x;
if (osi.dwMinorVersion == 0)
{
genus = kPGPclWindowsGenus95;
if (LOWORD(osi.dwBuildNumber) > 1080)
species = kPGPclWindowsSpecies95OSR2;
else
species = kPGPclWindowsSpecies95OSR1;
}
else if (osi.dwMinorVersion == 10)
{
genus = kPGPclWindowsGenus98;
if (LOWORD(osi.dwBuildNumber) < 2222)
species = kPGPclWindowsSpecies98;
else
species = kPGPclWindowsSpecies98SE;
}
else if (osi.dwMinorVersion == 90)
{
genus = kPGPclWindowsGenusMillenium;
species = kPGPclWindowsSpeciesMillenium;
}
else
{
genus = kPGPclWindowsGenusPostMillenium;
species = kPGPclWindowsSpeciesPostMillenium;
}
break;
case VER_PLATFORM_WIN32_NT:
family = kPGPclWindowsFamilyNT;
if (osi.dwMajorVersion == 3)
{
genus = kPGPclWindowsGenusNT3;
species = kPGPclWindowsSpeciesNT3;
}
else if (osi.dwMajorVersion == 4)
{
DWORD dwSP = sGetServicePackNumber ();
genus = kPGPclWindowsGenusNT4;
switch (LOWORD (dwSP)) {
case 0x0000:
species = kPGPclWindowsSpeciesNT4NoSp;
break;
case 0x0100:
species = kPGPclWindowsSpeciesNT4Sp1;
break;
case 0x0200:
species = kPGPclWindowsSpeciesNT4Sp2;
break;
case 0x0300:
species = kPGPclWindowsSpeciesNT4Sp3;
break;
case 0x0400:
species = kPGPclWindowsSpeciesNT4Sp4;
break;
case 0x0500:
species = kPGPclWindowsSpeciesNT4Sp5;
break;
case 0x0600:
species = kPGPclWindowsSpeciesNT4Sp6;
break;
default :
species = kPGPclWindowsSpeciesNT4PostSp6;
break;
}
}
else if (osi.dwMajorVersion == 5)
{
if (osi.dwMinorVersion == 0)
{
genus = kPGPclWindowsGenus2000;
if (LOWORD(osi.dwBuildNumber) < 2195)
species = kPGPclWindowsSpecies2000Beta;
else
{
DWORD dwSP = sGetServicePackNumber ();
switch (LOWORD (dwSP)) {
case 0x0000:
species = kPGPclWindowsSpecies2000;
break;
case 0x0100:
species = kPGPclWindowsSpecies2000Sp1;
break;
case 0x0200:
species = kPGPclWindowsSpecies2000Sp2;
break;
case 0x0300:
species = kPGPclWindowsSpecies2000Sp3;
break;
default:
species = kPGPclWindowsSpecies2000;
break;
}
}
}
else if (osi.dwMinorVersion == 1)
{
genus = kPGPclWindowsGenusXp;
if (LOWORD(osi.dwBuildNumber) < 2600)
species = kPGPclWindowsSpeciesXpBeta;
else
{
DWORD dwSP = sGetServicePackNumber ();
switch (LOWORD (dwSP)) {
case 0x0000:
species = kPGPclWindowsSpeciesXp;
break;
case 0x0100:
species = kPGPclWindowsSpeciesXpSp1;
break;
default:
species = kPGPclWindowsSpeciesXp;
break;
}
}
/*
// we're currently not distinguishing "home" vs. "pro"
// but here is how we could do it :
if (osi.wSuiteMask & VER_SUITE_PERSONAL)
species = kPGPclWindowsSpeciesXpHome;
else
species = kPGPclWindowsSpeciesXpPro;
*/
}
}
else if (osi.dwMajorVersion > 5)
{
genus = kPGPclWindowsGenusPostKnown;
species = kPGPclWindowsSpeciesPostKnown;
}
break;
}
}
if (pFamily)
*pFamily = family;
if (pGenus)
*pGenus = genus;
if (pSpecies)
*pSpecies = species;
return kPGPError_NoErr;
}
// ___________________________________________________
//
// Determine if we're running as a terminal services client
// the prototype for the ProcessToSessionId call
typedef DWORD (WINAPI *ProcToSessIdProc) (
DWORD dwProcessId,
LPDWORD pdwSessionId);
PGPError PGPclExport
PGPclGetTerminalServicesSessionId (
PGPUInt32* puSessionId)
{
static ProcToSessIdProc s_fpProcToSessId = NULL;
PGPclWindowsSpecies species = kPGPclWindowsSpeciesUnknown;
DWORD dwSessionId = 0;
HINSTANCE hLib = NULL;
*puSessionId = 0;
PGPclGetWindowsVersion (NULL, NULL, &species);
if (species < kPGPclWindowsSpeciesNT4Sp4)
return kPGPError_NoErr;
if (IsNull (s_fpProcToSessId))
{
if (IsntNull (hLib = LoadLibrary ("KERNEL32.DLL")))
{
s_fpProcToSessId = (ProcToSessIdProc)GetProcAddress (
hLib, "ProcessIdToSessionId");
}
}
if (IsntNull (s_fpProcToSessId))
{
if ((*s_fpProcToSessId)(GetCurrentProcessId (), puSessionId))
return kPGPError_NoErr;
}
return kPGPError_Win32DllOpFailed;
}
PGPBoolean PGPclExport
PGPclRunningUnderTerminalServer (void)
{
PGPUInt32 uSessionId;
if (IsntPGPError (PGPclGetTerminalServicesSessionId (&uSessionId)))
{
if (uSessionId != 0)
return TRUE;
}
return FALSE;
}
// ___________________________________________________
//
// Determine the appropriate icon for a userid, based on
// its properties
PGPInt32 PGPclExport
PGPclDetermineUserIDIcon (
PGPKeyDBObjRef userid,
PGPBoolean* pbItalics)
{
PGPBoolean bAttrib = FALSE;
PGPInt32 iType = 0;
PGPInt32 iAlg;
PGPKeyDBObjRef key;
if (pbItalics)
*pbItalics = FALSE;
if (userid)
{
PGPGetKeyDBObjBooleanProperty (userid,
kPGPUserIDProperty_IsAttribute, &bAttrib);
if (bAttrib)
{
PGPGetKeyDBObjNumericProperty (userid,
kPGPUserIDProperty_AttributeType, &iType);
switch (iType) {
case kPGPAttribute_Image :
return IDX_PHOTOUSERID;
default :
if (pbItalics)
*pbItalics = TRUE;
return IDX_INVALIDUSERID;
}
}
}
key = PGPPeekKeyDBObjKey (userid);
PGPGetKeyDBObjNumericProperty (key, kPGPKeyProperty_AlgorithmID, &iAlg);
if (iAlg == kPGPPublicKeyAlgorithm_RSA)
return (IDX_RSAUSERID);
else
return (IDX_DSAUSERID);
}
// ___________________________________________________
//
// Determine the appropriate icon for a cert, based on
// its properties
PGPInt32 PGPclExport
PGPclDetermineCertIcon (
PGPKeyDBObjRef cert,
PGPBoolean* pbItalics,
PGPBoolean* pbX509)
{
PGPBoolean bRevoked, bVerified, bTried, bExpired;
PGPBoolean bNotCorrupt, bExportable, bX509;
PGPUInt32 uTrustLevel;
INT idx;
PGPGetKeyDBObjBooleanProperty (cert,
kPGPSigProperty_IsRevoked, &bRevoked);
PGPGetKeyDBObjBooleanProperty (cert,
kPGPSigProperty_IsExpired, &bExpired);
PGPGetKeyDBObjBooleanProperty (cert,
kPGPSigProperty_IsVerified, &bVerified);
PGPGetKeyDBObjBooleanProperty (cert,
kPGPSigProperty_IsTried, &bTried);
PGPGetKeyDBObjBooleanProperty (cert,
kPGPSigProperty_IsNotCorrupt, &bNotCorrupt);
PGPGetKeyDBObjBooleanProperty (cert,
kPGPSigProperty_IsExportable, &bExportable);
PGPGetKeyDBObjBooleanProperty (cert,
kPGPSigProperty_IsX509, &bX509);
PGPGetKeyDBObjNumericProperty (cert,
kPGPSigProperty_TrustLevel, &uTrustLevel);
if (pbX509)
*pbX509 = bX509;
if (bTried && !bVerified)
{
if (bX509)
idx = IDX_X509BADCERT;
else
idx = IDX_BADCERT;
}
else if (bX509)
{
if (bRevoked) idx = IDX_X509REVCERT;
else if (bExpired) idx = IDX_X509EXPCERT;
else idx = IDX_X509CERT;
}
else if (bRevoked) idx = IDX_REVCERT;
else if (bExpired) idx = IDX_EXPCERT;
else if (bVerified)
{
if (bExportable)
{
if (uTrustLevel >= 1) idx = IDX_TRUSTEDCERT;
else idx = IDX_EXPORTCERT;
}
else
{
if (uTrustLevel >= 2) idx = IDX_METACERT;
else idx = IDX_CERT;
}
}
else if (bNotCorrupt)
{
if (bExportable) idx = IDX_EXPORTCERT;
else idx = IDX_CERT;
}
else idx = IDX_BADCERT;
if ((idx == IDX_BADCERT) ||
(idx == IDX_X509BADCERT) ||
(idx == IDX_REVCERT) ||
(idx == IDX_EXPCERT))
{
if (pbItalics)
*pbItalics = TRUE;
}
return idx;
}
// ___________________________________________________
//
// Determine the appropriate icon for a key, based on
// its properties
PGPInt32 PGPclExport
PGPclDetermineKeyIcon (
PGPKeyDBObjRef key,
PGPBoolean* pbItalics)
{
PGPBoolean bRevoked, bSecret, bDisabled, bExpired, bSplit;
PGPBoolean bCanSign, bCanEncrypt, bCantDoAnything, bOnToken;
PGPUInt32 uIdx, uAlg, uVer;
PGPGetKeyDBObjBooleanProperty (key,
kPGPKeyProperty_IsRevoked, &bRevoked);
PGPGetKeyDBObjBooleanProperty (key,
kPGPKeyProperty_IsSecret, &bSecret);
PGPGetKeyDBObjBooleanProperty (key,
kPGPKeyProperty_IsDisabled, &bDisabled);
PGPGetKeyDBObjBooleanProperty (key,
kPGPKeyProperty_IsExpired, &bExpired);
PGPGetKeyDBObjBooleanProperty (key,
kPGPKeyProperty_IsSecretShared, &bSplit);
PGPGetKeyDBObjBooleanProperty (key,
kPGPKeyProperty_CanSign, &bCanSign);
PGPGetKeyDBObjBooleanProperty (key,
kPGPKeyProperty_CanEncrypt, &bCanEncrypt);
PGPGetKeyDBObjBooleanProperty (key,
kPGPKeyProperty_IsOnToken, &bOnToken);
PGPGetKeyDBObjNumericProperty (key,
kPGPKeyProperty_AlgorithmID, &uAlg);
PGPGetKeyDBObjNumericProperty (key,
kPGPKeyProperty_Version, &uVer);
bCantDoAnything = FALSE;
// RSA
if (uAlg == kPGPPublicKeyAlgorithm_RSA)
{
if (!bCanSign && !bCanEncrypt)
bCantDoAnything = TRUE;
if (uVer <= kPGPKeyVersion_V3)
{
if (bSecret)
{
if (bOnToken)
{
if (bRevoked) uIdx = IDX_RSATOKREVKEY;
else if (bExpired) uIdx = IDX_RSATOKEXPKEY;
else if (bDisabled) uIdx = IDX_RSATOKDISKEY;
else uIdx = IDX_RSATOKKEY;
}
else
{
if (bRevoked) uIdx = IDX_RSASECREVKEY;
else if (bExpired) uIdx = IDX_RSASECEXPKEY;
else if (bDisabled) uIdx = IDX_RSASECDISKEY;
else if (bSplit) uIdx = IDX_RS
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?