2007-11-10 14:39:45 +01:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
2007-12-20 21:14:21 +01:00
|
|
|
* File : file_system_util.h
|
2007-11-10 14:39:45 +01:00
|
|
|
* Project : 0 A.D.
|
2007-12-01 19:32:43 +01:00
|
|
|
* Description : helper functions for directory access
|
2007-11-10 14:39:45 +01:00
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// license: GPL; see lib/license.txt
|
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
#ifndef INCLUDED_FILE_SYSTEM_UTIL
|
|
|
|
#define INCLUDED_FILE_SYSTEM_UTIL
|
2007-11-10 14:39:45 +01:00
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
#include "lib/file/vfs/vfs.h"
|
2007-11-10 14:39:45 +01:00
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
extern void fs_SortFiles(FileInfos& files);
|
|
|
|
extern void fs_SortDirectories(DirectoryNames& directories);
|
|
|
|
|
2008-07-12 12:45:11 +02:00
|
|
|
extern LibError fs_GetPathnames(const PIVFS& fs, const VfsPath& path, const char* filter, VfsPaths& pathnames);
|
2007-11-10 14:39:45 +01:00
|
|
|
|
2007-11-20 19:51:07 +01:00
|
|
|
|
|
|
|
/**
|
2007-12-01 19:32:43 +01:00
|
|
|
* called for files in a directory.
|
|
|
|
*
|
|
|
|
* @param pathname full pathname (since FileInfo only gives the name).
|
|
|
|
* @param fileInfo file information
|
|
|
|
* @param cbData user-specified context
|
|
|
|
* @return INFO::CB_CONTINUE on success; any other value will immediately
|
|
|
|
* be returned to the caller (no more calls will be forthcoming).
|
|
|
|
*
|
|
|
|
* CAVEAT: pathname and fileInfo are only valid until the function
|
|
|
|
* returns!
|
2007-11-20 19:51:07 +01:00
|
|
|
**/
|
2007-12-20 21:14:21 +01:00
|
|
|
typedef LibError (*FileCallback)(const VfsPath& pathname, const FileInfo& fileInfo, const uintptr_t cbData);
|
2007-11-10 14:39:45 +01:00
|
|
|
|
2007-12-01 19:32:43 +01:00
|
|
|
enum DirFlags
|
2007-11-10 14:39:45 +01:00
|
|
|
{
|
2007-12-20 21:14:21 +01:00
|
|
|
DIR_RECURSIVE = 1
|
2007-11-10 14:39:45 +01:00
|
|
|
};
|
|
|
|
|
2007-12-01 19:32:43 +01:00
|
|
|
/**
|
2007-12-20 21:14:21 +01:00
|
|
|
* call back for each file in a directory tree
|
2007-12-01 19:32:43 +01:00
|
|
|
*
|
|
|
|
* @param cb see DirCallback
|
|
|
|
* @param pattern that file names must match. '*' and '&' wildcards
|
|
|
|
* are allowed. 0 matches everything.
|
|
|
|
* @param flags see DirFlags
|
|
|
|
* @param LibError
|
|
|
|
**/
|
2008-07-12 12:45:11 +02:00
|
|
|
extern LibError fs_ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern = 0, int flags = 0);
|
2007-11-10 14:39:45 +01:00
|
|
|
|
|
|
|
|
2007-12-01 19:32:43 +01:00
|
|
|
/**
|
|
|
|
* determine the next available pathname with a given format.
|
|
|
|
* this is useful when creating new files without overwriting the previous
|
|
|
|
* ones (screenshots are a good example).
|
|
|
|
*
|
2008-01-07 21:03:19 +01:00
|
|
|
* @param pathnameFormat format string for the pathname; must contain one
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
* format specifier for a size_t.
|
2007-12-01 19:32:43 +01:00
|
|
|
* example: "screenshots/screenshot%04d.png"
|
|
|
|
* @param nextNumber in: the first number to try; out: the next number.
|
|
|
|
* if 0, numbers corresponding to existing files are skipped.
|
2008-01-07 21:03:19 +01:00
|
|
|
* @param nextPathname receives the output.
|
2007-12-01 19:32:43 +01:00
|
|
|
**/
|
2008-07-12 12:45:11 +02:00
|
|
|
extern void fs_NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname);
|
2007-11-10 14:39:45 +01:00
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
#endif // #ifndef INCLUDED_FILE_SYSTEM_UTIL
|