]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filesys.cpp
Applied patch [ 649284 ] Fix wxODBC to work with MySQL 2.x
[wxWidgets.git] / src / common / filesys.cpp
index 93b65254dd35fd1dbf554a75c00eb68c0d35b85b..5ed5a520d03fb2ba2a3d3310b5b60b2ddac5ca88 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "wx/wxprec.h"
 
-#ifdef __BORDLANDC__
+#ifdef __BORLANDC__
 #pragma hdrstop
 #endif
 
@@ -173,7 +173,7 @@ wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString&
 {
     // location has Unix path separators
     wxString right = ms_root + GetRightLocation(location);
-    wxFileName fn(right, wxPATH_UNIX);
+    wxFileName fn = wxFileSystem::URLToFileName(right);
 
     if (!wxFileExists(fn.GetFullPath()))
         return (wxFSFile*) NULL;
@@ -189,7 +189,8 @@ wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString&
 wxString wxLocalFSHandler::FindFirst(const wxString& spec, int flags)
 {
     wxString right = ms_root + GetRightLocation(spec);
-    return wxFindFirstFile(right, flags);
+    return wxFindFirstFile(wxFileSystem::URLToFileName(right).GetFullPath(),
+                           flags);
 }
 
 wxString wxLocalFSHandler::FindNext()
@@ -417,7 +418,63 @@ 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
+wxFileName wxFileSystem::URLToFileName(const wxString& url)
+{
+       wxString path = url;
+
+       if ( path.Find(wxT("file://")) == 0 )
+       {
+               path = path.Mid(7);
+       }
+
+#ifndef __UNIX__
+       // 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);
+       }
+       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 wxFileName(path, wxPATH_NATIVE);
+}
+
+// Returns the file URL for a native path
+wxString wxFileSystem::FileNameToURL(const wxFileName& filename)
+{
+    wxFileName fn = filename;
+    fn.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE);
+    wxString url = fn.GetFullPath(wxPATH_NATIVE);
+
+#ifdef __WXMSW__
+    // unc notation
+    if ( url.Find(wxT("\\\\")) == 0 ) 
+    {
+        url = url.Mid(2);
+    }
+    else
+    {
+        url = wxT("/") + url;
+    }
+#endif
+
+    url.Replace(g_nativePathString, g_unixPathString);
+    url = wxT("file://") + url;
+    return url;
+}
 
 
 ///// Module: