Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
vfs_util.h
Go to the documentation of this file.
1/* Copyright (C) 2015 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
33namespace vfs {
34
35extern 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::OK 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 **/
49typedef Status (*FileCallback)(const VfsPath& pathname, const CFileInfo& fileInfo, const uintptr_t cbData);
50
51/**
52 * called for directories in a directory.
53 *
54 * @param pathname full pathname
55 * @param cbData user-specified context
56 * @return INFO::OK on success; any other value will immediately
57 * be returned to the caller (no more calls will be forthcoming).
58 *
59 * CAVEAT: pathname only valid until the function returns!
60 **/
61typedef Status (*DirCallback)(const VfsPath& pathname, const uintptr_t cbData);
62
64{
66};
67
68/**
69 * call back for each file in a directory tree, and optionally each directory.
70 *
71 * @param fs
72 * @param path
73 * @param cb @ref FileCallback
74 * @param cbData
75 * @param pattern that file names must match. '*' and '&' wildcards
76 * are allowed. 0 matches everything.
77 * @param flags @ref DirFlags
78 * @param dircb @ref DirCallback
79 * @param dircbData
80 * @return Status
81 **/
82extern Status ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const wchar_t* pattern = 0, size_t flags = 0, DirCallback dircb = NULL, uintptr_t dircbData = 0);
83
84
85/**
86 * Determine the next available pathname with a given format.
87 * This is useful when creating new files without overwriting the previous
88 * ones (screenshots are a good example).
89 *
90 * @param fs
91 * @param pathnameFormat Format string for the pathname; must contain one
92 * format specifier for an integer.
93 * Example: "screenshots/screenshot%04d.png"
94 * @param nextNumber in: the first number to try; out: the next number.
95 * If 0, numbers corresponding to existing files are skipped.
96 * @param nextPathname receives the output.
97 **/
98extern void NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname);
99
100} // namespace vfs
101
102#endif // #ifndef INCLUDED_VFS_UTIL
Definition: file_system.h:43
Definition: path.h:80
Definition: pch_boost.h:51
Definition: vfs_util.cpp:39
DirFlags
Definition: vfs_util.h:64
@ DIR_RECURSIVE
Definition: vfs_util.h:65
Status GetPathnames(const PIVFS &fs, const VfsPath &path, const wchar_t *filter, VfsPaths &pathnames)
Definition: vfs_util.cpp:41
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:99
Status ForEachFile(const PIVFS &fs, const VfsPath &startPath, FileCallback cb, uintptr_t cbData, const wchar_t *pattern, size_t flags, DirCallback dircb, uintptr_t dircbData)
call back for each file in a directory tree, and optionally each directory.
Definition: vfs_util.cpp:58
Status(* DirCallback)(const VfsPath &pathname, const uintptr_t cbData)
called for directories in a directory.
Definition: vfs_util.h:61
Status(* FileCallback)(const VfsPath &pathname, const CFileInfo &fileInfo, const uintptr_t cbData)
called for files in a directory.
Definition: vfs_util.h:49
i64 Status
Error handling system.
Definition: status.h:173
std::shared_ptr< IVFS > PIVFS
Definition: vfs.h:220
std::vector< VfsPath > VfsPaths
Definition: vfs_path.h:44