X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b494c48b31885ee0d9cd91e7931ac837e00144a0..b9efe021b554fa3967d1442cf758435c5cd5ae8f:/src/common/fileconf.cpp diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index a4c5629b0b..2944b09995 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -292,7 +292,10 @@ wxString wxFileConfig::GetGlobalDir() // There's no such thing as global cfg dir in MS-DOS, let's return // current directory (FIXME_MGL?) return wxT(".\\"); +#elif defined(__WXWINCE__) + strDir = wxT("\\Windows\\"); #else // Windows + wxChar szWinDir[MAX_PATH]; ::GetWindowsDirectory(szWinDir, MAX_PATH); @@ -492,7 +495,7 @@ wxFileConfig::wxFileConfig(wxInputStream &inStream, wxMBConv& conv) char buf[1024]; do { - inStream.Read(buf, WXSIZEOF(buf)); + inStream.Read(buf, WXSIZEOF(buf)-1); // leave room for the NULL const wxStreamError err = inStream.GetLastError(); @@ -502,7 +505,12 @@ wxFileConfig::wxFileConfig(wxInputStream &inStream, wxMBConv& conv) break; } - strTmp.append(wxConvertMB2WX(buf), inStream.LastRead()); + // FIXME: this is broken because if we have part of multibyte + // character in the buffer (and another part hasn't been + // read yet) we're going to lose data because of conversion + // errors + buf[inStream.LastRead()] = '\0'; + strTmp += conv.cMB2WX(buf); } while ( !inStream.Eof() ); @@ -540,6 +548,7 @@ wxFileConfig::wxFileConfig(wxInputStream &inStream, wxMBConv& conv) Parse(memText, true /* local */); SetRootPath(); + ResetDirty(); } #endif // wxUSE_STREAMS @@ -584,7 +593,7 @@ void wxFileConfig::Parse(wxTextBuffer& buffer, bool bLocal) { LineListAppend(strLine); - // let the root group have it start line as well + // let the root group have its start line as well if ( !n ) { m_pCurrentGroup->SetLine(m_linesTail); @@ -1010,7 +1019,9 @@ bool wxFileConfig::Save(wxOutputStream& os, wxMBConv& conv) { wxString line = p->Text(); line += wxTextFile::GetEOL(); - if ( !os.Write(line.mb_str(conv), line.length()) ) + + wxCharBuffer buf(line.mb_str(conv)); + if ( !os.Write(buf, strlen(buf)) ) { wxLogError(_("Error saving user configuration data.")); @@ -1087,12 +1098,13 @@ bool wxFileConfig::DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso) if ( !m_pCurrentGroup->DeleteEntry(path.Name()) ) return false; + SetDirty(); + if ( bGroupIfEmptyAlso && m_pCurrentGroup->IsEmpty() ) { if ( m_pCurrentGroup != m_pRootGroup ) { wxFileConfigGroup *pGroup = m_pCurrentGroup; SetPath(wxT("..")); // changes m_pCurrentGroup! - if ( m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name()) ) - SetDirty(); + m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name()); } //else: never delete the root group } @@ -1253,6 +1265,9 @@ void wxFileConfig::LineListRemove(wxFileConfigLineList *pLine) else pNext->SetPrev(pPrev); + if ( m_pRootGroup->GetGroupLine() == pLine ) + m_pRootGroup->SetLine(m_linesHead); + wxLogTrace( FILECONF_TRACE_MASK, _T(" head: %s"), ((m_linesHead) ? m_linesHead->Text().c_str() : wxEmptyString) ); @@ -1312,7 +1327,8 @@ wxFileConfigGroup::~wxFileConfigGroup() void wxFileConfigGroup::SetLine(wxFileConfigLineList *pLine) { - wxASSERT( m_pLine == 0 ); // shouldn't be called twice + // shouldn't be called twice unless we are resetting the line + wxASSERT( m_pLine == 0 || pLine == 0 ); m_pLine = pLine; } @@ -1836,20 +1852,11 @@ void wxFileConfigEntry::SetValue(const wxString& strValue, bool bUser) } else // this entry didn't exist in the local file { - // add a new line to the file: note the hack for the root group - // which is special in that it doesn't have its own group line - // (something like "[/]") and so the line we get for it may be not - // its line at all if it doesn't have any entries - // - // this is definitely not the right place to fix it but changing - // the root group to have NULL m_pLine will probably break too - // much stuff elsewhere so I don't dare to do it... + // add a new line to the file: note that line returned by + // GetLastEntryLine() may be NULL if we're in the root group and it + // doesn't have any entries yet, but this is ok as passing NULL + // line to LineListInsert() means to prepend new line to the list wxFileConfigLineList *line = Group()->GetLastEntryLine(); - if ( !Group()->Parent() && line == Group()->GetGroupLine() ) - { - // prepend the first root group entry to the head of the list - line = NULL; - } m_pLine = Group()->Config()->LineListInsert(strLine, line); Group()->SetLastEntry(this);