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

📄 pgpadminxctl.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:


/////////////////////////////////////////////////////////////////////////////
// CPGPadminXCtrl property handlers

long CPGPadminXCtrl::GetNPrefBlocks() 
{
	pgpConfigInfo *pConfig;
	HANDLE hPrefFile;
	DWORD dwFileSize;

	// TODO: Add your property handler here
	m_nCurPrefBlock = 0;
	m_nPrefIndex = 0;

	if (m_szPrefBuffer != NULL)
	{
		PGPFreeData(m_szPrefBuffer);
		m_szPrefBuffer = NULL;
	}

	if (m_prefRef == NULL)
	{
		m_szPrefBuffer = (char *) PGPNewData(m_pgpMemMgr, 1, 0);
		m_szPrefBuffer[0] = 0;
		m_nPrefBlocks = 1;
		return 1;
	}

	if (g_hCurrentDlgWnd != NULL)
	{
		PGPSetPrefNumber(m_prefRef, kPGPPrefUserAccountStatus,
			kPGPPrefPGPNotInitialized);
		PGPSetPrefBoolean(m_prefRef, kPGPPrefFirstKeyGenerated,
			FALSE);
		PGPSetPrefString(m_prefRef, kPGPPrefRNGSeedFile, "");
		pConfig = (pgpConfigInfo *) GetWindowLong(g_hCurrentDlgWnd, GWL_USERDATA);
		SaveAdminOptions(pConfig);
	}

	hPrefFile = CreateFile(m_szPrefFile, GENERIC_READ, 0, NULL, OPEN_EXISTING,
					FILE_ATTRIBUTE_NORMAL, NULL);
	dwFileSize = GetFileSize(hPrefFile, NULL);
	m_szPrefBuffer = (char *) PGPNewData(m_pgpMemMgr, dwFileSize + 1, 0);
	ReadFile(hPrefFile, (void *) m_szPrefBuffer, dwFileSize, &dwFileSize, NULL);
	CloseHandle(hPrefFile);
	m_szPrefBuffer[dwFileSize] = 0;

	m_nPrefBlocks = 1;
	m_nPrefIndex = PREFS_BLOCK_SIZE;
	while (m_nPrefIndex < dwFileSize)
	{
		while (m_szPrefBuffer[m_nPrefIndex-1] != '\n')
			m_nPrefIndex--;

		m_nPrefBlocks++;
		m_nPrefIndex += PREFS_BLOCK_SIZE;
	}

	m_nPrefIndex = 0;
	return m_nPrefBlocks;
}

void CPGPadminXCtrl::SetNPrefBlocks(long nNewValue) 
{
	// TODO: Add your property handler here
	if (m_prefRef != NULL)
	{
		PGPFreePrefs(m_prefRef);
		m_prefRef = NULL;
		DeleteFile(m_szPrefFile);
	}

	if (m_szPrefBuffer != NULL)
	{
		PGPFreeData(m_szPrefBuffer);
		m_szPrefBuffer = NULL;
	}

	if (nNewValue)
		m_szPrefBuffer = (char *) PGPNewData(m_pgpMemMgr, 
									(nNewValue * PREFS_BLOCK_SIZE) + 1,
									kPGPMemoryMgrFlags_Clear);
	else
	{
		char szTempPath[_MAX_PATH];
		PFLFileSpecRef prefFile;
		PGPPrefRef userPrefRef;

		GetTempPath(_MAX_PATH, szTempPath);
		GetTempFileName(szTempPath, "pgp", 0, m_szPrefFile);
		PFLNewFileSpecFromFullPath(m_pgpMemMgr, m_szPrefFile, &prefFile);
		PGPOpenPrefFile(prefFile, clientDefaults, clientDefaultsSize, 
			&m_prefRef);
		PGPSetPrefWrap(m_prefRef, 0);
		PFLFreeFileSpec(prefFile);

		PGPclPeekClientLibPrefRefs(&userPrefRef, NULL);
		if (userPrefRef != NULL)
			PGPAddPrefs(userPrefRef, m_prefRef);
		
		if (g_hCurrentDlgWnd != NULL)
		{
			pgpConfigInfo *pConfig;
			
			pConfig = (pgpConfigInfo *) GetWindowLong(g_hCurrentDlgWnd, 
											GWL_USERDATA);
			
			FreeAdminOptions(pConfig);
			InitAdminOptions(m_pgpContext, pConfig, TRUE);
			pConfig->prefRef = m_prefRef;
			pConfig->prefRefNet = m_prefRefNet;
			LoadAdminOptions(pConfig);
			
			::DestroyWindow(g_hCurrentDlgWnd);
			sShowTabPage(GetSafeHwnd(), pConfig, m_pPage, m_bDisabled);
		}
	}

	m_nPrefBlocks = nNewValue;
	m_nCurPrefBlock = 0;
	m_nPrefIndex = 0;
	SetModifiedFlag();
}

