Click here to Skip to main content
15,885,908 members
Articles / Desktop Programming / MFC

Exile 1.8 - The Password Manager

Rate me:
Please Sign up or sign in to vote.
4.57/5 (51 votes)
6 Mar 20058 min read 255.2K   7.4K   111  
Yet another password manager.
// Settings.cpp: implementation of the CSettings class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "exile.h"
#include "Settings.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSettings::CSettings()
{

}

CSettings::~CSettings()
{

}

//////////////////////////////////////////////////////////////////////
// Writing

void CSettings::WriteBool(const CString& strName, const BOOL& bValue)
{
	WriteLong(strName, (long)bValue);	
}

void CSettings::WriteLong(const CString& strName, const LONG& lValue)
{
	COleVariant vt(lValue);
	WriteVariant(strName, vt);
}

void CSettings::WriteDouble(const CString& strName, const double& dValue)
{
	COleVariant vt(dValue);
	WriteVariant(strName, vt);
}

void CSettings::WriteString(const CString& strName, const CString& strValue)
{
	COleVariant vt(strValue);
	WriteVariant(strName, vt);
}

//////////////////////////////////////////////////////////////////////
// Reading

BOOL CSettings::ReadBool(const CString& strName, BOOL bDefault)
{
	COleVariant vt;
	
	// Returning default value
	if(!ReadVariant(strName, vt))
		return bDefault;

	vt.ChangeType(VT_I4);

	return (BOOL)vt.lVal;
}

LONG CSettings::ReadLong(const CString& strName, LONG lDefault)
{
	COleVariant vt;
	
	// Returning default value
	if(!ReadVariant(strName, vt))
		return lDefault;

	vt.ChangeType(VT_I4);

	return vt.lVal;
}

double CSettings::ReadDouble(const CString& strName, double dDefault)
{
	COleVariant vt;
	
	// Returning default value
	if(!ReadVariant(strName, vt))
		return dDefault;

	vt.ChangeType(VT_R8);

	return vt.dblVal;
}

CString CSettings::ReadString(const CString& strName, CString strDefault)
{
	COleVariant vt;
	
	// Returning default value
	if(!ReadVariant(strName, vt))
		return strDefault;

#ifdef _UNICODE
	vt.ChangeType(VT_LPWSTR);
#else
	vt.ChangeType(VT_LPSTR);
#endif // _UNICODE	

	return CString(*vt.pbstrVal);
}

//////////////////////////////////////////////////////////////////////
// Internal

void CSettings::WriteVariant(const CString& strName, const COleVariant& vtValue)
{
	MCSTRINGVARIANT::iterator msvi = m_mSettings.find(strName);

	if(m_mSettings.end() != msvi) // Overwriting
		msvi->second = vtValue;
	else
		m_mSettings.insert(std::make_pair(strName, vtValue));
}

BOOL CSettings::ReadVariant(const CString& strName, COleVariant& vtValue)
{
	MCSTRINGVARIANT::iterator msvi = m_mSettings.find(strName);

	if(m_mSettings.end() != msvi) // Nothing
		return FALSE;
	
	vtValue = msvi->second;
	return TRUE;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
I'll think about it later on...

Comments and Discussions