X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/42841dfcaddc6045ffc618acbb620b1fde1bc618..ba75967c9c0656ec0bcc342878cd9cdd27857ea9:/src/msw/regconf.cpp diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 13f59406cd..27c1e7e82b 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: msw/regconf.cpp +// Name: src/msw/regconf.cpp // Purpose: // Author: Vadim Zeitlin // Modified by: @@ -9,30 +9,25 @@ // 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 +#if wxUSE_CONFIG && wxUSE_REGKEY #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" @@ -58,6 +53,11 @@ bool TryGetValue(const wxRegKey& key, const wxString& str, long *plVal) 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 // ============================================================================ @@ -65,6 +65,7 @@ bool TryGetValue(const wxRegKey& key, const wxString& str, long *plVal) // ---------------------------------------------------------------------------- // 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 @@ -80,9 +81,9 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, // the convention is to put the programs keys under \ // (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(); @@ -93,12 +94,12 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, } // 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(); @@ -110,7 +111,7 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, } //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 @@ -126,7 +127,7 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, if ( bDoUseGlobal ) { - str = strGlobal.IsEmpty() ? strRoot : strGlobal; + str = strGlobal.empty() ? strRoot : strGlobal; m_keyGlobalRoot.ReserveMemoryForName(MEMORY_PREALLOC); m_keyGlobal.ReserveMemoryForName(MEMORY_PREALLOC); @@ -175,7 +176,7 @@ void wxRegConfig::SetPath(const wxString& strPath) // 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); } @@ -250,7 +251,7 @@ void wxRegConfig::SetPath(const wxString& strPath) // note that we don't have to check for src < end here as // *end == 0 so can't be '.' - if ( src[1] == _T('.') && src[2] == _T('.') && + if ( src[1] == wxT('.') && src[2] == wxT('.') && (src + 3 == end || src[3] == wxCONFIG_PATH_SEPARATOR) ) { if ( !totalSlashes ) @@ -285,7 +286,7 @@ void wxRegConfig::SetPath(const wxString& strPath) // we must have found a slash one way or another! wxASSERT_MSG( *dst == wxCONFIG_PATH_SEPARATOR, - _T("error in wxRegConfig::SetPath") ); + wxT("error in wxRegConfig::SetPath") ); // stay at the same position dst--; @@ -330,7 +331,7 @@ void wxRegConfig::SetPath(const wxString& strPath) dst--; } - *dst = _T('\0'); + *dst = wxT('\0'); buf.SetLength(dst - start); } @@ -355,7 +356,7 @@ void wxRegConfig::SetPath(const wxString& strPath) for ( ; src < end; src++, dst++ ) { if ( *src == wxCONFIG_PATH_SEPARATOR ) - *dst = _T('\\'); + *dst = wxT('\\'); else *dst = *src; } @@ -555,7 +556,7 @@ wxConfigBase::EntryType wxRegConfig::GetEntryType(const wxString& key) const bool wxRegConfig::DoReadString(const wxString& key, wxString *pStr) const { - wxCHECK_MSG( pStr, false, _T("wxRegConfig::Read(): NULL param") ); + wxCHECK_MSG( pStr, false, wxT("wxRegConfig::Read(): NULL param") ); wxConfigPathChanger path(this, key); @@ -592,7 +593,7 @@ bool wxRegConfig::DoReadString(const wxString& key, wxString *pStr) const bool wxRegConfig::DoReadLong(const wxString& key, long *plResult) const { - wxCHECK_MSG( plResult, false, _T("wxRegConfig::Read(): NULL param") ); + wxCHECK_MSG( plResult, false, wxT("wxRegConfig::Read(): NULL param") ); wxConfigPathChanger path(this, key); @@ -624,6 +625,40 @@ bool wxRegConfig::DoReadLong(const wxString& key, long *plResult) const return false; } +bool wxRegConfig::DoReadBinary(const wxString& key, wxMemoryBuffer *buf) const +{ + wxCHECK_MSG( buf, false, wxT("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) { wxConfigPathChanger path(this, key); @@ -648,6 +683,18 @@ bool wxRegConfig::DoWriteLong(const wxString& key, long lValue) 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 // ---------------------------------------------------------------------------- @@ -692,7 +739,7 @@ bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso) if ( bGroupIfEmptyAlso && m_keyLocal.IsEmpty() ) { wxString strKey = GetPath().AfterLast(wxCONFIG_PATH_SEPARATOR); - SetPath(_T("..")); // changes m_keyLocal + SetPath(wxT("..")); // changes m_keyLocal return LocalKey().DeleteKey(strKey); } } @@ -702,9 +749,20 @@ bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso) 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() @@ -722,5 +780,4 @@ bool wxRegConfig::DeleteAll() return bOk; } -#endif - // wxUSE_CONFIG +#endif // wxUSE_CONFIG && wxUSE_REGKEY