📄 main.c
字号:
/*__________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: Main.c,v 1.36 2002/11/18 03:31:08 pbj Exp $
__________________________________________________________________________*/
#include "precomp.h"
#include "pgpWin32IPC.h"
#include "PThotkey.h"
#include "PTdisk.h"
#include "PGPhk.h"
#include "pgpThreads.h"
#include "pgpClientPrefs.h"
#include "wtsapi32.h"
extern BOOL bInitingServices;
HWND TrayWindow(void)
{
HWND hwnd;
WNDCLASS wc;
// Register the Server Window Class
wc.style = 0;
wc.lpfnWndProc = EnclyptorProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hinst;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = 0;
wc.lpszMenuName = 0;
wc.lpszClassName = PGPTRAY_WINDOWNAME;
RegisterClass(&wc);
hwnd = CreateWindow(
PGPTRAY_WINDOWNAME, PGPTRAY_WINDOWNAME, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, g_hinst, NULL );
ShowWindow(hwnd, SW_HIDE);
UpdateWindow(hwnd);
return hwnd;
}
#define ICQDEFAULTPATH "Software\\Mirabilis\\ICQ\\DefaultPrefs"
BOOL
ICQGetPrefString (
char *szPref,
char *szString,
int uSize)
{
HKEY hkey;
LONG lResult;
DWORD dwValueType, dwSize;
memset(szString,0x00,uSize);
lResult = RegOpenKeyEx (HKEY_CURRENT_USER,ICQDEFAULTPATH,
0, KEY_READ, &hkey);
if (lResult == ERROR_SUCCESS)
{
dwSize = uSize;
lResult = RegQueryValueEx (hkey, szPref, 0, &dwValueType, szString, &dwSize);
RegCloseKey (hkey);
return TRUE;
}
return FALSE;
}
#define ICQUINPATH "Software\\Mirabilis\\ICQ\\Owners"
DWORD ReadICQRegKey(void)
{
DWORD dwICQ;
HKEY hKey;
dwICQ=0;
if(RegOpenKeyEx(HKEY_CURRENT_USER,
ICQUINPATH,
0,
KEY_ALL_ACCESS,
&hKey) == ERROR_SUCCESS)
{
DWORD size = sizeof(dwICQ);
DWORD type = 0;
RegQueryValueEx(hKey,
"LastOwner",
0,
&type,
(LPBYTE)&dwICQ,
&size);
RegCloseKey (hKey);
}
return dwICQ;
}
#define ICQ_REG_PATH "Software\\PGP Corporation\\PGP\\PGPicq"
void SavePrefWarning(DWORD dwRetries)
{
HKEY hKey;
LONG lResult;
DWORD dw = 0;
lResult=RegCreateKeyEx( HKEY_LOCAL_MACHINE,
ICQ_REG_PATH,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dw);
if (lResult == ERROR_SUCCESS)
{
dw = dwRetries;
RegSetValueEx ( hKey,
"NoPrefWarning",
0,
REG_DWORD,
(LPBYTE)&dw,
sizeof(dw));
RegCloseKey (hKey);
}
}
void GetPrefWarning(DWORD *pdwRetries)
{
HKEY hKey;
DWORD dw;
*pdwRetries=0;
if(ERROR_SUCCESS==RegOpenKeyEx( HKEY_LOCAL_MACHINE,
ICQ_REG_PATH,
0,
KEY_ALL_ACCESS,
&hKey))
{
DWORD size = sizeof(dw);
DWORD type = 0;
if(ERROR_SUCCESS==RegQueryValueEx(hKey,
"NoPrefWarning",
0,
&type,
(LPBYTE)&dw,
&size))
{
*pdwRetries = (BOOL)dw;
}
RegCloseKey (hKey);
}
}
BOOL SnoopICQPrefs(FILE *fin)
{
BOOL bRESU,bUseMsgRichText,bAdvanceAIMStyle;
int iRESU,iUseMsgRichText,iAdvanceAIMStyle;
char szRESU[50],szUseMsgRichText[50],szAdvanceAIMStyle[50];
int lenRESU,lenUseMsgRichText,lenAdvanceAIMStyle;
int iRead;
char *buf;
int i;
char lenbuffer[40];
int leni,RESUstop;
char high,low;
int total;
BOOL bCont,bAsk;
bCont=TRUE;
bAsk=FALSE;
leni=0;
RESUstop=0;
total=0;
strcpy(szRESU,"RESU\06");
strcpy(szUseMsgRichText,"UseMsgRichText");
strcpy(szAdvanceAIMStyle,"AdvanceAIMStyle");
lenRESU=strlen(szRESU);
lenUseMsgRichText=strlen(szUseMsgRichText);
lenAdvanceAIMStyle=strlen(szAdvanceAIMStyle);
iRESU=iUseMsgRichText=iAdvanceAIMStyle=0;
bRESU=bUseMsgRichText=bAdvanceAIMStyle=FALSE;
buf=(char *)malloc(1024);
if(buf!=0)
{
while(bCont)
{
iRead=fread(buf,1,1024,fin);
if(iRead==0)
break;
for(i=0;i<iRead;i++)
{
if(RESUstop!=0)
{
if((total+i)>RESUstop)
{
bCont=FALSE;
break;
}
}
lenbuffer[leni]=buf[i];
leni=(leni+1)%40;
if(!bRESU)
{
if(buf[i]==szRESU[iRESU])
{
iRESU++;
if(iRESU==lenRESU)
{
bRESU=TRUE;
high=lenbuffer[(leni+6)%40];
low=lenbuffer[(leni+5)%40];
RESUstop=total+i+(high<<8)+low;
}
}
else
{
iRESU=0;
}
}
else
{
if(!bUseMsgRichText)
{
if(buf[i]==szUseMsgRichText[iUseMsgRichText])
{
iUseMsgRichText++;
if(iUseMsgRichText==lenUseMsgRichText)
bUseMsgRichText=TRUE;
}
else
{
iUseMsgRichText=0;
}
}
/*
if(!bAdvanceAIMStyle)
{
if(buf[i]==szAdvanceAIMStyle[iAdvanceAIMStyle])
{
iAdvanceAIMStyle++;
if(iAdvanceAIMStyle==lenAdvanceAIMStyle)
bAdvanceAIMStyle=TRUE;
}
else
{
iAdvanceAIMStyle=0;
}
}
*/
}
}
total=total+iRead;
}
free(buf);
}
if(bRESU)
{
if(bUseMsgRichText)
{
MessageBox(NULL,
"The PGP ICQ plugin does not work with ICQ multi language support.\n"
"Please disable this in ICQ preferences and reboot:\n\n"
"Miscellaneous->General Settings->Multi language support",
"PGP Alert",MB_OK|MB_SETFOREGROUND|MB_ICONINFORMATION);
bAsk=TRUE;
}
/*
if(!bAdvanceAIMStyle)
{
MessageBox(NULL,
"The PGP ICQ plugin does not support split message mode.\n"
"Please disable this by pressing the Msg Mode button in\n"
"the ICQ message composition window",
"PGP Alert",MB_OK|MB_SETFOREGROUND|MB_ICONINFORMATION);
bAsk=TRUE;
}
*/
if(bAsk)
{
if(IDNO==MessageBox(NULL,
"Show ICQ preference warnings in the future?",
"PGP Alert",MB_YESNO|MB_SETFOREGROUND|MB_ICONINFORMATION))
{
SavePrefWarning(1);
}
}
}
return TRUE;
}
BOOL CheckICQPrefs()
{
char szPath[MAX_PATH];
char szFile[MAX_PATH];
int uSize;
DWORD dwUIN;
int len;
FILE *fin;
DWORD dwNoCheck;
GetPrefWarning(&dwNoCheck);
if(dwNoCheck==1)
return TRUE;
uSize=MAX_PATH;
if(PGPclIsComponentInstalled(kPGPclICQplugin))
{
dwUIN=ReadICQRegKey();
if(dwUIN!=0)
{
if(ICQGetPrefString("2000b Database",szPath,uSize))
{
len=strlen(szPath);
if(len!=0)
{
if(szPath[len-1]!='\\')
strcat(szPath,"\\");
sprintf(szFile,"%s%d.dat",szPath,dwUIN);
fin=fopen(szFile,"rb");
if(fin!=0)
{
SnoopICQPrefs(fin);
fclose(fin);
}
}
}
}
}
return TRUE;
}
/*
BOOL CheckKeyrings(PGPContextRef context)
{
PGPError err,clerr;
HCURSOR hcursorOld;
PGPKeyDBRef keydb;
keydb=NULL;
while (!PGPKeyDBRefIsValid (keydb))
{
hcursorOld = SetCursor (LoadCursor (NULL, IDC_WAIT));
err = PGPclOpenDefaultKeyrings (context,
kPGPOpenKeyDBFileOptions_Mutable,
&keydb);
SetCursor (hcursorOld);
if(IsntPGPError(err))
{
PGPFreeKeyDB(keydb);
break;
}
else
{
char szText[256];
switch(err)
{
case kPGPError_CantOpenFile:
{
LoadString (g_hinst, IDS_FILECANTOPEN, szText, sizeof (szText));
break;
}
case kPGPError_FilePermissions:
{
LoadString (g_hinst, IDS_FILEPERMISSIONS, szText, sizeof (szText));
break;
}
case kPGPError_FileLocked:
{
LoadString (g_hinst, IDS_FILELOCKED, szText, sizeof (szText));
break;
}
default:
{
LoadString (g_hinst, IDS_FILEERROR, szText, sizeof (szText));
break;
}
}
MessageBox(NULL,
szText,
"PGPtray",
MB_OK|MB_SETFOREGROUND|MB_ICONSTOP);
clerr=PGPclPreferences (context,
NULL,
kPGPclKeyringPrefs,
keydb);
if(IsPGPError(clerr))
return FALSE;
}
}
return TRUE;
}
*/
int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hinstPrev,
LPSTR lpszCmdLine, int nCmdShow)
{
// HWND hwnd;
MSG msg;
BOOL bHookSet;
BOOL bWTS;
int tries;
HINSTANCE hWTS;
FARPROC pWTSRegisterSessionNotification;
FARPROC pWTSUnRegisterSessionNotification;
g_hinst = hInstance;
g_hwnd = NULL;
g_hIconTrayDefault = NULL;
bHookSet=FALSE;
LoadString (g_hinst, IDS_SZAPP, szApp, sizeof(szApp));
/*
if(*lpszCmdLine)
{
FILELIST *ListHead;
if(!PGPscInit(NULL,&PGPsc,&PGPtls,0))
return TRUE;
hwnd=TrayWindow();
ListHead=PGPscCmdLineToFileList(lpszCmdLine);
PGPscDecryptFileList(hwnd, szApp, PGPsc,PGPtls, ListHead);
PGPscDestroy(hwnd,PGPsc,PGPtls);
return 0;
}
*/
if(PGPscWindowExists(PGPTRAY_WINDOWNAME,FALSE))
{
if(PGPscInit(NULL,&PGPsc,&PGPtls,0))
{
PGPPrefRef prefref;
if(IsntPGPError(PGPclPeekClientLibPrefRefs(&prefref,NULL)))
{
PGPSetPrefBoolean (prefref,kPGPPrefShowTrayIcon, TRUE);
PGPclFlushClientLibPrefs (prefref, NULL);
}
PGPscDestroy(NULL,PGPsc,PGPtls);
}
return(0);
}
bInitingServices=TRUE; // Initializing
g_hwnd=TrayWindow();
if(!PGPscInit(NULL,&PGPsc,&PGPtls,kPGPclEnableNewUserWizard))
{
TaskbarDeleteIcon(g_hwnd, TASKBAR_TRAY_ID);
return TRUE;
}
// Service is finally running... do things we delayed to get icon up
WMCreatePostServiceInit(g_hwnd);
bInitingServices=FALSE;
g_uReloadPrefsMsg = RegisterWindowMessage (kPGPclReloadPrefsMsg);
g_uReloadNetPrefsMsg = RegisterWindowMessage (kPGPclReloadNetPrefsMsg);
g_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
PGPscGetWipeOnDeletePrefs(PGPsc, &g_bWipeOnDelete, &g_bWipeProgress,
&g_dwPasses);
if (!PGPclRunningUnderTerminalServer ())
InitializeWipeOnDelete();
// g_hwnd=TrayWindow();
/// CheckKeyrings(PGPsc);
if(PGPscHookCBTWin(PGPsc))
{
PGPhkSetHook(); // Our CBT hook for current focus
bHookSet=TRUE;
}
CheckICQPrefs();
hWTS = LoadLibrary ("wtsapi32.dll");
if (hWTS)
{
pWTSRegisterSessionNotification =
GetProcAddress (hWTS, "WTSRegisterSessionNotification");
pWTSUnRegisterSessionNotification =
GetProcAddress (hWTS, "WTSUnRegisterSessionNotification");
if(pWTSRegisterSessionNotification)
{
tries=0;
do
{
bWTS=(*pWTSRegisterSessionNotification)(g_hwnd,NOTIFY_FOR_THIS_SESSION);
if(!bWTS)
{
Sleep(500);
tries++;
}
} while((!bWTS)&&(tries<30));
}
}
while( GetMessage( &msg, NULL, 0, 0 ) )
{
if( IsDialogMessage( g_hwnd, &msg ) )
// Process Tab messages and such
continue;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
if(hWTS)
{
if(bWTS)
{
if(pWTSUnRegisterSessionNotification)
(*pWTSUnRegisterSessionNotification)(g_hwnd);
}
FreeLibrary(hWTS);
}
if (!PGPclRunningUnderTerminalServer ())
UninitializeWipeOnDelete();
if(bHookSet)
{
PGPhkDeleteHook(); // Our CBT hook for current focus
}
TaskbarDeleteIcon(g_hwnd, TASKBAR_TRAY_ID);
PGPPurgePassphraseCache (PGPsc);
PGPPurgeKeyDBCache (PGPsc);
PGPscDestroy(NULL,PGPsc,PGPtls);
PTDiskShutdown ();
return 0;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -