X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6d8335660f15c5701b922a3f478aab6e6abcc3d4..44a6c8e61808e6197bc78e2344c2e93853943350:/src/msw/regconf.cpp diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 3becd8f334..854d39f7d0 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -20,10 +20,25 @@ // ---------------------------------------------------------------------------- // headers // ---------------------------------------------------------------------------- -#include + +#ifdef __GNUG__ + #pragma implementation "regconf.h" +#endif + +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif //__BORLANDC__ + +#ifndef WX_PRECOMP + #include +#endif //WX_PRECOMP + +#include #include -#include #include +#include // ---------------------------------------------------------------------------- // constants @@ -77,20 +92,20 @@ wxRegConfig::~wxRegConfig() // ---------------------------------------------------------------------------- void wxRegConfig::SetPath(const wxString& strPath) { - ArrayString aParts; + wxArrayString aParts; if ( strPath.IsEmpty() ) return; - if ( strPath[0] == APPCONF_PATH_SEPARATOR ) { + if ( strPath[0] == wxCONFIG_PATH_SEPARATOR ) { // absolute path - SplitPath(aParts, strPath); + wxSplitPath(aParts, strPath); } else { // relative path, combine with current one wxString strFullPath = GetPath(); - strFullPath << APPCONF_PATH_SEPARATOR << strPath; - SplitPath(aParts, strFullPath); + strFullPath << wxCONFIG_PATH_SEPARATOR << strPath; + wxSplitPath(aParts, strFullPath); } // recombine path parts in one variable @@ -98,7 +113,7 @@ void wxRegConfig::SetPath(const wxString& strPath) m_strPath.Empty(); for ( uint n = 0; n < aParts.Count(); n++ ) { strRegPath << '\\' << aParts[n]; - m_strPath << APPCONF_PATH_SEPARATOR << aParts[n]; + m_strPath << wxCONFIG_PATH_SEPARATOR << aParts[n]; } // change current key(s) @@ -125,13 +140,13 @@ void wxRegConfig::SetPath(const wxString& strPath) #define LOCAL_MASK 0x8000 #define IS_LOCAL_INDEX(l) (((l) & LOCAL_MASK) != 0) -bool wxRegConfig::GetFirstGroup(wxString& str, long& lIndex) +bool wxRegConfig::GetFirstGroup(wxString& str, long& lIndex) const { lIndex = 0; return GetNextGroup(str, lIndex); } -bool wxRegConfig::GetNextGroup (wxString& str, long& lIndex) +bool wxRegConfig::GetNextGroup(wxString& str, long& lIndex) const { // are we already enumerating local entries? if ( m_keyGlobal.IsOpened() && !IS_LOCAL_INDEX(lIndex) ) { @@ -154,35 +169,69 @@ bool wxRegConfig::GetNextGroup (wxString& str, long& lIndex) return bOk; } -bool wxRegConfig::GetFirstEntry(wxString& str, long& lIndex) +bool wxRegConfig::GetFirstEntry(wxString& str, long& lIndex) const { lIndex = 0; - return GetNextGroup(str, lIndex); + return GetNextEntry(str, lIndex); } -bool wxRegConfig::GetNextEntry (wxString& str, long& lIndex) +bool wxRegConfig::GetNextEntry(wxString& str, long& lIndex) const { // are we already enumerating local entries? if ( m_keyGlobal.IsOpened() && !IS_LOCAL_INDEX(lIndex) ) { // try to find a global entry which doesn't appear locally do { - if ( !m_keyGlobal.GetNextKey(str, lIndex) ) { + if ( !m_keyGlobal.GetNextValue(str, lIndex) ) { // no more global entries lIndex |= LOCAL_MASK; break; } - } while( m_keyLocal.HasSubKey(str) ); + } while( m_keyLocal.HasValue(str) ); } // much easier with local entries: get the next one we find // (don't forget to clear our flag bit and set it again later) lIndex &= ~LOCAL_MASK; - bool bOk = m_keyLocal.GetNextKey(str, lIndex); + bool bOk = m_keyLocal.GetNextValue(str, lIndex); lIndex |= LOCAL_MASK; return bOk; } +uint wxRegConfig::GetNumberOfEntries(bool bRecursive) const +{ + uint nEntries = 0; + + // dummy vars + wxString str; + long l; + bool bCont = ((wxRegConfig*)this)->GetFirstEntry(str, l); + while ( bCont ) { + nEntries++; + + bCont = ((wxRegConfig*)this)->GetNextEntry(str, l); + } + + return nEntries; +} + +uint wxRegConfig::GetNumberOfGroups(bool bRecursive) const +{ + uint nGroups = 0; + + // dummy vars + wxString str; + long l; + bool bCont = ((wxRegConfig*)this)->GetFirstGroup(str, l); + while ( bCont ) { + nGroups++; + + bCont = ((wxRegConfig*)this)->GetNextGroup(str, l); + } + + return nGroups; +} + // ---------------------------------------------------------------------------- // tests for existence // ---------------------------------------------------------------------------- @@ -201,9 +250,9 @@ bool wxRegConfig::HasEntry(const wxString& strName) const // reading/writing // ---------------------------------------------------------------------------- -bool wxRegConfig::Read(wxString& str, - const char *szKey, - const char *szDefault) const +bool wxRegConfig::Read(wxString *pStr, + const char *szKey, + const char *szDefault) const { PathChanger path(this, szKey); @@ -212,7 +261,7 @@ bool wxRegConfig::Read(wxString& str, // 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(), str) ) { + if ( TryGetValue(m_keyGlobal, path.Name(), *pStr) ) { if ( m_keyLocal.HasValue(path.Name()) ) { wxLogWarning("User value for immutable key '%s' ignored.", path.Name().c_str()); @@ -227,17 +276,20 @@ bool wxRegConfig::Read(wxString& str, } // first try local key - if ( TryGetValue(m_keyLocal, path.Name(), str) || - (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), str)) ) { + if ( TryGetValue(m_keyLocal, path.Name(), *pStr) || + (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) { return TRUE; } + if(IsRecordingDefaults()) + ((wxRegConfig*)this)->Write(szKey,szDefault); + // default value - str = szDefault; + *pStr = szDefault; return FALSE; } -bool wxRegConfig::Read(long &lValue, const char *szKey, long lDefault) const +bool wxRegConfig::Read(long *plResult, const char *szKey, long lDefault) const { PathChanger path(this, szKey); @@ -246,7 +298,7 @@ bool wxRegConfig::Read(long &lValue, const char *szKey, long lDefault) const // 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(), &lValue) ) { + if ( TryGetValue(m_keyGlobal, path.Name(), plResult) ) { if ( m_keyLocal.HasValue(path.Name()) ) { wxLogWarning("User value for immutable key '%s' ignored.", path.Name().c_str()); @@ -261,13 +313,13 @@ bool wxRegConfig::Read(long &lValue, const char *szKey, long lDefault) const } // first try local key - if ( TryGetValue(m_keyLocal, path.Name(), &lValue) || - (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), &lValue)) ) { + if ( TryGetValue(m_keyLocal, path.Name(), plResult) || + (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) { return TRUE; } // default - lValue = lDefault; + *plResult = lDefault; return FALSE; } @@ -305,8 +357,8 @@ bool wxRegConfig::DeleteEntry(const char *szValue, bool bGroupIfEmptyAlso) if ( !m_keyLocal.DeleteValue(path.Name()) ) return FALSE; - if ( m_keyLocal.IsEmpty() ) { - wxString strKey = GetPath().Right(APPCONF_PATH_SEPARATOR); + if ( !m_keyLocal.HasSubkeys() ) { + wxString strKey = GetPath().Right(wxCONFIG_PATH_SEPARATOR); SetPath(".."); // changes m_keyLocal return m_keyLocal.DeleteKey(strKey); } @@ -323,9 +375,6 @@ bool wxRegConfig::DeleteGroup(const char *szKey) bool wxRegConfig::DeleteAll() { - // first of all, prevent the creation of new registry entries - Config::EnableAutosave(FALSE); - m_keyLocal.Close(); m_keyGlobal.Close();