Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vfs_util.h
Go to the documentation of this file.
1 /* Copyright (c) 2010 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * helper functions for directory access
25  */
26 
27 #ifndef INCLUDED_VFS_UTIL
28 #define INCLUDED_VFS_UTIL
29 
30 #include "lib/os_path.h"
31 #include "lib/file/vfs/vfs.h"
32 
33 namespace vfs {
34 
35 extern Status GetPathnames(const PIVFS& fs, const VfsPath& path, const wchar_t* filter, VfsPaths& pathnames);
36 
37 /**
38  * called for files in a directory.
39  *
40  * @param pathname full pathname (since CFileInfo only gives the name).
41  * @param fileInfo file information
42  * @param cbData user-specified context
43  * @return INFO::CONTINUE on success; any other value will immediately
44  * be returned to the caller (no more calls will be forthcoming).
45  *
46  * CAVEAT: pathname and fileInfo are only valid until the function
47  * returns!
48  **/
49 typedef Status (*FileCallback)(const VfsPath& pathname, const CFileInfo& fileInfo, const uintptr_t cbData);
50 
52 {
54 };
55 
56 /**
57  * call back for each file in a directory tree
58  *
59  * @param fs
60  * @param path
61  * @param cb See DirCallback
62  * @param cbData
63  * @param pattern that file names must match. '*' and '&' wildcards
64  * are allowed. 0 matches everything.
65  * @param flags @ref DirFlags
66  * @return Status
67  **/
68 extern Status ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const wchar_t* pattern = 0, size_t flags = 0);
69 
70 
71 /**
72  * Determine the next available pathname with a given format.
73  * This is useful when creating new files without overwriting the previous
74  * ones (screenshots are a good example).
75  *
76  * @param fs
77  * @param pathnameFormat Format string for the pathname; must contain one
78  * format specifier for an integer.
79  * Example: "screenshots/screenshot%04d.png"
80  * @param nextNumber in: the first number to try; out: the next number.
81  * If 0, numbers corresponding to existing files are skipped.
82  * @param nextPathname receives the output.
83  **/
84 extern void NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname);
85 
86 } // namespace vfs
87 
88 #endif // #ifndef INCLUDED_VFS_UTIL
void NextNumberedFilename(const PIVFS &fs, const VfsPath &pathnameFormat, size_t &nextNumber, VfsPath &nextPathname)
Determine the next available pathname with a given format.
Definition: vfs_util.cpp:95
shared_ptr< IVFS > PIVFS
Definition: vfs.h:226
Status(* FileCallback)(const VfsPath &pathname, const CFileInfo &fileInfo, const uintptr_t cbData)
called for files in a directory.
Definition: vfs_util.h:49
DirFlags
Definition: vfs_util.h:51
Definition: path.h:75
i64 Status
Error handling system.
Definition: status.h:171
Status ForEachFile(const PIVFS &fs, const VfsPath &startPath, FileCallback cb, uintptr_t cbData, const wchar_t *pattern, size_t flags)
call back for each file in a directory tree
Definition: vfs_util.cpp:58
std::vector< VfsPath > VfsPaths
Definition: vfs_path.h:42
Status GetPathnames(const PIVFS &fs, const VfsPath &path, const wchar_t *filter, VfsPaths &pathnames)
Definition: vfs_util.cpp:40