modifications to URL<->filename conversion: take wxFileName, rename

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18116 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2002-12-08 20:28:12 +00:00
parent ec75d791f0
commit 9548c49a6a
3 changed files with 33 additions and 29 deletions

View File

@@ -29,6 +29,7 @@
#include "wx/stream.h" #include "wx/stream.h"
#include "wx/url.h" #include "wx/url.h"
#include "wx/datetime.h" #include "wx/datetime.h"
#include "wx/filename.h"
class wxFSFile; class wxFSFile;
class wxFileSystemHandler; class wxFileSystemHandler;
@@ -181,10 +182,10 @@ public:
static void CleanUpHandlers(); static void CleanUpHandlers();
// Returns the native path for a file URL // Returns the native path for a file URL
static wxString URLToNativePath( const wxString& url ); static wxFileName URLToFileName(const wxString& url);
// Returns the file URL for a native path // Returns the file URL for a native path
static wxString NativePathToURL( const wxString& path ); static wxString FileNameToURL(const wxFileName& filename);
protected: protected:

View File

@@ -173,8 +173,7 @@ wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString&
{ {
// location has Unix path separators // location has Unix path separators
wxString right = ms_root + GetRightLocation(location); wxString right = ms_root + GetRightLocation(location);
wxString nativePath = wxFileSystem::URLToNativePath(right); wxFileName fn = wxFileSystem::URLToFileName(right);
wxFileName fn(nativePath, wxPATH_UNIX);
if (!wxFileExists(fn.GetFullPath())) if (!wxFileExists(fn.GetFullPath()))
return (wxFSFile*) NULL; return (wxFSFile*) NULL;
@@ -190,7 +189,8 @@ wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString&
wxString wxLocalFSHandler::FindFirst(const wxString& spec, int flags) wxString wxLocalFSHandler::FindFirst(const wxString& spec, int flags)
{ {
wxString right = ms_root + GetRightLocation(spec); wxString right = ms_root + GetRightLocation(spec);
return wxFindFirstFile(right, flags); return wxFindFirstFile(wxFileSystem::URLToFileName(right).GetFullPath(),
flags);
} }
wxString wxLocalFSHandler::FindNext() wxString wxLocalFSHandler::FindNext()
@@ -422,7 +422,7 @@ const static wxString g_unixPathString(wxT("/"));
const static wxString g_nativePathString(wxFILE_SEP_PATH); const static wxString g_nativePathString(wxFILE_SEP_PATH);
// Returns the native path for a file URL // Returns the native path for a file URL
wxString wxFileSystem::URLToNativePath( const wxString& url ) wxFileName wxFileSystem::URLToFileName(const wxString& url)
{ {
wxString path = url; wxString path = url;
@@ -449,13 +449,15 @@ wxString wxFileSystem::URLToNativePath( const wxString& url )
path.Replace(g_unixPathString, g_nativePathString); path.Replace(g_unixPathString, g_nativePathString);
return path ; return wxFileName(path, wxPATH_NATIVE);
} }
// Returns the file URL for a native path // Returns the file URL for a native path
wxString wxFileSystem::NativePathToURL( const wxString& path ) wxString wxFileSystem::FileNameToURL(const wxFileName& filename)
{ {
wxString url = path ; wxFileName fn = filename;
fn.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE);
wxString url = fn.GetFullPath(wxPATH_NATIVE);
#ifdef __WXMSW__ #ifdef __WXMSW__
// unc notation // unc notation
@@ -464,10 +466,10 @@ wxString wxFileSystem::NativePathToURL( const wxString& path )
url = url.Mid(2); url = url.Mid(2);
} }
else else
#endif
{ {
url = wxT("/") + url; url = wxT("/") + url;
} }
#endif
url.Replace(g_nativePathString, g_unixPathString); url.Replace(g_nativePathString, g_unixPathString);
url = wxT("file://") + url; url = wxT("file://") + url;

View File

@@ -89,9 +89,9 @@ wxFSFile* wxZipFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& l
if (right.GetChar(0) == wxT('/')) right = right.Mid(1); if (right.GetChar(0) == wxT('/')) right = right.Mid(1);
wxString leftFilename = wxFileSystem::URLToNativePath(left); wxFileName leftFilename = wxFileSystem::URLToFileName(left);
s = new wxZipInputStream(leftFilename, right); s = new wxZipInputStream(leftFilename.GetFullPath(), right);
if (s && s->IsOk() ) if (s && s->IsOk() )
{ {
return new wxFSFile(s, return new wxFSFile(s,
@@ -137,7 +137,8 @@ wxString wxZipFSHandler::FindFirst(const wxString& spec, int flags)
} }
m_ZipFile = left; m_ZipFile = left;
m_Archive = (void*) unzOpen(m_ZipFile.mb_str()); wxString nativename = wxFileSystem::URLToFileName(m_ZipFile).GetFullPath();
m_Archive = (void*) unzOpen(nativename.mb_str());
m_Pattern = right.AfterLast(wxT('/')); m_Pattern = right.AfterLast(wxT('/'));
m_BaseDir = right.BeforeLast(wxT('/')); m_BaseDir = right.BeforeLast(wxT('/'));