X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/eaac8805cd0fc233aeb0fc40a31bf8d8e03bf59c..010024e17ee1c35dfb265c1b054ae88dbf7e1656:/src/msw/regconf.cpp diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 2fa8685006..af4dc5ab68 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -6,10 +6,10 @@ // Created: 27.04.98 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin -// Licence: wxWindows license +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "regconf.h" #endif @@ -43,7 +43,7 @@ // ---------------------------------------------------------------------------- // we put our data in HKLM\SOFTWARE_KEY\appname -#define SOFTWARE_KEY wxString("Software\\") +#define SOFTWARE_KEY wxString(wxT("Software\\")) // ---------------------------------------------------------------------------- // global functions @@ -124,7 +124,7 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, m_keyLocal.ReserveMemoryForName(MEMORY_PREALLOC); m_keyLocalRoot.SetName(wxRegKey::HKCU, SOFTWARE_KEY + str); - m_keyLocal.SetName(m_keyLocalRoot, _T("")); + m_keyLocal.SetName(m_keyLocalRoot, wxEmptyString); if ( bDoUseGlobal ) { @@ -134,7 +134,7 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, m_keyGlobal.ReserveMemoryForName(MEMORY_PREALLOC); m_keyGlobalRoot.SetName(wxRegKey::HKLM, SOFTWARE_KEY + str); - m_keyGlobal.SetName(m_keyGlobalRoot, _T("")); + m_keyGlobal.SetName(m_keyGlobalRoot, wxEmptyString); } // Create() will Open() if key already exists @@ -245,7 +245,8 @@ void wxRegConfig::SetPath(const wxString& strPath) size_t len = strFullPath.length(); const wxChar *end = src + len; - wxChar *dst = m_strPath.GetWriteBuf(len); + wxStringBufferLength buf(m_strPath, len); + wxChar *dst = buf; wxChar *start = dst; for ( ; src < end; src++, dst++ ) @@ -274,6 +275,7 @@ void wxRegConfig::SetPath(const wxString& strPath) // check the boundary condition below // this is more efficient than strrchr() + dst--; while ( *dst != wxCONFIG_PATH_SEPARATOR ) { dst--; @@ -288,10 +290,13 @@ void wxRegConfig::SetPath(const wxString& strPath) posLastSlash = -1; } - // this shouldn't happen + // we must have found a slash one way or another! wxASSERT_MSG( *dst == wxCONFIG_PATH_SEPARATOR, _T("error in wxRegConfig::SetPath") ); + // stay at the same position + dst--; + // we killed one totalSlashes--; } @@ -333,8 +338,7 @@ void wxRegConfig::SetPath(const wxString& strPath) } *dst = _T('\0'); - - m_strPath.UngetWriteBuf(dst - start); + buf.SetLength(dst - start); } #ifdef WX_DEBUG_SET_PATH @@ -346,21 +350,25 @@ void wxRegConfig::SetPath(const wxString& strPath) // registry APIs want backslashes instead of slashes wxString strRegPath; - size_t len = m_strPath.length(); + if ( !m_strPath.empty() ) + { + size_t len = m_strPath.length(); - const wxChar *src = m_strPath.c_str(); - wxChar *dst = strRegPath.GetWriteBuf(len); + const wxChar *src = m_strPath.c_str(); + wxStringBufferLength buf(strRegPath, len); + wxChar *dst = buf; - const wxChar *end = src + len; - for ( ; src < end; src++, dst++ ) - { - if ( *src == wxCONFIG_PATH_SEPARATOR ) - *dst = _T('\\'); - else - *dst = *src; - } + const wxChar *end = src + len; + for ( ; src < end; src++, dst++ ) + { + if ( *src == wxCONFIG_PATH_SEPARATOR ) + *dst = _T('\\'); + else + *dst = *src; + } - strRegPath.UngetWriteBuf(len); + buf.SetLength(len); + } // this is not needed any longer as we don't create keys unnecessarily any // more (now it is done on demand, i.e. only when they're going to contain @@ -378,13 +386,14 @@ void wxRegConfig::SetPath(const wxString& strPath) // change current key(s) m_keyLocal.SetName(m_keyLocalRoot, strRegPath); - m_keyGlobal.SetName(m_keyGlobalRoot, strRegPath); - // don't create it right now, wait until it is accessed - //m_keyLocal.Create(); + if ( GetStyle() & wxCONFIG_USE_GLOBAL_FILE ) + { + m_keyGlobal.SetName(m_keyGlobalRoot, strRegPath); - wxLogNull nolog; - m_keyGlobal.Open(); + wxLogNull nolog; + m_keyGlobal.Open(); + } } // ---------------------------------------------------------------------------- @@ -551,44 +560,10 @@ wxConfigBase::EntryType wxRegConfig::GetEntryType(const wxString& key) const // reading/writing // ---------------------------------------------------------------------------- -bool wxRegConfig::Read(const wxString& key, wxString *pStr) const +bool wxRegConfig::DoReadString(const wxString& key, wxString *pStr) const { - 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.Exists() && LocalKey().HasValue(path.Name()) ) { - wxLogWarning(wxT("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; - } - } + wxCHECK_MSG( pStr, FALSE, _T("wxRegConfig::Read(): NULL param") ); - // first try local key - if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) || - (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) { - // nothing to do - - *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; @@ -613,25 +588,19 @@ bool wxRegConfig::Read(const wxString& key, wxString *pStr, // first try local key if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) || (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) { - *pStr = wxConfigBase::ExpandEnvVars(*pStr); return TRUE; } - else { - if ( IsRecordingDefaults() ) { - ((wxRegConfig*)this)->Write(key, szDefault); - } - - // default value - *pStr = szDefault; - } - - *pStr = wxConfigBase::ExpandEnvVars(*pStr); return FALSE; } -bool wxRegConfig::Read(const wxString& key, long *plResult) const +// this exactly reproduces the string version above except for ExpandEnvVars(), +// we really should avoid this code duplication somehow... + +bool wxRegConfig::DoReadLong(const wxString& key, long *plResult) const { + wxCHECK_MSG( plResult, FALSE, _T("wxRegConfig::Read(): NULL param") ); + wxConfigPathChanger path(this, key); bool bQueryGlobal = TRUE; @@ -658,10 +627,11 @@ bool wxRegConfig::Read(const wxString& key, long *plResult) const (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) { return TRUE; } + return FALSE; } -bool wxRegConfig::Write(const wxString& key, const wxString& szValue) +bool wxRegConfig::DoWriteString(const wxString& key, const wxString& szValue) { wxConfigPathChanger path(this, key); @@ -673,7 +643,7 @@ bool wxRegConfig::Write(const wxString& key, const wxString& szValue) return LocalKey().SetValue(path.Name(), szValue); } -bool wxRegConfig::Write(const wxString& key, long lValue) +bool wxRegConfig::DoWriteLong(const wxString& key, long lValue) { wxConfigPathChanger path(this, key); @@ -728,7 +698,7 @@ bool wxRegConfig::DeleteEntry(const wxString& value, bool WXUNUSED(bGroupIfEmpty if ( m_keyLocal.IsEmpty() ) { wxString strKey = GetPath().AfterLast(wxCONFIG_PATH_SEPARATOR); - SetPath(".."); // changes m_keyLocal + SetPath(_T("..")); // changes m_keyLocal return LocalKey().DeleteKey(strKey); } }