command = Cmd_Argv (1);
- if (Q_strcasecmp(command, "on") == 0)
+ if (strcasecmp(command, "on") == 0)
{
enabled = true;
return;
}
- if (Q_strcasecmp(command, "off") == 0)
+ if (strcasecmp(command, "off") == 0)
{
if (playing)
CDAudio_Stop();
return;
}
- if (Q_strcasecmp(command, "reset") == 0)
+ if (strcasecmp(command, "reset") == 0)
{
enabled = true;
if (playing)
return;
}
- if (Q_strcasecmp(command, "remap") == 0)
+ if (strcasecmp(command, "remap") == 0)
{
ret = Cmd_Argc() - 2;
if (ret <= 0)
return;
}
- if (Q_strcasecmp(command, "close") == 0)
+ if (strcasecmp(command, "close") == 0)
{
CDAudio_CloseDoor();
return;
}
}
- if (Q_strcasecmp(command, "play") == 0)
+ if (strcasecmp(command, "play") == 0)
{
CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false);
return;
}
- if (Q_strcasecmp(command, "loop") == 0)
+ if (strcasecmp(command, "loop") == 0)
{
CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true);
return;
}
- if (Q_strcasecmp(command, "stop") == 0)
+ if (strcasecmp(command, "stop") == 0)
{
CDAudio_Stop();
return;
}
- if (Q_strcasecmp(command, "pause") == 0)
+ if (strcasecmp(command, "pause") == 0)
{
CDAudio_Pause();
return;
}
- if (Q_strcasecmp(command, "resume") == 0)
+ if (strcasecmp(command, "resume") == 0)
{
CDAudio_Resume();
return;
}
- if (Q_strcasecmp(command, "eject") == 0)
+ if (strcasecmp(command, "eject") == 0)
{
if (playing)
CDAudio_Stop();
return;
}
- if (Q_strcasecmp(command, "info") == 0)
+ if (strcasecmp(command, "info") == 0)
{
Con_Printf("%u tracks\n", maxTrack);
if (playing)
command = Cmd_Argv (1);
- if (Q_strcasecmp(command, "on") == 0)
+ if (strcasecmp(command, "on") == 0)
{
enabled = true;
return;
}
- if (Q_strcasecmp(command, "off") == 0)
+ if (strcasecmp(command, "off") == 0)
{
if (playing)
CDAudio_Stop();
return;
}
- if (Q_strcasecmp(command, "reset") == 0)
+ if (strcasecmp(command, "reset") == 0)
{
enabled = true;
if (playing)
return;
}
- if (Q_strcasecmp(command, "remap") == 0)
+ if (strcasecmp(command, "remap") == 0)
{
ret = Cmd_Argc() - 2;
if (ret <= 0)
return;
}
- if (Q_strcasecmp(command, "close") == 0)
+ if (strcasecmp(command, "close") == 0)
{
CDAudio_CloseDoor();
return;
}
}
- if (Q_strcasecmp(command, "play") == 0)
+ if (strcasecmp(command, "play") == 0)
{
CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false);
return;
}
- if (Q_strcasecmp(command, "loop") == 0)
+ if (strcasecmp(command, "loop") == 0)
{
CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true);
return;
}
- if (Q_strcasecmp(command, "stop") == 0)
+ if (strcasecmp(command, "stop") == 0)
{
CDAudio_Stop();
return;
}
- if (Q_strcasecmp(command, "pause") == 0)
+ if (strcasecmp(command, "pause") == 0)
{
CDAudio_Pause();
return;
}
- if (Q_strcasecmp(command, "resume") == 0)
+ if (strcasecmp(command, "resume") == 0)
{
CDAudio_Resume();
return;
}
- if (Q_strcasecmp(command, "eject") == 0)
+ if (strcasecmp(command, "eject") == 0)
{
if (playing)
CDAudio_Stop();
return;
}
- if (Q_strcasecmp(command, "info") == 0)
+ if (strcasecmp(command, "info") == 0)
{
Con_Printf("%u tracks\n", maxTrack);
if (playing)
if (!cls.demoplayback)
return;
- Qclose (cls.demofile);
+ FS_Close (cls.demofile);
cls.demoplayback = false;
cls.demofile = NULL;
return;
len = LittleLong (net_message.cursize);
- Qwrite (cls.demofile, &len, 4);
+ FS_Write (cls.demofile, &len, 4);
for (i=0 ; i<3 ; i++)
{
f = LittleFloat (cl.viewangles[i]);
- Qwrite (cls.demofile, &f, 4);
+ FS_Write (cls.demofile, &f, 4);
}
- Qwrite (cls.demofile, net_message.data, net_message.cursize);
- Qflush (cls.demofile);
+ FS_Write (cls.demofile, net_message.data, net_message.cursize);
+ FS_Flush (cls.demofile);
}
/*
}
// get the next message
- Qread (cls.demofile, &net_message.cursize, 4);
+ FS_Read (cls.demofile, &net_message.cursize, 4);
VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
for (i=0 ; i<3 ; i++)
{
- r = Qread (cls.demofile, &f, 4);
+ r = FS_Read (cls.demofile, &f, 4);
cl.mviewangles[0][i] = LittleFloat (f);
}
net_message.cursize = LittleLong (net_message.cursize);
if (net_message.cursize > MAX_DATAGRAM)
Host_Error ("Demo message > MAX_DATAGRAM");
- r = Qread (cls.demofile, net_message.data, net_message.cursize);
+ r = FS_Read (cls.demofile, net_message.data, net_message.cursize);
if (r != net_message.cursize)
{
CL_Disconnect ();
CL_WriteDemoMessage ();
// finish up
- Qclose (cls.demofile);
+ FS_Close (cls.demofile);
cls.demofile = NULL;
cls.demorecording = false;
Con_Printf ("Completed demo\n");
return;
}
-// write the forced cd track number, or -1
+ // write the forced cd track number, or -1
if (c == 4)
{
track = atoi(Cmd_Argv(3));
}
else
track = -1;
-
- sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
-//
-// start the map up
-//
+ // start the map up
if (c > 2)
Cmd_ExecuteString ( va("map %s", Cmd_Argv(2)), src_command);
-//
-// open the demo file
-//
- COM_DefaultExtension (name, ".dem");
+ // open the demo file
+ strncpy (name, Cmd_Argv(1), sizeof (name) - 1);
+ name[sizeof (name) - 1] = '\0';
+ FS_DefaultExtension (name, ".dem");
Con_Printf ("recording to %s.\n", name);
- cls.demofile = Qopen (name, "wb");
+ cls.demofile = FS_Open (name, "wb", false);
if (!cls.demofile)
{
Con_Printf ("ERROR: couldn't open.\n");
}
cls.forcetrack = track;
- Qprintf (cls.demofile, "%i\n", cls.forcetrack);
+ FS_Printf (cls.demofile, "%i\n", cls.forcetrack);
cls.demorecording = true;
}
return;
}
-//
-// disconnect from server
-//
+ // disconnect from server
CL_Disconnect ();
-//
-// open the demo file
-//
+ // open the demo file
strcpy (name, Cmd_Argv(1));
- COM_DefaultExtension (name, ".dem");
+ FS_DefaultExtension (name, ".dem");
Con_Printf ("Playing demo from %s.\n", name);
- COM_FOpenFile (name, &cls.demofile, false, true);
+ cls.demofile = FS_Open (name, "rb", false);
if (!cls.demofile)
{
Con_Printf ("ERROR: couldn't open.\n");
cls.state = ca_connected;
cls.forcetrack = 0;
- while ((c = Qgetc(cls.demofile)) != '\n')
+ while ((c = FS_Getc (cls.demofile)) != '\n')
if (c == '-')
neg = true;
else
fclose(f);
}
#else
- pointfile = COM_LoadFile(va("maps/%s.pts", cl.worldmodel->name), true);
+ pointfile = FS_LoadFile(va("maps/%s.pts", cl.worldmodel->name), true);
#endif
if (!pointfile)
{
// HACK HACK HACK
// load the image data for the player image in the config menu
- dat = (qpic_t *)COM_LoadFile ("gfx/menuplyr.lmp", false);
+ dat = (qpic_t *)FS_LoadFile ("gfx/menuplyr.lmp", false);
if (!dat)
Sys_Error("unable to load gfx/menuplyr.lmp");
SwapPic (dat);
for (; i<=9999 ; i++)
{
sprintf (filename, "dp%04i.tga", i);
- sprintf (checkname, "%s/%s", com_gamedir, filename);
- if (Sys_FileTime(checkname) == -1)
- break; // file doesn't exist
+ sprintf (checkname, "%s/%s", fs_gamedir, filename);
+ if (!FS_SysFileExists(checkname))
+ break;
}
if (i==10000)
{
return;
}
- sprintf(name, "%s/video/%s.dpv", com_gamedir, Cmd_Argv(1));
+ sprintf(name, "%s/video/%s.dpv", fs_gamedir, Cmd_Argv(1));
CL_VideoStart(name);
}
qboolean timedemo;
// -1 = use normal cd track
int forcetrack;
- QFile *demofile;
+ qfile_t *demofile;
// to meter out one message a frame
int td_lastframe;
// host_framecount at start
return;
}
- f = (char *)COM_LoadFile (Cmd_Argv(1), false);
+ f = (char *)FS_LoadFile (Cmd_Argv(1), false);
if (!f)
{
Con_Printf ("couldn't exec %s\n",Cmd_Argv(1));
// check functions
for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
{
- if (!Q_strcasecmp (cmd_argv[0],cmd->name))
+ if (!strcasecmp (cmd_argv[0],cmd->name))
{
cmd->function ();
return;
// check alias
for (a=cmd_alias ; a ; a=a->next)
{
- if (!Q_strcasecmp (cmd_argv[0], a->name))
+ if (!strcasecmp (cmd_argv[0], a->name))
{
Cbuf_InsertText (a->value);
return;
return; // not really connected
MSG_WriteByte (&cls.message, clc_stringcmd);
- if (Q_strcasecmp(Cmd_Argv(0), "cmd") != 0)
+ if (strcasecmp(Cmd_Argv(0), "cmd") != 0)
{
SZ_Print (&cls.message, Cmd_Argv(0));
SZ_Print (&cls.message, " ");
Sys_Error ("Cmd_CheckParm: NULL");
for (i = 1; i < Cmd_Argc (); i++)
- if (!Q_strcasecmp (parm, Cmd_Argv (i)))
+ if (!strcasecmp (parm, Cmd_Argv (i)))
return i;
return 0;
#include <stdlib.h>
#include <fcntl.h>
-#ifdef WIN32
-#include <io.h>
-#else
+#ifndef WIN32
#include <unistd.h>
#endif
cvar_t registered = {0, "registered","0"};
cvar_t cmdline = {0, "cmdline","0"};
-mempool_t *pak_mempool;
-
-qboolean com_modified; // set true if using non-id files
-
-void COM_InitFilesystem (void);
+extern qboolean fs_modified; // set true if using non-id files
char com_token[1024];
-char com_basedir[MAX_OSPATH];
int com_argc;
const char **com_argv;
char *gamedirname;
char com_modname[MAX_OSPATH];
-/*
-
-
-All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources.
-
-The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory is
-only used during filesystem initialization.
-
-The "game directory" is the first tree on the search path and directory that all generated files (savegames, screenshots, demos, config files) will be saved to. This can be overridden with the "-game" command line parameter. The game directory can never be changed while quake is executing. This is a precacution against having a malicious server instruct clients to write files over areas they shouldn't.
-
-The "cache directory" is only used during development to save network bandwidth, especially over ISDN / T1 lines. If there is a cache directory
-specified, when a file is found by the normal search path, it will be mirrored
-into the cache directory, then opened there.
-
-
-
-FIXME:
-The file "parms.txt" will be read out of the game directory and appended to the current command line arguments to allow different games to initialize startup parms differently. This could be used to add a "-sspeed 22050" for the high quality sound edition. Because they are added at the end, they will not override an explicit setting on the original command line.
-
-*/
-
-//============================================================================
-
-
-/*
-============================================================================
-
- LIBRARY REPLACEMENT FUNCTIONS
-
-============================================================================
-*/
-
-int Q_strncasecmp (const char *s1, const char *s2, int n)
-{
- int c1, c2;
-
- while (1)
- {
- c1 = *s1++;
- c2 = *s2++;
-
- if (!n--)
- return 0; // strings are equal until end point
-
- if (c1 != c2)
- {
- if (c1 >= 'a' && c1 <= 'z')
- c1 -= ('a' - 'A');
- if (c2 >= 'a' && c2 <= 'z')
- c2 -= ('a' - 'A');
- if (c1 != c2)
- return -1; // strings not equal
- }
- if (!c1)
- return 0; // strings are equal
- }
-
- return -1;
-}
-
-int Q_strcasecmp (const char *s1, const char *s2)
-{
- return Q_strncasecmp (s1, s2, 99999);
-}
/*
============================================================================
//============================================================================
-/*
-============
-COM_StripExtension
-============
-*/
-// LordHavoc: replacement for severely broken COM_StripExtension that was used in original quake.
-void COM_StripExtension (const char *in, char *out)
-{
- char *last = NULL;
- while (*in)
- {
- if (*in == '.')
- last = out;
- else if (*in == '/' || *in == '\\' || *in == ':')
- last = NULL;
- *out++ = *in++;
- }
- if (last)
- *last = 0;
- else
- *out = 0;
-}
-
-/*
-============
-COM_FileExtension
-============
-*/
-char *COM_FileExtension (const char *in)
-{
- static char exten[8];
- int i;
-
- while (*in && *in != '.')
- in++;
- if (!*in)
- return "";
- in++;
- for (i=0 ; i<7 && *in ; i++,in++)
- exten[i] = *in;
- exten[i] = 0;
- return exten;
-}
-
-/*
-============
-COM_FileBase
-============
-*/
-void COM_FileBase (const char *in, char *out)
-{
- const char *slash, *dot, *s;
-
- slash = in;
- dot = NULL;
- s = in;
- while(*s)
- {
- if (*s == '/')
- slash = s + 1;
- if (*s == '.')
- dot = s;
- s++;
- }
- if (dot == NULL)
- dot = s;
- if (dot - slash < 2)
- strcpy (out,"?model?");
- else
- {
- while (slash < dot)
- *out++ = *slash++;
- *out++ = 0;
- }
-}
-
-
-/*
-==================
-COM_DefaultExtension
-==================
-*/
-void COM_DefaultExtension (char *path, const char *extension)
-{
- const char *src;
-//
-// if path doesn't have a .EXT, append extension
-// (extension should include the .)
-//
- src = path + strlen(path) - 1;
-
- while (*src != '/' && src != path)
- {
- if (*src == '.')
- return; // it has an extension
- src--;
- }
-
- strcat (path, extension);
-}
-
-
/*
==============
COM_ParseToken
{
Cvar_Set ("cmdline", com_cmdline);
- if (!Sys_FileTime("gfx/pop.lmp"))
+ if (!FS_FileExists("gfx/pop.lmp"))
{
- if (com_modified)
+ if (fs_modified)
Con_Printf ("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n");
else
Con_Printf ("Playing shareware version.\n");
}
-void COM_Path_f (void);
-
-
/*
================
COM_InitArgv
void COM_InitGameType (void)
{
char name[MAX_OSPATH];
- COM_StripExtension(com_argv[0], name);
+ FS_StripExtension(com_argv[0], name);
COM_ToLowerString(name, name);
if (strstr(name, "transfusion"))
extern void Mathlib_Init(void);
+extern void FS_Init (void);
/*
================
}
#endif
- pak_mempool = Mem_AllocPool("paks");
-
Cvar_RegisterVariable (®istered);
Cvar_RegisterVariable (&cmdline);
- Cmd_AddCommand ("path", COM_Path_f);
Mathlib_Init();
- COM_InitFilesystem ();
+ FS_Init ();
COM_CheckRegistered ();
COM_InitGameType();
}
-/*
-=============================================================================
-
-QUAKE FILESYSTEM
-
-=============================================================================
-*/
-
-int com_filesize;
-
-
-//
-// in memory
-//
-
-typedef struct
-{
- char name[MAX_QPATH];
- int filepos, filelen;
-} packfile_t;
-
-typedef struct pack_s
-{
- char filename[MAX_OSPATH];
- int handle;
- int numfiles;
- packfile_t *files;
- mempool_t *mempool;
- struct pack_s *next;
-} pack_t;
-
-//
-// on disk
-//
-typedef struct
-{
- char name[56];
- int filepos, filelen;
-} dpackfile_t;
-
-typedef struct
-{
- char id[4];
- int dirofs;
- int dirlen;
-} dpackheader_t;
-
-// LordHavoc: was 2048, increased to 65536 and changed info[MAX_PACK_FILES] to a temporary alloc
-#define MAX_FILES_IN_PACK 65536
-
-pack_t *packlist = NULL;
-
-#if CACHEENABLE
-char com_cachedir[MAX_OSPATH];
-#endif
-char com_gamedir[MAX_OSPATH];
-
-typedef struct searchpath_s
-{
- // only one of filename / pack will be used
- char filename[MAX_OSPATH];
- pack_t *pack;
- struct searchpath_s *next;
-} searchpath_t;
-
-searchpath_t *com_searchpaths;
-
-/*
-============
-COM_Path_f
-
-============
-*/
-void COM_Path_f (void)
-{
- searchpath_t *s;
-
- Con_Printf ("Current search path:\n");
- for (s=com_searchpaths ; s ; s=s->next)
- {
- if (s->pack)
- {
- Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles);
- }
- else
- Con_Printf ("%s\n", s->filename);
- }
-}
-
-/*
-============
-COM_CreatePath
-
-LordHavoc: Previously only used for CopyFile, now also used for COM_WriteFile.
-============
-*/
-void COM_CreatePath (char *path)
-{
- char *ofs, save;
-
- for (ofs = path+1 ; *ofs ; ofs++)
- {
- if (*ofs == '/' || *ofs == '\\')
- {
- // create the directory
- save = *ofs;
- *ofs = 0;
- Sys_mkdir (path);
- *ofs = save;
- }
- }
-}
-
-
-/*
-============
-COM_WriteFile
-
-The filename will be prefixed by the current game directory
-============
-*/
-qboolean COM_WriteFile (const char *filename, void *data, int len)
-{
- int handle;
- char name[MAX_OSPATH];
-
- sprintf (name, "%s/%s", com_gamedir, filename);
-
- // LordHavoc: added this
- // create directories up to the file
- COM_CreatePath (name);
-
- handle = Sys_FileOpenWrite (name);
- if (handle == -1)
- {
- Con_Printf ("COM_WriteFile: failed on %s\n", name);
- return false;
- }
-
- Con_DPrintf ("COM_WriteFile: %s\n", name);
- Sys_FileWrite (handle, data, len);
- Sys_FileClose (handle);
- return true;
-}
-
-
-/*
-===========
-COM_CopyFile
-
-Copies a file over from the net to the local cache, creating any directories
-needed. This is for the convenience of developers using ISDN from home.
-===========
-*/
-void COM_CopyFile (char *netpath, char *cachepath)
-{
- int in, out, remaining, count;
- char buf[4096];
-
- remaining = Sys_FileOpenRead (netpath, &in);
- COM_CreatePath (cachepath); // create directories up to the cache file
- out = Sys_FileOpenWrite (cachepath);
-
- while (remaining)
- {
- if (remaining < (int)sizeof(buf))
- count = remaining;
- else
- count = sizeof(buf);
- Sys_FileRead (in, buf, count);
- Sys_FileWrite (out, buf, count);
- remaining -= count;
- }
-
- Sys_FileClose (in);
- Sys_FileClose (out);
-}
-
-/*
-===========
-COM_OpenRead
-===========
-*/
-QFile * COM_OpenRead (const char *path, int offs, int len, qboolean zip)
-{
- int fd = open (path, O_RDONLY);
- unsigned char id[2], len_bytes[4];
-
- if (fd == -1)
- {
- Sys_Error ("Couldn't open %s", path);
- return 0;
- }
- if (offs < 0 || len < 0)
- {
- // normal file
- offs = 0;
- len = lseek (fd, 0, SEEK_END);
- lseek (fd, 0, SEEK_SET);
- }
- lseek (fd, offs, SEEK_SET);
- if (zip)
- {
- read (fd, id, 2);
- if (id[0] == 0x1f && id[1] == 0x8b)
- {
- lseek (fd, offs + len - 4, SEEK_SET);
- read (fd, len_bytes, 4);
- len = ((len_bytes[3] << 24)
- | (len_bytes[2] << 16)
- | (len_bytes[1] << 8)
- | (len_bytes[0]));
- }
- }
- lseek (fd, offs, SEEK_SET);
- com_filesize = len;
-
-#ifdef WIN32
- setmode (fd, O_BINARY);
-#endif
- if (zip)
- return Qdopen (fd, "rbz");
- else
- return Qdopen (fd, "rb");
-}
-
-/*
-===========
-COM_FindFile
-
-Finds the file in the search path.
-Sets com_filesize and one of handle or file
-===========
-*/
-int COM_FindFile (const char *filename, QFile **file, qboolean quiet, qboolean zip)
-{
- searchpath_t *search;
- char netpath[MAX_OSPATH];
-#if CACHEENABLE
- char cachepath[MAX_OSPATH];
- int cachetime;
-#endif
- pack_t *pak;
- int i, findtime, filenamelen;
- char gzfilename[MAX_OSPATH];
-
- filenamelen = strlen (filename);
- sprintf (gzfilename, "%s.gz", filename);
-
- if (!file)
- Sys_Error ("COM_FindFile: file not set");
-
-//
-// search through the path, one element at a time
-//
- search = com_searchpaths;
-
- for ( ; search ; search = search->next)
- {
- // is the element a pak file?
- if (search->pack)
- {
- // look through all the pak file elements
- pak = search->pack;
- for (i=0 ; i<pak->numfiles ; i++)
- if (!strcmp (pak->files[i].name, filename)
- || !strcmp (pak->files[i].name, gzfilename))
- { // found it!
- if (!quiet)
- Sys_Printf ("PackFile: %s : %s\n",pak->filename, pak->files[i].name);
- // open a new file on the pakfile
- *file = COM_OpenRead (pak->filename, pak->files[i].filepos, pak->files[i].filelen, zip);
- return com_filesize;
- }
- }
- else
- {
- sprintf (netpath, "%s/%s",search->filename, filename);
-
- findtime = Sys_FileTime (netpath);
- if (findtime == -1)
- continue;
-
-#if CACHEENABLE
- // see if the file needs to be updated in the cache
- if (com_cachedir[0])
- {
-#if defined(_WIN32)
- if ((strlen(netpath) < 2) || (netpath[1] != ':'))
- sprintf (cachepath,"%s%s", com_cachedir, netpath);
- else
- sprintf (cachepath,"%s%s", com_cachedir, netpath+2);
-#else
- sprintf (cachepath,"%s%s", com_cachedir, netpath);
-#endif
-
- cachetime = Sys_FileTime (cachepath);
-
- if (cachetime < findtime)
- COM_CopyFile (netpath, cachepath);
- strcpy (netpath, cachepath);
- }
-#endif
- if (!quiet)
- Sys_Printf ("FindFile: %s\n",netpath);
- *file = COM_OpenRead (netpath, -1, -1, zip);
- return com_filesize;
- }
- }
-
- if (!quiet)
- Sys_Printf ("FindFile: can't find %s\n", filename);
-
- *file = NULL;
- com_filesize = -1;
- return -1;
-}
-
-
-/*
-===========
-COM_FOpenFile
-
-If the requested file is inside a packfile, a new QFile * will be opened
-into the file.
-===========
-*/
-int COM_FOpenFile (const char *filename, QFile **file, qboolean quiet, qboolean zip)
-{
- return COM_FindFile (filename, file, quiet, zip);
-}
-
-
-/*
-============
-COM_LoadFile
-
-Filename are reletive to the quake directory.
-Always appends a 0 byte.
-============
-*/
-qbyte *loadbuf;
-int loadsize;
-qbyte *COM_LoadFile (const char *path, qboolean quiet)
-{
- QFile *h;
- qbyte *buf;
- char base[1024];
- int len;
-
- buf = NULL; // quiet compiler warning
- loadsize = 0;
-
-// look for it in the filesystem or pack files
- len = COM_FOpenFile (path, &h, quiet, true);
- if (!h)
- return NULL;
-
- loadsize = len;
-
-// extract the filename base name for hunk tag
- COM_FileBase (path, base);
-
- buf = Mem_Alloc(tempmempool, len+1);
- if (!buf)
- Sys_Error ("COM_LoadFile: not enough available memory for %s (size %i)", path, len);
-
- ((qbyte *)buf)[len] = 0;
-
- Qread (h, buf, len);
- Qclose (h);
-
- return buf;
-}
-
-/*
-=================
-COM_LoadPackFile
-
-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.
-=================
-*/
-pack_t *COM_LoadPackFile (const char *packfile)
-{
- dpackheader_t header;
- int i, numpackfiles, packhandle;
- pack_t *pack;
- // LordHavoc: changed from stack array to temporary alloc, allowing huge pack directories
- dpackfile_t *info;
-
- if (Sys_FileOpenRead (packfile, &packhandle) == -1)
- return NULL;
-
- Sys_FileRead (packhandle, (void *)&header, sizeof(header));
- if (memcmp(header.id, "PACK", 4))
- Sys_Error ("%s is not a packfile", packfile);
- header.dirofs = LittleLong (header.dirofs);
- header.dirlen = LittleLong (header.dirlen);
-
- if (header.dirlen % sizeof(dpackfile_t))
- Sys_Error ("%s has an invalid directory size", packfile);
-
- numpackfiles = header.dirlen / sizeof(dpackfile_t);
-
- if (numpackfiles > MAX_FILES_IN_PACK)
- Sys_Error ("%s has %i files", packfile, numpackfiles);
-
- pack = Mem_Alloc(pak_mempool, sizeof (pack_t));
- strcpy (pack->filename, packfile);
- pack->handle = packhandle;
- pack->numfiles = numpackfiles;
- pack->mempool = Mem_AllocPool(packfile);
- pack->files = Mem_Alloc(pack->mempool, numpackfiles * sizeof(packfile_t));
- pack->next = packlist;
- packlist = pack;
-
- info = Mem_Alloc(tempmempool, sizeof(*info) * numpackfiles);
- Sys_FileSeek (packhandle, header.dirofs);
- Sys_FileRead (packhandle, (void *)info, header.dirlen);
-
-// parse the directory
- for (i = 0;i < numpackfiles;i++)
- {
- strcpy (pack->files[i].name, info[i].name);
- pack->files[i].filepos = LittleLong(info[i].filepos);
- pack->files[i].filelen = LittleLong(info[i].filelen);
- }
-
- Mem_Free(info);
-
- Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles);
- return pack;
-}
-
-
-/*
-================
-COM_AddGameDirectory
-
-Sets com_gamedir, adds the directory to the head of the path,
-then loads and adds pak1.pak pak2.pak ...
-================
-*/
-void COM_AddGameDirectory (char *dir)
-{
- stringlist_t *list, *current;
- searchpath_t *search;
- pack_t *pak;
- char pakfile[MAX_OSPATH];
-
- strcpy (com_gamedir, dir);
-
-//
-// add the directory to the search path
-//
- search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
- strcpy (search->filename, dir);
- search->next = com_searchpaths;
- com_searchpaths = search;
-
- // add any paks in the directory
- list = listdirectory(dir);
- for (current = list;current;current = current->next)
- {
- if (matchpattern(current->text, "*.pak", true))
- {
- sprintf (pakfile, "%s/%s", dir, current->text);
- pak = COM_LoadPackFile (pakfile);
- if (pak)
- {
- search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
- search->pack = pak;
- search->next = com_searchpaths;
- com_searchpaths = search;
- }
- else
- Con_Printf("unable to load pak \"%s\"\n", pakfile);
- }
- }
- freedirectory(list);
-}
-
-/*
-================
-COM_InitFilesystem
-================
-*/
-void COM_InitFilesystem (void)
-{
- int i;
- searchpath_t *search;
-
- strcpy(com_basedir, ".");
-
- // -basedir <path>
- // Overrides the system supplied base directory (under GAMENAME)
- i = COM_CheckParm ("-basedir");
- if (i && i < com_argc-1)
- strcpy (com_basedir, com_argv[i+1]);
-
- i = strlen (com_basedir);
- if (i > 0 && (com_basedir[i-1] == '\\' || com_basedir[i-1] == '/'))
- com_basedir[i-1] = 0;
-
-// start up with GAMENAME by default (id1)
- strcpy(com_modname, GAMENAME);
- COM_AddGameDirectory (va("%s/"GAMENAME, com_basedir));
- if (gamedirname[0])
- {
- com_modified = true;
- strcpy(com_modname, gamedirname);
- COM_AddGameDirectory (va("%s/%s", com_basedir, gamedirname));
- }
-
- // -game <gamedir>
- // Adds basedir/gamedir as an override game
- i = COM_CheckParm ("-game");
- if (i && i < com_argc-1)
- {
- com_modified = true;
- strcpy(com_modname, com_argv[i+1]);
- COM_AddGameDirectory (va("%s/%s", com_basedir, com_argv[i+1]));
- }
-
- // -path <dir or packfile> [<dir or packfile>] ...
- // Fully specifies the exact search path, overriding the generated one
- i = COM_CheckParm ("-path");
- if (i)
- {
- com_modified = true;
- com_searchpaths = NULL;
- while (++i < com_argc)
- {
- if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-')
- break;
-
- search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
- if ( !strcmp(COM_FileExtension(com_argv[i]), "pak") )
- {
- search->pack = COM_LoadPackFile (com_argv[i]);
- if (!search->pack)
- Sys_Error ("Couldn't load packfile: %s", com_argv[i]);
- }
- else
- strcpy (search->filename, com_argv[i]);
- search->next = com_searchpaths;
- com_searchpaths = search;
- }
- }
-}
-
-int COM_FileExists(const char *filename)
-{
- searchpath_t *search;
- char netpath[MAX_OSPATH];
- pack_t *pak;
- int i, findtime;
-
- for (search = com_searchpaths;search;search = search->next)
- {
- if (search->pack)
- {
- pak = search->pack;
- for (i = 0;i < pak->numfiles;i++)
- if (!strcmp (pak->files[i].name, filename))
- return true;
- }
- else
- {
- sprintf (netpath, "%s/%s",search->filename, filename);
- findtime = Sys_FileTime (netpath);
- if (findtime != -1)
- return true;
- }
- }
-
- return false;
-}
-
-
//======================================
// LordHavoc: added these because they are useful
#ifndef COMMON_H
#define COMMON_H
-// LordHavoc: MSVC has a different name for snprintf
+// MSVC has a different name for several standard functions
#ifdef WIN32
-#define snprintf _snprintf
+# define snprintf _snprintf
+# define vsnprintf _vsnprintf
+# define strcasecmp stricmp
+# define strncasecmp strnicmp
#endif
+
//============================================================================
typedef struct sizebuf_s
//============================================================================
-int Q_strcasecmp (const char *s1, const char *s2);
-int Q_strncasecmp (const char *s1, const char *s2, int n);
-
-//============================================================================
-
extern char com_token[1024];
-extern qboolean com_eof;
int COM_ParseToken (const char **data);
-extern char com_basedir[MAX_OSPATH];
extern int com_argc;
extern const char **com_argv;
void COM_InitArgv (void);
void COM_InitGameType (void);
-void COM_StripExtension (const char *in, char *out);
-void COM_FileBase (const char *in, char *out);
-void COM_DefaultExtension (char *path, const char *extension);
-
char *va(const char *format, ...);
// does a varargs printf into a temp buffer
//============================================================================
-extern int com_filesize;
-
-extern char com_gamedir[MAX_OSPATH];
-
-qboolean COM_WriteFile (const char *filename, void *data, int len);
-int COM_FOpenFile (const char *filename, QFile **file, qboolean quiet, qboolean zip);
-
-// set by COM_LoadFile functions
-extern int loadsize;
-qbyte *COM_LoadFile (const char *path, qboolean quiet);
-
-int COM_FileExists(const char *filename);
-
extern struct cvar_s registered;
#define GAME_NORMAL 0
extern int gamemode;
extern char *gamename;
+extern char *gamedirname;
extern char com_modname[MAX_OSPATH];
// LordHavoc: useful...
if (con_debuglog)
{
- if (strlen (com_gamedir) < (MAXGAMEDIRLEN - strlen (t2)))
+ if (strlen (fs_gamedir) < (MAXGAMEDIRLEN - strlen (t2)))
{
- sprintf (temp, "%s%s", com_gamedir, t2);
+ sprintf (temp, "%s%s", fs_gamedir, t2);
unlink (temp);
}
logfile.integer = 1;
Con_DebugLog
================
*/
-void Con_DebugLog(const char *file, const char *fmt, ...)
+void Con_DebugLog (const char *msg)
{
- va_list argptr;
- FILE* fd;
-
- fd = fopen(file, "at");
- va_start(argptr, fmt);
- vfprintf (fd, fmt, argptr);
- va_end(argptr);
- fclose(fd);
+ qfile_t* file;
+
+ file = FS_Open ("qconsole.log", "at", true);
+ if (file)
+ {
+ FS_Printf (file, "%s", msg);
+ FS_Close (file);
+ }
}
vsprintf (msg,fmt,argptr);
va_end (argptr);
-// also echo to debugging console
+ // also echo to debugging console
Sys_Printf ("%s", msg);
-// log all messages to file
+ // log all messages to file
if (con_debuglog)
- {
- // can't use va() here because it might overwrite other important things
- char logname[MAX_OSPATH];
- sprintf(logname, "%s/qconsole.log", com_gamedir);
- Con_DebugLog(logname, "%s", msg);
- }
+ Con_DebugLog (msg);
if (!con_initialized)
return;
if (cls.state == ca_dedicated)
return; // no graphics mode
-// write it to the scrollable buffer
+ // write it to the scrollable buffer
Con_Print (msg);
}
with the archive flag set to true.
============
*/
-void Cvar_WriteVariables (QFile *f)
+void Cvar_WriteVariables (qfile_t *f)
{
cvar_t *var;
for (var = cvar_vars ; var ; var = var->next)
if (var->flags & CVAR_SAVE)
- Qprintf (f, "%s \"%s\"\n", var->name, var->string);
+ FS_Printf (f, "%s \"%s\"\n", var->name, var->string);
}
// command. Returns true if the command was a variable reference that
// was handled. (print or change)
-void Cvar_WriteVariables (QFile *f);
+void Cvar_WriteVariables (qfile_t *f);
// Writes lines containing "set variable value" for all variables
// with the archive flag set to true.
# End Source File\r
# Begin Source File\r
\r
-SOURCE=.\quakeio.c\r
+SOURCE=.\fs.c\r
# End Source File\r
# Begin Source File\r
\r
# End Source File\r
# Begin Source File\r
\r
-SOURCE=.\quakeio.h\r
+SOURCE=.\fs.h\r
# End Source File\r
# Begin Source File\r
\r
typedef struct
{
- FILE *file;
+ qfile_t *file;
int endoffile;
}
hz_bitstream_read_t;
hz_bitstream_read_t *hz_bitstream_read_open(char *filename)
{
- FILE *file;
+ qfile_t *file;
hz_bitstream_read_t *stream;
- if ((file = fopen(filename, "rb")))
+ if ((file = FS_Open (filename, "rb", false)))
{
stream = malloc(sizeof(hz_bitstream_read_t));
memset(stream, 0, sizeof(*stream));
{
if (stream)
{
- fclose(stream->file);
+ FS_Close(stream->file);
free(stream);
}
}
unsigned int hz_bitstream_read_currentbyte(hz_bitstream_read_t *stream)
{
- return ftell(stream->file);
+ return FS_Tell(stream->file);
}
int hz_bitstream_read_seek(hz_bitstream_read_t *stream, unsigned int position)
{
stream->endoffile = 0;
- return fseek(stream->file, position, SEEK_SET) != 0;
+ return FS_Seek(stream->file, position, SEEK_SET) != 0;
}
hz_bitstream_readblocks_t *hz_bitstream_read_blocks_new(void)
else
b->size = s;
s -= b->size;
- if (fread(b->data, 1, b->size, stream->file) != b->size)
+ if (FS_Read(stream->file, b->data, b->size) != b->size)
{
stream->endoffile = 1;
break;
--- /dev/null
+/*
+ Quake file system
+
+ Copyright (C) 2003 Mathieu Olivier
+ Copyright (C) 1999,2000 contributors of the QuakeForge project
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to:
+
+ Free Software Foundation, Inc.
+ 59 Temple Place - Suite 330
+ Boston, MA 02111-1307, USA
+*/
+
+#include "quakedef.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <fcntl.h>
+
+#ifdef WIN32
+# include <direct.h>
+# include <io.h>
+#else
+# include <pwd.h>
+# include <sys/stat.h>
+# include <unistd.h>
+#endif
+
+#ifndef PATH_MAX
+# define PATH_MAX 512
+#endif
+
+#include "fs.h"
+
+/*
+
+All of Quake's data access is through a hierchal file system, but the contents
+of the file system can be transparently merged from several sources.
+
+The "base directory" is the path to the directory holding the quake.exe and
+all game directories. The sys_* files pass this to host_init in
+quakeparms_t->basedir. This can be overridden with the "-basedir" command
+line parm to allow code debugging in a different directory. The base
+directory is only used during filesystem initialization.
+
+The "game directory" is the first tree on the search path and directory that
+all generated files (savegames, screenshots, demos, config files) will be
+saved to. This can be overridden with the "-game" command line parameter.
+The game directory can never be changed while quake is executing. This is a
+precacution against having a malicious server instruct clients to write files
+over areas they shouldn't.
+
+*/
+
+
+/*
+=============================================================================
+
+TYPES
+
+=============================================================================
+*/
+
+// Our own file structure on top of FILE
+typedef enum
+{
+ FS_FLAG_NONE = 0,
+ FS_FLAG_PACKED = (1 << 0) // inside a package (PAK or PK3)
+// FS_FLAG_COMPRESSED = (1 << 1) // compressed (inside a PK3 file)
+} fs_flags_t;
+
+struct qfile_s
+{
+ fs_flags_t flags;
+ FILE* stream;
+ size_t length; // file size (PACKED only)
+ size_t offset; // offset into a package (PACKED only)
+ size_t position; // current position in the file (PACKED only)
+};
+
+
+// PAK files on disk
+typedef struct
+{
+ char name[56];
+ int filepos, filelen;
+} dpackfile_t;
+
+typedef struct
+{
+ char id[4];
+ int dirofs;
+ int dirlen;
+} dpackheader_t;
+
+
+// Packages in memory
+typedef struct
+{
+ char name[MAX_QPATH];
+ int filepos, filelen;
+} packfile_t;
+
+typedef struct pack_s
+{
+ char filename[MAX_OSPATH];
+ FILE *handle;
+ int numfiles;
+ packfile_t *files;
+ mempool_t *mempool;
+ struct pack_s *next;
+} pack_t;
+
+
+// Search paths for files (including packages)
+typedef struct searchpath_s
+{
+ // only one of filename / pack will be used
+ char filename[MAX_OSPATH];
+ pack_t *pack;
+ struct searchpath_s *next;
+} searchpath_t;
+
+
+/*
+=============================================================================
+
+VARIABLES
+
+=============================================================================
+*/
+
+mempool_t *fs_mempool;
+mempool_t *pak_mempool;
+
+int fs_filesize;
+
+pack_t *packlist = NULL;
+
+searchpath_t *fs_searchpaths;
+
+// LordHavoc: was 2048, increased to 65536 and changed info[MAX_PACK_FILES] to a temporary alloc
+#define MAX_FILES_IN_PACK 65536
+
+char fs_gamedir[MAX_OSPATH];
+char fs_basedir[MAX_OSPATH];
+
+qboolean fs_modified; // set true if using non-id files
+
+
+/*
+=============================================================================
+
+PRIVATE FUNCTIONS
+
+=============================================================================
+*/
+
+
+/*
+============
+FS_CreatePath
+
+LordHavoc: Previously only used for CopyFile, now also used for FS_WriteFile.
+============
+*/
+void FS_CreatePath (char *path)
+{
+ char *ofs, save;
+
+ for (ofs = path+1 ; *ofs ; ofs++)
+ {
+ if (*ofs == '/' || *ofs == '\\')
+ {
+ // create the directory
+ save = *ofs;
+ *ofs = 0;
+ FS_mkdir (path);
+ *ofs = save;
+ }
+ }
+}
+
+
+/*
+============
+FS_Path_f
+
+============
+*/
+void FS_Path_f (void)
+{
+ searchpath_t *s;
+
+ Con_Printf ("Current search path:\n");
+ for (s=fs_searchpaths ; s ; s=s->next)
+ {
+ if (s->pack)
+ {
+ Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles);
+ }
+ else
+ Con_Printf ("%s\n", s->filename);
+ }
+}
+
+
+/*
+=================
+FS_LoadPackFile
+
+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.
+=================
+*/
+pack_t *FS_LoadPackFile (const char *packfile)
+{
+ dpackheader_t header;
+ int i, numpackfiles;
+ FILE *packhandle;
+ pack_t *pack;
+ // LordHavoc: changed from stack array to temporary alloc, allowing huge pack directories
+ dpackfile_t *info;
+
+ packhandle = fopen (packfile, "rb");
+ if (!packhandle)
+ return NULL;
+
+ fread ((void *)&header, 1, sizeof(header), packhandle);
+ if (memcmp(header.id, "PACK", 4))
+ Sys_Error ("%s is not a packfile", packfile);
+ header.dirofs = LittleLong (header.dirofs);
+ header.dirlen = LittleLong (header.dirlen);
+
+ if (header.dirlen % sizeof(dpackfile_t))
+ Sys_Error ("%s has an invalid directory size", packfile);
+
+ numpackfiles = header.dirlen / sizeof(dpackfile_t);
+
+ if (numpackfiles > MAX_FILES_IN_PACK)
+ Sys_Error ("%s has %i files", packfile, numpackfiles);
+
+ pack = Mem_Alloc(pak_mempool, sizeof (pack_t));
+ strcpy (pack->filename, packfile);
+ pack->handle = packhandle;
+ pack->numfiles = numpackfiles;
+ pack->mempool = Mem_AllocPool(packfile);
+ pack->files = Mem_Alloc(pack->mempool, numpackfiles * sizeof(packfile_t));
+ pack->next = packlist;
+ packlist = pack;
+
+ info = Mem_Alloc(tempmempool, sizeof(*info) * numpackfiles);
+ fseek (packhandle, header.dirofs, SEEK_SET);
+ fread ((void *)info, 1, header.dirlen, packhandle);
+
+// parse the directory
+ for (i = 0;i < numpackfiles;i++)
+ {
+ strcpy (pack->files[i].name, info[i].name);
+ pack->files[i].filepos = LittleLong(info[i].filepos);
+ pack->files[i].filelen = LittleLong(info[i].filelen);
+ }
+
+ Mem_Free(info);
+
+ Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles);
+ return pack;
+}
+
+
+/*
+================
+FS_AddGameDirectory
+
+Sets fs_gamedir, adds the directory to the head of the path,
+then loads and adds pak1.pak pak2.pak ...
+================
+*/
+void FS_AddGameDirectory (char *dir)
+{
+ stringlist_t *list, *current;
+ searchpath_t *search;
+ pack_t *pak;
+ char pakfile[MAX_OSPATH];
+
+ strcpy (fs_gamedir, dir);
+
+ // add the directory to the search path
+ search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
+ strcpy (search->filename, dir);
+ search->next = fs_searchpaths;
+ fs_searchpaths = search;
+
+ // add any paks in the directory
+ list = listdirectory(dir);
+ for (current = list;current;current = current->next)
+ {
+ if (matchpattern(current->text, "*.pak", true))
+ {
+ sprintf (pakfile, "%s/%s", dir, current->text);
+ pak = FS_LoadPackFile (pakfile);
+ if (pak)
+ {
+ search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
+ search->pack = pak;
+ search->next = fs_searchpaths;
+ fs_searchpaths = search;
+ }
+ else
+ Con_Printf("unable to load pak \"%s\"\n", pakfile);
+ }
+ }
+ freedirectory(list);
+}
+
+
+/*
+============
+FS_FileExtension
+============
+*/
+char *FS_FileExtension (const char *in)
+{
+ static char exten[8];
+ int i;
+
+ while (*in && *in != '.')
+ in++;
+ if (!*in)
+ return "";
+ in++;
+ for (i=0 ; i<7 && *in ; i++,in++)
+ exten[i] = *in;
+ exten[i] = 0;
+ return exten;
+}
+
+
+/*
+================
+FS_Init
+================
+*/
+void FS_Init (void)
+{
+ int i;
+ searchpath_t *search;
+
+ fs_mempool = Mem_AllocPool("file management");
+ pak_mempool = Mem_AllocPool("paks");
+
+ Cmd_AddCommand ("path", FS_Path_f);
+
+ strcpy(fs_basedir, ".");
+
+ // -basedir <path>
+ // Overrides the system supplied base directory (under GAMENAME)
+ i = COM_CheckParm ("-basedir");
+ if (i && i < com_argc-1)
+ strcpy (fs_basedir, com_argv[i+1]);
+
+ i = strlen (fs_basedir);
+ if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
+ fs_basedir[i-1] = 0;
+
+ // start up with GAMENAME by default (id1)
+ strcpy(com_modname, GAMENAME);
+ FS_AddGameDirectory (va("%s/"GAMENAME, fs_basedir));
+ if (gamedirname[0])
+ {
+ fs_modified = true;
+ strcpy(com_modname, gamedirname);
+ FS_AddGameDirectory (va("%s/%s", fs_basedir, gamedirname));
+ }
+
+ // -game <gamedir>
+ // Adds basedir/gamedir as an override game
+ i = COM_CheckParm ("-game");
+ if (i && i < com_argc-1)
+ {
+ fs_modified = true;
+ strcpy(com_modname, com_argv[i+1]);
+ FS_AddGameDirectory (va("%s/%s", fs_basedir, com_argv[i+1]));
+ }
+
+ // -path <dir or packfile> [<dir or packfile>] ...
+ // Fully specifies the exact search path, overriding the generated one
+ i = COM_CheckParm ("-path");
+ if (i)
+ {
+ fs_modified = true;
+ fs_searchpaths = NULL;
+ while (++i < com_argc)
+ {
+ if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-')
+ break;
+
+ search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
+ if ( !strcmp(FS_FileExtension(com_argv[i]), "pak") )
+ {
+ search->pack = FS_LoadPackFile (com_argv[i]);
+ if (!search->pack)
+ Sys_Error ("Couldn't load packfile: %s", com_argv[i]);
+ }
+ else
+ strcpy (search->filename, com_argv[i]);
+ search->next = fs_searchpaths;
+ fs_searchpaths = search;
+ }
+ }
+}
+
+
+/*
+=============================================================================
+
+MAIN FUNCTIONS
+
+=============================================================================
+*/
+
+/*
+====================
+FS_Open
+
+Internal function used to create a qfile_t and open the relevant file on disk
+====================
+*/
+static qfile_t* FS_SysOpen (const char* filepath, const char* mode)
+{
+ qfile_t* file;
+
+ file = Mem_Alloc (fs_mempool, sizeof (*file));
+ memset (file, 0, sizeof (*file));
+
+ file->stream = fopen (filepath, mode);
+ if (!file->stream)
+ {
+ Mem_Free (file);
+ return NULL;
+ }
+
+ return file;
+}
+
+
+/*
+===========
+FS_OpenRead
+===========
+*/
+qfile_t *FS_OpenRead (const char *path, int offs, int len)
+{
+ qfile_t* file;
+
+ file = FS_SysOpen (path, "rb");
+ if (!file)
+ {
+ Sys_Error ("Couldn't open %s", path);
+ return NULL;
+ }
+
+ // Normal file
+ if (offs < 0 || len < 0)
+ {
+ FS_Seek (file, 0, SEEK_END);
+ len = FS_Tell (file);
+ FS_Seek (file, 0, SEEK_SET);
+ }
+ // Packed file
+ else
+ {
+ FS_Seek (file, offs, SEEK_SET);
+
+ file->flags |= FS_FLAG_PACKED;
+ file->length = len;
+ file->offset = offs;
+ file->position = 0;
+ }
+
+ fs_filesize = len;
+
+ return file;
+}
+
+/*
+===========
+FS_FOpenFile
+
+If the requested file is inside a packfile, a new qfile_t* will be opened
+into the file.
+
+Sets fs_filesize
+===========
+*/
+qfile_t *FS_FOpenFile (const char *filename, qboolean quiet)
+{
+ searchpath_t *search;
+ char netpath[MAX_OSPATH];
+ pack_t *pak;
+ int i, filenamelen;
+
+ filenamelen = strlen (filename);
+
+ // search through the path, one element at a time
+ search = fs_searchpaths;
+
+ for ( ; search ; search = search->next)
+ {
+ // is the element a pak file?
+ if (search->pack)
+ {
+ // look through all the pak file elements
+ pak = search->pack;
+ for (i=0 ; i<pak->numfiles ; i++)
+ if (!strcmp (pak->files[i].name, filename))
+ { // found it!
+ if (!quiet)
+ Sys_Printf ("PackFile: %s : %s\n",pak->filename, pak->files[i].name);
+ // open a new file in the pakfile
+ return FS_OpenRead (pak->filename, pak->files[i].filepos, pak->files[i].filelen);
+ }
+ }
+ else
+ {
+ sprintf (netpath, "%s/%s",search->filename, filename);
+
+ if (!FS_SysFileExists (netpath))
+ continue;
+
+ if (!quiet)
+ Sys_Printf ("FindFile: %s\n",netpath);
+ return FS_OpenRead (netpath, -1, -1);
+ }
+ }
+
+ if (!quiet)
+ Sys_Printf ("FindFile: can't find %s\n", filename);
+
+ fs_filesize = -1;
+ return NULL;
+}
+
+
+/*
+====================
+FS_Open
+
+Open a file. The syntax is the same as fopen
+====================
+*/
+qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet)
+{
+ // If the file is opened in "write" or "append" mode
+ if (strchr (mode, 'w') || strchr (mode, 'a'))
+ {
+ char real_path [MAX_OSPATH];
+
+ // Open the file on disk directly
+ snprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath);
+ return FS_SysOpen (real_path, mode);
+ }
+
+ // Else, we look at the various search paths
+ return FS_FOpenFile (filepath, quiet);
+}
+
+
+/*
+====================
+FS_Close
+
+Close a file
+====================
+*/
+int FS_Close (qfile_t* file)
+{
+ if (fclose (file->stream))
+ return EOF;
+
+ Mem_Free (file);
+ return 0;
+}
+
+
+/*
+====================
+FS_Write
+
+Write "datasize" bytes into a file
+====================
+*/
+size_t FS_Write (qfile_t* file, const void* data, size_t datasize)
+{
+ return fwrite (data, 1, datasize, file->stream);
+}
+
+
+/*
+====================
+FS_Read
+
+Read up to "buffersize" bytes from a file
+====================
+*/
+size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
+{
+ size_t nb;
+
+ // If the file belongs to a package, we must take care
+ // to not read after the end of the file
+ if (file->flags & FS_FLAG_PACKED)
+ {
+ size_t remain = file->length - file->position;
+ if (buffersize > remain)
+ buffersize = remain;
+ }
+
+ nb = fread (buffer, 1, buffersize, file->stream);
+
+ // Update the position index if the file is packed
+ if ((file->flags & FS_FLAG_PACKED) && nb > 0)
+ file->position += nb;
+
+ return nb;
+}
+
+
+/*
+====================
+FS_Flush
+
+Flush the file output stream
+====================
+*/
+int FS_Flush (qfile_t* file)
+{
+ return fflush (file->stream);
+}
+
+
+/*
+====================
+FS_Printf
+
+Print a string into a file
+====================
+*/
+int FS_Printf (qfile_t* file, const char* format, ...)
+{
+ int result;
+ va_list args;
+
+ va_start (args, format);
+ result = vfprintf (file->stream, format, args);
+ va_end (args);
+
+ return result;
+}
+
+
+/*
+====================
+FS_Getc
+
+Get the next character of a file
+====================
+*/
+int FS_Getc (qfile_t* file)
+{
+ int c;
+
+ // If the file belongs to a package, we must take care
+ // to not read after the end of the file
+ if (file->flags & FS_FLAG_PACKED)
+ {
+ if (file->position >= file->length)
+ return EOF;
+ }
+
+ c = fgetc (file->stream);
+
+ // Update the position index if the file is packed
+ if ((file->flags & FS_FLAG_PACKED) && c != EOF)
+ file->position++;
+
+ return c;
+}
+
+
+/*
+====================
+FS_Seek
+
+Move the position index in a file
+====================
+*/
+int FS_Seek (qfile_t* file, long offset, int whence)
+{
+ // Packed files receive a special treatment
+ if (file->flags & FS_FLAG_PACKED)
+ {
+ switch (whence)
+ {
+ case SEEK_CUR:
+ offset += file->position;
+ // It continues on the next case (no break)
+
+ case SEEK_SET:
+ if (offset < 0 || offset > file->length)
+ return -1;
+ if (fseek (file->stream, file->offset + offset, SEEK_SET) == -1)
+ return -1;
+ file->position = offset;
+ return 0;
+
+ case SEEK_END:
+ if (offset > 0 || -offset > file->length)
+ return -1;
+ if (fseek (file->stream, file->offset + file->length + offset, SEEK_SET) == -1)
+ return -1;
+ file->position = file->length + offset;
+ return 0;
+
+ default:
+ return -1;
+ }
+ }
+
+ return fseek (file->stream, offset, whence);
+}
+
+
+/*
+====================
+FS_Tell
+
+Give the current position in a file
+====================
+*/
+long FS_Tell (qfile_t* file)
+{
+ if (file->flags & FS_FLAG_PACKED)
+ return file->position;
+
+ return ftell (file->stream);
+}
+
+
+/*
+====================
+FS_Gets
+
+Extract a line from a file
+====================
+*/
+char* FS_Gets (qfile_t* file, char* buffer, int buffersize)
+{
+ if (!fgets (buffer, buffersize, file->stream))
+ return NULL;
+
+ // Check that we didn't read after the end of a packed file, and update the position
+ if (file->flags & FS_FLAG_PACKED)
+ {
+ size_t len = strlen (buffer);
+ size_t max = file->length - file->position;
+
+ if (len > max)
+ {
+ buffer[max] = '\0';
+ file->position = file->length;
+ }
+ else
+ file->position += len;
+ }
+
+ return buffer;
+}
+
+
+/*
+==========
+FS_Getline
+
+Dynamic length version of fgets. DO NOT free the buffer.
+==========
+*/
+char *FS_Getline (qfile_t *file)
+{
+ static int size = 256;
+ static char *buf = 0;
+ char *t;
+ int len;
+
+ if (!buf)
+ buf = Mem_Alloc (fs_mempool, size);
+
+ if (!FS_Gets (file, buf, size))
+ return 0;
+
+ len = strlen (buf);
+ while (buf[len - 1] != '\n' && buf[len - 1] != '\r')
+ {
+ t = Mem_Alloc (fs_mempool, size + 256);
+ memcpy(t, buf, size);
+ Mem_Free(buf);
+ size += 256;
+ buf = t;
+ if (!FS_Gets (file, buf + len, size - len))
+ break;
+ len = strlen (buf);
+ }
+ while ((len = strlen(buf)) && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
+ buf[len - 1] = 0;
+ return buf;
+}
+
+
+/*
+====================
+FS_Eof
+
+Extract a line from a file
+====================
+*/
+int FS_Eof (qfile_t* file)
+{
+ if (file->flags & FS_FLAG_PACKED)
+ return (file->position == file->length);
+
+ return feof (file->stream);
+}
+
+
+/*
+============
+FS_LoadFile
+
+Filename are relative to the quake directory.
+Always appends a 0 byte.
+============
+*/
+qbyte *FS_LoadFile (const char *path, qboolean quiet)
+{
+ qfile_t *h;
+ qbyte *buf;
+
+ // look for it in the filesystem or pack files
+ h = FS_Open (path, "rb", quiet);
+ if (!h)
+ return NULL;
+
+ buf = Mem_Alloc(tempmempool, fs_filesize+1);
+ if (!buf)
+ Sys_Error ("FS_LoadFile: not enough available memory for %s (size %i)", path, fs_filesize);
+
+ ((qbyte *)buf)[fs_filesize] = 0;
+
+ FS_Read (h, buf, fs_filesize);
+ FS_Close (h);
+
+ return buf;
+}
+
+
+/*
+============
+FS_WriteFile
+
+The filename will be prefixed by the current game directory
+============
+*/
+qboolean FS_WriteFile (const char *filename, void *data, int len)
+{
+ FILE *handle;
+ char name[MAX_OSPATH];
+
+ sprintf (name, "%s/%s", fs_gamedir, filename);
+
+ // Create directories up to the file
+ FS_CreatePath (name);
+
+ handle = fopen (name, "wb");
+ if (!handle)
+ {
+ Con_Printf ("FS_WriteFile: failed on %s\n", name);
+ return false;
+ }
+
+ Con_DPrintf ("FS_WriteFile: %s\n", name);
+ fwrite (data, 1, len, handle);
+ fclose (handle);
+ return true;
+}
+
+
+/*
+=============================================================================
+
+OTHERS FUNCTIONS
+
+=============================================================================
+*/
+
+/*
+============
+FS_StripExtension
+============
+*/
+void FS_StripExtension (const char *in, char *out)
+{
+ char *last = NULL;
+ while (*in)
+ {
+ if (*in == '.')
+ last = out;
+ else if (*in == '/' || *in == '\\' || *in == ':')
+ last = NULL;
+ *out++ = *in++;
+ }
+ if (last)
+ *last = 0;
+ else
+ *out = 0;
+}
+
+
+/*
+==================
+FS_DefaultExtension
+==================
+*/
+void FS_DefaultExtension (char *path, const char *extension)
+{
+ const char *src;
+
+ // if path doesn't have a .EXT, append extension
+ // (extension should include the .)
+ src = path + strlen(path) - 1;
+
+ while (*src != '/' && src != path)
+ {
+ if (*src == '.')
+ return; // it has an extension
+ src--;
+ }
+
+ strcat (path, extension);
+}
+
+
+qboolean FS_FileExists (const char *filename)
+{
+ searchpath_t *search;
+ char netpath[MAX_OSPATH];
+ pack_t *pak;
+ int i;
+
+ for (search = fs_searchpaths;search;search = search->next)
+ {
+ if (search->pack)
+ {
+ pak = search->pack;
+ for (i = 0;i < pak->numfiles;i++)
+ if (!strcmp (pak->files[i].name, filename))
+ return true;
+ }
+ else
+ {
+ sprintf (netpath, "%s/%s",search->filename, filename);
+ if (FS_SysFileExists (netpath))
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+qboolean FS_SysFileExists (const char *path)
+{
+#if WIN32
+ FILE *f;
+
+ f = fopen (path, "rb");
+ if (f)
+ {
+ fclose (f);
+ return true;
+ }
+
+ return false;
+#else
+ struct stat buf;
+
+ if (stat (path,&buf) == -1)
+ return false;
+
+ return true;
+#endif
+}
+
+void FS_mkdir (const char *path)
+{
+#if WIN32
+ _mkdir (path);
+#else
+ mkdir (path, 0777);
+#endif
+}
--- /dev/null
+/*
+ Quake file system
+
+ Copyright (C) 2003 Mathieu Olivier
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to:
+
+ Free Software Foundation, Inc.
+ 59 Temple Place - Suite 330
+ Boston, MA 02111-1307, USA
+*/
+
+#ifndef QUAKEIO_H
+#define QUAKEIO_H
+
+
+// ------ Types ------ //
+
+typedef struct qfile_s qfile_t;
+
+
+// ------ Variables ------ //
+
+extern char fs_gamedir [MAX_OSPATH];
+extern char fs_basedir [MAX_OSPATH];
+
+extern int fs_filesize; // set by FS_Open and FS_LoadFile
+
+
+// ------ Main functions ------ //
+
+// NOTE: the file path is automatically prefixed by the current game directory for each
+// file created by FS_WriteFile, or opened in "write" or "append" mode by FS_Open
+
+qfile_t *FS_Open (const char* filepath, const char* mode, qboolean quiet);
+int FS_Close (qfile_t* file);
+size_t FS_Write (qfile_t* file, const void* data, size_t datasize);
+size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize);
+int FS_Flush (qfile_t* file);
+int FS_Printf (qfile_t* file, const char* format, ...);
+int FS_Getc (qfile_t* file);
+int FS_Seek (qfile_t* file, long offset, int whence);
+long FS_Tell (qfile_t* file);
+char *FS_Gets (qfile_t* file, char* buffer, int buffersize);
+char *FS_Getline (qfile_t *file); // DO NOT FREE the returned buffer
+int FS_Eof (qfile_t* file);
+
+qbyte *FS_LoadFile (const char *path, qboolean quiet);
+qboolean FS_WriteFile (const char *filename, void *data, int len);
+
+
+// ------ Other functions ------ //
+
+void FS_StripExtension (const char *in, char *out);
+void FS_DefaultExtension (char *path, const char *extension);
+
+qboolean FS_FileExists (const char *filename); // the file can be into a package
+qboolean FS_SysFileExists (const char *filename); // only look for files outside of packages
+
+void FS_mkdir (const char *path);
+
+
+#endif
}
for (i = 0;i < 6;i++)
- if (!Q_strcasecmp (modes[i].name, Cmd_Argv(1) ) )
+ if (!strcasecmp (modes[i].name, Cmd_Argv(1) ) )
break;
if (i == 6)
{
#pragma warning(disable : 4018) // LordHavoc: MSVC++ 4 x86, signed/unsigned mismatch
#endif
-#ifdef _WIN32
-#include <windows.h>
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#endif
-
-//#include <GL/gl.h>
//====================================================
*/
void Host_WriteConfiguration (void)
{
- QFile *f;
+ qfile_t *f;
// dedicated servers initialize the host but don't parse and set the
// config.cfg cvars
if (host_initialized && cls.state != ca_dedicated)
{
- f = Qopen (va("%s/config.cfg",com_gamedir), "w");
+ f = FS_Open ("config.cfg", "w", false);
if (!f)
{
Con_Printf ("Couldn't write config.cfg.\n");
Key_WriteBindings (f);
Cvar_WriteVariables (f);
- Qclose (f);
+ FS_Close (f);
}
}
//============================================================================
void Render_Init(void);
-void QuakeIO_Init(void);
/*
====================
Memory_Init_Commands();
R_Modules_Init();
Cbuf_Init ();
- QuakeIO_Init ();
V_Init ();
COM_Init ();
Host_InitLocal ();
void Host_Savegame_f (void)
{
char name[256];
- QFile *f;
+ qfile_t *f;
int i;
char comment[SAVEGAME_COMMENT_LENGTH+1];
}
}
- sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
- COM_DefaultExtension (name, ".sav");
+ strncpy (name, Cmd_Argv(1), sizeof (name) - 1);
+ name[sizeof (name) - 1] = '\0';
+ FS_DefaultExtension (name, ".sav");
Con_Printf ("Saving game to %s...\n", name);
- f = Qopen (name, "w");
+ f = FS_Open (name, "w", false);
if (!f)
{
Con_Printf ("ERROR: couldn't open.\n");
return;
}
- Qprintf (f, "%i\n", SAVEGAME_VERSION);
+ FS_Printf (f, "%i\n", SAVEGAME_VERSION);
Host_SavegameComment (comment);
- Qprintf (f, "%s\n", comment);
+ FS_Printf (f, "%s\n", comment);
for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
- Qprintf (f, "%f\n", svs.clients->spawn_parms[i]);
- Qprintf (f, "%d\n", current_skill);
- Qprintf (f, "%s\n", sv.name);
- Qprintf (f, "%f\n",sv.time);
+ FS_Printf (f, "%f\n", svs.clients->spawn_parms[i]);
+ FS_Printf (f, "%d\n", current_skill);
+ FS_Printf (f, "%s\n", sv.name);
+ FS_Printf (f, "%f\n",sv.time);
// write the light styles
for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
{
if (sv.lightstyles[i])
- Qprintf (f, "%s\n", sv.lightstyles[i]);
+ FS_Printf (f, "%s\n", sv.lightstyles[i]);
else
- Qprintf (f,"m\n");
+ FS_Printf (f,"m\n");
}
for (i=0 ; i<sv.num_edicts ; i++)
{
ED_Write (f, EDICT_NUM(i));
- Qflush (f);
+ FS_Flush (f);
}
- Qclose (f);
+ FS_Close (f);
Con_Printf ("done.\n");
}
return;
}
- sprintf (sv_loadgame, "%s/%s", com_gamedir, Cmd_Argv(1));
- COM_DefaultExtension (sv_loadgame, ".sav");
+ sprintf (sv_loadgame, "%s/%s", fs_gamedir, Cmd_Argv(1));
+ FS_DefaultExtension (sv_loadgame, ".sav");
Con_Printf ("Loading game from %s...\n", sv_loadgame);
}
void Host_PerformLoadGame(char *name)
{
- QFile *f;
+ qfile_t *f;
char mapname[MAX_QPATH];
float time, tfloat;
char buf[32768];
cls.demonum = -1; // stop demo loop in case this fails
- f = Qopen (name, "rz");
+ f = FS_Open (name, "r", false);
if (!f)
{
Con_Printf ("ERROR: couldn't open.\n");
return;
}
- str = Qgetline (f);
+ str = FS_Getline (f);
sscanf (str, "%i\n", &version);
if (version != SAVEGAME_VERSION)
{
- Qclose (f);
+ FS_Close (f);
Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
return;
}
SCR_BeginLoadingPlaque ();
- str = Qgetline (f);
+ str = FS_Getline (f);
for (i = 0;i < NUM_SPAWN_PARMS;i++)
{
- str = Qgetline (f);
+ str = FS_Getline (f);
sscanf (str, "%f\n", &spawn_parms[i]);
}
// this silliness is so we can load 1.06 save files, which have float skill values
- str = Qgetline (f);
+ str = FS_Getline (f);
sscanf (str, "%f\n", &tfloat);
current_skill = (int)(tfloat + 0.1);
Cvar_SetValue ("skill", (float)current_skill);
- strcpy (mapname, Qgetline (f));
+ strcpy (mapname, FS_Getline (f));
- str = Qgetline (f);
+ str = FS_Getline (f);
sscanf (str, "%f\n",&time);
CL_Disconnect_f ();
for (i = 0;i < MAX_LIGHTSTYLES;i++)
{
- str = Qgetline (f);
+ str = FS_Getline (f);
sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
strcpy (sv.lightstyles[i], str);
}
// load the edicts out of the savegame file
// -1 is the globals
entnum = -1;
- while (!Qeof(f))
+ while (!FS_Eof (f))
{
for (i = 0;i < (int)sizeof(buf) - 1;i++)
{
- r = Qgetc (f);
+ r = FS_Getc (f);
if (r == EOF || !r)
break;
buf[i] = r;
sv.num_edicts = entnum;
sv.time = time;
- Qclose (f);
+ FS_Close (f);
for (i = 0;i < NUM_SPAWN_PARMS;i++)
svs.clients->spawn_parms[i] = spawn_parms[i];
{
if (!client->active || !client->spawned)
continue;
- if (Q_strcasecmp(client->name, Cmd_Argv(1)))
+ if (strcasecmp(client->name, Cmd_Argv(1)))
continue;
host_client = client;
SV_ClientPrintf("%s", text);
{
if (!host_client->active)
continue;
- if (Q_strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
+ if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
break;
}
}
const qbyte *palette, *fin, *enddata;
int x, y, x2, dataByte;
- if (loadsize < (int)sizeof(pcx) + 768)
+ if (fs_filesize < (int)sizeof(pcx) + 768)
{
Con_Printf ("Bad pcx file\n");
return NULL;
image_width = pcx.xmax+1;
image_height = pcx.ymax+1;
- palette = f + loadsize - 768;
+ palette = f + fs_filesize - 768;
image_rgba = Mem_Alloc(tempmempool, image_width*image_height*4);
if (!image_rgba)
TargaHeader targa_header;
unsigned char palette[256*4], *p;
- if (loadsize < 19)
+ if (fs_filesize < 19)
return NULL;
- enddata = f + loadsize;
+ enddata = f + fs_filesize;
targa_header.id_length = f[0];
targa_header.colormap_type = f[1];
qbyte *image_rgba;
int width, height;
- if (loadsize < 9)
+ if (fs_filesize < 9)
{
Con_Printf("LoadLMP: invalid LMP file\n");
return NULL;
if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight))
return NULL;
- if (loadsize < 8 + width * height)
+ if (fs_filesize < 8 + width * height)
{
Con_Printf("LoadLMP: invalid LMP file\n");
return NULL;
qbyte *image_8bit;
int width, height;
- if (loadsize < 9)
+ if (fs_filesize < 9)
{
Con_Printf("LoadLMPAs8Bit: invalid LMP file\n");
return NULL;
if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight))
return NULL;
- if (loadsize < 8 + width * height)
+ if (fs_filesize < 8 + width * height)
{
Con_Printf("LoadLMPAs8Bit: invalid LMP file\n");
return NULL;
if (*c == '*')
*c = '#';
sprintf (name, "override/%s.tga", basename);
- f = COM_LoadFile(name, true);
+ f = FS_LoadFile(name, true);
if (f)
{
data = LoadTGA (f, matchwidth, matchheight);
goto loaded;
}
sprintf (name, "override/%s.jpg", basename);
- f = COM_LoadFile(name, true);
+ f = FS_LoadFile(name, true);
if (f)
{
data = JPEG_LoadImage (f, matchwidth, matchheight);
goto loaded;
}
sprintf (name, "textures/%s.tga", basename);
- f = COM_LoadFile(name, true);
+ f = FS_LoadFile(name, true);
if (f)
{
data = LoadTGA (f, matchwidth, matchheight);
goto loaded;
}
sprintf (name, "textures/%s.jpg", basename);
- f = COM_LoadFile(name, true);
+ f = FS_LoadFile(name, true);
if (f)
{
data = JPEG_LoadImage (f, matchwidth, matchheight);
goto loaded;
}
sprintf (name, "textures/%s.pcx", basename);
- f = COM_LoadFile(name, true);
+ f = FS_LoadFile(name, true);
if (f)
{
data = LoadPCX (f, matchwidth, matchheight);
goto loaded;
}
sprintf (name, "%s.tga", basename);
- f = COM_LoadFile(name, true);
+ f = FS_LoadFile(name, true);
if (f)
{
data = LoadTGA (f, matchwidth, matchheight);
goto loaded;
}
sprintf (name, "%s.jpg", basename);
- f = COM_LoadFile(name, true);
+ f = FS_LoadFile(name, true);
if (f)
{
data = JPEG_LoadImage (f, matchwidth, matchheight);
goto loaded;
}
sprintf (name, "%s.pcx", basename);
- f = COM_LoadFile(name, true);
+ f = FS_LoadFile(name, true);
if (f)
{
data = LoadPCX (f, matchwidth, matchheight);
goto loaded;
}
sprintf (name, "%s.lmp", basename);
- f = COM_LoadFile(name, true);
+ f = FS_LoadFile(name, true);
if (f)
{
data = LoadLMP (f, matchwidth, matchheight);
*out++ = in[1];
*out++ = in[0];
}
- ret = COM_WriteFile (filename, buffer, width*height*3 + 18 );
+ ret = FS_WriteFile (filename, buffer, width*height*3 + 18 );
Mem_Free(buffer);
return ret;
*out++ = in[0];
}
}
- COM_WriteFile (filename, buffer, width*height*3 + 18 );
+ FS_WriteFile (filename, buffer, width*height*3 + 18 );
Mem_Free(buffer);
}
*out++ = in[3];
}
}
- COM_WriteFile (filename, buffer, width*height*4 + 18 );
+ FS_WriteFile (filename, buffer, width*height*4 + 18 );
Mem_Free(buffer);
}
cinfo->src = (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr));
cinfo->src->next_input_byte = buffer;
- cinfo->src->bytes_in_buffer = com_filesize;
+ cinfo->src->bytes_in_buffer = fs_filesize;
cinfo->src->init_source = JPEG_Noop;
cinfo->src->fill_input_buffer = JPEG_FillInputBuffer;
return str[0];
for (kn=keynames ; kn->name ; kn++)
- if (!Q_strcasecmp(str,kn->name))
+ if (!strcasecmp(str,kn->name))
return kn->keynum;
return -1;
}
Writes lines containing "bind key value"
============
*/
-void Key_WriteBindings (QFile *f)
+void Key_WriteBindings (qfile_t *f)
{
int i;
for (i = 0;i < 256;i++)
if (keybindings[i] && *keybindings[i])
- Qprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
+ FS_Printf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
}
void Key_Event (int key, qboolean down);
void Key_Init (void);
-void Key_WriteBindings (QFile *f);
+void Key_WriteBindings (qfile_t *f);
void Key_SetBinding (int keynum, char *binding);
void Key_ClearStates (void);
filematch.o host.o host_cmd.o image.o mathlib.o matrixlib.o \
model_alias.o model_brush.o model_shared.o model_sprite.o \
net_bsd.o net_dgrm.o net_loop.o net_main.o net_master.o \
- net_udp.o palette.o portals.o protocol.o quakeio.o sys_linux.o \
+ net_udp.o palette.o portals.o protocol.o fs.o sys_linux.o \
sys_shared.o world.o wad.o zone.o
OBJ_COMMON= $(CLIENTOBJECTS) $(SERVEROBJECTS) $(SHAREDOBJECTS)
sbar.o snd_dma.o snd_mem.o snd_mix.o sv_main.o sv_move.o \
sv_phys.o sv_user.o sv_light.o view.o wad.o world.o zone.o vid_shared.o \
palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o \
- r_modules.o r_explosion.o r_lerpanim.o protocol.o quakeio.o ui.o \
+ r_modules.o r_explosion.o r_lerpanim.o protocol.o fs.o ui.o \
portals.o sys_shared.o gl_backend.o cl_particles.o cl_screen.o cgamevm.o \
cgame.o filematch.o collision.o cl_collision.o matrixlib.o cl_video.o \
dpvsimpledecode.o wavefile.o meshqueue.o net_master.o r_shadow.o jpeg.o
filematch.o host.o host_cmd.o image.o mathlib.o matrixlib.o \
model_alias.o model_brush.o model_shared.o model_sprite.o \
net_dgrm.o net_loop.o net_main.o net_master.o \
- palette.o portals.o protocol.o quakeio.o \
+ palette.o portals.o protocol.o fs.o \
sys_shared.o world.o wad.o zone.o
int i, j;
char name[MAX_OSPATH];
char *str;
- QFile *f;
+ qfile_t *f;
int version;
for (i=0 ; i<MAX_SAVEGAMES ; i++)
{
strcpy (m_filenames[i], "--- UNUSED SLOT ---");
loadable[i] = false;
- sprintf (name, "%s/s%i.sav", com_gamedir, i);
- f = Qopen (name, "rz");
+ sprintf (name, "%s/s%i.sav", fs_gamedir, i);
+ f = FS_Open (name, "r", false);
if (!f)
continue;
- str = Qgetline (f);
+ str = FS_Getline (f);
sscanf (str, "%i\n", &version);
- str = Qgetline (f);
+ str = FS_Getline (f);
strncpy (m_filenames[i], str, sizeof(m_filenames[i])-1);
// change _ back to space
if (m_filenames[i][j] == '_')
m_filenames[i][j] = ' ';
loadable[i] = true;
- Qclose (f);
+ FS_Close (f);
}
}
if (menuplyr_load)
{
menuplyr_load = false;
- f = COM_LoadFile("gfx/menuplyr.lmp", true);
+ f = FS_LoadFile("gfx/menuplyr.lmp", true);
if (!f)
{
menuplyr_failed = true;
if (gamemode == GAME_NEHAHRA)
{
- if (COM_FileExists("maps/neh1m4.bsp"))
+ if (FS_FileExists("maps/neh1m4.bsp"))
{
- if (COM_FileExists("hearing.dem"))
+ if (FS_FileExists("hearing.dem"))
{
Con_Printf("Nehahra movie and game detected.\n");
NehGameType = TYPE_BOTH;
}
else
{
- if (COM_FileExists("hearing.dem"))
+ if (FS_FileExists("hearing.dem"))
{
Con_Printf("Nehahra movie detected.\n");
NehGameType = TYPE_DEMO;
{
// LordHavoc: hope is not lost yet, check for a .lit file to load
strcpy(litfilename, loadmodel->name);
- COM_StripExtension(litfilename, litfilename);
+ FS_StripExtension(litfilename, litfilename);
strcat(litfilename, ".lit");
- data = (qbyte*) COM_LoadFile (litfilename, false);
+ data = (qbyte*) FS_LoadFile (litfilename, false);
if (data)
{
- if (loadsize > 8 && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
+ if (fs_filesize > 8 && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
{
i = LittleLong(((int *)data)[1]);
if (i == 1)
{
Con_DPrintf("loaded %s\n", litfilename);
- loadmodel->lightdata = Mem_Alloc(loadmodel->mempool, loadsize - 8);
- memcpy(loadmodel->lightdata, data + 8, loadsize - 8);
+ loadmodel->lightdata = Mem_Alloc(loadmodel->mempool, fs_filesize - 8);
+ memcpy(loadmodel->lightdata, data + 8, fs_filesize - 8);
Mem_Free(data);
return;
}
}
else
{
- if (loadsize == 8)
+ if (fs_filesize == 8)
Con_Printf("Empty .lit file, ignoring\n");
else
Con_Printf("Corrupt .lit file (old version?), ignoring\n");
mlight_t *e;
strcpy(lightsfilename, loadmodel->name);
- COM_StripExtension(lightsfilename, lightsfilename);
+ FS_StripExtension(lightsfilename, lightsfilename);
strcat(lightsfilename, ".lights");
- s = lightsstring = (char *) COM_LoadFile (lightsfilename, false);
+ s = lightsstring = (char *) FS_LoadFile (lightsfilename, false);
if (s)
{
numlights = 0;
{
if (checkdisk)
{
- buf = COM_LoadFile (mod->name, false);
+ buf = FS_LoadFile (mod->name, false);
if (!buf)
{
if (crash)
return NULL;
}
- crc = CRC_Block(buf, com_filesize);
+ crc = CRC_Block(buf, fs_filesize);
}
else
crc = mod->crc;
if (!buf)
{
- buf = COM_LoadFile (mod->name, false);
+ buf = FS_LoadFile (mod->name, false);
if (!buf)
{
if (crash)
Host_Error ("Mod_LoadModel: %s not found", mod->name);
return NULL;
}
- crc = CRC_Block(buf, com_filesize);
+ crc = CRC_Block(buf, fs_filesize);
}
// allocate a new model
break;
case 2:
- if (Q_strcasecmp(Cmd_Argv(1), "off") == 0)
+ if (strcasecmp(Cmd_Argv(1), "off") == 0)
banAddr = 0x00000000;
else
banAddr = inet_addr(Cmd_Argv(1));
else
{
for (s = net_activeSockets; s; s = s->next)
- if (Q_strcasecmp(Cmd_Argv(1), s->address) == 0)
+ if (strcasecmp(Cmd_Argv(1), s->address) == 0)
break;
if (s == NULL)
return;
if (host && hostCacheCount)
{
for (n = 0; n < hostCacheCount; n++)
- if (Q_strcasecmp (host, hostcache[n].name) == 0)
+ if (strcasecmp (host, hostcache[n].name) == 0)
{
if (hostcache[n].driver != myDriverLevel)
continue;
if (host && hostCacheCount)
{
for (n = 0; n < hostCacheCount; n++)
- if (Q_strcasecmp (host, hostcache[n].name) == 0)
+ if (strcasecmp (host, hostcache[n].name) == 0)
{
if (hostcache[n].driver != myDriverLevel)
continue;
{
if (i == n)
continue;
- if (Q_strcasecmp (hostcache[n].name, hostcache[i].name) == 0)
+ if (strcasecmp (hostcache[n].name, hostcache[i].name) == 0)
{
i = strlen(hostcache[n].name);
if (i < 15 && hostcache[n].name[i-1] > '8')
if (host)
{
- if (Q_strcasecmp (host, "local") == 0)
+ if (strcasecmp (host, "local") == 0)
{
net_driverlevel = 0;
return dfunc.Connect (host);
if (hostCacheCount)
{
for (n = 0; n < hostCacheCount; n++)
- if (Q_strcasecmp (host, hostcache[n].name) == 0)
+ if (strcasecmp (host, hostcache[n].name) == 0)
{
host = hostcache[n].cname;
break;
if (hostCacheCount)
for (n = 0; n < hostCacheCount; n++)
- if (Q_strcasecmp (host, hostcache[n].name) == 0)
+ if (strcasecmp (host, hostcache[n].name) == 0)
{
host = hostcache[n].cname;
break;
palette_complete[255] = 0; // completely transparent black
// FIXME: fullbright_start should be read from colormap.lmp
- colormap = COM_LoadFile("gfx/colormap.lmp", true);
- if (colormap && com_filesize >= 16385)
+ colormap = FS_LoadFile("gfx/colormap.lmp", true);
+ if (colormap && fs_filesize >= 16385)
fullbright_start = 256 - colormap[16384];
else
fullbright_start = 256;
float gamma, scale, base;
qbyte *pal;
qbyte temp[256];
- pal = (qbyte *)COM_LoadFile ("gfx/palette.lmp", false);
+ pal = (qbyte *)FS_LoadFile ("gfx/palette.lmp", false);
if (!pal)
Sys_Error ("Couldn't load gfx/palette.lmp");
memcpy(host_basepal, pal, 765);
For savegames
=============
*/
-void ED_Write (QFile *f, edict_t *ed)
+void ED_Write (qfile_t *f, edict_t *ed)
{
ddef_t *d;
int *v;
char *name;
int type;
- Qprintf (f, "{\n");
+ FS_Printf (f, "{\n");
if (ed->free)
{
- Qprintf (f, "}\n");
+ FS_Printf (f, "}\n");
return;
}
if (j == type_size[type])
continue;
- Qprintf (f,"\"%s\" ",name);
- Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
+ FS_Printf (f,"\"%s\" ",name);
+ FS_Printf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
}
- Qprintf (f, "}\n");
+ FS_Printf (f, "}\n");
}
void ED_PrintNum (int ent)
ED_WriteGlobals
=============
*/
-void ED_WriteGlobals (QFile *f)
+void ED_WriteGlobals (qfile_t *f)
{
ddef_t *def;
int i;
char *name;
int type;
- Qprintf (f,"{\n");
+ FS_Printf (f,"{\n");
for (i=0 ; i<progs->numglobaldefs ; i++)
{
def = &pr_globaldefs[i];
continue;
name = PR_GetString(def->s_name);
- Qprintf (f,"\"%s\" ", name);
- Qprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
+ FS_Printf (f,"\"%s\" ", name);
+ FS_Printf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
}
- Qprintf (f,"}\n");
+ FS_Printf (f,"}\n");
}
/*
Mem_EmptyPool(progs_mempool);
Mem_EmptyPool(edictstring_mempool);
- temp = COM_LoadFile ("progs.dat", false);
+ temp = FS_LoadFile ("progs.dat", false);
if (!temp)
Host_Error ("PR_LoadProgs: couldn't load progs.dat");
- progs = (dprograms_t *)Mem_Alloc(progs_mempool, com_filesize);
+ progs = (dprograms_t *)Mem_Alloc(progs_mempool, fs_filesize);
- memcpy(progs, temp, com_filesize);
+ memcpy(progs, temp, fs_filesize);
Mem_Free(temp);
- Con_DPrintf ("Programs occupy %iK.\n", com_filesize/1024);
+ Con_DPrintf ("Programs occupy %iK.\n", fs_filesize/1024);
- pr_crc = CRC_Block((qbyte *)progs, com_filesize);
+ pr_crc = CRC_Block((qbyte *)progs, fs_filesize);
// byte swap the header
for (i = 0;i < (int) sizeof(*progs) / 4;i++)
// returns a copy of the string allocated from the server's string heap
void ED_Print (edict_t *ed);
-void ED_Write (QFile *f, edict_t *ed);
+void ED_Write (qfile_t *f, edict_t *ed);
const char *ED_ParseEdict (const char *data, edict_t *ent);
-void ED_WriteGlobals (QFile *f);
+void ED_WriteGlobals (qfile_t *f);
void ED_ParseGlobals (const char *data);
void ED_LoadFromFile (const char *data);
#define SOUND_CHANNELS 8
#include "zone.h"
-#include "quakeio.h"
+#include "fs.h"
#include "common.h"
#include "cvar.h"
#include "bspfile.h"
+++ /dev/null
-/*
- quakeio.c
-
- (description)
-
- Copyright (C) 1996-1997 Id Software, Inc.
- Copyright (C) 1999,2000 contributors of the QuakeForge project
- Please see the file "AUTHORS" for a list of contributors
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to:
-
- Free Software Foundation, Inc.
- 59 Temple Place - Suite 330
- Boston, MA 02111-1307, USA
-
- $Id$
-*/
-
-#include "quakedef.h"
-#include <stdlib.h>
-#include <string.h>
-#ifdef WIN32
-# include <io.h>
-# include <fcntl.h>
-#else
-# include <pwd.h>
-# include <unistd.h>
-#endif
-
-#include <stdarg.h>
-#include <stdlib.h>
-#include <limits.h>
-
-#ifndef PATH_MAX
-# define PATH_MAX 512
-#endif
-
-#include "quakeio.h"
-
-#ifdef WIN32
-# ifndef __BORLANDC__
-# define setmode _setmode
-# define O_BINARY _O_BINARY
-# endif
-#endif
-
-mempool_t *quakeio_mempool;
-
-void
-Qexpand_squiggle (const char *path, char *dest)
-{
- char *home;
-
-#ifndef _WIN32
- struct passwd *pwd_ent;
-#endif
-
- if (strncmp (path, "~/", 2) != 0) {
- strcpy (dest, path);
- return;
- }
-
-#ifdef _WIN32
- // LordHavoc: first check HOME to duplicate previous version behavior
- // (also handy if someone wants it somewhere other than their
- // windows directory)
- home = getenv ("HOME");
- if (!home || !home[0])
- home = getenv ("WINDIR");
-#else
- if ((pwd_ent = getpwuid (getuid ()))) {
- home = pwd_ent->pw_dir;
- } else
- home = getenv ("HOME");
-#endif
-
- if (home) {
- strcpy (dest, home);
- strncat (dest, path + 1, MAX_OSPATH - strlen (dest)); // skip
- // leading ~
- } else
- strcpy (dest, path);
-}
-
-int
-Qrename (const char *old, const char *new)
-{
- char e_old[PATH_MAX];
- char e_new[PATH_MAX];
-
- Qexpand_squiggle (old, e_old);
- Qexpand_squiggle (new, e_new);
- return rename (e_old, e_new);
-}
-
-QFile *
-Qopen (const char *path, const char *mode)
-{
- QFile *file;
- char m[80], *p;
- int zip = 0;
- char e_path[PATH_MAX];
-
- Qexpand_squiggle (path, e_path);
- path = e_path;
-
- for (p = m; *mode && p - m < (int)(sizeof (m) - 1); mode++) {
- if (*mode == 'z') {
- zip = 1;
- continue;
- }
-#ifndef HAVE_ZLIB
- if (strchr ("0123456789fh", *mode)) {
- continue;
- }
-#endif
- *p++ = *mode;
- }
- *p = 0;
-
- file = Mem_Alloc(quakeio_mempool, sizeof (*file));
- memset(file, 0, sizeof(*file));
- if (!file)
- return 0;
-#ifdef HAVE_ZLIB
- if (zip) {
- file->gzfile = gzopen (path, m);
- if (!file->gzfile) {
- Mem_Free(file);
- return 0;
- }
- } else
-#endif
- {
- file->file = fopen (path, m);
- if (!file->file) {
- Mem_Free(file);
- return 0;
- }
- }
- return file;
-}
-
-QFile *
-Qdopen (int fd, const char *mode)
-{
- QFile *file;
- char m[80], *p;
- int zip = 0;
-
- for (p = m; *mode && p - m < (int)(sizeof (m) - 1); mode++) {
- if (*mode == 'z') {
- zip = 1;
- continue;
- }
- *p++ = *mode;
- }
-
- *p = 0;
-
- file = Mem_Alloc(quakeio_mempool, sizeof (*file));
- memset(file, 0, sizeof(*file));
- if (!file)
- return 0;
-#ifdef HAVE_ZLIB
- if (zip) {
- file->gzfile = gzdopen (fd, m);
- if (!file->gzfile) {
- Mem_Free(file);
- return 0;
- }
- } else
-#endif
- {
- file->file = fdopen (fd, m);
- if (!file->file) {
- Mem_Free(file);
- return 0;
- }
- }
-#ifdef WIN32
- if (file->file)
- setmode (_fileno (file->file), O_BINARY);
-#endif
- return file;
-}
-
-void
-Qclose (QFile *file)
-{
- if (file->file)
- fclose (file->file);
-#ifdef HAVE_ZLIB
- else
- gzclose (file->gzfile);
-#endif
- Mem_Free(file);
-}
-
-int
-Qread (QFile *file, void *buf, int count)
-{
- if (file->file)
- return fread (buf, 1, count, file->file);
-#ifdef HAVE_ZLIB
- else
- return gzread (file->gzfile, buf, count);
-#else
- return -1;
-#endif
-}
-
-int
-Qwrite (QFile *file, void *buf, int count)
-{
- if (file->file)
- return fwrite (buf, 1, count, file->file);
-#ifdef HAVE_ZLIB
- else
- return gzwrite (file->gzfile, buf, count);
-#else
- return -1;
-#endif
-}
-
-int
-Qprintf (QFile *file, const char *fmt, ...)
-{
- va_list args;
- int ret = -1;
-
- va_start (args, fmt);
- if (file->file)
- ret = vfprintf (file->file, fmt, args);
-#ifdef HAVE_ZLIB
- else {
- char buf[4096];
-
- va_start (args, fmt);
-#ifdef HAVE_VSNPRINTF
- (void) vsnprintf (buf, sizeof (buf), fmt, args);
-#else
- (void) vsprintf (buf, fmt, args);
-#endif
- va_end (args);
- ret = strlen (buf); /* some *snprintf don't return the nb
- of bytes written */
- if (ret > 0)
- ret = gzwrite (file->gzfile, buf, (unsigned) ret);
- }
-#endif
- va_end (args);
- return ret;
-}
-
-char *
-Qgets (QFile *file, char *buf, int count)
-{
- if (file->file)
- return fgets (buf, count, file->file);
-#ifdef HAVE_ZLIB
- else
- return gzgets (file->gzfile, buf, count);
-#else
- return 0;
-#endif
-}
-
-int
-Qgetc (QFile *file)
-{
- if (file->file)
- return fgetc (file->file);
-#ifdef HAVE_ZLIB
- else
- return gzgetc (file->gzfile);
-#else
- return -1;
-#endif
-}
-
-int
-Qputc (QFile *file, int c)
-{
- if (file->file)
- return fputc (c, file->file);
-#ifdef HAVE_ZLIB
- else
- return gzputc (file->gzfile, c);
-#else
- return -1;
-#endif
-}
-
-int
-Qseek (QFile *file, long offset, int whence)
-{
- if (file->file)
- return fseek (file->file, offset, whence);
-#ifdef HAVE_ZLIB
- else
- return gzseek (file->gzfile, offset, whence);
-#else
- return -1;
-#endif
-}
-
-long
-Qtell (QFile *file)
-{
- if (file->file)
- return ftell (file->file);
-#ifdef HAVE_ZLIB
- else
- return gztell (file->gzfile);
-#else
- return -1;
-#endif
-}
-
-int
-Qflush (QFile *file)
-{
- if (file->file)
- return fflush (file->file);
-#ifdef HAVE_ZLIB
- else
- return gzflush (file->gzfile, Z_SYNC_FLUSH);
-#else
- return -1;
-#endif
-}
-
-int
-Qeof (QFile *file)
-{
- if (file->file)
- return feof (file->file);
-#ifdef HAVE_ZLIB
- else
- return gzeof (file->gzfile);
-#else
- return -1;
-#endif
-}
-
-/*
-
- Qgetline
-
- Dynamic length version of Qgets. DO NOT free the buffer.
-
-*/
-char *
-Qgetline (QFile *file)
-{
- static int size = 256;
- static char *buf = 0;
- char *t;
- int len;
-
- if (!buf)
- buf = Mem_Alloc(quakeio_mempool, size);
-
- if (!Qgets (file, buf, size))
- return 0;
-
- len = strlen (buf);
- while (buf[len - 1] != '\n' && buf[len - 1] != '\r')
- {
- t = Mem_Alloc(quakeio_mempool, size + 256);
- memcpy(t, buf, size);
- Mem_Free(buf);
- size += 256;
- buf = t;
- if (!Qgets (file, buf + len, size - len))
- break;
- len = strlen (buf);
- }
- while ((len = strlen(buf)) && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
- buf[len - 1] = 0;
- return buf;
-}
-
-void QuakeIO_Init(void)
-{
- quakeio_mempool = Mem_AllocPool("file management");
-}
-
+++ /dev/null
-/*
- quakeio.h
-
- (description)
-
- Copyright (C) 1996-1997 Id Software, Inc.
- Copyright (C) 1999,2000 contributors of the QuakeForge project
- Please see the file "AUTHORS" for a list of contributors
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to:
-
- Free Software Foundation, Inc.
- 59 Temple Place - Suite 330
- Boston, MA 02111-1307, USA
-
- $Id$
-*/
-#ifndef __quakeio_h
-#define __quakeio_h
-
-//#define HAVE_ZLIB
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_ZLIB
-# include <zlib.h>
-# ifdef WIN32
-# undef FAR
-# endif
-#endif
-
-//#include "QF/gcc_attr.h"
-
-typedef struct {
- FILE *file;
-#ifdef HAVE_ZLIB
- gzFile *gzfile;
-#endif
-} QFile;
-
-void Qexpand_squiggle(const char *path, char *dest);
-int Qrename(const char *old, const char *new);
-QFile *Qopen(const char *path, const char *mode);
-QFile *Qdopen(int fd, const char *mode);
-void Qclose(QFile *file);
-int Qread(QFile *file, void *buf, int count);
-int Qwrite(QFile *file, void *buf, int count);
-//int Qprintf(QFile *file, const char *fmt, ...) __attribute__((format(printf,2,3)));
-int Qprintf(QFile *file, const char *fmt, ...);
-char *Qgets(QFile *file, char *buf, int count);
-int Qgetc(QFile *file);
-int Qputc(QFile *file, int c);
-int Qseek(QFile *file, long offset, int whence);
-long Qtell(QFile *file);
-int Qflush(QFile *file);
-int Qeof(QFile *file);
-char *Qgetline(QFile *file);
-
-#endif /*__quakeio_h*/
Con_Printf("No map loaded.\n");
return;
}
- COM_StripExtension(cl.worldmodel->name, name);
+ FS_StripExtension(cl.worldmodel->name, name);
strcat(name, ".rtlights");
- lightsstring = COM_LoadFile(name, false);
+ lightsstring = FS_LoadFile(name, false);
if (lightsstring)
{
s = lightsstring;
Con_Printf("No map loaded.\n");
return;
}
- COM_StripExtension(cl.worldmodel->name, name);
+ FS_StripExtension(cl.worldmodel->name, name);
strcat(name, ".rtlights");
bufchars = bufmaxchars = 0;
buf = NULL;
}
}
if (bufchars)
- COM_WriteFile(name, buf, bufchars);
+ FS_WriteFile(name, buf, bufchars);
if (buf)
Mem_Free(buf);
}
Con_Printf("No map loaded.\n");
return;
}
- COM_StripExtension(cl.worldmodel->name, name);
+ FS_StripExtension(cl.worldmodel->name, name);
strcat(name, ".lights");
- lightsstring = COM_LoadFile(name, false);
+ lightsstring = FS_LoadFile(name, false);
if (lightsstring)
{
s = lightsstring;
strcpy(namebuffer, "sound/");
strcat(namebuffer, s->name);
- data = COM_LoadFile(namebuffer, false);
+ data = FS_LoadFile(namebuffer, false);
if (!data)
{
return NULL;
}
- info = GetWavinfo (s->name, data, com_filesize);
+ info = GetWavinfo (s->name, data, fs_filesize);
// LordHavoc: stereo sounds are now allowed (intended for music)
if (info.channels < 1 || info.channels > 2)
{
if (cl_avidemo_soundfile == NULL)
{
sprintf (filename, "%s/dpavi.wav", com_gamedir);
- cl_avidemo_soundfile = fopen(filename, "wb");
+ cl_avidemo_soundfile = FS_Open (filename, "wb", false);
memset(out, 0, 44);
fwrite(out, 1, 44, cl_avidemo_soundfile);
// header will be filled out when file is closed
// load replacement entity file if found
entities = NULL;
if (sv_entpatch.integer)
- entities = COM_LoadFile(va("maps/%s.ent", sv.name), true);
+ entities = FS_LoadFile(va("maps/%s.ent", sv.name), true);
if (entities)
{
Con_Printf("Loaded maps/%s.ent\n", sv.name);
case clc_stringcmd:
s = MSG_ReadString ();
ret = 0;
- if (Q_strncasecmp(s, "status", 6) == 0
- || Q_strncasecmp(s, "name", 4) == 0
- || Q_strncasecmp(s, "say", 3) == 0
- || Q_strncasecmp(s, "say_team", 8) == 0
- || Q_strncasecmp(s, "tell", 4) == 0
- || Q_strncasecmp(s, "color", 5) == 0
- || Q_strncasecmp(s, "kill", 4) == 0
- || Q_strncasecmp(s, "pause", 5) == 0
- || Q_strncasecmp(s, "spawn", 5) == 0
- || Q_strncasecmp(s, "begin", 5) == 0
- || Q_strncasecmp(s, "prespawn", 8) == 0
- || Q_strncasecmp(s, "kick", 4) == 0
- || Q_strncasecmp(s, "ping", 4) == 0
- || Q_strncasecmp(s, "ban", 3) == 0
- || Q_strncasecmp(s, "pmodel", 6) == 0
- || (gamemode == GAME_NEHAHRA && (Q_strncasecmp(s, "max", 3) == 0 || Q_strncasecmp(s, "monster", 7) == 0 || Q_strncasecmp(s, "scrag", 5) == 0 || Q_strncasecmp(s, "gimme", 5) == 0 || Q_strncasecmp(s, "wraith", 6) == 0))
- || (gamemode != GAME_NEHAHRA && (Q_strncasecmp(s, "god", 3) == 0 || Q_strncasecmp(s, "notarget", 8) == 0 || Q_strncasecmp(s, "fly", 3) == 0 || Q_strncasecmp(s, "give", 4) == 0 || Q_strncasecmp(s, "noclip", 6) == 0)))
+ if (strncasecmp(s, "status", 6) == 0
+ || strncasecmp(s, "name", 4) == 0
+ || strncasecmp(s, "say", 3) == 0
+ || strncasecmp(s, "say_team", 8) == 0
+ || strncasecmp(s, "tell", 4) == 0
+ || strncasecmp(s, "color", 5) == 0
+ || strncasecmp(s, "kill", 4) == 0
+ || strncasecmp(s, "pause", 5) == 0
+ || strncasecmp(s, "spawn", 5) == 0
+ || strncasecmp(s, "begin", 5) == 0
+ || strncasecmp(s, "prespawn", 8) == 0
+ || strncasecmp(s, "kick", 4) == 0
+ || strncasecmp(s, "ping", 4) == 0
+ || strncasecmp(s, "ban", 3) == 0
+ || strncasecmp(s, "pmodel", 6) == 0
+ || (gamemode == GAME_NEHAHRA && (strncasecmp(s, "max", 3) == 0 || strncasecmp(s, "monster", 7) == 0 || strncasecmp(s, "scrag", 5) == 0 || strncasecmp(s, "gimme", 5) == 0 || strncasecmp(s, "wraith", 6) == 0))
+ || (gamemode != GAME_NEHAHRA && (strncasecmp(s, "god", 3) == 0 || strncasecmp(s, "notarget", 8) == 0 || strncasecmp(s, "fly", 3) == 0 || strncasecmp(s, "give", 4) == 0 || strncasecmp(s, "noclip", 6) == 0)))
{
ret = 1;
Cmd_ExecuteString (s, src_client);
void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
-//
-// file IO
-//
-
-// returns the file size
-// return -1 if file is not present
-// the file should be in BINARY mode for stupid OSs that care
-int Sys_FileOpenRead (const char *path, int *hndl);
-
-int Sys_FileOpenWrite (const char *path);
-void Sys_FileClose (int handle);
-void Sys_FileSeek (int handle, int position);
-int Sys_FileRead (int handle, void *dest, int count);
-int Sys_FileWrite (int handle, void *data, int count);
-int Sys_FileTime (const char *path);
-void Sys_mkdir (const char *path);
-
//
// system IO
//
#include "quakedef.h"
#include <time.h>
-#ifdef WIN32
-#include <direct.h>
-#else
-#include <sys/stat.h>
+#ifndef WIN32
#include <unistd.h>
#include <fcntl.h>
#endif
-#include <errno.h>
extern cvar_t timestamps;
extern cvar_t timeformat;
#endif
va_start (argptr, fmt);
-#ifdef HAVE_VSNPRINTF
vsnprintf (start, sizeof(start), fmt, argptr);
-#else
- vsprintf (start, fmt, argptr);
-#endif
va_end (argptr);
if (sys_nostdout)
#endif
}
-// LordHavoc: 256 pak files (was 10)
-#define MAX_HANDLES 256
-QFile *sys_handles[MAX_HANDLES];
-
-int findhandle (void)
-{
- int i;
-
- for (i = 1;i < MAX_HANDLES;i++)
- if (!sys_handles[i])
- return i;
- Sys_Error ("out of handles");
- return -1;
-}
-
-/*
-================
-Sys_FileLength
-================
-*/
-int Sys_FileLength (QFile *f)
-{
- int pos, end;
-
- pos = Qtell (f);
- Qseek (f, 0, SEEK_END);
- end = Qtell (f);
- Qseek (f, pos, SEEK_SET);
-
- return end;
-}
-
-int Sys_FileOpenRead (const char *path, int *handle)
-{
- QFile *f;
- int i, retval;
-
- i = findhandle ();
-
- f = Qopen(path, "rbz");
-
- if (!f)
- {
- *handle = -1;
- retval = -1;
- }
- else
- {
- sys_handles[i] = f;
- *handle = i;
- retval = Sys_FileLength(f);
- }
-
- return retval;
-}
-
-int Sys_FileOpenWrite (const char *path)
-{
- QFile *f;
- int i;
-
- i = findhandle ();
-
- f = Qopen(path, "wb");
- if (!f)
- {
- Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno));
- return 0;
- }
- sys_handles[i] = f;
-
- return i;
-}
-
-void Sys_FileClose (int handle)
-{
- Qclose (sys_handles[handle]);
- sys_handles[handle] = NULL;
-}
-
-void Sys_FileSeek (int handle, int position)
-{
- Qseek (sys_handles[handle], position, SEEK_SET);
-}
-
-int Sys_FileRead (int handle, void *dest, int count)
-{
- return Qread (sys_handles[handle], dest, count);
-}
-
-int Sys_FileWrite (int handle, void *data, int count)
-{
- return Qwrite (sys_handles[handle], data, count);
-}
-
-int Sys_FileTime (const char *path)
-{
-#if WIN32
- QFile *f;
-
- f = Qopen(path, "rb");
- if (f)
- {
- Qclose(f);
- return 1;
- }
-
- return -1;
-#else
- struct stat buf;
-
- if (stat (path,&buf) == -1)
- return -1;
-
- return buf.st_mtime;
-#endif
-}
-
-void Sys_mkdir (const char *path)
-{
-#if WIN32
- _mkdir (path);
-#else
- mkdir (path, 0777);
-#endif
-}
char engineversion[128];
void Sys_Shared_EarlyInit(void)
{
+ const char* os;
+
Memory_Init ();
COM_InitArgv();
COM_InitGameType();
#if defined(__linux__)
- sprintf (engineversion, "%s Linux %s", gamename, buildstring);
+ os = "Linux";
#elif defined(WIN32)
- sprintf (engineversion, "%s Windows %s", gamename, buildstring);
+ os = "Windows";
#else
- sprintf (engineversion, "%s Unknown %s", gamename, buildstring);
+ os = "Unknown";
#endif
+ snprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
if (COM_CheckParm("-nostdout"))
sys_nostdout = 1;
int infotableofs;
void *temp;
- temp = COM_LoadFile (filename, false);
+ temp = FS_LoadFile (filename, false);
if (!temp)
Sys_Error ("W_LoadWadFile: couldn't load %s", filename);
if (wad_mempool)
Mem_FreePool(&wad_mempool);
wad_mempool = Mem_AllocPool(filename);
- wad_base = Mem_Alloc(wad_mempool, loadsize);
+ wad_base = Mem_Alloc(wad_mempool, fs_filesize);
- memcpy(wad_base, temp, loadsize);
+ memcpy(wad_base, temp, fs_filesize);
Mem_Free(temp);
header = (wadinfo_t *)wad_base;
typedef struct
{
char name[16];
- QFile *file;
+ qfile_t *file;
int position;
int size;
} texwadlump_t;
wadinfo_t header;
int i, j;
int infotableofs;
- QFile *file;
+ qfile_t *file;
int numlumps;
- COM_FOpenFile (filename, &file, false, false);
+ file = FS_Open (filename, "rb", false);
if (!file)
{
if (complain)
return;
}
- if (Qread(file, &header, sizeof(wadinfo_t)) != sizeof(wadinfo_t))
+ if (FS_Read(file, &header, sizeof(wadinfo_t)) != sizeof(wadinfo_t))
{Con_Printf ("W_LoadTextureWadFile: unable to read wad header");return;}
if(memcmp(header.identification, "WAD3", 4))
if (numlumps < 1 || numlumps > TEXWAD_MAXIMAGES)
{Con_Printf ("W_LoadTextureWadFile: invalid number of lumps (%i)\n", numlumps);return;}
infotableofs = LittleLong(header.infotableofs);
- if (Qseek(file, infotableofs, SEEK_SET))
+ if (FS_Seek (file, infotableofs, SEEK_SET))
{Con_Printf ("W_LoadTextureWadFile: unable to seek to lump table");return;}
if (!(lumps = Mem_Alloc(tempmempool, sizeof(lumpinfo_t)*numlumps)))
{Con_Printf ("W_LoadTextureWadFile: unable to allocate temporary memory for lump table");return;}
- if (Qread(file, lumps, sizeof(lumpinfo_t) * numlumps) != (int)sizeof(lumpinfo_t) * numlumps)
+ if (FS_Read(file, lumps, sizeof(lumpinfo_t) * numlumps) != (int)sizeof(lumpinfo_t) * numlumps)
{Con_Printf ("W_LoadTextureWadFile: unable to read lump table");return;}
for (i=0, lump_p = lumps ; i<numlumps ; i++,lump_p++)
{
char texname[17];
int i, j;
- QFile *file;
+ qfile_t *file;
miptex_t *tex;
qbyte *data;
if (!strcmp(texname, texwadlump[i].name)) // found it
{
file = texwadlump[i].file;
- if (Qseek(file, texwadlump[i].position, SEEK_SET))
+ if (FS_Seek(file, texwadlump[i].position, SEEK_SET))
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
tex = Mem_Alloc(tempmempool, texwadlump[i].size);
if (!tex)
return NULL;
- if (Qread(file, tex, texwadlump[i].size) < texwadlump[i].size)
+ if (FS_Read(file, tex, texwadlump[i].size) < texwadlump[i].size)
{Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
tex->width = LittleLong(tex->width);
+#include "quakedef.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int validfmt, position, length, l;
char *error;
wavefile_t *w;
- FILE *file;
+ qfile_t *file;
unsigned char buffer[1024];
error = NULL;
- file = fopen(filename, "rb");
+ file = FS_Open (filename, "rb", true);
if (file)
{
w = malloc(sizeof(*w));
if (w)
{
w->file = file;
- if (fread(buffer, 12, 1, w->file))
+ if (FS_Read (w->file, buffer, 12))
{
if (!memcmp(buffer, "RIFF", 4))
{
validfmt = 0;
for(;;)
{
- if (!fread(buffer, 8, 1, w->file))
+ if (!FS_Read(w->file, buffer, 8))
{
//error = "error reading chunk\n");
break;
}
- position = ftell(w->file);
+ position = FS_Tell(w->file);
length = buffer[4] | (buffer[5] << 8) | (buffer[6] << 16) | (buffer[7] << 24);
if (!memcmp(buffer, "fmt ", 4))
{
l = length;
if (l > 16)
l = 16;
- if (!fread(buffer, l, 1, w->file))
+ if (!FS_Read(w->file, buffer, l))
{
error = "error reading \"fmt \" chunk\n";
break;
}
// other chunks that might be of interest:
// "cue " (for looping)
- if (fseek(w->file, position + length, SEEK_SET))
+ if (FS_Seek(w->file, position + length, SEEK_SET))
{
error = "error seeking to next chunk\n";
break;
w->info_bytespersample = w->info_channels * w->info_bytesperchannel;
w->length = w->datalength / w->info_bytespersample;
w->position = 0;
- fseek(w->file, w->dataposition, SEEK_SET);
+ FS_Seek(w->file, w->dataposition, SEEK_SET);
return w;
}
}
}
else
error = "unable to allocate memory\n";
- fclose(file);
+ FS_Close(file);
}
else
error = "unable to open file\n";
{
if (f)
{
- fclose(f->file);
+ FS_Close(f->file);
free(f);
}
}
w->bufferlength = length + 100;
w->buffer = malloc(w->bufferlength * w->info_bytespersample);
}
- length = fread(w->buffer, w->info_bytespersample, length, w->file);
+ length = FS_Read(w->file, w->buffer, w->info_bytespersample * length);
w->position += length;
if (length > 0)
{
else
{
w->position = samples;
- fseek(w->file, w->dataposition + w->position * w->info_bytespersample, SEEK_SET);
+ FS_Seek(w->file, w->dataposition + w->position * w->info_bytespersample, SEEK_SET);
return 0;
}
}
#ifndef WAVEFILE_H
#define WAVEFILE_H
+#include "quakedef.h"
+
typedef struct wavefile_s
{
// file this is reading from
- FILE *file;
+ qfile_t *file;
// these settings are read directly from the wave format
// 1 is uncompressed PCM