Revision: 7326
http://mahogany.svn.sourceforge.net/mahogany/?rev=7326&view=rev
Author: vadz
Date: 2007-08-20 15:01:20 -0700 (Mon, 20 Aug 2007)
Log Message:
-----------
fixes for reading files in Unicode build
Modified Paths:
--------------
trunk/M/src/classes/ComposeTemplate.cpp
trunk/M/src/gui/wxComposeView.cpp
Modified: trunk/M/src/classes/ComposeTemplate.cpp
===================================================================
--- trunk/M/src/classes/ComposeTemplate.cpp 2007-08-20 22:00:10 UTC (rev
7325)
+++ trunk/M/src/classes/ComposeTemplate.cpp 2007-08-20 22:01:20 UTC (rev
7326)
@@ -1443,7 +1443,36 @@
wxFileName fn(strSignFile);
fn.MakeAbsolute(mApplication->GetLocalDir());
- hasSign = fileSig.Open(fn.GetFullPath());
+ const wxString path = fn.GetFullPath();
+
+ // interpret the file as Unicode by default in Unicode build
+#if wxUSE_UNICODE
+ {
+ wxLogNull noLog;
+ hasSign = fileSig.Open(path);
+ }
+
+ if ( !hasSign )
+#endif // wxUSE_UNICODE
+ {
+ // but if it fails, use the current locale encoding
+ wxLogNull noLog;
+ hasSign = fileSig.Open(path, wxCSConv(wxFONTENCODING_SYSTEM));
+ }
+
+ if ( !hasSign )
+ {
+ // and if it still fails, try to interpret it as latin1 as
+ // otherwise we'd never be able to read non-UTF-8 files in UTF-8
+ // locale
+ hasSign = fileSig.Open(path, wxConvISO8859_1);
+ }
+
+ if ( !hasSign )
+ {
+ wxLogError(_("Failed to read signature file \"%s\""),
+ path.c_str());
+ }
}
if ( !hasSign )
@@ -1457,7 +1486,7 @@
}
else
{
- // to show message from wxTextFile::Open()
+ // to show error message from wxTextFile::Open()
wxLog *log = wxLog::GetActiveTarget();
if ( log )
log->Flush();
Modified: trunk/M/src/gui/wxComposeView.cpp
===================================================================
--- trunk/M/src/gui/wxComposeView.cpp 2007-08-20 22:00:10 UTC (rev 7325)
+++ trunk/M/src/gui/wxComposeView.cpp 2007-08-20 22:01:20 UTC (rev 7326)
@@ -875,18 +875,40 @@
{
const String& filename = m_part->GetFileName();
wxFile file(filename);
- if ( !file.IsOpened() )
+ wxString content;
+
+ bool ok = file.IsOpened();
+ if ( ok )
{
- wxLogError(_("Failed to open attachment."));
- break;
+ const wxFileOffset len = file.Length();
+ if ( len == 0 )
+ {
+ wxLogWarning(_("Attached file \"%s\" is empty"),
+ filename.c_str());
+ break;
+ }
+
+ if ( len != wxInvalidOffset )
+ {
+ wxCharBuffer buf(len);
+ ok = file.Read(buf.data(), len) != wxInvalidOffset;
+
+ if ( ok )
+ {
+ buf.data()[len] = '\0';
+ content = wxString::From8BitData(buf, len);
+ }
+ }
+ else // len == wxInvalidOffset
+ {
+ ok = false;
+ }
}
- wxString content;
- const wxFileOffset len = file.Length();
- if ( len == wxInvalidOffset ||
- file.Read(wxStringBuffer(content, len + 1), len) != len )
+ if ( !ok )
{
- wxLogError(_("Failed to read attachment data."));
+ wxLogError(_("Failed to get data of attached file \"%s\"."),
+ filename.c_str());
break;
}
@@ -3882,13 +3904,12 @@
{
// read the text from the file
wxString text;
- off_t lenFile = 0; // suppress warning
wxFile file(filename);
bool ok = file.IsOpened();
if ( ok )
{
- lenFile = file.Length();
+ const wxFileOffset lenFile = file.Length();
if ( lenFile == 0 )
{
if ( insMode != MessageEditor::Insert_Replace )
@@ -3899,13 +3920,31 @@
}
//else: replace old text with new (empty) one
}
- else // non empty file
+ else if ( lenFile != wxInvalidOffset ) // non empty file
{
- wxStringBuffer buf(text, lenFile + 1);
- buf[lenFile] = '\0';
+ wxCharBuffer buf(lenFile);
+ ok = file.Read(buf.data(), lenFile) != wxInvalidOffset;
- ok = file.Read(buf, lenFile) != wxInvalidOffset;
+ if ( ok )
+ {
+ buf.data()[lenFile] = '\0';
+#if wxUSE_UNICODE
+ // try to interpret the file contents as Unicode
+ text = wxString(buf, wxConvAuto());
+ if ( text.empty() )
+#endif // wxUSE_UNICODE
+ {
+ // this works whether m_encoding == wxFONTENCODING_SYSTEM (we
+ // use the current locale encoding then) or not (in which case
+ // we use the specified encoding)
+ text = wxString(buf, wxCSConv(m_encoding));
+ }
+ }
}
+ else // lenFile == wxInvalidOffset
+ {
+ ok = false;
+ }
}
if ( !ok )
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates