]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filesys.cpp
changing guard to support popupwindows as well
[wxWidgets.git] / src / common / filesys.cpp
index 8488c57702c1e87e896e9eb63852a1560314fe2f..038e55407fb989b4b18b83a29f7c535414c3bdaf 100644 (file)
@@ -27,6 +27,7 @@
 #include "wx/mimetype.h"
 #include "wx/filename.h"
 #include "wx/tokenzr.h"
+#include "wx/uri.h"
 #include "wx/private/fileback.h"
 
 // ----------------------------------------------------------------------------
@@ -518,16 +519,19 @@ wxString wxFileSystem::FindNext()
 }
 
 bool wxFileSystem::FindFileInPath(wxString *pStr,
-                                  const wxChar *path,
-                                  const wxChar *basename)
+                                  const wxString& path,
+                                  const wxString& basename)
 {
     // we assume that it's not empty
-    wxCHECK_MSG( !wxIsEmpty(basename), false,
+    wxCHECK_MSG( !basename.empty(), false,
                 _T("empty file name in wxFileSystem::FindFileInPath"));
 
+    wxString name;
     // skip path separator in the beginning of the file name if present
-    if ( wxIsPathSeparator(*basename) )
-       basename++;
+    if ( wxIsPathSeparator(basename[0u]) )
+        name = basename.substr(1);
+    else
+        name = basename;
 
     wxStringTokenizer tokenizer(path, wxPATH_SEP);
     while ( tokenizer.HasMoreTokens() )
@@ -535,7 +539,7 @@ bool wxFileSystem::FindFileInPath(wxString *pStr,
         wxString strFile = tokenizer.GetNextToken();
         if ( !wxEndsWithPathSeparator(strFile) )
             strFile += wxFILE_SEP_PATH;
-        strFile += basename;
+        strFile += name;
 
         wxFSFile *file = OpenFile(strFile);
         if ( file )
@@ -610,8 +614,7 @@ wxFileName wxFileSystem::URLToFileName(const wxString& url)
         path = path.Mid(2);
 #endif
 
-    path.Replace(wxT("%25"), wxT("%"));
-    path.Replace(wxT("%3A"), wxT(":"));
+    path = wxURI::Unescape(path);
 
 #ifdef __WXMSW__
     // file urls either start with a forward slash (local harddisk),
@@ -658,7 +661,8 @@ wxString wxFileSystem::FileNameToURL(const wxFileName& filename)
 #endif
 
     url.Replace(g_nativePathString, g_unixPathString);
-    url.Replace(wxT("%"), wxT("%25"));
+    url.Replace(wxT("%"), wxT("%25")); // '%'s must be replaced first!
+    url.Replace(wxT("#"), wxT("%23"));
     url.Replace(wxT(":"), wxT("%3A"));
     url = wxT("file:") + url;
     return url;