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