DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
fs.c File Reference
#include <limits.h>
#include <fcntl.h>
#include <pwd.h>
#include <sys/stat.h>
#include <unistd.h>
#include "quakedef.h"
#include "thread.h"
#include "fs.h"
#include "wad.h"
#include "utf8lib.h"
+ Include dependency graph for fs.c:

Go to the source code of this file.

Data Structures

struct  dpackfile_t
 
struct  dpackheader_t
 
struct  pack_t
 
struct  packfile_t
 
struct  pk3_endOfCentralDir_t
 
struct  qfile_t
 
struct  searchpath_t
 Search paths for files (including packages) More...
 
struct  z_stream
 
struct  ztoolkit_t
 

Macros

#define FILE_BUFF_SIZE   2048
 
#define FILEDESC_CLOSE   close
 
#define FILEDESC_INVALID   -1
 
#define FILEDESC_ISVALID(fd)
 
#define FILEDESC_READ   read
 
#define FILEDESC_READ   ReadAll
 
#define FILEDESC_SEEK   lseek
 
#define FILEDESC_WRITE   write
 
#define FILEDESC_WRITE   WriteAll
 
#define MAX_WBITS   15
 
#define O_BINARY   0
 
#define O_NONBLOCK   0
 
#define QFILE_FLAG_DATA   (1 << 2)
 file is actually already loaded data
 
#define QFILE_FLAG_DEFLATED   (1 << 1)
 file is compressed using the deflate algorithm (PK3 only)
 
#define QFILE_FLAG_PACKED   (1 << 0)
 inside a package (PAK or PK3)
 
#define QFILE_FLAG_REMOVE   (1 << 3)
 real file will be removed on close
 
#define S_ISDIR(a)
 
#define WPATHDEF(var)
 
#define Z_BINARY   0
 
#define Z_BUF_ERROR   (-5)
 
#define Z_DATA_ERROR   (-3)
 
#define Z_DEFAULT_COMPRESSION   (-1)
 
#define Z_DEFLATED   8
 
#define Z_FINISH   4
 
#define Z_FULL_FLUSH   3
 
#define Z_MEM_ERROR   (-4)
 
#define Z_MEMLEVEL_DEFAULT   8
 
#define Z_NO_FLUSH   0
 
#define Z_NULL   0
 
#define Z_OK   0
 
#define Z_STREAM_END   1
 
#define Z_STREAM_ERROR   (-2)
 
#define Z_SYNC_FLUSH   2
 
#define Z_SYNC_FLUSH   2
 
#define ZIP_CDIR_CHUNK_BASE_SIZE   46
 
#define ZIP_CDIR_HEADER   0x504B0102
 
#define ZIP_DATA_HEADER   0x504B0304
 
#define ZIP_END_CDIR_SIZE   22
 
#define ZIP_END_HEADER   0x504B0506
 
#define ZIP_LOCAL_CHUNK_BASE_SIZE   30
 
#define ZIP_MAX_COMMENTS_SIZE   ((unsigned short)0xFFFF)
 
#define ZLIB_VERSION   "1.2.3"
 

Typedefs

typedef int filedesc_t
 

Functions

static filedesc_t FILEDESC_DUP (const char *filename, filedesc_t fd)
 
static fs_offset_t ReadAll (const filedesc_t fd, void *const buf, const size_t length)
 
static fs_offset_t WriteAll (const filedesc_t fd, const void *const buf, const size_t length)
 

Packages in memory

static void AssertBufsize (sizebuf_t *buf, int length)
 
static void COM_InsertFlags (const char *buf)
 
int con_linewidth
 
cvar_t cvar_fs_gamedir = {CF_CLIENT | CF_SERVER | CF_READONLY | CF_PERSISTENT, "fs_gamedir", "", "the list of currently selected gamedirs (use the 'gamedir' command to change this)"}
 
static int flush
 
static packfile_tFS_AddFileToPack (const char *name, pack_t *pack, fs_offset_t offset, fs_offset_t packsize, fs_offset_t realsize, int flags)
 
static void FS_AddGameDirectory (const char *dir)
 
static void FS_AddGameHierarchy (const char *dir)
 
qbool FS_AddPack (const char *pakfile, qbool *already_loaded, qbool keep_plain_dirs, qbool dlcache)
 
static qbool FS_AddPack_Fullpath (const char *pakfile, const char *shortname, qbool *already_loaded, qbool keep_plain_dirs, qbool dlcache)
 
static void FS_AddSelfPack (void)
 
gamedir_tfs_all_gamedirs = NULL
 
int fs_all_gamedirs_count = 0
 
char fs_basedir [MAX_OSPATH]
 
qbool FS_ChangeGameDirs (int numgamedirs, const char *gamedirs[], qbool failmissing)
 
const char * FS_CheckGameDir (const char *gamedir)
 
const char *const fs_checkgamedir_missing = "missing"
 
int FS_CheckNastyPath (const char *path, qbool isgamedir)
 
static int FS_ChooseUserDir (userdirmode_t userdirmode, char *userdir, size_t userdirsize)
 
static void FS_ClearSearchPath (void)
 
int FS_Close (qfile_t *file)
 
int FS_CRCFile (const char *filename, size_t *filesizepointer)
 
void FS_CreatePath (char *path)
 
void FS_DefaultExtension (char *path, const char *extension, size_t size_path)
 
unsigned char * FS_Deflate (const unsigned char *data, size_t size, size_t *deflated_size, int level, mempool_t *mempool)
 
void FS_Dir_f (cmd_state_t *cmd)
 
cvar_t fs_empty_files_in_pack_mark_deletions = {CF_CLIENT | CF_SERVER, "fs_empty_files_in_pack_mark_deletions", "0", "if enabled, empty files in a pak/pk3 count as not existing but cancel the search in further packs, effectively allowing patch pak/pk3 files to 'delete' files"}
 
const char * FS_FileExists (const char *filename)
 Look for a file in the packages and in the filesystem Returns its canonical name (same case as used in the pack) if found, else NULL.
 
const char * FS_FileExtension (const char *in)
 
qfile_t * FS_FileFromData (const unsigned char *data, const size_t size, qbool quiet)
 
fs_offset_t FS_FileSize (qfile_t *file)
 
int FS_FileType (const char *filename)
 Look for a file in the packages and in the filesystem.
 
const char * FS_FileWithoutPath (const char *in)
 
static searchpath_tFS_FindFile (const char *name, int *index, const char **canonicalname, qbool quiet)
 
void FS_FreeSearch (fssearch_t *search)
 
char fs_gamedir [MAX_OSPATH]
 
static void FS_GameDir_f (cmd_state_t *cmd)
 
char fs_gamedirs [MAX_GAMEDIRS][MAX_QPATH]
 
int FS_Getc (qfile_t *file)
 
qbool FS_HasZlib (void)
 
unsigned char * FS_Inflate (const unsigned char *data, size_t size, size_t *inflated_size, mempool_t *mempool)
 
void FS_Init (void)
 
void FS_Init_Commands (void)
 
static void FS_Init_Dir (void)
 
void FS_Init_SelfPack (void)
 
qbool FS_IsRegisteredQuakePack (const char *name)
 
static int FS_ListDirectory (const char *pattern, int oneperline)
 
static void FS_ListDirectoryCmd (cmd_state_t *cmd, const char *cmdname, int oneperline)
 
static void FS_ListGameDirs (void)
 
static unsigned char * FS_LoadAndCloseQFile (qfile_t *file, const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
 
unsigned char * FS_LoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
 
static pack_tFS_LoadPackPAK (const char *packfile)
 
static pack_tFS_LoadPackPK3 (const char *packfile)
 
static pack_tFS_LoadPackPK3FromFD (const char *packfile, filedesc_t packhandle, qbool silent)
 
static pack_tFS_LoadPackVirtual (const char *dirname)
 
void FS_Ls_f (cmd_state_t *cmd)
 
mempool_tfs_mempool
 
static void FS_mkdir (const char *path)
 
voidfs_mutex = NULL
 
int fs_numgamedirs = 0
 
static qfile_t * FS_OpenPackedFile (pack_t *pack, int pack_ind)
 
static qfile_t * FS_OpenReadFile (const char *filename, qbool quiet, qbool nonblocking, int symlinkLevels)
 
qfile_t * FS_OpenRealFile (const char *filepath, const char *mode, qbool quiet)
 
qfile_t * FS_OpenVirtualFile (const char *filepath, qbool quiet)
 
static void FS_Path_f (cmd_state_t *cmd)
 
int FS_Print (qfile_t *file, const char *msg)
 
int FS_Printf (qfile_t *file, const char *format,...)
 
void FS_Purge (qfile_t *file)
 
fs_offset_t FS_Read (qfile_t *file, void *buffer, size_t buffersize)
 
void FS_RemoveOnClose (qfile_t *file)
 
void FS_Rescan (void)
 
static void FS_Rescan_f (cmd_state_t *cmd)
 
void FS_SanitizePath (char *path)
 
fssearch_tFS_Search (const char *pattern, int caseinsensitive, int quiet, const char *packfile)
 
searchpath_tfs_searchpaths = NULL
 
int FS_Seek (qfile_t *file, fs_offset_t offset, int whence)
 
static pack_tfs_selfpack = NULL
 
addgamedirs_t FS_SetGameDirs (int numgamedirs, const char *gamedirs[], qbool failmissing, qbool abortonfail)
 
void FS_Shutdown (void)
 
void FS_StripExtension (const char *in, char *out, size_t size_out)
 
static const char * FS_SysCheckGameDir (const char *gamedir, char *buf, size_t buflength)
 
qbool FS_SysFileExists (const char *path)
 Look for a file in the filesystem only.
 
int FS_SysFileType (const char *path)
 Look for a file in the filesystem only.
 
unsigned char * FS_SysLoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
 
qfile_t * FS_SysOpen (const char *filepath, const char *mode, qbool nonblocking)
 
int FS_SysOpenFD (const char *filepath, const char *mode, qbool nonblocking)
 
static filedesc_t FS_SysOpenFiledesc (const char *filepath, const char *mode, qbool nonblocking)
 
fs_offset_t FS_Tell (qfile_t *file)
 
int FS_UnGetc (qfile_t *file, unsigned char c)
 
cvar_t fs_unload_dlcache = {CF_CLIENT, "fs_unload_dlcache", "1", "if enabled, unload dlcache's loaded pak/pk3 files when changing server and/or map WARNING: disabling unloading can cause servers to override assets of other servers, \"memory leaking\" by dlcache assets never unloading and many more issues"}
 
void FS_UnloadPacks_dlcache (void)
 
char fs_userdir [MAX_OSPATH]
 
int FS_VPrintf (qfile_t *file, const char *format, va_list ap)
 
void FS_Which_f (cmd_state_t *cmd)
 
const char * FS_WhichPack (const char *filename)
 
fs_offset_t FS_Write (qfile_t *file, const void *data, size_t datasize)
 
qbool FS_WriteFile (const char *filename, const void *data, fs_offset_t len)
 
qbool FS_WriteFileInBlocks (const char *filename, const void *const *data, const fs_offset_t *len, size_t count)
 
static int (ZEXPORT *qz_inflate)(z_stream *strm
 
static int level
 
#define MAX_FILES_IN_PACK   65536
 
static int int int int memLevel
 
static int int method
 
#define PACKFILE_FLAG_DEFLATED   (1 << 1)
 file compressed using the deflate algorithm
 
#define PACKFILE_FLAG_SYMLINK   (1 << 2)
 file is a symbolic link
 
#define PACKFILE_FLAG_TRUEOFFS   (1 << 0)
 the offset in packfile_t is the true contents offset
 
static int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd)
 
static void PK3_CloseLibrary (void)
 
static qbool PK3_GetEndOfCentralDir (const char *packfile, filedesc_t packhandle, pk3_endOfCentralDir_t *eocd)
 
static qbool PK3_GetTrueFileOffset (packfile_t *pfile, pack_t *pack)
 
static qbool PK3_OpenLibrary (void)
 
#define qz_deflateInit2(strm, level, method, windowBits, memLevel, strategy)
 
#define qz_inflateInit2(strm, windowBits)
 
cvar_t scr_screenshot_name = {CF_CLIENT | CF_PERSISTENT, "scr_screenshot_name","dp", "prefix name for saved screenshots (changes based on -game commandline, as well as which game mode is running; the date is encoded using strftime escapes)"}
 
static int int int int int strategy
 
static int const char int stream_size
 
static int const char * version
 
static int windowBits
 
#define ZEXPORT
 
static dllhandle_t zlib_dll = NULL
 Handle for Zlib DLL.
 
static dllfunction_t zlibfuncs []
 

Macro Definition Documentation

◆ FILE_BUFF_SIZE

#define FILE_BUFF_SIZE   2048

Definition at line 302 of file fs.c.

◆ FILEDESC_CLOSE

◆ FILEDESC_INVALID

#define FILEDESC_INVALID   -1

Definition at line 107 of file fs.c.

Referenced by FS_LoadPackVirtual(), and FS_SysOpenFiledesc().

◆ FILEDESC_ISVALID

#define FILEDESC_ISVALID ( fd)
Value:
((fd) != -1)

Definition at line 108 of file fs.c.

Referenced by FS_LoadPackPAK(), FS_LoadPackPK3(), FS_OpenPackedFile(), and FS_SysOpen().

◆ FILEDESC_READ [1/2]

#define FILEDESC_READ   read

◆ FILEDESC_READ [2/2]

#define FILEDESC_READ   ReadAll

Definition at line 109 of file fs.c.

◆ FILEDESC_SEEK

#define FILEDESC_SEEK   lseek

◆ FILEDESC_WRITE [1/2]

#define FILEDESC_WRITE   write

Definition at line 110 of file fs.c.

Referenced by FS_VPrintf(), FS_Write(), and WriteAll().

◆ FILEDESC_WRITE [2/2]

#define FILEDESC_WRITE   WriteAll

Definition at line 110 of file fs.c.

◆ MAX_FILES_IN_PACK

#define MAX_FILES_IN_PACK   65536

Definition at line 440 of file fs.c.

Referenced by FS_LoadPackPAK(), and FS_LoadPackPK3FromFD().

◆ MAX_WBITS

#define MAX_WBITS   15

Definition at line 232 of file fs.c.

Referenced by FS_Deflate(), FS_Inflate(), and FS_OpenPackedFile().

◆ O_BINARY

#define O_BINARY   0

Definition at line 56 of file fs.c.

Referenced by FS_SysOpenFiledesc().

◆ O_NONBLOCK

#define O_NONBLOCK   0

Definition at line 61 of file fs.c.

Referenced by FS_SysOpenFiledesc(), Sys_Error(), Sys_HandleCrash(), Sys_Main(), and Sys_Print().

◆ PACKFILE_FLAG_DEFLATED

#define PACKFILE_FLAG_DEFLATED   (1 << 1)

file compressed using the deflate algorithm

Definition at line 372 of file fs.c.

Referenced by FS_OpenPackedFile(), and PK3_BuildFileList().

◆ PACKFILE_FLAG_SYMLINK

#define PACKFILE_FLAG_SYMLINK   (1 << 2)

file is a symbolic link

Definition at line 374 of file fs.c.

Referenced by FS_OpenReadFile(), and PK3_BuildFileList().

◆ PACKFILE_FLAG_TRUEOFFS

#define PACKFILE_FLAG_TRUEOFFS   (1 << 0)

the offset in packfile_t is the true contents offset

Definition at line 370 of file fs.c.

Referenced by FS_LoadPackPAK(), FS_OpenPackedFile(), and PK3_GetTrueFileOffset().

◆ QFILE_FLAG_DATA

#define QFILE_FLAG_DATA   (1 << 2)

file is actually already loaded data

Definition at line 298 of file fs.c.

Referenced by FS_Close(), FS_FileFromData(), FS_Read(), and FS_Seek().

◆ QFILE_FLAG_DEFLATED

#define QFILE_FLAG_DEFLATED   (1 << 1)

file is compressed using the deflate algorithm (PK3 only)

Definition at line 296 of file fs.c.

Referenced by FS_OpenPackedFile(), FS_Read(), and FS_Seek().

◆ QFILE_FLAG_PACKED

#define QFILE_FLAG_PACKED   (1 << 0)

inside a package (PAK or PK3)

Definition at line 294 of file fs.c.

Referenced by FS_OpenPackedFile().

◆ QFILE_FLAG_REMOVE

#define QFILE_FLAG_REMOVE   (1 << 3)

real file will be removed on close

Definition at line 300 of file fs.c.

Referenced by FS_Close(), and FS_RemoveOnClose().

◆ qz_deflateInit2

#define qz_deflateInit2 ( strm,
level,
method,
windowBits,
memLevel,
strategy )
Value:
qz_deflateInit2_((strm), (level), (method), (windowBits), (memLevel), (strategy), ZLIB_VERSION, sizeof(z_stream))
static int int method
Definition fs.c:481
#define ZLIB_VERSION
Definition fs.c:239
static int int int int memLevel
Definition fs.c:481
static int windowBits
Definition fs.c:479
static int level
Definition fs.c:481
static int int int int int strategy
Definition fs.c:481
Definition fs.c:270

Definition at line 488 of file fs.c.

488#define qz_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
489 qz_deflateInit2_((strm), (level), (method), (windowBits), (memLevel), (strategy), ZLIB_VERSION, sizeof(z_stream))

Referenced by FS_Deflate().

◆ qz_inflateInit2

#define qz_inflateInit2 ( strm,
windowBits )
Value:
qz_inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))

Definition at line 486 of file fs.c.

486#define qz_inflateInit2(strm, windowBits) \
487 qz_inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))

Referenced by FS_Inflate(), and FS_OpenPackedFile().

◆ S_ISDIR

#define S_ISDIR ( a)
Value:
(((a) & S_IFMT) == S_IFDIR)
ret a

Referenced by FS_SysFileType().

◆ WPATHDEF

#define WPATHDEF ( var)
Value:
;

Definition at line 84 of file fs.c.

Referenced by FS_Init_Dir(), FS_mkdir(), FS_SysFileType(), and FS_SysOpenFiledesc().

◆ Z_BINARY

#define Z_BINARY   0

Definition at line 241 of file fs.c.

Referenced by FS_Deflate().

◆ Z_BUF_ERROR

#define Z_BUF_ERROR   (-5)

Definition at line 238 of file fs.c.

Referenced by FS_Inflate().

◆ Z_DATA_ERROR

#define Z_DATA_ERROR   (-3)

Definition at line 236 of file fs.c.

Referenced by FS_Inflate().

◆ Z_DEFAULT_COMPRESSION

#define Z_DEFAULT_COMPRESSION   (-1)

Definition at line 246 of file fs.c.

Referenced by FS_Deflate().

◆ Z_DEFLATED

#define Z_DEFLATED   8

Definition at line 242 of file fs.c.

Referenced by FS_Deflate().

◆ Z_FINISH

#define Z_FINISH   4

Definition at line 250 of file fs.c.

Referenced by FS_Deflate().

◆ Z_FULL_FLUSH

#define Z_FULL_FLUSH   3

Definition at line 249 of file fs.c.

◆ Z_MEM_ERROR

#define Z_MEM_ERROR   (-4)

Definition at line 237 of file fs.c.

Referenced by FS_Inflate().

◆ Z_MEMLEVEL_DEFAULT

#define Z_MEMLEVEL_DEFAULT   8

Definition at line 243 of file fs.c.

Referenced by FS_Deflate().

◆ Z_NO_FLUSH

#define Z_NO_FLUSH   0

Definition at line 247 of file fs.c.

Referenced by FS_Inflate().

◆ Z_NULL

#define Z_NULL   0

Definition at line 245 of file fs.c.

Referenced by FS_Deflate(), and FS_Inflate().

◆ Z_OK

#define Z_OK   0

Definition at line 233 of file fs.c.

Referenced by FS_Deflate(), FS_Inflate(), FS_OpenPackedFile(), and FS_Read().

◆ Z_STREAM_END

#define Z_STREAM_END   1

Definition at line 234 of file fs.c.

Referenced by FS_Deflate(), FS_Inflate(), and FS_Read().

◆ Z_STREAM_ERROR

#define Z_STREAM_ERROR   (-2)

Definition at line 235 of file fs.c.

Referenced by FS_Inflate().

◆ Z_SYNC_FLUSH [1/2]

#define Z_SYNC_FLUSH   2

Definition at line 231 of file fs.c.

Referenced by FS_Read().

◆ Z_SYNC_FLUSH [2/2]

#define Z_SYNC_FLUSH   2

Definition at line 231 of file fs.c.

◆ ZEXPORT

#define ZEXPORT

Definition at line 474 of file fs.c.

◆ ZIP_CDIR_CHUNK_BASE_SIZE

#define ZIP_CDIR_CHUNK_BASE_SIZE   46

Definition at line 214 of file fs.c.

Referenced by PK3_BuildFileList().

◆ ZIP_CDIR_HEADER

#define ZIP_CDIR_HEADER   0x504B0102

Definition at line 208 of file fs.c.

Referenced by PK3_BuildFileList().

◆ ZIP_DATA_HEADER

#define ZIP_DATA_HEADER   0x504B0304

Definition at line 207 of file fs.c.

Referenced by PK3_GetTrueFileOffset().

◆ ZIP_END_CDIR_SIZE

#define ZIP_END_CDIR_SIZE   22

Definition at line 213 of file fs.c.

Referenced by PK3_GetEndOfCentralDir().

◆ ZIP_END_HEADER

#define ZIP_END_HEADER   0x504B0506

Definition at line 209 of file fs.c.

Referenced by PK3_GetEndOfCentralDir().

◆ ZIP_LOCAL_CHUNK_BASE_SIZE

#define ZIP_LOCAL_CHUNK_BASE_SIZE   30

Definition at line 215 of file fs.c.

Referenced by PK3_GetTrueFileOffset().

◆ ZIP_MAX_COMMENTS_SIZE

#define ZIP_MAX_COMMENTS_SIZE   ((unsigned short)0xFFFF)

Definition at line 212 of file fs.c.

Referenced by PK3_GetEndOfCentralDir().

◆ ZLIB_VERSION

#define ZLIB_VERSION   "1.2.3"

Definition at line 239 of file fs.c.

Typedef Documentation

◆ filedesc_t

typedef int filedesc_t

Definition at line 106 of file fs.c.

Function Documentation

◆ AssertBufsize()

static void AssertBufsize ( sizebuf_t * buf,
int length )
static

Definition at line 4257 of file fs.c.

4258{
4259 if(buf->cursize + length > buf->maxsize)
4260 {
4261 int oldsize = buf->maxsize;
4262 unsigned char *olddata;
4263 olddata = buf->data;
4264 buf->maxsize += length;
4265 buf->data = (unsigned char *) Mem_Alloc(tempmempool, buf->maxsize);
4266 if(olddata)
4267 {
4268 memcpy(buf->data, olddata, oldsize);
4270 }
4271 }
4272}
static unsigned char olddata[NET_MAXMESSAGE]
Definition cl_parse.c:313
GLenum GLuint GLenum GLsizei length
Definition glquake.h:657
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glquake.h:657
mempool_t * tempmempool
Definition zone.c:794
#define Mem_Free(mem)
Definition zone.h:96
#define Mem_Alloc(pool, size)
Definition zone.h:92

References buf, length, Mem_Alloc, Mem_Free, olddata, and tempmempool.

Referenced by FS_Inflate().

◆ COM_InsertFlags()

static void COM_InsertFlags ( const char * buf)
static

Definition at line 1911 of file fs.c.

1911 {
1912 const char *p;
1913 char *q;
1914 const char **new_argv;
1915 int i = 0;
1916 int args_left = 256;
1917 new_argv = (const char **)Mem_Alloc(fs_mempool, sizeof(*sys.argv) * (sys.argc + args_left + 2));
1918 if(sys.argc == 0)
1919 new_argv[0] = "dummy"; // Can't really happen.
1920 else
1921 new_argv[0] = sys.argv[0];
1922 ++i;
1923 p = buf;
1924 while(COM_ParseToken_Console(&p))
1925 {
1926 size_t sz = strlen(com_token) + 1; // shut up clang
1927 if(i > args_left)
1928 break;
1929 q = (char *)Mem_Alloc(fs_mempool, sz);
1930 dp_strlcpy(q, com_token, sz);
1931 new_argv[i] = q;
1932 ++i;
1933 }
1934 // Now: i <= args_left + 1.
1935 if (sys.argc >= 1)
1936 {
1937 memcpy((char *)(&new_argv[i]), &sys.argv[1], sizeof(*sys.argv) * (sys.argc - 1));
1938 i += sys.argc - 1;
1939 }
1940 // Now: i <= args_left + (sys.argc || 1).
1941 new_argv[i] = NULL;
1942 sys.argv = new_argv;
1943 sys.argc = i;
1944}
char com_token[MAX_INPUTLINE]
Definition common.c:39
qbool COM_ParseToken_Console(const char **datapointer)
Definition common.c:819
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
mempool_t * fs_mempool
Definition fs.c:434
float strlen(string s)
int i
#define NULL
Definition qtypes.h:12
int argc
Definition sys.h:146
const char ** argv
Definition sys.h:147
sys_t sys
Definition sys_shared.c:42

References sys_t::argc, sys_t::argv, buf, COM_ParseToken_Console(), com_token, dp_strlcpy, fs_mempool, i, Mem_Alloc, NULL, strlen(), and sys.

Referenced by FS_Init_SelfPack().

◆ FILEDESC_DUP()

static filedesc_t FILEDESC_DUP ( const char * filename,
filedesc_t fd )
static

Definition at line 113 of file fs.c.

113 {
114 return dup(fd);
115}

Referenced by FS_OpenPackedFile().

◆ FS_AddFileToPack()

static packfile_t * FS_AddFileToPack ( const char * name,
pack_t * pack,
fs_offset_t offset,
fs_offset_t packsize,
fs_offset_t realsize,
int flags )
static

Definition at line 954 of file fs.c.

