X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/90186e524e347a3a779c928a44fb7d744b3efcf7..db400410d8117199728e15cab01824681d517e3e:/src/msw/regconf.cpp diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 8943720d8f..9c77482ec9 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -21,18 +21,21 @@ #endif #ifndef WX_PRECOMP - #include + #include "wx/string.h" #endif //WX_PRECOMP -#include -#include -#include -#include +#include "wx/event.h" +#include "wx/app.h" +#include "wx/log.h" + +#if wxUSE_CONFIG + +#include "wx/config.h" #ifndef __WIN16__ -#include -#include +#include "wx/msw/registry.h" +#include "wx/msw/regconf.h" // ---------------------------------------------------------------------------- // constants @@ -98,7 +101,7 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, if ( appName.IsEmpty() ) { - wxCHECK_RET( wxTheApp, "No application name in wxRegConfig ctor!" ); + wxCHECK_RET( wxTheApp, wxT("No application name in wxRegConfig ctor!") ); strRoot << wxTheApp->GetAppName(); } else @@ -131,6 +134,7 @@ wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName, { wxLogNull nolog; m_keyGlobalRoot.Open(); + m_keyGlobal.Open(); } } @@ -160,13 +164,25 @@ void wxRegConfig::SetPath(const wxString& strPath) } // recombine path parts in one variable - wxString strRegPath; + wxString strOldPath = m_strPath, strRegPath; m_strPath.Empty(); for ( size_t n = 0; n < aParts.Count(); n++ ) { strRegPath << '\\' << aParts[n]; m_strPath << wxCONFIG_PATH_SEPARATOR << aParts[n]; } + if ( m_strPath == strOldPath ) + return; + + // as we create the registry key when SetPath(key) is done, we can be left + // with plenty of empty keys if this was only done to try to read some value + // which, in fact, doesn't exist - to prevent this from happening we + // automatically delete the old key if it was empty + if ( m_keyLocal.IsEmpty() ) + { + m_keyLocal.DeleteSelf(); + } + // change current key(s) m_keyLocal.SetName(m_keyLocalRoot, strRegPath); m_keyGlobal.SetName(m_keyGlobalRoot, strRegPath); @@ -202,13 +218,15 @@ bool wxRegConfig::GetNextGroup(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) ) { - // no more global entries - lIndex |= LOCAL_MASK; - break; + while ( m_keyGlobal.GetNextKey(str, lIndex) ) { + if ( !m_keyLocal.HasSubKey(str) ) { + // ok, found one - return it + return TRUE; } - } while( m_keyLocal.HasSubKey(str) ); + } + + // no more global entries + lIndex |= LOCAL_MASK; } // much easier with local entries: get the next one we find @@ -231,13 +249,15 @@ 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.GetNextValue(str, lIndex) ) { - // no more global entries - lIndex |= LOCAL_MASK; - break; + while ( m_keyGlobal.GetNextValue(str, lIndex) ) { + if ( !m_keyLocal.HasValue(str) ) { + // ok, found one - return it + return TRUE; } - } while( m_keyLocal.HasValue(str) ); + } + + // no more global entries + lIndex |= LOCAL_MASK; } // much easier with local entries: get the next one we find @@ -287,14 +307,39 @@ size_t wxRegConfig::GetNumberOfGroups(bool bRecursive) const // tests for existence // ---------------------------------------------------------------------------- -bool wxRegConfig::HasGroup(const wxString& strName) const +bool wxRegConfig::HasGroup(const wxString& key) const +{ + wxConfigPathChanger path(this, key); + + wxString strName(path.Name()); + + return m_keyLocal.HasSubKey(strName) || m_keyGlobal.HasSubKey(strName); +} + +bool wxRegConfig::HasEntry(const wxString& key) const { - return m_keyLocal.HasSubKey(strName) || m_keyGlobal.HasSubKey(strName); + wxConfigPathChanger path(this, key); + + wxString strName(path.Name()); + + return m_keyLocal.HasValue(strName) || m_keyGlobal.HasValue(strName); } -bool wxRegConfig::HasEntry(const wxString& strName) const +wxConfigBase::EntryType wxRegConfig::GetEntryType(const wxString& key) const { - return m_keyLocal.HasValue(strName) || m_keyGlobal.HasValue(strName); + wxConfigPathChanger path(this, key); + + wxString strName(path.Name()); + + bool isNumeric; + if ( m_keyLocal.HasValue(strName) ) + isNumeric = m_keyLocal.IsNumericValue(strName); + else if ( m_keyGlobal.HasValue(strName) ) + isNumeric = m_keyGlobal.IsNumericValue(strName); + else + return wxConfigBase::Type_Unknown; + + return isNumeric ? wxConfigBase::Type_Integer : wxConfigBase::Type_String; } // ---------------------------------------------------------------------------- @@ -312,7 +357,7 @@ bool wxRegConfig::Read(const wxString& key, wxString *pStr) const if ( IsImmutable(path.Name()) ) { if ( TryGetValue(m_keyGlobal, path.Name(), *pStr) ) { if ( m_keyLocal.HasValue(path.Name()) ) { - wxLogWarning("User value for immutable key '%s' ignored.", + wxLogWarning(wxT("User value for immutable key '%s' ignored."), path.Name().c_str()); } *pStr = wxConfigBase::ExpandEnvVars(*pStr); @@ -329,8 +374,6 @@ bool wxRegConfig::Read(const wxString& key, wxString *pStr) const (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) { // nothing to do - // TODO: do we return TRUE? Not in original implementation, - // but I don't see why not. -- JACS *pStr = wxConfigBase::ExpandEnvVars(*pStr); return TRUE; } @@ -350,7 +393,7 @@ bool wxRegConfig::Read(const wxString& key, wxString *pStr, if ( IsImmutable(path.Name()) ) { if ( TryGetValue(m_keyGlobal, path.Name(), *pStr) ) { if ( m_keyLocal.HasValue(path.Name()) ) { - wxLogWarning("User value for immutable key '%s' ignored.", + wxLogWarning(wxT("User value for immutable key '%s' ignored."), path.Name().c_str()); } @@ -393,7 +436,7 @@ bool wxRegConfig::Read(const wxString& key, long *plResult) const if ( IsImmutable(path.Name()) ) { if ( TryGetValue(m_keyGlobal, path.Name(), plResult) ) { if ( m_keyLocal.HasValue(path.Name()) ) { - wxLogWarning("User value for immutable key '%s' ignored.", + wxLogWarning(wxT("User value for immutable key '%s' ignored."), path.Name().c_str()); } @@ -418,7 +461,7 @@ bool wxRegConfig::Write(const wxString& key, const wxString& szValue) wxConfigPathChanger path(this, key); if ( IsImmutable(path.Name()) ) { - wxLogError("Can't change immutable entry '%s'.", path.Name().c_str()); + wxLogError(wxT("Can't change immutable entry '%s'."), path.Name().c_str()); return FALSE; } @@ -430,7 +473,7 @@ bool wxRegConfig::Write(const wxString& key, long lValue) wxConfigPathChanger path(this, key); if ( IsImmutable(path.Name()) ) { - wxLogError("Can't change immutable entry '%s'.", path.Name().c_str()); + wxLogError(wxT("Can't change immutable entry '%s'."), path.Name().c_str()); return FALSE; } @@ -493,7 +536,7 @@ bool wxRegConfig::RenameGroup(const wxString& oldName, const wxString& newName) // TODO there is no way to rename a registry key - we must do a deep copy // ourselves - wxFAIL_MSG("Registry key renaming not implemented"); + wxFAIL_MSG(wxT("Registry key renaming not implemented")); return FALSE; } @@ -508,7 +551,7 @@ bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso) if ( !m_keyLocal.DeleteValue(path.Name()) ) return FALSE; - if ( !m_keyLocal.HasSubkeys() ) { + if ( m_keyLocal.IsEmpty() ) { wxString strKey = GetPath().AfterLast(wxCONFIG_PATH_SEPARATOR); SetPath(".."); // changes m_keyLocal return m_keyLocal.DeleteKey(strKey); @@ -542,3 +585,5 @@ bool wxRegConfig::DeleteAll() #endif // __WIN16__ +#endif + // wxUSE_CONFIG