]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filesys.cpp
added FindFileInPath() (part of an otherwise rejected patch)
[wxWidgets.git] / src / common / filesys.cpp
index 65cc39f1c0e8cf9cdeb1af6d4102e82481b93be3..61ec083da446e7c3728772e64bf26b7faca0f6bb 100644 (file)
@@ -26,6 +26,7 @@
 #include "wx/module.h"
 #include "wx/mimetype.h"
 #include "wx/filename.h"
+#include "wx/tokenzr.h"
 
 
 //--------------------------------------------------------------------------------
@@ -447,7 +448,37 @@ 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)
 {