957{
958 int (*strcmp_funct) (const char* str1, const char* str2);
959 int left, right, middle;
960 packfile_t *pfile;
961
962 strcmp_funct = pack->ignorecase ? strcasecmp : strcmp;
963
964 // Look for the slot we should put that file into (binary search)
965 left = 0;
966 right = pack->numfiles - 1;
967 while (left <= right)
968 {
969 int diff;
970
971 middle = (left + right) / 2;
972 diff = strcmp_funct (pack->files[middle].name, name);
973
974 // If we found the file, there's a problem
975 if (!diff)
976 Con_Printf ("Package %s contains the file %s several times\n", pack->filename, name);
977
978 // If we're too far in the list
979 if (diff > 0)
980 right = middle - 1;
981 else
982 left = middle + 1;
983 }
984
985 // We have to move the right of the list by one slot to free the one we need
986 pfile = &pack->files[left];
987 memmove (pfile + 1, pfile, (pack->numfiles - left) * sizeof (*pfile));
988 pack->numfiles++;
989
990 dp_strlcpy (pfile->name, name, sizeof (pfile->name));
991 pfile->offset = offset;
992 pfile->packsize = packsize;
993 pfile->realsize = realsize;
994 pfile->flags = flags;
995
996 return pfile;
997}
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
float flags
static int(ZEXPORT *qz_inflate)(z_stream *strm
GLuint GLuint GLintptr offset
Definition glquake.h:632
const GLchar * name
Definition glquake.h:601
int numfiles
Definition fs.c:391
qbool ignorecase
PK3 ignores case.
Definition fs.c:390
char filename[MAX_OSPATH]
Definition fs.c:387
packfile_t * files
Definition fs.c:394
fs_offset_t realsize
real file size (uncompressed)
Definition fs.c:382
char name[MAX_QPATH]
Definition fs.c:378
fs_offset_t offset
Definition fs.c:380
fs_offset_t packsize
size in the package
Definition fs.c:381
int flags
Definition fs.c:379
static vec3_t right
Definition sv_user.c:305

References Con_Printf(), dp_strlcpy, pack_t::filename, pack_t::files, flags, packfile_t::flags, pack_t::ignorecase, int(), name, packfile_t::name, pack_t::numfiles, offset, packfile_t::offset, packfile_t::packsize, packfile_t::realsize, and right.

Referenced by FS_LoadPackPAK(), and PK3_BuildFileList().

◆ FS_AddGameDirectory()

static void FS_AddGameDirectory ( const char * dir)
static

Definition at line 1340 of file fs.c.

1341{
1342 int i;
1343 stringlist_t list;
1344 searchpath_t *search;
1345
1346 dp_strlcpy (fs_gamedir, dir, sizeof (fs_gamedir));
1347
1348 stringlistinit(&list);
1349 listdirectory(&list, "", dir);
1350 stringlistsort(&list, false);
1351
1352 // add any PAK package in the directory
1353 for (i = 0;i < list.numstrings;i++)
1354 {
1355 if (!strcasecmp(FS_FileExtension(list.strings[i]), "pak"))
1356 {
1357 FS_AddPack_Fullpath(list.strings[i], list.strings[i] + strlen(dir), NULL, false, false);
1358 }
1359 }
1360
1361 // add any PK3 package in the directory
1362 for (i = 0;i < list.numstrings;i++)
1363 {
1364 if (!strcasecmp(FS_FileExtension(list.strings[i]), "pk3") || !strcasecmp(FS_FileExtension(list.strings[i]), "obb") || !strcasecmp(FS_FileExtension(list.strings[i]), "pk3dir")
1365 || !strcasecmp(FS_FileExtension(list.strings[i]), "dpk") || !strcasecmp(FS_FileExtension(list.strings[i]), "dpkdir"))
1366 {
1367 FS_AddPack_Fullpath(list.strings[i], list.strings[i] + strlen(dir), NULL, false, false);
1368 }
1369 }
1370
1372
1373 // Add the directory to the search path
1374 // (unpacked files have the priority over packed files)
1375 search = (searchpath_t *)Mem_Alloc(fs_mempool, sizeof(searchpath_t));
1376 dp_strlcpy (search->filename, dir, sizeof (search->filename));
1377 search->next = fs_searchpaths;
1378 fs_searchpaths = search;
1379}
void stringlistfreecontents(stringlist_t *list)
Definition filematch.c:87
void stringlistinit(stringlist_t *list)
Definition filematch.c:82
void stringlistsort(stringlist_t *list, qbool uniq)
Definition filematch.c:129
void listdirectory(stringlist_t *list, const char *basepath, const char *path)
Definition filematch.c:198
const char * FS_FileExtension(const char *in)
Definition fs.c:1403
char fs_gamedir[MAX_OSPATH]
Definition fs.c:443
searchpath_t * fs_searchpaths
Definition fs.c:437
static qbool FS_AddPack_Fullpath(const char *pakfile, const char *shortname, qbool *already_loaded, qbool keep_plain_dirs, qbool dlcache)
Definition fs.c:1194
vec2 dir
Search paths for files (including packages)
Definition fs.c:400
struct searchpath_s * next
Definition fs.c:404
char filename[MAX_OSPATH]
Definition fs.c:402
char ** strings
Definition filematch.h:31

References dir, dp_strlcpy, searchpath_t::filename, FS_AddPack_Fullpath(), FS_FileExtension(), fs_gamedir, fs_mempool, fs_searchpaths, i, listdirectory(), Mem_Alloc, searchpath_t::next, NULL, stringlist_t::numstrings, stringlistfreecontents(), stringlistinit(), stringlistsort(), stringlist_t::strings, and strlen().

Referenced by FS_AddGameHierarchy().

◆ FS_AddGameHierarchy()

static void FS_AddGameHierarchy ( const char * dir)
static

Definition at line 1387 of file fs.c.

1388{
1389 char vabuf[1024];
1390 // Add the common game directory
1391 FS_AddGameDirectory (va(vabuf, sizeof(vabuf), "%s%s/", fs_basedir, dir));
1392
1393 if (*fs_userdir)
1394 FS_AddGameDirectory(va(vabuf, sizeof(vabuf), "%s%s/", fs_userdir, dir));
1395}
char * va(char *buf, size_t buflen, const char *format,...)
Definition common.c:972
static void FS_AddGameDirectory(const char *dir)
Definition fs.c:1340
char fs_basedir[MAX_OSPATH]
Definition fs.c:444
char fs_userdir[MAX_OSPATH]
Definition fs.c:442

References dir, FS_AddGameDirectory(), fs_basedir, fs_userdir, and va().

Referenced by FS_Rescan().

◆ FS_AddPack()

qbool FS_AddPack ( const char * pakfile,
qbool * already_loaded,
qbool keep_plain_dirs,
qbool dlcache )

Adds the given pack to the search path and searches for it in the game path. The pack type is autodetected by the file extension.

Returns true if the file was successfully added to the search path or if it was already included.

If keep_plain_dirs is set, the pack will be added AFTER the first sequence of plain directories.

Definition at line 1309 of file fs.c.

1310{
1311 char fullpath[MAX_OSPATH];
1312 int index;
1313 searchpath_t *search;
1314
1315 if(already_loaded)
1316 *already_loaded = false;
1317
1318 // then find the real name...
1319 search = FS_FindFile(pakfile, &index, NULL, true);
1320 if(!search || search->pack)
1321 {
1322 Con_Printf("could not find pak \"%s\"\n", pakfile);
1323 return false;
1324 }
1325
1326 dpsnprintf(fullpath, sizeof(fullpath), "%s%s", search->filename, pakfile);
1327
1328 return FS_AddPack_Fullpath(fullpath, pakfile, already_loaded, keep_plain_dirs, dlcache);
1329}
int dpsnprintf(char *buffer, size_t buffersize, const char *format,...)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
Definition common.c:997
static searchpath_t * FS_FindFile(const char *name, int *index, const char **canonicalname, qbool quiet)
Definition fs.c:2691
GLuint index
Definition glquake.h:629
#define MAX_OSPATH
max length of a filesystem pathname
Definition qdefs.h:175
pack_t * pack
Definition fs.c:403

References Con_Printf(), dpsnprintf(), searchpath_t::filename, FS_AddPack_Fullpath(), FS_FindFile(), index, MAX_OSPATH, NULL, and searchpath_t::pack.

Referenced by Curl_Begin(), and Curl_EndDownload().

◆ FS_AddPack_Fullpath()

static qbool FS_AddPack_Fullpath ( const char * pakfile,
const char * shortname,
qbool * already_loaded,
qbool keep_plain_dirs,
qbool dlcache )
static

Adds the given pack to the search path. The pack type is autodetected by the file extension.

Returns true if the file was successfully added to the search path or if it was already included.

If keep_plain_dirs is set, the pack will be added AFTER the first sequence of plain directories.

Definition at line 1194 of file fs.c.

1195{
1196 searchpath_t *search;
1197 pack_t *pak = NULL;
1198 const char *ext = FS_FileExtension(pakfile);
1199 size_t l;
1200
1201 for(search = fs_searchpaths; search; search = search->next)
1202 {
1203 if(search->pack && !strcasecmp(search->pack->filename, pakfile))
1204 {
1205 if(already_loaded)
1206 *already_loaded = true;
1207 return true; // already loaded
1208 }
1209 }
1210
1211 if(already_loaded)
1212 *already_loaded = false;
1213
1214 if(!strcasecmp(ext, "pk3dir") || !strcasecmp(ext, "dpkdir"))
1215 pak = FS_LoadPackVirtual (pakfile);
1216 else if(!strcasecmp(ext, "pak"))
1217 pak = FS_LoadPackPAK (pakfile);
1218 else if(!strcasecmp(ext, "pk3") || !strcasecmp(ext, "dpk"))
1219 pak = FS_LoadPackPK3 (pakfile);
1220 else if(!strcasecmp(ext, "obb")) // android apk expansion
1221 pak = FS_LoadPackPK3 (pakfile);
1222 else
1223 Con_Printf("\"%s\" does not have a pack extension\n", pakfile);
1224
1225 if(pak)
1226 {
1227 dp_strlcpy(pak->shortname, shortname, sizeof(pak->shortname));
1228
1229 //Con_DPrintf(" Registered pack with short name %s\n", shortname);
1230 if(keep_plain_dirs)
1231 {
1232 // find the first item whose next one is a pack or NULL
1233 searchpath_t *insertion_point = 0;
1235 {
1236 insertion_point = fs_searchpaths;
1237 for(;;)
1238 {
1239 if(!insertion_point->next)
1240 break;
1241 if(insertion_point->next->pack)
1242 break;
1243 insertion_point = insertion_point->next;
1244 }
1245 }
1246 // If insertion_point is NULL, this means that either there is no
1247 // item in the list yet, or that the very first item is a pack. In
1248 // that case, we want to insert at the beginning...
1249 if(!insertion_point)
1250 {
1251 search = (searchpath_t *)Mem_Alloc(fs_mempool, sizeof(searchpath_t));
1252 search->next = fs_searchpaths;
1253 fs_searchpaths = search;
1254 }
1255 else
1256 // otherwise we want to append directly after insertion_point.
1257 {
1258 search = (searchpath_t *)Mem_Alloc(fs_mempool, sizeof(searchpath_t));
1259 search->next = insertion_point->next;
1260 insertion_point->next = search;
1261 }
1262 }
1263 else
1264 {
1265 search = (searchpath_t *)Mem_Alloc(fs_mempool, sizeof(searchpath_t));
1266 search->next = fs_searchpaths;
1267 fs_searchpaths = search;
1268 }
1269 search->pack = pak;
1270 search->pack->dlcache = dlcache;
1271 if(pak->vpack)
1272 {
1273 dpsnprintf(search->filename, sizeof(search->filename), "%s/", pakfile);
1274 // if shortname ends with "pk3dir" or "dpkdir", strip that suffix to make it just "pk3" or "dpk"
1275 // same goes for the name inside the pack structure
1276 l = strlen(pak->shortname);
1277 if(l >= 7)
1278 if(!strcasecmp(pak->shortname + l - 7, ".pk3dir") || !strcasecmp(pak->shortname + l - 7, ".dpkdir"))
1279 pak->shortname[l - 3] = 0;
1280 l = strlen(pak->filename);
1281 if(l >= 7)
1282 if(!strcasecmp(pak->filename + l - 7, ".pk3dir") || !strcasecmp(pak->filename + l - 7, ".dpkdir"))
1283 pak->filename[l - 3] = 0;
1284 }
1285 return true;
1286 }
1287 else
1288 {
1289 Con_Printf(CON_ERROR "unable to load pak \"%s\"\n", pakfile);
1290 return false;
1291 }
1292}
#define CON_ERROR
Definition console.h:102
static pack_t * FS_LoadPackPK3(const char *packfile)
Definition fs.c:891
static pack_t * FS_LoadPackVirtual(const char *dirname)
Definition fs.c:1165
static pack_t * FS_LoadPackPAK(const char *packfile)
Definition fs.c:1081
Definition fs.c:386
char shortname[MAX_QPATH]
Definition fs.c:388
qbool vpack
Definition fs.c:392
qbool dlcache
Definition fs.c:393

References CON_ERROR, Con_Printf(), pack_t::dlcache, dp_strlcpy, dpsnprintf(), pack_t::filename, searchpath_t::filename, FS_FileExtension(), FS_LoadPackPAK(), FS_LoadPackPK3(), FS_LoadPackVirtual(), fs_mempool, fs_searchpaths, Mem_Alloc, searchpath_t::next, NULL, searchpath_t::pack, pack_t::shortname, strlen(), and pack_t::vpack.

Referenced by FS_AddGameDirectory(), and FS_AddPack().

◆ FS_AddSelfPack()

static void FS_AddSelfPack ( void )
static

Definition at line 1519 of file fs.c.

1520{
1521 if(fs_selfpack)
1522 {
1523 searchpath_t *search;
1524 search = (searchpath_t *)Mem_Alloc(fs_mempool, sizeof(searchpath_t));
1525 search->next = fs_searchpaths;
1526 search->pack = fs_selfpack;
1527 fs_searchpaths = search;
1528 }
1529}
static pack_t * fs_selfpack
Definition fs.c:445

References fs_mempool, fs_searchpaths, fs_selfpack, Mem_Alloc, searchpath_t::next, and searchpath_t::pack.

Referenced by FS_Init_SelfPack(), and FS_Rescan().

◆ FS_ChangeGameDirs()

qbool FS_ChangeGameDirs ( int numgamedirs,
const char * gamedirs[],
qbool failmissing )

Definition at line 1719 of file fs.c.

1720{
1721 addgamedirs_t addresult = COM_ChangeGameTypeForGameDirs(numgamedirs, gamedirs, failmissing, false);
1722
1723 if (addresult == GAMEDIRS_ALLGOOD)
1724 return true; // already using this set of gamedirs, do nothing
1725 else if (addresult == GAMEDIRS_FAILURE)
1726 return false;
1727
1729
1730 if (cls.demoplayback)
1731 CL_Disconnect();
1732 cls.demonum = 0; // make sure startdemos will work if the mod uses it
1733
1734 // unload all sounds so they will be reloaded from the new files as needed
1736
1737 // reinitialize filesystem to detect the new paks
1738 FS_Rescan();
1739
1740 // reload assets after the config is executed
1741 Cbuf_InsertText(cmd_local, "\nloadconfig\nr_restart\n");
1742
1743 return true;
1744}
client_static_t cls
Definition cl_main.c:116
void CL_Disconnect(void)
Definition cl_main.c:478
void Cbuf_InsertText(cmd_state_t *cmd, const char *text)
Definition cmd.c:292
cmd_state_t * cmd_local
command interpreter for local commands injected by SVQC, CSQC, MQC, server or client engine code uses...
Definition cmd.c:25
int COM_ChangeGameTypeForGameDirs(unsigned numgamedirs, const char *gamedirs[], qbool failmissing, qbool init)
Definition com_game.c:122
void FS_Rescan(void)
Definition fs.c:1538
addgamedirs_t
Definition fs.h:102
@ GAMEDIRS_ALLGOOD
Definition fs.h:103
@ GAMEDIRS_FAILURE
Definition fs.h:104
void Host_SaveConfig(const char *file)
Definition host.c:196
#define CONFIGFILENAME
Definition quakedef.h:29
void S_UnloadAllSounds_f(cmd_state_t *cmd)
Definition snd_main.c:864
qbool demoplayback
Definition client.h:587

References Cbuf_InsertText(), CL_Disconnect(), cls, cmd_local, COM_ChangeGameTypeForGameDirs(), CONFIGFILENAME, client_static_t::demonum, client_static_t::demoplayback, FS_Rescan(), GAMEDIRS_ALLGOOD, GAMEDIRS_FAILURE, Host_SaveConfig(), and S_UnloadAllSounds_f().

Referenced by CL_ParseServerInfo(), FS_GameDir_f(), and ModList_Enable().

◆ FS_CheckGameDir()

const char * FS_CheckGameDir ( const char * gamedir)

Definition at line 1824 of file fs.c.

1825{
1826 const char *ret;
1827 static char buf[8192];
1828 char vabuf[1024];
1829
1830 if (FS_CheckNastyPath(gamedir, true))
1831 return NULL;
1832
1833 ret = FS_SysCheckGameDir(va(vabuf, sizeof(vabuf), "%s%s/", fs_userdir, gamedir), buf, sizeof(buf));
1834 if(ret)
1835 {
1836 if(!*ret)
1837 {
1838 // get description from basedir
1839 ret = FS_SysCheckGameDir(va(vabuf, sizeof(vabuf), "%s%s/", fs_basedir, gamedir), buf, sizeof(buf));
1840 if(ret)
1841 return ret;
1842 return "";
1843 }
1844 return ret;
1845 }
1846
1847 ret = FS_SysCheckGameDir(va(vabuf, sizeof(vabuf), "%s%s/", fs_basedir, gamedir), buf, sizeof(buf));
1848 if(ret)
1849 return ret;
1850
1852}
static const char * FS_SysCheckGameDir(const char *gamedir, char *buf, size_t buflength)
Definition fs.c:1786
const char *const fs_checkgamedir_missing
Definition fs.c:438
int FS_CheckNastyPath(const char *path, qbool isgamedir)
Definition fs.c:2619
return ret

References buf, fs_basedir, fs_checkgamedir_missing, FS_CheckNastyPath(), FS_SysCheckGameDir(), fs_userdir, NULL, ret, and va().

Referenced by FS_ListGameDirs(), FS_SetGameDirs(), and ModList_RebuildList().

◆ FS_CheckNastyPath()

int FS_CheckNastyPath ( const char * path,
qbool isgamedir )

Definition at line 2619 of file fs.c.

2620{
2621 // all: never allow an empty path, as for gamedir it would access the parent directory and a non-gamedir path it is just useless
2622 if (!path[0])
2623 return 2;
2624
2625 // Windows: don't allow \ in filenames (windows-only), period.
2626 // (on Windows \ is a directory separator, but / is also supported)
2627 if (strstr(path, "\\"))
2628 return 1; // non-portable
2629
2630 // Mac: don't allow Mac-only filenames - : is a directory separator
2631 // instead of /, but we rely on / working already, so there's no reason to
2632 // support a Mac-only path
2633 // Amiga and Windows: : tries to go to root of drive
2634 if (strstr(path, ":"))
2635 return 1; // non-portable attempt to go to root of drive
2636
2637 // Amiga: // is parent directory
2638 if (strstr(path, "//"))
2639 return 1; // non-portable attempt to go to parent directory
2640
2641 // all: don't allow going to parent directory (../ or /../)
2642 if (strstr(path, ".."))
2643 return 2; // attempt to go outside the game directory
2644
2645 // Windows and UNIXes: don't allow absolute paths
2646 if (path[0] == '/')
2647 return 2; // attempt to go outside the game directory
2648
2649 // all: don't allow . character immediately before a slash, this catches all imaginable cases of ./, ../, .../, etc
2650 if (strstr(path, "./"))
2651 return 2; // possible attempt to go outside the game directory
2652
2653 // all: forbid trailing slash on gamedir
2654 if (isgamedir && path[strlen(path)-1] == '/')
2655 return 2;
2656
2657 // all: forbid leading dot on any filename for any reason
2658 if (strstr(path, "/."))
2659 return 2; // attempt to go outside the game directory
2660
2661 // after all these checks we're pretty sure it's a / separated filename
2662 // and won't do much if any harm
2663 return false;
2664}

References strlen().

Referenced by CL_DownloadBegin_f(), FS_CheckGameDir(), FS_OpenReadFile(), FS_OpenRealFile(), FS_OpenVirtualFile(), SV_Download_f(), and VM_loadfromfile().

◆ FS_ChooseUserDir()

static int FS_ChooseUserDir ( userdirmode_t userdirmode,
char * userdir,
size_t userdirsize )
static

Definition at line 1946 of file fs.c.

1947{
1948#if defined(__IPHONEOS__)
1949 if (userdirmode == USERDIRMODE_HOME)
1950 {
1951 // fs_basedir is "" by default, to utilize this you can simply add your gamedir to the Resources in xcode
1952 // fs_userdir stores configurations to the Documents folder of the app
1953 dp_strlcpy(userdir, "../Documents/", MAX_OSPATH);
1954 return 1;
1955 }
1956 return -1;
1957
1958#elif defined(WIN32)
1959 char homedir[MAX_OSWPATH];
1960 wchar *homedirw;
1961#if _MSC_VER >= 1400
1962 size_t homedirwlen;
1963#endif
1964 char mydocsdir[MAX_OSWPATH];
1965 wchar mydocsdirw[MAX_OSWPATH];
1966 char savedgamesdir[MAX_OSWPATH];
1967 wchar *savedgamesdirw;
1968 int fd;
1969 char vabuf[1024];
1970
1971 userdir[0] = 0;
1972 switch(userdirmode)
1973 {
1974 default:
1975 return -1;
1976 case USERDIRMODE_NOHOME:
1977 dp_strlcpy(userdir, fs_basedir, userdirsize);
1978 break;
1980 if (!shfolder_dll)
1981 Sys_LoadDependency(shfolderdllnames, &shfolder_dll, shfolderfuncs);
1982 mydocsdir[0] = 0;
1983 if (qSHGetFolderPath && qSHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdirw) == S_OK)
1984 {
1985 NARROW(mydocsdirw, mydocsdir);
1986 dpsnprintf(userdir, userdirsize, "%s/My Games/%s/", mydocsdir, gameuserdirname);
1987 break;
1988 }
1989#if _MSC_VER >= 1400
1990 _wdupenv_s(&homedirw, &homedirwlen, L"USERPROFILE");
1991 NARROW(homedirw, homedir);
1992 if(homedir[0])
1993 {
1994 dpsnprintf(userdir, userdirsize, "%s/.%s/", homedir, gameuserdirname);
1995 free(homedirw);
1996 break;
1997 }
1998#else
1999 homedirw = _wgetenv(L"USERPROFILE");
2000 NARROW(homedirw, homedir);
2001 if(homedir[0])
2002 {
2003 dpsnprintf(userdir, userdirsize, "%s/.%s/", homedir, gameuserdirname);
2004 break;
2005 }
2006#endif
2007 return -1;
2009 if (!shell32_dll)
2010 Sys_LoadDependency(shell32dllnames, &shell32_dll, shell32funcs);
2011 if (!ole32_dll)
2012 Sys_LoadDependency(ole32dllnames, &ole32_dll, ole32funcs);
2013 if (qSHGetKnownFolderPath && qCoInitializeEx && qCoTaskMemFree && qCoUninitialize)
2014 {
2015 savedgamesdir[0] = 0;
2016 qCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
2017/*
2018#ifdef __cplusplus
2019 if (SHGetKnownFolderPath(FOLDERID_SavedGames, KF_FLAG_CREATE | KF_FLAG_NO_ALIAS, NULL, &savedgamesdirw) == S_OK)
2020#else
2021 if (SHGetKnownFolderPath(&FOLDERID_SavedGames, KF_FLAG_CREATE | KF_FLAG_NO_ALIAS, NULL, &savedgamesdirw) == S_OK)
2022#endif
2023*/
2024 if (qSHGetKnownFolderPath(&qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &savedgamesdirw) == S_OK)
2025 {
2026 NARROW(savedgamesdirw, savedgamesdir);
2027 qCoTaskMemFree(savedgamesdirw);
2028 }
2029 qCoUninitialize();
2030 if (savedgamesdir[0])
2031 {
2032 dpsnprintf(userdir, userdirsize, "%s/%s/", savedgamesdir, gameuserdirname);
2033 break;
2034 }
2035 }
2036 return -1;
2037 }
2038#else
2039 int fd;
2040 char *homedir;
2041 char vabuf[1024];
2042 userdir[0] = 0;
2043 switch(userdirmode)
2044 {
2045 default:
2046 return -1;
2047 case USERDIRMODE_NOHOME:
2048 dp_strlcpy(userdir, fs_basedir, userdirsize);
2049 break;
2050 case USERDIRMODE_HOME:
2051 homedir = getenv("HOME");
2052 if(homedir)
2053 {
2054 dpsnprintf(userdir, userdirsize, "%s/.%s/", homedir, gameuserdirname);
2055 break;
2056 }
2057 return -1;
2059 homedir = getenv("HOME");
2060 if(homedir)
2061 {
2062#ifdef MACOSX
2063 dpsnprintf(userdir, userdirsize, "%s/Library/Application Support/%s/", homedir, gameuserdirname);
2064#else
2065 // the XDG say some files would need to go in:
2066 // XDG_CONFIG_HOME (or ~/.config/%s/)
2067 // XDG_DATA_HOME (or ~/.local/share/%s/)
2068 // XDG_CACHE_HOME (or ~/.cache/%s/)
2069 // and also search the following global locations if defined:
2070 // XDG_CONFIG_DIRS (normally /etc/xdg/%s/)
2071 // XDG_DATA_DIRS (normally /usr/share/%s/)
2072 // this would be too complicated...
2073 return -1;
2074#endif
2075 break;
2076 }
2077 return -1;
2078 }
2079#endif
2080
2081
2082#if !defined(__IPHONEOS__)
2083
2084#ifdef WIN32
2085 // historical behavior...
2086 if (userdirmode == USERDIRMODE_NOHOME && strcmp(gamedirname1, "id1"))
2087 return 0; // don't bother checking if the basedir folder is writable, it's annoying... unless it is Quake on Windows where NOHOME is the default preferred and we have to check for an error case
2088#endif
2089
2090 // see if we can write to this path (note: won't create path)
2091#ifdef WIN32
2092 // no access() here, we must try to open the file for appending
2093 fd = FS_SysOpenFiledesc(va(vabuf, sizeof(vabuf), "%s%s/config.cfg", userdir, gamedirname1), "a", false);
2094 if(fd >= 0)
2095 FILEDESC_CLOSE(fd);
2096#else
2097 // on Unix, we don't need to ACTUALLY attempt to open the file
2098 if(access(va(vabuf, sizeof(vabuf), "%s%s/", userdir, gamedirname1), W_OK | X_OK) >= 0)
2099 fd = 1;
2100 else
2101 fd = -1;
2102#endif
2103 if(fd >= 0)
2104 {
2105 return 1; // good choice - the path exists and is writable
2106 }
2107 else
2108 {
2109 if (userdirmode == USERDIRMODE_NOHOME)
2110 return -1; // path usually already exists, we lack permissions
2111 else
2112 return 0; // probably good - failed to write but maybe we need to create path
2113 }
2114#endif
2115}
const char * gameuserdirname
Definition com_game.c:32
const char * gamedirname1
Definition com_game.c:29
@ USERDIRMODE_SAVEDGAMES
Definition common.h:287
@ USERDIRMODE_NOHOME
Definition common.h:284
@ USERDIRMODE_MYGAMES
Definition common.h:286
@ USERDIRMODE_HOME
Definition common.h:285
#define FILEDESC_CLOSE
Definition fs.c:111
static filedesc_t FS_SysOpenFiledesc(const char *filepath, const char *mode, qbool nonblocking)
Definition fs.c:2383
qbool Sys_LoadDependency(const char **dllnames, dllhandle_t *handle, const dllfunction_t *fcts)
Definition sys_shared.c:131
#define NARROW(wstr, str)
Definition utf8lib.h:107

References dp_strlcpy, dpsnprintf(), FILEDESC_CLOSE, fs_basedir, FS_SysOpenFiledesc(), gamedirname1, gameuserdirname, MAX_OSPATH, NARROW, NULL, Sys_LoadDependency(), USERDIRMODE_HOME, USERDIRMODE_MYGAMES, USERDIRMODE_NOHOME, USERDIRMODE_SAVEDGAMES, and va().

Referenced by FS_Init_Dir().

◆ FS_ClearSearchPath()

static void FS_ClearSearchPath ( void )
static

Definition at line 1451 of file fs.c.

1452{
1453 // unload all packs and directory information, close all pack files
1454 // (if a qfile is still reading a pack it won't be harmed because it used
1455 // dup() to get its own handle already)
1456 while (fs_searchpaths)
1457 {
1458 searchpath_t *search = fs_searchpaths;
1459 fs_searchpaths = search->next;
1460 if (search->pack && search->pack != fs_selfpack)
1461 {
1462 if(!search->pack->vpack)
1463 {
1464 // close the file
1465 FILEDESC_CLOSE(search->pack->handle);
1466 // free any memory associated with it
1467 if (search->pack->files)
1468 Mem_Free(search->pack->files);
1469 }
1470 Mem_Free(search->pack);
1471 }
1472 Mem_Free(search);
1473 }
1474}
filedesc_t handle
Definition fs.c:389

References FILEDESC_CLOSE, pack_t::files, fs_searchpaths, fs_selfpack, pack_t::handle, Mem_Free, searchpath_t::next, searchpath_t::pack, and pack_t::vpack.

Referenced by FS_Rescan(), and FS_Shutdown().

◆ FS_Close()

int FS_Close ( qfile_t * file)

Definition at line 2971 of file fs.c.

