From 21905d7265b6891f9c92c68c05399ea12fb23ba0 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 3 Dec 2002 13:55:44 +0000 Subject: [PATCH] Fixed a bug in virtual filesystem by converting to native filename when necessary. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/publicity/publicity.txt | 12 ++++++++ include/wx/filesys.h | 7 +++++ src/common/filesys.cpp | 54 +++++++++++++++++++++++++++++++++++- src/common/fs_zip.cpp | 4 ++- 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/docs/publicity/publicity.txt b/docs/publicity/publicity.txt index 565119023c..81eaa5841e 100644 --- a/docs/publicity/publicity.txt +++ b/docs/publicity/publicity.txt @@ -28,6 +28,18 @@ comp.windows.x comp.windows.x.announce comp.windows.x.motif +Note: submissions to comp.windows.linux.announce must be +sent to cola@stump.algebra.com, with short descr +of software and location. See http://stump.algebra.com/~cola/ +NO CROSSPOSTING when sending to this address. + +Pack plenty information into the subject. +Don't write a subject like "Foo version 1.1 released". Many +people will not know what Foo is, so the subject won't help them +select articles. Instead, say "Foo 1.1 - copy files more +efficiently than cp". There is no need to say that the article +is an announcement, so don't write a subject like "ANNOUNCEMENT: +Foo version 1.1 released". News and links sites: ----------------------- diff --git a/include/wx/filesys.h b/include/wx/filesys.h index b8e5da0927..b819282152 100644 --- a/include/wx/filesys.h +++ b/include/wx/filesys.h @@ -180,6 +180,13 @@ public: // remove all items from the m_Handlers list static void CleanUpHandlers(); + // Returns the native path for a file URL + static wxString URLToNativePath( const wxString& url ); + + // Returns the file URL for a native path + static wxString NativePathToURL( const wxString& path ); + + protected: wxString m_Path; // the path (location) we are currently in diff --git a/src/common/filesys.cpp b/src/common/filesys.cpp index c2c0e8110a..8e26b5d904 100644 --- a/src/common/filesys.cpp +++ b/src/common/filesys.cpp @@ -173,7 +173,8 @@ wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& { // location has Unix path separators wxString right = ms_root + GetRightLocation(location); - wxFileName fn(right, wxPATH_UNIX); + wxString nativePath = wxFileSystem::URLToNativePath(right); + wxFileName fn(nativePath, wxPATH_UNIX); if (!wxFileExists(fn.GetFullPath())) return (wxFSFile*) NULL; @@ -417,7 +418,58 @@ void wxFileSystem::CleanUpHandlers() m_Handlers.Clear(); } +const static wxString g_unixPathString(wxT("/")); +const static wxString g_nativePathString(wxFILE_SEP_PATH); +// Returns the native path for a file URL +wxString wxFileSystem::URLToNativePath( const wxString& url ) +{ + wxString path = url ; + + if ( path.Find(wxT("file://")) == 0 ) + { + path = path.Mid(7) ; + } + + // file urls either start with a forward slash (local harddisk), + // otherwise they have a servername/sharename notation, + // which only exists on msw and corresponds to a unc + if ( path[0u] == wxT('/') && path [1u] != wxT('/')) + { + path = path.Mid(1) ; + } +#ifdef __WXMSW__ + else if ( (url.Find(wxT("file://")) == 0) && + (path.Find(wxT('/')) != wxNOT_FOUND) && + (path.Length() > 1) && (path[1u] != wxT(':')) ) + { + path = wxT("\\\\") + path ; + } +#endif + path.Replace(g_unixPathString, g_nativePathString) ; + + return path ; +} + +// Returns the file URL for a native path +wxString wxFileSystem::NativePathToURL( const wxString& path ) +{ + wxString url = path ; +#ifdef __WXMSW__ + // unc notation + if ( url.Find(wxT("\\\\")) == 0 ) + { + url = url.Mid(2) ; + } + else +#endif + { + url = wxT("/") + url ; + } + url.Replace(g_nativePathString, g_unixPathString) ; + url = wxT("file://") + url ; + return url ; +} ///// Module: diff --git a/src/common/fs_zip.cpp b/src/common/fs_zip.cpp index cf0a49cb65..18d421b7be 100644 --- a/src/common/fs_zip.cpp +++ b/src/common/fs_zip.cpp @@ -89,7 +89,9 @@ wxFSFile* wxZipFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& l if (right.GetChar(0) == wxT('/')) right = right.Mid(1); - s = new wxZipInputStream(left, right); + wxString leftFilename = wxFileSystem::URLToNativePath(left); + + s = new wxZipInputStream(leftFilename, right); if (s && s->IsOk() ) { return new wxFSFile(s,