X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a3a584a7a6ade199990dd4463488e4bbf3545349..6363699a2849533e011a1757b46b33ecf1a54e57:/src/common/textfile.cpp?ds=sidebyside diff --git a/src/common/textfile.cpp b/src/common/textfile.cpp index f0e08b4012..5f4dd6a268 100644 --- a/src/common/textfile.cpp +++ b/src/common/textfile.cpp @@ -31,13 +31,14 @@ #if wxUSE_TEXTFILE #ifndef WX_PRECOMP - #include "wx/string.h" - #include "wx/intl.h" - #include "wx/file.h" - #include "wx/log.h" + #include "wx/string.h" + #include "wx/intl.h" + #include "wx/file.h" + #include "wx/log.h" #endif #include "wx/textfile.h" +#include "wx/filename.h" // ============================================================================ // wxTextFile class implementation @@ -61,20 +62,22 @@ bool wxTextFile::OnExists() const bool wxTextFile::OnOpen(const wxString &strBufferName, wxTextBufferOpenMode OpenMode) { - wxFile::OpenMode FileOpenMode = wxFile::read; - - switch (OpenMode) - { + wxFile::OpenMode FileOpenMode; + + switch ( OpenMode ) + { + default: + wxFAIL_MSG( _T("unknown open mode in wxTextFile::Open") ); + // fall through + case ReadAccess : FileOpenMode = wxFile::read; break; + case WriteAccess : FileOpenMode = wxFile::write; break; - default : - wxASSERT(0); // Should not happen. - break; - } + } return m_file.Open(strBufferName.c_str(), FileOpenMode); } @@ -136,6 +139,7 @@ bool wxTextFile::OnRead(wxMBConv& conv) AddLine(str, wxTextFileType_Mac); chLast = ch; #if wxUSE_UNICODE + conv_mbBuf[0] = ch; if (conv.MB2WC(conv_wcBuf, conv_mbBuf, 2) == (size_t)-1) conv_wcBuf[0] = ch; str = conv_wcBuf[0]; @@ -146,6 +150,7 @@ bool wxTextFile::OnRead(wxMBConv& conv) else { // add to the current line #if wxUSE_UNICODE + conv_mbBuf[0] = ch; if (conv.MB2WC(conv_wcBuf, conv_mbBuf, 2) == (size_t)-1) conv_wcBuf[0] = ch; str += conv_wcBuf[0]; @@ -168,7 +173,11 @@ bool wxTextFile::OnRead(wxMBConv& conv) bool wxTextFile::OnWrite(wxTextFileType typeNew, wxMBConv& conv) { - wxTempFile fileTmp(m_strBufferName); + wxFileName fn = m_strBufferName; + if ( !fn.IsAbsolute() ) + fn.Normalize(); + + wxTempFile fileTmp(fn.GetFullPath()); if ( !fileTmp.IsOpened() ) { wxLogError(_("can't write buffer '%s' to disk."), m_strBufferName.c_str());