X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/807a903e6807ae3e49928bda488a04bc0d832149..819451b6c76bdcaf5fd8865479209859511aa986:/src/msw/regconf.cpp diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 34a60f02bd..050ef4646f 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -6,7 +6,7 @@ // Created: 27.04.98 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin -// Licence: wxWindows license +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -22,6 +22,7 @@ #ifndef WX_PRECOMP #include "wx/string.h" + #include "wx/intl.h" #endif //WX_PRECOMP #include "wx/event.h" @@ -42,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 @@ -220,7 +221,11 @@ void wxRegConfig::SetPath(const wxString& strPath) { strFullPath.reserve(2*m_strPath.length()); - strFullPath << m_strPath << wxCONFIG_PATH_SEPARATOR << strPath; + strFullPath << m_strPath; + if ( strFullPath.Len() == 0 || + strFullPath.Last() != wxCONFIG_PATH_SEPARATOR ) + strFullPath << wxCONFIG_PATH_SEPARATOR; + strFullPath << strPath; } // simplify it: we need to handle ".." here @@ -269,6 +274,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--; @@ -283,10 +289,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--; } @@ -304,8 +313,12 @@ void wxRegConfig::SetPath(const wxString& strPath) totalSlashes++; } - //else: nothing to do, we squeeze several subseuquent - // slashes into one + else // previous char was a slash too + { + // squeeze several subsequent slashes into one: i.e. + // just ignore this one + dst--; + } } } else // normal character @@ -337,21 +350,24 @@ 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(); + wxChar *dst = strRegPath.GetWriteBuf(len); - 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); + strRegPath.UngetWriteBuf(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 @@ -463,7 +479,7 @@ bool wxRegConfig::GetNextEntry(wxString& str, long& lIndex) const return bOk; } -size_t wxRegConfig::GetNumberOfEntries(bool bRecursive) const +size_t wxRegConfig::GetNumberOfEntries(bool WXUNUSED(bRecursive)) const { size_t nEntries = 0; @@ -480,7 +496,7 @@ size_t wxRegConfig::GetNumberOfEntries(bool bRecursive) const return nEntries; } -size_t wxRegConfig::GetNumberOfGroups(bool bRecursive) const +size_t wxRegConfig::GetNumberOfGroups(bool WXUNUSED(bRecursive)) const { size_t nGroups = 0; @@ -542,44 +558,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; @@ -604,25 +586,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; @@ -649,10 +625,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); @@ -664,7 +641,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); @@ -690,34 +667,7 @@ bool wxRegConfig::RenameEntry(const wxString& oldName, const wxString& newName) if ( HasEntry(newName) ) return FALSE; - // delete the old entry and create the new one - but do in the reverse - // order to not lose the data if Create() fails - - bool ok; - if ( m_keyLocal.IsNumericValue(oldName) ) - { - long val; - ok = m_keyLocal.QueryValue(oldName, &val) && - m_keyLocal.SetValue(newName, val); - } - else - { - wxString val; - ok = m_keyLocal.QueryValue(oldName, val) && - m_keyLocal.SetValue(newName, val); - } - - if ( !ok ) - return FALSE; - - if ( !m_keyLocal.DeleteValue(oldName) ) - { - m_keyLocal.DeleteValue(newName); - - return FALSE; - } - - return TRUE; + return m_keyLocal.RenameValue(oldName, newName); } bool wxRegConfig::RenameGroup(const wxString& oldName, const wxString& newName) @@ -730,17 +680,13 @@ bool wxRegConfig::RenameGroup(const wxString& oldName, const wxString& newName) if ( HasGroup(newName) ) return FALSE; - // TODO there is no way to rename a registry key - we must do a deep copy - // ourselves - wxFAIL_MSG(wxT("Registry key renaming not implemented")); - - return FALSE; + return wxRegKey(m_keyLocal, oldName).Rename(newName); } // ---------------------------------------------------------------------------- // deleting // ---------------------------------------------------------------------------- -bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso) +bool wxRegConfig::DeleteEntry(const wxString& value, bool WXUNUSED(bGroupIfEmptyAlso)) { wxConfigPathChanger path(this, value); @@ -750,7 +696,7 @@ bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso) if ( m_keyLocal.IsEmpty() ) { wxString strKey = GetPath().AfterLast(wxCONFIG_PATH_SEPARATOR); - SetPath(".."); // changes m_keyLocal + SetPath(_T("..")); // changes m_keyLocal return LocalKey().DeleteKey(strKey); } }