]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/ifilesystem.h
misc fixes
[xonotic/netradiant.git] / include / ifilesystem.h
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
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.
11
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.
16
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
20 */
21
22 #ifndef _IFILESYSTEM_H_
23 #define _IFILESYSTEM_H_
24
25 //
26 // Plugin interface for the virtual filesystem used by Radiant
27 //
28
29 // NOTE: If you want to write a VFS plugin then you must export
30 // "QERPlug_ListInterfaces" and "QERPlug_RequestInterface"
31 // (see qerplugin.h for more information)
32
33 #ifdef _WIN32
34 #define VFS_NATIVESEPARATOR '\\'
35 #else
36 #define VFS_NATIVESEPARATOR '/'
37 #endif
38
39 #define VFS_MAJOR "VFS"
40
41 // return the file system supported by the plugin, for example: "quake1" or "quake3"
42 //typedef const char* (WINAPI* PFN_VFSGETFORMAT) ();
43 // add all files from a directory to the vfs
44 typedef void (* PFN_VFSINITDIRECTORY) (const char *path);
45 // free all resources used by the plugin
46 typedef void (* PFN_VFSSHUTDOWN) ();
47 // free memory allocated by VFS for this pointer
48 typedef void (* PFN_VFSFREEFILE) (void *p);
49 // return a GSList with all the directories under basedir 
50 typedef GSList* (* PFN_VFSGETDIRLIST) (const char *basedir);
51 // return a GSList with all the files under basedir (extension can be NULL)
52 typedef GSList* (* PFN_VFSGETFILELIST) (const char *basedir, const char *extension);
53 // free a dirlist or filelist returned from one of the above functions
54 typedef void (* PFN_VFSCLEARFILEDIRLIST) (GSList **lst);
55 #define VFS_SEARCH_PAK 0x1
56 #define VFS_SEARCH_DIR 0x2
57 /*!
58 \brief return the number of files with the exact name described in filename
59 there can be several hits for a given file, or this can be used to check for existence
60 \param flags is optional and can be used with VFS_SEARCH_* bits, if flag is 0, everything is searched, else only the specified bits
61 paks are searched first, then search directories
62 */
63 typedef int (* PFN_VFSGETFILECOUNT) (const char *filename, int flags);
64 /*!
65 \brief load file, allocate buffer
66 \return -1 if fails or the size of the buffer allocated
67 \param index is used to load the i-th file in the search directories (see vfsGetFileCount)
68 this will scan in the search directories first, then it will search in the pak files
69 WARNING: the allocated buffer must be freed with a g_free call
70 NOTE TTimo: the g_free release is utter horror
71  see http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=491
72 */
73 typedef int (* PFN_VFSLOADFILE) (const char *filename, void **buffer, int index);
74 // load a file from it's full path into the buffer, returns the file size or -1
75 // the allocated buffer must be freed with a g_free call
76 typedef int (* PFN_VFSLOADFULLPATHFILE) (const char *filename, void **buffer);
77 // takes an absolute file path, returns a shortened relative file path if the absolute path matches a valid basedir or NULL if an error occured
78 typedef char* (* PFN_VFSEXTRACTRELATIVEPATH) (const char *in);
79 /*!
80 \return the full path (in a static buff) to a file given it's relative path (NULL if not found)
81 \param index if several files are matching (as returned in a call to vfsGetFileCount), get the index-th file
82 \param flag 0 or a combination of VFS_SEARCH_PAK or VFS_SEARCH_DIR
83 HYDRA:
84   this now searches VFS/PAK files in addition to the filesystem
85   if FLAG is 0 then ONLY dirs are searched.
86   PAK's are searched before DIRs to mimic engine behaviour
87   index is ignored when searching PAK files.
88   when searching VFS, files are searched case insensitive.
89
90 WARNING: if you use index from vfsGetFileCount, it works only with a vfsGetFileCount for the search directories only (not the pak files)
91 FIXME TTimo our VFS names are case insensitive.
92    this function is not able to build the full path from case-insensitive name
93    ( this is http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=130 )
94 */
95 typedef char* (* PFN_VFSGETFULLPATH) (const char *in, int index, int flag);
96 /*!
97 these return a static char*, doesn't need to be freed or anything
98 get the base path to use when raising file dialogs
99 we manually add "maps/" or "sounds/" or "mapobjects/models/" etc.
100 FIXME: I'm not sure this is used / relevant anymore
101 */
102 typedef const char* (* PFN_VFSBASEPROMPTPATH) ();
103
104 // VFS API
105 struct _QERFileSystemTable
106 {
107   int m_nSize;
108   PFN_VFSINITDIRECTORY        m_pfnInitDirectory;
109   PFN_VFSSHUTDOWN             m_pfnShutdown;
110   PFN_VFSFREEFILE             m_pfnFreeFile;
111   PFN_VFSGETDIRLIST           m_pfnGetDirList;
112   PFN_VFSGETFILELIST          m_pfnGetFileList;
113   PFN_VFSCLEARFILEDIRLIST     m_pfnClearFileDirList;
114   PFN_VFSGETFILECOUNT         m_pfnGetFileCount;
115   PFN_VFSLOADFILE             m_pfnLoadFile;
116   PFN_VFSLOADFULLPATHFILE     m_pfnLoadFullPathFile;
117   PFN_VFSEXTRACTRELATIVEPATH  m_pfnExtractRelativePath;
118   PFN_VFSGETFULLPATH          m_pfnGetFullPath;
119   PFN_VFSBASEPROMPTPATH       m_pfnBasePromptPath;
120 };
121
122 #ifdef USE_VFSTABLE_DEFINE
123 #ifndef __VFSTABLENAME
124 #define __VFSTABLENAME g_FileSystemTable
125 #endif
126 #define vfsInitDirectory __VFSTABLENAME.m_pfnInitDirectory
127 #define vfsShutdown __VFSTABLENAME.m_pfnShutdown
128 #define vfsFreeFile __VFSTABLENAME.m_pfnFreeFile
129 #define vfsGetDirList __VFSTABLENAME.m_pfnGetDirList
130 #define vfsGetFileList __VFSTABLENAME.m_pfnGetFileList
131 #define vfsClearFileDirList __VFSTABLENAME.m_pfnClearFileDirList
132 #define vfsGetFileCount __VFSTABLENAME.m_pfnGetFileCount
133 #define vfsLoadFile __VFSTABLENAME.m_pfnLoadFile
134 #define vfsLoadFullPathFile __VFSTABLENAME.m_pfnLoadFullPathFile
135 #define vfsExtractRelativePath __VFSTABLENAME.m_pfnExtractRelativePath
136 #define vfsGetFullPath __VFSTABLENAME.m_pfnGetFullPath
137 #define vfsBasePromptPath __VFSTABLENAME.m_pfnBasePromptPath
138 #endif
139
140 #endif // _IFILESYSTEM_H_