X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fda7962d029672a5f4c718a3c6b2559856f4cd95..03e7d1397ecbc051c6ee3adbc7928ffd404b57f2:/src/msw/regconf.cpp diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 07af68b3a0..1777569b88 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,31 +9,24 @@ // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#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 __WIN16__ +#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" @@ -82,9 +75,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(); @@ -95,12 +88,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(); @@ -112,7 +105,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 @@ -128,7 +121,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); @@ -148,16 +141,11 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, if ( bDoUseGlobal ) { wxLogNull nolog; - m_keyGlobalRoot.Open(); - m_keyGlobal.Open(); + m_keyGlobalRoot.Open(wxRegKey::Read); + m_keyGlobal.Open(wxRegKey::Read); } } -wxRegConfig::~wxRegConfig() -{ - // nothing to do - key will be closed in their dtors -} - // ---------------------------------------------------------------------------- // path management // ---------------------------------------------------------------------------- @@ -182,7 +170,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); } @@ -222,9 +210,9 @@ void wxRegConfig::SetPath(const wxString& 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; } @@ -245,7 +233,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++ ) @@ -337,8 +326,7 @@ void wxRegConfig::SetPath(const wxString& strPath) } *dst = _T('\0'); - - m_strPath.UngetWriteBuf(dst - start); + buf.SetLength(dst - start); } #ifdef WX_DEBUG_SET_PATH @@ -355,7 +343,8 @@ void wxRegConfig::SetPath(const wxString& strPath) size_t len = m_strPath.length(); const wxChar *src = m_strPath.c_str(); - wxChar *dst = strRegPath.GetWriteBuf(len); + wxStringBufferLength buf(strRegPath, len); + wxChar *dst = buf; const wxChar *end = src + len; for ( ; src < end; src++, dst++ ) @@ -366,7 +355,7 @@ void wxRegConfig::SetPath(const wxString& strPath) *dst = *src; } - strRegPath.UngetWriteBuf(len); + buf.SetLength(len); } // this is not needed any longer as we don't create keys unnecessarily any @@ -385,13 +374,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(wxRegKey::Read); + } } // ---------------------------------------------------------------------------- @@ -423,7 +413,7 @@ bool wxRegConfig::GetNextGroup(wxString& str, long& lIndex) const while ( m_keyGlobal.GetNextKey(str, lIndex) ) { if ( !m_keyLocal.Exists() || !LocalKey().HasSubKey(str) ) { // ok, found one - return it - return TRUE; + return true; } } @@ -433,7 +423,7 @@ bool wxRegConfig::GetNextGroup(wxString& str, long& lIndex) const // 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) @@ -458,7 +448,7 @@ bool wxRegConfig::GetNextEntry(wxString& str, long& lIndex) const while ( m_keyGlobal.GetNextValue(str, lIndex) ) { if ( !m_keyLocal.Exists() || !LocalKey().HasValue(str) ) { // ok, found one - return it - return TRUE; + return true; } } @@ -468,7 +458,7 @@ bool wxRegConfig::GetNextEntry(wxString& str, long& lIndex) const // 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) @@ -560,11 +550,11 @@ 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, _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 @@ -575,21 +565,21 @@ bool wxRegConfig::DoReadString(const wxString& key, wxString *pStr) const 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(), @@ -597,11 +587,11 @@ 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, _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 @@ -612,21 +602,21 @@ bool wxRegConfig::DoReadLong(const wxString& key, long *plResult) const 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::DoWriteString(const wxString& key, const wxString& szValue) @@ -635,7 +625,7 @@ 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); @@ -647,7 +637,7 @@ bool wxRegConfig::DoWriteLong(const wxString& key, long lValue) 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); @@ -661,11 +651,11 @@ bool wxRegConfig::RenameEntry(const wxString& oldName, const wxString& newName) { // 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); } @@ -674,11 +664,11 @@ bool wxRegConfig::RenameGroup(const wxString& oldName, const wxString& 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); } @@ -686,29 +676,41 @@ bool wxRegConfig::RenameGroup(const wxString& oldName, const wxString& newName) // ---------------------------------------------------------------------------- // deleting // ---------------------------------------------------------------------------- -bool wxRegConfig::DeleteEntry(const wxString& value, bool WXUNUSED(bGroupIfEmptyAlso)) + +bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso) { wxConfigPathChanger path(this, value); if ( m_keyLocal.Exists() ) { if ( !m_keyLocal.DeleteValue(path.Name()) ) - return FALSE; + return false; - if ( m_keyLocal.IsEmpty() ) { + if ( bGroupIfEmptyAlso && m_keyLocal.IsEmpty() ) { wxString strKey = GetPath().AfterLast(wxCONFIG_PATH_SEPARATOR); SetPath(_T("..")); // changes m_keyLocal return LocalKey().DeleteKey(strKey); } } - return TRUE; + return true; } bool wxRegConfig::DeleteGroup(const wxString& key) { wxConfigPathChanger path(this, 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() @@ -726,8 +728,4 @@ bool wxRegConfig::DeleteAll() return bOk; } -#endif - // __WIN16__ - -#endif - // wxUSE_CONFIG +#endif // wxUSE_CONFIG