BSTR CPGPadminXCtrl::GetSzPrefs() 
{
	CString strResult;
	BSTR bstrPrefs;
	char szPrefs[PREFS_BLOCK_SIZE+3];
	UINT nBlockSize;

	// TODO: Add your property handler here
	if ((m_szPrefBuffer == NULL) || (m_nCurPrefBlock == m_nPrefBlocks))
	{
		strResult = (LPCSTR) "";
		return strResult.AllocSysString();
	}

	strcpy(szPrefs, "\r\n");
	strncpy(&szPrefs[2], &m_szPrefBuffer[m_nPrefIndex], PREFS_BLOCK_SIZE);
	nBlockSize = PREFS_BLOCK_SIZE;
	while (szPrefs[nBlockSize+1] != '\n')
		nBlockSize--;

	m_nPrefIndex += nBlockSize;
	m_nCurPrefBlock++;
	szPrefs[nBlockSize+2] = 0;
	strResult = (LPCSTR) szPrefs;
	bstrPrefs = strResult.AllocSysString();

	if (m_nCurPrefBlock == m_nPrefBlocks)
	{
		if (m_szPrefBuffer != NULL)
		{
			PGPFreeData(m_szPrefBuffer);
			m_szPrefBuffer = NULL;
		}
	}

	return bstrPrefs;
}

