X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e04487ebe8375d5dae8f61800569fbbb94d2139a..14f8fa9d7fa07b02c276981d135ce73cf6818879:/src/common/fileconf.cpp diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 5c7c706d6e..5ef534169b 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -46,10 +46,12 @@ #include "wx/utils.h" // for wxGetHomeDir -// _WINDOWS_ is defined when windows.h is included, -// __WXMSW__ is defined for MS Windows compilation -#if defined(__WXMSW__) && !defined(_WINDOWS_) - #include +#if defined(__WXMAC__) + #include "wx/mac/private.h" // includes mac headers +#endif + +#if defined(__WXMSW__) + #include "wx/msw/private.h" #endif //windows.h #if defined(__WXPM__) #define INCL_DOS @@ -338,11 +340,11 @@ wxString wxFileConfig::GetLocalFileName(const wxChar *szFile) #ifdef __VMS__ // On VMS I saw the problem that the home directory was appended // twice for the configuration file. Does that also happen for other // platforms? - wxString str = wxT( '.' ); + wxString str = wxT( '.' ); #else wxString str = GetLocalDir(); #endif - + #if defined( __UNIX__ ) && !defined( __VMS ) && !defined( __WXMAC__ ) str << wxT('.'); #endif @@ -674,7 +676,11 @@ void wxFileConfig::Parse(wxTextBuffer& buffer, bool bLocal) while ( wxIsspace(*pEnd) ) pEnd++; - pEntry->SetValue(FilterInValue(pEnd), FALSE /* read from file */); + wxString value = pEnd; + if ( !(GetStyle() & wxCONFIG_USE_NO_ESCAPE_CHARACTERS) ) + value = FilterInValue(value); + + pEntry->SetValue(value, FALSE); } } } @@ -819,8 +825,7 @@ bool wxFileConfig::HasEntry(const wxString& strName) const // read/write values // ---------------------------------------------------------------------------- -bool wxFileConfig::Read(const wxString& key, - wxString* pStr) const +bool wxFileConfig::DoReadString(const wxString& key, wxString* pStr) const { wxConfigPathChanger path(this, key); @@ -829,44 +834,22 @@ bool wxFileConfig::Read(const wxString& key, return FALSE; } - *pStr = ExpandEnvVars(pEntry->Value()); - return TRUE; -} + *pStr = pEntry->Value(); -bool wxFileConfig::Read(const wxString& key, - wxString* pStr, const wxString& defVal) const -{ - wxConfigPathChanger path(this, key); - - wxFileConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name()); - bool ok; - if (pEntry == NULL) { - if( IsRecordingDefaults() ) - ((wxFileConfig *)this)->Write(key,defVal); - *pStr = ExpandEnvVars(defVal); - ok = FALSE; - } - else { - *pStr = ExpandEnvVars(pEntry->Value()); - ok = TRUE; - } - - return ok; + return TRUE; } -bool wxFileConfig::Read(const wxString& key, long *pl) const +bool wxFileConfig::DoReadLong(const wxString& key, long *pl) const { wxString str; if ( !Read(key, & str) ) { return FALSE; } - - *pl = wxAtol(str); - return TRUE; + return str.ToLong(pl) ; } -bool wxFileConfig::Write(const wxString& key, const wxString& szValue) +bool wxFileConfig::DoWriteString(const wxString& key, const wxString& szValue) { wxConfigPathChanger path(this, key); @@ -901,12 +884,9 @@ bool wxFileConfig::Write(const wxString& key, const wxString& szValue) return TRUE; } -bool wxFileConfig::Write(const wxString& key, long lValue) +bool wxFileConfig::DoWriteLong(const wxString& key, long lValue) { - // ltoa() is not ANSI :-( - wxString buf; - buf.Printf(wxT("%ld"), lValue); - return Write(key, buf); + return Write(key, wxString::Format(_T("%ld"), lValue)); } bool wxFileConfig::Flush(bool /* bCurrentOnly */) @@ -925,14 +905,24 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */) wxTempFile file(m_strLocalFile); - if ( !file.IsOpened() ) { + if ( !file.IsOpened() ) + { wxLogError(_("can't open user configuration file.")); return FALSE; } // write all strings to file - for ( wxFileConfigLineList *p = m_linesHead; p != NULL; p = p->Next() ) { - if ( !file.Write(p->Text() + wxTextFile::GetEOL()) ) { + for ( wxFileConfigLineList *p = m_linesHead; p != NULL; p = p->Next() ) + { + wxString line = p->Text(); + line += wxTextFile::GetEOL(); +#if wxUSE_UNICODE + wxCharBuffer buf = wxConvLocal.cWX2MB( line ); + if ( !file.Write( (const char*)buf, strlen( (const char*) buf ) ) ) +#else + if ( !file.Write( line.c_str(), line.Len() ) ) +#endif + { wxLogError(_("can't write user configuration file.")); return FALSE; } @@ -944,7 +934,7 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */) if ( ret ) { FSSpec spec ; - + wxMacFilename2FSSpec( m_strLocalFile , &spec ) ; FInfo finfo ; if ( FSpGetFInfo( &spec , &finfo ) == noErr ) @@ -1591,9 +1581,16 @@ void wxFileConfigEntry::SetValue(const wxString& strValue, bool bUser) m_strValue = strValue; if ( bUser ) { - wxString strVal = FilterOutValue(strValue); + wxString strValFiltered; + if ( Group()->Config()->GetStyle() & wxCONFIG_USE_NO_ESCAPE_CHARACTERS ) { + strValFiltered = strValue; + } + else { + strValFiltered = FilterOutValue(strValue); + } + wxString strLine; - strLine << FilterOutEntryName(m_strName) << wxT('=') << strVal; + strLine << FilterOutEntryName(m_strName) << wxT('=') << strValFiltered; if ( m_pLine != NULL ) { // entry was read from the local config file, just modify the line