[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [4952] Forbid multibyte characters in filenames
From: |
Greg Chicares |
Subject: |
[lmi-commits] [4952] Forbid multibyte characters in filenames |
Date: |
Sat, 15 May 2010 20:41:54 +0000 |
Revision: 4952
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4952
Author: chicares
Date: 2010-05-15 20:41:53 +0000 (Sat, 15 May 2010)
Log Message:
-----------
Forbid multibyte characters in filenames
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/census_document.cpp
lmi/trunk/illustration_document.cpp
lmi/trunk/mec_document.cpp
lmi/trunk/wx_utility.cpp
lmi/trunk/wx_utility.hpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-05-14 21:40:34 UTC (rev 4951)
+++ lmi/trunk/ChangeLog 2010-05-15 20:41:53 UTC (rev 4952)
@@ -25793,3 +25793,15 @@
xml_serializable.tpp
Prefer contains() and map_lookup() to std::find().
+20100515T2041Z <address@hidden> [706]
+
+ census_document.cpp
+ illustration_document.cpp
+ mec_document.cpp
+ wx_utility.cpp
+ wx_utility.hpp
+Forbid multibyte characters in filenames. See:
+ http://lists.nongnu.org/archive/html/lmi/2009-12/msg00004.html
+ http://lists.nongnu.org/archive/html/lmi/2010-05/msg00023.html
+et seqq.
+
Modified: lmi/trunk/census_document.cpp
===================================================================
--- lmi/trunk/census_document.cpp 2010-05-14 21:40:34 UTC (rev 4951)
+++ lmi/trunk/census_document.cpp 2010-05-15 20:41:53 UTC (rev 4952)
@@ -34,6 +34,7 @@
#include "census_view.hpp"
#include "illustrator.hpp"
#include "miscellany.hpp"
+#include "wx_utility.hpp"
#include <fstream>
@@ -70,7 +71,8 @@
}
else
{
- std::ifstream ifs(filename.c_str());
+ std::string f = ValidateAndConvertFilename(filename);
+ std::ifstream ifs(f.c_str());
if(!ifs)
{
warning()
@@ -117,7 +119,8 @@
bool CensusDocument::DoSaveDocument(wxString const& filename)
{
- std::ofstream ofs(filename.c_str(), ios_out_trunc_binary());
+ std::string f = ValidateAndConvertFilename(filename);
+ std::ofstream ofs(f.c_str(), ios_out_trunc_binary());
doc_.write(ofs);
if(!ofs)
{
Modified: lmi/trunk/illustration_document.cpp
===================================================================
--- lmi/trunk/illustration_document.cpp 2010-05-14 21:40:34 UTC (rev 4951)
+++ lmi/trunk/illustration_document.cpp 2010-05-15 20:41:53 UTC (rev 4952)
@@ -33,6 +33,7 @@
#include "illustration_view.hpp"
#include "illustrator.hpp"
#include "miscellany.hpp"
+#include "wx_utility.hpp"
#include <fstream>
@@ -98,7 +99,8 @@
}
else
{
- std::ifstream ifs(filename.c_str());
+ std::string f = ValidateAndConvertFilename(filename);
+ std::ifstream ifs(f.c_str());
if(!ifs)
{
warning()
@@ -175,7 +177,8 @@
return false;
}
- std::ofstream ofs(filename.c_str(), ios_out_trunc_binary());
+ std::string f = ValidateAndConvertFilename(filename);
+ std::ofstream ofs(f.c_str(), ios_out_trunc_binary());
doc_.write(ofs);
if(!ofs)
{
Modified: lmi/trunk/mec_document.cpp
===================================================================
--- lmi/trunk/mec_document.cpp 2010-05-14 21:40:34 UTC (rev 4951)
+++ lmi/trunk/mec_document.cpp 2010-05-15 20:41:53 UTC (rev 4952)
@@ -32,6 +32,7 @@
#include "alert.hpp"
#include "mec_view.hpp"
#include "miscellany.hpp"
+#include "wx_utility.hpp"
#include <fstream>
@@ -69,7 +70,8 @@
}
else
{
- std::ifstream ifs(filename.c_str());
+ std::string f = ValidateAndConvertFilename(filename);
+ std::ifstream ifs(f.c_str());
if(!ifs)
{
warning()
@@ -118,7 +120,8 @@
bool mec_document::DoSaveDocument(wxString const& filename)
{
- std::ofstream ofs(filename.c_str(), ios_out_trunc_binary());
+ std::string f = ValidateAndConvertFilename(filename);
+ std::ofstream ofs(f.c_str(), ios_out_trunc_binary());
doc_.write(ofs);
if(!ofs)
{
Modified: lmi/trunk/wx_utility.cpp
===================================================================
--- lmi/trunk/wx_utility.cpp 2010-05-14 21:40:34 UTC (rev 4951)
+++ lmi/trunk/wx_utility.cpp 2010-05-15 20:41:53 UTC (rev 4952)
@@ -39,6 +39,7 @@
#include <wx/clipbrd.h>
#include <wx/dataobj.h>
#include <wx/datetime.h>
+#include <wx/msgdlg.h>
#include <wx/utils.h> // wxSafeYield()
#include <wx/window.h>
@@ -292,3 +293,33 @@
return *w;
}
+/// Convert a filename to an NTBS std::string, throwing upon failure.
+///
+/// An operating system might hand an NTMBS or an NTWCS to wx.
+/// When wx hands that in turn to lmi in a context where a
+/// std::basic_fstream is wanted, data loss may occur because
+/// std::basic_fstream requires an NTBS argument--see:
+/// http://lists.nongnu.org/archive/html/lmi/2010-05/msg00023.html
+/// This function throws if that problem would occur.
+
+std::string ValidateAndConvertFilename(wxString const& w)
+{
+ if(w.IsEmpty())
+ {
+ fatal_error() << "Filename is empty." << LMI_FLUSH;
+ }
+ std::string s(w.mb_str());
+ if(s.empty())
+ {
+ wxString x =
+ "Filename '"
+ + w
+ + "' contains multi-byte characters, but only"
+ + " single-byte characters are supported."
+ ;
+ wxMessageBox(x, "Problematic filename");
+ throw hobsons_choice_exception();
+ }
+ return s;
+}
+
Modified: lmi/trunk/wx_utility.hpp
===================================================================
--- lmi/trunk/wx_utility.hpp 2010-05-14 21:40:34 UTC (rev 4951)
+++ lmi/trunk/wx_utility.hpp 2010-05-15 20:41:53 UTC (rev 4952)
@@ -32,6 +32,7 @@
#include <boost/type_traits.hpp>
#include <wx/event.h>
+#include <wx/string.h>
#include <stdexcept>
#include <string>
@@ -138,5 +139,7 @@
wxApp& TheApp();
wxWindow& TopWindow();
+std::string ValidateAndConvertFilename(wxString const&);
+
#endif // wx_utility_hpp
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [4952] Forbid multibyte characters in filenames,
Greg Chicares <=