cldiskwiz.c

来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C语言 代码 · 共 1,374 行 · 第 1/3 页

C
1,374 行
字号

				if((pkgi->diskSize%(1024*1024*2))==0)
					sprintf(szSize,"%d GB",pkgi->diskSize/(1024*1024*2));
				else if((pkgi->diskSize%(1024*2))==0)
					sprintf(szSize,"%d MB",pkgi->diskSize/(1024*2));
				else 
					sprintf(szSize,"%d KB",pkgi->diskSize/2);

				SetWindowText(GetDlgItem(hwnd,IDC_CORPDISKSIZE),
					szSize);

				SetWindowText(GetDlgItem(hwnd,IDC_CORPDISKFILENAME),
					pkgi->diskName);

				{
					CHAR sz[kPGPMaxUserIDSize];
					UINT u;

					PostMessage (GetParent (hwnd),
							PSM_SETWIZBUTTONS, 0, PSWIZB_BACK|PSWIZB_NEXT);

					if (PGPKeyDBObjRefIsValid (pkgi->diskADK))
					{
						ShowWindow (GetDlgItem (hwnd, IDC_CORPDISKADKTEXT), SW_SHOW);
						ShowWindow (UTF8EditGetHandle (
								GetDlgItem (hwnd, IDC_CORPDISKADK)), SW_SHOW);
						ShowWindow (GetDlgItem (hwnd, IDC_ADKTEXT2), SW_SHOW);
						u = sizeof(sz);
						PGPclGetPrimaryUserIDNameUTF8 (
								pkgi->diskADK, sz, sizeof(sz), &u);
						UTF8EditSetText (GetDlgItem (hwnd, IDC_CORPDISKADK), sz);
					}

					SetWindowLong (hwnd, DWL_MSGRESULT, 0L);
				}

				bReturnCode = TRUE;
				break;
			}

			case PSN_KILLACTIVE :
			{
				pkgi = (PDISKINFO)GetWindowLong (hwnd, GWL_USERDATA);

				GetWindowText(GetDlgItem(hwnd,IDC_CORPDISKFILENAME),
					pkgi->diskName,MAX_PATH);
				break;
			}
		}
		break;
	}
	}

	return bReturnCode;
}



//	______________________________________________
//
//  Dialog procedure for handling beginning introductory
//  dialog.

static LRESULT WINAPI
sKeyWizardIntroDlgProc (
		HWND	hwnd,
		UINT	uMsg,
		WPARAM	wParam,
		LPARAM	lParam)
{
	BOOL			bReturnCode = FALSE;
	PDISKINFO		pkgi		= NULL;

	switch (uMsg) {
	case WM_INITDIALOG:
	{
		PROPSHEETPAGE *ppspMsgRec = (PROPSHEETPAGE *) lParam;

		pkgi = (PDISKINFO) ppspMsgRec->lParam;
		SetWindowLong (hwnd, GWL_USERDATA, (LPARAM)pkgi);

		// center dialog on screen
		PGPclCenterWindowOnMonitor (GetParent(hwnd), kPGPclWindowMonitor);

		SendDlgItemMessage (hwnd, IDC_HEADING, WM_SETFONT,
				(WPARAM)pkgi->hfontIntro, (LPARAM)FALSE);

		return TRUE;
	}

	case WM_ACTIVATE :
		InvalidateRect (hwnd, NULL, TRUE);
		break;

	case WM_PAINT :
		pkgi = (PDISKINFO)GetWindowLong (hwnd, GWL_USERDATA);

		if (pkgi->hpaletteIntro)
		{
			PAINTSTRUCT ps;
			HDC			hDC = BeginPaint (hwnd, &ps);

			SelectPalette (hDC, pkgi->hpaletteIntro, FALSE);
			RealizePalette (hDC);
			EndPaint (hwnd, &ps);
		}
		break;

	case WM_NOTIFY:
	{
		LPNMHDR pnmh = (LPNMHDR) lParam;

		switch(pnmh->code) {
		case PSN_SETACTIVE:
			pkgi = (PDISKINFO)GetWindowLong (hwnd, GWL_USERDATA);

			PostMessage(GetParent(hwnd),
					PSM_SETWIZBUTTONS, 0, PSWIZB_NEXT);
			SendDlgItemMessage(hwnd, IDC_WIZBITMAP, STM_SETIMAGE,
					IMAGE_BITMAP, (LPARAM) pkgi->hbitmapIntro);

			SetWindowLong(hwnd, DWL_MSGRESULT, 0L);
			bReturnCode = TRUE;
			break;

		case PSN_KILLACTIVE :
			break;
		}

		break;
	}
	}

	return bReturnCode;
}

void ConstructValidDefaultPath(char *filename)
{
	char defaultPath[MAX_PATH];
	int len;
	PGPUInt32 i;
	FILE *ftest;

	PGPclGetPath(kPGPclDefaultSaveAsFolder, 
		defaultPath, 
		MAX_PATH);

	// Make sure it ends in a slash
	len=strlen(defaultPath);
	if(len!=0)
	{
		if(defaultPath[len-1]!='\\')
			strcat(defaultPath,"\\");
	}

	i=1;

	while (TRUE)
	{
		sprintf(filename,"%sPGPdisk%d.pgd",defaultPath,i);

		ftest=fopen(filename,"rb");

		if(ftest!=0)
		{
			fclose(ftest);
		}
		else
		{
			break;
		}
		i++;
	}
}

//	______________________________________________
//
//  Create wizard data structures and call PropertySheet
//  to actually create wizard

static PGPError
sDiskGenerationWizard (
	PGPContextRef		context,
	HWND				hwndParent,
	PGPKeyID			*pKeyID)
{
	PGPError			err					= kPGPError_NoErr;

	DISKINFO			KGInfo;
	PROPSHEETPAGE		pspWiz[NUM_WIZ_PAGES];
	PROPSHEETHEADER		pshWiz;
	INT					iIndex;
	INT					iNumBits, iBitmap;
	HDC					hDC;
	PGPPrefRef			userPrefRef;
	PGPBoolean			bUseADK,bAbort,bCreateDisk;

	bAbort=bCreateDisk=FALSE;

	// intialize windows
	s_hwndCollectEntropy = NULL;

	memset(&KGInfo,0x00,sizeof(DISKINFO));

	// Set defaults
	if (PGPContextRefIsValid (context))
		KGInfo.context = context;
	else
		KGInfo.context = g_context;

	KGInfo.hwndParent			= hwndParent;
	KGInfo.hwndWiz				= NULL;
	KGInfo.hpaletteIntro		= NULL;
	KGInfo.hpaletteDone			= NULL;

	// Determine which bitmap will be displayed in the wizard
	hDC = GetDC (NULL);	 // DC for desktop
	iNumBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES);
	ReleaseDC (NULL, hDC);

	if (iNumBits <= 1)
		iBitmap = IDB_KEYWIZ1;
	else if (iNumBits <= 4)
		iBitmap = IDB_KEYWIZ4;
	else
		iBitmap = IDB_KEYWIZ8;

	KGInfo.hbitmapIntro = CLLoadResourceBitmap (g_hInst,
			MAKEINTRESOURCE (iBitmap), &KGInfo.hpaletteIntro);
	KGInfo.hbitmapDone = CLLoadResourceBitmap (g_hInst,
			MAKEINTRESOURCE (iBitmap), &KGInfo.hpaletteDone);

	// load special fonts
	KGInfo.hfontIntro = CLLoadHeadingFont (FALSE);
	KGInfo.hfontInterior = CLLoadHeadingFont (TRUE);

	// load icon bitmaps
	KGInfo.hiconAlert = ImageList_GetIcon (
			g_hilClientLib, IDX_ALERT, ILD_TRANSPARENT);
	KGInfo.hiconDoing = ImageList_GetIcon (
			g_hilClientLib, IDX_ARROW, ILD_TRANSPARENT);
	KGInfo.hiconDone = ImageList_GetIcon (
			g_hilClientLib, IDX_CHECK, ILD_TRANSPARENT);
	KGInfo.hiconNotDone = ImageList_GetIcon (
			g_hilClientLib, IDX_ERROR, ILD_TRANSPARENT);

	// Set the values common to all pages
	for (iIndex=0; iIndex<NUM_WIZ_PAGES; iIndex++)
	{
		pspWiz[iIndex].dwSize		= sizeof(PROPSHEETPAGE);
		pspWiz[iIndex].dwFlags		= PSP_DEFAULT;
		pspWiz[iIndex].hInstance	= g_hInst;
		pspWiz[iIndex].pszTemplate  = NULL;
		pspWiz[iIndex].hIcon		= NULL;
		pspWiz[iIndex].pszTitle		= NULL;
		pspWiz[iIndex].pfnDlgProc   = NULL;
		pspWiz[iIndex].lParam		= (LPARAM) &KGInfo;
		pspWiz[iIndex].pfnCallback  = NULL;
		pspWiz[iIndex].pcRefParent  = NULL;
	}

	// Set up the intro page
	pspWiz[KGWIZ_CORPDISKINTRO].pszTemplate = MAKEINTRESOURCE(IDD_KEYWIZ_CORPDISKINTRO);
	pspWiz[KGWIZ_CORPDISKINTRO].pfnDlgProc = sKeyWizardIntroDlgProc;

	// Set up the corporate options page
	pspWiz[KGWIZ_CORPDISKOPTS].pszTemplate = MAKEINTRESOURCE(IDD_KEYWIZ_CORPDISKOPTS);
	pspWiz[KGWIZ_CORPDISKOPTS].pfnDlgProc = sKeyWizardCorpOptsDlgProc;

	// Set up the entropy page
	pspWiz[KGWIZ_ENTROPY].pszTemplate = MAKEINTRESOURCE(IDD_KEYWIZ_RANDOBITS);
	pspWiz[KGWIZ_ENTROPY].pfnDlgProc = sKeyWizardRandobitsDlgProc;

	// Set up the progress dialog
	pspWiz[KGWIZ_CORPDISKCREATION].pszTemplate = MAKEINTRESOURCE(IDD_KEYWIZ_CORPDISKCREATION);
	pspWiz[KGWIZ_CORPDISKCREATION].pfnDlgProc = sKeyWizardProgressDlgProc;

	// Set up the done page
	pspWiz[KGWIZ_CORPDISK_DONE].pszTemplate = MAKEINTRESOURCE(IDD_KEYWIZ_CORPDISK_DONE);
	pspWiz[KGWIZ_CORPDISK_DONE].pfnDlgProc = sKeyWizardDoneDlgProc;

	// Create the header
	pshWiz.dwSize		= sizeof(PROPSHEETHEADER);
	pshWiz.dwFlags		= PSH_WIZARD | PSH_PROPSHEETPAGE;
	pshWiz.hwndParent   = hwndParent;
	pshWiz.hInstance	= g_hInst;
	pshWiz.hIcon		= NULL;
	pshWiz.pszCaption   = NULL;
	pshWiz.nPages		= NUM_WIZ_PAGES;
	pshWiz.nStartPage   = KGWIZ_CORPDISKINTRO;
	pshWiz.ppsp			= pspWiz;
	pshWiz.pfnCallback  = NULL;

	PGPclPeekClientLibPrefRefs(&userPrefRef, NULL);

	if(userPrefRef==NULL)
	{
		MessageBox(hwndParent,
			"Error reading preferences. Please consult your administrator.",
			"PGP Error",
			MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);

		bAbort=TRUE;
	}
	else
	{
		err = PGPGetPrefBoolean( userPrefRef,
					kPGPPrefDiskCreate, &bCreateDisk);

		if(IsPGPError(err)||(!bCreateDisk))
		{
			bAbort=TRUE;
		}
		else
		{
			err = PGPGetPrefNumber( userPrefRef,
						kPGPPrefDiskSize, &(KGInfo.diskSize) );

			err = PGPGetPrefNumber( userPrefRef,
						kPGPPrefDiskAlgorithm, &(KGInfo.diskAlgorithm) );		
			
			err = PGPGetPrefNumber( userPrefRef,
						kPGPPrefDiskFileSystem, &(KGInfo.diskFS) );

			err = PGPGetPrefBoolean( userPrefRef,
						kPGPPrefUsePGPdiskADK, &bUseADK );
		}
	}	

	ConstructValidDefaultPath(KGInfo.diskName);

	if(!bAbort)
	{
		// Execute the Wizard - doesn't return until Cancel or Save
		err = PGPdiskEngineInitLibrary(0);

		if(IsPGPError(err))
		{
			MessageBox(hwndParent,
				"Could not init DiskEngine library. Please consult your administrator.",
				"PGP Error",
				MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
		}
		else
		{
			err = PGPdiskUIInitLibrary();

			if(IsPGPError(err))
			{
				MessageBox(hwndParent,
					"Could not init DiskUI library. Please consult your administrator.",
					"PGP Error",
					MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
			}
			else
			{
				err=PGPdiskNewContext(kPGPdiskAPIVersion, &(KGInfo.diskContext));

				if(IsPGPError(err))
				{
					MessageBox(hwndParent,
						"Could not get Disk context. Please consult your administrator.",
						"PGP Error",
						MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
				}
				else
				{
					PGPdiskDirtyPGPKeyDB(KGInfo.diskContext);

					err=PGPdiskOpenPeekContextPGPKeyDB(KGInfo.diskContext,&(KGInfo.keydbMain));
					
					if(IsntPGPError(err))
					{
						if( bUseADK )
						{
							PGPSize	dataLength;
							PGPByte	*data;
								
							err = PGPGetPrefData( userPrefRef,
												kPGPPrefPGPdiskADKKeyID,
												&dataLength, &data );
							if( IsntPGPError( err ) )
							{
								err=PGPFindKeyByKeyID(
									KGInfo.keydbMain,
									(PGPKeyID *)data,
									&(KGInfo.diskADK));

								if(IsPGPError(err))
								{
									MessageBox(hwndParent,
										"The ADK for PGPdisk could not be found. Please consult your administrator.",
										"PGP Error",
										MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
									bAbort=TRUE;
								}

								PGPFreeData(data);
							}
						}

						if(!bAbort)
						{
							err=PGPFindKeyByKeyID(KGInfo.keydbMain,pKeyID,&(KGInfo.keyNew));

							if(IsntPGPError(err))
							{
								PropertySheet(&pshWiz);

								// Just in case the thread hasn't finished cancelling
								if(KGInfo.hThread!=0)
								{
									WaitForSingleObject(KGInfo.hThread,INFINITE);
									CloseHandle(KGInfo.hThread);
								}
							}
						}
					}

					PGPdiskFreeContext(KGInfo.diskContext);
				}
				PGPdiskUICleanupLibrary();
			}
			PGPdiskEngineCleanupLibrary();
		}
	}

	s_hwndCollectEntropy = NULL;

	DeleteObject (KGInfo.hbitmapIntro);
	DeleteObject (KGInfo.hbitmapDone);
	DeleteObject (KGInfo.hfontIntro);
	DeleteObject (KGInfo.hfontInterior);

	DestroyIcon (KGInfo.hiconAlert);
	DestroyIcon (KGInfo.hiconDoing);
	DestroyIcon (KGInfo.hiconDone);
	DestroyIcon (KGInfo.hiconNotDone);

	return kPGPError_NoErr;
}


//	______________________________________________
//
//  Create wizard data structures and call PropertySheet
//  to actually create wizard

PGPError PGPclExport
PGPclDiskGenerationWizard (
	PGPContextRef		context,
	HWND				hwndParent,
	PGPKeyID			*pKeyID)
{
	return sDiskGenerationWizard (context,
			hwndParent, pKeyID);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?