2000-01-27 17:06:02 +00:00
|
|
|
/*
|
2000-03-24 13:34:14 +00:00
|
|
|
quakefs.c
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
virtual filesystem functions
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999,2000 Nelson Rush.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
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.
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
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.
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
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$
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
#include <config.h>
|
2000-01-27 17:06:02 +00:00
|
|
|
#include <ctype.h>
|
2000-05-01 08:57:11 +00:00
|
|
|
#include <limits.h>
|
2000-02-20 21:19:50 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2000-02-03 00:34:12 +00:00
|
|
|
#include <unistd.h>
|
2000-02-20 21:19:50 +00:00
|
|
|
#endif
|
2000-02-03 00:34:12 +00:00
|
|
|
#include <fcntl.h>
|
2000-02-02 05:07:29 +00:00
|
|
|
#include <qtypes.h>
|
|
|
|
#include <quakefs.h>
|
|
|
|
#include <sys.h>
|
|
|
|
#include <console.h>
|
|
|
|
#include <common_quakedef.h>
|
|
|
|
#include <zone.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <draw.h>
|
2000-04-27 04:55:43 +00:00
|
|
|
#include <cvars.h>
|
2000-04-27 09:25:38 +00:00
|
|
|
#include <cmd.h>
|
|
|
|
#if defined(QUAKEWORLD) && defined(SERVERONLY)
|
|
|
|
#include <common_protocol.h>
|
|
|
|
#include <server.h>
|
|
|
|
#endif
|
2000-03-11 00:46:46 +00:00
|
|
|
|
2000-03-08 01:12:26 +00:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <fnmatch.h>
|
2000-03-11 00:46:46 +00:00
|
|
|
|
2000-02-20 21:19:50 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
QUAKE FILESYSTEM
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
2000-03-04 02:39:12 +00:00
|
|
|
char gamedirfile[MAX_OSPATH];
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
cvar_t *fs_basepath;
|
|
|
|
cvar_t *fs_sharepath;
|
|
|
|
|
2000-03-04 01:55:01 +00:00
|
|
|
#ifdef GENERATIONS
|
|
|
|
#include <unzip.h>
|
2000-01-27 17:06:02 +00:00
|
|
|
typedef unsigned char byte_t;
|
|
|
|
|
|
|
|
#ifndef _AIX
|
|
|
|
typedef unsigned int uint_t;
|
|
|
|
typedef unsigned short ushort_t;
|
|
|
|
#endif
|
2000-02-03 08:46:52 +00:00
|
|
|
#endif
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-02-03 11:29:22 +00:00
|
|
|
int com_filesize;
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-02-03 11:29:22 +00:00
|
|
|
/*
|
|
|
|
In-memory pack file structs
|
|
|
|
*/
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char name[MAX_QPATH];
|
|
|
|
int filepos, filelen;
|
|
|
|
} packfile_t;
|
|
|
|
|
|
|
|
typedef struct pack_s
|
|
|
|
{
|
|
|
|
char filename[MAX_OSPATH];
|
2000-02-08 07:23:09 +00:00
|
|
|
QFile *handle;
|
2000-01-27 17:06:02 +00:00
|
|
|
int numfiles;
|
|
|
|
packfile_t *files;
|
|
|
|
} pack_t;
|
|
|
|
|
2000-02-03 11:29:22 +00:00
|
|
|
/*
|
|
|
|
Structs for pack files on disk
|
|
|
|
*/
|
2000-01-27 17:06:02 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char name[56];
|
|
|
|
int filepos, filelen;
|
|
|
|
} dpackfile_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char id[4];
|
|
|
|
int dirofs;
|
|
|
|
int dirlen;
|
|
|
|
} dpackheader_t;
|
|
|
|
|
|
|
|
#define MAX_FILES_IN_PACK 2048
|
|
|
|
|
|
|
|
char com_gamedir[MAX_OSPATH];
|
|
|
|
|
|
|
|
typedef struct searchpath_s
|
|
|
|
{
|
|
|
|
char filename[MAX_OSPATH];
|
|
|
|
pack_t *pack; // only one of filename / pack will be used
|
|
|
|
struct searchpath_s *next;
|
|
|
|
} searchpath_t;
|
|
|
|
|
|
|
|
searchpath_t *com_searchpaths;
|
|
|
|
searchpath_t *com_base_searchpaths; // without gamedirs
|
|
|
|
|
|
|
|
/*
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_filelength
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-04-18 09:24:29 +00:00
|
|
|
int
|
|
|
|
COM_filelength (QFile *f)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
int end;
|
|
|
|
|
2000-02-08 07:23:09 +00:00
|
|
|
pos = Qtell (f);
|
|
|
|
Qseek (f, 0, SEEK_END);
|
|
|
|
end = Qtell (f);
|
|
|
|
Qseek (f, pos, SEEK_SET);
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
/*
|
|
|
|
COM_FileOpenRead
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
COM_FileOpenRead (char *path, QFile **hndl)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-02-08 07:23:09 +00:00
|
|
|
QFile *f;
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-02-08 20:59:36 +00:00
|
|
|
f = Qopen(path, "rbz");
|
2000-01-27 17:06:02 +00:00
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
*hndl = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*hndl = f;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
return COM_filelength(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_Path_f
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-04-18 09:24:29 +00:00
|
|
|
void
|
|
|
|
COM_Path_f (void)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
searchpath_t *s;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
Con_Printf ("Current search path:\n");
|
|
|
|
for (s=com_searchpaths ; s ; s=s->next)
|
|
|
|
{
|
|
|
|
if (s == com_base_searchpaths)
|
|
|
|
Con_Printf ("----------\n");
|
|
|
|
if (s->pack)
|
|
|
|
Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles);
|
|
|
|
else
|
|
|
|
Con_Printf ("%s\n", s->filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-31 05:58:16 +00:00
|
|
|
/*
|
2000-04-01 09:59:35 +00:00
|
|
|
COM_Maplist_f
|
2000-03-31 05:58:16 +00:00
|
|
|
|
2000-04-01 09:59:35 +00:00
|
|
|
List map files in gamepaths.
|
2000-03-31 05:58:16 +00:00
|
|
|
*/
|
2000-04-01 09:59:35 +00:00
|
|
|
void
|
|
|
|
COM_Maplist_f ( void )
|
2000-03-31 00:49:19 +00:00
|
|
|
{
|
|
|
|
searchpath_t *search;
|
2000-04-01 09:59:35 +00:00
|
|
|
DIR *dir_ptr;
|
2000-03-31 00:49:19 +00:00
|
|
|
struct dirent *dirent;
|
2000-04-01 09:59:35 +00:00
|
|
|
char buf[MAX_OSPATH];
|
2000-03-31 00:49:19 +00:00
|
|
|
|
2000-04-01 09:59:35 +00:00
|
|
|
for (search = com_searchpaths ; search != NULL ; search = search->next) {
|
2000-03-31 04:46:53 +00:00
|
|
|
if (search->pack) {
|
|
|
|
int i;
|
|
|
|
pack_t *pak = search->pack;
|
2000-03-31 20:14:14 +00:00
|
|
|
Con_Printf ("Looking in %s...\n",search->pack->filename);
|
2000-03-31 04:46:53 +00:00
|
|
|
for (i=0 ; i<pak->numfiles ; i++) {
|
|
|
|
char *name=pak->files[i].name;
|
|
|
|
if (!fnmatch ("maps/*.bsp", name, FNM_PATHNAME)
|
|
|
|
|| !fnmatch ("maps/*.bsp.gz", name, FNM_PATHNAME))
|
|
|
|
Con_Printf ("%s\n", name+5);
|
2000-03-31 00:49:19 +00:00
|
|
|
}
|
2000-03-31 04:46:53 +00:00
|
|
|
} else {
|
|
|
|
snprintf (buf, sizeof(buf), "%s/maps", search->filename);
|
|
|
|
dir_ptr = opendir(buf);
|
|
|
|
Con_Printf ("Looking in %s...\n",buf);
|
|
|
|
if (!dir_ptr)
|
|
|
|
continue;
|
|
|
|
while ((dirent = readdir (dir_ptr)))
|
2000-04-01 09:59:35 +00:00
|
|
|
if (!fnmatch ("*.bsp", dirent->d_name, 0)
|
|
|
|
|| !fnmatch ("*.bsp.gz", dirent->d_name, 0))
|
2000-03-31 04:46:53 +00:00
|
|
|
Con_Printf ("%s\n", dirent->d_name);
|
|
|
|
closedir (dir_ptr);
|
2000-03-31 00:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
/*
|
2000-04-01 09:59:35 +00:00
|
|
|
COM_WriteFile
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-01 09:59:35 +00:00
|
|
|
The filename will be prefixed by the current game directory
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-04-01 09:59:35 +00:00
|
|
|
void
|
|
|
|
COM_WriteFile ( char *filename, void *data, int len )
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-02-08 07:23:09 +00:00
|
|
|
QFile *f;
|
2000-01-27 17:06:02 +00:00
|
|
|
char name[MAX_OSPATH];
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
snprintf(name, sizeof(name), "%s/%s", com_gamedir, filename);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-02-08 07:23:09 +00:00
|
|
|
f = Qopen (name, "wb");
|
2000-01-27 17:06:02 +00:00
|
|
|
if (!f) {
|
|
|
|
Sys_mkdir(com_gamedir);
|
2000-02-08 07:23:09 +00:00
|
|
|
f = Qopen (name, "wb");
|
2000-01-27 17:06:02 +00:00
|
|
|
if (!f)
|
|
|
|
Sys_Error ("Error opening %s", filename);
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
Sys_Printf ("COM_WriteFile: %s\n", name);
|
2000-02-08 07:23:09 +00:00
|
|
|
Qwrite (f, data, len);
|
|
|
|
Qclose (f);
|
2000-01-27 17:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-04-01 09:59:35 +00:00
|
|
|
COM_CreatePath
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-01 09:59:35 +00:00
|
|
|
Only used for CopyFile and download
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-04-01 09:59:35 +00:00
|
|
|
void
|
|
|
|
COM_CreatePath ( char *path )
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
char *ofs;
|
2000-04-30 10:50:24 +00:00
|
|
|
char e_path[PATH_MAX];
|
|
|
|
|
|
|
|
Qexpand_squiggle (path, e_path);
|
|
|
|
path = e_path;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-04-01 09:59:35 +00:00
|
|
|
for (ofs = path+1 ; *ofs ; ofs++) {
|
|
|
|
if (*ofs == '/') { // create the directory
|
2000-01-27 17:06:02 +00:00
|
|
|
*ofs = 0;
|
|
|
|
Sys_mkdir (path);
|
|
|
|
*ofs = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_CopyFile
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
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.
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-04-18 09:24:29 +00:00
|
|
|
void
|
|
|
|
COM_CopyFile (char *netpath, char *cachepath)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-02-08 07:23:09 +00:00
|
|
|
QFile *in, *out;
|
2000-01-27 17:06:02 +00:00
|
|
|
int remaining, count;
|
|
|
|
char buf[4096];
|
2000-03-19 15:59:51 +00:00
|
|
|
|
|
|
|
remaining = COM_FileOpenRead (netpath, &in);
|
2000-01-27 17:06:02 +00:00
|
|
|
COM_CreatePath (cachepath); // create directories up to the cache file
|
2000-02-08 07:23:09 +00:00
|
|
|
out = Qopen(cachepath, "wb");
|
2000-01-27 17:06:02 +00:00
|
|
|
if (!out)
|
|
|
|
Sys_Error ("Error opening %s", cachepath);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
while (remaining)
|
|
|
|
{
|
|
|
|
if (remaining < sizeof(buf))
|
|
|
|
count = remaining;
|
|
|
|
else
|
|
|
|
count = sizeof(buf);
|
2000-02-08 07:23:09 +00:00
|
|
|
Qread (in, buf, count);
|
|
|
|
Qwrite (out, buf, count);
|
2000-01-27 17:06:02 +00:00
|
|
|
remaining -= count;
|
|
|
|
}
|
|
|
|
|
2000-02-08 07:23:09 +00:00
|
|
|
Qclose (in);
|
|
|
|
Qclose (out);
|
2000-01-27 17:06:02 +00:00
|
|
|
}
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
/*
|
|
|
|
COM_OpenRead
|
|
|
|
*/
|
|
|
|
QFile *
|
|
|
|
COM_OpenRead (const char *path, int offs, int len)
|
2000-02-03 00:34:12 +00:00
|
|
|
{
|
2000-02-08 07:23:09 +00:00
|
|
|
int fd=open(path,O_RDONLY);
|
2000-02-03 00:34:12 +00:00
|
|
|
unsigned char id[2];
|
|
|
|
unsigned char 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);
|
|
|
|
}
|
|
|
|
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;
|
2000-02-08 20:59:36 +00:00
|
|
|
return Qdopen(fd,"rbz");
|
2000-02-08 05:06:58 +00:00
|
|
|
return 0;
|
2000-02-03 00:34:12 +00:00
|
|
|
}
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
int file_from_pak; // global indicating file came from pack file ZOID
|
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
/*
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_FOpenFile
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
Finds the file in the search path.
|
|
|
|
Sets com_filesize and one of handle or file
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-04-18 09:24:29 +00:00
|
|
|
int
|
|
|
|
COM_FOpenFile (char *filename, QFile **gzfile)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
searchpath_t *search;
|
|
|
|
char netpath[MAX_OSPATH];
|
|
|
|
pack_t *pak;
|
|
|
|
int i;
|
|
|
|
int findtime;
|
2000-02-03 21:44:46 +00:00
|
|
|
#ifdef HAS_ZLIB
|
2000-01-30 22:46:30 +00:00
|
|
|
char gzfilename[MAX_OSPATH];
|
2000-05-05 01:24:05 +00:00
|
|
|
int filenamelen;;
|
2000-01-30 22:46:30 +00:00
|
|
|
|
2000-05-05 01:24:05 +00:00
|
|
|
filenamelen = strlen(filename);
|
2000-01-30 22:46:30 +00:00
|
|
|
strncpy(gzfilename,filename,sizeof(gzfilename));
|
|
|
|
strncat(gzfilename,".gz",sizeof(gzfilename));
|
2000-02-03 21:44:46 +00:00
|
|
|
#endif
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
file_from_pak = 0;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
//
|
|
|
|
// search through the path, one element at a time
|
|
|
|
//
|
|
|
|
for (search = com_searchpaths ; search ; search = search->next)
|
|
|
|
{
|
|
|
|
// is the element a pak file?
|
|
|
|
if (search->pack)
|
|
|
|
{
|
|
|
|
// look through all the pak file elements
|
|
|
|
pak = search->pack;
|
2000-01-30 22:46:30 +00:00
|
|
|
for (i=0 ; i<pak->numfiles ; i++) {
|
|
|
|
char *fn=0;
|
2000-05-05 01:24:05 +00:00
|
|
|
#ifdef HAS_ZLIB
|
|
|
|
if (!strncmp(pak->files[i].name, filename, filenamelen)) {
|
|
|
|
if (!pak->files[i].name[filenamelen])
|
|
|
|
fn=filename;
|
|
|
|
else if (!strcmp (pak->files[i].name, gzfilename))
|
|
|
|
fn=gzfilename;
|
|
|
|
}
|
|
|
|
#else
|
2000-01-27 17:06:02 +00:00
|
|
|
if (!strcmp (pak->files[i].name, filename))
|
2000-01-30 22:46:30 +00:00
|
|
|
fn=filename;
|
2000-02-03 21:44:46 +00:00
|
|
|
#endif
|
2000-01-30 22:46:30 +00:00
|
|
|
if (fn)
|
2000-01-27 17:06:02 +00:00
|
|
|
{ // found it!
|
2000-02-27 18:51:50 +00:00
|
|
|
if (developer->value)
|
2000-01-30 22:46:30 +00:00
|
|
|
Sys_Printf ("PackFile: %s : %s\n",pak->filename, fn);
|
2000-02-27 18:51:50 +00:00
|
|
|
// open a new file on the pakfile
|
2000-02-08 07:23:09 +00:00
|
|
|
*gzfile=COM_OpenRead(pak->filename,pak->files[i].filepos,
|
|
|
|
pak->files[i].filelen);
|
2000-01-27 17:06:02 +00:00
|
|
|
file_from_pak = 1;
|
|
|
|
return com_filesize;
|
|
|
|
}
|
2000-01-30 22:46:30 +00:00
|
|
|
}
|
2000-01-27 17:06:02 +00:00
|
|
|
}
|
|
|
|
else
|
2000-03-19 15:59:51 +00:00
|
|
|
{
|
2000-01-27 17:06:02 +00:00
|
|
|
// check a file in the directory tree
|
2000-01-30 22:46:30 +00:00
|
|
|
snprintf(netpath, sizeof(netpath), "%s/%s",search->filename,
|
|
|
|
filename);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
findtime = Sys_FileTime (netpath);
|
2000-01-30 22:46:30 +00:00
|
|
|
if (findtime == -1) {
|
2000-02-03 21:44:46 +00:00
|
|
|
#ifdef HAS_ZLIB
|
2000-01-30 22:46:30 +00:00
|
|
|
snprintf(netpath, sizeof(netpath), "%s/%s",search->filename,
|
|
|
|
gzfilename);
|
|
|
|
findtime = Sys_FileTime (netpath);
|
|
|
|
if (findtime == -1)
|
2000-02-03 21:44:46 +00:00
|
|
|
#endif
|
2000-01-30 22:46:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-02-27 07:13:32 +00:00
|
|
|
if(developer->value)
|
2000-01-27 17:06:02 +00:00
|
|
|
Sys_Printf ("FindFile: %s\n",netpath);
|
|
|
|
|
2000-02-08 07:23:09 +00:00
|
|
|
*gzfile=COM_OpenRead(netpath,-1,-1);
|
2000-02-03 00:34:12 +00:00
|
|
|
return com_filesize;
|
2000-01-27 17:06:02 +00:00
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
Sys_Printf ("FindFile: can't find %s\n", filename);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-02-03 00:34:12 +00:00
|
|
|
*gzfile = NULL;
|
2000-01-27 17:06:02 +00:00
|
|
|
com_filesize = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cache_user_t *loadcache;
|
|
|
|
byte *loadbuf;
|
|
|
|
int loadsize;
|
2000-04-18 09:24:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
COM_LoadFile
|
|
|
|
|
|
|
|
Filename are relative to the quake directory.
|
|
|
|
Allways appends a 0 byte to the loaded data.
|
|
|
|
*/
|
|
|
|
byte *
|
|
|
|
COM_LoadFile (char *path, int usehunk)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-02-08 05:06:58 +00:00
|
|
|
QFile *h;
|
2000-01-27 17:06:02 +00:00
|
|
|
byte *buf;
|
|
|
|
char base[32];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
buf = NULL; // quiet compiler warning
|
|
|
|
|
|
|
|
// look for it in the filesystem or pack files
|
|
|
|
len = com_filesize = COM_FOpenFile (path, &h);
|
|
|
|
if (!h)
|
|
|
|
return NULL;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
// extract the filename base name for hunk tag
|
|
|
|
COM_FileBase (path, base);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
if (usehunk == 1)
|
|
|
|
buf = Hunk_AllocName (len+1, base);
|
|
|
|
else if (usehunk == 2)
|
|
|
|
buf = Hunk_TempAlloc (len+1);
|
|
|
|
else if (usehunk == 0)
|
|
|
|
buf = Z_Malloc (len+1);
|
|
|
|
else if (usehunk == 3)
|
|
|
|
buf = Cache_Alloc (loadcache, len+1, base);
|
|
|
|
else if (usehunk == 4)
|
|
|
|
{
|
|
|
|
if (len+1 > loadsize)
|
|
|
|
buf = Hunk_TempAlloc (len+1);
|
|
|
|
else
|
|
|
|
buf = loadbuf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Sys_Error ("COM_LoadFile: bad usehunk");
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
Sys_Error ("COM_LoadFile: not enough space for %s", path);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
((byte *)buf)[len] = 0;
|
|
|
|
#ifndef SERVERONLY
|
|
|
|
Draw_BeginDisc ();
|
|
|
|
#endif
|
2000-02-08 05:06:58 +00:00
|
|
|
Qread (h, buf, len);
|
|
|
|
Qclose (h);
|
2000-01-27 17:06:02 +00:00
|
|
|
#ifndef SERVERONLY
|
|
|
|
Draw_EndDisc ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
byte *
|
|
|
|
COM_LoadHunkFile (char *path)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
return COM_LoadFile (path, 1);
|
|
|
|
}
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
byte *
|
|
|
|
COM_LoadTempFile (char *path)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
return COM_LoadFile (path, 2);
|
|
|
|
}
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
void
|
|
|
|
COM_LoadCacheFile (char *path, struct cache_user_s *cu)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
loadcache = cu;
|
|
|
|
COM_LoadFile (path, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
// uses temp hunk if larger than bufsize
|
2000-04-18 09:24:29 +00:00
|
|
|
byte *
|
|
|
|
COM_LoadStackFile (char *path, void *buffer, int bufsize)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
byte *buf;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
loadbuf = (byte *)buffer;
|
|
|
|
loadsize = bufsize;
|
|
|
|
buf = COM_LoadFile (path, 4);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_LoadPackFile
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
Takes an explicit (not game tree related) path to a pak file.
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
Loads the header and directory, adding the files at the beginning
|
|
|
|
of the list so they override previous pack files.
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-04-18 09:24:29 +00:00
|
|
|
pack_t *
|
|
|
|
COM_LoadPackFile (char *packfile)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-03-02 19:57:24 +00:00
|
|
|
dpackheader_t header;
|
|
|
|
int i;
|
2000-01-27 17:06:02 +00:00
|
|
|
packfile_t *newfiles;
|
2000-03-02 19:57:24 +00:00
|
|
|
int numpackfiles;
|
2000-01-27 17:06:02 +00:00
|
|
|
pack_t *pack;
|
2000-02-08 07:23:09 +00:00
|
|
|
QFile *packhandle;
|
2000-01-27 17:06:02 +00:00
|
|
|
dpackfile_t info[MAX_FILES_IN_PACK];
|
|
|
|
|
|
|
|
if (COM_FileOpenRead (packfile, &packhandle) == -1)
|
|
|
|
return NULL;
|
|
|
|
|
2000-02-08 07:23:09 +00:00
|
|
|
Qread (packhandle, &header, sizeof(header));
|
2000-01-27 17:06:02 +00:00
|
|
|
if (header.id[0] != 'P' || header.id[1] != 'A'
|
|
|
|
|| header.id[2] != 'C' || header.id[3] != 'K')
|
|
|
|
Sys_Error ("%s is not a packfile", packfile);
|
|
|
|
header.dirofs = LittleLong (header.dirofs);
|
|
|
|
header.dirlen = LittleLong (header.dirlen);
|
|
|
|
|
|
|
|
numpackfiles = header.dirlen / sizeof(dpackfile_t);
|
|
|
|
|
|
|
|
if (numpackfiles > MAX_FILES_IN_PACK)
|
|
|
|
Sys_Error ("%s has %i files", packfile, numpackfiles);
|
|
|
|
|
|
|
|
newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t));
|
|
|
|
|
2000-02-08 07:23:09 +00:00
|
|
|
Qseek (packhandle, header.dirofs, SEEK_SET);
|
|
|
|
Qread (packhandle, info, header.dirlen);
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
// parse the directory
|
|
|
|
for (i=0 ; i<numpackfiles ; i++)
|
|
|
|
{
|
|
|
|
strcpy (newfiles[i].name, info[i].name);
|
|
|
|
newfiles[i].filepos = LittleLong(info[i].filepos);
|
|
|
|
newfiles[i].filelen = LittleLong(info[i].filelen);
|
|
|
|
}
|
|
|
|
|
|
|
|
pack = Z_Malloc (sizeof (pack_t));
|
|
|
|
strcpy (pack->filename, packfile);
|
|
|
|
pack->handle = packhandle;
|
|
|
|
pack->numfiles = numpackfiles;
|
|
|
|
pack->files = newfiles;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles);
|
|
|
|
return pack;
|
|
|
|
}
|
|
|
|
|
2000-03-04 01:55:01 +00:00
|
|
|
#ifdef GENERATIONS
|
2000-01-27 17:06:02 +00:00
|
|
|
int
|
2000-02-03 21:13:23 +00:00
|
|
|
COM_pakzip_checkfile(unzFile *pak, const char *path)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
int status;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
status = unzLocateFile(pak, path, 2);
|
|
|
|
return (status == UNZ_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-02-03 21:13:23 +00:00
|
|
|
COM_pakzip_closepak(unzFile *pak)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
if (pak)
|
|
|
|
unzClose(pak);
|
|
|
|
pak = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-02-03 21:13:23 +00:00
|
|
|
COM_pakzip_close(unzFile *pak)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
unzCloseCurrentFile(pak);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-03 21:13:23 +00:00
|
|
|
COM_pakzip_read(unzFile *pak, void *buf, uint_t size, uint_t nmemb)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-03-04 01:55:01 +00:00
|
|
|
int len = unzReadCurrentFile(pak, buf, size * nmemb);
|
2000-01-27 17:06:02 +00:00
|
|
|
return len / size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-03 21:13:23 +00:00
|
|
|
COM_pakzip_open(unzFile *pak, const char *path)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
if (unzLocateFile(pak, path, 2) != UNZ_OK)
|
|
|
|
return 0;
|
|
|
|
if (unzOpenCurrentFile(pak) != UNZ_OK)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint_t
|
2000-02-03 21:13:23 +00:00
|
|
|
COM_pakzip_getlen(unzFile *pak)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
unz_file_info info;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
if (unzGetCurrentFileInfo(pak, &info, NULL, 0, NULL, 0, NULL, 0)
|
|
|
|
!= UNZ_OK)
|
|
|
|
return 0;
|
|
|
|
return info.uncompressed_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint_t
|
2000-02-03 21:13:23 +00:00
|
|
|
COM_pakzip_readfile(unzFile *pak, const char *path, uint_t bufsize, byte_t *buf)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
uint_t len;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-02-03 21:13:23 +00:00
|
|
|
if (!COM_pakzip_open(pak,path))
|
2000-01-27 17:06:02 +00:00
|
|
|
return 0;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-02-03 21:13:23 +00:00
|
|
|
if ((len = COM_pakzip_getlen(pak)) != 0)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-02-03 21:13:23 +00:00
|
|
|
if (COM_pakzip_read(pak, (void*)buf, 1, len) != len)
|
2000-01-27 17:06:02 +00:00
|
|
|
len = 0;
|
|
|
|
}
|
2000-02-03 21:13:23 +00:00
|
|
|
COM_pakzip_close(pak);
|
2000-01-27 17:06:02 +00:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
pack_t *
|
|
|
|
COM_LoadPackZipFile (char *packfile)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-03-04 01:55:01 +00:00
|
|
|
int i=0;
|
2000-01-27 17:06:02 +00:00
|
|
|
packfile_t *newfiles;
|
|
|
|
float numpackfiles;
|
|
|
|
unzFile *pak;
|
|
|
|
pack_t *pack_old;
|
|
|
|
int status;
|
2000-03-04 01:55:01 +00:00
|
|
|
|
|
|
|
// This following variable info is unused ATM.
|
|
|
|
// dpackfile_t info[MAX_FILES_IN_PACK];
|
2000-03-04 02:39:12 +00:00
|
|
|
char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
pak = unzOpen(packfile);
|
|
|
|
|
|
|
|
numpackfiles = 0;
|
|
|
|
Con_Printf ("Assigned Numpackfiles\n");
|
|
|
|
|
|
|
|
if (!pak)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
newfiles = Hunk_AllocName (numpackfiles * sizeof(unzFile), "packfile");
|
|
|
|
|
|
|
|
status=unzGoToFirstFile(pak);
|
|
|
|
|
|
|
|
while(status == UNZ_OK) {
|
2000-03-04 01:55:01 +00:00
|
|
|
// unzGetCurrentFileInfo(pak,NULL,&szCurrentFileName,64,NULL,0,NULL,0);
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
if(strcmp(newfiles[i].name, szCurrentFileName)==0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
strcpy (newfiles[i].name, szCurrentFileName);
|
|
|
|
Con_Printf ("strcpy'ed %s into newfiles[%i].name Ok\n",szCurrentFileName, i);
|
|
|
|
|
|
|
|
newfiles[i].filepos = LittleLong(unztell(pak));
|
|
|
|
// newfiles[i].filelen = LittleLong(COM_pak3_readfile(pak,packfile,64,64));
|
|
|
|
|
|
|
|
Con_Printf ("Added File\n");
|
|
|
|
status=unzGoToNextFile(pak);
|
|
|
|
++numpackfiles;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf ("Added files in %s to game data Ok\n", packfile);
|
|
|
|
|
|
|
|
pack_old = Hunk_Alloc (sizeof (pack_t));
|
|
|
|
strcpy (pack_old->filename, packfile);
|
|
|
|
//pack_old->handle = unzGetLocalExtrafield(packfile, NULL, NULL);
|
|
|
|
pack_old->numfiles = numpackfiles;
|
|
|
|
pack_old->files = newfiles;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
Con_Printf ("Added packfile %s (%.0f files)\n", packfile, numpackfiles);
|
|
|
|
|
2000-02-14 03:08:14 +00:00
|
|
|
COM_pakzip_close(pak);
|
2000-01-27 17:06:02 +00:00
|
|
|
return pack_old;
|
|
|
|
}
|
2000-03-04 01:55:01 +00:00
|
|
|
#endif
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-31 23:38:37 +00:00
|
|
|
#define FBLOCK_SIZE 32
|
|
|
|
#define FNAME_SIZE MAX_OSPATH
|
|
|
|
|
2000-02-02 06:49:43 +00:00
|
|
|
void
|
|
|
|
COM_LoadGameDirectory(char *dir)
|
2000-02-01 05:13:30 +00:00
|
|
|
{
|
2000-02-02 06:49:43 +00:00
|
|
|
searchpath_t *search;
|
|
|
|
pack_t *pak;
|
2000-03-08 01:12:26 +00:00
|
|
|
DIR *dir_ptr;
|
|
|
|
struct dirent *dirent;
|
2000-04-01 06:26:03 +00:00
|
|
|
char **pakfiles = NULL;
|
2000-03-31 22:46:39 +00:00
|
|
|
int i = 0, bufsize = 0, count = 0;
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
Con_DPrintf ("COM_LoadGameDirectory (\"%s\")\n", dir);
|
|
|
|
|
2000-04-01 06:26:03 +00:00
|
|
|
pakfiles = malloc(FBLOCK_SIZE * sizeof(char *));
|
2000-03-31 23:38:37 +00:00
|
|
|
bufsize += FBLOCK_SIZE;
|
2000-03-31 22:46:39 +00:00
|
|
|
if (!pakfiles)
|
|
|
|
goto COM_LoadGameDirectory_free;
|
2000-04-01 06:26:03 +00:00
|
|
|
|
|
|
|
for (i = count; i < bufsize; i++) {
|
|
|
|
pakfiles[i] = NULL;
|
|
|
|
}
|
2000-03-31 22:46:39 +00:00
|
|
|
|
2000-03-08 01:12:26 +00:00
|
|
|
dir_ptr = opendir(dir);
|
2000-03-08 04:17:12 +00:00
|
|
|
if (!dir_ptr)
|
|
|
|
return;
|
2000-02-02 06:49:43 +00:00
|
|
|
|
2000-03-08 01:12:26 +00:00
|
|
|
while ((dirent = readdir(dir_ptr))) {
|
2000-04-01 09:59:35 +00:00
|
|
|
if (!fnmatch("*.pak", dirent->d_name, 0)) {
|
2000-03-31 22:46:39 +00:00
|
|
|
if (count >= bufsize) {
|
2000-03-31 23:38:37 +00:00
|
|
|
bufsize += FBLOCK_SIZE;
|
2000-04-01 06:26:03 +00:00
|
|
|
pakfiles = realloc(pakfiles, bufsize * sizeof(char *));
|
2000-03-31 22:46:39 +00:00
|
|
|
if (!pakfiles)
|
|
|
|
goto COM_LoadGameDirectory_free;
|
|
|
|
for (i = count; i < bufsize; i++)
|
|
|
|
pakfiles[i] = NULL;
|
2000-03-08 01:12:26 +00:00
|
|
|
}
|
2000-04-01 06:26:03 +00:00
|
|
|
|
2000-03-31 22:46:39 +00:00
|
|
|
pakfiles[count] = malloc(FNAME_SIZE);
|
|
|
|
snprintf(pakfiles[count], FNAME_SIZE - 1, "%s/%s", dir,
|
|
|
|
dirent->d_name);
|
|
|
|
pakfiles[count][FNAME_SIZE - 1] = '\0';
|
|
|
|
count++;
|
2000-02-02 05:10:56 +00:00
|
|
|
}
|
2000-02-02 06:49:43 +00:00
|
|
|
}
|
2000-03-08 01:12:26 +00:00
|
|
|
closedir(dir_ptr);
|
2000-02-01 05:13:30 +00:00
|
|
|
|
2000-04-02 12:13:19 +00:00
|
|
|
// XXX WARNING!!! This is /NOT/ subtable for strcmp!!!!!
|
|
|
|
// This passes 'char **' instead of 'char *' to the cmp function!
|
|
|
|
qsort(pakfiles, count, sizeof(char *),
|
|
|
|
(int (*)(const void *, const void *)) Q_qstrcmp);
|
2000-03-31 22:46:39 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
pak = COM_LoadPackFile(pakfiles[i]);
|
|
|
|
|
|
|
|
if (!pak) {
|
|
|
|
Sys_Error(va("Bad pakfile %s!!", pakfiles[i]));
|
|
|
|
} else {
|
|
|
|
search = Z_Malloc (sizeof(searchpath_t));
|
|
|
|
search->pack = pak;
|
|
|
|
search->next = com_searchpaths;
|
|
|
|
com_searchpaths = search;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
COM_LoadGameDirectory_free:
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
free(pakfiles[i]);
|
|
|
|
free(pakfiles);
|
|
|
|
|
2000-03-04 01:55:01 +00:00
|
|
|
#ifdef GENERATIONS
|
2000-03-19 15:59:51 +00:00
|
|
|
for (done=false, i=0 ; !done ; i++ ) {
|
2000-03-04 01:55:01 +00:00
|
|
|
snprintf(pakfile, sizeof(pakfile), "%s/pak%i.qz", dir, i);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-02-03 21:13:23 +00:00
|
|
|
pak = COM_LoadPackZipFile(pakfile);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-02-02 06:49:43 +00:00
|
|
|
if(!pak) {
|
|
|
|
done = true;
|
|
|
|
} else {
|
|
|
|
search = Hunk_Alloc (sizeof(searchpath_t));
|
|
|
|
search->pack = pak;
|
|
|
|
search->next = com_searchpaths;
|
|
|
|
com_searchpaths = search;
|
2000-03-31 22:46:39 +00:00
|
|
|
}
|
2000-02-02 06:49:43 +00:00
|
|
|
}
|
2000-02-01 05:13:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
/*
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_AddDirectory
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
Sets com_gamedir, adds the directory to the head of the path,
|
|
|
|
then loads and adds pak1.pak pak2.pak ...
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-04-18 09:24:29 +00:00
|
|
|
void
|
|
|
|
COM_AddDirectory (char *dir)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
searchpath_t *search;
|
|
|
|
char *p;
|
2000-04-30 10:50:24 +00:00
|
|
|
char e_dir[PATH_MAX];
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-30 10:50:24 +00:00
|
|
|
Qexpand_squiggle (dir, e_dir);
|
|
|
|
dir = e_dir;
|
2000-04-27 00:37:57 +00:00
|
|
|
|
2000-04-30 10:50:24 +00:00
|
|
|
if ((p = strrchr(dir, '/')) != NULL) {
|
|
|
|
strcpy (gamedirfile, ++p);
|
|
|
|
strcpy (com_gamedir, dir);
|
|
|
|
} else {
|
|
|
|
strcpy (gamedirfile, dir);
|
|
|
|
strcpy (com_gamedir, va("%s/%s", fs_basepath->string, dir));
|
2000-04-27 00:37:57 +00:00
|
|
|
}
|
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
//
|
|
|
|
// add the directory to the search path
|
|
|
|
//
|
2000-02-20 04:20:00 +00:00
|
|
|
search = Z_Malloc (sizeof(searchpath_t));
|
2000-01-27 17:06:02 +00:00
|
|
|
strcpy (search->filename, dir);
|
|
|
|
search->next = com_searchpaths;
|
|
|
|
com_searchpaths = search;
|
|
|
|
|
|
|
|
//
|
|
|
|
// add any pak files in the format pak0.pak pak1.pak, ...
|
|
|
|
//
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_LoadGameDirectory (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
COM_AddGameDirectory
|
|
|
|
|
|
|
|
FIXME: this is a wrapper for COM_AddDirectory (which used to be
|
|
|
|
this function) to have it load share and base paths. Whenver
|
|
|
|
someone goes through to clean up the fs code, this function should
|
|
|
|
merge with COM_AddGameDirectory.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
COM_AddGameDirectory (char *dir)
|
|
|
|
{
|
2000-04-18 09:33:53 +00:00
|
|
|
Con_DPrintf ("COM_AddGameDirectory (\"%s/%s\")\n",
|
2000-04-18 09:24:29 +00:00
|
|
|
fs_sharepath->string, dir);
|
|
|
|
|
|
|
|
if (strcmp (fs_sharepath->string, fs_basepath->string) != 0)
|
|
|
|
COM_AddDirectory (va("%s/%s", fs_sharepath->string, dir));
|
|
|
|
COM_AddDirectory (va("%s/%s", fs_basepath->string, dir));
|
2000-01-27 17:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_Gamedir
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
Sets the gamedir and path to a different directory.
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-04-18 09:24:29 +00:00
|
|
|
void
|
|
|
|
COM_Gamedir (char *dir)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-04-18 09:24:29 +00:00
|
|
|
searchpath_t *next;
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
if (strstr(dir, "..") || strstr(dir, "/")
|
|
|
|
|| strstr(dir, "\\") || strstr(dir, ":") )
|
|
|
|
{
|
|
|
|
Con_Printf ("Gamedir should be a single filename, not a path\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
if (strcmp (gamedirfile, dir) == 0)
|
2000-01-27 17:06:02 +00:00
|
|
|
return; // still the same
|
|
|
|
strcpy (gamedirfile, dir);
|
|
|
|
|
|
|
|
//
|
|
|
|
// free up any current game dir info
|
|
|
|
//
|
|
|
|
while (com_searchpaths != com_base_searchpaths)
|
|
|
|
{
|
|
|
|
if (com_searchpaths->pack)
|
|
|
|
{
|
2000-02-08 07:23:09 +00:00
|
|
|
Qclose (com_searchpaths->pack->handle);
|
2000-01-27 17:06:02 +00:00
|
|
|
Z_Free (com_searchpaths->pack->files);
|
|
|
|
Z_Free (com_searchpaths->pack);
|
|
|
|
}
|
|
|
|
next = com_searchpaths->next;
|
|
|
|
Z_Free (com_searchpaths);
|
|
|
|
com_searchpaths = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// flush all data, so it will be forced to reload
|
|
|
|
//
|
|
|
|
Cache_Flush ();
|
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
if (strcmp (dir, GAMENAME) == 0)
|
|
|
|
return;
|
2000-02-03 20:27:25 +00:00
|
|
|
#ifdef QUAKEWORLD
|
2000-04-18 09:24:29 +00:00
|
|
|
if (strcmp (dir, "qw") == 0)
|
2000-01-27 17:06:02 +00:00
|
|
|
return;
|
2000-02-03 20:27:25 +00:00
|
|
|
#endif
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_AddGameDirectory (dir);
|
2000-01-27 17:06:02 +00:00
|
|
|
}
|
|
|
|
|
2000-04-27 09:25:38 +00:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
SV_Gamedir_f
|
|
|
|
|
|
|
|
Sets the gamedir and path to a different directory.
|
|
|
|
================
|
|
|
|
*/
|
2000-04-27 10:56:31 +00:00
|
|
|
|
2000-04-27 09:25:38 +00:00
|
|
|
void COM_Gamedir_f (void)
|
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
if (Cmd_Argc() == 1)
|
|
|
|
{
|
2000-04-30 10:50:24 +00:00
|
|
|
Con_Printf ("Current gamedir: %s\n", gamedirfile);
|
2000-04-27 09:25:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cmd_Argc() != 2)
|
|
|
|
{
|
|
|
|
Con_Printf ("Usage: gamedir <newdir>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dir = Cmd_Argv(1);
|
|
|
|
|
|
|
|
if (strstr(dir, "..") || strstr(dir, "/")
|
|
|
|
|| strstr(dir, "\\") || strstr(dir, ":") )
|
|
|
|
{
|
|
|
|
Con_Printf ("Gamedir should be a single filename, not a path\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
COM_Gamedir (dir);
|
|
|
|
#if defined(QUAKEWORLD) && defined(SERVERONLY)
|
|
|
|
Info_SetValueForStarKey (svs.info, "*gamedir", dir, MAX_SERVERINFO_STRING);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
/*
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_InitFilesystem
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
2000-02-03 11:29:22 +00:00
|
|
|
void
|
|
|
|
COM_InitFilesystem ( void )
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
2000-04-18 09:24:29 +00:00
|
|
|
#ifdef UQUAKE
|
|
|
|
int i;
|
|
|
|
#endif
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-25 12:31:03 +00:00
|
|
|
fs_basepath = Cvar_Get ("fs_basepath", FS_BASEPATH, CVAR_ROM,
|
2000-04-18 09:24:29 +00:00
|
|
|
"the location of your game directories");
|
|
|
|
fs_sharepath = Cvar_Get ("fs_sharepath", fs_basepath->string,
|
|
|
|
CVAR_ROM, "read-only game directories");
|
2000-04-27 09:25:38 +00:00
|
|
|
Cmd_AddCommand ("gamedir", COM_Gamedir_f);
|
|
|
|
|
2000-02-03 11:29:22 +00:00
|
|
|
/*
|
|
|
|
start up with GAMENAME by default
|
|
|
|
*/
|
2000-04-18 09:24:29 +00:00
|
|
|
COM_AddGameDirectory (GAMENAME);
|
|
|
|
if (hipnotic)
|
|
|
|
COM_AddGameDirectory ("hipnotic");
|
|
|
|
if (rogue)
|
|
|
|
COM_AddGameDirectory ("rogue");
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-04-18 09:24:29 +00:00
|
|
|
#ifdef QUAKEWORLD
|
|
|
|
COM_AddGameDirectory ("qw");
|
|
|
|
#elif UQUAKE
|
2000-02-03 11:29:22 +00:00
|
|
|
i = COM_CheckParm ("-game");
|
2000-04-18 09:24:29 +00:00
|
|
|
if (i && i < com_argc-1)
|
|
|
|
COM_AddGameDirectory (com_argv[i+1]);
|
|
|
|
#endif
|
2000-02-03 11:29:22 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
// any set gamedirs will be freed up to here
|
|
|
|
com_base_searchpaths = com_searchpaths;
|
|
|
|
}
|
2000-04-18 09:24:29 +00:00
|
|
|
|