From 19b7a746414b4da49c74ca66f7cdc4862a501ff0 Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Sat, 3 May 2014 21:19:06 +0800 Subject: [PATCH] Normalize file names before going any further --- src/wraplibxml.cpp | 4 ++-- src/xmlcopyeditor.cpp | 34 ++++++---------------------------- src/xmlcopyeditor.h | 2 +- src/xmldoc.cpp | 33 +++++++++++++++++---------------- src/xmldoc.h | 18 +++++++++--------- 5 files changed, 35 insertions(+), 56 deletions(-) diff --git a/src/wraplibxml.cpp b/src/wraplibxml.cpp index 50d591e..ac90517 100644 --- a/src/wraplibxml.cpp +++ b/src/wraplibxml.cpp @@ -715,8 +715,8 @@ xmlChar *WrapLibxml::xmlFileNameToURL ( const wxString &fileName ) return NULL; wxFileName fn ( fileName ); - fn.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE); - wxString url = fn.GetFullPath(wxPATH_NATIVE); + fn.Normalize(); + wxString url = fn.GetFullPath(); return xmlPathToURI ( ( xmlChar * ) ( const char * ) url.utf8_str() ); } diff --git a/src/xmlcopyeditor.cpp b/src/xmlcopyeditor.cpp index c1e3c76..6414e66 100644 --- a/src/xmlcopyeditor.cpp +++ b/src/xmlcopyeditor.cpp @@ -2983,19 +2983,13 @@ void MyFrame::OnOpen ( wxCommandEvent& event ) break; } -bool MyFrame::openFile ( wxString& fileName, bool largeFile ) +bool MyFrame::openFile ( const wxString &file, bool largeFile ) { -#ifndef __WXMSW__ - // truncate string up to file:/ portion added by GNOME - wxString filePrefix = _T ( "file:" ); - int index = fileName.Find ( filePrefix.c_str() ); - if ( index != -1 ) - { - fileName = fileName.Mid ( ( size_t ) index + filePrefix.Length() ); - } -#endif + wxFileName fn = WrapLibxml::URLToFileName ( file ); + fn.Normalize(); - if ( !wxFileExists ( fileName ) ) + wxString fileName = fn.GetFullPath(); + if ( !fn.IsFileReadable() ) { wxString message; message.Printf ( _ ( "Cannot open %s." ), fileName.c_str() ); @@ -3012,15 +3006,6 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile ) return false; } - wxString directory, name, extension; - wxFileName::SplitPath ( fileName, NULL, &directory, &name, &extension ); - - if ( !extension.empty() ) - { - name += _T ( "." ); - name += extension; - } - wxString wideError; pair posPair; XmlDoc *doc; @@ -3238,21 +3223,16 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile ) #endif doc->setFullFileName ( fileName ); - doc->setShortFileName ( name ); - doc->setDirectory ( directory ); openFileSet.insert ( fileName ); history.AddFileToHistory ( fileName ); updateFileMenu(); - wxFileName ofn ( fileName ); - doc->setLastModified ( ofn.GetModificationTime() ); - mainBook->AddPage ( ( wxWindow * ) doc, name, _T ( "" ) ); + mainBook->AddPage ( ( wxWindow * ) doc, fn.GetFullName(), _T ( "" ) ); } statusProgress ( wxEmptyString ); mainBook->Layout(); - wxFileName fn ( fileName ); doc->setLastModified ( fn.GetModificationTime() ); doc->SetFocus(); @@ -3614,8 +3594,6 @@ void MyFrame::saveAs() openFileSet.erase ( doc->getFullFileName() ); doc->setFullFileName ( path ); - doc->setShortFileName ( name ); - doc->setDirectory ( directory ); history.AddFileToHistory ( path ); // update history updateFileMenu(); diff --git a/src/xmlcopyeditor.h b/src/xmlcopyeditor.h index 211a675..72d68bd 100644 --- a/src/xmlcopyeditor.h +++ b/src/xmlcopyeditor.h @@ -349,7 +349,7 @@ class MyFrame : public wxFrame bool forcePane = false ); // public to allow IPC access - bool openFile ( wxString& fileName, bool largeFile = false ); + bool openFile ( const wxString &fileName, bool largeFile = false ); bool isOpen ( const wxString& fileName ); bool activateTab ( const wxString& fileName ); void reloadTab(); diff --git a/src/xmldoc.cpp b/src/xmldoc.cpp index 0414ced..f114363 100644 --- a/src/xmldoc.cpp +++ b/src/xmldoc.cpp @@ -51,37 +51,38 @@ XmlDoc::XmlDoc ( style ) { } -wxString& XmlDoc::getDirectory() +wxString XmlDoc::getDirectory() { - return directory; + return mFileName.GetPath(); } -wxString& XmlDoc::getFullFileName() + +wxString XmlDoc::getFullFileName() { - return fullFileName; + return mFileName.GetFullPath(); } -wxString& XmlDoc::getShortFileName() + +wxString XmlDoc::getShortFileName() { - return shortFileName; + return mFileName.GetFullName(); } -wxDateTime XmlDoc::getLastModified() + +const wxDateTime& XmlDoc::getLastModified() { return lastModified; } -void XmlDoc::setDirectory ( const wxString& s ) +void XmlDoc::setFullFileName ( const wxString &s ) { - directory = s; + mFileName.Assign ( s ); + mFileName.Normalize(); } -void XmlDoc::setFullFileName ( const wxString& s ) +void XmlDoc::setShortFileName ( const wxString &s ) { - fullFileName = s; + mFileName.SetFullName ( s ); } -void XmlDoc::setShortFileName ( const wxString& s ) -{ - shortFileName = s; -} -void XmlDoc::setLastModified ( wxDateTime dt ) + +void XmlDoc::setLastModified ( const wxDateTime& dt ) { lastModified = dt; } diff --git a/src/xmldoc.h b/src/xmldoc.h index c936cdf..069449d 100644 --- a/src/xmldoc.h +++ b/src/xmldoc.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "xmlctrl.h" class XmlDoc : public XmlCtrl @@ -43,16 +44,15 @@ class XmlDoc : public XmlCtrl const wxPoint& position = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0 ); - wxString& getDirectory(); - wxString& getFullFileName(); - wxString& getShortFileName(); - wxDateTime getLastModified(); - void setDirectory ( const wxString& s ); - void setFullFileName ( const wxString& s ); - void setShortFileName ( const wxString& s ); - void setLastModified ( wxDateTime dt ); + wxString getDirectory(); + wxString getFullFileName(); + wxString getShortFileName(); + const wxDateTime& getLastModified(); + void setFullFileName ( const wxString &s ); + void setShortFileName ( const wxString &s ); + void setLastModified ( const wxDateTime &dt ); private: - wxString directory, fullFileName, shortFileName; + wxFileName mFileName; wxDateTime lastModified; };