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

📄 cpgpclprefs.h

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 H
字号:
/*____________________________________________________________________________
		Copyright (C) 2002 PGP Corporation
        All rights reserved.

        $Id: CPGPclPrefs.h,v 1.8 2002/08/06 20:10:19 dallen Exp $
____________________________________________________________________________*/

#ifndef Included_CPGPclPrefs_h	// [
#define Included_CPGPclPrefs_h

#include "CString.h"

#include "pgpClientLib.h"
#include "pgpClientPrefs.h"

#include "CPGPdata.h"

_PGP_BEGIN

// Class CPGPclPrefs

class CPGPclPrefs
{
	NOT_COPYABLE(CPGPclPrefs)

public:
	CPGPclPrefs();
	CPGPclPrefs(PGPPrefRef prefs);
	~CPGPclPrefs();

	PGPBoolean	IsAttached() const;
	PGPBoolean	WeOpened() const;

	operator PGPPrefRef() const {return mPrefs;}
	PGPPrefRef	Get() const {return mPrefs;}

	PGPBoolean	GetBoolean(PGPPrefIndex prefIndex) const;
	PGPUInt32	GetNumber(PGPPrefIndex prefIndex) const;
	void		GetString(PGPPrefIndex prefIndex, CString& string) const;
	void		GetData(PGPPrefIndex prefIndex, CPGPData& data) const;

	void	SetBoolean(PGPPrefIndex prefIndex, PGPBoolean boolData) const;
	void	SetNumber(PGPPrefIndex prefIndex, PGPUInt32 numData) const;
	void	SetString(PGPPrefIndex prefIndex, const char *str) const;
	void	SetData(PGPPrefIndex prefIndex, const CPGPData& data) const;

	void	Open();
	void	Flush();

	void	Attach(PGPPrefRef prefs);
	void	Clear(PGPBoolean saveChanges = FALSE);

private:
	PGPBoolean	mPrefsOpened;
	PGPPrefRef	mPrefs;
};


// Class CPGPclPrefs member functions

inline 
CPGPclPrefs::CPGPclPrefs() : 
	mPrefsOpened(FALSE), mPrefs(kInvalidPGPPrefRef)
{
}

inline 
CPGPclPrefs::CPGPclPrefs(PGPPrefRef prefs) : 
	mPrefsOpened(FALSE), mPrefs(prefs)
{
	Attach(prefs);
}

inline 
CPGPclPrefs::~CPGPclPrefs()
{
	try
	{
		Clear();
	}
	catch (CComboError&) { }
}

inline 
PGPBoolean 
CPGPclPrefs::IsAttached() const
{
	return (PGPPrefRefIsValid(mPrefs));
}

inline 
PGPBoolean 
CPGPclPrefs::WeOpened() const
{
	return (mPrefsOpened);
}

inline 
PGPBoolean 
CPGPclPrefs::GetBoolean(PGPPrefIndex prefIndex) const
{
	pgpAssert(IsAttached());

	PGPBoolean	prefBool;

	PGPError	pgpErr	= PGPGetPrefBoolean(mPrefs, prefIndex, &prefBool);
	THROW_IF_PGPERROR(pgpErr);

	return prefBool;
}

inline 
PGPUInt32 
CPGPclPrefs::GetNumber(PGPPrefIndex prefIndex) const
{
	pgpAssert(IsAttached());

	PGPUInt32	prefNum;

	PGPError	pgpErr	= PGPGetPrefNumber(mPrefs, prefIndex, &prefNum);
	THROW_IF_PGPERROR(pgpErr);

	return prefNum;
}

inline 
void 
CPGPclPrefs::GetString(PGPPrefIndex prefIndex, CString& string) const
{
	pgpAssert(IsAttached());

	PGPError	pgpErr	= PGPGetPrefStringBuffer(mPrefs, prefIndex, 
		1024, string.GetBuffer(1024));
	string.ReleaseBuffer();

	THROW_IF_PGPERROR(pgpErr);
}

inline 
void 
CPGPclPrefs::GetData(PGPPrefIndex prefIndex, CPGPData& data) const
{
	pgpAssert(IsAttached());

	void	*pData;
	PGPSize	size;

	PGPError	pgpErr	= PGPGetPrefData(mPrefs, prefIndex, &size, &pData);
	THROW_IF_PGPERROR(pgpErr);

	data.Attach(pData, size, TRUE);
}

inline 
void 
CPGPclPrefs::SetBoolean(PGPPrefIndex prefIndex, PGPBoolean boolData) const
{
	pgpAssert(IsAttached());

	PGPError	pgpErr	= PGPSetPrefBoolean(mPrefs, prefIndex, boolData);
	THROW_IF_PGPERROR(pgpErr);
}

inline 
void 
CPGPclPrefs::SetNumber(PGPPrefIndex prefIndex, PGPUInt32 numData) const
{
	pgpAssert(IsAttached());

	PGPError	pgpErr	= PGPSetPrefNumber(mPrefs, prefIndex, numData);
	THROW_IF_PGPERROR(pgpErr);
}

inline 
void 
CPGPclPrefs::SetString(PGPPrefIndex prefIndex, const char *str) const
{
	pgpAssert(IsAttached());

	PGPError	pgpErr	= PGPSetPrefString(mPrefs, prefIndex, str);
	THROW_IF_PGPERROR(pgpErr);
}

inline 
void 
CPGPclPrefs::SetData(PGPPrefIndex prefIndex, const CPGPData& data) const
{
	pgpAssert(IsAttached());

	PGPError	pgpErr	= PGPSetPrefData(mPrefs, prefIndex, data.Size(), 
		data.Get());
	THROW_IF_PGPERROR(pgpErr);
}

inline 
void 
CPGPclPrefs::Open()
{
	Clear();

	PGPError	pgpErr	= PGPclPeekClientLibPrefRefs(&mPrefs, NULL);
	THROW_IF_PGPERROR(pgpErr);

	mPrefsOpened = TRUE;
}

inline 
void 
CPGPclPrefs::Flush()
{
	pgpAssert(IsAttached());
	PGPclFlushClientLibPrefs(mPrefs, NULL);
}

inline 
void 
CPGPclPrefs::Attach(PGPPrefRef prefs)
{
	pgpAssert(PGPPrefRefIsValid(prefs));

	Clear();
	mPrefs = prefs;
}

inline 
void 
CPGPclPrefs::Clear(PGPBoolean saveChanges)
{
	if (WeOpened())
	{
		if (saveChanges)
			PGPclFlushClientLibPrefs(mPrefs, NULL);
	}

	mPrefsOpened = FALSE;
	mPrefs = kInvalidPGPPrefRef;
}

_PGP_END

#endif	// ] Included_CPGPclPrefs_h

⌨️ 快捷键说明

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