wxConfig changes to be more logical.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@636 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1998-08-27 21:06:02 +00:00
parent 73fb82f3f3
commit 1824493628
14 changed files with 570 additions and 190 deletions

View File

@@ -50,6 +50,7 @@
#endif
#include <stdlib.h>
#include <math.h>
#include <ctype.h> // for isalnum()
// ----------------------------------------------------------------------------
@@ -67,6 +68,15 @@ bool wxConfigBase::ms_bAutoCreate = TRUE;
// wxConfigBase
// ----------------------------------------------------------------------------
// Not all args will always be used by derived classes, but
// including them all in each class ensures compatibility.
wxConfigBase::wxConfigBase(const wxString& appName, const wxString& vendorName,
const wxString& localFilename, const wxString& globalFilename, long style):
m_appName(appName), m_vendorName(vendorName), m_style(style)
{
m_bExpandEnvVars = TRUE; m_bRecordDefaults = FALSE;
}
wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig)
{
wxConfigBase *pOld = ms_pConfig;
@@ -80,8 +90,7 @@ wxConfigBase *wxConfigBase::Create()
ms_pConfig =
#if defined(__WXMSW__) && defined(wxCONFIG_WIN32_NATIVE)
#ifdef __WIN32__
new wxRegConfig(wxTheApp->GetVendorName() + '\\'
+ wxTheApp->GetAppName());
new wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
#else //WIN16
new wxIniConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
#endif
@@ -93,21 +102,101 @@ wxConfigBase *wxConfigBase::Create()
return ms_pConfig;
}
const char *wxConfigBase::Read(const char *szKey, const char *szDefault) const
wxString wxConfigBase::Read(const wxString& key, const wxString& defVal) const
{
static char s_szBuf[1024];
wxString s;
Read(&s, szKey, szDefault);
strncpy(s_szBuf, s, WXSIZEOF(s_szBuf));
return s_szBuf;
Read(key, &s, defVal);
return s;
}
bool wxConfigBase::Read(const wxString& key, wxString *str, const wxString& defVal) const
{
if (!Read(key, str))
{
*str = ExpandEnvVars(defVal);
return FALSE;
}
else
return TRUE;
}
bool wxConfigBase::Read(const wxString& key, long *pl, long defVal) const
{
if (!Read(key, pl))
{
*pl = defVal;
return FALSE;
}
else
return TRUE;
}
bool wxConfigBase::Read(const wxString& key, double* val) const
{
wxString str;
if (Read(key, str))
{
*val = atof(str);
return TRUE;
}
else
return FALSE;
}
bool wxConfigBase::Read(const wxString& key, double* val, double defVal) const
{
if (!Read(key, val))
{
*val = defVal;
return FALSE;
}
else
return TRUE;
}
bool wxConfigBase::Read(const wxString& key, bool* val) const
{
long l;
if (Read(key, & l))
{
*val = (l != 0);
return TRUE;
}
else
return FALSE;
}
bool wxConfigBase::Read(const wxString& key, bool* val, bool defVal) const
{
if (!Read(key, val))
{
*val = defVal;
return FALSE;
}
else
return TRUE;
}
// Convenience functions
bool wxConfigBase::Write(const wxString& key, double val)
{
wxString str;
str.Printf("%f", val);
return Write(key, str);
}
bool wxConfigBase::Write(const wxString& key, bool value)
{
long l = (value ? 1 : 0);
return Write(key, l);
}
// ----------------------------------------------------------------------------
// Config::PathChanger
// wxConfigPathChanger
// ----------------------------------------------------------------------------
wxConfigBase::PathChanger::PathChanger(const wxConfigBase *pContainer,
wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer,
const wxString& strEntry)
{
m_pContainer = (wxConfigBase *)pContainer;
@@ -132,7 +221,7 @@ wxConfigBase::PathChanger::PathChanger(const wxConfigBase *pContainer,
}
}
wxConfigBase::PathChanger::~PathChanger()
wxConfigPathChanger::~wxConfigPathChanger()
{
// only restore path if it was changed
if ( m_bChanged ) {
@@ -293,3 +382,4 @@ void wxSplitPath(wxArrayString& aParts, const char *sz)
}
}

View File

@@ -32,6 +32,7 @@
#include <wx/intl.h>
#endif //WX_PRECOMP
#include <wx/app.h>
#include <wx/dynarray.h>
#include <wx/file.h>
#include <wx/log.h>
@@ -207,6 +208,7 @@ void wxFileConfig::Init()
}
}
#if 0
wxFileConfig::wxFileConfig(const char *szAppName, bool bLocalOnly)
{
wxASSERT( !IsEmpty(szAppName) ); // invent a name for your application!
@@ -237,6 +239,55 @@ wxFileConfig::wxFileConfig(const wxString& strLocal, const wxString& strGlobal)
Init();
}
#endif
// New-style constructor
wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName,
const wxString& strLocal, const wxString& strGlobal, long style)
: wxConfigBase(appName, vendorName, strLocal, strGlobal, style),
m_strLocalFile(strLocal), m_strGlobalFile(strGlobal)
{
// Make up an application name if not supplied
if (appName.IsEmpty() && wxTheApp)
{
SetAppName(wxTheApp->GetAppName());
}
// Make up names for files if empty
if (m_strLocalFile.IsEmpty() && (style & wxCONFIG_USE_LOCAL_FILE) && wxTheApp)
{
m_strLocalFile = wxTheApp->GetAppName();
}
if (m_strGlobalFile.IsEmpty() && (style & wxCONFIG_USE_GLOBAL_FILE))
{
// TODO: What should the default global filename be?
m_strGlobalFile = "global";
}
// Check if styles are not supplied, but filenames are, in which case
// add the correct styles.
if (!m_strLocalFile.IsEmpty() && ((style & wxCONFIG_USE_LOCAL_FILE) != wxCONFIG_USE_LOCAL_FILE))
SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE);
if (!m_strGlobalFile.IsEmpty() && ((style & wxCONFIG_USE_GLOBAL_FILE) != wxCONFIG_USE_GLOBAL_FILE))
SetStyle(GetStyle() | wxCONFIG_USE_GLOBAL_FILE);
// if the path is not absolute, prepend the standard directory to it
if ( !strLocal.IsEmpty() && !wxIsAbsolutePath(strLocal) )
{
m_strLocalFile = GetLocalDir();
m_strLocalFile << strLocal;
}
if ( !strGlobal.IsEmpty() && !wxIsAbsolutePath(strGlobal) )
{
m_strGlobalFile = GetGlobalDir();
m_strGlobalFile << strGlobal;
}
Init();
}
void wxFileConfig::CleanUp()
{
@@ -509,7 +560,7 @@ size_t wxFileConfig::GetNumberOfGroups(bool bRecursive) const
bool wxFileConfig::HasGroup(const wxString& strName) const
{
PathChanger path(this, strName);
wxConfigPathChanger path(this, strName);
ConfigGroup *pGroup = m_pCurrentGroup->FindSubgroup(path.Name());
return pGroup != NULL;
@@ -517,7 +568,7 @@ bool wxFileConfig::HasGroup(const wxString& strName) const
bool wxFileConfig::HasEntry(const wxString& strName) const
{
PathChanger path(this, strName);
wxConfigPathChanger path(this, strName);
ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
return pEntry != NULL;
@@ -527,50 +578,54 @@ bool wxFileConfig::HasEntry(const wxString& strName) const
// read/write values
// ----------------------------------------------------------------------------
bool wxFileConfig::Read(wxString *pstr,
const char *szKey,
const char *szDefault) const
bool wxFileConfig::Read(const wxString& key,
wxString* pStr) const
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, key);
ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
if (pEntry == NULL) {
return FALSE;
}
else {
*pStr = ExpandEnvVars(pEntry->Value());
return TRUE;
}
}
bool wxFileConfig::Read(const wxString& key,
wxString* pStr, const wxString& defVal) const
{
wxConfigPathChanger path(this, key);
ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
if (pEntry == NULL) {
if( IsRecordingDefaults() )
((wxFileConfig *)this)->Write(szKey,szDefault);
*pstr = ExpandEnvVars(szDefault);
((wxFileConfig *)this)->Write(key,defVal);
*pStr = ExpandEnvVars(defVal);
return FALSE;
}
else {
*pstr = ExpandEnvVars(pEntry->Value());
*pStr = ExpandEnvVars(pEntry->Value());
return TRUE;
}
}
const char *wxFileConfig::Read(const char *szKey,
const char *szDefault) const
{
static wxString s_str;
Read(&s_str, szKey, szDefault);
return s_str.c_str();
}
bool wxFileConfig::Read(long *pl, const char *szKey, long lDefault) const
bool wxFileConfig::Read(const wxString& key, long *pl) const
{
wxString str;
if ( Read(&str, szKey) ) {
if ( Read(key, & str) ) {
*pl = atol(str);
return TRUE;
}
else {
*pl = lDefault;
return FALSE;
}
}
bool wxFileConfig::Write(const char *szKey, const char *szValue)
bool wxFileConfig::Write(const wxString& key, const wxString& szValue)
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, key);
wxString strName = path.Name();
if ( strName.IsEmpty() ) {
@@ -611,12 +666,12 @@ bool wxFileConfig::Write(const char *szKey, const char *szValue)
return TRUE;
}
bool wxFileConfig::Write(const char *szKey, long lValue)
bool wxFileConfig::Write(const wxString& key, long lValue)
{
// ltoa() is not ANSI :-(
char szBuf[40]; // should be good for sizeof(long) <= 16 (128 bits)
sprintf(szBuf, "%ld", lValue);
return Write(szKey, szBuf);
return Write(key, szBuf);
}
bool wxFileConfig::Flush(bool /* bCurrentOnly */)
@@ -646,9 +701,9 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
// delete groups/entries
// ----------------------------------------------------------------------------
bool wxFileConfig::DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso)
bool wxFileConfig::DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso)
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, key);
if ( !m_pCurrentGroup->DeleteEntry(path.Name()) )
return FALSE;
@@ -665,9 +720,9 @@ bool wxFileConfig::DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso)
return TRUE;
}
bool wxFileConfig::DeleteGroup(const char *szKey)
bool wxFileConfig::DeleteGroup(const wxString& key)
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, key);
return m_pCurrentGroup->DeleteSubgroupByName(path.Name());
}

View File

@@ -25,6 +25,7 @@
#ifndef WX_PRECOMP
#include <wx/string.h>
#include <wx/intl.h>
#include <wx/app.h>
#endif //WX_PRECOMP
#include <wx/dynarray.h>
@@ -54,21 +55,47 @@
// ctor & dtor
// ----------------------------------------------------------------------------
wxIniConfig::wxIniConfig(const wxString& strAppName, const wxString& strVendor)
: m_strAppName(strAppName), m_strVendor(strVendor)
wxIniConfig::wxIniConfig(const wxString& strAppName, const wxString& strVendor,
const wxString& localFilename, const wxString& globalFilename, long style):
wxConfigBase(strAppName, strVendor, localFilename, globalFilename, style)
{
if ( strVendor.IsEmpty() )
m_strVendor = strAppName;
if ( GetAppName().IsEmpty() )
{
wxString app;
if (wxTheApp)
app = wxTheApp->GetAppName();
wxASSERT( !app.IsEmpty() );
SetAppName(app);
}
// append the extension if none given and it's not an absolute file name
// (otherwise we assume that they know what they're doing)
if ( !wxIsPathSeparator(m_strAppName[0u]) &&
m_strAppName.Find('.') == NOT_FOUND ) {
m_strAppName << ".ini";
}
// Vendor name is required in wxIniConfig.
// TODO: should it be required? Why isn't appName used instead? -- JACS
if ( GetVendorName().IsEmpty() )
{
wxString vendor;
if (wxTheApp)
vendor = wxTheApp->GetVendorName();
else
vendor = strAppName;
SetVendorName(vendor);
}
// set root path
SetPath("");
m_strLocalFilename = localFilename;
if (m_strLocalFilename.IsEmpty())
{
m_strLocalFilename = GetAppName() + ".ini";
}
// append the extension if none given and it's not an absolute file name
// (otherwise we assume that they know what they're doing)
if ( !wxIsPathSeparator(m_strLocalFilename[0u]) &&
m_strLocalFilename.Find('.') == NOT_FOUND )
{
m_strLocalFilename << ".ini";
}
// set root path
SetPath("");
}
wxIniConfig::~wxIniConfig()
@@ -142,7 +169,7 @@ const wxString& wxIniConfig::GetPath() const
return s_str;
}
wxString wxIniConfig::GetPrivateKeyName(const char *szKey) const
wxString wxIniConfig::GetPrivateKeyName(const wxString& szKey) const
{
wxString strKey;
@@ -154,7 +181,7 @@ wxString wxIniConfig::GetPrivateKeyName(const char *szKey) const
return strKey;
}
wxString wxIniConfig::GetKeyName(const char *szKey) const
wxString wxIniConfig::GetKeyName(const wxString& szKey) const
{
wxString strKey;
@@ -240,7 +267,7 @@ bool wxIniConfig::IsEmpty() const
char szBuf[1024];
GetPrivateProfileString(m_strGroup, NULL, "",
szBuf, WXSIZEOF(szBuf), m_strAppName);
szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
if ( !::IsEmpty(szBuf) )
return FALSE;
@@ -255,11 +282,9 @@ bool wxIniConfig::IsEmpty() const
// read/write
// ----------------------------------------------------------------------------
bool wxIniConfig::Read(wxString *pstr,
const char *szKey,
const char *szDefault) const
bool wxIniConfig::Read(const wxString& szKey, wxString *pstr) const
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, szKey);
wxString strKey = GetPrivateKeyName(path.Name());
char szBuf[1024]; // @@ should dynamically allocate memory...
@@ -268,7 +293,34 @@ bool wxIniConfig::Read(wxString *pstr,
// NB: the lpDefault param to GetPrivateProfileString can't be NULL
GetPrivateProfileString(m_strGroup, strKey, "",
szBuf, WXSIZEOF(szBuf), m_strAppName);
szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
if ( ::IsEmpty(szBuf) ) {
// now look in win.ini
wxString strKey = GetKeyName(path.Name());
GetProfileString(m_strGroup, strKey, "", szBuf, WXSIZEOF(szBuf));
}
if ( ::IsEmpty(szBuf) ) {
return FALSE;
}
else {
return TRUE;
}
}
bool wxIniConfig::Read(const wxString& szKey, wxString *pstr,
const wxString& szDefault) const
{
wxConfigPathChanger path(this, szKey);
wxString strKey = GetPrivateKeyName(path.Name());
char szBuf[1024]; // @@ should dynamically allocate memory...
// first look in the private INI file
// NB: the lpDefault param to GetPrivateProfileString can't be NULL
GetPrivateProfileString(m_strGroup, strKey, "",
szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
if ( ::IsEmpty(szBuf) ) {
// now look in win.ini
wxString strKey = GetKeyName(path.Name());
@@ -284,18 +336,9 @@ bool wxIniConfig::Read(wxString *pstr,
}
}
const char *wxIniConfig::Read(const char *szKey,
const char *szDefault) const
bool wxIniConfig::Read(const wxString& szKey, long *pl) const
{
static wxString s_str;
Read(&s_str, szKey, szDefault);
return s_str.c_str();
}
bool wxIniConfig::Read(long *pl, const char *szKey, long lDefault) const
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, szKey);
wxString strKey = GetPrivateKeyName(path.Name());
// hack: we have no mean to know if it really found the default value or
@@ -303,7 +346,7 @@ bool wxIniConfig::Read(long *pl, const char *szKey, long lDefault) const
static const int nMagic = 17; // 17 is some "rare" number
static const int nMagic2 = 28; // arbitrary number != nMagic
long lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic, m_strAppName);
long lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic, m_strLocalFilename);
if ( lVal != nMagic ) {
// the value was read from the file
*pl = lVal;
@@ -311,7 +354,7 @@ bool wxIniConfig::Read(long *pl, const char *szKey, long lDefault) const
}
// is it really nMagic?
lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic2, m_strAppName);
lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic2, m_strLocalFilename);
if ( lVal == nMagic ) {
// the nMagic it returned was indeed read from the file
*pl = lVal;
@@ -319,28 +362,18 @@ bool wxIniConfig::Read(long *pl, const char *szKey, long lDefault) const
}
// no, it was just returning the default value, so now look in win.ini
*pl = GetProfileInt(m_strVendor, GetKeyName(szKey), lDefault);
*pl = GetProfileInt(GetVendorName(), GetKeyName(szKey), *pl);
// we're not going to check here whether it read the default or not: it's
// not that important
return TRUE;
}
long wxIniConfig::Read(const char *szKey, long lDefault) const
bool wxIniConfig::Write(const wxString& szKey, const wxString& szValue)
{
long lVal;
Read(&lVal, szKey, lDefault);
return lVal;
}
bool wxIniConfig::Write(const char *szKey, const char *szValue)
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, szKey);
wxString strKey = GetPrivateKeyName(path.Name());
bool bOk = WritePrivateProfileString(m_strGroup, strKey,
szValue, m_strAppName) != 0;
szValue, m_strLocalFilename) != 0;
if ( !bOk )
wxLogLastError("WritePrivateProfileString");
@@ -348,7 +381,7 @@ bool wxIniConfig::Write(const char *szKey, const char *szValue)
return bOk;
}
bool wxIniConfig::Write(const char *szKey, long lValue)
bool wxIniConfig::Write(const wxString& szKey, long lValue)
{
// ltoa() is not ANSI :-(
char szBuf[40]; // should be good for sizeof(long) <= 16 (128 bits)
@@ -360,7 +393,7 @@ bool wxIniConfig::Write(const char *szKey, long lValue)
bool wxIniConfig::Flush(bool /* bCurrentOnly */)
{
// this is just the way it works
return WritePrivateProfileString(NULL, NULL, NULL, m_strAppName) != 0;
return WritePrivateProfileString(NULL, NULL, NULL, m_strLocalFilename) != 0;
}
// ----------------------------------------------------------------------------
@@ -378,7 +411,7 @@ bool wxIniConfig::DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso)
// delete the current group too
bool bOk = WritePrivateProfileString(m_strGroup, NULL,
NULL, m_strAppName) != 0;
NULL, m_strLocalFilename) != 0;
if ( !bOk )
wxLogLastError("WritePrivateProfileString");
@@ -388,12 +421,12 @@ bool wxIniConfig::DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso)
bool wxIniConfig::DeleteGroup(const char *szKey)
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, szKey);
// passing NULL as section name to WritePrivateProfileString deletes the
// whole section according to the docs
bool bOk = WritePrivateProfileString(path.Name(), NULL,
NULL, m_strAppName) != 0;
NULL, m_strLocalFilename) != 0;
if ( !bOk )
wxLogLastError("WritePrivateProfileString");
@@ -404,7 +437,7 @@ bool wxIniConfig::DeleteGroup(const char *szKey)
bool wxIniConfig::DeleteAll()
{
// first delete our group in win.ini
WriteProfileString(m_strVendor, NULL, NULL);
WriteProfileString(GetVendorName(), NULL, NULL);
// then delete our own ini file
char szBuf[MAX_PATH];
@@ -415,7 +448,7 @@ bool wxIniConfig::DeleteAll()
wxFAIL_MSG("buffer is too small for Windows directory.");
wxString strFile = szBuf;
strFile << '\\' << m_strAppName;
strFile << '\\' << m_strLocalFilename;
if ( !DeleteFile(strFile) ) {
wxLogSysError(_("Can't delete the INI file '%s'"), strFile.c_str());

View File

@@ -158,6 +158,7 @@ MSWOBJS = \
$(MSWDIR)\helpwin.obj \
$(MSWDIR)\icon.obj \
$(MSWDIR)\imaglist.obj \
$(MSWDIR)\iniconf.obj \
$(MSWDIR)\joystick.obj \
$(MSWDIR)\listbox.obj \
$(MSWDIR)\listctrl.obj \
@@ -787,6 +788,11 @@ $(COMMDIR)/gdicmn.obj: $*.$(SRCSUFF)
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
<<
$(COMMDIR)/iniconf.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
<<
$(COMMDIR)/intl.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@

View File

@@ -35,6 +35,7 @@
#include <wx/string.h>
#endif //WX_PRECOMP
#include <wx/app.h>
#include <wx/log.h>
#include <wx/config.h>
#include <wx/msw/registry.h>
@@ -69,6 +70,8 @@ bool TryGetValue(const wxRegKey& key, const wxString& str, long *plVal)
// ----------------------------------------------------------------------------
// ctor/dtor
// ----------------------------------------------------------------------------
#if 0
wxRegConfig::wxRegConfig(const wxString& strRoot)
: m_keyLocalRoot(wxRegKey::HKCU, SOFTWARE_KEY + strRoot),
m_keyLocal(m_keyLocalRoot, ""),
@@ -84,6 +87,57 @@ wxRegConfig::wxRegConfig(const wxString& strRoot)
wxLogNull nolog;
m_keyGlobalRoot.Open();
}
#endif
// TODO: vendor name is ignored, because we can't yet do the test for optional vendor
// name in the constructor body. We need a wxRegKey::Set that takes the same
// args as the constructor. Then we'll set m_keyLocalRoot etc. in the constructor body.
wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName,
const wxString& strLocal, const wxString& strGlobal, long style)
: wxConfigBase(appName, vendorName, strLocal, strGlobal, style),
m_keyLocalRoot(wxRegKey::HKCU, SOFTWARE_KEY + appName),
m_keyLocal(m_keyLocalRoot, ""),
m_keyGlobalRoot(wxRegKey::HKLM, SOFTWARE_KEY + appName),
m_keyGlobal(m_keyGlobalRoot, "")
{
// TODO: really, we should check and supply an app name if one isn't supplied.
// Unfortunately I don't know how to initialise the member wxRegKey
// variables from within the constructor body. -- JACS
// Vadim - we just need an implementation of wxRegKey::Set,
// and then we can uncomment this and remove the constructor lines above.
/*
wxString strRoot(appName);
if (appName.IsEmpty() && wxTheApp)
{
strRoot = wxTheApp->GetAppName();
}
wxASSERT( !strRoot.IsEmpty() );
if (!vendorName.IsEmpty())
{
strRoot += "\\";
strRoot += vendorName;
}
m_keyLocalRoot.Set(wxRegKey::HKCU, SOFTWARE_KEY + strRoot),
m_keyLocal.Set(m_keyLocalRoot, ""),
m_keyGlobalRoot.Set(wxRegKey::HKLM, SOFTWARE_KEY + strRoot),
m_keyGlobal.Set(m_keyGlobalRoot, "")
*/
// Create() will Open() if key already exists
m_keyLocalRoot.Create();
// as it's the same key, Open() shouldn't fail (i.e. no need for Create())
m_keyLocal.Open();
wxLogNull nolog;
m_keyGlobalRoot.Open();
}
wxRegConfig::~wxRegConfig()
{
@@ -252,11 +306,47 @@ bool wxRegConfig::HasEntry(const wxString& strName) const
// reading/writing
// ----------------------------------------------------------------------------
bool wxRegConfig::Read(wxString *pStr,
const char *szKey,
const char *szDefault) const
bool wxRegConfig::Read(const wxString& key, wxString *pStr) const
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, key);
bool bQueryGlobal = TRUE;
// if immutable key exists in global key we must check that it's not
// overriden by the local key with the same name
if ( IsImmutable(path.Name()) ) {
if ( TryGetValue(m_keyGlobal, path.Name(), *pStr) ) {
if ( m_keyLocal.HasValue(path.Name()) ) {
wxLogWarning("User value for immutable key '%s' ignored.",
path.Name().c_str());
}
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
return TRUE;
}
else {
// don't waste time - it's not there anyhow
bQueryGlobal = FALSE;
}
}
// first try local key
if ( TryGetValue(m_keyLocal, path.Name(), *pStr) ||
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
// nothing to do
// TODO: do we return TRUE? Not in original implementation,
// but I don't see why not. -- JACS
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
return TRUE;
}
return FALSE;
}
bool wxRegConfig::Read(const wxString& key, wxString *pStr,
const wxString& szDefault) const
{
wxConfigPathChanger path(this, key);
bool bQueryGlobal = TRUE;
@@ -280,11 +370,12 @@ bool wxRegConfig::Read(wxString *pStr,
// first try local key
if ( TryGetValue(m_keyLocal, path.Name(), *pStr) ||
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
// nothing to do
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
return TRUE;
}
else {
if ( IsRecordingDefaults() ) {
((wxRegConfig*)this)->Write(szKey, szDefault);
((wxRegConfig*)this)->Write(key, szDefault);
}
// default value
@@ -296,9 +387,9 @@ bool wxRegConfig::Read(wxString *pStr,
return FALSE;
}
bool wxRegConfig::Read(long *plResult, const char *szKey, long lDefault) const
bool wxRegConfig::Read(const wxString& key, long *plResult) const
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, key);
bool bQueryGlobal = TRUE;
@@ -324,15 +415,12 @@ bool wxRegConfig::Read(long *plResult, const char *szKey, long lDefault) const
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) {
return TRUE;
}
// default
*plResult = lDefault;
return FALSE;
}
bool wxRegConfig::Write(const char *szKey, const char *szValue)
bool wxRegConfig::Write(const wxString& key, const wxString& szValue)
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, key);
if ( IsImmutable(path.Name()) ) {
wxLogError("Can't change immutable entry '%s'.", path.Name().c_str());
@@ -342,9 +430,9 @@ bool wxRegConfig::Write(const char *szKey, const char *szValue)
return m_keyLocal.SetValue(path.Name(), szValue);
}
bool wxRegConfig::Write(const char *szKey, long lValue)
bool wxRegConfig::Write(const wxString& key, long lValue)
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, key);
if ( IsImmutable(path.Name()) ) {
wxLogError("Can't change immutable entry '%s'.", path.Name().c_str());
@@ -357,9 +445,9 @@ bool wxRegConfig::Write(const char *szKey, long lValue)
// ----------------------------------------------------------------------------
// deleting
// ----------------------------------------------------------------------------
bool wxRegConfig::DeleteEntry(const char *szValue, bool bGroupIfEmptyAlso)
bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso)
{
PathChanger path(this, szValue);
wxConfigPathChanger path(this, value);
if ( !m_keyLocal.DeleteValue(path.Name()) )
return FALSE;
@@ -373,9 +461,9 @@ bool wxRegConfig::DeleteEntry(const char *szValue, bool bGroupIfEmptyAlso)
return TRUE;
}
bool wxRegConfig::DeleteGroup(const char *szKey)
bool wxRegConfig::DeleteGroup(const wxString& key)
{
PathChanger path(this, szKey);
wxConfigPathChanger path(this, key);
return m_keyLocal.DeleteKey(path.Name());
}