]> git.xonotic.org Git - xonotic/darkplaces.git/blob - fs.h
Merge PR 'Make particles solid squares when cl_particles_quake is set to 2'
[xonotic/darkplaces.git] / fs.h
1 /*
2         DarkPlaces file system
3
4         Copyright (C) 2003-2005 Mathieu Olivier
5
6         This program is free software; you can redistribute it and/or
7         modify it under the terms of the GNU General Public License
8         as published by the Free Software Foundation; either version 2
9         of the License, or (at your option) any later version.
10
11         This program is distributed in the hope that it will be useful,
12         but WITHOUT ANY WARRANTY; without even the implied warranty of
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15         See the GNU General Public License for more details.
16
17         You should have received a copy of the GNU General Public License
18         along with this program; if not, write to:
19
20                 Free Software Foundation, Inc.
21                 59 Temple Place - Suite 330
22                 Boston, MA  02111-1307, USA
23 */
24
25 #ifndef FS_H
26 #define FS_H
27
28 #include <stddef.h>
29 #include <stdarg.h>
30 #include "qtypes.h"
31 #include "qdefs.h"
32 #include "zone.h"
33
34 // ------ Types ------ //
35
36 typedef struct qfile_s qfile_t;
37 typedef int64_t fs_offset_t;
38
39 // ------ Variables ------ //
40
41 extern char fs_gamedir [MAX_OSPATH];
42 extern char fs_basedir [MAX_OSPATH];
43 extern char fs_userdir [MAX_OSPATH];
44
45 // list of active game directories (empty if not running a mod)
46 #define MAX_GAMEDIRS 16
47 extern int fs_numgamedirs;
48 extern char fs_gamedirs[MAX_GAMEDIRS][MAX_QPATH];
49
50 typedef struct vfs_s
51 {
52         char gamedir[MAX_OSPATH];
53         char basedir[MAX_OSPATH];
54         char userdir[MAX_OSPATH];
55         int numgamedirs;
56         char gamedirs[MAX_GAMEDIRS][MAX_QPATH];
57 } vfs_t;
58
59 // ------ Main functions ------ //
60
61 // IMPORTANT: the file path is automatically prefixed by the current game directory for
62 // each file created by FS_WriteFile, or opened in "write" or "append" mode by FS_OpenRealFile
63
64 qbool FS_AddPack(const char *pakfile, qbool *already_loaded, qbool keep_plain_dirs); // already_loaded may be NULL if caller does not care
65 const char *FS_WhichPack(const char *filename);
66 void FS_CreatePath (char *path);
67 int FS_SysOpenFD(const char *filepath, const char *mode, qbool nonblocking); // uses absolute path
68 qfile_t* FS_SysOpen (const char* filepath, const char* mode, qbool nonblocking); // uses absolute path
69 qfile_t* FS_OpenRealFile (const char* filepath, const char* mode, qbool quiet);
70 qfile_t* FS_OpenVirtualFile (const char* filepath, qbool quiet);
71 qfile_t* FS_FileFromData (const unsigned char *data, const size_t size, qbool quiet);
72 int FS_Close (qfile_t* file);
73 void FS_RemoveOnClose(qfile_t* file);
74 fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize);
75 fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize);
76 int FS_Print(qfile_t* file, const char *msg);
77 int FS_Printf(qfile_t* file, const char* format, ...) DP_FUNC_PRINTF(2);
78 int FS_VPrintf(qfile_t* file, const char* format, va_list ap);
79 int FS_Getc (qfile_t* file);
80 int FS_UnGetc (qfile_t* file, unsigned char c);
81 int FS_Seek (qfile_t* file, fs_offset_t offset, int whence);
82 fs_offset_t FS_Tell (qfile_t* file);
83 fs_offset_t FS_FileSize (qfile_t* file);
84 void FS_Purge (qfile_t* file);
85 const char *FS_FileWithoutPath (const char *in);
86 const char *FS_FileExtension (const char *in);
87 int FS_CheckNastyPath (const char *path, qbool isgamedir);
88 void FS_SanitizePath (char *path);
89
90 extern const char *const fs_checkgamedir_missing; // "(missing)"
91 const char *FS_CheckGameDir(const char *gamedir); // returns NULL if nasty, fs_checkgamedir_missing (exact pointer) if missing
92
93 typedef struct
94 {
95         char name[MAX_OSPATH];
96         char description[8192];
97 }
98 gamedir_t;
99 extern gamedir_t *fs_all_gamedirs; // terminated by entry with empty name
100 extern int fs_all_gamedirs_count;
101
102 qbool FS_ChangeGameDirs(int numgamedirs, char gamedirs[][MAX_QPATH], qbool complain, qbool failmissing);
103 qbool FS_IsRegisteredQuakePack(const char *name);
104 int FS_CRCFile(const char *filename, size_t *filesizepointer);
105 void FS_Rescan(void);
106
107 typedef struct fssearch_s
108 {
109         int numfilenames;
110         char **filenames;
111         // array of filenames
112         char *filenamesbuffer;
113 }
114 fssearch_t;
115
116 fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet, const char *packfile);
117 void FS_FreeSearch(fssearch_t *search);
118
119 unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer);
120 unsigned char *FS_SysLoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer);
121 qbool FS_WriteFileInBlocks (const char *filename, const void *const *data, const fs_offset_t *len, size_t count);
122 qbool FS_WriteFile (const char *filename, const void *data, fs_offset_t len);
123
124
125 // ------ Other functions ------ //
126
127 void FS_StripExtension (const char *in, char *out, size_t size_out);
128 void FS_DefaultExtension (char *path, const char *extension, size_t size_path);
129
130 #define FS_FILETYPE_NONE 0
131 #define FS_FILETYPE_FILE 1
132 #define FS_FILETYPE_DIRECTORY 2
133 int FS_FileType (const char *filename);         // the file can be into a package
134 int FS_SysFileType (const char *filename);              // only look for files outside of packages
135
136 qbool FS_FileExists (const char *filename);             // the file can be into a package
137 qbool FS_SysFileExists (const char *filename);  // only look for files outside of packages
138
139 unsigned char *FS_Deflate(const unsigned char *data, size_t size, size_t *deflated_size, int level, mempool_t *mempool);
140 unsigned char *FS_Inflate(const unsigned char *data, size_t size, size_t *inflated_size, mempool_t *mempool);
141
142 qbool FS_HasZlib(void);
143
144 void FS_Init_SelfPack(void);
145 void FS_Init(void);
146 void FS_Shutdown(void);
147 void FS_Init_Commands(void);
148
149 #endif