X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dcbe38820019dd8dab9c8c89ebbb310cca7f5e99..885ee23543a6264c0ffd904aec4bc6d78a249517:/src/common/fileconf.cpp diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index a261372eaa..454dc463ad 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -85,6 +85,9 @@ wxString wxFileConfig::GetGlobalDir() #ifdef __UNIX__ strDir = "/etc/"; + #elif defined(__WXSTUBS__) + // TODO + wxASSERT( TRUE ) ; #else // Windows #ifndef _MAX_PATH #define _MAX_PATH 512 @@ -133,7 +136,7 @@ wxString wxFileConfig::GetLocalDir() wxString wxFileConfig::GetGlobalFileName(const char *szFile) { - wxString str = GetLocalDir(); + wxString str = GetGlobalDir(); str << szFile; if ( strchr(szFile, '.') == NULL ) @@ -220,18 +223,18 @@ 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]) ) + if ( !strLocal.IsEmpty() && !wxIsAbsolutePath(strLocal) ) { m_strLocalFile = GetLocalDir(); m_strLocalFile << strLocal; } - if ( !strGlobal.IsEmpty() && !wxIsPathSeparator(strGlobal[0u]) ) + if ( !strGlobal.IsEmpty() && !wxIsAbsolutePath(strGlobal) ) { m_strGlobalFile = GetGlobalDir(); m_strGlobalFile << strGlobal; } + Init(); } @@ -264,8 +267,8 @@ void wxFileConfig::Parse(wxTextFile& file, bool bLocal) const char *pEnd; wxString strLine; - uint nLineCount = file.GetLineCount(); - for ( uint n = 0; n < nLineCount; n++ ) { + size_t nLineCount = file.GetLineCount(); + for ( size_t n = 0; n < nLineCount; n++ ) { strLine = file[n]; // add the line to linked list @@ -416,7 +419,7 @@ void wxFileConfig::SetPath(const wxString& strPath) } // change current group - uint n; + size_t n; m_pCurrentGroup = m_pRootGroup; for ( n = 0; n < aParts.Count(); n++ ) { ConfigGroup *pNextGroup = m_pCurrentGroup->FindSubgroup(aParts[n]); @@ -444,7 +447,7 @@ bool wxFileConfig::GetFirstGroup(wxString& str, long& lIndex) const bool wxFileConfig::GetNextGroup (wxString& str, long& lIndex) const { - if ( uint(lIndex) < m_pCurrentGroup->Groups().Count() ) { + if ( size_t(lIndex) < m_pCurrentGroup->Groups().Count() ) { str = m_pCurrentGroup->Groups()[lIndex++]->Name(); return TRUE; } @@ -460,7 +463,7 @@ bool wxFileConfig::GetFirstEntry(wxString& str, long& lIndex) const bool wxFileConfig::GetNextEntry (wxString& str, long& lIndex) const { - if ( uint(lIndex) < m_pCurrentGroup->Entries().Count() ) { + if ( size_t(lIndex) < m_pCurrentGroup->Entries().Count() ) { str = m_pCurrentGroup->Entries()[lIndex++]->Name(); return TRUE; } @@ -468,13 +471,13 @@ bool wxFileConfig::GetNextEntry (wxString& str, long& lIndex) const return FALSE; } -uint wxFileConfig::GetNumberOfEntries(bool bRecursive) const +size_t wxFileConfig::GetNumberOfEntries(bool bRecursive) const { - uint n = m_pCurrentGroup->Entries().Count(); + size_t n = m_pCurrentGroup->Entries().Count(); if ( bRecursive ) { ConfigGroup *pOldCurrentGroup = m_pCurrentGroup; - uint nSubgroups = m_pCurrentGroup->Groups().Count(); - for ( uint nGroup = 0; nGroup < nSubgroups; nGroup++ ) { + size_t nSubgroups = m_pCurrentGroup->Groups().Count(); + for ( size_t nGroup = 0; nGroup < nSubgroups; nGroup++ ) { CONST_CAST m_pCurrentGroup = m_pCurrentGroup->Groups()[nGroup]; n += GetNumberOfEntries(TRUE); CONST_CAST m_pCurrentGroup = pOldCurrentGroup; @@ -484,13 +487,13 @@ uint wxFileConfig::GetNumberOfEntries(bool bRecursive) const return n; } -uint wxFileConfig::GetNumberOfGroups(bool bRecursive) const +size_t wxFileConfig::GetNumberOfGroups(bool bRecursive) const { - uint n = m_pCurrentGroup->Groups().Count(); + size_t n = m_pCurrentGroup->Groups().Count(); if ( bRecursive ) { ConfigGroup *pOldCurrentGroup = m_pCurrentGroup; - uint nSubgroups = m_pCurrentGroup->Groups().Count(); - for ( uint nGroup = 0; nGroup < nSubgroups; nGroup++ ) { + size_t nSubgroups = m_pCurrentGroup->Groups().Count(); + for ( size_t nGroup = 0; nGroup < nSubgroups; nGroup++ ) { CONST_CAST m_pCurrentGroup = m_pCurrentGroup->Groups()[nGroup]; n += GetNumberOfGroups(TRUE); CONST_CAST m_pCurrentGroup = pOldCurrentGroup; @@ -532,6 +535,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; } @@ -570,7 +575,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(); @@ -671,17 +676,13 @@ 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; } @@ -789,7 +790,7 @@ wxFileConfig::ConfigGroup::ConfigGroup(wxFileConfig::ConfigGroup *pParent, wxFileConfig::ConfigGroup::~ConfigGroup() { // entries - uint n, nCount = m_aEntries.Count(); + size_t n, nCount = m_aEntries.Count(); for ( n = 0; n < nCount; n++ ) delete m_aEntries[n]; @@ -920,7 +921,7 @@ wxString wxFileConfig::ConfigGroup::GetFullName() const wxFileConfig::ConfigEntry * wxFileConfig::ConfigGroup::FindEntry(const char *szName) const { - uint i, + size_t i, lo = 0, hi = m_aEntries.Count(); int res; @@ -950,7 +951,7 @@ wxFileConfig::ConfigGroup::FindEntry(const char *szName) const wxFileConfig::ConfigGroup * wxFileConfig::ConfigGroup::FindSubgroup(const char *szName) const { - uint i, + size_t i, lo = 0, hi = m_aSubgroups.Count(); int res; @@ -1029,8 +1030,8 @@ bool wxFileConfig::ConfigGroup::DeleteSubgroup(ConfigGroup *pGroup) wxCHECK( pGroup != NULL, FALSE ); // deleting non existing group? // delete all entries - uint nCount = pGroup->m_aEntries.Count(); - for ( uint nEntry = 0; nEntry < nCount; nEntry++ ) { + size_t nCount = pGroup->m_aEntries.Count(); + for ( size_t nEntry = 0; nEntry < nCount; nEntry++ ) { LineList *pLine = pGroup->m_aEntries[nEntry]->GetLine(); if ( pLine != NULL ) m_pConfig->LineListRemove(pLine); @@ -1038,7 +1039,7 @@ bool wxFileConfig::ConfigGroup::DeleteSubgroup(ConfigGroup *pGroup) // and subgroups of this sungroup nCount = pGroup->m_aSubgroups.Count(); - for ( uint nGroup = 0; nGroup < nCount; nGroup++ ) { + for ( size_t nGroup = 0; nGroup < nCount; nGroup++ ) { pGroup->DeleteSubgroup(pGroup->m_aSubgroups[nGroup]); } @@ -1052,7 +1053,7 @@ bool wxFileConfig::ConfigGroup::DeleteSubgroup(ConfigGroup *pGroup) // go back until we find a subgroup or reach the group's line ConfigGroup *pNewLast = NULL; - uint n, nSubgroups = m_aSubgroups.Count(); + size_t n, nSubgroups = m_aSubgroups.Count(); LineList *pl; for ( pl = pLine->Prev(); pl != m_pLine; pl = pl->Prev() ) { // is it our subgroup? @@ -1103,7 +1104,7 @@ bool wxFileConfig::ConfigGroup::DeleteEntry(const char *szName) // go back until we find another entry or reach the group's line ConfigEntry *pNewLast = NULL; - uint n, nEntries = m_aEntries.Count(); + size_t n, nEntries = m_aEntries.Count(); LineList *pl; for ( pl = pLine->Prev(); pl != m_pLine; pl = pl->Prev() ) { // is it our subgroup? @@ -1272,7 +1273,7 @@ wxString FilterIn(const wxString& str) bool bQuoted = !str.IsEmpty() && str[0] == '"'; - for ( uint n = bQuoted ? 1 : 0; n < str.Len(); n++ ) { + for ( size_t n = bQuoted ? 1 : 0; n < str.Len(); n++ ) { if ( str[n] == '\\' ) { switch ( str[++n] ) { case 'n': @@ -1313,6 +1314,9 @@ wxString FilterIn(const wxString& str) // quote the string before writing it to file wxString FilterOut(const wxString& str) { + if(str.IsEmpty()) + return str; + wxString strResult; strResult.Alloc(str.Len()); @@ -1323,7 +1327,7 @@ wxString FilterOut(const wxString& str) strResult += '"'; char c; - for ( uint n = 0; n < str.Len(); n++ ) { + for ( size_t n = 0; n < str.Len(); n++ ) { switch ( str[n] ) { case '\n': c = 'n'; @@ -1342,8 +1346,10 @@ wxString FilterOut(const wxString& str) break; case '"': - if ( bQuote ) + if ( bQuote ) { c = '"'; + break; + } //else: fall through default: