]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/ifilesystem.h
* reactivated WXY_Print function to generate screenshots from the xy window
[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 */
72 typedef int (* PFN_VFSLOADFILE) (const char *filename, void **buffer, int index);
73 // load a file from it's full path into the buffer, returns the file size or -1
74 // the allocated buffer must be freed with a g_free call
75 typedef int (* PFN_VFSLOADFULLPATHFILE) (const char *filename, void **buffer);
76 // 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
77 typedef char* (* PFN_VFSEXTRACTRELATIVEPATH) (const char *in);
78 /*!
79 \return the full path (in a static buff) to a file given it's relative path (NULL if not found)
80 \param index if several files are matching (as returned in a call to vfsGetFileCount), get the index-th file
81 \param flag 0 or a combination of VFS_SEARCH_PAK or VFS_SEARCH_DIR
82 HYDRA:
83   this now searches VFS/PAK files in addition to the filesystem
84   if FLAG is 0 then ONLY dirs are searched.
85   PAK's are searched before DIRs to mimic engine behaviour
86   index is ignored when searching PAK files.
87   when searching VFS, files are searched case insensitive.
88
89 WARNING: if you use index from vfsGetFileCount, it works only with a vfsGetFileCount for the search directories only (not the pak files)
90 FIXME TTimo our VFS names are case insensitive.
91    this function is not able to build the full path from case-insensitive name
92 */
93 typedef char* (* PFN_VFSGETFULLPATH) (const char *in, int index, int flag);
94 /*!
95 these return a static char*, doesn't need to be freed or anything
96 get the base path to use when raising file dialogs
97 we manually add "maps/" or "sounds/" or "mapobjects/models/" etc.
98 FIXME: I'm not sure this is used / relevant anymore
99 */
100 typedef const char* (* PFN_VFSBASEPROMPTPATH) ();
101
102 // VFS API
103 struct _QERFileSystemTable
104 {
105   int m_nSize;
106   PFN_VFSINITDIRECTORY        m_pfnInitDirectory;
107   PFN_VFSSHUTDOWN             m_pfnShutdown;
108   PFN_VFSFREEFILE             m_pfnFreeFile;
109   PFN_VFSGETDIRLIST           m_pfnGetDirList;
110   PFN_VFSGETFILELIST          m_pfnGetFileList;
111   PFN_VFSCLEARFILEDIRLIST     m_pfnClearFileDirList;
112   PFN_VFSGETFILECOUNT         m_pfnGetFileCount;
113   PFN_VFSLOADFILE             m_pfnLoadFile;
114   PFN_VFSLOADFULLPATHFILE     m_pfnLoadFullPathFile;
115   PFN_VFSEXTRACTRELATIVEPATH  m_pfnExtractRelativePath;
116   PFN_VFSGETFULLPATH          m_pfnGetFullPath;
117   PFN_VFSBASEPROMPTPATH       m_pfnBasePromptPath;
118 };
119
120 #ifdef USE_VFSTABLE_DEFINE
121 #ifndef __VFSTABLENAME
122 #define __VFSTABLENAME g_FileSystemTable
123 #endif
124 #define vfsInitDirectory __VFSTABLENAME.m_pfnInitDirectory
125 #define vfsShutdown __VFSTABLENAME.m_pfnShutdown
126 #define vfsFreeFile __VFSTABLENAME.m_pfnFreeFile
127 #define vfsGetDirList __VFSTABLENAME.m_pfnGetDirList
128 #define vfsGetFileList __VFSTABLENAME.m_pfnGetFileList
129 #define vfsClearFileDirList __VFSTABLENAME.m_pfnClearFileDirList
130 #define vfsGetFileCount __VFSTABLENAME.m_pfnGetFileCount
131 #define vfsLoadFile __VFSTABLENAME.m_pfnLoadFile
132 #define vfsLoadFullPathFile __VFSTABLENAME.m_pfnLoadFullPathFile
133 #define vfsExtractRelativePath __VFSTABLENAME.m_pfnExtractRelativePath
134 #define vfsGetFullPath __VFSTABLENAME.m_pfnGetFullPath
135 #define vfsBasePromptPath __VFSTABLENAME.m_pfnBasePromptPath
136 #endif
137
138 #endif // _IFILESYSTEM_H_