X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5787c2b9c2ed0bcb14bfde933c228f921c3a30c0..d1427b705318677afe28b1291867f6930c8823a7:/src/common/fileconf.cpp diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index ebbea030fb..24d10b9833 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -133,7 +133,7 @@ wxString wxFileConfig::GetLocalDir() wxString wxFileConfig::GetGlobalFileName(const char *szFile) { - wxString str = GetLocalDir(); + wxString str = GetGlobalDir(); str << szFile; if ( strchr(szFile, '.') == NULL ) @@ -157,7 +157,8 @@ wxString wxFileConfig::GetLocalFileName(const char *szFile) str << szFile; #ifdef __WXMSW__ - str << ".ini"; + if ( strchr(szFile, '.') == NULL ) + str << ".ini"; #endif return str; @@ -219,14 +220,17 @@ wxFileConfig::wxFileConfig(const wxString& strLocal, const wxString& strGlobal) : m_strLocalFile(strLocal), m_strGlobalFile(strGlobal) { // if the path is not absolute, prepend the standard directory to it - - if ( !strLocal.IsEmpty() && !wxIsPathSeparator(strLocal[0u]) ) - m_strLocalFile = GetLocalDir(); - m_strLocalFile << strLocal; - - if ( !strGlobal.IsEmpty() && !wxIsPathSeparator(strGlobal[0u]) ) - m_strGlobalFile = GetGlobalDir(); - m_strGlobalFile << strGlobal; + if ( !strLocal.IsEmpty() && !wxIsAbsolutePath(strLocal) ) + { + m_strLocalFile = GetLocalDir(); + m_strLocalFile << strLocal; + } + + if ( !strGlobal.IsEmpty() && !wxIsAbsolutePath(strGlobal) ) + { + m_strGlobalFile = GetGlobalDir(); + m_strGlobalFile << strGlobal; + } Init(); } @@ -432,13 +436,13 @@ void wxFileConfig::SetPath(const wxString& strPath) // enumeration // ---------------------------------------------------------------------------- -bool wxFileConfig::GetFirstGroup(wxString& str, long& lIndex) +bool wxFileConfig::GetFirstGroup(wxString& str, long& lIndex) const { lIndex = 0; return GetNextGroup(str, lIndex); } -bool wxFileConfig::GetNextGroup (wxString& str, long& lIndex) +bool wxFileConfig::GetNextGroup (wxString& str, long& lIndex) const { if ( uint(lIndex) < m_pCurrentGroup->Groups().Count() ) { str = m_pCurrentGroup->Groups()[lIndex++]->Name(); @@ -448,13 +452,13 @@ bool wxFileConfig::GetNextGroup (wxString& str, long& lIndex) return FALSE; } -bool wxFileConfig::GetFirstEntry(wxString& str, long& lIndex) +bool wxFileConfig::GetFirstEntry(wxString& str, long& lIndex) const { lIndex = 0; return GetNextEntry(str, lIndex); } -bool wxFileConfig::GetNextEntry (wxString& str, long& lIndex) +bool wxFileConfig::GetNextEntry (wxString& str, long& lIndex) const { if ( uint(lIndex) < m_pCurrentGroup->Entries().Count() ) { str = m_pCurrentGroup->Entries()[lIndex++]->Name(); @@ -528,6 +532,8 @@ bool wxFileConfig::Read(wxString *pstr, ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name()); if (pEntry == NULL) { + if( IsRecordingDefaults() ) + ((wxFileConfig *)this)->Write(szKey,szDefault); *pstr = ExpandEnvVars(szDefault); return FALSE; } @@ -566,7 +572,7 @@ bool wxFileConfig::Write(const char *szKey, const char *szValue) wxString strName = path.Name(); if ( strName.IsEmpty() ) { // setting the value of a group is an error - wxASSERT_MSG( IsEmpty(szValue), "can't set value of a group!" ); + wxASSERT_MSG( IsEmpty(szValue), _("can't set value of a group!") ); // ... except if it's empty in which case it's a way to force it's creation m_pCurrentGroup->SetDirty(); @@ -648,7 +654,7 @@ bool wxFileConfig::DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso) if ( m_pCurrentGroup != m_pRootGroup ) { ConfigGroup *pGroup = m_pCurrentGroup; SetPath(".."); // changes m_pCurrentGroup! - m_pCurrentGroup->DeleteSubgroup(pGroup->Name()); + m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name()); } //else: never delete the root group } @@ -660,24 +666,20 @@ bool wxFileConfig::DeleteGroup(const char *szKey) { PathChanger path(this, szKey); - return m_pCurrentGroup->DeleteSubgroup(path.Name()); + return m_pCurrentGroup->DeleteSubgroupByName(path.Name()); } bool wxFileConfig::DeleteAll() { CleanUp(); - m_strLocalFile = m_strGlobalFile = ""; - Init(); - const char *szFile = m_strLocalFile; if ( remove(szFile) == -1 ) wxLogSysError(_("can't delete user configuration file '%s'"), szFile); - szFile = m_strGlobalFile; - if ( remove(szFile) ) - wxLogSysError(_("can't delete system configuration file '%s'"), szFile); + m_strLocalFile = m_strGlobalFile = ""; + Init(); return TRUE; } @@ -1012,9 +1014,16 @@ wxFileConfig::ConfigGroup::AddSubgroup(const wxString& strName) delete several of them. */ -bool wxFileConfig::ConfigGroup::DeleteSubgroup(const char *szName) +bool wxFileConfig::ConfigGroup::DeleteSubgroupByName(const char *szName) +{ + return DeleteSubgroup(FindSubgroup(szName)); +} + +// doesn't delete the subgroup itself, but does remove references to it from +// all other data structures (and normally the returned pointer should be +// deleted a.s.a.p. because there is nothing much to be done with it anyhow) +bool wxFileConfig::ConfigGroup::DeleteSubgroup(ConfigGroup *pGroup) { - ConfigGroup *pGroup = FindSubgroup(szName); wxCHECK( pGroup != NULL, FALSE ); // deleting non existing group? // delete all entries @@ -1025,6 +1034,12 @@ bool wxFileConfig::ConfigGroup::DeleteSubgroup(const char *szName) m_pConfig->LineListRemove(pLine); } + // and subgroups of this sungroup + nCount = pGroup->m_aSubgroups.Count(); + for ( uint nGroup = 0; nGroup < nCount; nGroup++ ) { + pGroup->DeleteSubgroup(pGroup->m_aSubgroups[nGroup]); + } + LineList *pLine = pGroup->m_pLine; if ( pLine != NULL ) { // notice that we may do this test inside the previous "if" because the @@ -1325,8 +1340,10 @@ wxString FilterOut(const wxString& str) break; case '"': - if ( bQuote ) + if ( bQuote ) { c = '"'; + break; + } //else: fall through default: