|
#include "stdafx.h"
#include "Profile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
namespace SbjCore
{
namespace Sys
{
struct SetSharedProfileStateImpl
{
CWinApp* pApp;
LPCTSTR lpszOldProfile;
CString sShared;
bool bSharable;
SetSharedProfileStateImpl(bool bIsSharable) :
pApp(::AfxGetApp()),
bSharable(bIsSharable),
lpszOldProfile(NULL)
{
if (pApp != NULL)
{
if (bSharable)
{
lpszOldProfile = pApp->m_pszProfileName;
CString sOldProfile(lpszOldProfile);
sShared = _T("Shared\\") + sOldProfile;
pApp->m_pszProfileName = sShared;
}
}
}
virtual ~SetSharedProfileStateImpl()
{
if (pApp != NULL)
{
if (bSharable)
{
pApp->m_pszProfileName = lpszOldProfile;
}
}
}
};
SetSharedProfileState::SetSharedProfileState(bool bIsSharable) :
m_pImpl(new SetSharedProfileStateImpl(bIsSharable))
{
}
SetSharedProfileState::~SetSharedProfileState()
{
try
{
delete m_pImpl;
}
catch (...)
{
ASSERT(FALSE);
}
}
/////////////////////////////////////////////////////////////////////////////////////
struct SetAlternateProfileImpl
{
CWinApp* pApp;
LPCTSTR lpszOldProfile;
CString sAltProfile;
SetAlternateProfileImpl(LPCTSTR lpszAltProfile) :
pApp(::AfxGetApp()),
sAltProfile(lpszAltProfile == NULL ? _T("") : lpszAltProfile),
lpszOldProfile(NULL)
{
if (!sAltProfile.IsEmpty())
{
if (pApp != NULL)
{
lpszOldProfile = pApp->m_pszProfileName;
pApp->m_pszProfileName = sAltProfile;
}
}
}
virtual ~SetAlternateProfileImpl()
{
if (!sAltProfile.IsEmpty())
{
if (pApp != NULL)
{
pApp->m_pszProfileName = lpszOldProfile;
}
}
}
};
SetAlternateProfile::SetAlternateProfile(LPCTSTR lpszAltProfile) :
m_pImpl(new SetAlternateProfileImpl(lpszAltProfile))
{
}
SetAlternateProfile::~SetAlternateProfile()
{
try
{
delete m_pImpl;
}
catch (...)
{
ASSERT(FALSE);
}
}
/////////////////////////////////////////////////////////////////////////////////////
const CString GetProfileValue(
LPCTSTR lpszSection,
LPCTSTR lpszEntry,
LPCTSTR lpszValue,
bool bCreateEntry /*= true*/,
bool bIsShareable /*= false*/)
{
CString s;
CWinApp* pApp = ::AfxGetApp();
if (pApp != NULL)
{
SetSharedProfileState theState(bIsShareable);
s = pApp->GetProfileString(lpszSection, lpszEntry, lpszValue);
if (bCreateEntry)
{
pApp->WriteProfileString(lpszSection, lpszEntry, s);
}
}
return s;
}
BOOL WriteProfileValue(
LPCTSTR lpszSection,
LPCTSTR lpszEntry,
LPCTSTR lpszValue,
bool bIsShareable /*= false*/)
{
bool bRslt = false;
CWinApp* pApp = ::AfxGetApp();
if (pApp != NULL)
{
SetSharedProfileState theState(bIsShareable);
bRslt = pApp->WriteProfileString(lpszSection, lpszEntry, lpszValue);
}
return bRslt;
}
}
}
|
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.
Real name is Steve Johnson. Programming since 1979. Started on a Heathkit Micro with a DEC LSI-11 and UCSD Pascal. Moved to PCs & DOS as soon as Turbo Pascal became available. Did some Assembly, ISR, TSR etc. All this while working for a Manufacturing Co. for 8 years. Had my own solo Co. doing barcode labeling software for 4 years (terrible business man, all I wanted to do was code). Since then working for various software companies. Moved to Windows around the time of 3.1 with Borland C then C++. Then on to VC++ and MFC, and just about anything I could get my hands on or had to learn for my job, and been at it ever since. Of course recently I've been playing with .NET, ASP, C#, WPF etc.