added FindFileInPath() (part of an otherwise rejected patch)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40266 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-07-24 13:34:26 +00:00
parent 591087eda4
commit 3ab6fcee36
3 changed files with 62 additions and 0 deletions

View 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} \membersection{wxFileSystem::wxFileSystem}\label{wxfilesystemwxfilesystem}
\func{}{wxFileSystem}{\void} \func{}{wxFileSystem}{\void}
Constructor. Constructor.
\membersection{wxFileSystem::AddHandler}\label{wxfilesystemaddhandler} \membersection{wxFileSystem::AddHandler}\label{wxfilesystemaddhandler}
\func{static void}{AddHandler}{\param{wxFileSystemHandler }{*handler}} \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 are deleted in wxFileSystem's destructor so that you don't have to
care about it. care about it.
\membersection{wxFileSystem::ChangePathTo}\label{wxfilesystemchangepathto} \membersection{wxFileSystem::ChangePathTo}\label{wxfilesystemchangepathto}
\func{void}{ChangePathTo}{\param{const wxString\& }{location}, \param{bool }{is\_dir = false}} \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' !! f = fs -> OpenFile("hello.htm"); // opens file 'subdir/folder/hello.htm' !!
\end{verbatim} \end{verbatim}
\membersection{wxFileSystem::GetPath}\label{wxfilesystemgetpath} \membersection{wxFileSystem::GetPath}\label{wxfilesystemgetpath}
\func{wxString}{GetPath}{\void} \func{wxString}{GetPath}{\void}
Returns actual path (set by \helpref{ChangePathTo}{wxfilesystemchangepathto}). Returns actual path (set by \helpref{ChangePathTo}{wxfilesystemchangepathto}).
\membersection{wxFileSystem::FileNameToURL}\label{wxfilesystemfilenametourl} \membersection{wxFileSystem::FileNameToURL}\label{wxfilesystemfilenametourl}
\func{static wxString}{FileNameToURL}{\param{wxFileName }{filename}} \func{static wxString}{FileNameToURL}{\param{wxFileName }{filename}}
@@ -100,6 +105,26 @@ Converts filename into URL.
\helpref{wxFileSystem::URLToFileName}{wxfilesystemurltofilename}, \helpref{wxFileSystem::URLToFileName}{wxfilesystemurltofilename},
\helpref{wxFileName}{wxfilename} \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} \membersection{wxFileSystem::FindFirst}\label{wxfilesystemfindfirst}
\func{wxString}{FindFirst}{\param{const wxString\& }{wildcard}, \param{int }{flags = 0}} \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 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). wxFILE (only files), wxDIR (only directories) or 0 (both).
\membersection{wxFileSystem::FindNext}\label{wxfilesystemfindnext} \membersection{wxFileSystem::FindNext}\label{wxfilesystemfindnext}
\func{wxString}{FindNext}{\void} \func{wxString}{FindNext}{\void}
Returns the next filename that matches parameters passed to \helpref{FindFirst}{wxfilesystemfindfirst}. Returns the next filename that matches parameters passed to \helpref{FindFirst}{wxfilesystemfindfirst}.
\membersection{wxFileSystem::OpenFile}\label{wxfilesystemopenfile} \membersection{wxFileSystem::OpenFile}\label{wxfilesystemopenfile}
\func{wxFSFile*}{OpenFile}{\param{const wxString\& }{location}} \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 absolute path. Note that the user is responsible for deleting the returned
wxFSFile. wxFSFile.
\membersection{wxFileSystem::URLToFileName}\label{wxfilesystemurltofilename} \membersection{wxFileSystem::URLToFileName}\label{wxfilesystemurltofilename}
\func{static wxFileName}{URLToFileName}{\param{const wxString\& }{url}} \func{static wxFileName}{URLToFileName}{\param{const wxString\& }{url}}

View File

@@ -181,6 +181,9 @@ public:
wxString FindFirst(const wxString& spec, int flags = 0); wxString FindFirst(const wxString& spec, int flags = 0);
wxString FindNext(); 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. // Adds FS handler.
// In fact, this class is only front-end to the FS handlers :-) // In fact, this class is only front-end to the FS handlers :-)
static void AddHandler(wxFileSystemHandler *handler); static void AddHandler(wxFileSystemHandler *handler);

View File

@@ -26,6 +26,7 @@
#include "wx/module.h" #include "wx/module.h"
#include "wx/mimetype.h" #include "wx/mimetype.h"
#include "wx/filename.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)
{ {