void CPGPadminXCtrl::SetSzPrefs(LPCTSTR lpszNewValue) 
{
	char szTempPath[_MAX_PATH];
	PFLFileSpecRef prefFile;
	HANDLE hPrefFile;
	DWORD dwLength;

	// TODO: Add your property handler here
	if ((m_szPrefBuffer == NULL) || (m_nCurPrefBlock == m_nPrefBlocks) ||
		lpszNewValue == NULL)
		return;

	dwLength = strlen(lpszNewValue);
	if (!dwLength)
		return;

	dwLength -= 2;
	strncpy(&m_szPrefBuffer[m_nPrefIndex], &lpszNewValue[2], dwLength);
	m_nPrefIndex += dwLength;
	m_nCurPrefBlock++;

	if (m_nCurPrefBlock == m_nPrefBlocks)
	{
		GetTempPath(_MAX_PATH, szTempPath);
		GetTempFileName(szTempPath, "pgp", 0, m_szPrefFile);
		hPrefFile = CreateFile(m_szPrefFile, GENERIC_WRITE, 0, NULL, 
			CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

		dwLength = m_nPrefIndex;
		m_szPrefBuffer[dwLength] = 0;
		WriteFile(hPrefFile, m_szPrefBuffer, dwLength, &dwLength, NULL);
		PGPFreeData(m_szPrefBuffer);
		m_szPrefBuffer = NULL;
		
		CloseHandle(hPrefFile);
		PFLNewFileSpecFromFullPath(m_pgpMemMgr, m_szPrefFile, &prefFile);
		PGPOpenPrefFile(prefFile, clientDefaults, clientDefaultsSize, 
			&m_prefRef);
		PGPSetPrefWrap(m_prefRef, 0);
		PFLFreeFileSpec(prefFile);
		
		if (g_hCurrentDlgWnd != NULL)
		{
			pgpConfigInfo *pConfig;
			
			pConfig = (pgpConfigInfo *) GetWindowLong(g_hCurrentDlgWnd, 
											GWL_USERDATA);
			
			FreeAdminOptions(pConfig);
			InitAdminOptions(m_pgpContext, pConfig, TRUE);
			pConfig->prefRef = m_prefRef;
			pConfig->prefRefNet = m_prefRefNet;
			LoadAdminOptions(pConfig);
			
			::DestroyWindow(g_hCurrentDlgWnd);
			sShowTabPage(GetSafeHwnd(), pConfig, m_pPage, m_bDisabled);
		}
	}

	SetModifiedFlag();
}

long CPGPadminXCtrl::GetNNetPrefBlocks() 
{
	pgpConfigInfo *pConfig;
	HANDLE hNetPrefFile;
	DWORD dwFileSize;

	// TODO: Add your property handler here
	m_nCurNetPrefBlock = 0;
	m_nNetPrefIndex = 0;

	if (m_szNetPrefBuffer != NULL)
	{
		PGPFreeData(m_szNetPrefBuffer);
		m_szNetPrefBuffer = NULL;
	}

	if (m_prefRefNet == NULL)
	{
		m_szNetPrefBuffer = (char *) PGPNewData(m_pgpMemMgr, 1, 0);
		m_szNetPrefBuffer[0] = 0;
		m_nNetPrefBlocks = 1;
		return 1;
	}

	if (g_hCurrentDlgWnd != NULL)
	{
		pConfig = (pgpConfigInfo *) GetWindowLong(g_hCurrentDlgWnd, GWL_USERDATA);
		SaveAdminOptions(pConfig);
	}

	hNetPrefFile = CreateFile(m_szNetPrefFile, GENERIC_READ, 0, NULL, OPEN_EXISTING,
					FILE_ATTRIBUTE_NORMAL, NULL);
	dwFileSize = GetFileSize(hNetPrefFile, NULL);
	m_szNetPrefBuffer = (char *) PGPNewData(m_pgpMemMgr, dwFileSize + 1, 0);
	ReadFile(hNetPrefFile, (void *) m_szNetPrefBuffer, dwFileSize, &dwFileSize, NULL);
	CloseHandle(hNetPrefFile);
	m_szNetPrefBuffer[dwFileSize] = 0;

	m_nNetPrefBlocks = 1;
	m_nNetPrefIndex = PREFS_BLOCK_SIZE;
	while (m_nNetPrefIndex < dwFileSize)
	{
		while (m_szNetPrefBuffer[m_nNetPrefIndex-1] != '\n')
			m_nNetPrefIndex--;

		m_nNetPrefBlocks++;
		m_nNetPrefIndex += PREFS_BLOCK_SIZE;
	}

	m_nNetPrefIndex = 0;
	return m_nNetPrefBlocks;
}

void CPGPadminXCtrl::SetNNetPrefBlocks(long nNewValue) 
{
	// TODO: Add your property handler here
	if (m_prefRefNet != NULL)
	{
		PGPFreePrefs(m_prefRefNet);
		m_prefRefNet = NULL;
		DeleteFile(m_szNetPrefFile);
	}

	if (m_szNetPrefBuffer != NULL)
	{
		PGPFreeData(m_szNetPrefBuffer);
		m_szNetPrefBuffer = NULL;
	}

	if (nNewValue)
		m_szNetPrefBuffer = (char *) PGPNewData(m_pgpMemMgr, 
									(nNewValue * PREFS_BLOCK_SIZE) + 1, 
									kPGPMemoryMgrFlags_Clear);
	else
	{
		char szTempPath[_MAX_PATH];
		PFLFileSpecRef prefFile;
		PGPPrefRef userPrefRef;

		GetTempPath(_MAX_PATH, szTempPath);
		GetTempFileName(szTempPath, "pgp", 0, m_szNetPrefFile);
		PFLNewFileSpecFromFullPath(m_pgpMemMgr, m_szNetPrefFile, &prefFile);
		PGPOpenPrefFile(prefFile, netDefaults, netDefaultsSize, 
			&m_prefRefNet);
		PGPSetPrefWrap(m_prefRefNet, 0);
		PFLFreeFileSpec(prefFile);

		PGPclPeekClientLibPrefRefs(NULL, &userPrefRef);
		if (userPrefRef != NULL)
			PGPAddPrefs(userPrefRef, m_prefRefNet);
		
		if (g_hCurrentDlgWnd != NULL)
		{
			pgpConfigInfo *pConfig;
			
			pConfig = (pgpConfigInfo *) GetWindowLong(g_hCurrentDlgWnd, 
											GWL_USERDATA);
			
			FreeAdminOptions(pConfig);
			InitAdminOptions(m_pgpContext, pConfig, TRUE);
			pConfig->prefRef = m_prefRef;
			pConfig->prefRefNet = m_prefRefNet;
			LoadAdminOptions(pConfig);
			
			::DestroyWindow(g_hCurrentDlgWnd);
			sShowTabPage(GetSafeHwnd(), pConfig, m_pPage, m_bDisabled);
		}
	}

	m_nNetPrefBlocks = nNewValue;
	m_nCurNetPrefBlock = 0;
	m_nNetPrefIndex = 0;
	SetModifiedFlag();
}

BSTR CPGPadminXCtrl::GetSzNetPrefs() 
{
	CString strResult;
	BSTR bstrNetPrefs;
	char szNetPrefs[PREFS_BLOCK_SIZE+1];
	int nBlockSize;

	// TODO: Add your property handler here
	if ((m_szNetPrefBuffer == NULL) || (m_nCurNetPrefBlock == m_nNetPrefBlocks))
	{
		strResult = (LPCSTR) "";
		return strResult.AllocSysString();
	}

	strcpy(szNetPrefs, "\r\n");
	strncpy(&szNetPrefs[2], &m_szNetPrefBuffer[m_nNetPrefIndex], PREFS_BLOCK_SIZE);
	nBlockSize = PREFS_BLOCK_SIZE;
	while (szNetPrefs[nBlockSize+1] != '\n')
		nBlockSize--;

	m_nNetPrefIndex += nBlockSize;
	m_nCurNetPrefBlock++;
	szNetPrefs[nBlockSize+2] = 0;
	strResult = (LPCSTR) szNetPrefs;
	bstrNetPrefs = strResult.AllocSysString();

	if (m_nCurNetPrefBlock == m_nNetPrefBlocks)
	{
		if (m_szNetPrefBuffer != NULL)
		{
			PGPFreeData(m_szNetPrefBuffer);
			m_szNetPrefBuffer = NULL;
		}
	}

	return bstrNetPrefs;
}

void CPGPadminXCtrl::SetSzNetPrefs(LPCTSTR lpszNewValue) 
{
	char szTempPath[_MAX_PATH];
	PFLFileSpecRef prefFile;
	HANDLE hNetPrefFile;
	DWORD dwLength;

	// TODO: Add your property handler here
	if ((m_szNetPrefBuffer == NULL) || (m_nCurNetPrefBlock == m_nNetPrefBlocks) ||
		lpszNewValue == NULL)
		return;

	dwLength = strlen(lpszNewValue);
	if (!dwLength)
		return;

	dwLength -= 2;
	strncpy(&m_szNetPrefBuffer[m_nNetPrefIndex], &lpszNewValue[2], dwLength);
	m_nNetPrefIndex += dwLength;
	m_nCurNetPrefBlock++;

	if (m_nCurNetPrefBlock == m_nNetPrefBlocks)
	{
		GetTempPath(_MAX_PATH, szTempPath);
		GetTempFileName(szTempPath, "pgp", 0, m_szNetPrefFile);
		hNetPrefFile = CreateFile(m_szNetPrefFile, GENERIC_WRITE, 0, NULL, 
			CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

		dwLength = m_nNetPrefIndex;
		m_szNetPrefBuffer[dwLength] = 0;
		WriteFile(hNetPrefFile, m_szNetPrefBuffer, dwLength, &dwLength, NULL);
		PGPFreeData(m_szNetPrefBuffer);
		m_szNetPrefBuffer = NULL;
		
		CloseHandle(hNetPrefFile);
		PFLNewFileSpecFromFullPath(m_pgpMemMgr, m_szNetPrefFile, &prefFile);
		PGPOpenPrefFile(prefFile, netDefaults, netDefaultsSize, 
			&m_prefRefNet);
		PGPSetPrefWrap(m_prefRefNet, 0);
		PFLFreeFileSpec(prefFile);
		
		if (g_hCurrentDlgWnd != NULL)
		{
			pgpConfigInfo *pConfig;
			
			pConfig = (pgpConfigInfo *) GetWindowLong(g_hCurrentDlgWnd, 
											GWL_USERDATA);
			
			FreeAdminOptions(pConfig);
			InitAdminOptions(m_pgpContext, pConfig, TRUE);
			pConfig->prefRef = m_prefRef;
			pConfig->prefRefNet = m_prefRefNet;
			LoadAdminOptions(pConfig);
			
			::DestroyWindow(g_hCurrentDlgWnd);
			sShowTabPage(GetSafeHwnd(), pConfig, m_pPage, m_bDisabled);
		}
	}

	SetModifiedFlag();
}

BOOL CPGPadminXCtrl::GetDisabled() 
{
	// TODO: Add your property handler here

	return m_bDisabled;
}

void CPGPadminXCtrl::SetDisabled(BOOL bNewValue) 
{
	// TODO: Add your property handler here
	m_bDisabled = bNewValue;
	if (g_hCurrentDlgWnd != NULL)
	{
		pgpConfigInfo *pConfig;
			
		pConfig = (pgpConfigInfo *) GetWindowLong(g_hCurrentDlgWnd, 
										GWL_USERDATA);

		::DestroyWindow(g_hCurrentDlgWnd);
		sShowTabPage(GetSafeHwnd(), pConfig, m_pPage, m_bDisabled);
	}

	SetModifiedFlag();
}

long CPGPadminXCtrl::GetNDefaultKeyBlocks() 
{
	pgpConfigInfo *pConfig;
	char *szToken;

	// TODO: Add your property handler here
	m_nCurKeyBlock = 0;
	m_nKeyIndex = 0;

	if (m_szKeyBuffer != NULL)
	{
		PGPFreeData(m_szKeyBuffer);
		m_szKeyBuffer = NULL;
	}

	if (g_hCurrentDlgWnd != NULL)
	{
		pConfig = (pgpConfigInfo *) GetWindowLong(g_hCurrentDlgWnd, GWL_USERDATA);
		SaveAdminOptions(pConfig);
	}

	if (pConfig->szDefaultKeysBuffer == NULL)
	{
		m_nKeyBlocks = 1;
		return 1;
	}

	m_szKeyBuffer = (char *) PGPNewData(pConfig->memoryMgr, 
								pConfig->nDefaultKeysBufferSize, 0);
	strcpy(m_szKeyBuffer, pConfig->szDefaultKeysBuffer);

	szToken = strtok(m_szKeyBuffer, "\r\n");
	m_nKeyBlocks = 0;
	while (szToken != NULL)
	{
		m_nKeyBlocks++;
		if (*szToken == '\n')
			szToken = strtok(NULL, "\r\n");

		szToken = strtok(NULL, "\r\n");
	}

	return m_nKeyBlocks;
}

void CPGPadminXCtrl::SetNDefaultKeyBlocks(long nNewValue) 
{
	// TODO: Add your property handler here
	SetModifiedFlag();
}

BSTR CPGPadminXCtrl::GetSzDefaultKeys() 
{
	CString strResult;
	BSTR bstrKeyBlock;
	char szKeyBlock[MAX_KEY_BLOCK+1];

	// TODO: Add your property handler here
	if ((m_szKeyBuffer == NULL) || (m_nCurKeyBlock == m_nKeyBlocks))
	{
		strResult = (LPCSTR) "";
		return strResult.AllocSysString();
	}

	while ((m_szKeyBuffer[m_nKeyIndex] == '\r') ||
		(m_szKeyBuffer[m_nKeyIndex] == '\n'))
		m_nKeyIndex++;

	strcpy(szKeyBlock, &m_szKeyBuffer[m_nKeyIndex]);
	m_nKeyIndex += strlen(szKeyBlock);
	m_nCurPrefBlock++;
	strResult = (LPCSTR) szKeyBlock;
	bstrKeyBlock = strResult.AllocSysString();

	if (m_nCurKeyBlock == m_nKeyBlocks)
	{
		if (m_szKeyBuffer != NULL)
		{
			PGPFreeData(m_szKeyBuffer);
			m_szKeyBuffer = NULL;
		}
	}
	else while (m_szKeyBuffer[m_nKeyIndex] == 0)
		m_nKeyIndex++;

	return bstrKeyBlock;
}

void CPGPadminXCtrl::SetSzDefaultKeys(LPCTSTR lpszNewValue) 
{
	// TODO: Add your property handler here
	SetModifiedFlag();
}


BSTR CPGPadminXCtrl::GetSzProductKey() 
{
	CString strResult;
	// TODO: Add your property handler here

	if (m_szProductKey != NULL)
		strResult = (LPCSTR) m_szProductKey;
	else
		strResult = (LPCSTR) "";

	return strResult.AllocSysString();
}

void CPGPadminXCtrl::SetSzProductKey(LPCTSTR lpszNewValue) 
{
	// TODO: Add your property handler here

	if (lpszNewValue == NULL)
		return;

	m_szProductKey = (char *) PGPNewData(m_pgpMemMgr, strlen(lpszNewValue) + 1, 0);
	strcpy(m_szProductKey, lpszNewValue);
	SetModifiedFlag();
}

⌨️ 快捷键说明

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