]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fileconf.cpp
wxTheColourDatabase->Find() can fail.
[wxWidgets.git] / src / common / fileconf.cpp
index 3a25662db7c74018a7e7fe1474b205d347f5b66a..2e4468252f2ebe63e57aa318e7a38718ef3db1ba 100644 (file)
 // headers
 // ----------------------------------------------------------------------------
 
+// For compilers that support precompilation, includes "wx.h".
 #include  "wx/wxprec.h"
 
 #ifdef    __BORLANDC__
-  #pragma hdrstop
+    #pragma hdrstop
 #endif  //__BORLANDC__
 
 #if wxUSE_CONFIG && wxUSE_FILECONFIG
 
 #ifndef   WX_PRECOMP
-  #include  "wx/string.h"
-  #include  "wx/intl.h"
+    #include  "wx/dynarray.h"
+    #include  "wx/string.h"
+    #include  "wx/intl.h"
 #endif  //WX_PRECOMP
 
 #include  "wx/app.h"
-#include  "wx/dynarray.h"
 #include  "wx/file.h"
 #include  "wx/log.h"
 #include  "wx/textfile.h"
@@ -308,18 +309,22 @@ wxString wxFileConfig::GetLocalDir()
 
 #if defined(__WXMAC__) || defined(__DOS__)
     // no local dir concept on Mac OS 9 or MS-DOS
-    return GetGlobalDir() ;
+    strDir << GetGlobalDir() ;
 #else
     wxGetHomeDir(&strDir);
 
-#ifdef  __UNIX__
-#ifdef __VMS
-    if (strDir.Last() != wxT(']'))
-#endif
-    if (strDir.Last() != wxT('/')) strDir << wxT('/');
-#else
-    if (strDir.Last() != wxT('\\')) strDir << wxT('\\');
-#endif
+    #ifdef  __UNIX__
+        if (
+            (strDir.Last() != wxT('/'))
+        #ifdef __VMS
+            && (strDir.Last() != wxT(']'))
+        #endif
+            )
+            strDir << wxT('/');
+    #else
+        if (strDir.Last() != wxT('\\'))
+            strDir << wxT('\\');
+    #endif
 #endif
 
     return strDir;
@@ -390,7 +395,7 @@ void wxFileConfig::Init()
     {
         wxTextFile fileGlobal(m_strGlobalFile);
 
-        if ( fileGlobal.Open(m_conv/*ignored in ANSI build*/) )
+        if ( fileGlobal.Open(*m_conv/*ignored in ANSI build*/) )
         {
             Parse(fileGlobal, false /* global */);
             SetRootPath();
@@ -405,7 +410,7 @@ void wxFileConfig::Init()
     if ( !m_strLocalFile.empty() && wxFile::Exists(m_strLocalFile) )
     {
         wxTextFile fileLocal(m_strLocalFile);
-        if ( fileLocal.Open(m_conv/*ignored in ANSI build*/) )
+        if ( fileLocal.Open(*m_conv/*ignored in ANSI build*/) )
         {
             Parse(fileLocal, true /* local */);
             SetRootPath();
@@ -422,12 +427,13 @@ void wxFileConfig::Init()
 // constructor supports creation of wxFileConfig objects of any type
 wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName,
                            const wxString& strLocal, const wxString& strGlobal,
-                           long style, wxMBConv& conv)
+                           long style,
+                           const wxMBConv& conv)
             : wxConfigBase(::GetAppName(appName), vendorName,
                            strLocal, strGlobal,
                            style),
               m_strLocalFile(strLocal), m_strGlobalFile(strGlobal),
-              m_conv(conv)
+              m_conv(conv.Clone())
 {
     // Make up names for files if empty
     if ( m_strLocalFile.empty() && (style & wxCONFIG_USE_LOCAL_FILE) )
@@ -470,8 +476,8 @@ wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName,
 
 #if wxUSE_STREAMS
 
-wxFileConfig::wxFileConfig(wxInputStream &inStream, wxMBConv& conv)
-            : m_conv(conv)
+wxFileConfig::wxFileConfig(wxInputStream &inStream, const wxMBConv& conv)
+            : m_conv(conv.Clone())
 {
     // always local_file when this constructor is called (?)
     SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE);
@@ -566,6 +572,8 @@ wxFileConfig::~wxFileConfig()
     Flush();
 
     CleanUp();
+
+    delete m_conv;
 }
 
 // ----------------------------------------------------------------------------
@@ -1007,7 +1015,7 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
   {
     wxString line = p->Text();
     line += wxTextFile::GetEOL();
-    if ( !file.Write(line, m_conv) )
+    if ( !file.Write(line, *m_conv) )
     {
       wxLogError(_("can't write user configuration file."));
       return false;
@@ -1032,7 +1040,7 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
 
 #if wxUSE_STREAMS
 
-bool wxFileConfig::Save(wxOutputStream& os, wxMBConv& conv)
+bool wxFileConfig::Save(wxOutputStream& os, const wxMBConv& conv)
 {
     // save unconditionally, even if not dirty
     for ( wxFileConfigLineList *p = m_linesHead; p != NULL; p = p->Next() )
@@ -1156,9 +1164,6 @@ bool wxFileConfig::DeleteAll()
                         m_strLocalFile.c_str());
           return false;
       }
-
-      m_strLocalFile =
-      m_strGlobalFile = wxEmptyString;
   }
 
   Init();
@@ -2026,8 +2031,11 @@ static wxString FilterInEntryName(const wxString& str)
   strResult.Alloc(str.Len());
 
   for ( const wxChar *pc = str.c_str(); *pc != '\0'; pc++ ) {
-    if ( *pc == wxT('\\') )
-      pc++;
+    if ( *pc == wxT('\\') ) {
+      // we need to test it here or we'd skip past the NUL in the loop line
+      if ( *++pc == _T('\0') )
+        break;
+    }
 
     strResult += *pc;
   }