]> icculus.org git repositories - divverent/darkplaces.git/blob - fs.h
I suppose 0xE000 is a valid fontmap char... so render it as charmap item 0
[divverent/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
29 // ------ Types ------ //
30
31 typedef struct qfile_s qfile_t;
32
33 #ifdef WIN32
34 //typedef long fs_offset_t; // 32bit
35 typedef __int64 fs_offset_t; ///< 64bit (lots of warnings, and read/write still don't take 64bit on win64)
36 #else
37 typedef long long fs_offset_t;
38 #endif
39
40
41
42 // ------ Variables ------ //
43
44 extern char fs_gamedir [MAX_OSPATH];
45 extern char fs_basedir [MAX_OSPATH];
46 extern char fs_userdir [MAX_OSPATH];
47
48 // list of active game directories (empty if not running a mod)
49 #define MAX_GAMEDIRS 16
50 extern int fs_numgamedirs;
51 extern char fs_gamedirs[MAX_GAMEDIRS][MAX_QPATH];
52
53
54 // ------ Main functions ------ //
55
56 // IMPORTANT: the file path is automatically prefixed by the current game directory for
57 // each file created by FS_WriteFile, or opened in "write" or "append" mode by FS_OpenRealFile
58
59 qboolean FS_AddPack(const char *pakfile, qboolean *already_loaded, qboolean keep_plain_dirs); // already_loaded may be NULL if caller does not care
60 const char *FS_WhichPack(const char *filename);
61 void FS_CreatePath (char *path);
62 int FS_SysOpenFD(const char *filepath, const char *mode, qboolean nonblocking); // uses absolute path
63 qfile_t* FS_SysOpen (const char* filepath, const char* mode, qboolean nonblocking); // uses absolute path
64 qfile_t* FS_OpenRealFile (const char* filepath, const char* mode, qboolean quiet);
65 qfile_t* FS_OpenVirtualFile (const char* filepath, qboolean quiet);
66 qfile_t* FS_FileFromData (const unsigned char *data, const size_t size, qboolean quiet);
67 int FS_Close (qfile_t* file);
68 void FS_RemoveOnClose(qfile_t* file);
69 fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize);
70 fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize);
71 int FS_Print(qfile_t* file, const char *msg);
72 int FS_Printf(qfile_t* file, const char* format, ...) DP_FUNC_PRINTF(2);
73 int FS_VPrintf(qfile_t* file, const char* format, va_list ap);
74 int FS_Getc (qfile_t* file);
75 int FS_UnGetc (qfile_t* file, unsigned char c);
76 int FS_Seek (qfile_t* file, fs_offset_t offset, int whence);
77 fs_offset_t FS_Tell (qfile_t* file);
78 fs_offset_t FS_FileSize (qfile_t* file);
79 void FS_Purge (qfile_t* file);
80 const char *FS_FileWithoutPath (const char *in);
81 const char *FS_FileExtension (const char *in);
82 int FS_CheckNastyPath (const char *path, qboolean isgamedir);
83
84 extern const char *const fs_checkgamedir_missing; // "(missing)"
85 const char *FS_CheckGameDir(const char *gamedir); // returns NULL if nasty, fs_checkgamedir_missing (exact pointer) if missing
86
87 typedef struct
88 {
89         char name[MAX_OSPATH];
90         char description[8192];
91 }
92 gamedir_t;
93 extern gamedir_t *fs_all_gamedirs; // terminated by entry with empty name
94 extern int fs_all_gamedirs_count;
95
96 qboolean FS_ChangeGameDirs(int numgamedirs, char gamedirs[][MAX_QPATH], qboolean complain, qboolean failmissing);
97 qboolean FS_IsRegisteredQuakePack(const char *name);
98 int FS_CRCFile(const char *filename, size_t *filesizepointer);
99 void FS_Rescan(void);
100
101 typedef struct fssearch_s
102 {
103         int numfilenames;
104         char **filenames;
105         // array of filenames
106         char *filenamesbuffer;
107 }
108 fssearch_t;
109
110 fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet);
111 void FS_FreeSearch(fssearch_t *search);
112
113 unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet, fs_offset_t *filesizepointer);
114 qboolean FS_WriteFileInBlocks (const char *filename, const void *const *data, const fs_offset_t *len, size_t count);
115 qboolean FS_WriteFile (const char *filename, const void *data, fs_offset_t len);
116
117
118 // ------ Other functions ------ //
119
120 void FS_StripExtension (const char *in, char *out, size_t size_out);
121 void FS_DefaultExtension (char *path, const char *extension, size_t size_path);
122
123 #define FS_FILETYPE_NONE 0
124 #define FS_FILETYPE_FILE 1
125 #define FS_FILETYPE_DIRECTORY 2
126 int FS_FileType (const char *filename);         // the file can be into a package
127 int FS_SysFileType (const char *filename);              // only look for files outside of packages
128
129 qboolean FS_FileExists (const char *filename);          // the file can be into a package
130 qboolean FS_SysFileExists (const char *filename);       // only look for files outside of packages
131
132 void FS_mkdir (const char *path);
133
134 unsigned char *FS_Deflate(const unsigned char *data, size_t size, size_t *deflated_size, int level, mempool_t *mempool);
135 unsigned char *FS_Inflate(const unsigned char *data, size_t size, size_t *inflated_size, mempool_t *mempool);
136
137 qboolean FS_HasZlib(void);
138
139 #endif