]> git.saurik.com Git - wxWidgets.git/commitdiff
added FindFileInPath() (part of an otherwise rejected patch)
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 24 Jul 2006 13:34:26 +0000 (13:34 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 24 Jul 2006 13:34:26 +0000 (13:34 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40266 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/filesys.tex
include/wx/filesys.h
src/common/filesys.cpp

index 8c8b0f62152ea1c40fd0529bff80c1f305a3eb6b..15bfcca767f5bb82cf943d2664b5133240f74195 100644 (file)
@@ -26,12 +26,14 @@ provide access to user-defined virtual file systems.
 
 \latexignore{\rtfignore{\wxheading{Members}}}
 
 
 \latexignore{\rtfignore{\wxheading{Members}}}
 
+
 \membersection{wxFileSystem::wxFileSystem}\label{wxfilesystemwxfilesystem}
 
 \func{}{wxFileSystem}{\void}
 
 Constructor. 
 
 \membersection{wxFileSystem::wxFileSystem}\label{wxfilesystemwxfilesystem}
 
 \func{}{wxFileSystem}{\void}
 
 Constructor. 
 
+
 \membersection{wxFileSystem::AddHandler}\label{wxfilesystemaddhandler}
 
 \func{static void}{AddHandler}{\param{wxFileSystemHandler }{*handler}}
 \membersection{wxFileSystem::AddHandler}\label{wxfilesystemaddhandler}
 
 \func{static void}{AddHandler}{\param{wxFileSystemHandler }{*handler}}
@@ -51,6 +53,7 @@ This is because (a) AddHandler is a static method, and (b) the handlers
 are deleted in wxFileSystem's destructor so that you don't have to
 care about it.
 
 are deleted in wxFileSystem's destructor so that you don't have to
 care about it.
 
+
 \membersection{wxFileSystem::ChangePathTo}\label{wxfilesystemchangepathto}
 
 \func{void}{ChangePathTo}{\param{const wxString\& }{location}, \param{bool }{is\_dir = false}}
 \membersection{wxFileSystem::ChangePathTo}\label{wxfilesystemchangepathto}
 
 \func{void}{ChangePathTo}{\param{const wxString\& }{location}, \param{bool }{is\_dir = false}}
@@ -83,12 +86,14 @@ commands change the path to "dir/subdir/":
   f = fs -> OpenFile("hello.htm"); // opens file 'subdir/folder/hello.htm' !!
 \end{verbatim}
 
   f = fs -> OpenFile("hello.htm"); // opens file 'subdir/folder/hello.htm' !!
 \end{verbatim}
 
+
 \membersection{wxFileSystem::GetPath}\label{wxfilesystemgetpath}
 
 \func{wxString}{GetPath}{\void}
 
 Returns actual path (set by \helpref{ChangePathTo}{wxfilesystemchangepathto}).
 
 \membersection{wxFileSystem::GetPath}\label{wxfilesystemgetpath}
 
 \func{wxString}{GetPath}{\void}
 
 Returns actual path (set by \helpref{ChangePathTo}{wxfilesystemchangepathto}).
 
+
 \membersection{wxFileSystem::FileNameToURL}\label{wxfilesystemfilenametourl}
 
 \func{static wxString}{FileNameToURL}{\param{wxFileName }{filename}}
 \membersection{wxFileSystem::FileNameToURL}\label{wxfilesystemfilenametourl}
 
 \func{static wxString}{FileNameToURL}{\param{wxFileName }{filename}}
@@ -100,6 +105,26 @@ Converts filename into URL.
 \helpref{wxFileSystem::URLToFileName}{wxfilesystemurltofilename},
 \helpref{wxFileName}{wxfilename}
 
 \helpref{wxFileSystem::URLToFileName}{wxfilesystemurltofilename},
 \helpref{wxFileName}{wxfilename}
 
+
+\membersection{wxFileSystem::FindFileInPath}\label{wxfilesystemfindfileinpath}
+
+\func{bool}{FindFileInPath}{\param{wxString }{*str}, \param{const wxChar }{*path}, \param{const wxChar }{*file}}
+
+Looks for the file with the given name \arg{file} in a colon or semi-colon
+(depending on the current platform) separated list of directories in
+\arg{path}. If the file is found in any directory, returns \true and the full
+path of the file in \arg{str}, otherwise returns \false and doesn't modify 
+\arg{str}.
+
+\wxheading{Parameters}
+
+\docparam{str}{Receives the full path of the file, must not be \NULL}
+
+\docparam{path}{\texttt{wxPATH\_SEP}-separated list of directories}
+
+\docparam{file}{the name of the file to look for}
+
+
 \membersection{wxFileSystem::FindFirst}\label{wxfilesystemfindfirst}
 
 \func{wxString}{FindFirst}{\param{const wxString\& }{wildcard}, \param{int }{flags = 0}}
 \membersection{wxFileSystem::FindFirst}\label{wxfilesystemfindfirst}
 
 \func{wxString}{FindFirst}{\param{const wxString\& }{wildcard}, \param{int }{flags = 0}}
@@ -108,12 +133,14 @@ Works like \helpref{wxFindFirstFile}{wxfindfirstfile}. Returns name of the first
 filename (within filesystem's current path) that matches {\it wildcard}. {\it flags} may be one of
 wxFILE (only files), wxDIR (only directories) or 0 (both).
 
 filename (within filesystem's current path) that matches {\it wildcard}. {\it flags} may be one of
 wxFILE (only files), wxDIR (only directories) or 0 (both).
 
+
 \membersection{wxFileSystem::FindNext}\label{wxfilesystemfindnext}
 
 \func{wxString}{FindNext}{\void}
 
 Returns the next filename that matches parameters passed to \helpref{FindFirst}{wxfilesystemfindfirst}.
 
 \membersection{wxFileSystem::FindNext}\label{wxfilesystemfindnext}
 
 \func{wxString}{FindNext}{\void}
 
 Returns the next filename that matches parameters passed to \helpref{FindFirst}{wxfilesystemfindfirst}.
 
+
 \membersection{wxFileSystem::OpenFile}\label{wxfilesystemopenfile}
 
 \func{wxFSFile*}{OpenFile}{\param{const wxString\& }{location}}
 \membersection{wxFileSystem::OpenFile}\label{wxfilesystemopenfile}
 
 \func{wxFSFile*}{OpenFile}{\param{const wxString\& }{location}}
@@ -124,6 +151,7 @@ or NULL if failed. It first tries to open the file in relative scope
 absolute path.  Note that the user is responsible for deleting the returned
 wxFSFile.  
 
 absolute path.  Note that the user is responsible for deleting the returned
 wxFSFile.  
 
+
 \membersection{wxFileSystem::URLToFileName}\label{wxfilesystemurltofilename}
 
 \func{static wxFileName}{URLToFileName}{\param{const wxString\& }{url}}
 \membersection{wxFileSystem::URLToFileName}\label{wxfilesystemurltofilename}
 
 \func{static wxFileName}{URLToFileName}{\param{const wxString\& }{url}}
index ae51b8d7c4742379ac2630331b33618cb714501e..ff06ee7dbdae194c0909a34a79651502fbbbf85f 100644 (file)
@@ -181,6 +181,9 @@ public:
     wxString FindFirst(const wxString& spec, int flags = 0);
     wxString FindNext();
 
     wxString FindFirst(const wxString& spec, int flags = 0);
     wxString FindNext();
 
+    // find a file in a list of directories, returns false if not found
+    bool FindFileInPath(wxString *pStr, const wxChar *path, const wxChar *file);
+
     // Adds FS handler.
     // In fact, this class is only front-end to the FS handlers :-)
     static void AddHandler(wxFileSystemHandler *handler);
     // Adds FS handler.
     // In fact, this class is only front-end to the FS handlers :-)
     static void AddHandler(wxFileSystemHandler *handler);
index 65cc39f1c0e8cf9cdeb1af6d4102e82481b93be3..61ec083da446e7c3728772e64bf26b7faca0f6bb 100644 (file)
@@ -26,6 +26,7 @@
 #include "wx/module.h"
 #include "wx/mimetype.h"
 #include "wx/filename.h"
 #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();
 }
 
     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)
 {
 
 void wxFileSystem::AddHandler(wxFileSystemHandler *handler)
 {