⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		RetVal=FileListFromDirectory(filelist,filename,UserCancel);
	}
	else
	{
		RetVal=FileListFromFile(filelist,filename,UserCancel);
	}

	return RetVal;
}

BOOL FreeFileList(FILELIST *FileList)
{
	FILELIST *FreeAtLast;

	while(FileList!=0)
	{
		FreeAtLast=FileList;
		FileList=FileList->next;
		memset(FreeAtLast->name,0x00,strlen(FreeAtLast->name));
		free(FreeAtLast->name);
		memset(FreeAtLast,0x00,sizeof(FILELIST));
		free(FreeAtLast);
	}

	return TRUE;
}

FILELIST *HDropToFileList(HDROP hDrop)
{
	char szFile[5000+1];
	int NumFiles,i,ReturnCode;
	FILELIST *ListHead;

	NumFiles=DragQueryFile(hDrop,0xFFFFFFFF,NULL,0);
	ListHead=0;
	ReturnCode=TRUE;

	if(NumFiles==0)
		return 0;

	for(i=0;i<NumFiles && ReturnCode == TRUE;i++)
	{
		DragQueryFile(hDrop,i,szFile,5000);
		AddToFileList(&ListHead,szFile,NULL);
	}

	return ListHead;
}

FILELIST *CmdLineToFileList(char *szCmdLine)
{
	char *szNext,*szNow;
	FILELIST *ListHead;
	HANDLE hFindFile;
	WIN32_FIND_DATAA FindFileDataA;
	char szLongName[MAX_PATH+1];
	char *name;
	char *path;

	szNext=szCmdLine;
	ListHead=0;

	while(szNext!=NULL)
	{
		szNow=szNext;
			
		szNext=strstr(szNext," ");
		
		if(szNext!=NULL)
		{
			szNext=strstr(szNext,":\\");

			if(szNext!=NULL)
			{
				szNext=szNext-2;
				if(szNext>szCmdLine)
				{
					*szNext=0;
					szNext++;
				}
				else
				{
					szNext=NULL;
				}
			}
		}
		
		strcpy(szLongName,szNow);

		hFindFile=FindFirstFileA(szNow,&FindFileDataA);

		if(hFindFile!=NULL)
		{
			name=strrchr(szNow,'\\');

			if(name!=NULL)
			{
				path=szNow;
				*name=0;
				name++;

				strcpy(szLongName,path);
				strcat(szLongName,"\\");
				strcat(szLongName,FindFileDataA.cFileName);
			}
			else
			{	
				strcpy(szLongName,FindFileDataA.cFileName);
			}

			CloseHandle(hFindFile);
		}

		AddToFileList(&ListHead,szLongName,NULL);
	}

	return ListHead;
}

UINT PGPscQueryCacheSecsRemaining (void)
{
	UINT SignCacheSecs;
	UINT DecCacheSecs;

	SignCacheSecs=PGPclQuerySigningCacheSecsRemaining();
	DecCacheSecs=PGPclQueryDecryptionCacheSecsRemaining ();

	if(SignCacheSecs>DecCacheSecs)
		return SignCacheSecs;

	return DecCacheSecs;
}

BOOL PGPscPreferences(HWND hwnd,void *PGPsc,void *PGPtls)
{
	PGPContextRef context;
	PGPtlsContextRef tls;

	context=(PGPContextRef)PGPsc;
	tls=(PGPtlsContextRef)PGPtls;

	PGPclPreferences(context,hwnd, PGPCL_GENERALPREFS, NULL);

	return TRUE;
}

BOOL PGPscAbout (HWND hwnd,void *PGPsc)
{
	PGPContextRef context;

	context=(PGPContextRef)PGPsc;

	PGPclHelpAbout (context,hwnd,NULL,NULL,NULL);

	return TRUE;
}

BOOL DoLaunchKeys(HWND hwnd)
{  
	char PGPkeys[MAX_PATH];
	int error;
	char StrRes[500];
	
	PGPpath(PGPkeys);

// Since Windows can't handle tray launched from CD
	SetCurrentDirectory(PGPkeys);

	strcat(PGPkeys,"PGPkeys.exe /s");
	error=WinExec(PGPkeys, SW_SHOW);
 
	if(error<=31)
	{ 
		LoadString (g_hinst, IDS_CANTOPENPGPKEYS, StrRes, sizeof(StrRes));

		MessageBox(hwnd,PGPkeys,
			StrRes,
			MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);

		return FALSE;
	}

	return TRUE;
}

