UFO: Alien Invasion
Loading...
Searching...
No Matches
filesys.h
Go to the documentation of this file.
1
5
6/*
7All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9Copyright (C) 1997-2001 Id Software, Inc.
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20See the GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26*/
27
28#pragma once
29
30#include <stdio.h>
31#include <string.h>
32#include "../shared/ufotypes.h"
33#include "../shared/cxx.h"
34#define BASEDIRNAME "base"
35
36/* Maximum maps constant */
37#define MAX_MAPS 400
38
39/* max length of the ufo virtual filesystem */
40#define MAX_QPATH 64
41
42/* max length of a filesystem pathname
43 * windows + linux 256, macosx 32 */
44#define MAX_OSPATH 256
45
46/* max files in a directory */
47#define MAX_FILES 512
48
49/*
50==============================================================
51FILESYSTEM
52==============================================================
53*/
54typedef struct qFILE_s {
55 void* z;
58 unsigned long filepos;
59 unsigned long size;
60
61 inline FILE* getFile () const
62 {
63 return f;
64 }
65} qFILE;
66
73
79
81typedef struct filelink_s {
82 struct filelink_s* next;
83 char* from;
85 char* to;
87
88typedef struct {
90 unsigned long filepos;
91 unsigned long filelen;
93
94typedef struct pack_s {
99} pack_t;
100
101typedef struct searchpath_s {
104 bool write;
106 struct searchpath_s* next;
108
113
114/*
115==============================================================
116FILESYSTEM
117==============================================================
118*/
119extern char* fs_maps[MAX_MAPS];
120extern int fs_numInstalledMaps;
121
122/* directory searching */
123#define SFF_ARCH 0x01
124#define SFF_HIDDEN 0x02
125#define SFF_RDONLY 0x04
126#define SFF_SUBDIR 0x08
127#define SFF_SYSTEM 0x10
128
129int FS_FileLength(qFILE* f);
130int FS_Seek(qFILE* f, long offset, int origin);
131int FS_WriteFile(const void* buffer, size_t len, const char* filename);
132int FS_Write(const void* buffer, int len, qFILE* f);
133int FS_Printf(qFILE* f, const char* msg, ...) __attribute__((format(__printf__, 2, 3)));
134void FS_InitFilesystem(bool writeToHomeDir);
135void FS_AddGameDirectory(const char* dir, bool write);
136void FS_AddHomeAsGameDirectory(const char* dir, bool write);
137void FS_RestartFilesystem(const char* gamedir);
138const char* FS_Gamedir(void);
139void FS_CreateOpenPipeFile(const char* filename, qFILE* f);
140const char* FS_NextPath(const char* prevpath);
142int FS_GetModList(struct linkedList_t** mods);
143const char* FS_GetCwd(void);
144void FS_NormPath(char* path);
145bool FS_FileExists(const char* filename, ...) __attribute__((format(__printf__, 1, 2)));
146
147void FS_GetMaps(bool reset);
148
149int FS_OpenFile(const char* filename, qFILE* file, filemode_t mode);
150void FS_CloseFile(qFILE* f);
151
152bool FS_RenameFile(const char* from, const char* to, bool relative);
153void FS_RemoveFile(const char* osPath);
154void FS_CopyFile(const char* fromOSPath, const char* toOSPath);
155
156/* note: this can't be called from another DLL, due to MS libc issues */
157
158int FS_LoadFile(const char* path, byte** buffer);
159
160/* a null buffer will just return the file length without loading */
161/* a -1 length is not present */
162
163int FS_Read2(void* buffer, int len, qFILE* f, bool failOnEmptyRead);
164int FS_Read(void* buffer, int len, qFILE* f);
165/* properly handles partial reads */
166
167void FS_FreeFile(void* buffer);
168
169int FS_CheckFile(const char* fmt, ...) __attribute__((format(__printf__, 1, 2)));
170
171int FS_BuildFileList(const char* files);
172const char* FS_NextFileFromFileList(const char* files);
173char* FS_NextScriptHeader(const char* files, const char** name, const char** text);
174void FS_CreatePath(const char* path);
175
176/* Make sure we have this available */
177char** FS_ListFiles(const char* findname, int* numfiles, unsigned musthave, unsigned canthave);
178
179const char* FS_GetFileData(const char* files);
180
184void FS_Shutdown(void);
185
187private:
189public:
191 {
192 memset(&_file, 0, sizeof(_file));
193 }
195 {
197 }
198 inline qFILE* operator& ()
199 {
200 return &_file;
201 }
202 inline operator bool () const
203 {
204 return file() || zip();
205 }
206 inline bool file () const
207 {
208 return _file.f;
209 }
210 inline bool zip () const
211 {
212 return _file.z;
213 }
214 inline FILE* getFile () const
215 {
216 return _file.getFile();
217 }
218};
void FS_CloseFile(qFILE *f)
~ScopedFile()
Definition filesys.h:194
bool zip() const
Definition filesys.h:210
qFILE _file
Definition filesys.h:188
FILE * getFile() const
Definition filesys.h:214
bool file() const
Definition filesys.h:206
#define __attribute__(x)
Definition cxx.h:37
const char * FS_GetFileData(const char *files)
Returns the buffer of a file.
Definition files.cpp:1137
void FS_CreatePath(const char *path)
Creates any directories needed to store the given filename.
Definition files.cpp:117
int FS_Read2(void *buffer, int len, qFILE *f, bool failOnEmptyRead)
Read a file into a given buffer in memory.
Definition files.cpp:327
int fs_numInstalledMaps
Definition files.cpp:1314
const char * FS_NextPath(const char *prevpath)
Allows enumerating all of the directories in the search path.
Definition files.cpp:614
void FS_InitFilesystem(bool writeToHomeDir)
Definition files.cpp:890
void FS_RemoveFile(const char *osPath)
Definition files.cpp:1692
int FS_CheckFile(const char *fmt,...)
Just returns the filelength and -1 if the file wasn't found.
Definition files.cpp:298
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition files.cpp:384
void FS_CopyFile(const char *fromOSPath, const char *toOSPath)
Copy a fully specified file from one place to another.
Definition files.cpp:1654
char * FS_NextScriptHeader(const char *files, const char **name, const char **text)
Definition files.cpp:1196
void FS_FreeFile(void *buffer)
Definition files.cpp:411
int FS_GetModList(linkedList_t **mods)
Searches and builds a list of mod directories.
Definition files.cpp:669
const char * FS_NextFileFromFileList(const char *files)
Returns the next file that is found in the virtual filesystem identified by the given file pattern.
Definition files.cpp:1081
void FS_AddHomeAsGameDirectory(const char *dir, bool write)
Definition files.cpp:655
void FS_RestartFilesystem(const char *gamedir)
Restart the filesystem (reload all pk3 files).
Definition files.cpp:1643
bool FS_RenameFile(const char *from, const char *to, bool relative)
Renames a file.
Definition files.cpp:1709
char ** FS_ListFiles(const char *findname, int *numfiles, unsigned musthave, unsigned canthave)
Builds a qsorted filelist.
Definition files.cpp:562
const char * FS_GetCwd(void)
Return current working dir.
Definition files.cpp:1570
int FS_Read(void *buffer, int len, qFILE *f)
Definition files.cpp:371
void FS_Shutdown(void)
Cleanup function.
Definition files.cpp:1604
void FS_CreateOpenPipeFile(const char *filename, qFILE *f)
Definition files.cpp:47
int FS_OpenFile(const char *filename, qFILE *file, filemode_t mode)
Finds and opens the file in the search path.
Definition files.cpp:162
void FS_NormPath(char *path)
Convert operating systems path separators to ufo virtual filesystem separators (/).
Definition files.cpp:83
void FS_GetMaps(bool reset)
File the fs_maps array with valid maps.
Definition files.cpp:1375
const char * FS_Gamedir(void)
Called to find where to write a file (savegames, etc).
Definition files.cpp:68
void FS_AddGameDirectory(const char *dir, bool write)
Adds the directory to the head of the search path.
Definition files.cpp:495
int FS_BuildFileList(const char *fileList)
Build a filelist.
Definition files.cpp:962
bool FS_FileExists(const char *filename,...)
Checks whether a file exists (not in virtual filesystem).
Definition files.cpp:1583
char * fs_maps[MAX_MAPS]
Definition files.cpp:1313
int FS_Seek(qFILE *f, long offset, int origin)
Sets the file position of the given file.
Definition files.cpp:246
#define MAX_OSPATH
Definition filesys.h:44
fsMode_t
Definition filesys.h:67
@ FS_READ
Definition filesys.h:68
@ FS_APPEND
Definition filesys.h:70
@ FS_WRITE
Definition filesys.h:69
@ FS_APPEND_SYNC
Definition filesys.h:71
int FS_Write(const void *buffer, int len, qFILE *f)
Properly handles partial writes.
Definition files.cpp:1513
void FS_ExecAutoexec(void)
int FS_WriteFile(const void *buffer, size_t len, const char *filename)
Definition files.cpp:1546
int FS_FileLength(qFILE *f)
Returns the size of a given file or -1 if no file is opened.
Definition files.cpp:91
void FS_CloseFile(qFILE *f)
Closes a file handle.
#define MAX_MAPS
Definition filesys.h:37
#define MAX_QPATH
Definition filesys.h:40
int FS_Printf(qFILE *f, const char *msg,...) __attribute__((format(__printf__
filemode_t
Definition filesys.h:110
@ FILE_APPEND
Definition filesys.h:111
@ FILE_READ
Definition filesys.h:111
@ FILE_WRITE
Definition filesys.h:111
fsOrigin_t
Definition filesys.h:74
@ FS_SEEK_END
Definition filesys.h:76
@ FS_SEEK_CUR
Definition filesys.h:75
@ FS_SEEK_SET
Definition filesys.h:77
voidpf uLong int origin
Definition ioapi.h:45
const char * filename
Definition ioapi.h:41
const char int mode
Definition ioapi.h:41
voidpf uLong offset
Definition ioapi.h:45
void format(__printf__, 1, 2)))
QGL_EXTERN GLuint GLchar GLuint * len
Definition r_gl.h:99
QGL_EXTERN GLfloat f
Definition r_gl.h:114
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
int numfiles
Definition filesys.h:97
qFILE handle
Definition filesys.h:96
char filename[MAX_OSPATH]
Definition filesys.h:95
packfile_t * files
Definition filesys.h:98
char name[MAX_QPATH]
Definition filesys.h:89
unsigned long filepos
Definition filesys.h:90
unsigned long filelen
Definition filesys.h:91
char name[MAX_OSPATH]
Definition filesys.h:57
void * z
Definition filesys.h:55
FILE * f
Definition filesys.h:56
FILE * getFile() const
Definition filesys.h:61
unsigned long size
Definition filesys.h:59
unsigned long filepos
Definition filesys.h:58
pack_t * pack
Definition filesys.h:103
struct searchpath_s * next
Definition filesys.h:106
char filename[MAX_OSPATH]
Definition filesys.h:102
#define FILE
Cross-platform type definitions.
static char findname[MAX_OSPATH]