TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / core / System / VFS.h
blob71ea1c789c59e1a8c5216eb61c8aeab9f9673a7a
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 /**
22 * @file VFS.h
23 * Compatibility layer for file and dir access functions on Un*x and MS Win
24 * @author The GemRB Project
27 #ifndef VFS_H
28 #define VFS_H
30 #ifndef _MAX_PATH
31 #ifdef WIN32
32 #define _MAX_PATH 260
33 #else
34 #define _MAX_PATH FILENAME_MAX
35 #endif
36 #endif
38 #include "exports.h"
39 #include "globals.h"
41 #include <string>
42 #include <sys/stat.h>
44 #ifdef WIN32
45 #include <direct.h>
46 #include <io.h>
47 #include <windows.h>
48 #endif
50 #ifndef R_OK
51 #define R_OK 04
52 #endif
54 #ifdef WIN32
56 typedef struct _FILE {
57 HANDLE hFile;
58 } _FILE;
60 GEM_EXPORT _FILE* _fopen(const char* filename, const char* mode);
61 GEM_EXPORT size_t _fread(void* ptr, size_t size, size_t n, _FILE* stream);
62 GEM_EXPORT size_t _fwrite(const void* ptr, size_t size, size_t n,
63 _FILE* stream);
64 GEM_EXPORT size_t _fseek(_FILE* stream, long offset, int whence);
65 GEM_EXPORT int _fgetc(_FILE* stream);
66 GEM_EXPORT long int _ftell(_FILE* stream);
67 GEM_EXPORT int _feof(_FILE* stream);
68 GEM_EXPORT int _fclose(_FILE* stream);
69 #define mkdir(path, rights) _mkdir(path)
70 #define ResolveFilePath(p)
72 #else // ! WIN32
74 #define _FILE FILE
75 #define _fopen fopen
76 #define _fread fread
77 #define _fwrite fwrite
78 #define _fseek fseek
79 #define _fgetc fgetc
80 #define _ftell ftell
81 #define _feof feof
82 #define _fclose fclose
84 /** Handle ~ -> $HOME mapping and do initial case-sensitity check */
85 GEM_EXPORT void ResolveFilePath(char* FilePath);
86 GEM_EXPORT void ResolveFilePath(std::string& FilePath);
88 #endif // ! WIN32
90 #ifdef WIN32
91 const char PathDelimiter = '\\';
92 const char PathListSeparator = ';';
93 #else
94 const char PathDelimiter = '/';
95 const char PathListSeparator = ':';
96 #endif
97 const char SPathDelimiter[] = { PathDelimiter, '\0' };
98 const char SPathListSeparator[] = { PathListSeparator, '\0' };
101 * Finds a file matching a glob.
103 * @param[out] target name of matching file
104 * @param[in] Dir directory to look in
105 * @param[in] glob pattern to match
106 * @return true if match is found
108 GEM_EXPORT bool FileGlob(char *target, const char* Dir, const char* glob);
109 GEM_EXPORT bool dir_exists(const char* path);
110 GEM_EXPORT bool file_exists(const char* path);
113 * Joins NULL-terminated list of directories and copies it to 'target'.
115 * @param[out] target Joined path.
116 * @param[in] base Properly cased path to join to.
117 * @param[in] ... NULL terminated list of paths to join.
119 * This does a case-sensitive look up for all path components after the first and
120 * properly handles the case when paramater contain slashes.
122 * NOTE: This no longer handles target==base.
124 * Example:
125 * char filepath[_MAX_PATH];
126 * PathJoin( filepath, core->GUIScriptsPath, core->GameType, 'GUIDefines.py', NULL );
128 GEM_EXPORT bool PathJoin (char* target, const char* base, ...);
129 GEM_EXPORT bool PathJoinExt (char* target, const char* dir, const char* file, const char* ext = NULL);
130 GEM_EXPORT void FixPath (char *path, bool needslash);
132 GEM_EXPORT void ExtractFileFromPath(char *file, const char *full_path);
134 class DirectoryIterator {
135 public:
137 * @param[in] path Path to direcrtory to search.
139 * WARNING: the lifetime of path must be longer than the lifetime
140 * of DirectoryIterator.
142 DirectoryIterator(const char *path);
143 ~DirectoryIterator();
144 bool IsDirectory();
146 * Returns name of current entry.
148 * The returned string is only valid until the iterator is advanced.
149 * FIXME: This should return a const char*
151 char *GetName();
152 void GetFullPath(char *);
153 DirectoryIterator& operator++();
154 #include "operatorbool.h"
155 OPERATOR_BOOL(DirectoryIterator,void,Entry)
156 bool operator !() { return !Entry; }
157 void Rewind();
158 private:
159 void* Directory;
160 void* Entry;
161 const char *Path;
164 #endif // !VFS_H