2972{
2973 if(file->flags & QFILE_FLAG_DATA)
2974 {
2975 Mem_Free(file);
2976 return 0;
2977 }
2978
2979 if (FILEDESC_CLOSE (file->handle))
2980 return EOF;
2981
2982 if (file->filename)
2983 {
2984 if (file->flags & QFILE_FLAG_REMOVE)
2985 {
2986 if (remove(file->filename) == -1)
2987 {
2988 // No need to report this. If removing a just
2989 // written file failed, this most likely means
2990 // someone else deleted it first - which we
2991 // like.
2992 }
2993 }
2994
2995 Mem_Free((void *) file->filename);
2996 }
2997
2998 if (file->ztk)
2999 {
3000 qz_inflateEnd (&file->ztk->zstream);
3001 Mem_Free (file->ztk);
3002 }
3003
3004 Mem_Free (file);
3005 return 0;
3006}
#define QFILE_FLAG_REMOVE
real file will be removed on close
Definition fs.c:300
#define QFILE_FLAG_DATA
file is actually already loaded data
Definition fs.c:298
void remove(entity e)

References FILEDESC_CLOSE, Mem_Free, QFILE_FLAG_DATA, QFILE_FLAG_REMOVE, and remove().

Referenced by CL_CutDemo(), CL_Locs_Save_f(), CL_Stop_f(), CL_StopPlayback(), Con_ConDump_f(), Crypto_KeyGen_f(), Crypto_KeyGen_Finished(), Crypto_LoadFile(), Crypto_SavePubKeyTextFile(), Curl_Begin(), Curl_EndDownload(), FS_LoadAndCloseQFile(), FS_OpenReadFile(), FS_SysCheckGameDir(), FS_WriteFileInBlocks(), GetMapList(), Host_SaveConfig(), Host_UnlockSession(), hz_bitstream_read_close(), jam_close(), JPEG_SaveImage_preflipped(), Key_History_Init(), Key_History_Shutdown(), libavw_close(), Log_Close(), Log_Printf(), M_ScanSaves(), PNG_SaveImage_preflipped(), PRVM_Prog_Load(), QW_CL_CheckOrDownloadFile(), R_GLSL_DumpShader_f(), SCR_CaptureVideo_Avi_EndVideo(), SCR_CaptureVideo_Ogg_EndVideo(), SV_Download_f(), SV_DropClient(), SV_ReadClientMessage(), SV_Savegame_to(), SV_StopDemoRecording(), VM_buf_loadfile(), VM_fclose(), VM_Files_CloseAll(), W_LoadTextureWadFile(), and W_UnloadAll().

◆ FS_CRCFile()

int FS_CRCFile ( const char * filename,
size_t * filesizepointer )

Definition at line 4159 of file fs.c.

