2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
quakefs.c
|
|
|
|
|
|
|
|
virtual filesystem functions
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2001-03-09 07:58:10 +00:00
|
|
|
# include "config.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
2001-03-09 07:58:10 +00:00
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
#include <ctype.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#include <dirent.h>
|
2002-08-25 23:10:57 +00:00
|
|
|
#include <errno.h>
|
2001-08-22 22:03:16 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
2002-08-25 23:10:57 +00:00
|
|
|
#include <stdlib.h>
|
2001-03-09 07:58:10 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_FNMATCH_H
|
2001-03-09 07:58:10 +00:00
|
|
|
# define model_t sunmodel_t
|
|
|
|
# include <fnmatch.h>
|
|
|
|
# undef model_t
|
2001-09-29 09:39:27 +00:00
|
|
|
#else
|
|
|
|
# ifdef WIN32
|
|
|
|
# include "fnmatch.h"
|
|
|
|
# endif
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-16 21:40:45 +00:00
|
|
|
#ifdef HAVE_IO_H
|
2001-03-09 07:58:10 +00:00
|
|
|
# include <io.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2001-03-09 07:58:10 +00:00
|
|
|
# define _POSIX_
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
#include <limits.h>
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
2003-01-10 22:47:18 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/hash.h"
|
2002-03-12 23:45:36 +00:00
|
|
|
#include "QF/pak.h"
|
2002-07-21 06:11:28 +00:00
|
|
|
#include "QF/pakfile.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/qendian.h"
|
2003-01-10 22:47:18 +00:00
|
|
|
#include "QF/qfplist.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/qtypes.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
2001-03-30 00:30:38 +00:00
|
|
|
#include "QF/zone.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
#ifndef HAVE_FNMATCH_PROTO
|
2002-08-25 23:10:57 +00:00
|
|
|
int fnmatch (const char *__pattern, const char *__string, int __flags);
|
2001-03-09 07:58:10 +00:00
|
|
|
#endif
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
All of Quake's data access is through a hierchical file system, but the
|
|
|
|
contents of the file system can be transparently merged from several
|
|
|
|
sources.
|
|
|
|
|
|
|
|
The "user directory" is the path to the directory holding the quake.exe
|
2001-03-09 07:58:10 +00:00
|
|
|
and all game directories. This can be overridden with the "fs_sharepath"
|
|
|
|
and "fs_userpath" cvars to allow code debugging in a different directory.
|
2001-02-19 21:15:25 +00:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2002-08-25 23:10:57 +00:00
|
|
|
// QUAKE FILESYSTEM
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *fs_userpath;
|
|
|
|
cvar_t *fs_sharepath;
|
2003-01-10 22:47:18 +00:00
|
|
|
cvar_t *fs_dirconf;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
int qfs_filesize;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
searchpath_t *qfs_searchpaths;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-01-10 22:47:18 +00:00
|
|
|
//QFS
|
|
|
|
|
2003-01-27 18:16:15 +00:00
|
|
|
typedef struct qfs_var_s {
|
|
|
|
char *var;
|
|
|
|
char *val;
|
|
|
|
} qfs_var_t;
|
|
|
|
|
2003-02-25 18:13:56 +00:00
|
|
|
static void QFS_AddGameDirectory (const char *dir);
|
2003-01-10 22:47:18 +00:00
|
|
|
|
|
|
|
gamedir_t *qfs_gamedir;
|
|
|
|
static plitem_t *qfs_gd_plist;
|
|
|
|
static const char *qfs_game = "";
|
|
|
|
static const char *qfs_default_dirconf =
|
|
|
|
"{"
|
2003-02-07 20:18:59 +00:00
|
|
|
" QF = {"
|
|
|
|
" Path = \"QF\";"
|
|
|
|
" };"
|
2003-01-10 22:47:18 +00:00
|
|
|
" Quake = {"
|
2003-02-07 20:18:59 +00:00
|
|
|
" Inherit = QF;"
|
2003-01-10 22:47:18 +00:00
|
|
|
" Path = \"id1\";"
|
2003-01-13 17:32:00 +00:00
|
|
|
" GameCode = \"progs.dat\";"
|
2003-01-10 22:47:18 +00:00
|
|
|
" };"
|
|
|
|
" QuakeWorld = {"
|
|
|
|
" Inherit = (Quake);"
|
|
|
|
" Path = \"qw\";"
|
2003-01-27 21:56:30 +00:00
|
|
|
" SkinPath = \"${path}/skins\";"
|
2003-01-13 17:32:00 +00:00
|
|
|
" GameCode = \"qwprogs.dat\";"
|
2003-01-10 22:47:18 +00:00
|
|
|
" };"
|
2003-03-13 05:43:45 +00:00
|
|
|
" \"qw:qw\" = {"
|
|
|
|
" Inherit = (QuakeWorld);"
|
|
|
|
" };"
|
2003-01-10 22:47:18 +00:00
|
|
|
" \"qw:*\" = {"
|
|
|
|
" Inherit = (QuakeWorld);"
|
|
|
|
" Path = \"$gamedir\";"
|
|
|
|
" };"
|
|
|
|
" \"nq:*\" = {"
|
|
|
|
" Inherit = (Quake);"
|
2003-01-13 16:46:13 +00:00
|
|
|
" Path = \"$gamedir\";"
|
2003-01-10 22:47:18 +00:00
|
|
|
" };"
|
|
|
|
"}";
|
|
|
|
|
2003-01-27 18:16:15 +00:00
|
|
|
static const char *
|
|
|
|
qfs_var_get_key (void *_v, void *unused)
|
|
|
|
{
|
|
|
|
return ((qfs_var_t *)_v)->var;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qfs_var_free (void *_v, void *unused)
|
|
|
|
{
|
|
|
|
qfs_var_t *v = (qfs_var_t *) _v;
|
|
|
|
free (v->var);
|
|
|
|
free (v->val);
|
|
|
|
free (v);
|
|
|
|
}
|
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
static hashtab_t *
|
2003-01-27 18:16:15 +00:00
|
|
|
qfs_new_vars (void)
|
|
|
|
{
|
|
|
|
return Hash_NewTable (61, qfs_var_get_key, qfs_var_free, 0);
|
|
|
|
}
|
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
static void
|
2003-01-27 18:16:15 +00:00
|
|
|
qfs_set_var (hashtab_t *vars, const char *var, const char *val)
|
|
|
|
{
|
|
|
|
qfs_var_t *v = Hash_Find (vars, var);
|
|
|
|
|
|
|
|
if (!v) {
|
|
|
|
v = malloc (sizeof (qfs_var_t));
|
|
|
|
v->var = strdup (var);
|
|
|
|
v->val = 0;
|
|
|
|
Hash_Add (vars, v);
|
|
|
|
}
|
|
|
|
if (v->val)
|
|
|
|
free (v->val);
|
|
|
|
v->val = strdup (val);
|
|
|
|
}
|
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
static inline int
|
|
|
|
qfs_isident (byte c)
|
|
|
|
{
|
|
|
|
return ((c >= 'a' && c <='z') || (c >= 'A' && c <='Z')
|
|
|
|
|| (c >= '0' && c <= '9') || c == '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2003-01-27 18:16:15 +00:00
|
|
|
qfs_var_subst (const char *string, hashtab_t *vars)
|
|
|
|
{
|
|
|
|
dstring_t *new = dstring_newstr ();
|
|
|
|
const char *s = string;
|
|
|
|
const char *e = s;
|
|
|
|
const char *var;
|
|
|
|
char *t;
|
|
|
|
qfs_var_t *sub;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
while (*e && *e != '$')
|
|
|
|
e++;
|
|
|
|
dstring_appendsubstr (new, s, (e - s));
|
|
|
|
if (!*e++)
|
|
|
|
break;
|
|
|
|
if (*e == '$') {
|
|
|
|
dstring_appendstr (new, "$");
|
|
|
|
s = ++e;
|
|
|
|
} else if (*e == '{') {
|
|
|
|
s = e;
|
|
|
|
while (*e && *e != '}')
|
|
|
|
e++;
|
|
|
|
if (!*e) {
|
|
|
|
dstring_appendsubstr (new, s, (e - s));
|
|
|
|
break;
|
|
|
|
}
|
2003-02-12 23:29:16 +00:00
|
|
|
var = va ("%.*s", (int) (e - s) - 1, s + 1);
|
2003-01-27 18:16:15 +00:00
|
|
|
sub = Hash_Find (vars, var);
|
|
|
|
if (sub)
|
|
|
|
dstring_appendstr (new, sub->val);
|
|
|
|
else
|
|
|
|
dstring_appendsubstr (new, s - 1, (e - s) + 2);
|
|
|
|
s = ++e;
|
2003-01-27 21:56:30 +00:00
|
|
|
} else if (qfs_isident (*e)) {
|
2003-01-27 18:16:15 +00:00
|
|
|
s = e;
|
2003-01-27 21:56:30 +00:00
|
|
|
while (qfs_isident (*e))
|
2003-01-27 18:16:15 +00:00
|
|
|
e++;
|
2003-02-12 23:29:16 +00:00
|
|
|
var = va ("%.*s", (int) (e - s), s);
|
2003-01-27 18:16:15 +00:00
|
|
|
sub = Hash_Find (vars, var);
|
|
|
|
if (sub)
|
|
|
|
dstring_appendstr (new, sub->val);
|
|
|
|
else
|
|
|
|
dstring_appendsubstr (new, s - 1, (e - s) + 1);
|
|
|
|
s = e;
|
|
|
|
} else {
|
|
|
|
dstring_appendstr (new, "$");
|
|
|
|
s = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t = new->str;
|
|
|
|
free (new);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2003-01-10 22:47:18 +00:00
|
|
|
static void
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_get_gd_params (plitem_t *gdpl, gamedir_t *gamedir, dstring_t *path,
|
|
|
|
hashtab_t *vars)
|
2003-01-10 22:47:18 +00:00
|
|
|
{
|
|
|
|
plitem_t *p;
|
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
if ((p = PL_ObjectForKey (gdpl, "Path")) && *(char *) p->data) {
|
|
|
|
char *str = qfs_var_subst (p->data, vars);
|
|
|
|
char *e = strchr (str, '"');
|
|
|
|
|
|
|
|
if (!e)
|
|
|
|
e = str + strlen (str);
|
2003-02-12 23:29:16 +00:00
|
|
|
qfs_set_var (vars, "path", va ("%.*s", (int) (e - str), str));
|
2003-01-10 22:47:18 +00:00
|
|
|
if (path->str[0])
|
|
|
|
dstring_appendstr (path, ":");
|
2003-01-27 21:56:30 +00:00
|
|
|
dstring_appendstr (path, str);
|
|
|
|
free (str);
|
2003-01-10 22:47:18 +00:00
|
|
|
}
|
|
|
|
if (!gamedir->gamecode && (p = PL_ObjectForKey (gdpl, "GameCode")))
|
2003-01-27 21:56:30 +00:00
|
|
|
gamedir->gamecode = qfs_var_subst (p->data, vars);
|
2003-02-14 22:36:10 +00:00
|
|
|
if (!gamedir->dir.skins && (p = PL_ObjectForKey (gdpl, "SkinPath")))
|
|
|
|
gamedir->dir.skins = qfs_var_subst (p->data, vars);
|
|
|
|
if (!gamedir->dir.progs && (p = PL_ObjectForKey (gdpl, "ProgPath")))
|
|
|
|
gamedir->dir.progs = qfs_var_subst (p->data, vars);
|
|
|
|
if (!gamedir->dir.sound && (p = PL_ObjectForKey (gdpl, "SoundPath")))
|
|
|
|
gamedir->dir.sound = qfs_var_subst (p->data, vars);
|
|
|
|
if (!gamedir->dir.maps && (p = PL_ObjectForKey (gdpl, "MapPath")))
|
|
|
|
gamedir->dir.maps = qfs_var_subst (p->data, vars);
|
2003-01-10 22:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qfs_inherit (plitem_t *plist, plitem_t *gdpl, gamedir_t *gamedir,
|
2003-01-27 21:56:30 +00:00
|
|
|
dstring_t *path, hashtab_t *dirs, hashtab_t *vars)
|
2003-01-10 22:47:18 +00:00
|
|
|
{
|
|
|
|
plitem_t *base;
|
|
|
|
|
|
|
|
if (!(base = PL_ObjectForKey (gdpl, "Inherit")))
|
|
|
|
return;
|
|
|
|
if (base->type == QFString) {
|
|
|
|
if (Hash_Find (dirs, base->data))
|
|
|
|
return;
|
|
|
|
gdpl = PL_ObjectForKey (plist, base->data);
|
|
|
|
if (!gdpl) {
|
|
|
|
Sys_Printf ("base `%s' not found\n", (char *)base->data);
|
|
|
|
return;
|
|
|
|
}
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_set_var (vars, "gamedir", base->data);
|
2003-01-10 22:47:18 +00:00
|
|
|
Hash_Add (dirs, base->data);
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_get_gd_params (gdpl, gamedir, path, vars);
|
|
|
|
qfs_inherit (plist, gdpl, gamedir, path, dirs, vars);
|
2003-01-10 22:47:18 +00:00
|
|
|
} else if (base->type == QFArray) {
|
|
|
|
int i;
|
|
|
|
plarray_t *a = base->data;
|
|
|
|
for (i = 0; i < a->numvals; i++) {
|
|
|
|
base = a->values[i];
|
|
|
|
if (Hash_Find (dirs, base->data))
|
|
|
|
continue;
|
|
|
|
gdpl = PL_ObjectForKey (plist, base->data);
|
|
|
|
if (!gdpl) {
|
|
|
|
Sys_Printf ("base `%s' not found\n", (char *)base->data);
|
|
|
|
continue;
|
|
|
|
}
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_set_var (vars, "gamedir", base->data);
|
2003-01-10 22:47:18 +00:00
|
|
|
Hash_Add (dirs, base->data);
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_get_gd_params (gdpl, gamedir, path, vars);
|
|
|
|
qfs_inherit (plist, gdpl, gamedir, path, dirs, vars);
|
2003-01-10 22:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
qfs_compare (const void *a, const void *b)
|
|
|
|
{
|
|
|
|
return strcmp ((*(dictkey_t **)a)->key, (*(dictkey_t **)b)->key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
qfs_dir_get_key (void *_k, void *unused)
|
|
|
|
{
|
|
|
|
return _k;
|
|
|
|
}
|
|
|
|
|
2003-01-22 20:00:46 +00:00
|
|
|
static plitem_t *
|
|
|
|
qfs_find_gamedir (const char *name, hashtab_t *dirs)
|
2003-01-10 22:47:18 +00:00
|
|
|
{
|
2003-01-22 20:00:46 +00:00
|
|
|
plitem_t *gdpl = PL_ObjectForKey (qfs_gd_plist, name);
|
2003-01-10 22:47:18 +00:00
|
|
|
|
|
|
|
if (!gdpl) {
|
|
|
|
dictkey_t **list = (dictkey_t **) Hash_GetList (qfs_gd_plist->data);
|
|
|
|
dictkey_t **l;
|
|
|
|
for (l = list; *l; l++)
|
|
|
|
;
|
|
|
|
qsort (list, l - list, sizeof (char *), qfs_compare);
|
|
|
|
while (l-- != list) {
|
|
|
|
if (!fnmatch ((*l)->key, name, 0)) {
|
|
|
|
gdpl = (*l)->value;
|
|
|
|
Hash_Add (dirs, (*l)->key);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (list);
|
|
|
|
}
|
2003-01-22 20:00:46 +00:00
|
|
|
return gdpl;
|
|
|
|
}
|
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
static void
|
|
|
|
qfs_process_path (const char *path, const char *gamedir)
|
2003-01-22 20:00:46 +00:00
|
|
|
{
|
2003-01-27 21:56:30 +00:00
|
|
|
const char *e = path + strlen (path);
|
|
|
|
const char *s = e;
|
|
|
|
dstring_t *dir = dstring_new ();
|
|
|
|
|
|
|
|
while (s >= path) {
|
|
|
|
while (s != path && s[-1] !=':')
|
|
|
|
s--;
|
|
|
|
if (s != e) {
|
2003-02-12 23:29:16 +00:00
|
|
|
dsprintf (dir, "%.*s", (int) (e - s), s);
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_AddGameDirectory (dir->str);
|
2003-01-27 21:56:30 +00:00
|
|
|
}
|
|
|
|
e = --s;
|
|
|
|
}
|
|
|
|
dstring_delete (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qfs_build_gamedir (const char **list)
|
|
|
|
{
|
|
|
|
int j;
|
2003-01-22 20:00:46 +00:00
|
|
|
gamedir_t *gamedir;
|
|
|
|
plitem_t *gdpl;
|
|
|
|
dstring_t *path;
|
|
|
|
hashtab_t *dirs = Hash_NewTable (31, qfs_dir_get_key, 0, 0);
|
2003-01-27 21:56:30 +00:00
|
|
|
hashtab_t *vars = qfs_new_vars ();
|
|
|
|
const char *dir = 0;
|
2003-01-22 20:00:46 +00:00
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_set_var (vars, "game", qfs_game);
|
|
|
|
|
|
|
|
if (qfs_gamedir) {
|
|
|
|
if (qfs_gamedir->name)
|
|
|
|
free ((char *)qfs_gamedir->name);
|
2003-02-14 22:36:10 +00:00
|
|
|
if (qfs_gamedir->gamedir)
|
|
|
|
free ((char *)qfs_gamedir->gamedir);
|
2003-01-27 21:56:30 +00:00
|
|
|
if (qfs_gamedir->path)
|
|
|
|
free ((char *)qfs_gamedir->path);
|
|
|
|
if (qfs_gamedir->gamecode)
|
|
|
|
free ((char *)qfs_gamedir->gamecode);
|
2003-02-14 22:36:10 +00:00
|
|
|
if (qfs_gamedir->dir.def)
|
|
|
|
free ((char *)qfs_gamedir->dir.def);
|
|
|
|
if (qfs_gamedir->dir.skins)
|
|
|
|
free ((char *)qfs_gamedir->dir.skins);
|
|
|
|
if (qfs_gamedir->dir.progs)
|
|
|
|
free ((char *)qfs_gamedir->dir.progs);
|
|
|
|
if (qfs_gamedir->dir.sound)
|
|
|
|
free ((char *)qfs_gamedir->dir.sound);
|
|
|
|
if (qfs_gamedir->dir.maps)
|
|
|
|
free ((char *)qfs_gamedir->dir.maps);
|
2003-01-27 21:56:30 +00:00
|
|
|
free (qfs_gamedir);
|
2003-01-22 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
while (qfs_searchpaths) {
|
2003-01-27 21:56:30 +00:00
|
|
|
searchpath_t *next;
|
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
if (qfs_searchpaths->pack) {
|
|
|
|
Qclose (qfs_searchpaths->pack->handle);
|
|
|
|
free (qfs_searchpaths->pack->files);
|
|
|
|
free (qfs_searchpaths->pack);
|
2003-01-27 21:56:30 +00:00
|
|
|
}
|
2003-02-14 19:46:07 +00:00
|
|
|
next = qfs_searchpaths->next;
|
|
|
|
free (qfs_searchpaths);
|
|
|
|
qfs_searchpaths = next;
|
2003-01-27 21:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; list[j]; j++)
|
|
|
|
;
|
2003-01-10 22:47:18 +00:00
|
|
|
gamedir = calloc (1, sizeof (gamedir_t));
|
|
|
|
path = dstring_newstr ();
|
2003-01-27 21:56:30 +00:00
|
|
|
while (j--) {
|
|
|
|
const char *name = va ("%s:%s", qfs_game, dir = list[j]);
|
|
|
|
if (Hash_Find (dirs, name))
|
|
|
|
continue;
|
|
|
|
gdpl = qfs_find_gamedir (name, dirs);
|
|
|
|
if (!gdpl) {
|
|
|
|
Sys_Printf ("gamedir `%s' not found\n", name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Hash_Add (dirs, (void *) name);
|
2003-02-14 22:36:10 +00:00
|
|
|
if (!j) {
|
2003-01-27 21:56:30 +00:00
|
|
|
gamedir->name = strdup (name);
|
2003-02-14 22:36:10 +00:00
|
|
|
gamedir->gamedir = strdup (list[j]);
|
|
|
|
}
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_set_var (vars, "gamedir", dir);
|
|
|
|
qfs_get_gd_params (gdpl, gamedir, path, vars);
|
|
|
|
qfs_inherit (qfs_gd_plist, gdpl, gamedir, path, dirs, vars);
|
|
|
|
}
|
2003-01-10 22:47:18 +00:00
|
|
|
gamedir->path = path->str;
|
2003-02-14 22:36:10 +00:00
|
|
|
|
|
|
|
for (dir = gamedir->path; *dir && *dir != ':'; dir++)
|
|
|
|
;
|
|
|
|
gamedir->dir.def = nva ("%.*s", (int) (dir - gamedir->path),
|
|
|
|
gamedir->path);
|
|
|
|
if (!gamedir->dir.skins)
|
|
|
|
gamedir->dir.skins = nva ("%s/skins", gamedir->dir.def);
|
|
|
|
if (!gamedir->dir.progs)
|
|
|
|
gamedir->dir.progs = nva ("%s/progs", gamedir->dir.def);
|
|
|
|
if (!gamedir->dir.sound)
|
|
|
|
gamedir->dir.sound = nva ("%s/sound", gamedir->dir.def);
|
|
|
|
if (!gamedir->dir.maps)
|
|
|
|
gamedir->dir.maps = nva ("%s/maps", gamedir->dir.def);
|
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_gamedir = gamedir;
|
|
|
|
Sys_DPrintf ("%s\n", qfs_gamedir->name);
|
2003-02-14 22:36:10 +00:00
|
|
|
Sys_DPrintf (" gamedir : %s\n", qfs_gamedir->gamedir);
|
|
|
|
Sys_DPrintf (" path : %s\n", qfs_gamedir->path);
|
|
|
|
Sys_DPrintf (" gamecode: %s\n", qfs_gamedir->gamecode);
|
|
|
|
Sys_DPrintf (" def : %s\n", qfs_gamedir->dir.def);
|
|
|
|
Sys_DPrintf (" skins : %s\n", qfs_gamedir->dir.skins);
|
|
|
|
Sys_DPrintf (" progs : %s\n", qfs_gamedir->dir.progs);
|
|
|
|
Sys_DPrintf (" sound : %s\n", qfs_gamedir->dir.sound);
|
|
|
|
Sys_DPrintf (" maps : %s\n", qfs_gamedir->dir.maps);
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_process_path (qfs_gamedir->path, dir);
|
2003-01-10 22:47:18 +00:00
|
|
|
free (path);
|
|
|
|
Hash_DelTable (dirs);
|
2003-01-27 21:56:30 +00:00
|
|
|
Hash_DelTable (vars);
|
2003-01-10 22:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qfs_load_config (void)
|
|
|
|
{
|
|
|
|
QFile *f;
|
|
|
|
int len;
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
if (!(f = Qopen (fs_dirconf->string, "rt"))) {
|
|
|
|
Sys_DPrintf ("Could not load `%s', using builtin defaults\n",
|
|
|
|
fs_dirconf->string);
|
|
|
|
goto no_config;
|
|
|
|
}
|
|
|
|
len = Qfilesize (f);
|
|
|
|
buf = malloc (len + 3); // +3 for { } and \0
|
|
|
|
|
|
|
|
Qread (f, buf + 1, len);
|
|
|
|
Qclose (f);
|
|
|
|
|
|
|
|
// convert the config file to a plist dictionary
|
|
|
|
buf[0] = '{';
|
|
|
|
buf[len + 1] = '}';
|
|
|
|
buf[len + 2] = 0;
|
|
|
|
qfs_gd_plist = PL_GetPropertyList (buf);
|
|
|
|
free (buf);
|
|
|
|
if (qfs_gd_plist && qfs_gd_plist->type == QFDictionary)
|
|
|
|
return; // done
|
|
|
|
Sys_Printf ("not a dictionary\n");
|
|
|
|
no_config:
|
|
|
|
qfs_gd_plist = PL_GetPropertyList (qfs_default_dirconf);
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_FileBase (const char *in, char *out)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-25 23:10:57 +00:00
|
|
|
const char *slash, *dot, *s;
|
2001-03-09 07:58:10 +00:00
|
|
|
|
|
|
|
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)
|
2001-02-26 06:48:02 +00:00
|
|
|
strcpy (out, "?model?");
|
|
|
|
else {
|
2001-03-09 07:58:10 +00:00
|
|
|
while (slash < dot)
|
|
|
|
*out++ = *slash++;
|
|
|
|
*out++ = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
static void
|
|
|
|
QFS_Path_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
searchpath_t *s;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Current search path:\n");
|
2003-02-14 19:46:07 +00:00
|
|
|
for (s = qfs_searchpaths; s; s = s->next) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (s->pack)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%s (%i files)\n", s->pack->filename,
|
2001-02-26 06:48:02 +00:00
|
|
|
s->pack->numfiles);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%s\n", s->filename);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_WriteFile
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
The filename will be prefixed by the current game directory
|
|
|
|
*/
|
|
|
|
void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_WriteFile (const char *filename, void *data, int len)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
char name[MAX_OSPATH];
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *f;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-02-14 22:36:10 +00:00
|
|
|
snprintf (name, sizeof (name), "%s/%s", qfs_gamedir->dir.def, filename);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-02-14 22:36:10 +00:00
|
|
|
f = QFS_WOpen (name, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!f) {
|
2003-02-14 22:36:10 +00:00
|
|
|
Sys_Error ("Error opening %s", filename);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
Sys_Printf ("QFS_WriteFile: %s\n", name);
|
2001-02-19 21:15:25 +00:00
|
|
|
Qwrite (f, data, len);
|
|
|
|
Qclose (f);
|
|
|
|
}
|
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
/*
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_WriteBuffers
|
2001-03-09 07:58:10 +00:00
|
|
|
|
|
|
|
The filename will be prefixed by the current game directory
|
|
|
|
*/
|
|
|
|
void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_WriteBuffers (const char *filename, int count, ...)
|
2001-03-09 07:58:10 +00:00
|
|
|
{
|
|
|
|
char name[MAX_OSPATH];
|
|
|
|
va_list args;
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *f;
|
2001-03-09 07:58:10 +00:00
|
|
|
|
|
|
|
va_start (args, count);
|
|
|
|
|
2003-02-14 22:36:10 +00:00
|
|
|
snprintf (name, sizeof (name), "%s/%s", qfs_gamedir->dir.def, filename);
|
2001-03-09 07:58:10 +00:00
|
|
|
|
2003-02-14 22:36:10 +00:00
|
|
|
f = QFS_WOpen (name, 0);
|
2001-03-09 07:58:10 +00:00
|
|
|
if (!f) {
|
2003-02-14 22:36:10 +00:00
|
|
|
Sys_Error ("Error opening %s", filename);
|
2001-03-09 07:58:10 +00:00
|
|
|
}
|
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
Sys_Printf ("QFS_WriteBuffers: %s\n", name);
|
2001-03-09 07:58:10 +00:00
|
|
|
while (count--) {
|
|
|
|
void *data = va_arg (args, void *);
|
|
|
|
int len = va_arg (args, int);
|
|
|
|
|
|
|
|
Qwrite (f, data, len);
|
|
|
|
}
|
|
|
|
Qclose (f);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_CreatePath
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Only used for CopyFile and download
|
|
|
|
*/
|
|
|
|
void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_CreatePath (const char *path)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-07-24 03:22:54 +00:00
|
|
|
char *ofs;
|
2001-03-09 07:58:10 +00:00
|
|
|
char e_path[MAX_OSPATH];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Qexpand_squiggle (path, e_path);
|
|
|
|
|
2001-07-24 03:22:54 +00:00
|
|
|
for (ofs = e_path + 1; *ofs; ofs++) {
|
2001-02-26 06:48:02 +00:00
|
|
|
if (*ofs == '/') { // create the directory
|
2001-07-24 03:22:54 +00:00
|
|
|
*ofs = 0;
|
|
|
|
Sys_mkdir (e_path);
|
|
|
|
*ofs = '/';
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static QFile *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_OpenRead (const char *path, int offs, int len, int zip)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-09-27 04:27:19 +00:00
|
|
|
QFile *file;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2002-09-27 04:27:19 +00:00
|
|
|
if (offs < 0 || len < 0)
|
|
|
|
file = Qopen (path, zip ? "rbz" : "rb");
|
|
|
|
else
|
|
|
|
file = Qsubopen (path, offs, len, zip);
|
|
|
|
|
|
|
|
if (!file) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Couldn't open %s", path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
qfs_filesize = Qfilesize (file);
|
2002-09-27 04:27:19 +00:00
|
|
|
|
|
|
|
return file;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2002-08-20 06:11:10 +00:00
|
|
|
char *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_CompressPath (const char *pth)
|
2002-08-20 06:11:10 +00:00
|
|
|
{
|
|
|
|
char *p, *d;
|
2002-08-25 23:10:57 +00:00
|
|
|
char *path= malloc (strlen (pth) + 1);
|
2002-08-20 06:11:10 +00:00
|
|
|
|
|
|
|
for (d = path; *pth; d++, pth++) {
|
|
|
|
if (*pth == '\\')
|
|
|
|
*d = '/';
|
|
|
|
else
|
|
|
|
*d = *pth;
|
|
|
|
}
|
|
|
|
*d = 0;
|
|
|
|
|
|
|
|
p = path;
|
|
|
|
while (*p) {
|
|
|
|
if (p[0] == '.') {
|
|
|
|
if (p[1] == '.') {
|
|
|
|
if (p[2] == '/' || p[2] == 0) {
|
|
|
|
d = p;
|
|
|
|
if (d > path)
|
|
|
|
d--;
|
|
|
|
while (d > path && d[-1] != '/')
|
|
|
|
d--;
|
|
|
|
if (d == path
|
|
|
|
&& d[0] == '.' && d[1] == '.'
|
|
|
|
&& (d[2] == '/' || d[2] == '0')) {
|
|
|
|
p += 2 + (p[2] == '/');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strcpy (d, p + 2 + (p[2] == '/'));
|
|
|
|
p = d;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (p[1] == '/') {
|
|
|
|
strcpy (p, p + 2);
|
|
|
|
continue;
|
|
|
|
} else if (p[1] == 0) {
|
|
|
|
p[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*p && *p != '/')
|
|
|
|
p++;
|
|
|
|
if (*p == '/')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2001-08-21 00:06:22 +00:00
|
|
|
/*
|
|
|
|
contains_updir
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-21 00:06:22 +00:00
|
|
|
Checks if a string contains an updir ('..'), either at the ends or
|
|
|
|
surrounded by slashes ('/'). Doesn't check for leading slash.
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2001-08-21 00:06:22 +00:00
|
|
|
contains_updir (const char *filename)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (filename[0] == 0 || filename [1] == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; filename[i+1]; i++) {
|
2001-08-22 22:03:16 +00:00
|
|
|
if (!(i == 0 || filename[i-1] == '/') // beginning of string
|
|
|
|
// or first slash
|
2001-08-21 00:06:22 +00:00
|
|
|
|| filename[i] != '.' // first dot
|
|
|
|
|| filename[i+1] != '.') // second dot
|
|
|
|
continue;
|
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
if (filename[i+2] == 0 || filename[i+2] == '/')
|
|
|
|
// end of string or second slash
|
2001-08-21 00:06:22 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int file_from_pak; // global indicating file came from pack file ZOID
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_FOpenFile
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Finds the file in the search path.
|
2003-02-14 19:46:07 +00:00
|
|
|
Sets qfs_filesize and one of handle or file
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2002-06-14 20:36:28 +00:00
|
|
|
|
|
|
|
static int
|
2002-08-27 07:16:28 +00:00
|
|
|
open_file (searchpath_t *search, const char *filename, QFile **gzfile,
|
2003-04-09 05:55:41 +00:00
|
|
|
dstring_t *foundname, int zip)
|
2002-06-14 20:36:28 +00:00
|
|
|
{
|
|
|
|
char netpath[MAX_OSPATH];
|
|
|
|
|
|
|
|
file_from_pak = 0;
|
|
|
|
|
|
|
|
// is the element a pak file?
|
|
|
|
if (search->pack) {
|
2002-07-21 06:11:28 +00:00
|
|
|
dpackfile_t *packfile;
|
2002-06-14 20:36:28 +00:00
|
|
|
|
2002-07-21 06:11:28 +00:00
|
|
|
packfile = pack_find_file (search->pack, filename);
|
2002-06-14 20:36:28 +00:00
|
|
|
if (packfile) {
|
|
|
|
Sys_DPrintf ("PackFile: %s : %s\n", search->pack->filename,
|
|
|
|
packfile->name);
|
|
|
|
// open a new file on the pakfile
|
2003-04-09 05:55:41 +00:00
|
|
|
if (foundname) {
|
|
|
|
dstring_clearstr (foundname);
|
|
|
|
dstring_appendstr (foundname, packfile->name);
|
|
|
|
}
|
2003-02-14 19:46:07 +00:00
|
|
|
*gzfile = QFS_OpenRead (search->pack->filename, packfile->filepos,
|
2002-06-14 20:36:28 +00:00
|
|
|
packfile->filelen, zip);
|
|
|
|
file_from_pak = 1;
|
2003-02-14 19:46:07 +00:00
|
|
|
return qfs_filesize;
|
2002-06-14 20:36:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-08-27 17:53:24 +00:00
|
|
|
// sanity check the strings
|
|
|
|
if (strnlen (search->filename, sizeof (netpath))
|
|
|
|
+ strnlen (filename, sizeof (netpath)) + 2 > sizeof (netpath))
|
|
|
|
Sys_Error ("open_file: search->filename and/or filename "
|
|
|
|
"bogus: `%.*s' `%.*s'",
|
|
|
|
(int) sizeof (netpath), search->filename,
|
|
|
|
(int) sizeof (netpath), filename);
|
2002-06-14 20:36:28 +00:00
|
|
|
// check a file in the directory tree
|
2002-10-30 03:35:20 +00:00
|
|
|
snprintf (netpath, sizeof (netpath), "%s/%s", search->filename,
|
|
|
|
filename);
|
2002-06-14 20:36:28 +00:00
|
|
|
|
2003-04-09 05:55:41 +00:00
|
|
|
if (foundname) {
|
|
|
|
dstring_clearstr (foundname);
|
|
|
|
dstring_appendstr (foundname, filename);
|
|
|
|
}
|
2002-06-14 20:36:28 +00:00
|
|
|
if (Sys_FileTime (netpath) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
Sys_DPrintf ("FindFile: %s\n", netpath);
|
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
*gzfile = QFS_OpenRead (netpath, -1, -1, zip);
|
|
|
|
return qfs_filesize;
|
2002-06-14 20:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
int
|
2003-04-09 05:55:41 +00:00
|
|
|
_QFS_FOpenFile (const char *filename, QFile **gzfile,
|
|
|
|
dstring_t *foundname, int zip)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
searchpath_t *search;
|
2002-08-20 06:11:10 +00:00
|
|
|
char *path;
|
2002-06-14 20:36:28 +00:00
|
|
|
#ifdef HAVE_VORBIS
|
|
|
|
char oggfilename[MAX_OSPATH];
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2001-02-26 06:48:02 +00:00
|
|
|
char gzfilename[MAX_OSPATH];
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
2002-08-20 06:11:10 +00:00
|
|
|
// make sure they're not trying to do weird stuff with our private files
|
2003-02-14 19:46:07 +00:00
|
|
|
path = QFS_CompressPath (filename);
|
2002-08-20 06:11:10 +00:00
|
|
|
if (contains_updir(path)) {
|
|
|
|
Sys_Printf ("FindFile: %s: attempt to escape directory tree!\n", path);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2002-06-14 20:36:28 +00:00
|
|
|
#ifdef HAVE_VORBIS
|
2003-02-14 19:46:07 +00:00
|
|
|
if (strequal (".wav", QFS_FileExtension (path))) {
|
|
|
|
QFS_StripExtension (path, oggfilename);
|
2002-06-14 20:36:28 +00:00
|
|
|
strncat (oggfilename, ".ogg",
|
|
|
|
sizeof (oggfilename) - strlen (oggfilename) - 1);
|
|
|
|
} else {
|
|
|
|
oggfilename[0] = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ZLIB
|
2002-08-20 06:11:10 +00:00
|
|
|
snprintf (gzfilename, sizeof (gzfilename), "%s.gz", path);
|
2002-06-14 20:36:28 +00:00
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
// search through the path, one element at a time
|
2003-02-14 19:46:07 +00:00
|
|
|
for (search = qfs_searchpaths; search; search = search->next) {
|
2002-06-14 20:36:28 +00:00
|
|
|
#ifdef HAVE_VORBIS
|
2002-09-26 20:57:48 +00:00
|
|
|
//NOTE gzipped oggs not supported
|
2002-06-14 20:36:28 +00:00
|
|
|
if (oggfilename[0]
|
2002-09-26 20:57:48 +00:00
|
|
|
&& open_file (search, oggfilename, gzfile, foundname, false) != -1)
|
2002-08-20 06:11:10 +00:00
|
|
|
goto ok;
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
2002-04-30 04:39:03 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2002-06-14 20:36:28 +00:00
|
|
|
if (open_file (search, gzfilename, gzfile, foundname, zip) != -1)
|
2002-08-20 06:11:10 +00:00
|
|
|
goto ok;
|
2002-04-30 04:39:03 +00:00
|
|
|
#endif
|
2002-08-20 06:11:10 +00:00
|
|
|
if (open_file (search, path, gzfile, foundname, zip) != -1)
|
|
|
|
goto ok;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_DPrintf ("FindFile: can't find %s\n", filename);
|
2001-08-21 02:44:45 +00:00
|
|
|
error:
|
2001-02-19 21:15:25 +00:00
|
|
|
*gzfile = NULL;
|
2003-02-14 19:46:07 +00:00
|
|
|
qfs_filesize = -1;
|
2002-08-20 06:11:10 +00:00
|
|
|
free (path);
|
2001-02-19 21:15:25 +00:00
|
|
|
return -1;
|
2002-08-20 06:11:10 +00:00
|
|
|
ok:
|
|
|
|
free(path);
|
2003-02-14 19:46:07 +00:00
|
|
|
return qfs_filesize;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_FOpenFile (const char *filename, QFile **gzfile)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-04-09 05:55:41 +00:00
|
|
|
return _QFS_FOpenFile (filename, gzfile, 0, 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cache_user_t *loadcache;
|
2001-02-26 06:48:02 +00:00
|
|
|
byte *loadbuf;
|
|
|
|
int loadsize;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadFile
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Filename are relative to the quake directory.
|
2002-06-18 21:41:24 +00:00
|
|
|
Always appends a 0 byte to the loaded data.
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2003-05-08 23:24:02 +00:00
|
|
|
byte *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadFile (const char *path, int usehunk)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *h;
|
2001-03-09 07:58:10 +00:00
|
|
|
byte *buf = NULL;
|
2001-02-26 06:48:02 +00:00
|
|
|
char base[32];
|
|
|
|
int len;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
// look for it in the filesystem or pack files
|
2003-02-14 19:46:07 +00:00
|
|
|
len = qfs_filesize = QFS_FOpenFile (path, &h);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!h)
|
|
|
|
return NULL;
|
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
// extract the filename base name for hunk tag
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_FileBase (path, base);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (usehunk == 1)
|
2001-02-26 06:48:02 +00:00
|
|
|
buf = Hunk_AllocName (len + 1, base);
|
2001-02-19 21:15:25 +00:00
|
|
|
else if (usehunk == 2)
|
2001-02-26 06:48:02 +00:00
|
|
|
buf = Hunk_TempAlloc (len + 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
else if (usehunk == 0)
|
2001-02-26 06:48:02 +00:00
|
|
|
buf = calloc (1, len + 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
else if (usehunk == 3)
|
2001-02-26 06:48:02 +00:00
|
|
|
buf = Cache_Alloc (loadcache, len + 1, base);
|
|
|
|
else if (usehunk == 4) {
|
|
|
|
if (len + 1 > loadsize)
|
|
|
|
buf = Hunk_TempAlloc (len + 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
|
|
|
buf = loadbuf;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
2003-02-14 19:46:07 +00:00
|
|
|
Sys_Error ("QFS_LoadFile: bad usehunk");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!buf)
|
2003-02-14 19:46:07 +00:00
|
|
|
Sys_Error ("QFS_LoadFile: not enough space for %s", path);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-18 23:40:01 +00:00
|
|
|
buf[len] = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
Qread (h, buf, len);
|
|
|
|
Qclose (h);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
byte *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadHunkFile (const char *path)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-02-14 19:46:07 +00:00
|
|
|
return QFS_LoadFile (path, 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
byte *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadTempFile (const char *path)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-02-14 19:46:07 +00:00
|
|
|
return QFS_LoadFile (path, 2);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadCacheFile (const char *path, struct cache_user_s *cu)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
loadcache = cu;
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadFile (path, 3);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// uses temp hunk if larger than bufsize
|
2001-02-26 06:48:02 +00:00
|
|
|
byte *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadStackFile (const char *path, void *buffer, int bufsize)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
byte *buf;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
loadbuf = (byte *) buffer;
|
2001-02-19 21:15:25 +00:00
|
|
|
loadsize = bufsize;
|
2003-02-14 19:46:07 +00:00
|
|
|
buf = QFS_LoadFile (path, 4);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadPackFile
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static pack_t *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadPackFile (char *packfile)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-07-21 06:11:28 +00:00
|
|
|
pack_t *pack = pack_open (packfile);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-07-21 06:11:28 +00:00
|
|
|
if (pack)
|
|
|
|
Sys_Printf ("Added packfile %s (%i files)\n",
|
|
|
|
packfile, pack->numfiles);
|
2001-02-19 21:15:25 +00:00
|
|
|
return pack;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FBLOCK_SIZE 32
|
|
|
|
#define FNAME_SIZE MAX_OSPATH
|
|
|
|
|
|
|
|
// Note, this is /NOT/ a work-alike strcmp, this groups numbers sanely.
|
2002-10-30 02:43:23 +00:00
|
|
|
static int
|
2001-02-26 06:48:02 +00:00
|
|
|
qstrcmp (char **os1, char **os2)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int in1, in2, n1, n2;
|
|
|
|
char *s1, *s2;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
s1 = *os1;
|
|
|
|
s2 = *os2;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
in1 = in2 = n1 = n2 = 0;
|
|
|
|
|
2002-08-02 03:22:32 +00:00
|
|
|
if ((in1 = isdigit ((byte) *s1)))
|
2001-02-26 06:48:02 +00:00
|
|
|
n1 = strtol (s1, &s1, 10);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-02 03:22:32 +00:00
|
|
|
if ((in2 = isdigit ((byte) *s2)))
|
2001-02-26 06:48:02 +00:00
|
|
|
n2 = strtol (s2, &s2, 10);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (in1 && in2) {
|
|
|
|
if (n1 != n2)
|
2001-02-26 06:48:02 +00:00
|
|
|
return n1 - n2;
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
|
|
|
if (*s1 != *s2)
|
|
|
|
return *s1 - *s2;
|
|
|
|
else if (*s1 == '\0')
|
|
|
|
return *s1 - *s2;
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadGameDirectory (const char *dir)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
searchpath_t *search;
|
|
|
|
pack_t *pak;
|
|
|
|
DIR *dir_ptr;
|
|
|
|
struct dirent *dirent;
|
|
|
|
char **pakfiles = NULL;
|
|
|
|
int i = 0, bufsize = 0, count = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
Sys_DPrintf ("QFS_LoadGameDirectory (\"%s\")\n", dir);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
pakfiles = calloc (1, FBLOCK_SIZE * sizeof (char *));
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
bufsize += FBLOCK_SIZE;
|
|
|
|
if (!pakfiles)
|
2003-02-14 19:46:07 +00:00
|
|
|
goto QFS_LoadGameDirectory_free;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-12-05 16:29:09 +00:00
|
|
|
for (i = 0; i < bufsize; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
pakfiles[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
dir_ptr = opendir (dir);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!dir_ptr)
|
2003-02-14 19:46:07 +00:00
|
|
|
goto QFS_LoadGameDirectory_free;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while ((dirent = readdir (dir_ptr))) {
|
|
|
|
if (!fnmatch ("*.pak", dirent->d_name, 0)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (count >= bufsize) {
|
|
|
|
bufsize += FBLOCK_SIZE;
|
2001-02-26 06:48:02 +00:00
|
|
|
pakfiles = realloc (pakfiles, bufsize * sizeof (char *));
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!pakfiles)
|
2003-02-14 19:46:07 +00:00
|
|
|
goto QFS_LoadGameDirectory_free;
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = count; i < bufsize; i++)
|
|
|
|
pakfiles[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
pakfiles[count] = malloc (FNAME_SIZE);
|
2001-10-24 22:50:06 +00:00
|
|
|
if (!pakfiles[count])
|
2003-02-14 19:46:07 +00:00
|
|
|
Sys_Error ("QFS_LoadGameDirectory: MemoryAllocationFailure");
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (pakfiles[count], FNAME_SIZE - 1, "%s/%s", dir,
|
|
|
|
dirent->d_name);
|
2001-02-19 21:15:25 +00:00
|
|
|
pakfiles[count][FNAME_SIZE - 1] = '\0';
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
closedir (dir_ptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// XXX WARNING!!! This is /NOT/ subtable for strcmp!!!!!
|
2001-06-07 17:11:34 +00:00
|
|
|
// This passes 'void **' instead of 'char *' to the cmp function!
|
2001-02-26 06:48:02 +00:00
|
|
|
qsort (pakfiles, count, sizeof (char *),
|
|
|
|
(int (*)(const void *, const void *)) qstrcmp);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2003-02-14 19:46:07 +00:00
|
|
|
pak = QFS_LoadPackFile (pakfiles[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!pak) {
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error (va ("Bad pakfile %s!!", pakfiles[i]));
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2001-02-26 06:48:02 +00:00
|
|
|
search = calloc (1, sizeof (searchpath_t));
|
2001-02-19 21:15:25 +00:00
|
|
|
search->pack = pak;
|
2003-02-14 19:46:07 +00:00
|
|
|
search->next = qfs_searchpaths;
|
|
|
|
qfs_searchpaths = search;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadGameDirectory_free:
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2001-02-26 06:48:02 +00:00
|
|
|
free (pakfiles[i]);
|
|
|
|
free (pakfiles);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_AddDirectory
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-02-14 22:36:10 +00:00
|
|
|
Adds the directory to the head of the path, then loads and adds pak0.pak
|
|
|
|
pak1.pak ...
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_AddDirectory (const char *dir)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
searchpath_t *search;
|
2001-03-09 07:58:10 +00:00
|
|
|
char e_dir[MAX_OSPATH];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Qexpand_squiggle (dir, e_dir);
|
|
|
|
dir = e_dir;
|
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
// add the directory to the search path
|
2001-02-26 06:48:02 +00:00
|
|
|
search = calloc (1, sizeof (searchpath_t));
|
2001-02-19 21:15:25 +00:00
|
|
|
strcpy (search->filename, dir);
|
2003-02-14 19:46:07 +00:00
|
|
|
search->next = qfs_searchpaths;
|
|
|
|
qfs_searchpaths = search;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
// add any pak files in the format pak0.pak pak1.pak, ...
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_LoadGameDirectory (dir);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_AddGameDirectory (const char *dir)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-01-10 22:47:18 +00:00
|
|
|
if (!*dir)
|
|
|
|
return;
|
2003-02-14 19:46:07 +00:00
|
|
|
Sys_DPrintf ("QFS_AddGameDirectory (\"%s/%s\")\n",
|
2001-02-26 06:48:02 +00:00
|
|
|
fs_sharepath->string, dir);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (strcmp (fs_sharepath->string, fs_userpath->string) != 0)
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_AddDirectory (va ("%s/%s", fs_sharepath->string, dir));
|
|
|
|
QFS_AddDirectory (va ("%s/%s", fs_userpath->string, dir));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_Gamedir
|
2001-03-09 07:58:10 +00:00
|
|
|
|
|
|
|
Sets the gamedir and path to a different directory.
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
|
|
|
void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_Gamedir (const char *dir)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-01-27 21:56:30 +00:00
|
|
|
const char *list[2] = {dir, 0};
|
2003-01-10 22:47:18 +00:00
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_build_gamedir (list);
|
2001-03-09 07:58:10 +00:00
|
|
|
// flush all data, so it will be forced to reload
|
|
|
|
Cache_Flush ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-21 21:44:57 +00:00
|
|
|
void
|
2003-01-10 22:47:18 +00:00
|
|
|
QFS_Init (const char *game)
|
2001-03-09 07:58:10 +00:00
|
|
|
{
|
2003-01-22 20:00:46 +00:00
|
|
|
int i;
|
|
|
|
|
2001-04-10 23:39:30 +00:00
|
|
|
fs_sharepath = Cvar_Get ("fs_sharepath", FS_SHAREPATH, CVAR_ROM, NULL,
|
2001-08-22 22:03:16 +00:00
|
|
|
"location of shared (read only) game "
|
|
|
|
"directories");
|
2001-04-10 23:39:30 +00:00
|
|
|
fs_userpath = Cvar_Get ("fs_userpath", FS_USERPATH, CVAR_ROM, NULL,
|
2001-03-09 07:58:10 +00:00
|
|
|
"location of your game directories");
|
2003-01-10 22:47:18 +00:00
|
|
|
fs_dirconf = Cvar_Get ("fs_dirconf", "", CVAR_ROM, NULL,
|
|
|
|
"full path to gamedir.conf FIXME");
|
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
Cmd_AddCommand ("path", QFS_Path_f, "Show what paths Quake is using");
|
|
|
|
|
2003-01-10 22:47:18 +00:00
|
|
|
qfs_load_config ();
|
|
|
|
|
|
|
|
qfs_game = game;
|
|
|
|
|
2003-01-22 20:00:46 +00:00
|
|
|
if ((i = COM_CheckParm ("-game")) && i < com_argc - 1) {
|
|
|
|
char *gamedirs = NULL;
|
2003-01-27 21:56:30 +00:00
|
|
|
const char **list;
|
2003-01-22 20:00:46 +00:00
|
|
|
char *where;
|
|
|
|
int j, count = 1;
|
|
|
|
|
|
|
|
gamedirs = strdup (com_argv[i + 1]);
|
|
|
|
|
|
|
|
for (j = 0; gamedirs[j]; j++)
|
|
|
|
if (gamedirs[j] == ',')
|
|
|
|
count++;
|
|
|
|
|
2003-04-21 04:49:02 +00:00
|
|
|
list = calloc (count + 1, sizeof (char *));
|
2003-01-22 20:00:46 +00:00
|
|
|
|
|
|
|
j = 0;
|
|
|
|
where = strtok (gamedirs, ",");
|
|
|
|
while (where) {
|
|
|
|
list[j++] = where;
|
|
|
|
where = strtok (NULL, ",");
|
|
|
|
}
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_build_gamedir (list);
|
2003-01-22 20:00:46 +00:00
|
|
|
free (gamedirs);
|
|
|
|
free (list);
|
|
|
|
} else {
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_Gamedir ("");
|
2003-01-22 20:00:46 +00:00
|
|
|
}
|
2001-03-09 07:58:10 +00:00
|
|
|
}
|
|
|
|
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_SkipPath (const char *pathname)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *last;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
// char after last / on the line
|
2001-03-01 07:42:28 +00:00
|
|
|
if ((last = strrchr (pathname, '/')))
|
|
|
|
last++;
|
|
|
|
else
|
|
|
|
last = pathname;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_StripExtension (const char *in, char *out)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
while (*in && *in != '.')
|
|
|
|
*out++ = *in++;
|
|
|
|
*out = 0;
|
|
|
|
}
|
|
|
|
|
2002-06-14 20:36:28 +00:00
|
|
|
const char *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_FileExtension (const char *in)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
while (*in && *in != '.')
|
|
|
|
in++;
|
2002-06-14 20:36:28 +00:00
|
|
|
return in;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_DefaultExtension (char *path, const char *extension)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
char *src;
|
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
// if path doesn't have a .EXT, append extension
|
|
|
|
// (extension should include the .)
|
2001-02-26 06:48:02 +00:00
|
|
|
src = path + strlen (path) - 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while (*src != '/' && src != path) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (*src == '.')
|
2001-02-26 06:48:02 +00:00
|
|
|
return; // it has an extension
|
2001-02-19 21:15:25 +00:00
|
|
|
src--;
|
|
|
|
}
|
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
strncat (path, extension, MAX_OSPATH - strlen (path));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_NextFilename (char *filename, const char *prefix, const char *ext)
|
2001-03-09 07:58:10 +00:00
|
|
|
{
|
|
|
|
char *digits;
|
2003-02-16 22:43:06 +00:00
|
|
|
char checkname[MAX_OSPATH], exp[MAX_OSPATH];
|
2001-03-09 07:58:10 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
strncpy (filename, prefix, MAX_OSPATH - 4);
|
|
|
|
filename[MAX_OSPATH - 4] = 0;
|
|
|
|
digits = filename + strlen (filename);
|
|
|
|
strcat (filename, "000");
|
|
|
|
strncat (filename, ext, MAX_OSPATH - strlen (filename));
|
2003-02-16 22:43:06 +00:00
|
|
|
Qexpand_squiggle (fs_userpath->string, exp);
|
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
for (i = 0; i <= 999; i++) {
|
|
|
|
digits[0] = i / 100 + '0';
|
|
|
|
digits[1] = i / 10 % 10 + '0';
|
|
|
|
digits[2] = i % 10 + '0';
|
2003-02-14 22:36:10 +00:00
|
|
|
snprintf (checkname, sizeof (checkname),
|
2003-02-16 22:43:06 +00:00
|
|
|
"%s/%s/%s", exp, qfs_gamedir->dir.def,
|
2001-03-09 07:58:10 +00:00
|
|
|
filename);
|
|
|
|
if (Sys_FileTime (checkname) == -1)
|
|
|
|
return 1; // file doesn't exist
|
|
|
|
}
|
|
|
|
return 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-02-14 22:36:10 +00:00
|
|
|
|
|
|
|
QFile *
|
|
|
|
QFS_WOpen (const char *path, int zip)
|
|
|
|
{
|
|
|
|
dstring_t *full_path = dstring_new ();
|
|
|
|
QFile *file;
|
|
|
|
char mode[4] = "wb\000\000";
|
|
|
|
|
|
|
|
if (zip)
|
2003-05-09 21:10:59 +00:00
|
|
|
mode[2] = bound (1, zip, 9) + '0';
|
2003-02-14 22:36:10 +00:00
|
|
|
dsprintf (full_path, "%s/%s", fs_userpath->string, path);
|
|
|
|
QFS_CreatePath (full_path->str);
|
|
|
|
file = Qopen (full_path->str, mode);
|
|
|
|
dstring_delete (full_path);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QFS_Rename (const char *old, const char *new)
|
|
|
|
{
|
|
|
|
dstring_t *full_old = dstring_new ();
|
|
|
|
dstring_t *full_new = dstring_new ();
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dsprintf (full_old, "%s/%s", fs_userpath->string, old);
|
|
|
|
dsprintf (full_new, "%s/%s", fs_userpath->string, new);
|
|
|
|
QFS_CreatePath (full_new->str);
|
|
|
|
ret = Qrename (full_old->str, full_new->str);
|
|
|
|
dstring_delete (full_old);
|
|
|
|
dstring_delete (full_new);
|
|
|
|
return ret;
|
|
|
|
}
|