BOOL DoLaunchNet(HWND hwnd)
{  
	char PGPnet[MAX_PATH];
	int error;
	char StrRes[500];
	
	PGPpath(PGPnet);

// Since Windows can't handle tray launched from CD
	SetCurrentDirectory(PGPnet);

	strcat(PGPnet,"PGPnet.exe");
	error=WinExec(PGPnet, SW_SHOW);
 
	if(error<=31)
	{ 
		LoadString (g_hinst, IDS_CANTOPENPGPNET, StrRes, sizeof(StrRes));

		MessageBox(hwnd,PGPnet,
			StrRes,
			MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);

		return FALSE;
	}

	return TRUE;
}

BOOL DoLaunchTools(HWND hwnd)
{  
	char PGPtools[MAX_PATH];
	int error;
	char StrRes[500];

	PGPpath(PGPtools);

// Since Windows can't handle tray launched from CD
	SetCurrentDirectory(PGPtools);

	strcat(PGPtools,"PGPtools.exe");
	error=WinExec(PGPtools, SW_SHOW);
 
	if(error<=31)
	{ 
		LoadString (g_hinst, IDS_CANTOPENPGPTOOLS, StrRes, sizeof(StrRes));

		MessageBox(hwnd,PGPtools,
			StrRes,
			MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);

		return FALSE;
	}

	return TRUE;
}

BOOL DoLaunchDisk(HWND hwnd)
{  
	char PGPtools[MAX_PATH];
	int error;
	char StrRes[500];

	PGPpath(PGPtools);

// Since Windows can't handle tray launched from CD
	SetCurrentDirectory(PGPtools);

	strcat(PGPtools,"PGPdisk.exe");
	error=WinExec(PGPtools, SW_SHOW);
 
	if(error<=31)
	{ 
		LoadString (g_hinst, IDS_CANTOPENPGPDISK, StrRes, sizeof(StrRes));

		MessageBox(hwnd,PGPtools,
			StrRes,
			MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);

		return FALSE;
	}

	return TRUE;
}

BOOL CheckClipboard()
{
	char *pInput;
	DWORD dwInputSize;
	UINT ClipboardFormat;
	BOOL RetVal;

	RetVal=FALSE;

	pInput=RetrieveClipboardData
			(NULL,&ClipboardFormat,&dwInputSize);

	if((ClipboardFormat == CF_TEXT)&&(pInput!=0))
	{
		if(*pInput!=0)
		{
			RetVal=TRUE;
		}
	}

	if(pInput!=0)
	{
		memset(pInput,0x00,dwInputSize);
		free(pInput);
	}

	return RetVal;
}

void ControlA(void)
{
	g_KeyArray[0]=VK_CONTROL|SK_KEYDOWN;
	g_KeyArray[1]='A'|SK_KEYDOWN;
	g_KeyArray[2]='A';
	g_KeyArray[3]=VK_CONTROL;

	SendKeys( g_KeyArray, 4 );
}

void ControlC(void)
{
	g_KeyArray[0]=VK_CONTROL|SK_KEYDOWN;
	g_KeyArray[1]='C'|SK_KEYDOWN;
	g_KeyArray[2]='C';
	g_KeyArray[3]=VK_CONTROL;

	SendKeys( g_KeyArray, 4 );
}

void ControlV(void)
{
	g_KeyArray[0]=VK_CONTROL|SK_KEYDOWN;
	g_KeyArray[1]='V'|SK_KEYDOWN;
	g_KeyArray[2]='V';
	g_KeyArray[3]=VK_CONTROL;

	SendKeys( g_KeyArray, 4 );
}

void EMSetSel(HWND hwndEdit)
{
	SendMessage(hwndEdit,EM_SETSEL,0,-1);
}

void WMCopy(HWND hwndEdit)
{
	SendMessage(hwndEdit,WM_COPY,0,0);
}