4160{
4161 int crc = -1;
4162 unsigned char *filedata;
4163 fs_offset_t filesize;
4164 if (filesizepointer)
4165 *filesizepointer = 0;
4166 if (!filename || !*filename)
4167 return crc;
4168 filedata = FS_LoadFile(filename, tempmempool, true, &filesize);
4169 if (filedata)
4170 {
4171 if (filesizepointer)
4172 *filesizepointer = filesize;
4173 crc = CRC_Block(filedata, filesize);
4174 Mem_Free(filedata);
4175 }
4176 return crc;
4177}
unsigned short CRC_Block(const unsigned char *data, size_t size)
Definition com_crc16.c:75
unsigned char * FS_LoadFile(const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
Definition fs.c:3541
int64_t fs_offset_t
Definition fs.h:37

References CRC_Block(), FS_LoadFile(), Mem_Free, and tempmempool.

Referenced by CL_BeginDownloads(), CL_StopDownload(), and QW_CL_RequestNextDownload().

◆ FS_CreatePath()

void FS_CreatePath ( char * path)

Definition at line 1028 of file fs.c.

1029{
1030 char *ofs, save;
1031
1032 for (ofs = path+1 ; *ofs ; ofs++)
1033 {
1034 if (*ofs == '/' || *ofs == '\\')
1035 {
1036 // create the directory
1037 save = *ofs;
1038 *ofs = 0;
1039 FS_mkdir (path);
1040 *ofs = save;
1041 }
1042 }
1043}
static void FS_mkdir(const char *path)
Definition fs.c:999
prvm_uint_t ofs

References FS_mkdir(), and ofs.

Referenced by Crypto_KeyGen_f(), Crypto_KeyGen_Finished(), FS_OpenRealFile(), and Host_LockSession().

◆ FS_DefaultExtension()

void FS_DefaultExtension ( char * path,
const char * extension,
size_t size_path )

Definition at line 3642 of file fs.c.

3643{
3644 const char *src;
3645
3646 // if path doesn't have a .EXT, append extension
3647 // (extension should include the .)
3648 src = path + strlen(path);
3649
3650 while (*src != '/' && src != path)
3651 {
3652 if (*src == '.')
3653 return; // it has an extension
3654 src--;
3655 }
3656
3657 dp_strlcat (path, extension, size_path);
3658}
#define dp_strlcat(dst, src, dsize)
Definition common.h:304
prvm_eval_t * src

References dp_strlcat, src, and strlen().

Referenced by CL_PlayDemo(), CL_Record_f(), R_LoadTextureDDSFile(), SV_Loadgame_f(), SV_Savegame_f(), and SV_StartDemoRecording().

◆ FS_Deflate()

unsigned char * FS_Deflate ( const unsigned char * data,
size_t size,
size_t * deflated_size,
int level,
mempool_t * mempool )

Definition at line 4179 of file fs.c.

4180{
4181 z_stream strm;
4182 unsigned char *out = NULL;
4183 unsigned char *tmp;
4184
4185 *deflated_size = 0;
4186#ifndef LINK_TO_ZLIB
4187 if(!zlib_dll)
4188 return NULL;
4189#endif
4190
4191 memset(&strm, 0, sizeof(strm));
4192 strm.zalloc = Z_NULL;
4193 strm.zfree = Z_NULL;
4194 strm.opaque = Z_NULL;
4195
4196 if(level < 0)
4198
4200 {
4201 Con_Printf("FS_Deflate: deflate init error!\n");
4202 return NULL;
4203 }
4204
4205 strm.next_in = (unsigned char*)data;
4206 strm.avail_in = (unsigned int)size;
4207
4208 tmp = (unsigned char *) Mem_Alloc(tempmempool, size);
4209 if(!tmp)
4210 {
4211 Con_Printf("FS_Deflate: not enough memory in tempmempool!\n");
4212 qz_deflateEnd(&strm);
4213 return NULL;
4214 }
4215
4216 strm.next_out = tmp;
4217 strm.avail_out = (unsigned int)size;
4218
4219 if(qz_deflate(&strm, Z_FINISH) != Z_STREAM_END)
4220 {
4221 Con_Printf("FS_Deflate: deflate failed!\n");
4222 qz_deflateEnd(&strm);
4223 Mem_Free(tmp);
4224 return NULL;
4225 }
4226
4227 if(qz_deflateEnd(&strm) != Z_OK)
4228 {
4229 Con_Printf("FS_Deflate: deflateEnd failed\n");
4230 Mem_Free(tmp);
4231 return NULL;
4232 }
4233
4234 if(strm.total_out >= size)
4235 {
4236 Con_Printf("FS_Deflate: deflate is useless on this data!\n");
4237 Mem_Free(tmp);
4238 return NULL;
4239 }
4240
4241 out = (unsigned char *) Mem_Alloc(mempool, strm.total_out);
4242 if(!out)
4243 {
4244 Con_Printf("FS_Deflate: not enough memory in target mempool!\n");
4245 Mem_Free(tmp);
4246 return NULL;
4247 }
4248
4249 *deflated_size = (size_t)strm.total_out;
4250
4251 memcpy(out, tmp, strm.total_out);
4252 Mem_Free(tmp);
4253
4254 return out;
4255}
vector size
#define Z_DEFLATED
Definition fs.c:242
#define Z_BINARY
Definition fs.c:241
static dllhandle_t zlib_dll
Handle for Zlib DLL.
Definition fs.c:507
#define Z_STREAM_END
Definition fs.c:234
#define Z_FINISH
Definition fs.c:250
#define Z_OK
Definition fs.c:233
#define qz_deflateInit2(strm, level, method, windowBits, memLevel, strategy)
Definition fs.c:488
#define MAX_WBITS
Definition fs.c:232
#define Z_NULL
Definition fs.c:245
#define Z_MEMLEVEL_DEFAULT
Definition fs.c:243
#define Z_DEFAULT_COMPRESSION
Definition fs.c:246
GLsizeiptr const GLvoid * data
Definition glquake.h:639
unsigned int avail_in
number of bytes available at next_in
Definition fs.c:272
unsigned long total_out
total nb of bytes output so far
Definition fs.c:277
void * opaque
private data object passed to zalloc and zfree
Definition fs.c:284
void * zalloc
used to allocate the internal state
Definition fs.c:282
void * zfree
used to free the internal state
Definition fs.c:283
unsigned char * next_out
next output byte should be put there
Definition fs.c:275
unsigned int avail_out
remaining free space at next_out
Definition fs.c:276
unsigned char * next_in
next input byte
Definition fs.c:271

References z_stream::avail_in, z_stream::avail_out, Con_Printf(), data, int(), level, MAX_WBITS, Mem_Alloc, Mem_Free, z_stream::next_in, z_stream::next_out, NULL, z_stream::opaque, qz_deflateInit2, size, tempmempool, z_stream::total_out, Z_BINARY, Z_DEFAULT_COMPRESSION, Z_DEFLATED, Z_FINISH, Z_MEMLEVEL_DEFAULT, Z_NULL, Z_OK, Z_STREAM_END, z_stream::zalloc, z_stream::zfree, and zlib_dll.

Referenced by SV_Prepare_CSQC().

◆ FS_Dir_f()

void FS_Dir_f ( cmd_state_t * cmd)

Definition at line 4054 of file fs.c.

4055{
4056 FS_ListDirectoryCmd(cmd, "dir", true);
4057}
static void FS_ListDirectoryCmd(cmd_state_t *cmd, const char *cmdname, int oneperline)
Definition fs.c:4038
void cmd(string command,...)

References cmd(), and FS_ListDirectoryCmd().

Referenced by FS_Init_Commands().

◆ FS_FileExists()

const char * FS_FileExists ( const char * filename)

Look for a file in the packages and in the filesystem Returns its canonical name (same case as used in the pack) if found, else NULL.

If the file is found outside a pak, this will be the same pointer as passed in.

Definition at line 3694 of file fs.c.

3695{
3696 const char *canonicalname;
3697
3698 return FS_FindFile(filename, NULL, &canonicalname, true) ? canonicalname : NULL;
3699}

References FS_FindFile(), and NULL.

Referenced by CDAudio_Play_byName(), CL_BeginDownloads(), CL_SetupWorldModel(), CL_StopDownload(), Curl_Begin(), Curl_Curl_f(), Font_LoadFont(), FS_Rescan(), Host_AddConfigText(), loadimagepixelsbgra(), M_Menu_Main_f(), MR_SetRouting(), SV_Download_f(), and SV_SpawnServer().

◆ FS_FileExtension()

const char * FS_FileExtension ( const char * in)

Definition at line 1403 of file fs.c.

1404{
1405 const char *separator, *backslash, *colon, *dot;
1406
1407 dot = strrchr(in, '.');
1408 if (dot == NULL)
1409 return "";
1410
1411 separator = strrchr(in, '/');
1412 backslash = strrchr(in, '\\');
1413 if (!separator || separator < backslash)
1414 separator = backslash;
1415 colon = strrchr(in, ':');
1416 if (!separator || separator < colon)
1417 separator = colon;
1418
1419 if (separator && (dot < separator))
1420 return "";
1421
1422 return dot + 1;
1423}

References NULL.

Referenced by CL_PlayVideo_f(), CL_StopDownload(), FS_AddGameDirectory(), FS_AddPack_Fullpath(), Image_StripImageExtension(), Mod_LoadModel(), SCR_ScreenShot_f(), and SV_Download_f().

◆ FS_FileFromData()

qfile_t * FS_FileFromData ( const unsigned char * data,
const size_t size,
qbool quiet )

Definition at line 2952 of file fs.c.

2953{
2954 qfile_t* file;
2955 file = (qfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
2956 memset (file, 0, sizeof (*file));
2957 file->flags = QFILE_FLAG_DATA;
2958 file->ungetc = EOF;
2959 file->real_length = size;
2960 file->data = data;
2961 return file;
2962}

References data, fs_mempool, Mem_Alloc, QFILE_FLAG_DATA, and size.

Referenced by SV_Download_f().

◆ FS_FileSize()

fs_offset_t FS_FileSize ( qfile_t * file)

Definition at line 3475 of file fs.c.

3476{
3477 return file->real_length;
3478}

Referenced by LibAvW_FS_SeekSize(), SV_Download_f(), and SV_ReadClientMessage().

◆ FS_FileType()

int FS_FileType ( const char * filename)

Look for a file in the packages and in the filesystem.

Definition at line 3668 of file fs.c.

3669{
3670 searchpath_t *search;
3671 char fullpath[MAX_OSPATH];
3672
3673 search = FS_FindFile (filename, NULL, NULL, true);
3674 if(!search)
3675 return FS_FILETYPE_NONE;
3676
3677 if(search->pack && !search->pack->vpack)
3678 return FS_FILETYPE_FILE; // TODO can't check directories in paks yet, maybe later
3679
3680 dpsnprintf(fullpath, sizeof(fullpath), "%s%s", search->filename, filename);
3681 return FS_SysFileType(fullpath);
3682}
int FS_SysFileType(const char *path)
Look for a file in the filesystem only.
Definition fs.c:3709
#define FS_FILETYPE_FILE
Definition fs.h:138
#define FS_FILETYPE_NONE
Definition fs.h:137

References dpsnprintf(), searchpath_t::filename, FS_FILETYPE_FILE, FS_FILETYPE_NONE, FS_FindFile(), FS_SysFileType(), MAX_OSPATH, NULL, searchpath_t::pack, and pack_t::vpack.

Referenced by Con_CompleteCommandLine().

◆ FS_FileWithoutPath()

const char * FS_FileWithoutPath ( const char * in)

Definition at line 1431 of file fs.c.

1432{
1433 const char *separator, *backslash, *colon;
1434
1435 separator = strrchr(in, '/');
1436 backslash = strrchr(in, '\\');
1437 if (!separator || separator < backslash)
1438 separator = backslash;
1439 colon = strrchr(in, ':');
1440 if (!separator || separator < colon)
1441 separator = colon;
1442 return separator ? separator + 1 : in;
1443}

Referenced by COM_InitGameType(), and FS_IsRegisteredQuakePack().

◆ FS_FindFile()

static searchpath_t * FS_FindFile ( const char * name,
int * index,
const char ** canonicalname,
qbool quiet )
static

Definition at line 2691 of file fs.c.

2692{
2693 searchpath_t *search;
2694 pack_t *pak;
2695
2696 // search through the path, one element at a time
2697 for (search = fs_searchpaths;search;search = search->next)
2698 {
2699 // is the element a pak file?
2700 if (search->pack && !search->pack->vpack)
2701 {
2702 int (*strcmp_funct) (const char* str1, const char* str2);
2703 int left, right, middle;
2704
2705 pak = search->pack;
2706 strcmp_funct = pak->ignorecase ? strcasecmp : strcmp;
2707
2708 // Look for the file (binary search)
2709 left = 0;
2710 right = pak->numfiles - 1;
2711 while (left <= right)
2712 {
2713 int diff;
2714
2715 middle = (left + right) / 2;
2716 diff = strcmp_funct (pak->files[middle].name, name);
2717
2718 // Found it
2719 if (!diff)
2720 {
2722 {
2723 // yes, but the first one is empty so we treat it as not being there
2724 if (!quiet && developer_extra.integer)
2725 Con_DPrintf("FS_FindFile: %s is marked as deleted\n", name);
2726
2727 if (index != NULL)
2728 *index = -1;
2729 if (canonicalname)
2730 *canonicalname = NULL;
2731 return NULL;
2732 }
2733
2734 if (!quiet && developer_extra.integer)
2735 Con_DPrintf("FS_FindFile: %s in %s\n", pak->files[middle].name, pak->filename);
2736
2737 if (index != NULL)
2738 *index = middle;
2739 if (canonicalname)
2740 *canonicalname = pak->files[middle].name;
2741 return search;
2742 }
2743
2744 // If we're too far in the list
2745 if (diff > 0)
2746 right = middle - 1;
2747 else
2748 left = middle + 1;
2749 }
2750 }
2751 else
2752 {
2753 char netpath[MAX_OSPATH];
2754 dpsnprintf(netpath, sizeof(netpath), "%s%s", search->filename, name);
2755 if (FS_SysFileExists (netpath))
2756 {
2757 if (!quiet && developer_extra.integer)
2758 Con_DPrintf("FS_FindFile: %s\n", netpath);
2759
2760 if (index != NULL)
2761 *index = -1;
2762 if (canonicalname)
2763 *canonicalname = name;
2764 return search;
2765 }
2766 }
2767 }
2768
2769 if (!quiet && developer_extra.integer)
2770 Con_DPrintf("FS_FindFile: can't find %s\n", name);
2771
2772 if (index != NULL)
2773 *index = -1;
2774 if (canonicalname)
2775 *canonicalname = NULL;
2776 return NULL;
2777}
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
Definition console.c:1544
qbool FS_SysFileExists(const char *path)
Look for a file in the filesystem only.
Definition fs.c:3745
cvar_t fs_empty_files_in_pack_mark_deletions
Definition fs.c:456
cvar_t developer_extra
Definition host.c:49
int integer
Definition cvar.h:73

References Con_DPrintf(), developer_extra, dpsnprintf(), pack_t::filename, searchpath_t::filename, pack_t::files, fs_empty_files_in_pack_mark_deletions, fs_searchpaths, FS_SysFileExists(), pack_t::ignorecase, index, int(), cvar_t::integer, MAX_OSPATH, name, packfile_t::name, searchpath_t::next, NULL, pack_t::numfiles, searchpath_t::pack, packfile_t::realsize, right, and pack_t::vpack.

Referenced by FS_AddPack(), FS_FileExists(), FS_FileType(), FS_OpenReadFile(), FS_Which_f(), and FS_WhichPack().

◆ FS_FreeSearch()

void FS_FreeSearch ( fssearch_t * search)

Definition at line 3964 of file fs.c.

3965{
3966 Z_Free(search);
3967}
#define Z_Free(data)
Definition zone.h:164

References Z_Free.

Referenced by Cmd_Exec_f(), Con_CompleteCommandLine(), FS_ListDirectory(), GetMapList(), Image_FixTransparentPixels_f(), Mod_LoadQ3Shaders(), VM_search_end(), and VM_Search_Reset().

◆ FS_GameDir_f()

static void FS_GameDir_f ( cmd_state_t * cmd)
static

Definition at line 1751 of file fs.c.

1752{
1753 int i;
1754 int numgamedirs;
1755 const char *gamedirs[MAX_GAMEDIRS];
1756
1757 if (Cmd_Argc(cmd) < 2)
1758 {
1759 Con_Printf("gamedirs active:");
1760 for (i = 0;i < fs_numgamedirs;i++)
1761 Con_Printf(" %s%s", (strcasecmp(fs_gamedirs[i], gamedirname1) && (!gamedirname2 || strcasecmp(fs_gamedirs[i], gamedirname2))) ? "^7" : "^9", fs_gamedirs[i]);
1762 Con_Printf("\n");
1763 return;
1764 }
1765
1766 numgamedirs = Cmd_Argc(cmd) - 1;
1767 if (numgamedirs > MAX_GAMEDIRS)
1768 {
1769 Con_Printf(CON_ERROR "Too many gamedirs (%i > %i)\n", numgamedirs, MAX_GAMEDIRS);
1770 return;
1771 }
1772
1773 for (i = 0;i < numgamedirs;i++)
1774 gamedirs[i] = Cmd_Argv(cmd, i+1);
1775
1776 if ((cls.state == ca_connected && !cls.demoplayback) || sv.active)
1777 {
1778 // actually, changing during game would work fine, but would be stupid
1779 Con_Printf(CON_ERROR "Can not change gamedir while client is connected or server is running!\n");
1780 return;
1781 }
1782
1783 FS_ChangeGameDirs(numgamedirs, gamedirs, true);
1784}
@ ca_connected
Definition client.h:532
static int Cmd_Argc(cmd_state_t *cmd)
Definition cmd.h:249
static const char * Cmd_Argv(cmd_state_t *cmd, int arg)
Cmd_Argv(cmd, ) will return an empty string (not a NULL) if arg > argc, so string operations are alwa...
Definition cmd.h:254
const char * gamedirname2
Definition com_game.c:30
char fs_gamedirs[MAX_GAMEDIRS][MAX_QPATH]
Definition fs.c:449
qbool FS_ChangeGameDirs(int numgamedirs, const char *gamedirs[], qbool failmissing)
Definition fs.c:1719
int fs_numgamedirs
Definition fs.c:448
#define MAX_GAMEDIRS
Definition fs.h:46
server_t sv
local server
Definition sv_main.c:223
cactive_t state
Definition client.h:568
qbool active
false if only a net client
Definition server.h:66

References server_t::active, ca_connected, cls, cmd(), Cmd_Argc(), Cmd_Argv(), CON_ERROR, Con_Printf(), client_static_t::demoplayback, FS_ChangeGameDirs(), fs_gamedirs, fs_numgamedirs, gamedirname1, gamedirname2, i, MAX_GAMEDIRS, client_static_t::state, and sv.

Referenced by FS_Init_Commands().

◆ FS_Getc()

int FS_Getc ( qfile_t * file)

Definition at line 3324 of file fs.c.

3325{
3326 unsigned char c;
3327
3328 if (FS_Read (file, &c, 1) != 1)
3329 return EOF;
3330
3331 return c;
3332}
fs_offset_t FS_Read(qfile_t *file, void *buffer, size_t buffersize)
Definition fs.c:3067

References FS_Read().

Referenced by CL_PlayDemo(), Key_History_Init(), VM_buf_loadfile(), and VM_fgets().

◆ FS_HasZlib()

qbool FS_HasZlib ( void )

Definition at line 620 of file fs.c.

621{
622#ifdef LINK_TO_ZLIB
623 return true;
624#else
625 PK3_OpenLibrary(); // to be safe
626 return (zlib_dll != 0);
627#endif
628}
static qbool PK3_OpenLibrary(void)
Definition fs.c:581

References PK3_OpenLibrary(), and zlib_dll.

Referenced by CL_BeginDownloads().

◆ FS_Inflate()

unsigned char * FS_Inflate ( const unsigned char * data,
size_t size,
size_t * inflated_size,
mempool_t * mempool )

Definition at line 4274 of file fs.c.

4275{
4276 int ret;
4277 z_stream strm;
4278 unsigned char *out = NULL;
4279 unsigned char tmp[2048];
4280 unsigned int have;
4281 sizebuf_t outbuf;
4282
4283 *inflated_size = 0;
4284#ifndef LINK_TO_ZLIB
4285 if(!zlib_dll)
4286 return NULL;
4287#endif
4288
4289 memset(&outbuf, 0, sizeof(outbuf));
4290 outbuf.data = (unsigned char *) Mem_Alloc(tempmempool, sizeof(tmp));
4291 outbuf.maxsize = sizeof(tmp);
4292
4293 memset(&strm, 0, sizeof(strm));
4294 strm.zalloc = Z_NULL;
4295 strm.zfree = Z_NULL;
4296 strm.opaque = Z_NULL;
4297
4298 if(qz_inflateInit2(&strm, -MAX_WBITS) != Z_OK)
4299 {
4300 Con_Printf("FS_Inflate: inflate init error!\n");
4301 Mem_Free(outbuf.data);
4302 return NULL;
4303 }
4304
4305 strm.next_in = (unsigned char*)data;
4306 strm.avail_in = (unsigned int)size;
4307
4308 do
4309 {
4310 strm.next_out = tmp;
4311 strm.avail_out = sizeof(tmp);
4312 ret = qz_inflate(&strm, Z_NO_FLUSH);
4313 // it either returns Z_OK on progress, Z_STREAM_END on end
4314 // or an error code
4315 switch(ret)
4316 {
4317 case Z_STREAM_END:
4318 case Z_OK:
4319 break;
4320
4321 case Z_STREAM_ERROR:
4322 Con_Print("FS_Inflate: stream error!\n");
4323 break;
4324 case Z_DATA_ERROR:
4325 Con_Print("FS_Inflate: data error!\n");
4326 break;
4327 case Z_MEM_ERROR:
4328 Con_Print("FS_Inflate: mem error!\n");
4329 break;
4330 case Z_BUF_ERROR:
4331 Con_Print("FS_Inflate: buf error!\n");
4332 break;
4333 default:
4334 Con_Print("FS_Inflate: unknown error!\n");
4335 break;
4336
4337 }
4338 if(ret != Z_OK && ret != Z_STREAM_END)
4339 {
4340 Con_Printf("Error after inflating %u bytes\n", (unsigned)strm.total_in);
4341 Mem_Free(outbuf.data);
4342 qz_inflateEnd(&strm);
4343 return NULL;
4344 }
4345 have = sizeof(tmp) - strm.avail_out;
4346 AssertBufsize(&outbuf, max(have, sizeof(tmp)));
4347 SZ_Write(&outbuf, tmp, have);
4348 } while(ret != Z_STREAM_END);
4349
4350 qz_inflateEnd(&strm);
4351
4352 out = (unsigned char *) Mem_Alloc(mempool, outbuf.cursize);
4353 if(!out)
4354 {
4355 Con_Printf("FS_Inflate: not enough memory in target mempool!\n");
4356 Mem_Free(outbuf.data);
4357 return NULL;
4358 }
4359
4360 memcpy(out, outbuf.data, outbuf.cursize);
4361 Mem_Free(outbuf.data);
4362
4363 *inflated_size = (size_t)outbuf.cursize;
4364
4365 return out;
4366}
void SZ_Write(sizebuf_t *buf, const unsigned char *data, int length)
Definition common.c:72
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
#define Z_BUF_ERROR
Definition fs.c:238
#define Z_DATA_ERROR
Definition fs.c:236
#define Z_STREAM_ERROR
Definition fs.c:235
static void AssertBufsize(sizebuf_t *buf, int length)
Definition fs.c:4257
#define Z_NO_FLUSH
Definition fs.c:247
#define Z_MEM_ERROR
Definition fs.c:237
#define qz_inflateInit2(strm, windowBits)
Definition fs.c:486
#define max(A, B)
Definition mathlib.h:38
unsigned char * data
Definition common.h:52
int cursize
Definition common.h:54
int maxsize
Definition common.h:53
unsigned long total_in
total nb of input bytes read so far
Definition fs.c:273

References AssertBufsize(), z_stream::avail_in, z_stream::avail_out, Con_Print(), Con_Printf(), sizebuf_t::cursize, data, sizebuf_t::data, int(), max, MAX_WBITS, sizebuf_t::maxsize, Mem_Alloc, Mem_Free, z_stream::next_in, z_stream::next_out, NULL, z_stream::opaque, qz_inflateInit2, ret, size, SZ_Write(), tempmempool, z_stream::total_in, Z_BUF_ERROR, Z_DATA_ERROR, Z_MEM_ERROR, Z_NO_FLUSH, Z_NULL, Z_OK, Z_STREAM_END, Z_STREAM_ERROR, z_stream::zalloc, z_stream::zfree, and zlib_dll.

Referenced by CL_StopDownload().

◆ FS_Init()

void FS_Init ( void )

Definition at line 2342 of file fs.c.

2343{
2344 fs_mempool = Mem_AllocPool("file management", 0, NULL);
2345
2346 PK3_OpenLibrary ();
2347
2348 // initialize the self-pack (must be before COM_InitGameType as it may add command line options)
2350
2351 // detect gamemode from commandline options or executable name
2353
2354 FS_Init_Commands(); // assumes com_startupgamegroup is set
2355
2356 FS_Init_Dir();
2357}
void COM_InitGameType(void)
Definition com_game.c:95
static void FS_Init_Dir(void)
Definition fs.c:2139
void FS_Init_Commands(void)
Definition fs.c:2117
void FS_Init_SelfPack(void)
Definition fs.c:2299
#define Mem_AllocPool(name, flags, parent)
Definition zone.h:104

References COM_InitGameType(), FS_Init_Commands(), FS_Init_Dir(), FS_Init_SelfPack(), fs_mempool, Mem_AllocPool, NULL, and PK3_OpenLibrary().

Referenced by Host_Init().

◆ FS_Init_Commands()

void FS_Init_Commands ( void )

Definition at line 2117 of file fs.c.

2118{
2123
2124 Cmd_AddCommand(CF_SHARED, "gamedir", FS_GameDir_f, "changes active gamedir list, can take multiple arguments which shouldn't include the base directory, the last gamedir is the \"primary\" and files will be saved there (example usage: gamedir ctf id1)");
2125 Cmd_AddCommand(CF_SHARED, "fs_rescan", FS_Rescan_f, "rescans filesystem for new pack archives and any other changes");
2126 Cmd_AddCommand(CF_SHARED, "path", FS_Path_f, "print searchpath (game directories and archives)");
2127 Cmd_AddCommand(CF_SHARED, "dir", FS_Dir_f, "list files in searchpath matching an * filename pattern, one per line");
2128 Cmd_AddCommand(CF_SHARED, "ls", FS_Ls_f, "list files in searchpath matching an * filename pattern, multiple per line");
2129 Cmd_AddCommand(CF_SHARED, "which", FS_Which_f, "accepts a file name as argument and reports where the file is taken from");
2130
2131#ifdef __EMSCRIPTEN__
2133#endif
2134
2136 Cmd_AddCommand(CF_SHARED, "game", FS_GameDir_f, "alias of gamedir, for compatibility with some Quake mod READMEs");
2137}
void Cmd_AddCommand(unsigned flags, const char *cmd_name, xcommand_t function, const char *description)
called by the init functions of other parts of the program to register commands and functions to call...
Definition cmd.c:1661
#define CF_SHARED
Definition cmd.h:67
gamemode_t com_startupgamegroup
Definition com_game.c:36
@ GAME_NORMAL
Definition com_game.h:28
void Cvar_RegisterVariable(cvar_t *variable)
registers a cvar that already has the name, string, and optionally the archive elements set.
Definition cvar.c:599
void FS_Dir_f(cmd_state_t *cmd)
Definition fs.c:4054
void FS_Ls_f(cmd_state_t *cmd)
Definition fs.c:4059
static void FS_Rescan_f(cmd_state_t *cmd)
Definition fs.c:1623
cvar_t cvar_fs_gamedir
Definition fs.c:458
static void FS_GameDir_f(cmd_state_t *cmd)
Definition fs.c:1751
cvar_t fs_unload_dlcache
Definition fs.c:457
void FS_Which_f(cmd_state_t *cmd)
Definition fs.c:4064
cvar_t scr_screenshot_name
Definition fs.c:455
static void FS_Path_f(cmd_state_t *cmd)
Definition fs.c:1052
void Sys_EM_Register_Commands(void)
Definition sys_wasm.c:279

References CF_SHARED, Cmd_AddCommand(), com_startupgamegroup, cvar_fs_gamedir, Cvar_RegisterVariable(), FS_Dir_f(), fs_empty_files_in_pack_mark_deletions, FS_GameDir_f(), FS_Ls_f(), FS_Path_f(), FS_Rescan_f(), fs_unload_dlcache, FS_Which_f(), GAME_NORMAL, scr_screenshot_name, and Sys_EM_Register_Commands().

Referenced by FS_Init().

◆ FS_Init_Dir()

static void FS_Init_Dir ( void )
static

Definition at line 2139 of file fs.c.

2140{
2141 int i;
2142 int numgamedirs;
2143 const char *cmdline_gamedirs[MAX_GAMEDIRS];
2144 WPATHDEF(fs_basedirw);
2145
2146 *fs_basedir = 0;
2147 *fs_userdir = 0;
2148 *fs_gamedir = 0;
2149
2150 // -basedir <path>
2151 // Overrides the system supplied base directory (under GAMENAME)
2152// COMMANDLINEOPTION: Filesystem: -basedir <path> chooses what base directory the game data is in, inside this there should be a data directory for the game (for example id1)
2153 i = Sys_CheckParm ("-basedir");
2154 if (i && i < sys.argc-1)
2155 {
2156 dp_strlcpy (fs_basedir, sys.argv[i+1], sizeof (fs_basedir));
2157 i = (int)strlen (fs_basedir);
2158 if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
2159 fs_basedir[i-1] = 0;
2160 }
2161 else
2162 {
2163// If the base directory is explicitly defined by the compilation process
2164#ifdef DP_FS_BASEDIR
2165 dp_strlcpy(fs_basedir, DP_FS_BASEDIR, sizeof(fs_basedir));
2166#elif defined(__ANDROID__)
2167 dpsnprintf(fs_basedir, sizeof(fs_basedir), "/sdcard/%s/", gameuserdirname);
2168#elif defined(MACOSX)
2169 // FIXME: is there a better way to find the directory outside the .app, without using Objective-C?
2170 if (strstr(sys.argv[0], ".app/"))
2171 {
2172 char *split;
2173 dp_strlcpy(fs_basedir, sys.argv[0], sizeof(fs_basedir));
2174 split = strstr(fs_basedir, ".app/");
2175 if (split)
2176 {
2177 struct stat statresult;
2178 char vabuf[1024];
2179 // truncate to just after the .app/
2180 split[5] = 0;
2181 // see if gamedir exists in Resources
2182 if (stat(va(vabuf, sizeof(vabuf), "%s/Contents/Resources/%s", fs_basedir, gamedirname1), &statresult) == 0)
2183 {
2184 // found gamedir inside Resources, use it
2185 dp_strlcat(fs_basedir, "Contents/Resources/", sizeof(fs_basedir));
2186 }
2187 else
2188 {
2189 // no gamedir found in Resources, gamedir is probably
2190 // outside the .app, remove .app part of path
2191 while (split > fs_basedir && *split != '/')
2192 split--;
2193 *split = 0;
2194 }
2195 }
2196 }
2197#else
2198 // use the working directory
2199 #ifdef WIN32
2200 GetCurrentDirectoryW(sizeof(fs_basedirw) / sizeof(*fs_basedirw), fs_basedirw);
2201 NARROW(fs_basedirw, fs_basedir);
2202 #else
2203 getcwd(fs_basedir, sizeof(fs_basedir));
2204 #endif
2205#endif
2206 }
2207
2208 // make sure the appending of a path separator won't create an unterminated string
2209 memset(fs_basedir + sizeof(fs_basedir) - 2, 0, 2);
2210 // add a path separator to the end of the basedir if it lacks one
2211 if (fs_basedir[0] && fs_basedir[strlen(fs_basedir) - 1] != '/' && fs_basedir[strlen(fs_basedir) - 1] != '\\')
2212 dp_strlcat(fs_basedir, "/", sizeof(fs_basedir));
2213
2214 // Add the personal game directory
2215 if((i = Sys_CheckParm("-userdir")) && i < sys.argc - 1)
2216 dpsnprintf(fs_userdir, sizeof(fs_userdir), "%s/", sys.argv[i+1]);
2217 else if (Sys_CheckParm("-nohome"))
2218 *fs_userdir = 0; // user wants roaming installation, no userdir
2219 else
2220 {
2221#ifdef DP_FS_USERDIR
2222 dp_strlcpy(fs_userdir, DP_FS_USERDIR, sizeof(fs_userdir));
2223#else
2224 int dirmode;
2225 int highestuserdirmode = USERDIRMODE_COUNT - 1;
2226 int preferreduserdirmode = USERDIRMODE_COUNT - 1;
2227 int userdirstatus[USERDIRMODE_COUNT];
2228# ifdef WIN32
2229 // historical behavior...
2230 if (!strcmp(gamedirname1, "id1"))
2231 preferreduserdirmode = USERDIRMODE_NOHOME;
2232# endif
2233 // check what limitations the user wants to impose
2234 if (Sys_CheckParm("-home")) preferreduserdirmode = USERDIRMODE_HOME;
2235 if (Sys_CheckParm("-mygames")) preferreduserdirmode = USERDIRMODE_MYGAMES;
2236 if (Sys_CheckParm("-savedgames")) preferreduserdirmode = USERDIRMODE_SAVEDGAMES;
2237 // gather the status of the possible userdirs
2238 for (dirmode = 0;dirmode < USERDIRMODE_COUNT;dirmode++)
2239 {
2240 userdirstatus[dirmode] = FS_ChooseUserDir((userdirmode_t)dirmode, fs_userdir, sizeof(fs_userdir));
2241 if (userdirstatus[dirmode] == 1)
2242 Con_DPrintf("userdir %i = %s (writable)\n", dirmode, fs_userdir);
2243 else if (userdirstatus[dirmode] == 0)
2244 Con_DPrintf("userdir %i = %s (not writable or does not exist)\n", dirmode, fs_userdir);
2245 else
2246 Con_DPrintf("userdir %i (not applicable)\n", dirmode);
2247 }
2248 // some games may prefer writing to basedir, but if write fails we
2249 // have to search for a real userdir...
2250 if (preferreduserdirmode == 0 && userdirstatus[0] < 1)
2251 preferreduserdirmode = highestuserdirmode;
2252 // check for an existing userdir and continue using it if possible...
2253 for (dirmode = USERDIRMODE_COUNT - 1;dirmode > 0;dirmode--)
2254 if (userdirstatus[dirmode] == 1)
2255 break;
2256 // if no existing userdir found, make a new one...
2257 if (dirmode == 0 && preferreduserdirmode > 0)
2258 for (dirmode = preferreduserdirmode;dirmode > 0;dirmode--)
2259 if (userdirstatus[dirmode] >= 0)
2260 break;
2261 // and finally, we picked one...
2263 Con_DPrintf("userdir %i is the winner\n", dirmode);
2264#endif
2265 }
2266
2267 // if userdir equal to basedir, clear it to avoid confusion later
2268 if (!strcmp(fs_basedir, fs_userdir))
2269 fs_userdir[0] = 0;
2270
2271 // -game <gamedir>
2272 // Adds basedir/gamedir as an override game
2273 // LadyHavoc: now supports multiple -game directories
2274 // the last one is the primary (where files are saved) and is used to identify mods
2275 for (i = 1, numgamedirs = 0; i < sys.argc && numgamedirs < MAX_GAMEDIRS; i++)
2276 {
2277 if (!sys.argv[i])
2278 continue;
2279 if (!strcmp (sys.argv[i], "-game") && i < sys.argc-1)
2280 {
2281 i++;
2282 cmdline_gamedirs[numgamedirs++] = sys.argv[i];
2283 }
2284 }
2285 COM_ChangeGameTypeForGameDirs(numgamedirs, cmdline_gamedirs, true, true);
2286
2287 // generate the searchpath
2288 FS_Rescan();
2289
2290 if (Thread_HasThreads())
2292}
userdirmode_t
Definition common.h:283
@ USERDIRMODE_COUNT
Definition common.h:288
#define WPATHDEF(var)
Definition fs.c:84
void * fs_mutex
Definition fs.c:435
static int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t userdirsize)
Definition fs.c:1946
int Sys_CheckParm(const char *parm)
Definition sys_shared.c:327
qbool Thread_HasThreads(void)
Definition thread_null.c:13
#define Thread_CreateMutex()
Definition thread.h:15

References sys_t::argc, sys_t::argv, COM_ChangeGameTypeForGameDirs(), Con_DPrintf(), dp_strlcat, dp_strlcpy, dpsnprintf(), fs_basedir, FS_ChooseUserDir(), fs_gamedir, fs_mutex, FS_Rescan(), fs_userdir, gamedirname1, gameuserdirname, i, int(), MAX_GAMEDIRS, NARROW, strlen(), sys, Sys_CheckParm(), Thread_CreateMutex, Thread_HasThreads(), USERDIRMODE_COUNT, USERDIRMODE_HOME, USERDIRMODE_MYGAMES, USERDIRMODE_NOHOME, USERDIRMODE_SAVEDGAMES, va(), and WPATHDEF.

Referenced by FS_Init().

◆ FS_Init_SelfPack()

void FS_Init_SelfPack ( void )

Definition at line 2299 of file fs.c.

2300{
2301 char *buf;
2302
2303 // Load darkplaces.opt from the FS.
2304 if (!Sys_CheckParm("-noopt"))
2305 {
2306 buf = (char *) FS_SysLoadFile("darkplaces.opt", tempmempool, true, NULL);
2307 if(buf)
2308 {
2310 Mem_Free(buf);
2311 }
2312 }
2313
2314#ifndef USE_RWOPS
2315 // Provide the SelfPack.
2316 if (!Sys_CheckParm("-noselfpack") && sys.selffd >= 0)
2317 {
2319 if(fs_selfpack)
2320 {
2322 if (!Sys_CheckParm("-noopt"))
2323 {
2324 buf = (char *) FS_LoadFile("darkplaces.opt", tempmempool, true, NULL);
2325 if(buf)
2326 {
2328 Mem_Free(buf);
2329 }
2330 }
2331 }
2332 }
2333#endif
2334}
static void COM_InsertFlags(const char *buf)
Definition fs.c:1911
static pack_t * FS_LoadPackPK3FromFD(const char *packfile, filedesc_t packhandle, qbool silent)
Definition fs.c:836
static void FS_AddSelfPack(void)
Definition fs.c:1519
unsigned char * FS_SysLoadFile(const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
Definition fs.c:3556
int selffd
Definition sys.h:148

References sys_t::argv, buf, COM_InsertFlags(), FS_AddSelfPack(), FS_LoadFile(), FS_LoadPackPK3FromFD(), fs_selfpack, FS_SysLoadFile(), Mem_Free, NULL, sys_t::selffd, sys, Sys_CheckParm(), and tempmempool.

Referenced by FS_Init().

◆ FS_IsRegisteredQuakePack()

qbool FS_IsRegisteredQuakePack ( const char * name)

Definition at line 4113 of file fs.c.

4114{
4115 searchpath_t *search;
4116 pack_t *pak;
4117
4118 // search through the path, one element at a time
4119 for (search = fs_searchpaths;search;search = search->next)
4120 {
4121 if (search->pack && !search->pack->vpack && !strcasecmp(FS_FileWithoutPath(search->filename), name))
4122 // TODO do we want to support vpacks in here too?
4123 {
4124 int (*strcmp_funct) (const char* str1, const char* str2);
4125 int left, right, middle;
4126
4127 pak = search->pack;
4128 strcmp_funct = pak->ignorecase ? strcasecmp : strcmp;
4129
4130 // Look for the file (binary search)
4131 left = 0;
4132 right = pak->numfiles - 1;
4133 while (left <= right)
4134 {
4135 int diff;
4136
4137 middle = (left + right) / 2;
4138 diff = strcmp_funct (pak->files[middle].name, "gfx/pop.lmp");
4139
4140 // Found it
4141 if (!diff)
4142 return true;
4143
4144 // If we're too far in the list
4145 if (diff > 0)
4146 right = middle - 1;
4147 else
4148 left = middle + 1;
4149 }
4150
4151 // we found the requested pack but it is not registered quake
4152 return false;
4153 }
4154 }
4155
4156 return false;
4157}
const char * FS_FileWithoutPath(const char *in)
Definition fs.c:1431

References searchpath_t::filename, pack_t::files, FS_FileWithoutPath(), fs_searchpaths, pack_t::ignorecase, int(), name, packfile_t::name, searchpath_t::next, pack_t::numfiles, searchpath_t::pack, right, and pack_t::vpack.

Referenced by SV_Download_f().

◆ FS_ListDirectory()

static int FS_ListDirectory ( const char * pattern,
int oneperline )
static

Definition at line 3970 of file fs.c.

3971{
3972 int numfiles;
3973 int numcolumns;
3974 int numlines;
3975 int columnwidth;
3976 int linebufpos;
3977 int i, j, k, l;
3978 const char *name;
3979 char linebuf[MAX_INPUTLINE];
3980 fssearch_t *search;
3981 search = FS_Search(pattern, true, true, NULL);
3982 if (!search)
3983 return 0;
3984 numfiles = search->numfilenames;
3985 if (!oneperline)
3986 {
3987 // FIXME: the names could be added to one column list and then
3988 // gradually shifted into the next column if they fit, and then the
3989 // next to make a compact variable width listing but it's a lot more
3990 // complicated...
3991 // find width for columns
3992 columnwidth = 0;
3993 for (i = 0;i < numfiles;i++)
3994 {
3995 l = (int)strlen(search->filenames[i]);
3996 if (columnwidth < l)
3997 columnwidth = l;
3998 }
3999 // count the spacing character
4000 columnwidth++;
4001 // calculate number of columns
4002 numcolumns = con_linewidth / columnwidth;
4003 // don't bother with the column printing if it's only one column
4004 if (numcolumns >= 2)
4005 {
4006 numlines = (numfiles + numcolumns - 1) / numcolumns;
4007 for (i = 0;i < numlines;i++)
4008 {
4009 linebufpos = 0;
4010 for (k = 0;k < numcolumns;k++)
4011 {
4012 l = i * numcolumns + k;
4013 if (l < numfiles)
4014 {
4015 name = search->filenames[l];
4016 for (j = 0;name[j] && linebufpos + 1 < (int)sizeof(linebuf);j++)
4017 linebuf[linebufpos++] = name[j];
4018 // space out name unless it's the last on the line
4019 if (k + 1 < numcolumns && l + 1 < numfiles)
4020 for (;j < columnwidth && linebufpos + 1 < (int)sizeof(linebuf);j++)
4021 linebuf[linebufpos++] = ' ';
4022 }
4023 }
4024 linebuf[linebufpos] = 0;
4025 Con_Printf("%s\n", linebuf);
4026 }
4027 }
4028 else
4029 oneperline = true;
4030 }
4031 if (oneperline)
4032 for (i = 0;i < numfiles;i++)
4033 Con_Printf("%s\n", search->filenames[i]);
4034 FS_FreeSearch(search);
4035 return (int)numfiles;
4036}
void FS_FreeSearch(fssearch_t *search)
Definition fs.c:3964
fssearch_t * FS_Search(const char *pattern, int caseinsensitive, int quiet, const char *packfile)
Definition fs.c:3757
int con_linewidth
Definition console.c:94
#define MAX_INPUTLINE
maximum size of console commandline, QuakeC strings, and many other text processing buffers
Definition qdefs.h:94
char ** filenames
Definition fs.h:117
int numfilenames
Definition fs.h:116

References con_linewidth, Con_Printf(), fssearch_t::filenames, FS_FreeSearch(), FS_Search(), i, int(), MAX_INPUTLINE, name, NULL, fssearch_t::numfilenames, and strlen().

Referenced by FS_ListDirectoryCmd().

◆ FS_ListDirectoryCmd()

static void FS_ListDirectoryCmd ( cmd_state_t * cmd,
const char * cmdname,
int oneperline )
static

Definition at line 4038 of file fs.c.

4039{
4040 const char *pattern;
4041 if (Cmd_Argc(cmd) >= 3)
4042 {
4043 Con_Printf("usage:\n%s [path/pattern]\n", cmdname);
4044 return;
4045 }
4046 if (Cmd_Argc(cmd) == 2)
4047 pattern = Cmd_Argv(cmd, 1);
4048 else
4049 pattern = "*";
4050 if (!FS_ListDirectory(pattern, oneperline))
4051 Con_Print("No files found.\n");
4052}
static int FS_ListDirectory(const char *pattern, int oneperline)
Definition fs.c:3970

References cmd(), Cmd_Argc(), Cmd_Argv(), Con_Print(), Con_Printf(), and FS_ListDirectory().

Referenced by FS_Dir_f(), and FS_Ls_f().

◆ FS_ListGameDirs()

static void FS_ListGameDirs ( void )
static

Definition at line 1854 of file fs.c.

1855{
1856 stringlist_t list, list2;
1857 int i;
1858 const char *info;
1859 char vabuf[1024];
1860
1862 if(fs_all_gamedirs)
1864
1865 stringlistinit(&list);
1866 listdirectory(&list, va(vabuf, sizeof(vabuf), "%s/", fs_basedir), "");
1867 listdirectory(&list, va(vabuf, sizeof(vabuf), "%s/", fs_userdir), "");
1868 stringlistsort(&list, false);
1869
1870 stringlistinit(&list2);
1871 for(i = 0; i < list.numstrings; ++i)
1872 {
1873 if(i)
1874 if(!strcmp(list.strings[i-1], list.strings[i]))
1875 continue;
1876 info = FS_CheckGameDir(list.strings[i]);
1877 if(!info)
1878 continue;
1879 if(info == fs_checkgamedir_missing)
1880 continue;
1881 if(!*info)
1882 continue;
1883 stringlistappend(&list2, list.strings[i]);
1884 }
1886
1888 for(i = 0; i < list2.numstrings; ++i)
1889 {
1890 info = FS_CheckGameDir(list2.strings[i]);
1891 // all this cannot happen any more, but better be safe than sorry
1892 if(!info)
1893 continue;
1894 if(info == fs_checkgamedir_missing)
1895 continue;
1896 if(!*info)
1897 continue;
1901 }
1902}
void stringlistappend(stringlist_t *list, const char *text)
Definition filematch.c:103
gamedir_t * fs_all_gamedirs
Definition fs.c:452
const char * FS_CheckGameDir(const char *gamedir)
Definition fs.c:1824
int fs_all_gamedirs_count
Definition fs.c:453
Definition fs.h:94
char name[MAX_OSPATH]
Definition fs.h:95

References dp_strlcpy, fs_all_gamedirs, fs_all_gamedirs_count, fs_basedir, FS_CheckGameDir(), fs_checkgamedir_missing, fs_mempool, fs_userdir, i, listdirectory(), Mem_Alloc, Mem_Free, gamedir_t::name, name, stringlist_t::numstrings, stringlistappend(), stringlistfreecontents(), stringlistinit(), stringlistsort(), stringlist_t::strings, and va().

Referenced by FS_Rescan().

◆ FS_LoadAndCloseQFile()

static unsigned char * FS_LoadAndCloseQFile ( qfile_t * file,
const char * path,
mempool_t * pool,
qbool quiet,
fs_offset_t * filesizepointer )
static

Definition at line 3504 of file fs.c.

3505{
3506 unsigned char *buf = NULL;
3507 fs_offset_t filesize = 0;
3508
3509 if (file)
3510 {
3511 filesize = file->real_length;
3512 if(filesize < 0)
3513 {
3514 Con_Printf("FS_LoadFile(\"%s\", pool, %s, filesizepointer): trying to open a non-regular file\n", path, quiet ? "true" : "false");
3515 FS_Close(file);
3516 return NULL;
3517 }
3518
3519 buf = (unsigned char *)Mem_Alloc (pool, filesize + 1);
3520 buf[filesize] = '\0';
3521 FS_Read (file, buf, filesize);
3522 FS_Close (file);
3524 Con_Printf("loaded file \"%s\" (%u bytes)\n", path, (unsigned int)filesize);
3525 }
3526
3527 if (filesizepointer)
3528 *filesizepointer = filesize;
3529 return buf;
3530}
int FS_Close(qfile_t *file)
Definition fs.c:2971
cvar_t developer_loadfile
Definition host.c:51

References buf, Con_Printf(), developer_loadfile, FS_Close(), FS_Read(), cvar_t::integer, Mem_Alloc, and NULL.

Referenced by FS_LoadFile(), and FS_SysLoadFile().

◆ FS_LoadFile()

unsigned char * FS_LoadFile ( const char * path,
mempool_t * pool,
qbool quiet,
fs_offset_t * filesizepointer )

Definition at line 3541 of file fs.c.

3542{
3543 qfile_t *file = FS_OpenVirtualFile(path, quiet);
3544 return FS_LoadAndCloseQFile(file, path, pool, quiet, filesizepointer);
3545}
qfile_t * FS_OpenVirtualFile(const char *filepath, qbool quiet)
Definition fs.c:2929
static unsigned char * FS_LoadAndCloseQFile(qfile_t *file, const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
Definition fs.c:3504

References FS_LoadAndCloseQFile(), and FS_OpenVirtualFile().

Referenced by CL_CutDemo(), CL_IPLog_Load(), CL_Locs_Reload_f(), CL_Particles_LoadEffectInfo(), CL_ReadPointFile_f(), CL_VM_Init(), Cmd_Exec(), Curl_FindPackURL(), decode_image(), fontfilecache_LoadFile(), FS_CRCFile(), FS_Init_SelfPack(), GetMapList(), gl_main_newmap(), Image_GetStockPicSize(), LoadFont(), loadimagepixelsbgra(), LoadSubtitles(), M_Setup_Draw(), Mod_LoadModel(), Mod_LoadQ3Shaders(), Mod_LoadSkinFiles(), Mod_PSKMODEL_Load(), Mod_Q1BSP_LoadLighting(), Mod_Q1BSP_LoadMapBrushes(), Mod_Q2BSP_LoadTexinfo(), OGG_LoadVorbisFile(), Palette_Load(), Palette_LoadQ2Colormap(), Palette_SetupSpecialPalettes(), PRVM_LoadLNO(), PRVM_PO_Load(), PRVM_Prog_Load(), R_InitParticleTexture(), R_LoadQWSkin(), R_LoadTextureDDSFile(), R_Shadow_LoadLightsFile(), R_Shadow_LoadWorldLights(), R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(), S_LoadWavFile(), ShaderModeInfo_GetShaderText(), SV_Loadgame_f(), SV_ParticleEffectIndex(), SV_Prepare_CSQC(), SV_SpawnServer(), VM_loadfromfile(), W_GetLumpName(), and XMP_LoadModFile().

◆ FS_LoadPackPAK()

static pack_t * FS_LoadPackPAK ( const char * packfile)
static

Takes an explicit (not game tree related) path to a pak file. Loads the header and directory, adding the files at the beginning of the list so they override previous pack files.

Definition at line 1081 of file fs.c.

1082{
1083 dpackheader_t header;
1084 int i, numpackfiles;
1085 filedesc_t packhandle;
1086 pack_t *pack;
1087 dpackfile_t *info;
1088
1089 packhandle = FS_SysOpenFiledesc(packfile, "rb", false);
1090 if (!FILEDESC_ISVALID(packhandle))
1091 return NULL;
1092 if(FILEDESC_READ (packhandle, (void *)&header, sizeof(header)) != sizeof(header))
1093 {
1094 Con_Printf ("%s is not a packfile\n", packfile);
1095 FILEDESC_CLOSE(packhandle);
1096 return NULL;
1097 }
1098 if (memcmp(header.id, "PACK", 4))
1099 {
1100 Con_Printf ("%s is not a packfile\n", packfile);
1101 FILEDESC_CLOSE(packhandle);
1102 return NULL;
1103 }
1104 header.dirofs = LittleLong (header.dirofs);
1105 header.dirlen = LittleLong (header.dirlen);
1106
1107 if (header.dirlen % sizeof(dpackfile_t))
1108 {
1109 Con_Printf ("%s has an invalid directory size\n", packfile);
1110 FILEDESC_CLOSE(packhandle);
1111 return NULL;
1112 }
1113
1114 numpackfiles = header.dirlen / sizeof(dpackfile_t);
1115
1116 if (numpackfiles < 0 || numpackfiles > MAX_FILES_IN_PACK)
1117 {
1118 Con_Printf ("%s has %i files\n", packfile, numpackfiles);
1119 FILEDESC_CLOSE(packhandle);
1120 return NULL;
1121 }
1122
1123 info = (dpackfile_t *)Mem_Alloc(tempmempool, sizeof(*info) * numpackfiles);
1124 FILEDESC_SEEK (packhandle, header.dirofs, SEEK_SET);
1125 if(header.dirlen != FILEDESC_READ (packhandle, (void *)info, header.dirlen))
1126 {
1127 Con_Printf("%s is an incomplete PAK, not loading\n", packfile);
1128 Mem_Free(info);
1129 FILEDESC_CLOSE(packhandle);
1130 return NULL;
1131 }
1132
1133 pack = (pack_t *)Mem_Alloc(fs_mempool, sizeof (pack_t));
1134 pack->ignorecase = true; // PAK is sensitive in Quake1 but insensitive in Quake2
1135 dp_strlcpy (pack->filename, packfile, sizeof (pack->filename));
1136 pack->handle = packhandle;
1137 pack->numfiles = 0;
1138 pack->files = (packfile_t *)Mem_Alloc(fs_mempool, numpackfiles * sizeof(packfile_t));
1139
1140 // parse the directory
1141 for (i = 0;i < numpackfiles;i++)
1142 {
1143 fs_offset_t offset = (unsigned int)LittleLong (info[i].filepos);
1144 fs_offset_t size = (unsigned int)LittleLong (info[i].filelen);
1145
1146 // Ensure a zero terminated file name (required by format).
1147 info[i].name[sizeof(info[i].name) - 1] = 0;
1148
1150 }
1151
1152 Mem_Free(info);
1153
1154 Con_DPrintf("Added packfile %s (%i files)\n", packfile, numpackfiles);
1155 return pack;
1156}
#define LittleLong(l)
Definition common.h:92
static packfile_t * FS_AddFileToPack(const char *name, pack_t *pack, fs_offset_t offset, fs_offset_t packsize, fs_offset_t realsize, int flags)
Definition fs.c:954
#define FILEDESC_READ
Definition fs.c:109
int filedesc_t
Definition fs.c:106
#define FILEDESC_ISVALID(fd)
Definition fs.c:108
#define MAX_FILES_IN_PACK
Definition fs.c:440
#define FILEDESC_SEEK
Definition fs.c:112
#define PACKFILE_FLAG_TRUEOFFS
the offset in packfile_t is the true contents offset
Definition fs.c:370

References Con_DPrintf(), Con_Printf(), dpackheader_t::dirlen, dpackheader_t::dirofs, dp_strlcpy, FILEDESC_CLOSE, FILEDESC_ISVALID, FILEDESC_READ, FILEDESC_SEEK, pack_t::filename, pack_t::files, FS_AddFileToPack(), fs_mempool, FS_SysOpenFiledesc(), pack_t::handle, i, dpackheader_t::id, pack_t::ignorecase, int(), LittleLong, MAX_FILES_IN_PACK, Mem_Alloc, Mem_Free, dpackfile_t::name, name, NULL, pack_t::numfiles, offset, PACKFILE_FLAG_TRUEOFFS, size, and tempmempool.

Referenced by FS_AddPack_Fullpath().

◆ FS_LoadPackPK3()

static pack_t * FS_LoadPackPK3 ( const char * packfile)
static

Definition at line 891 of file fs.c.

892{
893 filedesc_t packhandle;
894 packhandle = FS_SysOpenFiledesc (packfile, "rb", false);
895 if (!FILEDESC_ISVALID(packhandle))
896 return NULL;
897 return FS_LoadPackPK3FromFD(packfile, packhandle, false);
898}

References FILEDESC_ISVALID, FS_LoadPackPK3FromFD(), FS_SysOpenFiledesc(), and NULL.

Referenced by FS_AddPack_Fullpath().

◆ FS_LoadPackPK3FromFD()

static pack_t * FS_LoadPackPK3FromFD ( const char * packfile,
filedesc_t packhandle,
qbool silent )
static

Definition at line 836 of file fs.c.

837{
839 pack_t *pack;
840 int real_nb_files;
841
842 if (! PK3_GetEndOfCentralDir (packfile, packhandle, &eocd))
843 {
844 if(!silent)
845 Con_Printf ("%s is not a PK3 file\n", packfile);
846 FILEDESC_CLOSE(packhandle);
847 return NULL;
848 }
849
850 // Multi-volume ZIP archives are NOT allowed
851 if (eocd.disknum != 0 || eocd.cdir_disknum != 0)
852 {
853 Con_Printf ("%s is a multi-volume ZIP archive\n", packfile);
854 FILEDESC_CLOSE(packhandle);
855 return NULL;
856 }
857
858 // We only need to do this test if MAX_FILES_IN_PACK is lesser than 65535
859 // since eocd.nbentries is an unsigned 16 bits integer
860#if MAX_FILES_IN_PACK < 65535
861 if (eocd.nbentries > MAX_FILES_IN_PACK)
862 {
863 Con_Printf ("%s contains too many files (%hu)\n", packfile, eocd.nbentries);
864 FILEDESC_CLOSE(packhandle);
865 return NULL;
866 }
867#endif
868
869 // Create a package structure in memory
870 pack = (pack_t *)Mem_Alloc(fs_mempool, sizeof (pack_t));
871 pack->ignorecase = true; // PK3 ignores case
872 dp_strlcpy (pack->filename, packfile, sizeof (pack->filename));
873 pack->handle = packhandle;
874 pack->numfiles = eocd.nbentries;
875 pack->files = (packfile_t *)Mem_Alloc(fs_mempool, eocd.nbentries * sizeof(packfile_t));
876
877 real_nb_files = PK3_BuildFileList (pack, &eocd);
878 if (real_nb_files < 0)
879 {
880 Con_Printf ("%s is not a valid PK3 file\n", packfile);
881 FILEDESC_CLOSE(pack->handle);
882 Mem_Free(pack);
883 return NULL;
884 }
885
886 Con_DPrintf("Added packfile %s (%i files)\n", packfile, real_nb_files);
887 return pack;
888}
static qbool PK3_GetEndOfCentralDir(const char *packfile, filedesc_t packhandle, pk3_endOfCentralDir_t *eocd)
Definition fs.c:637
static int PK3_BuildFileList(pack_t *pack, const pk3_endOfCentralDir_t *eocd)
Definition fs.c:712
unsigned short disknum
Definition fs.c:340
unsigned short nbentries
total number of entries in the central directory on this disk
Definition fs.c:343
unsigned short cdir_disknum
number of the disk with the start of the central directory
Definition fs.c:341

References pk3_endOfCentralDir_t::cdir_disknum, Con_DPrintf(), Con_Printf(), pk3_endOfCentralDir_t::disknum, dp_strlcpy, FILEDESC_CLOSE, pack_t::filename, pack_t::files, fs_mempool, pack_t::handle, pack_t::ignorecase, MAX_FILES_IN_PACK, Mem_Alloc, Mem_Free, pk3_endOfCentralDir_t::nbentries, NULL, pack_t::numfiles, PK3_BuildFileList(), and PK3_GetEndOfCentralDir().

Referenced by FS_Init_SelfPack(), and FS_LoadPackPK3().

◆ FS_LoadPackVirtual()

static pack_t * FS_LoadPackVirtual ( const char * dirname)
static

Definition at line 1165 of file fs.c.

1166{
1167 pack_t *pack;
1168 pack = (pack_t *)Mem_Alloc(fs_mempool, sizeof (pack_t));
1169 pack->vpack = true;
1170 pack->ignorecase = false;
1171 dp_strlcpy (pack->filename, dirname, sizeof(pack->filename));
1172 pack->handle = FILEDESC_INVALID;
1173 pack->numfiles = -1;
1174 pack->files = NULL;
1175 Con_DPrintf("Added packfile %s (virtual pack)\n", dirname);
1176 return pack;
1177}
#define FILEDESC_INVALID
Definition fs.c:107

References Con_DPrintf(), dp_strlcpy, FILEDESC_INVALID, pack_t::filename, pack_t::files, fs_mempool, pack_t::handle, pack_t::ignorecase, Mem_Alloc, NULL, pack_t::numfiles, and pack_t::vpack.

Referenced by FS_AddPack_Fullpath().

◆ FS_Ls_f()

void FS_Ls_f ( cmd_state_t * cmd)

Definition at line 4059 of file fs.c.

4060{
4061 FS_ListDirectoryCmd(cmd, "ls", false);
4062}

References cmd(), and FS_ListDirectoryCmd().

Referenced by FS_Init_Commands().

◆ FS_mkdir()

static void FS_mkdir ( const char * path)
static

Definition at line 999 of file fs.c.

1000{
1001 WPATHDEF(pathw);
1002
1003 if(Sys_CheckParm("-readonly"))
1004 return;
1005
1006 WIDE(path, pathw);
1007
1008#ifdef WIN32
1009 if (_wmkdir(pathw) == -1)
1010#else
1011 if (mkdir(path, 0777) == -1)
1012#endif
1013 {
1014 // No logging for this. The only caller is FS_CreatePath (which
1015 // calls it in ways that will intentionally produce EEXIST),
1016 // and its own callers always use the directory afterwards and
1017 // thus will detect failure that way.
1018 }
1019}
#define WIDE(str, wstr)
Definition utf8lib.h:106

References Sys_CheckParm(), WIDE, and WPATHDEF.

Referenced by FS_CreatePath().

◆ FS_OpenPackedFile()

static qfile_t * FS_OpenPackedFile ( pack_t * pack,
int pack_ind )
static

Definition at line 2518 of file fs.c.

2519{
2520 packfile_t *pfile;
2521 filedesc_t dup_handle;
2522 qfile_t* file;
2523
2524 pfile = &pack->files[pack_ind];
2525
2526 // If we don't have the true offset, get it now
2527 if (! (pfile->flags & PACKFILE_FLAG_TRUEOFFS))
2528 if (!PK3_GetTrueFileOffset (pfile, pack))
2529 return NULL;
2530
2531#ifndef LINK_TO_ZLIB
2532 // No Zlib DLL = no compressed files
2533 if (!zlib_dll && (pfile->flags & PACKFILE_FLAG_DEFLATED))
2534 {
2535 Con_Printf(CON_WARN "WARNING: can't open the compressed file %s\n"
2536 "You need the Zlib DLL to use compressed files\n",
2537 pfile->name);
2538 return NULL;
2539 }
2540#endif
2541
2542 // LadyHavoc: FILEDESC_SEEK affects all duplicates of a handle so we do it before
2543 // the dup() call to avoid having to close the dup_handle on error here
2544 if (FILEDESC_SEEK (pack->handle, pfile->offset, SEEK_SET) == -1)
2545 {
2546 Con_Printf ("FS_OpenPackedFile: can't lseek to %s in %s (offset: %08x%08x)\n",
2547 pfile->name, pack->filename, (unsigned int)(pfile->offset >> 32), (unsigned int)(pfile->offset));
2548 return NULL;
2549 }
2550
2551 dup_handle = FILEDESC_DUP (pack->filename, pack->handle);
2552 if (!FILEDESC_ISVALID(dup_handle))
2553 {
2554 Con_Printf ("FS_OpenPackedFile: can't dup package's handle (pack: %s)\n", pack->filename);
2555 return NULL;
2556 }
2557
2558 file = (qfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
2559 memset (file, 0, sizeof (*file));
2560 file->handle = dup_handle;
2561 file->flags = QFILE_FLAG_PACKED;
2562 file->real_length = pfile->realsize;
2563 file->offset = pfile->offset;
2564 file->position = 0;
2565 file->ungetc = EOF;
2566
2567 if (pfile->flags & PACKFILE_FLAG_DEFLATED)
2568 {
2569 ztoolkit_t *ztk;
2570
2571 file->flags |= QFILE_FLAG_DEFLATED;
2572
2573 // We need some more variables
2574 ztk = (ztoolkit_t *)Mem_Alloc (fs_mempool, sizeof (*ztk));
2575
2576 ztk->comp_length = pfile->packsize;
2577
2578 // Initialize zlib stream
2579 ztk->zstream.next_in = ztk->input;
2580 ztk->zstream.avail_in = 0;
2581
2582 /* From Zlib's "unzip.c":
2583 *
2584 * windowBits is passed < 0 to tell that there is no zlib header.
2585 * Note that in this case inflate *requires* an extra "dummy" byte
2586 * after the compressed stream in order to complete decompression and
2587 * return Z_STREAM_END.
2588 * In unzip, i don't wait absolutely Z_STREAM_END because I known the
2589 * size of both compressed and uncompressed data
2590 */
2591 if (qz_inflateInit2 (&ztk->zstream, -MAX_WBITS) != Z_OK)
2592 {
2593 Con_Printf ("FS_OpenPackedFile: inflate init error (file: %s)\n", pfile->name);
2594 FILEDESC_CLOSE(dup_handle);
2595 Mem_Free(ztk);
2596 Mem_Free(file);
2597 return NULL;
2598 }
2599
2600 ztk->zstream.next_out = file->buff;
2601 ztk->zstream.avail_out = sizeof (file->buff);
2602
2603 file->ztk = ztk;
2604 }
2605
2606 return file;
2607}
#define CON_WARN
Definition console.h:101
#define QFILE_FLAG_DEFLATED
file is compressed using the deflate algorithm (PK3 only)
Definition fs.c:296
static filedesc_t FILEDESC_DUP(const char *filename, filedesc_t fd)
Definition fs.c:113
#define QFILE_FLAG_PACKED
inside a package (PAK or PK3)
Definition fs.c:294
static qbool PK3_GetTrueFileOffset(packfile_t *pfile, pack_t *pack)
Definition fs.c:908
#define PACKFILE_FLAG_DEFLATED
file compressed using the deflate algorithm
Definition fs.c:372
size_t comp_length
length of the compressed file
Definition fs.c:306
unsigned char input[FILE_BUFF_SIZE]
Definition fs.c:309
z_stream zstream
Definition fs.c:305

References z_stream::avail_in, z_stream::avail_out, ztoolkit_t::comp_length, Con_Printf(), CON_WARN, FILEDESC_CLOSE, FILEDESC_DUP(), FILEDESC_ISVALID, FILEDESC_SEEK, pack_t::filename, pack_t::files, packfile_t::flags, fs_mempool, pack_t::handle, ztoolkit_t::input, MAX_WBITS, Mem_Alloc, Mem_Free, packfile_t::name, z_stream::next_in, z_stream::next_out, NULL, packfile_t::offset, PACKFILE_FLAG_DEFLATED, PACKFILE_FLAG_TRUEOFFS, packfile_t::packsize, PK3_GetTrueFileOffset(), QFILE_FLAG_DEFLATED, QFILE_FLAG_PACKED, qz_inflateInit2, packfile_t::realsize, Z_OK, zlib_dll, and ztoolkit_t::zstream.

Referenced by FS_OpenReadFile().

◆ FS_OpenReadFile()

static qfile_t * FS_OpenReadFile ( const char * filename,
qbool quiet,
qbool nonblocking,
int symlinkLevels )
static

Definition at line 2787 of file fs.c.

2788{
2789 searchpath_t *search;
2790 int pack_ind;
2791
2792 search = FS_FindFile (filename, &pack_ind, NULL, quiet);
2793
2794 // Not found?
2795 if (search == NULL)
2796 return NULL;
2797
2798 // Found in the filesystem?
2799 if (pack_ind < 0)
2800 {
2801 // this works with vpacks, so we are fine
2802 char path [MAX_OSPATH];
2803 dpsnprintf (path, sizeof (path), "%s%s", search->filename, filename);
2804 return FS_SysOpen (path, "rb", nonblocking);
2805 }
2806
2807 // So, we found it in a package...
2808
2809 // Is it a PK3 symlink?
2810 // TODO also handle directory symlinks by parsing the whole structure...
2811 // but heck, file symlinks are good enough for now
2812 if(search->pack->files[pack_ind].flags & PACKFILE_FLAG_SYMLINK)
2813 {
2814 if(symlinkLevels <= 0)
2815 {
2816 Con_Printf("symlink: %s: too many levels of symbolic links\n", filename);
2817 return NULL;
2818 }
2819 else
2820 {
2821 char linkbuf[MAX_QPATH];
2823 qfile_t *linkfile = FS_OpenPackedFile (search->pack, pack_ind);
2824 const char *mergeslash;
2825 char *mergestart;
2826
2827 if(!linkfile)
2828 return NULL;
2829 count = FS_Read(linkfile, linkbuf, sizeof(linkbuf) - 1);
2830 FS_Close(linkfile);
2831 if(count < 0)
2832 return NULL;
2833 linkbuf[count] = 0;
2834
2835 // Now combine the paths...
2836 mergeslash = strrchr(filename, '/');
2837 mergestart = linkbuf;
2838 if(!mergeslash)
2839 mergeslash = filename;
2840 while(!strncmp(mergestart, "../", 3))
2841 {
2842 mergestart += 3;
2843 while(mergeslash > filename)
2844 {
2845 --mergeslash;
2846 if(*mergeslash == '/')
2847 break;
2848 }
2849 }
2850 // Now, mergestart will point to the path to be appended, and mergeslash points to where it should be appended
2851 if(mergeslash == filename)
2852 {
2853 // Either mergeslash == filename, then we just replace the name (done below)
2854 }
2855 else
2856 {
2857 // Or, we append the name after mergeslash;
2858 // or rather, we can also shift the linkbuf so we can put everything up to and including mergeslash first
2859 int spaceNeeded = mergeslash - filename + 1;
2860 int spaceRemoved = mergestart - linkbuf;
2861 if(count - spaceRemoved + spaceNeeded >= MAX_QPATH)
2862 {
2863 Con_DPrintf("symlink: too long path rejected\n");
2864 return NULL;
2865 }
2866 memmove(linkbuf + spaceNeeded, linkbuf + spaceRemoved, count - spaceRemoved);
2867 memcpy(linkbuf, filename, spaceNeeded);
2868 linkbuf[count - spaceRemoved + spaceNeeded] = 0;
2869 mergestart = linkbuf;
2870 }
2871 if (!quiet && developer_loading.integer)
2872 Con_DPrintf("symlink: %s -> %s\n", filename, mergestart);
2873 if(FS_CheckNastyPath (mergestart, false))
2874 {
2875 Con_DPrintf("symlink: nasty path %s rejected\n", mergestart);
2876 return NULL;
2877 }
2878 return FS_OpenReadFile(mergestart, quiet, nonblocking, symlinkLevels - 1);
2879 }
2880 }
2881
2882 return FS_OpenPackedFile (search->pack, pack_ind);
2883}
qfile_t * FS_SysOpen(const char *filepath, const char *mode, qbool nonblocking)
Definition fs.c:2484
#define PACKFILE_FLAG_SYMLINK
file is a symbolic link
Definition fs.c:374
static qfile_t * FS_OpenReadFile(const char *filename, qbool quiet, qbool nonblocking, int symlinkLevels)
Definition fs.c:2787
static qfile_t * FS_OpenPackedFile(pack_t *pack, int pack_ind)
Definition fs.c:2518
GLenum GLenum GLsizei count
Definition glquake.h:656
cvar_t developer_loading
Definition host.c:52
#define MAX_QPATH
max length of a quake game pathname
Definition qdefs.h:169

References Con_DPrintf(), Con_Printf(), count, developer_loading, dpsnprintf(), searchpath_t::filename, pack_t::files, packfile_t::flags, FS_CheckNastyPath(), FS_Close(), FS_FindFile(), FS_OpenPackedFile(), FS_OpenReadFile(), FS_Read(), FS_SysOpen(), cvar_t::integer, MAX_OSPATH, MAX_QPATH, NULL, searchpath_t::pack, and PACKFILE_FLAG_SYMLINK.

Referenced by FS_OpenReadFile(), and FS_OpenVirtualFile().

◆ FS_OpenRealFile()

qfile_t * FS_OpenRealFile ( const char * filepath,
const char * mode,
qbool quiet )

Definition at line 2902 of file fs.c.

2903{
2904 char real_path [MAX_OSPATH];
2905
2906 if (FS_CheckNastyPath(filepath, false))
2907 {
2908 Con_Printf("FS_OpenRealFile(\"%s\", \"%s\", %s): nasty filename rejected\n", filepath, mode, quiet ? "true" : "false");
2909 return NULL;
2910 }
2911
2912 dpsnprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath); // this is never a vpack
2913
2914 // If the file is opened in "write", "append", or "read/write" mode,
2915 // create directories up to the file.
2916 if (mode[0] == 'w' || mode[0] == 'a' || strchr (mode, '+'))
2917 FS_CreatePath (real_path);
2918 return FS_SysOpen (real_path, mode, false);
2919}
void FS_CreatePath(char *path)
Definition fs.c:1028
GLenum mode
Definition glquake.h:718

References Con_Printf(), dpsnprintf(), FS_CheckNastyPath(), FS_CreatePath(), fs_gamedir, FS_SysOpen(), MAX_OSPATH, mode, and NULL.

Referenced by CheckPendingDownloads(), CL_CutDemo(), CL_Locs_Save_f(), CL_ParseServerInfo(), CL_Record_f(), Con_ConDump_f(), Curl_Begin(), Curl_EndDownload(), FS_WriteFileInBlocks(), Host_SaveConfig(), JPEG_SaveImage_preflipped(), Key_History_Init(), Key_History_Shutdown(), Log_Open(), Log_Printf(), M_ScanSaves(), PNG_SaveImage_preflipped(), PRVM_Prog_Load(), R_GLSL_DumpShader_f(), SCR_CaptureVideo_Avi_BeginVideo(), SCR_CaptureVideo_Ogg_BeginVideo(), SV_Savegame_to(), SV_StartDemoRecording(), and VM_fopen().

◆ FS_OpenVirtualFile()

qfile_t * FS_OpenVirtualFile ( const char * filepath,
qbool quiet )

Definition at line 2929 of file fs.c.

2930{
2931 qfile_t *result = NULL;
2932 if (FS_CheckNastyPath(filepath, false))
2933 {
2934 Con_Printf("FS_OpenVirtualFile(\"%s\", %s): nasty filename rejected\n", filepath, quiet ? "true" : "false");
2935 return NULL;
2936 }
2937
2939 result = FS_OpenReadFile (filepath, quiet, false, 16);
2941 return result;
2942}
#define Thread_LockMutex(m)
Definition thread.h:17
#define Thread_UnlockMutex(m)
Definition thread.h:18

References Con_Printf(), FS_CheckNastyPath(), fs_mutex, FS_OpenReadFile(), NULL, Thread_LockMutex, and Thread_UnlockMutex.

Referenced by CL_PlayDemo(), FS_LoadFile(), GetMapList(), hz_bitstream_read_open(), jam_open(), LibAvW_OpenVideo(), QW_CL_CheckOrDownloadFile(), SV_Download_f(), VM_buf_loadfile(), VM_fopen(), and W_LoadTextureWadFile().

◆ FS_Path_f()

static void FS_Path_f ( cmd_state_t * cmd)
static

Definition at line 1052 of file fs.c.

1053{
1054 searchpath_t *s;
1055
1056 Con_Print("Current search path:\n");
1057 for (s=fs_searchpaths ; s ; s=s->next)
1058 {
1059 if (s->pack)
1060 {
1061 if(s->pack->vpack)
1062 Con_Printf("%sdir (virtual pack)\n", s->pack->filename);
1063 else
1064 Con_Printf("%s (%i files)\n", s->pack->filename, s->pack->numfiles);
1065 }
1066 else
1067 Con_Printf("%s\n", s->filename);
1068 }
1069}

References Con_Print(), Con_Printf(), pack_t::filename, searchpath_t::filename, fs_searchpaths, searchpath_t::next, pack_t::numfiles, searchpath_t::pack, and pack_t::vpack.

Referenced by FS_Init_Commands().

◆ FS_Print()

int FS_Print ( qfile_t * file,
const char * msg )

Definition at line 3262 of file fs.c.

3263{
3264 return (int)FS_Write (file, msg, strlen (msg));
3265}
fs_offset_t FS_Write(qfile_t *file, const void *data, size_t datasize)
Definition fs.c:3020

References FS_Write(), and strlen().

Referenced by Log_Close(), Log_ConPrint(), Log_Open(), PRVM_ED_Write(), PRVM_ED_WriteGlobals(), R_GLSL_DumpShader_f(), and SV_Savegame_to().

◆ FS_Printf()

int FS_Printf ( qfile_t * file,
const char * format,
... )

Definition at line 3274 of file fs.c.

3275{
3276 int result;
3277 va_list args;
3278
3279 va_start (args, format);
3280 result = FS_VPrintf (file, format, args);
3281 va_end (args);
3282
3283 return result;
3284}
int FS_VPrintf(qfile_t *file, const char *format, va_list ap)
Definition fs.c:3294
GLint GLint GLint GLsizei GLsizei GLenum format
Definition glquake.h:649

References format, and FS_VPrintf().

Referenced by CL_CutDemo(), CL_Locs_Save_f(), CL_ParseServerInfo(), CL_Record_f(), Crypto_SavePubKeyTextFile(), Cvar_WriteVariables(), Key_History_Shutdown(), Key_WriteBindings(), PRVM_ED_Write(), PRVM_ED_WriteGlobals(), PRVM_Prog_Load(), SV_Savegame_to(), and SV_StartDemoRecording().

◆ FS_Purge()

void FS_Purge ( qfile_t * file)

Definition at line 3488 of file fs.c.

3489{
3490 file->buff_len = 0;
3491 file->buff_ind = 0;
3492 file->ungetc = EOF;
3493}

Referenced by FS_Read(), FS_Seek(), and FS_Write().

◆ FS_Read()

fs_offset_t FS_Read ( qfile_t * file,
void * buffer,
size_t buffersize )

Definition at line 3067 of file fs.c.

3068{
3069 fs_offset_t count, done;
3070
3071 if (buffersize == 0 || !buffer)
3072 return 0;
3073
3074 // Get rid of the ungetc character
3075 if (file->ungetc != EOF)
3076 {
3077 ((char*)buffer)[0] = file->ungetc;
3078 buffersize--;
3079 file->ungetc = EOF;
3080 done = 1;
3081 }
3082 else
3083 done = 0;
3084
3085 if(file->flags & QFILE_FLAG_DATA)
3086 {
3087 size_t left = file->real_length - file->position;
3088 if(buffersize > left)
3089 buffersize = left;
3090 memcpy(buffer, file->data + file->position, buffersize);
3091 file->position += buffersize;
3092 return buffersize;
3093 }
3094
3095 // First, we copy as many bytes as we can from "buff"
3096 if (file->buff_ind < file->buff_len)
3097 {
3098 count = file->buff_len - file->buff_ind;
3099 count = ((fs_offset_t)buffersize > count) ? count : (fs_offset_t)buffersize;
3100 done += count;
3101 memcpy (buffer, &file->buff[file->buff_ind], count);
3102 file->buff_ind += count;
3103
3104 buffersize -= count;
3105 if (buffersize == 0)
3106 return done;
3107 }
3108
3109 // NOTE: at this point, the read buffer is always empty
3110
3111 // If the file isn't compressed
3112 if (! (file->flags & QFILE_FLAG_DEFLATED))
3113 {
3114 fs_offset_t nb;
3115
3116 // We must take care to not read after the end of the file
3117 count = file->real_length - file->position;
3118
3119 // If we have a lot of data to get, put them directly into "buffer"
3120 if (buffersize > sizeof (file->buff) / 2)
3121 {
3122 if (count > (fs_offset_t)buffersize)
3123 count = (fs_offset_t)buffersize;
3124 if (FILEDESC_SEEK (file->handle, file->offset + file->position, SEEK_SET) == -1)
3125 {
3126 // Seek failed. When reading from a pipe, and
3127 // the caller never called FS_Seek, this still
3128 // works fine. So no reporting this error.
3129 }
3130 nb = FILEDESC_READ (file->handle, &((unsigned char*)buffer)[done], count);
3131 if (nb > 0)
3132 {
3133 done += nb;
3134 file->position += nb;
3135
3136 // Purge cached data
3137 FS_Purge (file);
3138 }
3139 }
3140 else
3141 {
3142 if (count > (fs_offset_t)sizeof (file->buff))
3143 count = (fs_offset_t)sizeof (file->buff);
3144 if (FILEDESC_SEEK (file->handle, file->offset + file->position, SEEK_SET) == -1)
3145 {
3146 // Seek failed. When reading from a pipe, and
3147 // the caller never called FS_Seek, this still
3148 // works fine. So no reporting this error.
3149 }
3150 nb = FILEDESC_READ (file->handle, file->buff, count);
3151 if (nb > 0)
3152 {
3153 file->buff_len = nb;
3154 file->position += nb;
3155
3156 // Copy the requested data in "buffer" (as much as we can)
3157 count = (fs_offset_t)buffersize > file->buff_len ? file->buff_len : (fs_offset_t)buffersize;
3158 memcpy (&((unsigned char*)buffer)[done], file->buff, count);
3159 file->buff_ind = count;
3160 done += count;
3161 }
3162 }
3163
3164 return done;
3165 }
3166
3167 // If the file is compressed, it's more complicated...
3168 // We cycle through a few operations until we have read enough data
3169 while (buffersize > 0)
3170 {
3171 ztoolkit_t *ztk = file->ztk;
3172 int error;
3173
3174 // NOTE: at this point, the read buffer is always empty
3175
3176 // If "input" is also empty, we need to refill it
3177 if (ztk->in_ind == ztk->in_len)
3178 {
3179 // If we are at the end of the file
3180 if (file->position == file->real_length)
3181 return done;
3182
3183 count = (fs_offset_t)(ztk->comp_length - ztk->in_position);
3184 if (count > (fs_offset_t)sizeof (ztk->input))
3185 count = (fs_offset_t)sizeof (ztk->input);
3186 FILEDESC_SEEK (file->handle, file->offset + (fs_offset_t)ztk->in_position, SEEK_SET);
3187 if (FILEDESC_READ (file->handle, ztk->input, count) != count)
3188 {
3189 Con_Printf ("FS_Read: unexpected end of file\n");
3190 break;
3191 }
3192
3193 ztk->in_ind = 0;
3194 ztk->in_len = count;
3195 ztk->in_position += count;
3196 }
3197
3198 ztk->zstream.next_in = &ztk->input[ztk->in_ind];
3199 ztk->zstream.avail_in = (unsigned int)(ztk->in_len - ztk->in_ind);
3200
3201 // Now that we are sure we have compressed data available, we need to determine
3202 // if it's better to inflate it in "file->buff" or directly in "buffer"
3203
3204 // Inflate the data in "file->buff"
3205 if (buffersize < sizeof (file->buff) / 2)
3206 {
3207 ztk->zstream.next_out = file->buff;
3208 ztk->zstream.avail_out = sizeof (file->buff);
3209 error = qz_inflate (&ztk->zstream, Z_SYNC_FLUSH);
3210 if (error != Z_OK && error != Z_STREAM_END)
3211 {
3212 Con_Printf ("FS_Read: Can't inflate file\n");
3213 break;
3214 }
3215 ztk->in_ind = ztk->in_len - ztk->zstream.avail_in;
3216
3217 file->buff_len = (fs_offset_t)sizeof (file->buff) - ztk->zstream.avail_out;
3218 file->position += file->buff_len;
3219
3220 // Copy the requested data in "buffer" (as much as we can)
3221 count = (fs_offset_t)buffersize > file->buff_len ? file->buff_len : (fs_offset_t)buffersize;
3222 memcpy (&((unsigned char*)buffer)[done], file->buff, count);
3223 file->buff_ind = count;
3224 }
3225
3226 // Else, we inflate directly in "buffer"
3227 else
3228 {
3229 ztk->zstream.next_out = &((unsigned char*)buffer)[done];
3230 ztk->zstream.avail_out = (unsigned int)buffersize;
3231 error = qz_inflate (&ztk->zstream, Z_SYNC_FLUSH);
3232 if (error != Z_OK && error != Z_STREAM_END)
3233 {
3234 Con_Printf ("FS_Read: Can't inflate file\n");
3235 break;
3236 }
3237 ztk->in_ind = ztk->in_len - ztk->zstream.avail_in;
3238
3239 // How much data did it inflate?
3240 count = (fs_offset_t)(buffersize - ztk->zstream.avail_out);
3241 file->position += count;
3242
3243 // Purge cached data
3244 FS_Purge (file);
3245 }
3246
3247 done += count;
3248 buffersize -= count;
3249 }
3250
3251 return done;
3252}
void FS_Purge(qfile_t *file)
Definition fs.c:3488
#define Z_SYNC_FLUSH
Definition fs.c:231
GLuint buffer
Definition glquake.h:630
void error(string err,...)
size_t in_ind
Definition fs.c:307
size_t in_position
position in the compressed file
Definition fs.c:308
size_t in_len
input buffer current index and length
Definition fs.c:307

References z_stream::avail_in, z_stream::avail_out, buffer, ztoolkit_t::comp_length, Con_Printf(), count, error(), FILEDESC_READ, FILEDESC_SEEK, FS_Purge(), ztoolkit_t::in_ind, ztoolkit_t::in_len, ztoolkit_t::in_position, ztoolkit_t::input, int(), z_stream::next_in, z_stream::next_out, QFILE_FLAG_DATA, QFILE_FLAG_DEFLATED, Z_OK, Z_STREAM_END, Z_SYNC_FLUSH, and ztoolkit_t::zstream.

Referenced by CL_ReadDemoMessage(), Crypto_LoadFile(), Curl_Begin(), FS_Getc(), FS_LoadAndCloseQFile(), FS_OpenReadFile(), FS_Seek(), FS_SysCheckGameDir(), GetMapList(), hz_bitstream_read_blocks_read(), jam_open(), jam_video(), LibAvW_FS_Read(), M_ScanSaves(), SV_ReadClientMessage(), SV_SendClientDatagram(), W_GetTextureBGRA(), and W_LoadTextureWadFile().

◆ FS_RemoveOnClose()

void FS_RemoveOnClose ( qfile_t * file)

Definition at line 3008 of file fs.c.

3009{
3010 file->flags |= QFILE_FLAG_REMOVE;
3011}

References QFILE_FLAG_REMOVE.

Referenced by CL_Stop_f(), and SV_StopDemoRecording().

◆ FS_Rescan()

void FS_Rescan ( void )

Definition at line 1538 of file fs.c.

1539{
1540 int i;
1541 char gamedirbuf[MAX_INPUTLINE];
1542 char vabuf[1024];
1543
1545
1547
1548 // update the com_modname (used for server info)
1549 if (gamedirname2 && gamedirname2[0])
1551 else
1553
1554 // -game <gamedir>
1555 // Adds basedir/gamedir as an override game
1556 // LadyHavoc: now supports multiple -game directories
1557 // set the com_modname (reported in server info)
1558 *gamedirbuf = 0;
1559 for (i = 0;i < fs_numgamedirs;i++)
1560 {
1562 // update the com_modname (used server info)
1564 if(i)
1565 dp_strlcat(gamedirbuf, va(vabuf, sizeof(vabuf), " %s", fs_gamedirs[i]), sizeof(gamedirbuf));
1566 else
1567 dp_strlcpy(gamedirbuf, fs_gamedirs[i], sizeof(gamedirbuf));
1568 }
1569 Cvar_SetQuick(&cvar_fs_gamedir, gamedirbuf); // so QC or console code can query it
1570
1571 // add back the selfpack as new first item
1573
1574 if (cls.state != ca_dedicated)
1575 {
1576 // set the default screenshot name to either the mod name or the
1577 // gamemode screenshot name
1578 if (strcmp(com_modname, gamedirname1))
1580 else
1582 }
1583
1584 if((i = Sys_CheckParm("-modname")) && i < sys.argc - 1)
1586
1587 // If "-condebug" is in the command line, remove the previous log file
1588 if (Sys_CheckParm ("-condebug") != 0)
1589 unlink (va(vabuf, sizeof(vabuf), "%s/qconsole.log", fs_gamedir));
1590
1591 // look for the pop.lmp file and set registered to true if it is found
1592 if (FS_FileExists("gfx/pop.lmp"))
1594 switch(gamemode)
1595 {
1596 case GAME_NORMAL:
1597 case GAME_HIPNOTIC:
1598 case GAME_ROGUE:
1599 if (!registered.integer)
1600 {
1601 if (fs_numgamedirs > 1)
1602 Con_Print("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n");
1603 else
1604 Con_Print("Playing shareware version.\n");
1605 }
1606 else
1607 Con_Print("Playing registered version.\n");
1608 break;
1609 case GAME_STEELSTORM:
1610 if (registered.integer)
1611 Con_Print("Playing registered version.\n");
1612 else
1613 Con_Print("Playing shareware version.\n");
1614 break;
1615 default:
1616 break;
1617 }
1618
1619 // unload all wads so that future queries will return the new data
1620 W_UnloadAll();
1621}
@ ca_dedicated
Definition client.h:530
char com_modname[MAX_OSPATH]
Definition com_game.c:33
const char * gamescreenshotname
Definition com_game.c:31
gamemode_t gamemode
Definition com_game.c:26
@ GAME_ROGUE
Definition com_game.h:30
@ GAME_STEELSTORM
added by motorsep
Definition com_game.h:53
@ GAME_HIPNOTIC
Definition com_game.h:29
cvar_t registered
Definition common.c:32
void Cvar_SetValueQuick(cvar_t *var, float value)
Definition cvar.c:473
void Cvar_SetQuick(cvar_t *var, const char *value)
Definition cvar.c:436
static void FS_ClearSearchPath(void)
Definition fs.c:1451
static void FS_AddGameHierarchy(const char *dir)
Definition fs.c:1387
static void FS_ListGameDirs(void)
Definition fs.c:1854
const char * FS_FileExists(const char *filename)
Look for a file in the packages and in the filesystem Returns its canonical name (same case as used i...
Definition fs.c:3694
void W_UnloadAll(void)
Definition wad.c:87

References sys_t::argc, sys_t::argv, ca_dedicated, cls, com_modname, Con_Print(), cvar_fs_gamedir, Cvar_SetQuick(), Cvar_SetValueQuick(), dp_strlcat, dp_strlcpy, FS_AddGameHierarchy(), FS_AddSelfPack(), FS_ClearSearchPath(), FS_FileExists(), fs_gamedir, fs_gamedirs, FS_ListGameDirs(), fs_numgamedirs, GAME_HIPNOTIC, GAME_NORMAL, GAME_ROGUE, GAME_STEELSTORM, gamedirname1, gamedirname2, gamemode, gamescreenshotname, i, cvar_t::integer, MAX_INPUTLINE, registered, scr_screenshot_name, client_static_t::state, sys, Sys_CheckParm(), va(), and W_UnloadAll().

Referenced by CL_StopDownload(), FS_ChangeGameDirs(), FS_Init_Dir(), and FS_Rescan_f().

◆ FS_Rescan_f()

static void FS_Rescan_f ( cmd_state_t * cmd)
static

Definition at line 1623 of file fs.c.

1624{
1625 FS_Rescan();
1626}

References FS_Rescan().

Referenced by FS_Init_Commands().

◆ FS_SanitizePath()

void FS_SanitizePath ( char * path)

Definition at line 2674 of file fs.c.

2675{
2676 for (; *path; path++)
2677 if (*path == '\\')
2678 *path = '/';
2679}

Referenced by loadimagepixelsbgra().

◆ FS_Search()

fssearch_t * FS_Search ( const char * pattern,
int caseinsensitive,
int quiet,
const char * packfile )

Definition at line 3757 of file fs.c.

3758{
3759 fssearch_t *search;
3760 searchpath_t *searchpath;
3761 pack_t *pak;
3762 int i, basepathlength, numfiles, numchars, resultlistindex, dirlistindex;
3763 stringlist_t resultlist;
3764 stringlist_t dirlist;
3765 stringlist_t matchedSet, foundSet;
3766 const char *start, *slash, *backslash, *colon, *separator;
3767 char *basepath;
3768
3769 for (i = 0;pattern[i] == '.' || pattern[i] == ':' || pattern[i] == '/' || pattern[i] == '\\';i++)
3770 ;
3771
3772 if (i > 0)
3773 {
3774 Con_Printf("Don't use punctuation at the beginning of a search pattern!\n");
3775 return NULL;
3776 }
3777
3778 stringlistinit(&resultlist);
3779 stringlistinit(&dirlist);
3780 search = NULL;
3781 slash = strrchr(pattern, '/');
3782 backslash = strrchr(pattern, '\\');
3783 colon = strrchr(pattern, ':');
3784 separator = max(slash, backslash);
3785 separator = max(separator, colon);
3786 basepathlength = separator ? (separator + 1 - pattern) : 0;
3787 basepath = (char *)Mem_Alloc (tempmempool, basepathlength + 1);
3788 if (basepathlength)
3789 memcpy(basepath, pattern, basepathlength);
3790 basepath[basepathlength] = 0;
3791
3792 // search through the path, one element at a time
3793 for (searchpath = fs_searchpaths;searchpath;searchpath = searchpath->next)
3794 {
3795 // is the element a pak file?
3796 if (searchpath->pack && !searchpath->pack->vpack)
3797 {
3798 // look through all the pak file elements
3799 pak = searchpath->pack;
3800 if(packfile)
3801 {
3802 if(strcmp(packfile, pak->shortname))
3803 continue;
3804 }
3805 for (i = 0;i < pak->numfiles;i++)
3806 {
3807 char temp[MAX_OSPATH];
3808 dp_strlcpy(temp, pak->files[i].name, sizeof(temp));
3809 while (temp[0])
3810 {
3811 if (matchpattern(temp, (char *)pattern, true))
3812 {
3813 for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
3814 if (!strcmp(resultlist.strings[resultlistindex], temp))
3815 break;
3816 if (resultlistindex == resultlist.numstrings)
3817 {
3818 stringlistappend(&resultlist, temp);
3819 if (!quiet && developer_loading.integer)
3820 Con_Printf("SearchPackFile: %s : %s\n", pak->filename, temp);
3821 }
3822 }
3823 // strip off one path element at a time until empty
3824 // this way directories are added to the listing if they match the pattern
3825 slash = strrchr(temp, '/');
3826 backslash = strrchr(temp, '\\');
3827 colon = strrchr(temp, ':');
3828 separator = temp;
3829 if (separator < slash)
3830 separator = slash;
3831 if (separator < backslash)
3832 separator = backslash;
3833 if (separator < colon)
3834 separator = colon;
3835 *((char *)separator) = 0;
3836 }
3837 }
3838 }
3839 else
3840 {
3841 if(packfile)
3842 continue;
3843
3844 start = pattern;
3845
3846 stringlistinit(&matchedSet);
3847 stringlistinit(&foundSet);
3848 // add a first entry to the set
3849 stringlistappend(&matchedSet, "");
3850 // iterate through pattern's path
3851 while (*start)
3852 {
3853 const char *asterisk, *wildcard, *nextseparator, *prevseparator;
3854 char subpath[MAX_OSPATH];
3855 char subpattern[MAX_OSPATH];
3856
3857 // find the next wildcard
3858 wildcard = strchr(start, '?');
3859 asterisk = strchr(start, '*');
3860 if (asterisk && (!wildcard || asterisk < wildcard))
3861 {
3862 wildcard = asterisk;
3863 }
3864
3865 if (wildcard)
3866 {
3867 nextseparator = strchr( wildcard, '/' );
3868 }
3869 else
3870 {
3871 nextseparator = NULL;
3872 }
3873
3874 if( !nextseparator ) {
3875 nextseparator = start + strlen( start );
3876 }
3877
3878 // prevseparator points past the '/' right before the wildcard and nextseparator at the one following it (or at the end of the string)
3879 // copy everything up except nextseperator
3880 dp_ustr2stp(subpattern, sizeof(subpattern), pattern, nextseparator - pattern);
3881 // find the last '/' before the wildcard
3882 prevseparator = strrchr( subpattern, '/' );
3883 if (!prevseparator)
3884 prevseparator = subpattern;
3885 else
3886 prevseparator++;
3887 // copy everything from start to the previous including the '/' (before the wildcard)
3888 // everything up to start is already included in the path of matchedSet's entries
3889 dp_ustr2stp(subpath, sizeof(subpath), start, (prevseparator - subpattern) - (start - pattern));
3890
3891 // for each entry in matchedSet try to open the subdirectories specified in subpath
3892 for( dirlistindex = 0 ; dirlistindex < matchedSet.numstrings ; dirlistindex++ ) {
3893 char temp[MAX_OSPATH];
3894 dp_strlcpy( temp, matchedSet.strings[ dirlistindex ], sizeof(temp) );
3895 dp_strlcat( temp, subpath, sizeof(temp) );
3896 listdirectory( &foundSet, searchpath->filename, temp );
3897 }
3898 if( dirlistindex == 0 ) {
3899 break;
3900 }
3901 // reset the current result set
3902 stringlistfreecontents( &matchedSet );
3903 // match against the pattern
3904 for( dirlistindex = 0 ; dirlistindex < foundSet.numstrings ; dirlistindex++ ) {
3905 const char *direntry = foundSet.strings[ dirlistindex ];
3906 if (matchpattern(direntry, subpattern, true)) {
3907 stringlistappend( &matchedSet, direntry );
3908 }
3909 }
3910 stringlistfreecontents( &foundSet );
3911
3912 start = nextseparator;
3913 }
3914
3915 for (dirlistindex = 0;dirlistindex < matchedSet.numstrings;dirlistindex++)
3916 {
3917 const char *matchtemp = matchedSet.strings[dirlistindex];
3918 if (matchpattern(matchtemp, (char *)pattern, true))
3919 {
3920 for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
3921 if (!strcmp(resultlist.strings[resultlistindex], matchtemp))
3922 break;
3923 if (resultlistindex == resultlist.numstrings)
3924 {
3925 stringlistappend(&resultlist, matchtemp);
3926 if (!quiet && developer_loading.integer)
3927 Con_Printf("SearchDirFile: %s\n", matchtemp);
3928 }
3929 }
3930 }
3931 stringlistfreecontents( &matchedSet );
3932 }
3933 }
3934
3935 if (resultlist.numstrings)
3936 {
3937 stringlistsort(&resultlist, true);
3938 numfiles = resultlist.numstrings;
3939 numchars = 0;
3940 for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
3941 numchars += (int)strlen(resultlist.strings[resultlistindex]) + 1;
3942 search = (fssearch_t *)Z_Malloc(sizeof(fssearch_t) + numchars + numfiles * sizeof(char *));
3943 search->filenames = (char **)((char *)search + sizeof(fssearch_t));
3944 search->filenamesbuffer = (char *)((char *)search + sizeof(fssearch_t) + numfiles * sizeof(char *));
3945 search->numfilenames = (int)numfiles;
3946 numfiles = 0;
3947 numchars = 0;
3948 for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
3949 {
3950 size_t textlen;
3951 search->filenames[numfiles] = search->filenamesbuffer + numchars;
3952 textlen = strlen(resultlist.strings[resultlistindex]) + 1;
3953 memcpy(search->filenames[numfiles], resultlist.strings[resultlistindex], textlen);
3954 numfiles++;
3955 numchars += (int)textlen;
3956 }
3957 }
3958 stringlistfreecontents(&resultlist);
3959
3960 Mem_Free(basepath);
3961 return search;
3962}
char * dp_ustr2stp(char *dst, size_t dsize, const char *src, size_t slen)
Copies a measured byte sequence (unterminated string) to a null-terminated string.
Definition common.c:1388
int matchpattern(const char *in, const char *pattern, int caseinsensitive)
Definition filematch.c:16
char * filenamesbuffer
Definition fs.h:119
#define Z_Malloc(size)
Definition zone.h:161

References Con_Printf(), developer_loading, dp_strlcat, dp_strlcpy, dp_ustr2stp(), pack_t::filename, searchpath_t::filename, fssearch_t::filenames, fssearch_t::filenamesbuffer, pack_t::files, fs_searchpaths, i, int(), cvar_t::integer, listdirectory(), matchpattern(), max, MAX_OSPATH, Mem_Alloc, Mem_Free, packfile_t::name, searchpath_t::next, NULL, fssearch_t::numfilenames, pack_t::numfiles, stringlist_t::numstrings, searchpath_t::pack, pack_t::shortname, stringlistappend(), stringlistfreecontents(), stringlistinit(), stringlistsort(), stringlist_t::strings, strlen(), tempmempool, pack_t::vpack, and Z_Malloc.

Referenced by Cmd_Exec_f(), Con_CompleteCommandLine(), FS_ListDirectory(), GetMapList(), Image_FixTransparentPixels_f(), Mod_LoadQ3Shaders(), and VM_search_begin().

◆ FS_Seek()

int FS_Seek ( qfile_t * file,
fs_offset_t offset,
int whence )

Definition at line 3360 of file fs.c.

3361{
3362 ztoolkit_t *ztk;
3363 unsigned char* buffer;
3364 fs_offset_t buffersize;
3365
3366 // Compute the file offset
3367 switch (whence)
3368 {
3369 case SEEK_CUR:
3370 offset += file->position - file->buff_len + file->buff_ind;
3371 break;
3372
3373 case SEEK_SET:
3374 break;
3375
3376 case SEEK_END:
3377 offset += file->real_length;
3378 break;
3379
3380 default:
3381 return -1;
3382 }
3383 if (offset < 0 || offset > file->real_length)
3384 return -1;
3385
3386 if(file->flags & QFILE_FLAG_DATA)
3387 {
3388 file->position = offset;
3389 return 0;
3390 }
3391
3392 // If we have the data in our read buffer, we don't need to actually seek
3393 if (file->position - file->buff_len <= offset && offset <= file->position)
3394 {
3395 file->buff_ind = offset + file->buff_len - file->position;
3396 return 0;
3397 }
3398
3399 // Purge cached data
3400 FS_Purge (file);
3401
3402 // Unpacked or uncompressed files can seek directly
3403 if (! (file->flags & QFILE_FLAG_DEFLATED))
3404 {
3405 if (FILEDESC_SEEK (file->handle, file->offset + offset, SEEK_SET) == -1)
3406 return -1;
3407 file->position = offset;
3408 return 0;
3409 }
3410
3411 // Seeking in compressed files is more a hack than anything else,
3412 // but we need to support it, so here we go.
3413 ztk = file->ztk;
3414
3415 // If we have to go back in the file, we need to restart from the beginning
3417 {
3418 ztk->in_ind = 0;
3419 ztk->in_len = 0;
3420 ztk->in_position = 0;
3421 file->position = 0;
3422 if (FILEDESC_SEEK (file->handle, file->offset, SEEK_SET) == -1)
3423 Con_Printf("IMPOSSIBLE: couldn't seek in already opened pk3 file.\n");
3424
3425 // Reset the Zlib stream
3426 ztk->zstream.next_in = ztk->input;
3427 ztk->zstream.avail_in = 0;
3428 qz_inflateReset (&ztk->zstream);
3429 }
3430
3431 // We need a big buffer to force inflating into it directly
3432 buffersize = 2 * sizeof (file->buff);
3433 buffer = (unsigned char *)Mem_Alloc (tempmempool, buffersize);
3434
3435 // Skip all data until we reach the requested offset
3436 while (offset > (file->position - file->buff_len + file->buff_ind))
3437 {
3438 fs_offset_t diff = offset - (file->position - file->buff_len + file->buff_ind);
3439 fs_offset_t count, len;
3440
3441 count = (diff > buffersize) ? buffersize : diff;
3442 len = FS_Read (file, buffer, count);
3443 if (len != count)
3444 {
3445 Mem_Free (buffer);
3446 return -1;
3447 }
3448 }
3449
3450 Mem_Free (buffer);
3451 return 0;
3452}
return position

References z_stream::avail_in, buffer, Con_Printf(), count, FILEDESC_SEEK, FS_Purge(), FS_Read(), ztoolkit_t::in_ind, ztoolkit_t::in_len, ztoolkit_t::in_position, ztoolkit_t::input, Mem_Alloc, Mem_Free, z_stream::next_in, offset, position, QFILE_FLAG_DATA, QFILE_FLAG_DEFLATED, tempmempool, and ztoolkit_t::zstream.

Referenced by CheckPendingDownloads(), CL_ReadDemoMessage(), GetMapList(), LibAvW_FS_Seek(), SCR_CaptureVideo_Avi_BeginVideo(), SCR_CaptureVideo_Avi_EndVideo(), SCR_CaptureVideo_RIFF_Finish(), SCR_CaptureVideo_RIFF_MakeIxChunk(), SCR_CaptureVideo_RIFF_Pop(), SV_ReadClientMessage(), W_GetTextureBGRA(), and W_LoadTextureWadFile().

◆ FS_SetGameDirs()

addgamedirs_t FS_SetGameDirs ( int numgamedirs,
const char * gamedirs[],
qbool failmissing,
qbool abortonfail )

Definition at line 1633 of file fs.c.

1634{
1635 int i, j, k;
1636 const char *p;
1637 const char *gamedirs_ok[MAX_GAMEDIRS + 2];
1638 int numgamedirs_ok;
1639
1640 // prepend the game-specific gamedirs (the primary and search order can be overriden)
1641 gamedirs_ok[0] = gamedirname1;
1642 numgamedirs_ok = 1;
1643 if (gamedirname2 && gamedirname2[0])
1644 {
1645 gamedirs_ok[1] = gamedirname2;
1646 ++numgamedirs_ok;
1647 }
1648
1649 // check the game-specific gamedirs
1650 for (i = 0; i < numgamedirs_ok; ++i)
1651 {
1652 p = FS_CheckGameDir(gamedirs_ok[i]);
1653 if(!p)
1654 Sys_Error("BUG: nasty gamedir name \"%s\" in gamemode_info", gamedirs_ok[i]);
1655 if(p == fs_checkgamedir_missing && failmissing)
1656 {
1657 Con_Printf(abortonfail ? CON_ERROR : CON_WARN "Base gamedir \"%s\" empty or not found!\n", gamedirs_ok[i]);
1658 if (abortonfail)
1659 return GAMEDIRS_FAILURE; // missing gamedirs
1660 }
1661 }
1662
1663 // copy and check the user-specified gamedirs
1664 for (i = 0; i < numgamedirs && (size_t)numgamedirs_ok < sizeof(gamedirs_ok) / sizeof(gamedirs_ok[0]); ++i)
1665 {
1666 // remove any previously-added duplicate (last one wins)
1667 for (j = 0; j < numgamedirs_ok; ++j)
1668 if (!strcasecmp(gamedirs_ok[j], gamedirs[i]))
1669 {
1670 --numgamedirs_ok;
1671 for (k = j; k < numgamedirs_ok; ++k)
1672 gamedirs_ok[k] = gamedirs_ok[k + 1];
1673 }
1674
1675 // if string is nasty, reject it
1676 p = FS_CheckGameDir(gamedirs[i]);
1677 if(!p)
1678 {
1679 Con_Printf(abortonfail ? CON_ERROR : CON_WARN "Nasty gamedir name \"%s\" rejected\n", gamedirs[i]);
1680 if (abortonfail)
1681 return GAMEDIRS_FAILURE; // nasty gamedirs
1682 else
1683 continue;
1684 }
1685 if(p == fs_checkgamedir_missing && failmissing)
1686 {
1687 Con_Printf(abortonfail ? CON_ERROR : CON_WARN "Gamedir \"%s\" empty or not found!\n", gamedirs[i]);
1688 if (abortonfail)
1689 return GAMEDIRS_FAILURE; // missing gamedirs
1690 else
1691 continue;
1692 }
1693
1694 gamedirs_ok[numgamedirs_ok++] = gamedirs[i];
1695 }
1696
1697 if (fs_numgamedirs == numgamedirs_ok)
1698 {
1699 for (i = 0;i < numgamedirs_ok;i++)
1700 if (strcasecmp(fs_gamedirs[i], gamedirs_ok[i]))
1701 break;
1702 if (i == numgamedirs_ok)
1703 return GAMEDIRS_ALLGOOD; // already using this set of gamedirs, do nothing
1704 }
1705
1706 if (numgamedirs_ok > MAX_GAMEDIRS)
1707 {
1708 Con_Printf(abortonfail ? CON_ERROR : CON_WARN "That is too many gamedirs (%i > %i)\n", numgamedirs_ok, MAX_GAMEDIRS);
1709 if (abortonfail)
1710 return GAMEDIRS_FAILURE; // too many gamedirs
1711 }
1712
1713 for (i = 0, fs_numgamedirs = 0; i < numgamedirs_ok && fs_numgamedirs < MAX_GAMEDIRS; ++i)
1714 dp_strlcpy(fs_gamedirs[fs_numgamedirs++], gamedirs_ok[i], sizeof(fs_gamedirs[0]));
1715
1716 return GAMEDIRS_SUCCESS;
1717}
@ GAMEDIRS_SUCCESS
Definition fs.h:105
void Sys_Error(const char *error,...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN
Causes the entire program to exit ASAP.
Definition sys_shared.c:724

References CON_ERROR, Con_Printf(), CON_WARN, dp_strlcpy, FS_CheckGameDir(), fs_checkgamedir_missing, fs_gamedirs, fs_numgamedirs, gamedirname1, gamedirname2, GAMEDIRS_ALLGOOD, GAMEDIRS_FAILURE, GAMEDIRS_SUCCESS, i, MAX_GAMEDIRS, and Sys_Error().

Referenced by COM_ChangeGameTypeForGameDirs().

◆ FS_Shutdown()

void FS_Shutdown ( void )

Definition at line 2364 of file fs.c.

2365{
2366 // close all pack files and such
2367 // (hopefully there aren't any other open files, but they'll be cleaned up
2368 // by the OS anyway)
2372
2373#ifdef WIN32
2374 Sys_FreeLibrary (&shfolder_dll);
2375 Sys_FreeLibrary (&shell32_dll);
2376 Sys_FreeLibrary (&ole32_dll);
2377#endif
2378
2379 if (fs_mutex)
2381}
static void PK3_CloseLibrary(void)
Definition fs.c:566
void Sys_FreeLibrary(dllhandle_t *handle)
Definition sys_shared.c:245
#define Thread_DestroyMutex(m)
Definition thread.h:16
#define Mem_FreePool(pool)
Definition zone.h:105

References FS_ClearSearchPath(), fs_mempool, fs_mutex, Mem_FreePool, PK3_CloseLibrary(), Sys_FreeLibrary(), and Thread_DestroyMutex.

◆ FS_StripExtension()

void FS_StripExtension ( const char * in,
char * out,
size_t size_out )

Definition at line 3612 of file fs.c.

3613{
3614 char *last = NULL;
3615 char currentchar;
3616
3617 if (size_out == 0)
3618 return;
3619
3620 while ((currentchar = *in) && size_out > 1)
3621 {
3622 if (currentchar == '.')
3623 last = out;
3624 else if (currentchar == '/' || currentchar == '\\' || currentchar == ':')
3625 last = NULL;
3626 *out++ = currentchar;
3627 in++;
3628 size_out--;
3629 }
3630 if (last)
3631 *last = 0;
3632 else
3633 *out = 0;
3634}

References NULL.

Referenced by CL_ParseServerInfo(), CL_SetupWorldModel(), COM_InitGameType(), dpvsimpledecode_open(), Image_StripImageExtension(), jam_open(), LibAvW_OpenVideo(), Mod_Decompile_f(), Mod_PSKMODEL_Load(), Mod_Q1BSP_LoadLighting(), Mod_Q1BSP_LoadMapBrushes(), Mod_Q1BSP_LoadTextures(), Mod_Q3BSP_LoadLightmaps(), PRVM_LoadLNO(), R_LoadTextureDDSFile(), and SV_SpawnServer().

◆ FS_SysCheckGameDir()

static const char * FS_SysCheckGameDir ( const char * gamedir,
char * buf,
size_t buflength )
static

Definition at line 1786 of file fs.c.

1787{
1788 qbool success;
1789 qfile_t *f;
1790 stringlist_t list;
1791 fs_offset_t n;
1792 char vabuf[1024];
1793
1794 stringlistinit(&list);
1795 listdirectory(&list, gamedir, "");
1796 success = list.numstrings > 0;
1798
1799 if(success)
1800 {
1801 f = FS_SysOpen(va(vabuf, sizeof(vabuf), "%smodinfo.txt", gamedir), "r", false);
1802 if(f)
1803 {
1804 n = FS_Read (f, buf, buflength - 1);
1805 if(n >= 0)
1806 buf[n] = 0;
1807 else
1808 *buf = 0;
1809 FS_Close(f);
1810 }
1811 else
1812 *buf = 0;
1813 return buf;
1814 }
1815
1816 return NULL;
1817}
#define n(x, y)
bool qbool
Definition qtypes.h:9
float f

References buf, f, FS_Close(), FS_Read(), FS_SysOpen(), listdirectory(), n, NULL, stringlist_t::numstrings, stringlistfreecontents(), stringlistinit(), and va().

Referenced by FS_CheckGameDir().

◆ FS_SysFileExists()

qbool FS_SysFileExists ( const char * path)

Look for a file in the filesystem only.

Definition at line 3745 of file fs.c.

3746{
3747 return FS_SysFileType (path) != FS_FILETYPE_NONE;
3748}

References FS_FILETYPE_NONE, and FS_SysFileType().

Referenced by FS_FindFile(), SCR_ScreenShot_f(), and Sys_FindInPATH().

◆ FS_SysFileType()

int FS_SysFileType ( const char * path)

Look for a file in the filesystem only.

Definition at line 3709 of file fs.c.

3710{
3711#ifdef WIN32
3712 // Sajt - some older sdks are missing this define
3713# ifndef INVALID_FILE_ATTRIBUTES
3714# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
3715# endif
3716 WPATHDEF(pathw);
3717 DWORD result;
3718
3719 WIDE(path, pathw);
3720 result = GetFileAttributesW(pathw);
3721
3722 if(result == INVALID_FILE_ATTRIBUTES)
3723 return FS_FILETYPE_NONE;
3724
3725 if(result & FILE_ATTRIBUTE_DIRECTORY)
3726 return FS_FILETYPE_DIRECTORY;
3727
3728 return FS_FILETYPE_FILE;
3729#else
3730 struct stat buf;
3731
3732 if (stat (path,&buf) == -1)
3733 return FS_FILETYPE_NONE;
3734
3735#ifndef S_ISDIR
3736#define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR)
3737#endif
3738 if(S_ISDIR(buf.st_mode))
3739 return FS_FILETYPE_DIRECTORY;
3740
3741 return FS_FILETYPE_FILE;
3742#endif
3743}
#define S_ISDIR(a)
#define FS_FILETYPE_DIRECTORY
Definition fs.h:139

References buf, FS_FILETYPE_DIRECTORY, FS_FILETYPE_FILE, FS_FILETYPE_NONE, S_ISDIR, WIDE, and WPATHDEF.

Referenced by FS_FileType(), and FS_SysFileExists().

◆ FS_SysLoadFile()

unsigned char * FS_SysLoadFile ( const char * path,
mempool_t * pool,
qbool quiet,
fs_offset_t * filesizepointer )

Definition at line 3556 of file fs.c.

3557{
3558 qfile_t *file = FS_SysOpen(path, "rb", false);
3559 return FS_LoadAndCloseQFile(file, path, pool, quiet, filesizepointer);
3560}

References FS_LoadAndCloseQFile(), and FS_SysOpen().

Referenced by FS_Init_SelfPack(), and listdirectory().

◆ FS_SysOpen()

qfile_t * FS_SysOpen ( const char * filepath,
const char * mode,
qbool nonblocking )

Definition at line 2484 of file fs.c.

2485{
2486 qfile_t* file;
2487
2488 file = (qfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
2489 file->ungetc = EOF;
2490 file->handle = FS_SysOpenFiledesc(filepath, mode, nonblocking);
2491 if (!FILEDESC_ISVALID(file->handle))
2492 {
2493 Mem_Free (file);
2494 return NULL;
2495 }
2496
2497 file->filename = Mem_strdup(fs_mempool, filepath);
2498
2499 file->real_length = FILEDESC_SEEK (file->handle, 0, SEEK_END);
2500
2501 // For files opened in append mode, we start at the end of the file
2502 if (mode[0] == 'a')
2503 file->position = file->real_length;
2504 else
2505 FILEDESC_SEEK (file->handle, 0, SEEK_SET);
2506
2507 return file;
2508}
#define Mem_strdup(pool, s)
Definition zone.h:97

References FILEDESC_ISVALID, FILEDESC_SEEK, fs_mempool, FS_SysOpenFiledesc(), Mem_Alloc, Mem_Free, Mem_strdup, mode, and NULL.

Referenced by Crypto_KeyGen_f(), Crypto_KeyGen_Finished(), Crypto_LoadFile(), Crypto_SavePubKeyTextFile(), FS_OpenReadFile(), FS_OpenRealFile(), FS_SysCheckGameDir(), FS_SysLoadFile(), and Host_LockSession().

◆ FS_SysOpenFD()

int FS_SysOpenFD ( const char * filepath,
const char * mode,
qbool nonblocking )

Definition at line 2468 of file fs.c.

2469{
2470#ifdef USE_RWOPS
2471 return -1;
2472#else
2473 return FS_SysOpenFiledesc(filepath, mode, nonblocking);
2474#endif
2475}

References FS_SysOpenFiledesc(), and mode.

Referenced by Sys_ProvideSelfFD().

◆ FS_SysOpenFiledesc()

static filedesc_t FS_SysOpenFiledesc ( const char * filepath,
const char * mode,
qbool nonblocking )
static

Definition at line 2383 of file fs.c.

2384{
2386 int mod, opt;
2387 unsigned int ind;
2388 qbool dolock = false;
2389 WPATHDEF(filepathw);
2390
2391 // Parse the mode string
2392 switch (mode[0])
2393 {
2394 case 'r':
2395 mod = O_RDONLY;
2396 opt = 0;
2397 break;
2398 case 'w':
2399 mod = O_WRONLY;
2400 opt = O_CREAT | O_TRUNC;
2401 break;
2402 case 'a':
2403 mod = O_WRONLY;
2404 opt = O_CREAT | O_APPEND;
2405 break;
2406 default:
2407 Con_Printf(CON_ERROR "FS_SysOpen(%s, %s): invalid mode\n", filepath, mode);
2408 return FILEDESC_INVALID;
2409 }
2410 for (ind = 1; mode[ind] != '\0'; ind++)
2411 {
2412 switch (mode[ind])
2413 {
2414 case '+':
2415 mod = O_RDWR;
2416 break;
2417 case 'b':
2418 opt |= O_BINARY;
2419 break;
2420 case 'l':
2421 dolock = true;
2422 break;
2423 default:
2424 Con_Printf(CON_ERROR "FS_SysOpen(%s, %s): unknown character in mode (%c)\n",
2425 filepath, mode, mode[ind]);
2426 }
2427 }
2428
2429 if (nonblocking)
2430 opt |= O_NONBLOCK;
2431
2432 if(Sys_CheckParm("-readonly") && mod != O_RDONLY)
2433 return FILEDESC_INVALID;
2434
2435#if USE_RWOPS
2436 if (dolock)
2437 return FILEDESC_INVALID;
2438 handle = SDL_RWFromFile(filepath, mode);
2439#else
2440# ifdef WIN32
2441 WIDE(filepath, filepathw);
2442# if _MSC_VER >= 1400
2443 _wsopen_s(&handle, filepathw, mod | opt, (dolock ? ((mod == O_RDONLY) ? _SH_DENYRD : _SH_DENYRW) : _SH_DENYNO), _S_IREAD | _S_IWRITE);
2444# else
2445 handle = _wsopen(filepathw, mod | opt, (dolock ? ((mod == O_RDONLY) ? _SH_DENYRD : _SH_DENYRW) : _SH_DENYNO), _S_IREAD | _S_IWRITE);
2446# endif
2447# else
2448 handle = open(filepath, mod | opt, 0666);
2449 if(handle >= 0 && dolock)
2450 {
2451 struct flock l;
2452 l.l_type = ((mod == O_RDONLY) ? F_RDLCK : F_WRLCK);
2453 l.l_whence = SEEK_SET;
2454 l.l_start = 0;
2455 l.l_len = 0;
2456 if(fcntl(handle, F_SETLK, &l) == -1)
2457 {
2458 FILEDESC_CLOSE(handle);
2459 handle = -1;
2460 }
2461 }
2462# endif
2463#endif
2464
2465 return handle;
2466}
float mod(float dividend, float divisor)
#define O_BINARY
Definition fs.c:56
#define O_NONBLOCK
Definition fs.c:61

References CON_ERROR, Con_Printf(), FILEDESC_CLOSE, FILEDESC_INVALID, mod(), mode, O_BINARY, O_NONBLOCK, Sys_CheckParm(), WIDE, and WPATHDEF.

Referenced by FS_ChooseUserDir(), FS_LoadPackPAK(), FS_LoadPackPK3(), FS_SysOpen(), and FS_SysOpenFD().

◆ FS_Tell()

fs_offset_t FS_Tell ( qfile_t * file)

Definition at line 3462 of file fs.c.

3463{
3464 return file->position - file->buff_len + file->buff_ind;
3465}

Referenced by CheckPendingDownloads(), SCR_CaptureVideo_RIFF_IndexEntry(), and SV_SendClientDatagram().

◆ FS_UnGetc()

int FS_UnGetc ( qfile_t * file,
unsigned char c )

Definition at line 3342 of file fs.c.

3343{
3344 // If there's already a character waiting to be read
3345 if (file->ungetc != EOF)
3346 return EOF;
3347
3348 file->ungetc = c;
3349 return c;
3350}

Referenced by VM_buf_loadfile(), and VM_fgets().

◆ FS_UnloadPacks_dlcache()

void FS_UnloadPacks_dlcache ( void )

Definition at line 1485 of file fs.c.

1486{
1487 searchpath_t *search = fs_searchpaths, *searchprev = fs_searchpaths, *searchnext;
1488
1490 return;
1491
1492 while (search)
1493 {
1494 searchnext = search->next;
1495 if (search->pack && search->pack->dlcache)
1496 {
1497 Con_DPrintf("Unloading pack: %s\n", search->pack->shortname);
1498
1499 // remove it from the search path list
1500 if (search == fs_searchpaths)
1501 fs_searchpaths = search->next;
1502 else
1503 searchprev->next = search->next;
1504
1505 // close the file
1506 FILEDESC_CLOSE(search->pack->handle);
1507 // free any memory associated with it
1508 if (search->pack->files)
1509 Mem_Free(search->pack->files);
1510 Mem_Free(search->pack);
1511 Mem_Free(search);
1512 }
1513 else
1514 searchprev = search;
1515 search = searchnext;
1516 }
1517}

References Con_DPrintf(), pack_t::dlcache, FILEDESC_CLOSE, pack_t::files, fs_searchpaths, fs_unload_dlcache, pack_t::handle, cvar_t::integer, Mem_Free, searchpath_t::next, searchpath_t::pack, and pack_t::shortname.

Referenced by CL_DisconnectEx(), and CL_ParseServerInfo().

◆ FS_VPrintf()

int FS_VPrintf ( qfile_t * file,
const char * format,
va_list ap )

Definition at line 3294 of file fs.c.

3295{
3296 int len;
3297 fs_offset_t buff_size = MAX_INPUTLINE;
3298 char *tempbuff;
3299
3300 for (;;)
3301 {
3302 tempbuff = (char *)Mem_Alloc (tempmempool, buff_size);
3303 len = dpvsnprintf (tempbuff, buff_size, format, ap);
3304 if (len >= 0 && len < buff_size)
3305 break;
3306 Mem_Free (tempbuff);
3307 buff_size *= 2;
3308 }
3309
3310 len = FILEDESC_WRITE (file->handle, tempbuff, len);
3311 Mem_Free (tempbuff);
3312
3313 return len;
3314}
int dpvsnprintf(char *buffer, size_t buffersize, const char *format, va_list args)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
Definition common.c:1010
#define FILEDESC_WRITE
Definition fs.c:110

References dpvsnprintf(), FILEDESC_WRITE, format, MAX_INPUTLINE, Mem_Alloc, Mem_Free, and tempmempool.

Referenced by FS_Printf(), and Log_Printf().

◆ FS_Which_f()

void FS_Which_f ( cmd_state_t * cmd)

Definition at line 4064 of file fs.c.

4065{
4066 const char *filename;
4067 int index;
4068 searchpath_t *sp;
4069 if (Cmd_Argc(cmd) != 2)
4070 {
4071 Con_Printf("usage:\n%s <file>\n", Cmd_Argv(cmd, 0));
4072 return;
4073 }
4074 filename = Cmd_Argv(cmd, 1);
4075 sp = FS_FindFile(filename, &index, NULL, true);
4076 if (!sp) {
4077 Con_Printf("%s isn't anywhere\n", filename);
4078 return;
4079 }
4080 if (sp->pack)
4081 {
4082 if(sp->pack->vpack)
4083 Con_Printf("%s is in virtual package %sdir\n", filename, sp->pack->shortname);
4084 else
4085 Con_Printf("%s is in package %s\n", filename, sp->pack->shortname);
4086 }
4087 else
4088 Con_Printf("%s is file %s%s\n", filename, sp->filename, filename);
4089}

References cmd(), Cmd_Argc(), Cmd_Argv(), Con_Printf(), searchpath_t::filename, FS_FindFile(), index, NULL, searchpath_t::pack, pack_t::shortname, and pack_t::vpack.

Referenced by FS_Init_Commands().

◆ FS_WhichPack()

const char * FS_WhichPack ( const char * filename)

Definition at line 4092 of file fs.c.

4093{
4094 int index;
4095 searchpath_t *sp = FS_FindFile(filename, &index, NULL, true);
4096 if(sp && sp->pack)
4097 return sp->pack->shortname;
4098 else if(sp)
4099 return "";
4100 else
4101 return 0;
4102}

References FS_FindFile(), index, NULL, searchpath_t::pack, and pack_t::shortname.

Referenced by Curl_SendRequirement(), SV_Download_f(), and VM_whichpack().

◆ FS_Write()

fs_offset_t FS_Write ( qfile_t * file,
const void * data,
size_t datasize )

Definition at line 3020 of file fs.c.

3021{
3022 fs_offset_t written = 0;
3023
3024 // If necessary, seek to the exact file position we're supposed to be
3025 if (file->buff_ind != file->buff_len)
3026 {
3027 if (FILEDESC_SEEK (file->handle, file->buff_ind - file->buff_len, SEEK_CUR) == -1)
3028 {
3029 Con_Printf(CON_WARN "WARNING: could not seek in %s.\n", file->filename);
3030 }
3031 }
3032
3033 // Purge cached data
3034 FS_Purge (file);
3035
3036 // Write the buffer and update the position
3037 // LadyHavoc: to hush a warning about passing size_t to an unsigned int parameter on Win64 we do this as multiple writes if the size would be too big for an integer (we never write that big in one go, but it's a theory)
3038 while (written < (fs_offset_t)datasize)
3039 {
3040 // figure out how much to write in one chunk
3041 fs_offset_t maxchunk = 1<<30; // 1 GiB
3042 int chunk = (int)min((fs_offset_t)datasize - written, maxchunk);
3043 int result = (int)FILEDESC_WRITE (file->handle, (const unsigned char *)data + written, chunk);
3044 // if at least some was written, add it to our accumulator
3045 if (result > 0)
3046 written += result;
3047 // if the result is not what we expected, consider the write to be incomplete
3048 if (result != chunk)
3049 break;
3050 }
3051 file->position = FILEDESC_SEEK (file->handle, 0, SEEK_CUR);
3052 if (file->real_length < file->position)
3053 file->real_length = file->position;
3054
3055 // note that this will never be less than 0 even if the write failed
3056 return written;
3057}
#define min(A, B)
Definition mathlib.h:37

References Con_Printf(), CON_WARN, data, FILEDESC_SEEK, FILEDESC_WRITE, FS_Purge(), int(), and min.

Referenced by CL_PasteDemo(), CL_WriteDemoMessage(), Con_ConDump_f(), Crypto_KeyGen_f(), Crypto_KeyGen_Finished(), CURL_fwrite(), FS_Print(), FS_WriteFileInBlocks(), JPEG_EmptyOutputBuffer(), JPEG_TermDestination(), Log_Start(), PNG_fWriteData(), SCR_CaptureVideo_Ogg_BeginVideo(), SCR_CaptureVideo_Ogg_EndVideo(), SCR_CaptureVideo_Ogg_FlushInterleaving(), SCR_CaptureVideo_Ogg_Interleave(), SCR_CaptureVideo_RIFF_Flush(), SCR_CaptureVideo_RIFF_FlushNoIncrease(), SCR_CaptureVideo_RIFF_Pop(), SCR_CaptureVideo_RIFF_WriteBytes(), SV_WriteDemoMessage(), VM_buf_writefile(), and VM_fputs().

◆ FS_WriteFile()

qbool FS_WriteFile ( const char * filename,
const void * data,
fs_offset_t len )

Definition at line 3593 of file fs.c.

3594{
3595 return FS_WriteFileInBlocks(filename, &data, &len, 1);
3596}
qbool FS_WriteFileInBlocks(const char *filename, const void *const *data, const fs_offset_t *len, size_t count)
Definition fs.c:3570

References data, and FS_WriteFileInBlocks().

Referenced by CL_StopDownload(), Image_WriteTGABGRA(), Mod_Decompile_f(), Mod_Decompile_OBJ(), Mod_Decompile_SMD(), QW_CL_ParseDownload(), R_SaveTextureDDSFile(), R_Shadow_SaveWorldLights(), and SV_SaveEntFile_f().

◆ FS_WriteFileInBlocks()

qbool FS_WriteFileInBlocks ( const char * filename,
const void *const * data,
const fs_offset_t * len,
size_t count )

Definition at line 3570 of file fs.c.

3571{
3572 qfile_t *file;
3573 size_t i;
3574 fs_offset_t lentotal;
3575
3576 file = FS_OpenRealFile(filename, "wb", false);
3577 if (!file)
3578 {
3579 Con_Printf("FS_WriteFile: failed on %s\n", filename);
3580 return false;
3581 }
3582
3583 lentotal = 0;
3584 for(i = 0; i < count; ++i)
3585 lentotal += len[i];
3586 Con_DPrintf("FS_WriteFile: %s (%u bytes)\n", filename, (unsigned int)lentotal);
3587 for(i = 0; i < count; ++i)
3588 FS_Write (file, data[i], len[i]);
3589 FS_Close (file);
3590 return true;
3591}
qfile_t * FS_OpenRealFile(const char *filepath, const char *mode, qbool quiet)
Definition fs.c:2902

References Con_DPrintf(), Con_Printf(), count, data, FS_Close(), FS_OpenRealFile(), FS_Write(), and i.

Referenced by FS_WriteFile(), and Image_WriteTGABGR_preflipped().

◆ int()

static int ( ZEXPORT * qz_inflate)
static

Referenced by animatemodel(), Buffer_Callback(), BufStr_Flush(), BuildGammaTable16(), BuildGammaTable8(), CDAudio_Play_byName(), CDAudio_StartPlaylist(), CL_Beam_AddPolygons(), CL_Beams_SetupBuiltinTexture(), CL_DrawVideo_DisplaySubtitleLine(), CL_Frame(), CL_GenericHitSuperContentsMask(), CL_GetTagMatrix(), CL_Locs_AddNode(), CL_Locs_Reload_f(), CL_Locs_Save_f(), CL_movestep(), CL_NewParticle(), CL_NewParticlesFromEffectinfo(), CL_Packet_f(), CL_ParseDownload(), CL_ParseServerMessage(), CL_ParticleCube(), CL_ParticleRain(), CL_Particles_ParseEffectInfo(), CL_PQRcon_f(), CL_Rcon_f(), CL_RelinkEffects(), CL_RelinkLightFlashes(), CL_RelinkWorld(), CL_Screen_Init(), CL_SpawnDecalParticleForSurface(), CL_StopDownload(), CL_TraceBox(), CL_TraceLine(), CL_TracePoint(), CL_Video_Frame(), Cmd_TokenizeString(), Collision_Cache_Lookup(), COM_InitGameType(), COM_ReadAndTokenizeLine(), Con_CheckResize(), Con_CompleteCommandLine(), Con_DisplayLineFunc(), Con_DisplayList(), Con_DrawConsole(), Con_DrawInput(), Con_DrawNotifyRect(), CSQC_AddRenderEdict(), Cvar_Get(), Cvar_RegisterVariable(), Cvar_SetQuick_Internal(), detect_match_rule(), DrawQ_SetClipArea(), DrawQ_String_Scale(), DrawQ_TextWidth_UntilWidth_TrackColors_Scale(), EntityFrame5_ExpandEdicts(), EntityFrameQuake_ReadEntity(), EntityFrameQuake_WriteFrame(), EntityState5_ReadUpdate(), FindFraction(), Font_Postprocess(), Font_SetSize(), Font_UnloadFont(), Font_VirtualToRealSize(), FS_AddFileToPack(), FS_Deflate(), FS_FindFile(), FS_Inflate(), FS_Init_Dir(), FS_IsRegisteredQuakePack(), FS_ListDirectory(), FS_LoadPackPAK(), FS_Read(), FS_Search(), FS_Write(), getdrawfont(), GetMapList(), gl_backend_devicelost(), GL_Mesh_ListVBOs(), GL_Setup(), GL_TextureMode_f(), Image_HeightmapToNormalmap_BGRA(), Image_Resample32Lerp(), Image_Resample32LerpLine(), InfoString_SetValue(), JPEG_SaveImage_to_Buffer(), Key_AddChar(), Key_History_Down(), Key_History_First(), Key_History_Get_foundCommand(), Key_History_Last(), Key_History_Up(), Key_Parse_CommonKeys(), Key_PrintBindList(), Key_StringToKeynum(), Key_Unbindall_f(), Key_WriteBindings(), LHNETADDRESS_FromString(), loadimagepixelsbgra(), M_Draw(), M_GameOptions_Key(), M_LanConfig_Key(), M_Main_Draw(), M_Menu_GameOptions_f(), M_ModList_Draw(), M_MultiPlayer_Draw(), M_Options_ColorControl_Draw(), M_Options_Draw(), M_Options_Effects_Draw(), M_Options_Graphics_Draw(), M_Setup_Key(), M_SinglePlayer_Draw(), M_UnbindCommand(), main(), MakeDownloadPacket(), Mod_BSP_FinalizePortals(), Mod_BSP_LightPoint_RecursiveBSPNode(), Mod_ClearUsed(), Mod_DARKPLACESMODEL_Load(), Mod_FindName(), Mod_GenerateLightmaps_CreateLightmaps(), Mod_IDP0_Load(), Mod_IDP2_Load(), Mod_IDP3_Load(), Mod_IDS2_Load(), Mod_INTERQUAKEMODEL_Load(), Mod_LoadModel(), Mod_LoadQ3Shaders(), Mod_Mesh_IndexForVertex(), mod_newmap(), Mod_OBJ_Load(), Mod_Print_f(), Mod_PSKMODEL_Load(), Mod_PurgeUnused(), Mod_Q1BSP_LoadEdges(), Mod_Q1BSP_LoadFaces(), Mod_Q1BSP_LoadTextures(), Mod_Q1BSP_ParseWadsFromEntityLump(), Mod_Q2BSP_LoadTexinfo(), Mod_Q3BSP_LightPoint(), Mod_Q3BSP_LoadLightGrid(), Mod_Q3BSP_LoadLightmaps(), Mod_Reload(), Mod_ShadowMesh_AddVertex(), mod_shutdown(), Mod_Skeletal_AnimateVertices_Generic(), Mod_Sprite_SharedSetup(), mod_start(), Mod_VBSP_LoadFaces(), Mod_ZYMOTICMODEL_Load(), MR_Init(), NetConn_BuildStatusResponse(), NetConn_ClientParsePacket(), NetConn_ReceivedMessage(), NetConn_SendUnreliableMessage(), NetConn_ServerParsePacket(), Nicks_CutMatchesAlphaNumeric(), Nicks_CutMatchesNormal(), Nicks_CutMatchesNoSpaces(), noise4f(), OGG_DecodeTags(), particletextureblotch(), PHYS_UnstickEntityReturnOffset(), PK3_BuildFileList(), PNG_fReadData(), PNG_LoadImage_BGRA(), PRVM_ConsoleCommand(), PRVM_ED_ParseEpair(), PRVM_LeakTest(), PRVM_PrintStatement(), PRVM_Prog_Load(), PRVM_UglyValueString(), R_Bloom_StartFrame(), R_BufferData_Store(), R_BuildFogTexture(), R_BuildLightMap(), R_CompleteLightPoint(), R_DrawParticles(), R_DrawTextureSurfaceList_ShowSurfaces(), R_GetCurrentTexture(), R_GLSL_Restart_f(), R_HDR_UpdateIrisAdaptation(), R_InitParticleTexture(), R_LoadTextureDDSFile(), R_Mesh_Draw(), R_Mesh_UpdateMeshBuffer(), R_RenderTarget_FreeUnused(), R_RenderTarget_Get(), R_RTLight_Compile(), R_ScissorForBBox(), R_Shadow_BounceGrid_AssignPhotons_Task(), R_Shadow_BounceGrid_CheckEnable(), R_Shadow_BounceGrid_ConvertPixelsAndUpload(), R_Shadow_BounceGrid_Slice(), R_Shadow_BounceGrid_UpdateSpacing(), R_Shadow_DrawCoronas(), R_Shadow_EditLights_DrawSelectedLightProperties(), R_Shadow_GetRTLightInfo(), R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(), R_Shadow_MakeTextures_MakeCorona(), R_StainNode(), R_tcMod_ApplyToMatrix(), r_textures_devicelost(), r_textures_devicerestored(), R_TimeReport(), R_TimeReport_EndFrame(), R_Water_StartFrame(), RSurf_FogPoint(), RSurf_FogVertex(), S_ConvertPaintBuffer(), S_MixToBuffer(), S_PaintAndSubmit(), S_PlaySfxOnChannel(), S_SoundList_f(), S_StartSound_StartPosition_Flags(), S_UnloadAllSounds_f(), Sbar_DeathmatchOverlay(), Sbar_Draw(), Sbar_DrawInventory(), Sbar_IntermissionOverlay(), Sbar_MiniDeathmatchOverlay(), Sbar_PrintScoreboardItem(), Sbar_Score(), Sbar_SoloScoreboard(), SCR_CaptureVideo_Avi_SoundFrame(), SCR_CaptureVideo_Ogg_BeginVideo(), SCR_CaptureVideo_RIFF_Pop(), SCR_Centerprint_f(), SCR_DrawCenterString(), SCR_DrawCurlDownload(), SCR_DrawInfobarString(), SCR_DrawQWDownload(), SCR_DrawScreen(), should_use_incmap(), snap_to_pixel_x(), snap_to_pixel_y(), SND_PickChannel(), SV_CleanupEnts(), SV_CreateBaseline(), SV_DisableCheats_c(), SV_Ent_Remove_f(), SV_FixCheckBottom(), SV_FlyMove(), SV_GenericHitSuperContentsMask(), SV_GetModelFromEdict(), SV_GetTagIndex(), SV_GetTagMatrix(), SV_Give_f(), SV_God_f(), SV_Kick_f(), SV_LinkEdict(), SV_Loadgame_f(), SV_movestep(), SV_Notarget_f(), SV_Physics_Step(), SV_Physics_Toss(), SV_Pings_f(), SV_PlayerPhysics(), SV_PointSuperContents(), SV_Prepare_CSQC(), SV_PrepareEntityForSending(), SV_PushEntity(), SV_PushMove(), SV_ReadClientMessage(), SV_Savegame_to(), SV_SaveSpawnparms(), SV_SendClientDatagram(), SV_SpawnServer(), SV_StartPointSound(), SV_StartSound(), SV_Status_f(), SV_Tell_f(), SV_TraceBox(), SV_TraceLine(), SV_TracePoint(), SV_UpdateToReliableMessages(), SV_Viewframe_f(), SV_Viewmodel_f(), SV_Viewnext_f(), SV_Viewprev_f(), SV_WalkMove(), SV_WaterJump(), SV_WriteClientdataToMessage(), SVBSP_InsertOccluderPolygonNodes(), Sys_Con_NearestColor(), u8_strpad(), u8_strpad_colorcodes(), V_CalcRefdefUsing(), VID_ApplyJoyState(), VM_altstr_get(), VM_altstr_ins(), VM_altstr_set(), VM_argv(), VM_argv_end_index(), VM_argv_start_index(), VM_buf_copy(), VM_buf_create(), VM_buf_sort(), VM_buf_writefile(), VM_bufstr_add(), VM_bufstr_find(), VM_bufstr_free(), VM_bufstr_get(), VM_bufstr_set(), VM_cin_getstate(), VM_CL_boxparticles(), VM_CL_droptofloor(), VM_CL_frameduration(), VM_CL_frameforname(), VM_CL_getinputstate(), VM_CL_getplayerkey(), VM_CL_getstatf(), VM_CL_getstati(), VM_CL_getstats(), VM_CL_gettaginfo(), VM_CL_lightstyle(), VM_CL_makestatic(), VM_CL_particle(), VM_CL_ParticleTheme(), VM_CL_ParticleThemeFree(), VM_CL_ParticleThemeFromGlobals(), VM_CL_ParticleThemeSave(), VM_CL_pointparticles(), VM_CL_R_AddDynamicLight(), VM_CL_R_AddEntities(), VM_CL_R_PolygonBegin(), VM_CL_R_SetView(), VM_CL_runplayerphysics(), VM_CL_setattachment(), VM_CL_setmodelindex(), VM_CL_skel_build(), VM_CL_skel_copybones(), VM_CL_skel_create(), VM_CL_skel_delete(), VM_CL_skel_find_bone(), VM_CL_skel_get_boneabs(), VM_CL_skel_get_bonename(), VM_CL_skel_get_boneparent(), VM_CL_skel_get_bonerel(), VM_CL_skel_get_numbones(), VM_CL_skel_mul_bone(), VM_CL_skel_mul_bones(), VM_CL_skel_set_bone(), VM_CL_sound(), VM_CL_SpawnParticle(), VM_CL_SpawnParticleDelayed(), VM_CL_te_explosion2(), VM_CL_tracebox(), VM_CL_traceline(), VM_CL_trailparticles(), VM_CL_V_CalcRefdef(), VM_drawcharacter(), VM_drawcolorcodedstring(), VM_drawfill(), VM_drawline(), VM_drawpic(), VM_drawrotpic(), VM_drawstring(), VM_drawsubpic(), VM_entityfieldname(), VM_entityfieldtype(), VM_fclose(), VM_fgets(), VM_fopen(), VM_fputs(), VM_FrameBlendFromFrameGroupBlend(), VM_GenerateFrameGroupBlend(), VM_getentityfieldstring(), VM_getsoundtime(), VM_getsurfacepoint(), VM_getsurfacepointattribute(), VM_getsurfacetriangle(), VM_gettime(), VM_M_getgamedirinfo(), VM_M_getresolution(), VM_M_getserverlistnumber(), VM_M_getserverliststat(), VM_M_getserverliststring(), VM_M_setserverlistmasknumber(), VM_M_setserverlistmaskstring(), VM_M_setserverlistsort(), VM_M_WriteDest(), VM_matchpattern(), VM_netaddress_resolve(), VM_putentityfieldstring(), VM_registercvar(), VM_search_begin(), VM_search_end(), VM_search_getfilename(), VM_search_getsize(), VM_sprint(), VM_sprintf(), VM_str2chr(), VM_strconv(), VM_stringwidth(), VM_strireplace(), VM_strlennocol(), VM_strpad(), VM_strreplace(), VM_strstrofs(), VM_substring(), VM_SV_AddStat(), VM_SV_droptofloor(), VM_SV_frameduration(), VM_SV_frameforname(), VM_SV_gettaginfo(), VM_SV_lightstyle(), VM_SV_modelnameforindex(), VM_SV_particle(), VM_SV_pointparticles(), VM_SV_pointsound(), VM_SV_setcolor(), VM_SV_setmodelindex(), VM_SV_setpause(), VM_SV_skel_build(), VM_SV_skel_copybones(), VM_SV_skel_create(), VM_SV_skel_delete(), VM_SV_skel_find_bone(), VM_SV_skel_get_boneabs(), VM_SV_skel_get_bonename(), VM_SV_skel_get_boneparent(), VM_SV_skel_get_bonerel(), VM_SV_skel_get_numbones(), VM_SV_skel_mul_bone(), VM_SV_skel_mul_bones(), VM_SV_skel_set_bone(), VM_SV_sound(), VM_SV_tracebox(), VM_SV_traceline(), VM_SV_UpdateCustomStats(), VM_tokenizebyseparator(), VM_UpdateEdictSkeleton(), VM_vectoyaw(), W_GetTextureBGRA(), World_EntitiesInBox(), World_LinkEdict_AreaGrid(), WriteDest(), and XMP_GetSamplesFloat().

◆ PK3_BuildFileList()

static int PK3_BuildFileList ( pack_t * pack,
const pk3_endOfCentralDir_t * eocd )
static

Definition at line 712 of file fs.c.

713{
714 unsigned char *central_dir, *ptr;
715 unsigned int ind;
716 fs_offset_t remaining;
717
718 // Load the central directory in memory
719 central_dir = (unsigned char *)Mem_Alloc (tempmempool, eocd->cdir_size);
720 if (FILEDESC_SEEK (pack->handle, eocd->cdir_offset, SEEK_SET) == -1)
721 {
722 Mem_Free (central_dir);
723 return -1;
724 }
725 if(FILEDESC_READ (pack->handle, central_dir, eocd->cdir_size) != (fs_offset_t) eocd->cdir_size)
726 {
727 Mem_Free (central_dir);
728 return -1;
729 }
730
731 // Extract the files properties
732 // The parsing is done "by hand" because some fields have variable sizes and
733 // the constant part isn't 4-bytes aligned, which makes the use of structs difficult
734 remaining = eocd->cdir_size;
735 pack->numfiles = 0;
736 ptr = central_dir;
737 for (ind = 0; ind < eocd->nbentries; ind++)
738 {
739 fs_offset_t namesize, count;
740
741 // Checking the remaining size
742 if (remaining < ZIP_CDIR_CHUNK_BASE_SIZE)
743 {
744 Mem_Free (central_dir);
745 return -1;
746 }
747 remaining -= ZIP_CDIR_CHUNK_BASE_SIZE;
748
749 // Check header
750 if (BuffBigLong (ptr) != ZIP_CDIR_HEADER)
751 {
752 Mem_Free (central_dir);
753 return -1;
754 }
755
756 namesize = (unsigned short)BuffLittleShort (&ptr[28]); // filename length
757
758 // Check encryption, compression, and attributes
759 // 1st uint8 : general purpose bit flag
760 // Check bits 0 (encryption), 3 (data descriptor after the file), and 5 (compressed patched data (?))
761 //
762 // LadyHavoc: bit 3 would be a problem if we were scanning the archive
763 // but is not a problem in the central directory where the values are
764 // always real.
765 //
766 // bit 3 seems to always be set by the standard Mac OSX zip maker
767 //
768 // 2nd uint8 : external file attributes
769 // Check bits 3 (file is a directory) and 5 (file is a volume (?))
770 if ((ptr[8] & 0x21) == 0 && (ptr[38] & 0x18) == 0)
771 {
772 // Still enough bytes for the name?
773 if (remaining < namesize || namesize >= (int)sizeof (*pack->files))
774 {
775 Mem_Free (central_dir);
776 return -1;
777 }
778
779 // WinZip doesn't use the "directory" attribute, so we need to check the name directly
780 if (ptr[ZIP_CDIR_CHUNK_BASE_SIZE + namesize - 1] != '/')
781 {
782 char filename [sizeof (pack->files[0].name)];
783 fs_offset_t offset, packsize, realsize;
784 int flags;
785
786 // Extract the name (strip it if necessary)
787 namesize = min(namesize, (int)sizeof (filename) - 1);
788 memcpy (filename, &ptr[ZIP_CDIR_CHUNK_BASE_SIZE], namesize);
789 filename[namesize] = '\0';
790
791 if (BuffLittleShort (&ptr[10]))
793 else
794 flags = 0;
795 offset = (unsigned int)(BuffLittleLong (&ptr[42]) + eocd->prepended_garbage);
796 packsize = (unsigned int)BuffLittleLong (&ptr[20]);
797 realsize = (unsigned int)BuffLittleLong (&ptr[24]);
798
799 switch(ptr[5]) // C_VERSION_MADE_BY_1
800 {
801 case 3: // UNIX_
802 case 2: // VMS_
803 case 16: // BEOS_
804 if((BuffLittleShort(&ptr[40]) & 0120000) == 0120000)
805 // can't use S_ISLNK here, as this has to compile on non-UNIX too
807 break;
808 }
809
810 FS_AddFileToPack (filename, pack, offset, packsize, realsize, flags);
811 }
812 }
813
814 // Skip the name, additionnal field, and comment
815 // 1er uint16 : extra field length
816 // 2eme uint16 : file comment length
817 count = namesize + (unsigned short)BuffLittleShort (&ptr[30]) + (unsigned short)BuffLittleShort (&ptr[32]);
819 remaining -= count;
820 }
821
822 // If the package is empty, central_dir is NULL here
823 if (central_dir != NULL)
824 Mem_Free (central_dir);
825 return pack->numfiles;
826}
short BuffLittleShort(const unsigned char *buffer)
Extract a little endian 16bit short from the given buffer.
Definition com_msg.c:76
int BuffLittleLong(const unsigned char *buffer)
Extract a little endian 32bit int from the given buffer.
Definition com_msg.c:71
int BuffBigLong(const unsigned char *buffer)
Extract a big endian 32bit int from the given buffer.
Definition com_msg.c:49
#define ZIP_CDIR_HEADER
Definition fs.c:208
#define ZIP_CDIR_CHUNK_BASE_SIZE
Definition fs.c:214
fs_offset_t prepended_garbage
Definition fs.c:347
unsigned int cdir_offset
with respect to the starting disk number
Definition fs.c:345
unsigned int cdir_size
size of the central directory
Definition fs.c:344

References BuffBigLong(), BuffLittleLong(), BuffLittleShort(), pk3_endOfCentralDir_t::cdir_offset, pk3_endOfCentralDir_t::cdir_size, count, FILEDESC_READ, FILEDESC_SEEK, pack_t::files, flags, FS_AddFileToPack(), pack_t::handle, int(), Mem_Alloc, Mem_Free, min, packfile_t::name, pk3_endOfCentralDir_t::nbentries, NULL, pack_t::numfiles, offset, PACKFILE_FLAG_DEFLATED, PACKFILE_FLAG_SYMLINK, pk3_endOfCentralDir_t::prepended_garbage, tempmempool, ZIP_CDIR_CHUNK_BASE_SIZE, and ZIP_CDIR_HEADER.

Referenced by FS_LoadPackPK3FromFD().

◆ PK3_CloseLibrary()

static void PK3_CloseLibrary ( void )
static

Definition at line 566 of file fs.c.

567{
568#ifndef LINK_TO_ZLIB
570#endif
571}

References Sys_FreeLibrary(), and zlib_dll.

Referenced by FS_Shutdown().

◆ PK3_GetEndOfCentralDir()

static qbool PK3_GetEndOfCentralDir ( const char * packfile,
filedesc_t packhandle,
pk3_endOfCentralDir_t * eocd )
static

Definition at line 637 of file fs.c.

638{
639 fs_offset_t filesize, maxsize;
640 unsigned char *buffer, *ptr;
641 int ind;
642
643 // Get the package size
644 filesize = FILEDESC_SEEK (packhandle, 0, SEEK_END);
645 if (filesize < ZIP_END_CDIR_SIZE)
646 return false;
647
648 // Load the end of the file in memory
650 maxsize = filesize;
651 else
653 buffer = (unsigned char *)Mem_Alloc (tempmempool, maxsize);
654 FILEDESC_SEEK (packhandle, filesize - maxsize, SEEK_SET);
655 if (FILEDESC_READ (packhandle, buffer, maxsize) != (fs_offset_t) maxsize)
656 {
658 return false;
659 }
660
661 // Look for the end of central dir signature around the end of the file
662 maxsize -= ZIP_END_CDIR_SIZE;
663 ptr = &buffer[maxsize];
664 ind = 0;
665 while (BuffBigLong (ptr) != ZIP_END_HEADER)
666 {
667 if (ind == maxsize)
668 {
670 return false;
671 }
672
673 ind++;
674 ptr--;
675 }
676
677 memcpy (eocd, ptr, ZIP_END_CDIR_SIZE);
678 eocd->signature = LittleLong (eocd->signature);
679 eocd->disknum = LittleShort (eocd->disknum);
680 eocd->cdir_disknum = LittleShort (eocd->cdir_disknum);
681 eocd->localentries = LittleShort (eocd->localentries);
682 eocd->nbentries = LittleShort (eocd->nbentries);
683 eocd->cdir_size = LittleLong (eocd->cdir_size);
684 eocd->cdir_offset = LittleLong (eocd->cdir_offset);
685 eocd->comment_size = LittleShort (eocd->comment_size);
686 eocd->prepended_garbage = filesize - (ind + ZIP_END_CDIR_SIZE) - eocd->cdir_offset - eocd->cdir_size; // this detects "SFX" zip files
687 eocd->cdir_offset += eocd->prepended_garbage;
688
690
691 if (
692 eocd->cdir_size > filesize ||
693 eocd->cdir_offset >= filesize ||
694 eocd->cdir_offset + eocd->cdir_size > filesize
695 )
696 {
697 // Obviously invalid central directory.
698 return false;
699 }
700
701 return true;
702}
#define LittleShort(l)
Definition common.h:90
#define ZIP_MAX_COMMENTS_SIZE
Definition fs.c:212
#define ZIP_END_HEADER
Definition fs.c:209
#define ZIP_END_CDIR_SIZE
Definition fs.c:213
unsigned int signature
Definition fs.c:339
unsigned short comment_size
Definition fs.c:346
unsigned short localentries
number of entries in the central directory on this disk
Definition fs.c:342

References BuffBigLong(), buffer, pk3_endOfCentralDir_t::cdir_disknum, pk3_endOfCentralDir_t::cdir_offset, pk3_endOfCentralDir_t::cdir_size, pk3_endOfCentralDir_t::comment_size, pk3_endOfCentralDir_t::disknum, FILEDESC_READ, FILEDESC_SEEK, LittleLong, LittleShort, pk3_endOfCentralDir_t::localentries, Mem_Alloc, Mem_Free, pk3_endOfCentralDir_t::nbentries, pk3_endOfCentralDir_t::prepended_garbage, pk3_endOfCentralDir_t::signature, tempmempool, ZIP_END_CDIR_SIZE, ZIP_END_HEADER, and ZIP_MAX_COMMENTS_SIZE.

Referenced by FS_LoadPackPK3FromFD().

◆ PK3_GetTrueFileOffset()

static qbool PK3_GetTrueFileOffset ( packfile_t * pfile,
pack_t * pack )
static

Definition at line 908 of file fs.c.

909{
910 unsigned char buffer [ZIP_LOCAL_CHUNK_BASE_SIZE];
912
913 // Already found?
914 if (pfile->flags & PACKFILE_FLAG_TRUEOFFS)
915 return true;
916
917 // Load the local file description
918 if (FILEDESC_SEEK (pack->handle, pfile->offset, SEEK_SET) == -1)
919 {
920 Con_Printf ("Can't seek in package %s\n", pack->filename);
921 return false;
922 }
925 {
926 Con_Printf ("Can't retrieve file %s in package %s\n", pfile->name, pack->filename);
927 return false;
928 }
929
930 // Skip name and extra field
932
934 return true;
935}
#define ZIP_DATA_HEADER
Definition fs.c:207
#define ZIP_LOCAL_CHUNK_BASE_SIZE
Definition fs.c:215

References BuffBigLong(), buffer, BuffLittleShort(), Con_Printf(), count, FILEDESC_READ, FILEDESC_SEEK, pack_t::filename, packfile_t::flags, pack_t::handle, packfile_t::name, packfile_t::offset, PACKFILE_FLAG_TRUEOFFS, ZIP_DATA_HEADER, and ZIP_LOCAL_CHUNK_BASE_SIZE.

Referenced by FS_OpenPackedFile().

◆ PK3_OpenLibrary()

static qbool PK3_OpenLibrary ( void )
static

Definition at line 581 of file fs.c.

582{
583#ifdef LINK_TO_ZLIB
584 return true;
585#else
586 const char* dllnames [] =
587 {
588#if defined(WIN32)
589# ifdef ZLIB_USES_WINAPI
590 "zlibwapi.dll",
591 "zlib.dll",
592# else
593 "zlib1.dll",
594# endif
595#elif defined(MACOSX)
596 "libz.dylib",
597#else
598 "libz.so.1",
599 "libz.so",
600#endif
601 NULL
602 };
603
604 // Already loaded?
605 if (zlib_dll)
606 return true;
607
608 // Load the DLL
609 return Sys_LoadDependency (dllnames, &zlib_dll, zlibfuncs);
610#endif
611}
static dllfunction_t zlibfuncs[]
Definition fs.c:494

References NULL, Sys_LoadDependency(), zlib_dll, and zlibfuncs.

Referenced by FS_HasZlib(), and FS_Init().

◆ ReadAll()

static fs_offset_t ReadAll ( const filedesc_t fd,
void *const buf,
const size_t length )
static

Definition at line 135 of file fs.c.

136{
137 char *const p = (char *)buf;
138 size_t cursor = 0;
139 do
140 {
141 const fs_offset_t result = FILEDESC_READ(fd, p + cursor, length - cursor);
142 if (result < 0) // Error
143 return result;
144 if (result == 0) // EOF
145 break;
146 cursor += result;
147 } while (cursor < length);
148 return cursor;
149}

References buf, FILEDESC_READ, and length.

◆ WriteAll()

static fs_offset_t WriteAll ( const filedesc_t fd,
const void *const buf,
const size_t length )
static

Definition at line 159 of file fs.c.

160{
161 const char *const p = (const char *)buf;
162 size_t cursor = 0;
163 do
164 {
165 const fs_offset_t result = FILEDESC_WRITE(fd, p + cursor, length - cursor);
166 if (result < 0) // Error
167 return result;
168 cursor += result;
169 } while (cursor < length);
170 return cursor;
171}

References buf, FILEDESC_WRITE, and length.

Variable Documentation

◆ con_linewidth

int con_linewidth
extern

Definition at line 94 of file console.c.

Referenced by FS_ListDirectory().

◆ cvar_fs_gamedir

cvar_t cvar_fs_gamedir = {CF_CLIENT | CF_SERVER | CF_READONLY | CF_PERSISTENT, "fs_gamedir", "", "the list of currently selected gamedirs (use the 'gamedir' command to change this)"}

Definition at line 458 of file fs.c.

458{CF_CLIENT | CF_SERVER | CF_READONLY | CF_PERSISTENT, "fs_gamedir", "", "the list of currently selected gamedirs (use the 'gamedir' command to change this)"};
#define CF_READONLY
cvar cannot be changed from the console or the command buffer, and is considered CF_PERSISTENT
Definition cmd.h:54
#define CF_PERSISTENT
cvar must not be reset on gametype switch (such as scr_screenshot_name, which otherwise isn't set to ...
Definition cmd.h:58
#define CF_SERVER
cvar/command that only the server can change/execute
Definition cmd.h:49
#define CF_CLIENT
cvar/command that only the client can change/execute
Definition cmd.h:48

Referenced by FS_Init_Commands(), and FS_Rescan().

◆ flush

static int flush

Definition at line 477 of file fs.c.

◆ fs_all_gamedirs

gamedir_t* fs_all_gamedirs = NULL

Definition at line 452 of file fs.c.

Referenced by FS_ListGameDirs(), and VM_M_getgamedirinfo().

◆ fs_all_gamedirs_count

int fs_all_gamedirs_count = 0

Definition at line 453 of file fs.c.

Referenced by FS_ListGameDirs(), and VM_M_getgamedirinfo().

◆ fs_basedir

◆ fs_checkgamedir_missing

const char* const fs_checkgamedir_missing = "missing"

Definition at line 438 of file fs.c.

Referenced by FS_CheckGameDir(), FS_ListGameDirs(), FS_SetGameDirs(), and ModList_RebuildList().

◆ fs_empty_files_in_pack_mark_deletions

cvar_t fs_empty_files_in_pack_mark_deletions = {CF_CLIENT | CF_SERVER, "fs_empty_files_in_pack_mark_deletions", "0", "if enabled, empty files in a pak/pk3 count as not existing but cancel the search in further packs, effectively allowing patch pak/pk3 files to 'delete' files"}

Definition at line 456 of file fs.c.

456{CF_CLIENT | CF_SERVER, "fs_empty_files_in_pack_mark_deletions", "0", "if enabled, empty files in a pak/pk3 count as not existing but cancel the search in further packs, effectively allowing patch pak/pk3 files to 'delete' files"};

Referenced by FS_FindFile(), and FS_Init_Commands().

◆ fs_gamedir

char fs_gamedir[MAX_OSPATH]

Definition at line 443 of file fs.c.

Referenced by FS_AddGameDirectory(), FS_Init_Dir(), FS_OpenRealFile(), FS_Rescan(), and SCR_ScreenShot_f().

◆ fs_gamedirs

◆ fs_mempool

◆ fs_mutex

void* fs_mutex = NULL

Definition at line 435 of file fs.c.

Referenced by FS_Init_Dir(), FS_OpenVirtualFile(), and FS_Shutdown().

◆ fs_numgamedirs

int fs_numgamedirs = 0

◆ fs_searchpaths

◆ fs_selfpack

pack_t* fs_selfpack = NULL
static

Definition at line 445 of file fs.c.

Referenced by FS_AddSelfPack(), FS_ClearSearchPath(), and FS_Init_SelfPack().

◆ fs_unload_dlcache

cvar_t fs_unload_dlcache = {CF_CLIENT, "fs_unload_dlcache", "1", "if enabled, unload dlcache's loaded pak/pk3 files when changing server and/or map WARNING: disabling unloading can cause servers to override assets of other servers, \"memory leaking\" by dlcache assets never unloading and many more issues"}

Definition at line 457 of file fs.c.

457{CF_CLIENT, "fs_unload_dlcache", "1", "if enabled, unload dlcache's loaded pak/pk3 files when changing server and/or map WARNING: disabling unloading can cause servers to override assets of other servers, \"memory leaking\" by dlcache assets never unloading and many more issues"};

Referenced by FS_Init_Commands(), and FS_UnloadPacks_dlcache().

◆ fs_userdir

◆ level

GLint level

Definition at line 481 of file fs.c.

Referenced by FS_Deflate(), and libavw_message().

◆ memLevel

int int int int memLevel

Definition at line 481 of file fs.c.

◆ method

int int method

Definition at line 481 of file fs.c.

◆ scr_screenshot_name

cvar_t scr_screenshot_name = {CF_CLIENT | CF_PERSISTENT, "scr_screenshot_name","dp", "prefix name for saved screenshots (changes based on -game commandline, as well as which game mode is running; the date is encoded using strftime escapes)"}

Definition at line 455 of file fs.c.

455{CF_CLIENT | CF_PERSISTENT, "scr_screenshot_name","dp", "prefix name for saved screenshots (changes based on -game commandline, as well as which game mode is running; the date is encoded using strftime escapes)"};

Referenced by FS_Init_Commands(), FS_Rescan(), and SCR_ScreenShot_f().

◆ strategy

int int int int int strategy

Definition at line 481 of file fs.c.

◆ stream_size

static int int int int int const char int stream_size

Definition at line 479 of file fs.c.

◆ version

◆ windowBits

static int int int windowBits

Definition at line 479 of file fs.c.

◆ zlib_dll

dllhandle_t zlib_dll = NULL
static

Handle for Zlib DLL.

Definition at line 507 of file fs.c.

Referenced by FS_Deflate(), FS_HasZlib(), FS_Inflate(), FS_OpenPackedFile(), PK3_CloseLibrary(), and PK3_OpenLibrary().

◆ zlibfuncs

dllfunction_t zlibfuncs[]
static
Initial value:
=
{
{"inflate", (void **) &qz_inflate},
{"inflateEnd", (void **) &qz_inflateEnd},
{"inflateInit2_", (void **) &qz_inflateInit2_},
{"inflateReset", (void **) &qz_inflateReset},
{"deflateInit2_", (void **) &qz_deflateInit2_},
{"deflateEnd", (void **) &qz_deflateEnd},
{"deflate", (void **) &qz_deflate},
}

Definition at line 494 of file fs.c.

495{
496 {"inflate", (void **) &qz_inflate},
497 {"inflateEnd", (void **) &qz_inflateEnd},
498 {"inflateInit2_", (void **) &qz_inflateInit2_},
499 {"inflateReset", (void **) &qz_inflateReset},
500 {"deflateInit2_", (void **) &qz_deflateInit2_},
501 {"deflateEnd", (void **) &qz_deflateEnd},
502 {"deflate", (void **) &qz_deflate},
503 {NULL, NULL}
504};

Referenced by PK3_OpenLibrary().