]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filesys.cpp
Corrected line endings, deps now relative
[wxWidgets.git] / src / common / filesys.cpp
index 5586e348dccdaf35db4e095dc1e67dd9b9fafae0..d335bf7e7a63549af9c4d7f7541498d61f31c641 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "wx/wxprec.h"
 
 
 #include "wx/wxprec.h"
 
-#ifdef __BORDLANDC__
+#ifdef __BORLANDC__
 #pragma hdrstop
 #endif
 
 #pragma hdrstop
 #endif
 
@@ -173,7 +173,8 @@ wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString&
 {
     // location has Unix path separators
     wxString right = ms_root + GetRightLocation(location);
 {
     // 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;
 
     if (!wxFileExists(fn.GetFullPath()))
         return (wxFSFile*) NULL;
@@ -417,7 +418,61 @@ void wxFileSystem::CleanUpHandlers()
     m_Handlers.Clear();
 }
 
     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) ;
+       }
+
+#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 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:
 
 
 ///// Module:
@@ -434,35 +489,35 @@ class wxFileSystemModule : public wxModule
         #if wxUSE_MIMETYPE
             gs_FSMimeFallbacks = new wxFileTypeInfo[6];
             gs_FSMimeFallbacks[0] =
         #if wxUSE_MIMETYPE
             gs_FSMimeFallbacks = new wxFileTypeInfo[6];
             gs_FSMimeFallbacks[0] =
-            wxFileTypeInfo("image/jpeg",
-                           "",
-                           "",
-                           "JPEG image (from fallback)",
-                           "jpg", "jpeg", NULL);
+            wxFileTypeInfo(_T("image/jpeg"),
+                           _T(""),
+                           _T(""),
+                           _T("JPEG image (from fallback)"),
+                           _T("jpg"), _T("jpeg"), NULL);
             gs_FSMimeFallbacks[1] =
             gs_FSMimeFallbacks[1] =
-            wxFileTypeInfo("image/gif",
-                           "",
-                           "",
-                           "GIF image (from fallback)",
-                           "gif", NULL);
+            wxFileTypeInfo(_T("image/gif"),
+                           _T(""),
+                           _T(""),
+                           _T("GIF image (from fallback)"),
+                           _T("gif"), NULL);
             gs_FSMimeFallbacks[2] =
             gs_FSMimeFallbacks[2] =
-            wxFileTypeInfo("image/png",
-                           "",
-                           "",
-                           "PNG image (from fallback)",
-                           "png", NULL);
+            wxFileTypeInfo(_T("image/png"),
+                           _T(""),
+                           _T(""),
+                           _T("PNG image (from fallback)"),
+                           _T("png"), NULL);
             gs_FSMimeFallbacks[3] =
             gs_FSMimeFallbacks[3] =
-            wxFileTypeInfo("image/bmp",
-                           "",
-                           "",
-                           "windows bitmap image (from fallback)",
-                           "bmp", NULL);
+            wxFileTypeInfo(_T("image/bmp"),
+                           _T(""),
+                           _T(""),
+                           _T("windows bitmap image (from fallback)"),
+                           _T("bmp"), NULL);
             gs_FSMimeFallbacks[4] =
             gs_FSMimeFallbacks[4] =
-            wxFileTypeInfo("text/html",
-                           "",
-                           "",
-                           "HTML document (from fallback)",
-                           "htm", "html", NULL);
+            wxFileTypeInfo(_T("text/html"),
+                           _T(""),
+                           _T(""),
+                           _T("HTML document (from fallback)"),
+                           _T("htm"), _T("html"), NULL);
             gs_FSMimeFallbacks[5] =
             // must terminate the table with this!
             wxFileTypeInfo();
             gs_FSMimeFallbacks[5] =
             // must terminate the table with this!
             wxFileTypeInfo();