]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fileconf.cpp
fixed typo
[wxWidgets.git] / src / common / fileconf.cpp
index 36537f99cffb477f4756670b1c5b02a98705b518..071b90f243423f33a7478da46acdfd8945410338 100644 (file)
@@ -10,7 +10,7 @@
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 #pragma implementation "fileconf.h"
 #endif
 
@@ -24,7 +24,7 @@
   #pragma hdrstop
 #endif  //__BORLANDC__
 
-#if wxUSE_CONFIG
+#if wxUSE_CONFIG && wxUSE_FILECONFIG
 
 #ifndef   WX_PRECOMP
   #include  "wx/string.h"
@@ -106,8 +106,15 @@ static wxString GetAppName(const wxString& appname);
 // "template" array types
 // ----------------------------------------------------------------------------
 
-WX_DEFINE_SORTED_EXPORTED_ARRAY(wxFileConfigEntry *, ArrayEntries);
-WX_DEFINE_SORTED_EXPORTED_ARRAY(wxFileConfigGroup *, ArrayGroups);
+#ifdef WXMAKINGDLL_BASE
+    WX_DEFINE_SORTED_USER_EXPORTED_ARRAY(wxFileConfigEntry *, ArrayEntries,
+                                         WXDLLIMPEXP_BASE);
+    WX_DEFINE_SORTED_USER_EXPORTED_ARRAY(wxFileConfigGroup *, ArrayGroups,
+                                         WXDLLIMPEXP_BASE);
+#else
+    WX_DEFINE_SORTED_ARRAY(wxFileConfigEntry *, ArrayEntries);
+    WX_DEFINE_SORTED_ARRAY(wxFileConfigGroup *, ArrayGroups);
+#endif
 
 // ----------------------------------------------------------------------------
 // wxFileConfigLineList
@@ -487,10 +494,21 @@ wxFileConfig::wxFileConfig(wxInputStream &inStream, wxMBConv& conv)
         wxString strTmp;
 
         char buf[1024];
-        while ( !inStream.Read(buf, WXSIZEOF(buf)).Eof() )
-            strTmp.append(wxConvertMB2WX(buf), inStream.LastRead());
+        do
+        {
+            inStream.Read(buf, WXSIZEOF(buf));
+
+            const wxStreamError err = inStream.GetLastError();
 
-        strTmp.append(wxConvertMB2WX(buf), inStream.LastRead());
+            if ( err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF )
+            {
+                wxLogError(_("Error reading config options."));
+                break;
+            }
+
+            strTmp.append(wxConvertMB2WX(buf), inStream.LastRead());
+        }
+        while ( !inStream.Eof() );
 
         strTrans = wxTextBuffer::Translate(strTmp);
     }
@@ -616,7 +634,11 @@ void wxFileConfig::Parse(wxTextBuffer& buffer, bool bLocal)
       SetPath(strGroup);
 
       if ( bLocal )
+      {
+        if ( m_pCurrentGroup->Parent() )
+          m_pCurrentGroup->Parent()->SetLastGroup(m_pCurrentGroup);
         m_pCurrentGroup->SetLine(m_linesTail);
+      }
 
       // check that there is nothing except comments left on this line
       bool bCont = TRUE;
@@ -671,9 +693,6 @@ void wxFileConfig::Parse(wxTextBuffer& buffer, bool bLocal)
         if ( pEntry == NULL ) {
           // new entry
           pEntry = m_pCurrentGroup->AddEntry(strKey, n);
-
-          if ( bLocal )
-            pEntry->SetLine(m_linesTail);
         }
         else {
           if ( bLocal && pEntry->IsImmutable() ) {
@@ -691,11 +710,12 @@ void wxFileConfig::Parse(wxTextBuffer& buffer, bool bLocal)
             wxLogWarning(_("file '%s', line %d: key '%s' was first found at line %d."),
                          buffer.GetName(), n + 1, strKey.c_str(), pEntry->Line());
 
-            if ( bLocal )
-              pEntry->SetLine(m_linesTail);
           }
         }
 
+        if ( bLocal )
+          pEntry->SetLine(m_linesTail);
+
         // skip whitespace
         while ( wxIsspace(*pEnd) )
           pEnd++;
@@ -1081,8 +1101,11 @@ bool wxFileConfig::DeleteAll()
 {
   CleanUp();
 
-  if ( wxRemove(m_strLocalFile) == -1 )
-    wxLogSysError(_("can't delete user configuration file '%s'"), m_strLocalFile.c_str());
+  if ( wxFile::Exists(m_strLocalFile) && wxRemove(m_strLocalFile) == -1 )
+  {
+      wxLogSysError(_("can't delete user configuration file '%s'"), m_strLocalFile.c_str());
+      return FALSE;
+  }
 
   m_strLocalFile = m_strGlobalFile = wxT("");
   Init();
@@ -1827,8 +1850,6 @@ 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
-            wxASSERT( m_nLine == wxNOT_FOUND );   // consistency check
-
             wxFileConfigLineList *line = Group()->GetLastEntryLine();
             m_pLine = Group()->Config()->LineListInsert(strLine, line);