///////////////////////////////////////////////////////////////////////////////
-// Name: msw/regconf.cpp
+// Name: src/msw/regconf.cpp
// Purpose:
// Author: Vadim Zeitlin
// Modified by:
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "regconf.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
-#ifndef WX_PRECOMP
- #include "wx/string.h"
- #include "wx/intl.h"
-#endif //WX_PRECOMP
-
-#include "wx/event.h"
-#include "wx/app.h"
-#include "wx/log.h"
-
#if wxUSE_CONFIG
#include "wx/config.h"
+#ifndef WX_PRECOMP
+ #include "wx/string.h"
+ #include "wx/intl.h"
+ #include "wx/log.h"
+ #include "wx/event.h"
+ #include "wx/app.h"
+#endif //WX_PRECOMP
+
#include "wx/msw/registry.h"
#include "wx/msw/regconf.h"
return key.IsOpened() && key.HasValue(str) && key.QueryValue(str, plVal);
}
+bool TryGetValue(const wxRegKey& key, const wxString& str, wxMemoryBuffer &plVal)
+{
+ return key.IsOpened() && key.HasValue(str) && key.QueryValue(str, plVal);
+}
+
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// ctor/dtor
// ----------------------------------------------------------------------------
+IMPLEMENT_ABSTRACT_CLASS(wxRegConfig, wxConfigBase)
// create the config object which stores its data under HKCU\vendor\app and, if
// style & wxCONFIG_USE_GLOBAL_FILE, under HKLM\vendor\app
// the convention is to put the programs keys under <vendor>\<appname>
// (but it can be overriden by specifying the pathes explicitly in strLocal
// and/or strGlobal)
- if ( strLocal.IsEmpty() || (strGlobal.IsEmpty() && bDoUseGlobal) )
+ if ( strLocal.empty() || (strGlobal.empty() && bDoUseGlobal) )
{
- if ( vendorName.IsEmpty() )
+ if ( vendorName.empty() )
{
if ( wxTheApp )
strRoot = wxTheApp->GetVendorName();
}
// no '\\' needed if no vendor name
- if ( !strRoot.IsEmpty() )
+ if ( !strRoot.empty() )
{
strRoot += '\\';
}
- if ( appName.IsEmpty() )
+ if ( appName.empty() )
{
wxCHECK_RET( wxTheApp, wxT("No application name in wxRegConfig ctor!") );
strRoot << wxTheApp->GetAppName();
}
//else: we don't need to do all the complicated stuff above
- wxString str = strLocal.IsEmpty() ? strRoot : strLocal;
+ wxString str = strLocal.empty() ? strRoot : strLocal;
// as we're going to change the name of these keys fairly often and as
// there are only few of wxRegConfig objects (usually 1), we can allow
if ( bDoUseGlobal )
{
- str = strGlobal.IsEmpty() ? strRoot : strGlobal;
+ str = strGlobal.empty() ? strRoot : strGlobal;
m_keyGlobalRoot.ReserveMemoryForName(MEMORY_PREALLOC);
m_keyGlobal.ReserveMemoryForName(MEMORY_PREALLOC);
}
}
-wxRegConfig::~wxRegConfig()
-{
- // nothing to do - key will be closed in their dtors
-}
-
// ----------------------------------------------------------------------------
// path management
// ----------------------------------------------------------------------------
// because GetPath() returns "" when we're at root, we must understand
// empty string as "/"
- if ( strPath.IsEmpty() || (strPath[0] == wxCONFIG_PATH_SEPARATOR) ) {
+ if ( strPath.empty() || (strPath[0] == wxCONFIG_PATH_SEPARATOR) ) {
// absolute path
wxSplitPath(aParts, strPath);
}
strFullPath.reserve(2*m_strPath.length());
strFullPath << m_strPath;
- if ( strFullPath.Len() == 0 ||
+ if ( strFullPath.Len() == 0 ||
strFullPath.Last() != wxCONFIG_PATH_SEPARATOR )
- strFullPath << wxCONFIG_PATH_SEPARATOR;
+ strFullPath << wxCONFIG_PATH_SEPARATOR;
strFullPath << strPath;
}
while ( m_keyGlobal.GetNextKey(str, lIndex) ) {
if ( !m_keyLocal.Exists() || !LocalKey().HasSubKey(str) ) {
// ok, found one - return it
- return TRUE;
+ return true;
}
}
// if we don't have the key at all, don't try to enumerate anything under it
if ( !m_keyLocal.Exists() )
- return FALSE;
+ return false;
// much easier with local entries: get the next one we find
// (don't forget to clear our flag bit and set it again later)
while ( m_keyGlobal.GetNextValue(str, lIndex) ) {
if ( !m_keyLocal.Exists() || !LocalKey().HasValue(str) ) {
// ok, found one - return it
- return TRUE;
+ return true;
}
}
// if we don't have the key at all, don't try to enumerate anything under it
if ( !m_keyLocal.Exists() )
- return FALSE;
+ return false;
// much easier with local entries: get the next one we find
// (don't forget to clear our flag bit and set it again later)
bool wxRegConfig::DoReadString(const wxString& key, wxString *pStr) const
{
- wxCHECK_MSG( pStr, FALSE, _T("wxRegConfig::Read(): NULL param") );
+ wxCHECK_MSG( pStr, false, _T("wxRegConfig::Read(): NULL param") );
wxConfigPathChanger path(this, key);
- bool bQueryGlobal = TRUE;
+ 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
path.Name().c_str());
}
- return TRUE;
+ return true;
}
else {
// don't waste time - it's not there anyhow
- bQueryGlobal = FALSE;
+ bQueryGlobal = false;
}
}
// first try local key
if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) ||
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
// this exactly reproduces the string version above except for ExpandEnvVars(),
bool wxRegConfig::DoReadLong(const wxString& key, long *plResult) const
{
- wxCHECK_MSG( plResult, FALSE, _T("wxRegConfig::Read(): NULL param") );
+ wxCHECK_MSG( plResult, false, _T("wxRegConfig::Read(): NULL param") );
wxConfigPathChanger path(this, key);
- bool bQueryGlobal = TRUE;
+ 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
path.Name().c_str());
}
- return TRUE;
+ return true;
}
else {
// don't waste time - it's not there anyhow
- bQueryGlobal = FALSE;
+ bQueryGlobal = false;
}
}
// first try local key
if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), plResult)) ||
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) {
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
+}
+
+bool wxRegConfig::DoReadBinary(const wxString& key, wxMemoryBuffer *buf) const
+{
+ wxCHECK_MSG( buf, false, _T("wxRegConfig::Read(): NULL param") );
+
+ 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(), *buf) ) {
+ if ( m_keyLocal.Exists() && LocalKey().HasValue(path.Name()) ) {
+ wxLogWarning(wxT("User value for immutable key '%s' ignored."),
+ path.Name().c_str());
+ }
+
+ return true;
+ }
+ else {
+ // don't waste time - it's not there anyhow
+ bQueryGlobal = false;
+ }
+ }
+
+ // first try local key
+ if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *buf)) ||
+ (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *buf)) ) {
+ return true;
+ }
+
+ return false;
}
bool wxRegConfig::DoWriteString(const wxString& key, const wxString& szValue)
if ( IsImmutable(path.Name()) ) {
wxLogError(wxT("Can't change immutable entry '%s'."), path.Name().c_str());
- return FALSE;
+ return false;
}
return LocalKey().SetValue(path.Name(), szValue);
if ( IsImmutable(path.Name()) ) {
wxLogError(wxT("Can't change immutable entry '%s'."), path.Name().c_str());
- return FALSE;
+ return false;
}
return LocalKey().SetValue(path.Name(), lValue);
}
+bool wxRegConfig::DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf)
+{
+ wxConfigPathChanger path(this, key);
+
+ if ( IsImmutable(path.Name()) ) {
+ wxLogError(wxT("Can't change immutable entry '%s'."), path.Name().c_str());
+ return false;
+ }
+
+ return LocalKey().SetValue(path.Name(), buf);
+}
+
// ----------------------------------------------------------------------------
// renaming
// ----------------------------------------------------------------------------
{
// check that the old entry exists...
if ( !HasEntry(oldName) )
- return FALSE;
+ return false;
// and that the new one doesn't
if ( HasEntry(newName) )
- return FALSE;
+ return false;
return m_keyLocal.RenameValue(oldName, newName);
}
{
// check that the old group exists...
if ( !HasGroup(oldName) )
- return FALSE;
+ return false;
// and that the new one doesn't
if ( HasGroup(newName) )
- return FALSE;
+ return false;
return wxRegKey(m_keyLocal, oldName).Rename(newName);
}
if ( m_keyLocal.Exists() ) {
if ( !m_keyLocal.DeleteValue(path.Name()) )
- return FALSE;
+ return false;
if ( bGroupIfEmptyAlso && m_keyLocal.IsEmpty() ) {
wxString strKey = GetPath().AfterLast(wxCONFIG_PATH_SEPARATOR);
}
}
- return TRUE;
+ return true;
}
bool wxRegConfig::DeleteGroup(const wxString& key)
{
- wxConfigPathChanger path(this, key);
+ wxConfigPathChanger path(this, RemoveTrailingSeparator(key));
- return m_keyLocal.Exists() ? LocalKey().DeleteKey(path.Name()) : TRUE;
+ if ( !m_keyLocal.Exists() )
+ {
+ // nothing to do
+ return true;
+ }
+
+ if ( !LocalKey().DeleteKey(path.Name()) )
+ return false;
+
+ path.UpdateIfDeleted();
+
+ return true;
}
bool wxRegConfig::DeleteAll()
return bOk;
}
-#endif
- // wxUSE_CONFIG
+#endif // wxUSE_CONFIG