2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined(INCLUDED_IFILESYSTEM_H)
23 #define INCLUDED_IFILESYSTEM_H
26 #include "generic/constant.h"
28 template<typename FirstArgument>
30 typedef Callback1<const char*> ArchiveNameCallback;
31 typedef Callback1<const char*> FileNameCallback;
34 class ArchiveTextFile;
39 typedef struct _GSList GSList;
41 /// The Virtual File System.
42 class VirtualFileSystem
45 INTEGER_CONSTANT(Version, 1);
46 STRING_CONSTANT(Name, "VFS");
48 /// \brief Adds a root search \p path.
49 /// Called before \c initialise.
50 virtual void initDirectory(const char *path) = 0;
51 /// \brief Initialises the filesystem.
52 /// Called after all root search paths have been added.
53 virtual void initialise() = 0;
54 /// \brief Shuts down the filesystem.
55 virtual void shutdown() = 0;
57 /// \brief Returns the file identified by \p filename opened in binary mode, or 0 if not found.
58 /// The caller must \c release() the file returned if it is not 0.
59 virtual ArchiveFile* openFile(const char* filename) = 0;
60 /// \brief Returns the file identified by \p filename opened in text mode, or 0 if not found.
61 /// The caller must \c release() the file returned if it is not 0.
62 virtual ArchiveTextFile* openTextFile(const char* filename) = 0;
64 /// \brief Opens the file identified by \p filename and reads it into \p buffer, or sets *\p buffer to 0 if not found.
65 /// Returns the size of the buffer allocated, or undefined value if *\p buffer is 0;
66 /// The caller must free the allocated buffer by calling \c freeFile
67 /// \deprecated Deprecated - use \c openFile.
68 virtual std::size_t loadFile(const char *filename, void **buffer) = 0;
69 /// \brief Frees the buffer returned by \c loadFile.
70 /// \deprecated Deprecated.
71 virtual void freeFile(void *p) = 0;
73 /// \brief Calls \p callback for each directory under \p basedir.
74 virtual void forEachDirectory(const char* basedir, const FileNameCallback& callback, std::size_t depth = 1) = 0;
75 /// \brief Calls \p callback for each file under \p basedir matching \p extension.
76 /// Use "*" as \p extension to match all file extensions.
77 virtual void forEachFile(const char* basedir, const char* extension, const FileNameCallback& callback, std::size_t depth = 1) = 0;
79 /// \brief Returns a list containing the relative names of all the directories under \p basedir.
80 /// The caller must free the returned list by calling \c clearFileDirList;
81 /// \deprecated Deprecated - use \c forEachDirectory.
82 virtual GSList* getDirList(const char *basedir) = 0;
83 /// \brief Returns a list containing the relative names of the files under \p basedir (\p extension can be "*" for all files).
84 /// The caller must free the returned list by calling \c clearFileDirList.
85 /// \deprecated Deprecated - use \c forEachFile.
86 virtual GSList* getFileList(const char *basedir, const char *extension) = 0;
87 /// \brief Frees the \p list returned from \c getDirList or \c getFileList.
88 /// \deprecated Deprecated.
89 virtual void clearFileDirList(GSList **list) = 0;
91 /// \brief Returns the absolute filename for a relative \p name, or "" if not found.
92 virtual const char* findFile(const char* name) = 0;
93 /// \brief Returns the filesystem root for an absolute \p name, or "" if not found.
94 /// This can be used to convert an absolute name to a relative name.
95 virtual const char* findRoot(const char* name) = 0;
97 /// \brief Attach an \p observer whose realise() and unrealise() methods will be called when the filesystem is initialised or shut down.
98 virtual void attach(ModuleObserver& observer) = 0;
99 /// \brief Detach an \p observer previously-attached by calling \c attach.
100 virtual void detach(ModuleObserver& observer) = 0;
102 virtual Archive* getArchive(const char* archiveName) = 0;
103 virtual void forEachArchive(const ArchiveNameCallback& callback) = 0;
106 #include "modulesystem.h"
108 template<typename Type>
110 typedef GlobalModule<VirtualFileSystem> GlobalFileSystemModule;
112 template<typename Type>
113 class GlobalModuleRef;
114 typedef GlobalModuleRef<VirtualFileSystem> GlobalFileSystemModuleRef;
116 inline VirtualFileSystem& GlobalFileSystem()
118 return GlobalFileSystemModule::getTable();
122 /// \deprecated Use \c openFile.
123 inline int vfsLoadFile(const char* filename, void** buffer, int index = 0)
125 return static_cast<int>(GlobalFileSystem().loadFile(filename, buffer));
128 /// \deprecated Deprecated.
129 inline void vfsFreeFile(void* p)
131 GlobalFileSystem().freeFile(p);