BOOL DoCopy(HWND hwnd,void *PGPsc,BOOL bUseCurrent,HWND *hwndFocus)
{
	BOOL ClipOK;
	HWND hwndEdit;
	BOOL RetVal=TRUE;
	char WinClass[256];
	PGPContextRef context;
	DWORD OtherAppThreadID;
	DWORD OtherAppProcessID;
	HWND hwndOldFocus;
	DWORD TrayThreadID;

	context=(PGPContextRef)PGPsc;

	*hwndFocus=NULL;

	if(bUseCurrent)
	{
		TrayThreadID=GetCurrentThreadId();
		hwndEdit=ReadCurrentFocus();
		*hwndFocus=hwndEdit;

		GetClassName(hwndEdit,WinClass,255);

		ClipboardWipe(NULL,context);

		// We can key off WinClass if something else
		// needs to be done 

		OtherAppThreadID = GetWindowThreadProcessId( hwndEdit, 
			&OtherAppProcessID);

		AttachThreadInput( TrayThreadID, OtherAppThreadID, TRUE );

		hwndOldFocus=SetFocus(hwndEdit);

		WMCopy(hwndEdit);

		ClipOK=CheckClipboard();
		if(!ClipOK)
		{
			// We can key off WinClass if something else
			// needs to be done 
			EMSetSel(hwndEdit);
			WMCopy(hwndEdit);

			ClipOK=CheckClipboard();
			if(!ClipOK)
			{
				ControlC();
			
				ClipOK=CheckClipboard();
				if(!ClipOK)
				{
					ControlA();
					ControlC();

					ClipOK=CheckClipboard();
					if(!ClipOK)
					{
						RetVal=FALSE;
					}
				}
			}
		}

		AttachThreadInput( TrayThreadID, OtherAppThreadID, FALSE );
		SetFocus(hwndOldFocus);
	}

	if(!RetVal)
	{
#if _DEBUG
		MessageBox(hwnd,WinClass,"Couldn't get text. _DEBUG VERSION ONLY_ info",
			MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
#else
		PGPscMessageBox (hwnd,IDS_PGPERROR,IDS_CANTAUTOCOPY,
			MB_OK|MB_ICONSTOP);
#endif
	}
	return RetVal;
}

void DoPaste(BOOL bUseCurrent,HWND hwndFocus)
{
	HWND hwndEdit;
	char WinClass[256];
	DWORD OtherAppThreadID;
	DWORD OtherAppProcessID;
	DWORD TrayThreadID;

	if(bUseCurrent)
	{
		TrayThreadID=GetCurrentThreadId();
		hwndEdit=hwndFocus; 
		GetClassName(hwndEdit,WinClass,255);

		OtherAppThreadID = GetWindowThreadProcessId( hwndEdit, 
			&OtherAppProcessID);

		AttachThreadInput( TrayThreadID, OtherAppThreadID, TRUE );

		// We can key off WinClass if something else
		// needs to be done 

		SetFocus(hwndEdit);

		ControlV();

		AttachThreadInput( TrayThreadID, OtherAppThreadID, FALSE );
	}
}

void DoFocus(BOOL bUseCurrent,HWND hwndFocus)
{
	HWND hwndEdit;
	char WinClass[256];
	DWORD OtherAppThreadID;
	DWORD OtherAppProcessID;
	DWORD TrayThreadID;

	if(bUseCurrent)
	{
		TrayThreadID=GetCurrentThreadId();
		hwndEdit=hwndFocus; 
		GetClassName(hwndEdit,WinClass,255);

		OtherAppThreadID = GetWindowThreadProcessId( hwndEdit, 
			&OtherAppProcessID);

		AttachThreadInput( TrayThreadID, OtherAppThreadID, TRUE );

		// We can key off WinClass if something else
		// needs to be done 

		SetFocus(hwndEdit);

		AttachThreadInput( TrayThreadID, OtherAppThreadID, FALSE );
	}
}

void StartUpdateTimer(HWND hwnd, UINT *pnLaunchKeysTimer)
{
	if (pnLaunchKeysTimer != NULL)
		*pnLaunchKeysTimer = 0;

	if (hwnd == NULL)
		return;

	UpdateTimerProc(hwnd, WM_TIMER, LAUNCHKEYS_TIMER, 0);

	*pnLaunchKeysTimer = SetTimer(hwnd, LAUNCHKEYS_TIMER, 
									MILLISECONDS_PER_DAY,
									(TIMERPROC) UpdateTimerProc);
	return;
}


VOID CALLBACK UpdateTimerProc(HWND hwnd, 
							  UINT uMsg, 
							  UINT idEvent, 
							  DWORD dwTime)
{
	PGPMemoryMgrRef memoryMgr;
	PGPBoolean		bUpdateAllKeys;
	PGPBoolean		bUpdateTrustedIntroducers;
	PGPBoolean		bUpdateCRLs;
	PGPError		err = kPGPError_NoErr;

	if (idEvent != LAUNCHKEYS_TIMER)
		return;

	err = PGPNewMemoryMgr(0, &memoryMgr);
	if (IsPGPError(err))
	{
		PGPclErrorBox(hwnd, err);
		return;
	}

	err = PGPclCheckAutoUpdate(memoryMgr, FALSE, 
			&bUpdateAllKeys, &bUpdateTrustedIntroducers, &bUpdateCRLs);
	if (IsPGPError(err))
	{
		PGPclErrorBox(hwnd, err);
		return;
	}

	if (bUpdateAllKeys || bUpdateTrustedIntroducers || bUpdateCRLs)
		DoLaunchKeys(hwnd);

	PGPFreeMemoryMgr(memoryMgr);
	return;
}
 
BOOL FileHasThisExtension(char *filename,char *extension)
{
	char *p;

	if(filename!=NULL)
	{
		if((p = strrchr(filename, '\\')))
			filename=p; // we just want the filename not path

		if((p = strrchr(filename, '.')))
		{
			p++;

			if(!strcmpi(p,extension))
				return TRUE;
		}
	}

	return FALSE;
}
	
LRESULT CALLBACK PlaybackHook( int nCode, WPARAM wParam,
                 LPARAM lParam )
{
   LPEVENTMSG lpEM;

   switch(nCode) {
      case HC_SKIP:
		 g_KeyIndex++;
         if( g_KeyIndex == g_NumKeys ) {  // no more keys?
            // remove hook
            UnhookWindowsHookEx(g_hJournalHook);
            g_hJournalHook = NULL;
         }
         return 0;

      case HC_GETNEXT:
         lpEM = (LPEVENTMSG)lParam;
         if( lpJournalKeys[g_KeyIndex] & SK_KEYDOWN )
            lpEM->message = lpJournalKeys[g_KeyIndex] & SK_SYSKEY
                                        ? WM_SYSKEYDOWN : WM_KEYDOWN;
         else
            lpEM->message = lpJournalKeys[g_KeyIndex] & SK_SYSKEY 
                                        ? WM_SYSKEYUP : WM_KEYUP;
         lpEM->paramL = LOBYTE(lpJournalKeys[g_KeyIndex])
               | (MapVirtualKey(LOBYTE(lpJournalKeys[g_KeyIndex]),0)<<8);
         lpEM->paramH = 1;
         lpEM->time = GetCurrentTime();
         return 0;

      default:
         return CallNextHookEx(g_hJournalHook,nCode,wParam,lParam);
   }
}

#define KeyDown( uKey ) ( GetAsyncKeyState(uKey) & 0x8000 )

BOOL WINAPI SendKeys( UINT *lpKeys, UINT nKeys )
{
   lpJournalKeys = lpKeys;
   g_KeyIndex =   0;
   g_NumKeys =  nKeys;
   if( g_hJournalHook )
      return FALSE;
   while( KeyDown(VK_MENU) || KeyDown(VK_SHIFT)
                                || KeyDown(VK_CONTROL) ) {
      MSG msg;
      if( PeekMessage(&msg,NULL,0,0,PM_REMOVE) ) {
         if( msg.message == WM_QUIT ) {
            PostMessage(msg.hwnd,msg.message,msg.wParam,msg.lParam);
            return FALSE;
         }
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
   }
   g_hJournalHook = SetWindowsHookEx(WH_JOURNALPLAYBACK,
      (HOOKPROC)PlaybackHook,g_hinst,0);
   if(!g_hJournalHook) return FALSE;
   // while hook is installed, pump messages
   while(g_hJournalHook) {
      MSG msg;
      if( PeekMessage(&msg,NULL,0,0,PM_REMOVE) ) {
         if( msg.message == WM_QUIT ) {
            if( g_hJournalHook )
               UnhookWindowsHookEx(g_hJournalHook);
            PostMessage(msg.hwnd,msg.message,msg.wParam,msg.lParam);
            return FALSE;
         }
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
   }
   return TRUE;
}
		
/*__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 + -