]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filesys.cpp
i18n files are installed as part of wxBase (and should be ideally part of separate...
[wxWidgets.git] / src / common / filesys.cpp
index 65cc39f1c0e8cf9cdeb1af6d4102e82481b93be3..405598e9c2aca71d01dbfe54cae8f2741a51f9f3 100644 (file)
@@ -26,6 +26,7 @@
 #include "wx/module.h"
 #include "wx/mimetype.h"
 #include "wx/filename.h"
+#include "wx/tokenzr.h"
 
 
 //--------------------------------------------------------------------------------
@@ -447,13 +448,57 @@ wxString wxFileSystem::FindNext()
     else return m_FindFileHandler -> FindNext();
 }
 
+bool wxFileSystem::FindFileInPath(wxString *pStr,
+                                  const wxChar *path,
+                                  const wxChar *basename)
+{
+    // we assume that it's not empty
+    wxCHECK_MSG( !wxIsEmpty(basename), false,
+                _T("empty file name in wxFileSystem::FindFileInPath"));
+
+    // skip path separator in the beginning of the file name if present
+    if ( wxIsPathSeparator(*basename) )
+       basename++;
+
+    wxStringTokenizer tokenizer(path, wxPATH_SEP);
+    while ( tokenizer.HasMoreTokens() )
+    {
+        wxString strFile = tokenizer.GetNextToken();
+        if ( !wxEndsWithPathSeparator(strFile) )
+            strFile += wxFILE_SEP_PATH;
+        strFile += basename;
+
+        wxFSFile *file = OpenFile(strFile);
+        if ( file )
+        {
+            delete file;
+            *pStr = strFile;
+            return true;
+        }
+    }
 
+    return false;
+}
 
 void wxFileSystem::AddHandler(wxFileSystemHandler *handler)
 {
-    m_Handlers.Append(handler);
+    // prepend the handler to the beginning of the list because handlers added
+    // last should have the highest priority to allow overriding them
+    m_Handlers.Insert((size_t)0, handler);
 }
 
+bool wxFileSystem::HasHandlerForPath(const wxString &location)
+{
+    for ( wxList::compatibility_iterator node = m_Handlers.GetFirst();
+           node; node = node->GetNext() )
+    {
+        wxFileSystemHandler *h = (wxFileSystemHandler*) node->GetData();
+        if (h->CanOpen(location))
+            return true;
+    }
+
+    return false;
+}
 
 void wxFileSystem::CleanUpHandlers()
 {