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
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$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
|
2003-05-23 17:17:01 +00:00
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
# include <io.h>
|
2003-07-09 04:21:45 +00:00
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-08-25 13:35:20 +00:00
|
|
|
#if defined(_WIN32) && defined(HAVE_MALLOC_H)
|
2007-03-22 23:20:57 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#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>
|
2007-03-19 10:43:29 +00:00
|
|
|
#include <sys/stat.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
|
2004-01-20 03:47:27 +00:00
|
|
|
# ifdef _WIN32
|
2001-09-29 09:39:27 +00:00
|
|
|
# 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"
|
2011-12-24 01:04:33 +00:00
|
|
|
#include "QF/mathlib.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.
|
2010-01-13 06:42:26 +00:00
|
|
|
The base directory is used only during filesystem initialization.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2010-01-13 06:42:26 +00:00
|
|
|
The "cache directory" is used only during development to save network
|
2001-02-19 21:15:25 +00:00
|
|
|
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
|
|
|
|
2010-08-24 07:48:49 +00:00
|
|
|
static cvar_t *fs_userpath;
|
|
|
|
static cvar_t *fs_sharepath;
|
|
|
|
static cvar_t *fs_dirconf;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE const char *qfs_userpath;
|
2003-05-23 17:17:01 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int qfs_filesize;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-24 07:47:39 +00:00
|
|
|
typedef struct searchpath_s {
|
|
|
|
char *filename;
|
|
|
|
struct pack_s *pack; // only one of filename / pack will be used
|
|
|
|
struct searchpath_s *next;
|
|
|
|
} searchpath_t;
|
|
|
|
|
|
|
|
static 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;
|
|
|
|
|
2010-08-25 00:57:44 +00:00
|
|
|
static void qfs_add_gamedir (const char *dir);
|
2003-01-10 22:47:18 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE gamedir_t *qfs_gamedir;
|
2003-01-10 22:47:18 +00:00
|
|
|
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\";"
|
2011-09-10 23:04:47 +00:00
|
|
|
" HudType = \"id\";"
|
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\";"
|
2011-09-10 23:04:47 +00:00
|
|
|
" HudType = \"id\";"
|
|
|
|
" };"
|
|
|
|
" \"Hipnotic\" = {"
|
|
|
|
" Inherit = (Quake);"
|
|
|
|
" Path = \"hipnotic\";"
|
|
|
|
" HudType = \"hipnotic\";"
|
|
|
|
" };"
|
|
|
|
" \"Rogue\" = {"
|
|
|
|
" Inherit = (Quake);"
|
|
|
|
" Path = \"rogue\";"
|
|
|
|
" HudType = \"rogue\";"
|
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
|
|
|
" };"
|
2005-02-14 09:08:32 +00:00
|
|
|
" \"hipnotic:*\" = {"
|
2011-09-10 23:04:47 +00:00
|
|
|
" Inherit = (Hipnotic);"
|
2005-02-14 09:08:32 +00:00
|
|
|
" Path = \"$gamedir\";"
|
|
|
|
" };"
|
|
|
|
" \"rogue:*\" = {"
|
2011-09-10 23:04:47 +00:00
|
|
|
" Inherit = (Rogue);"
|
2005-02-14 09:08:32 +00:00
|
|
|
" Path = \"$gamedir\";"
|
|
|
|
" };"
|
|
|
|
" \"abyss\" = {"
|
|
|
|
" Inherit = (Quake);"
|
|
|
|
" Path = \"abyss\";"
|
|
|
|
" };"
|
|
|
|
" \"abyss:*\" = {"
|
|
|
|
" Inherit = (abyss);"
|
|
|
|
" Path = \"$gamedir\";"
|
|
|
|
" };"
|
2003-01-10 22:47:18 +00:00
|
|
|
"}";
|
|
|
|
|
2004-02-03 03:01:06 +00:00
|
|
|
|
2010-08-24 07:33:22 +00:00
|
|
|
#define GAMEDIR_CALLBACK_CHUNK 16
|
|
|
|
static gamedir_callback_t **gamedir_callbacks;
|
2004-02-03 03:01:06 +00:00
|
|
|
static int num_gamedir_callbacks;
|
2010-08-24 07:33:22 +00:00
|
|
|
static int max_gamedir_callbacks;
|
2004-02-03 03:01:06 +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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2011-09-11 04:09:24 +00:00
|
|
|
return dstring_freeze (new);
|
2003-01-27 18:16:15 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2010-08-20 03:58:37 +00:00
|
|
|
const char *ps;
|
2003-01-10 22:47:18 +00:00
|
|
|
|
2010-08-20 03:58:37 +00:00
|
|
|
if ((p = PL_ObjectForKey (gdpl, "Path")) && *(ps = PL_String (p))) {
|
|
|
|
char *str = qfs_var_subst (ps, vars);
|
2003-01-27 21:56:30 +00:00
|
|
|
|
2011-09-11 04:10:14 +00:00
|
|
|
qfs_set_var (vars, "path", 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")))
|
2010-08-20 03:58:37 +00:00
|
|
|
gamedir->gamecode = qfs_var_subst (PL_String (p), vars);
|
2011-09-10 23:04:47 +00:00
|
|
|
if (!gamedir->hudtype && (p = PL_ObjectForKey (gdpl, "HudType")))
|
|
|
|
gamedir->hudtype = qfs_var_subst (PL_String (p), vars);
|
2003-02-14 22:36:10 +00:00
|
|
|
if (!gamedir->dir.skins && (p = PL_ObjectForKey (gdpl, "SkinPath")))
|
2010-08-20 03:58:37 +00:00
|
|
|
gamedir->dir.skins = qfs_var_subst (PL_String (p), vars);
|
2010-08-24 13:42:00 +00:00
|
|
|
if (!gamedir->dir.models && (p = PL_ObjectForKey (gdpl, "ModelPath")))
|
|
|
|
gamedir->dir.models = qfs_var_subst (PL_String (p), vars);
|
2003-02-14 22:36:10 +00:00
|
|
|
if (!gamedir->dir.sound && (p = PL_ObjectForKey (gdpl, "SoundPath")))
|
2010-08-20 03:58:37 +00:00
|
|
|
gamedir->dir.sound = qfs_var_subst (PL_String (p), vars);
|
2003-02-14 22:36:10 +00:00
|
|
|
if (!gamedir->dir.maps && (p = PL_ObjectForKey (gdpl, "MapPath")))
|
2010-08-20 03:58:37 +00:00
|
|
|
gamedir->dir.maps = qfs_var_subst (PL_String (p), vars);
|
2012-01-05 08:04:23 +00:00
|
|
|
if (!gamedir->dir.shots && (p = PL_ObjectForKey (gdpl, "ShotsPath")))
|
|
|
|
gamedir->dir.shots = qfs_var_subst (PL_String (p), 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
|
|
|
{
|
2010-08-20 03:58:37 +00:00
|
|
|
plitem_t *base_item;
|
2003-01-10 22:47:18 +00:00
|
|
|
|
2010-08-20 03:58:37 +00:00
|
|
|
if (!(base_item = PL_ObjectForKey (gdpl, "Inherit")))
|
2003-01-10 22:47:18 +00:00
|
|
|
return;
|
2010-08-20 03:58:37 +00:00
|
|
|
switch (PL_Type (base_item)) {
|
|
|
|
case QFString:
|
|
|
|
{
|
|
|
|
const char *base = PL_String (base_item);
|
|
|
|
if (Hash_Find (dirs, base))
|
|
|
|
return;
|
|
|
|
gdpl = PL_ObjectForKey (plist, base);
|
|
|
|
if (!gdpl) {
|
|
|
|
Sys_Printf ("base `%s' not found\n", base);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qfs_set_var (vars, "gamedir", base);
|
|
|
|
Hash_Add (dirs, strdup (base));
|
|
|
|
qfs_get_gd_params (gdpl, gamedir, path, vars);
|
|
|
|
qfs_inherit (plist, gdpl, gamedir, path, dirs, vars);
|
2003-01-10 22:47:18 +00:00
|
|
|
}
|
2010-08-20 03:58:37 +00:00
|
|
|
break;
|
|
|
|
case QFArray:
|
|
|
|
{
|
|
|
|
int i, num_dirs;
|
|
|
|
plitem_t *basedir_item;
|
|
|
|
const char *basedir;
|
|
|
|
|
|
|
|
num_dirs = PL_A_NumObjects (base_item);
|
|
|
|
for (i = 0; i < num_dirs; i++) {
|
|
|
|
basedir_item = PL_ObjectAtIndex (base_item, i);
|
|
|
|
if (!basedir_item)
|
|
|
|
continue;
|
|
|
|
basedir = PL_String (basedir_item);
|
|
|
|
if (!basedir || Hash_Find (dirs, basedir))
|
|
|
|
continue;
|
|
|
|
gdpl = PL_ObjectForKey (plist, basedir);
|
|
|
|
if (!gdpl) {
|
|
|
|
Sys_Printf ("base `%s' not found\n", basedir);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
qfs_set_var (vars, "gamedir", basedir);
|
|
|
|
Hash_Add (dirs, strdup (basedir));
|
|
|
|
qfs_get_gd_params (gdpl, gamedir, path, vars);
|
|
|
|
qfs_inherit (plist, gdpl, gamedir, path, dirs, vars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2003-01-10 22:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
qfs_compare (const void *a, const void *b)
|
|
|
|
{
|
2010-08-20 02:57:47 +00:00
|
|
|
return strcmp (*(const char **) a, *(const char **) b);
|
2003-01-10 22:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
qfs_dir_get_key (void *_k, void *unused)
|
|
|
|
{
|
|
|
|
return _k;
|
|
|
|
}
|
|
|
|
|
2004-01-07 06:40:10 +00:00
|
|
|
static void
|
|
|
|
qfs_dir_free (void *_k, void *unused)
|
|
|
|
{
|
|
|
|
free (_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) {
|
2010-08-20 02:57:47 +00:00
|
|
|
plitem_t *keys = PL_D_AllKeys (qfs_gd_plist);
|
|
|
|
int num_keys = PL_A_NumObjects (keys);
|
|
|
|
const char **list = malloc (num_keys * sizeof (char *));
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_keys; i++)
|
|
|
|
list[i] = PL_String (PL_ObjectAtIndex (keys, i));
|
|
|
|
qsort (list, num_keys, sizeof (const char *), qfs_compare);
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
if (!fnmatch (list[i], name, 0)) {
|
|
|
|
gdpl = PL_ObjectForKey (qfs_gd_plist, list[i]);
|
|
|
|
Hash_Add (dirs, strdup (list[i]));
|
2003-01-10 22:47:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (list);
|
2010-08-20 02:57:47 +00:00
|
|
|
PL_Free (keys);
|
2003-01-10 22:47:18 +00:00
|
|
|
}
|
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);
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_add_gamedir (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;
|
2004-01-07 06:40:10 +00:00
|
|
|
hashtab_t *dirs = Hash_NewTable (31, qfs_dir_get_key, qfs_dir_free, 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);
|
2010-08-24 13:42:00 +00:00
|
|
|
if (qfs_gamedir->dir.models)
|
|
|
|
free ((char *)qfs_gamedir->dir.models);
|
2003-02-14 22:36:10 +00:00
|
|
|
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
|
|
|
}
|
2010-08-24 07:20:07 +00:00
|
|
|
if (qfs_searchpaths->filename)
|
|
|
|
free (qfs_searchpaths->filename);
|
|
|
|
|
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;
|
|
|
|
}
|
2004-01-07 06:40:10 +00:00
|
|
|
Hash_Add (dirs, strdup (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);
|
2012-01-05 05:00:57 +00:00
|
|
|
if (!gamedir->hudtype)
|
|
|
|
gamedir->hudtype = strdup ("id");
|
2003-02-14 22:36:10 +00:00
|
|
|
if (!gamedir->dir.skins)
|
|
|
|
gamedir->dir.skins = nva ("%s/skins", gamedir->dir.def);
|
2010-08-24 13:42:00 +00:00
|
|
|
if (!gamedir->dir.models)
|
|
|
|
gamedir->dir.models = nva ("%s/progs", gamedir->dir.def);
|
2003-02-14 22:36:10 +00:00
|
|
|
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);
|
2012-01-05 08:04:23 +00:00
|
|
|
if (!gamedir->dir.shots)
|
|
|
|
gamedir->dir.shots = strdup ("QF");
|
2003-02-14 22:36:10 +00:00
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_gamedir = gamedir;
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS, "%s\n", qfs_gamedir->name);
|
|
|
|
Sys_MaskPrintf (SYS_FS, " gamedir : %s\n", qfs_gamedir->gamedir);
|
|
|
|
Sys_MaskPrintf (SYS_FS, " path : %s\n", qfs_gamedir->path);
|
|
|
|
Sys_MaskPrintf (SYS_FS, " gamecode: %s\n", qfs_gamedir->gamecode);
|
2011-09-10 23:04:47 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS, " hudtype : %s\n", qfs_gamedir->hudtype);
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS, " def : %s\n", qfs_gamedir->dir.def);
|
|
|
|
Sys_MaskPrintf (SYS_FS, " skins : %s\n", qfs_gamedir->dir.skins);
|
|
|
|
Sys_MaskPrintf (SYS_FS, " models : %s\n", qfs_gamedir->dir.models);
|
|
|
|
Sys_MaskPrintf (SYS_FS, " sound : %s\n", qfs_gamedir->dir.sound);
|
|
|
|
Sys_MaskPrintf (SYS_FS, " 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)
|
|
|
|
{
|
2007-04-07 12:17:01 +00:00
|
|
|
QFile *f = 0;
|
2003-01-10 22:47:18 +00:00
|
|
|
int len;
|
|
|
|
char *buf;
|
2004-01-06 07:33:19 +00:00
|
|
|
char *dirconf;
|
2003-01-10 22:47:18 +00:00
|
|
|
|
2007-04-07 12:17:01 +00:00
|
|
|
if (*fs_dirconf->string) {
|
2010-08-24 07:01:01 +00:00
|
|
|
dirconf = Sys_ExpandSquiggle (fs_dirconf->string);
|
2007-04-07 12:17:01 +00:00
|
|
|
if (!(f = Qopen (dirconf, "rt")))
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS,
|
2010-11-23 05:09:30 +00:00
|
|
|
"Could not load `%s', using builtin defaults\n",
|
|
|
|
dirconf);
|
2007-04-07 12:17:01 +00:00
|
|
|
free (dirconf);
|
|
|
|
}
|
2004-01-06 07:33:19 +00:00
|
|
|
if (!f)
|
2003-01-10 22:47:18 +00:00
|
|
|
goto no_config;
|
2004-01-06 07:33:19 +00:00
|
|
|
|
2003-01-10 22:47:18 +00:00
|
|
|
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;
|
2005-05-05 22:50:09 +00:00
|
|
|
if (qfs_gd_plist)
|
|
|
|
PL_Free (qfs_gd_plist);
|
2003-01-10 22:47:18 +00:00
|
|
|
qfs_gd_plist = PL_GetPropertyList (buf);
|
|
|
|
free (buf);
|
2010-08-20 03:58:37 +00:00
|
|
|
if (qfs_gd_plist && PL_Type (qfs_gd_plist) == QFDictionary)
|
2003-01-10 22:47:18 +00:00
|
|
|
return; // done
|
|
|
|
Sys_Printf ("not a dictionary\n");
|
|
|
|
no_config:
|
2005-05-05 22:50:09 +00:00
|
|
|
if (qfs_gd_plist)
|
|
|
|
PL_Free (qfs_gd_plist);
|
2003-01-10 22:47:18 +00:00
|
|
|
qfs_gd_plist = PL_GetPropertyList (qfs_default_dirconf);
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:26:31 +00:00
|
|
|
/*
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_contains_updir
|
2010-08-24 23:26:31 +00:00
|
|
|
|
|
|
|
Checks if a string contains an updir ('..'), either at the ends or
|
|
|
|
surrounded by slashes ('/'). Doesn't check for leading slash.
|
|
|
|
Assumes canonical (compressed) path.
|
|
|
|
*/
|
|
|
|
static inline int
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_contains_updir (const char *path, int levels)
|
2010-08-24 23:26:31 +00:00
|
|
|
{
|
|
|
|
do {
|
|
|
|
if (path[0] != '.' || path[1] != '.'
|
|
|
|
|| (path[2] != '/' && path[2] != 0))
|
|
|
|
return 0;
|
|
|
|
if (!path[2])
|
|
|
|
break;
|
|
|
|
// first part of path is ../
|
|
|
|
if (levels <= 0)
|
|
|
|
return 1;
|
|
|
|
path += 3;
|
|
|
|
} while (levels-- > 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-10-16 05:17:09 +00:00
|
|
|
qfs_expand_path (dstring_t *full_path, const char *base, const char *path,
|
|
|
|
int levels)
|
2010-08-24 23:26:31 +00:00
|
|
|
{
|
|
|
|
const char *separator = "/";
|
|
|
|
char *cpath;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!base || !*base) {
|
|
|
|
errno = EACCES;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cpath = QFS_CompressPath (path);
|
2010-10-16 05:17:09 +00:00
|
|
|
if (qfs_contains_updir (cpath, levels)) {
|
2010-08-24 23:26:31 +00:00
|
|
|
free (cpath);
|
|
|
|
errno = EACCES;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*cpath == '/')
|
|
|
|
separator = "";
|
|
|
|
len = strlen (base);
|
2011-09-09 08:30:07 +00:00
|
|
|
if (len && base[len - 1] == '/')
|
2010-08-24 23:26:31 +00:00
|
|
|
len--;
|
|
|
|
dsprintf (full_path, "%.*s%s%s", len, base, separator, cpath);
|
|
|
|
free (cpath);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
qfs_expand_userpath (dstring_t *full_path, const char *path)
|
|
|
|
{
|
2010-10-16 05:17:09 +00:00
|
|
|
return qfs_expand_path (full_path, qfs_userpath, path, 0);
|
2010-08-24 23:26:31 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE char *
|
2003-07-08 22:39:45 +00:00
|
|
|
QFS_FileBase (const char *in)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2011-09-09 08:39:00 +00:00
|
|
|
const char *base;
|
|
|
|
const char *ext;
|
2011-09-09 10:55:54 +00:00
|
|
|
int len;
|
2003-07-08 22:39:45 +00:00
|
|
|
char *out;
|
2001-03-09 07:58:10 +00:00
|
|
|
|
2011-09-09 08:39:00 +00:00
|
|
|
base = QFS_SkipPath (in);
|
|
|
|
ext = QFS_FileExtension (base);
|
|
|
|
len = ext - base;
|
|
|
|
out = malloc (len + 1);
|
2011-09-09 10:55:54 +00:00
|
|
|
strncpy (out, base, len);
|
2011-09-09 08:39:00 +00:00
|
|
|
out [len] = 0;
|
2003-07-08 22:39:45 +00:00
|
|
|
return out;
|
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
|
2010-08-25 00:57:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2004-01-19 07:47:41 +00:00
|
|
|
QFS_WriteFile (const char *filename, const void *data, int len)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *f;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-05-23 17:17:01 +00:00
|
|
|
f = QFS_WOpen (filename, 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
|
|
|
}
|
|
|
|
|
|
|
|
Qwrite (f, data, len);
|
|
|
|
Qclose (f);
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static QFile *
|
2010-08-25 00:57:44 +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
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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] == '.'
|
2010-08-25 03:04:58 +00:00
|
|
|
&& (d[2] == '/' || d[2] == '\0')) {
|
|
|
|
p += 2 + (p[2] == '/');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (d[0] == '/'
|
|
|
|
&& d[1] == '.' && d[2] == '.'
|
|
|
|
&& (d[3] == '/' || d[3] == '\0')) {
|
|
|
|
*p = 0;
|
2002-08-20 06:11:10 +00:00
|
|
|
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++;
|
2007-03-21 13:05:23 +00:00
|
|
|
if (*p == '/') {
|
2002-08-20 06:11:10 +00:00
|
|
|
p++;
|
2010-08-25 03:04:58 +00:00
|
|
|
// skip over multiple / (foo//bar -> foo/bar)
|
2007-03-21 13:05:23 +00:00
|
|
|
for (d = p; *d == '/'; d++)
|
|
|
|
;
|
|
|
|
if (d != p)
|
|
|
|
strcpy (p, d);
|
|
|
|
}
|
2002-08-20 06:11:10 +00:00
|
|
|
}
|
2010-08-25 03:04:58 +00:00
|
|
|
// strip any trailing /, but not if it's the root /
|
|
|
|
if (--p != path && *p == '/')
|
|
|
|
*p = 0;
|
2002-08-20 06:11:10 +00:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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
|
|
|
{
|
|
|
|
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) {
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS_F, "PackFile: %s : %s\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
search->pack->filename, packfile->name);
|
2002-06-14 20:36:28 +00:00
|
|
|
// 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);
|
|
|
|
}
|
2010-08-25 00:57:44 +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 {
|
|
|
|
// check a file in the directory tree
|
2010-08-24 23:26:31 +00:00
|
|
|
dstring_t *netpath = dstring_new ();
|
2002-06-14 20:36:28 +00:00
|
|
|
|
2010-10-16 05:17:09 +00:00
|
|
|
if (qfs_expand_path (netpath, search->filename, filename, 1) == 0) {
|
2010-08-24 23:26:31 +00:00
|
|
|
if (foundname) {
|
|
|
|
dstring_clearstr (foundname);
|
|
|
|
dstring_appendstr (foundname, filename);
|
|
|
|
}
|
|
|
|
if (Sys_FileTime (netpath->str) == -1) {
|
|
|
|
dstring_delete (netpath);
|
|
|
|
return -1;
|
|
|
|
}
|
2002-06-14 20:36:28 +00:00
|
|
|
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS_F, "FindFile: %s\n", netpath->str);
|
2002-06-14 20:36:28 +00:00
|
|
|
|
2010-08-25 00:57:44 +00:00
|
|
|
*gzfile = qfs_openread (netpath->str, -1, -1, zip);
|
2010-08-24 23:26:31 +00:00
|
|
|
dstring_delete (netpath);
|
|
|
|
return qfs_filesize;
|
|
|
|
}
|
|
|
|
dstring_delete (netpath);
|
|
|
|
return -1;
|
2002-06-14 20:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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
|
2003-07-08 22:39:45 +00:00
|
|
|
char *oggfilename;
|
2002-06-14 20:36:28 +00:00
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2003-07-08 22:39:45 +00:00
|
|
|
char *gzfilename;
|
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);
|
2010-08-25 00:57:44 +00:00
|
|
|
if (qfs_contains_updir(path, 1)) {
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS,
|
2010-11-23 05:09:30 +00:00
|
|
|
"FindFile: %s: attempt to escape directory tree!\n",
|
|
|
|
path);
|
2002-08-20 06:11:10 +00:00
|
|
|
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))) {
|
2003-07-08 22:39:45 +00:00
|
|
|
oggfilename = alloca (strlen (path) + 1);
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_StripExtension (path, oggfilename);
|
2002-06-14 20:36:28 +00:00
|
|
|
strncat (oggfilename, ".ogg",
|
|
|
|
sizeof (oggfilename) - strlen (oggfilename) - 1);
|
|
|
|
} else {
|
2003-07-08 22:39:45 +00:00
|
|
|
oggfilename = 0;
|
2002-06-14 20:36:28 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ZLIB
|
2003-07-08 22:39:45 +00:00
|
|
|
gzfilename = alloca (strlen (path) + 3 + 1);
|
2003-07-09 15:38:19 +00:00
|
|
|
sprintf (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
|
2003-07-08 22:39:45 +00:00
|
|
|
if (oggfilename
|
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
|
|
|
}
|
|
|
|
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS_NF, "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
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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;
|
2003-07-08 22:39:45 +00:00
|
|
|
char *base;
|
2001-02-26 06:48:02 +00:00
|
|
|
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-07-08 22:39:45 +00:00
|
|
|
base = QFS_FileBase (path);
|
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);
|
|
|
|
|
2003-07-08 22:39:45 +00:00
|
|
|
free (base);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_load_pakfile
|
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 *
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_load_pakfile (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)
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS, "Added packfile %s (%i files)\n",
|
2002-07-21 06:11:28 +00:00
|
|
|
packfile, pack->numfiles);
|
2001-02-19 21:15:25 +00:00
|
|
|
return pack;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FBLOCK_SIZE 32
|
|
|
|
|
|
|
|
// Note, this is /NOT/ a work-alike strcmp, this groups numbers sanely.
|
2002-10-30 02:43:23 +00:00
|
|
|
static int
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_file_sort (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
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_load_gamedir (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
|
|
|
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS, "qfs_load_gamedir (\"%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)
|
2010-08-25 00:57:44 +00:00
|
|
|
goto qfs_load_gamedir_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)
|
2010-08-25 00:57:44 +00:00
|
|
|
goto qfs_load_gamedir_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)
|
2010-08-25 00:57:44 +00:00
|
|
|
goto qfs_load_gamedir_free;
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = count; i < bufsize; i++)
|
|
|
|
pakfiles[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:26:31 +00:00
|
|
|
// at this point, dir is known to not have a trailing /, and
|
|
|
|
// dirent->d_name definitely won't start with one.
|
2010-08-24 07:20:07 +00:00
|
|
|
pakfiles[count] = nva ("%s/%s", dir, dirent->d_name);
|
2001-10-24 22:50:06 +00:00
|
|
|
if (!pakfiles[count])
|
2010-08-25 00:57:44 +00:00
|
|
|
Sys_Error ("qfs_load_gamedir: Memory allocation failure");
|
2001-02-19 21:15:25 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
closedir (dir_ptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qsort (pakfiles, count, sizeof (char *),
|
2010-08-25 00:57:44 +00:00
|
|
|
(int (*)(const void *, const void *)) qfs_file_sort);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2010-08-25 00:57:44 +00:00
|
|
|
pak = qfs_load_pakfile (pakfiles[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!pak) {
|
2004-11-02 07:39:00 +00:00
|
|
|
Sys_Error ("Bad pakfile %s!!", pakfiles[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2010-08-24 07:20:07 +00:00
|
|
|
search = malloc (sizeof (searchpath_t));
|
|
|
|
search->filename = 0;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_load_gamedir_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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_add_dir
|
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
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_add_dir (const char *dir)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
searchpath_t *search;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-09 07:58:10 +00:00
|
|
|
// add the directory to the search path
|
2010-08-24 07:20:07 +00:00
|
|
|
search = malloc (sizeof (searchpath_t));
|
|
|
|
search->filename = strdup (dir);
|
|
|
|
search->pack = 0;
|
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, ...
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_load_gamedir (dir);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_add_gamedir (const char *dir)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2005-09-06 11:39:32 +00:00
|
|
|
const char *e;
|
|
|
|
const char *s;
|
|
|
|
dstring_t *s_dir;
|
2010-08-24 23:26:31 +00:00
|
|
|
dstring_t *f_dir;
|
2005-09-06 11:39:32 +00:00
|
|
|
|
2003-01-10 22:47:18 +00:00
|
|
|
if (!*dir)
|
|
|
|
return;
|
2005-09-06 11:39:32 +00:00
|
|
|
e = fs_sharepath->string + strlen (fs_sharepath->string);
|
|
|
|
s = e;
|
|
|
|
s_dir = dstring_new ();
|
2010-08-24 23:26:31 +00:00
|
|
|
f_dir = dstring_new ();
|
2005-09-06 11:39:32 +00:00
|
|
|
|
|
|
|
while (s >= fs_sharepath->string) {
|
|
|
|
while (s != fs_sharepath->string && s[-1] !=':')
|
|
|
|
s--;
|
|
|
|
if (s != e) {
|
|
|
|
dsprintf (s_dir, "%.*s", (int) (e - s), s);
|
|
|
|
if (strcmp (s_dir->str, fs_userpath->string) != 0) {
|
2010-10-16 05:17:09 +00:00
|
|
|
if (qfs_expand_path (f_dir, s_dir->str, dir, 0) != 0) {
|
2010-08-24 23:26:31 +00:00
|
|
|
Sys_Printf ("dropping bad directory %s\n", dir);
|
|
|
|
break;
|
|
|
|
}
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS, "qfs_add_gamedir (\"%s\")\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
f_dir->str);
|
2005-09-06 11:39:32 +00:00
|
|
|
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_add_dir (f_dir->str);
|
2005-09-06 11:39:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
e = --s;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-24 23:26:31 +00:00
|
|
|
qfs_expand_userpath (f_dir, dir);
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS, "qfs_add_gamedir (\"%s\")\n", f_dir->str);
|
2010-08-25 00:57:44 +00:00
|
|
|
qfs_add_dir (f_dir->str);
|
2010-08-24 23:26:31 +00:00
|
|
|
|
|
|
|
dstring_delete (f_dir);
|
|
|
|
dstring_delete (s_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
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2010-08-24 23:25:23 +00:00
|
|
|
QFS_Gamedir (const char *gamedir)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2004-02-03 03:01:06 +00:00
|
|
|
int i;
|
2010-08-24 23:25:23 +00:00
|
|
|
const char *list[2] = {gamedir, 0};
|
2003-01-10 22:47:18 +00:00
|
|
|
|
2003-01-27 21:56:30 +00:00
|
|
|
qfs_build_gamedir (list);
|
2004-02-03 03:01:06 +00:00
|
|
|
|
|
|
|
// Make sure everyone else knows we've changed gamedirs
|
|
|
|
for (i = 0; i < num_gamedir_callbacks; i++) {
|
2007-03-24 10:13:10 +00:00
|
|
|
gamedir_callbacks[i] (0);
|
2004-02-03 03:01:06 +00:00
|
|
|
}
|
2001-03-09 07:58:10 +00:00
|
|
|
Cache_Flush ();
|
2007-03-24 10:13:10 +00:00
|
|
|
for (i = 0; i < num_gamedir_callbacks; i++) {
|
|
|
|
gamedir_callbacks[i] (1);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2004-02-03 03:01:06 +00:00
|
|
|
QFS_GamedirCallback (gamedir_callback_t *func)
|
|
|
|
{
|
2010-08-24 07:33:22 +00:00
|
|
|
if (num_gamedir_callbacks == max_gamedir_callbacks) {
|
|
|
|
size_t size = (max_gamedir_callbacks + GAMEDIR_CALLBACK_CHUNK)
|
|
|
|
* sizeof (gamedir_callback_t *);
|
|
|
|
gamedir_callbacks = realloc (gamedir_callbacks, size);
|
|
|
|
if (!gamedir_callbacks)
|
|
|
|
Sys_Error ("Too many gamedir callbacks!\n");
|
|
|
|
max_gamedir_callbacks += GAMEDIR_CALLBACK_CHUNK;
|
2004-02-03 03:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!func) {
|
|
|
|
Sys_Error ("null gamedir callback\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
gamedir_callbacks[num_gamedir_callbacks] = func;
|
|
|
|
num_gamedir_callbacks++;
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:26:31 +00:00
|
|
|
static void
|
|
|
|
qfs_path_cvar (cvar_t *var)
|
|
|
|
{
|
|
|
|
char *cpath = QFS_CompressPath (var->string);
|
|
|
|
if (strcmp (cpath, var->string))
|
|
|
|
Cvar_Set (var, cpath);
|
|
|
|
free (cpath);
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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;
|
|
|
|
|
2010-08-24 23:26:31 +00:00
|
|
|
fs_sharepath = Cvar_Get ("fs_sharepath", FS_SHAREPATH, CVAR_ROM,
|
|
|
|
qfs_path_cvar,
|
2010-01-13 06:42:26 +00:00
|
|
|
"location of shared (read-only) game "
|
2001-08-22 22:03:16 +00:00
|
|
|
"directories");
|
2010-08-24 23:26:31 +00:00
|
|
|
fs_userpath = Cvar_Get ("fs_userpath", FS_USERPATH, CVAR_ROM,
|
|
|
|
qfs_path_cvar,
|
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");
|
|
|
|
|
2010-08-25 00:57:44 +00:00
|
|
|
Cmd_AddCommand ("path", qfs_path_f, "Show what paths Quake is using");
|
2003-02-14 19:46:07 +00:00
|
|
|
|
2010-08-24 07:01:01 +00:00
|
|
|
qfs_userpath = Sys_ExpandSquiggle (fs_userpath->string);
|
2003-05-23 17:17:01 +00:00
|
|
|
|
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);
|
2007-03-22 23:20:57 +00:00
|
|
|
free ((void*)list);
|
2003-01-22 20:00:46 +00:00
|
|
|
} 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
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE 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;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_StripExtension (const char *in, char *out)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-12-28 05:25:06 +00:00
|
|
|
char *tmp;
|
|
|
|
|
2007-03-26 09:06:50 +00:00
|
|
|
if (out != in)
|
|
|
|
strcpy (out, in);
|
2003-12-28 05:25:06 +00:00
|
|
|
|
2011-09-09 08:35:12 +00:00
|
|
|
tmp = out + (QFS_FileExtension (out) - out);
|
|
|
|
*tmp = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE const char *
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_FileExtension (const char *in)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2011-09-09 08:33:29 +00:00
|
|
|
const char *tmp;
|
|
|
|
const char *end = in + strlen (in);
|
|
|
|
|
|
|
|
for (tmp = end; tmp != in; tmp--) {
|
|
|
|
if (tmp[-1] == '/')
|
|
|
|
return end;
|
|
|
|
if (tmp[-1] == '.') {
|
|
|
|
if (tmp - 1 == in || tmp[-2] == '/')
|
|
|
|
return end;
|
|
|
|
return tmp - 1;
|
|
|
|
}
|
|
|
|
}
|
2003-12-28 05:25:06 +00:00
|
|
|
|
2011-09-09 08:33:29 +00:00
|
|
|
return end;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2010-08-24 07:20:07 +00:00
|
|
|
QFS_DefaultExtension (dstring_t *path, const char *extension)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2011-09-09 08:37:45 +00:00
|
|
|
const char *ext;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
// if path doesn't have a .EXT, append extension
|
|
|
|
// (extension should include the .)
|
2011-09-09 08:37:45 +00:00
|
|
|
ext = QFS_FileExtension (path->str);
|
|
|
|
if (*ext)
|
|
|
|
return; // it has an extension
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-24 07:20:07 +00:00
|
|
|
dstring_appendstr (path, extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE void
|
|
|
|
QFS_SetExtension (struct dstring_s *path, const char *extension)
|
|
|
|
{
|
|
|
|
const char *ext = QFS_FileExtension (path->str);
|
2011-09-09 10:55:54 +00:00
|
|
|
int offs = ext - path->str;
|
2010-08-24 07:20:07 +00:00
|
|
|
|
2011-09-09 08:37:45 +00:00
|
|
|
if (*ext) {
|
|
|
|
// path has an extension... cut it off
|
|
|
|
path->str[offs] = 0;
|
|
|
|
path->size = offs + 1;
|
2010-08-24 07:20:07 +00:00
|
|
|
}
|
|
|
|
dstring_appendstr (path, extension);
|
2001-03-09 07:58:10 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2003-05-23 17:17:01 +00:00
|
|
|
QFS_NextFilename (dstring_t *filename, const char *prefix, const char *ext)
|
2001-03-09 07:58:10 +00:00
|
|
|
{
|
|
|
|
char *digits;
|
|
|
|
int i;
|
2010-08-24 23:26:31 +00:00
|
|
|
int ret = 0;
|
|
|
|
dstring_t *full_path = dstring_new ();
|
2001-03-09 07:58:10 +00:00
|
|
|
|
2003-05-23 17:17:01 +00:00
|
|
|
dsprintf (filename, "%s0000%s", prefix, ext);
|
|
|
|
digits = filename->str + strlen (prefix);
|
2003-06-06 12:35:52 +00:00
|
|
|
|
2003-05-23 17:17:01 +00:00
|
|
|
for (i = 0; i <= 9999; i++) {
|
|
|
|
digits[0] = i / 1000 + '0';
|
|
|
|
digits[1] = i / 100 % 10 + '0';
|
2003-06-06 12:35:52 +00:00
|
|
|
digits[2] = i / 10 % 10 + '0';
|
|
|
|
digits[3] = i % 10 + '0';
|
2010-08-24 23:26:31 +00:00
|
|
|
|
|
|
|
if (qfs_expand_userpath (full_path, filename->str) == -1)
|
|
|
|
break;
|
|
|
|
if (Sys_FileTime (full_path->str) == -1) {
|
|
|
|
// file doesn't exist, so we can use this name
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
2001-03-09 07:58:10 +00:00
|
|
|
}
|
2010-08-24 23:26:31 +00:00
|
|
|
dstring_delete (full_path);
|
|
|
|
return ret;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-02-14 22:36:10 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE QFile *
|
2003-05-23 17:17:01 +00:00
|
|
|
QFS_Open (const char *path, const char *mode)
|
2003-02-14 22:36:10 +00:00
|
|
|
{
|
|
|
|
dstring_t *full_path = dstring_new ();
|
2004-05-09 22:58:37 +00:00
|
|
|
QFile *file = 0;
|
2004-04-13 03:38:16 +00:00
|
|
|
const char *m;
|
|
|
|
int write = 0;
|
2003-02-14 22:36:10 +00:00
|
|
|
|
2010-08-24 23:26:31 +00:00
|
|
|
if (qfs_expand_userpath (full_path, path) == 0) {
|
2010-12-28 00:08:51 +00:00
|
|
|
Sys_MaskPrintf (SYS_FS, "QFS_Open: %s %s\n", full_path->str, mode);
|
2004-04-13 04:42:12 +00:00
|
|
|
for (m = mode; *m; m++)
|
|
|
|
if (*m == 'w' || *m == '+' || *m == 'a')
|
|
|
|
write = 1;
|
|
|
|
if (write)
|
2010-08-24 23:21:07 +00:00
|
|
|
if (Sys_CreatePath (full_path->str) == -1)
|
2004-05-09 22:58:37 +00:00
|
|
|
goto done;
|
2004-04-13 04:42:12 +00:00
|
|
|
file = Qopen (full_path->str, mode);
|
|
|
|
}
|
2004-05-09 22:58:37 +00:00
|
|
|
done:
|
2003-02-14 22:36:10 +00:00
|
|
|
dstring_delete (full_path);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE QFile *
|
2003-05-23 17:17:01 +00:00
|
|
|
QFS_WOpen (const char *path, int zip)
|
|
|
|
{
|
2003-08-05 01:45:52 +00:00
|
|
|
char mode[5] = "wb\000\000\000";
|
2003-05-23 17:17:01 +00:00
|
|
|
|
2003-07-08 20:11:10 +00:00
|
|
|
if (zip) {
|
|
|
|
mode[2] = 'z';
|
|
|
|
mode[3] = bound (1, zip, 9) + '0';
|
|
|
|
}
|
2003-05-23 17:17:01 +00:00
|
|
|
return QFS_Open (path, mode);
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2007-03-18 07:12:45 +00:00
|
|
|
QFS_Rename (const char *old_path, const char *new_path)
|
2003-02-14 22:36:10 +00:00
|
|
|
{
|
|
|
|
dstring_t *full_old = dstring_new ();
|
|
|
|
dstring_t *full_new = dstring_new ();
|
|
|
|
int ret;
|
|
|
|
|
2010-08-24 23:26:31 +00:00
|
|
|
if ((ret = qfs_expand_userpath (full_old, old_path)) != -1)
|
2010-12-28 01:28:46 +00:00
|
|
|
if ((ret = qfs_expand_userpath (full_new, new_path)) != -1)
|
|
|
|
if ((ret = Sys_CreatePath (full_new->str)) != -1) {
|
|
|
|
Sys_Printf ("QFS_Rename %s %s\n", full_old->str, full_new->str);
|
2010-08-24 23:26:31 +00:00
|
|
|
ret = Qrename (full_old->str, full_new->str);
|
2010-12-28 01:28:46 +00:00
|
|
|
}
|
2003-02-14 22:36:10 +00:00
|
|
|
dstring_delete (full_old);
|
|
|
|
dstring_delete (full_new);
|
|
|
|
return ret;
|
|
|
|
}
|
2003-05-23 17:17:01 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2003-05-23 17:17:01 +00:00
|
|
|
QFS_Remove (const char *path)
|
|
|
|
{
|
|
|
|
dstring_t *full_path = dstring_new ();
|
|
|
|
int ret;
|
|
|
|
|
2010-08-24 23:26:31 +00:00
|
|
|
if ((ret = qfs_expand_userpath (full_path, path)) != -1)
|
|
|
|
ret = Qremove (full_path->str);
|
2003-05-23 17:17:01 +00:00
|
|
|
dstring_delete (full_path);
|
|
|
|
return ret;
|
|
|
|
}
|
2004-04-20 22:25:52 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE filelist_t *
|
2004-04-20 22:25:52 +00:00
|
|
|
QFS_FilelistNew (void)
|
|
|
|
{
|
|
|
|
return calloc (1, sizeof (filelist_t));
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2004-04-23 22:53:39 +00:00
|
|
|
QFS_FilelistAdd (filelist_t *filelist, const char *fname, const char *ext)
|
2004-04-20 22:25:52 +00:00
|
|
|
{
|
|
|
|
char **new_list;
|
2004-04-23 22:53:39 +00:00
|
|
|
char *s, *str;
|
2004-04-20 22:25:52 +00:00
|
|
|
|
|
|
|
while ((s = strchr(fname, '/')))
|
2004-04-23 22:53:39 +00:00
|
|
|
fname = s + 1;
|
2004-04-20 22:25:52 +00:00
|
|
|
if (filelist->count == filelist->size) {
|
|
|
|
filelist->size += 32;
|
|
|
|
new_list = realloc (filelist->list, filelist->size * sizeof (char *));
|
|
|
|
|
|
|
|
if (!new_list) {
|
|
|
|
filelist->size -= 32;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
filelist->list = new_list;
|
|
|
|
}
|
2004-04-23 22:53:39 +00:00
|
|
|
str = strdup (fname);
|
2004-04-20 22:25:52 +00:00
|
|
|
|
2004-04-23 22:53:39 +00:00
|
|
|
if (ext && (s = strstr(str, va(".%s", ext))))
|
2004-04-20 22:25:52 +00:00
|
|
|
*s = 0;
|
2004-04-23 22:53:39 +00:00
|
|
|
filelist->list[filelist->count++] = str;
|
2004-04-20 22:25:52 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2004-04-20 22:52:09 +00:00
|
|
|
QFS_FilelistFill (filelist_t *list, const char *path, const char *ext,
|
|
|
|
int strip)
|
2004-04-20 22:25:52 +00:00
|
|
|
{
|
|
|
|
searchpath_t *search;
|
|
|
|
DIR *dir_ptr;
|
|
|
|
struct dirent *dirent;
|
2010-08-24 23:26:31 +00:00
|
|
|
char *cpath, *cp;
|
|
|
|
const char *separator = "/";
|
|
|
|
|
|
|
|
if (strchr (ext, '/') || strchr (ext, '\\'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
cp = cpath = QFS_CompressPath (path);
|
2010-12-27 01:31:54 +00:00
|
|
|
if (*cp && cp[strlen (cp) - 1] == '/')
|
2010-08-24 23:26:31 +00:00
|
|
|
separator = "";
|
2004-04-20 22:25:52 +00:00
|
|
|
|
|
|
|
for (search = qfs_searchpaths; search != NULL; search = search->next) {
|
|
|
|
if (search->pack) {
|
|
|
|
int i;
|
|
|
|
pack_t *pak = search->pack;
|
|
|
|
|
|
|
|
for (i = 0; i < pak->numfiles; i++) {
|
|
|
|
char *name = pak->files[i].name;
|
2010-12-27 01:31:54 +00:00
|
|
|
if (!fnmatch (va("%s%s*.%s", cp, separator, ext), name,
|
|
|
|
FNM_PATHNAME)
|
|
|
|
|| !fnmatch (va("%s%s*.%s.gz", cp, separator, ext), name,
|
|
|
|
FNM_PATHNAME))
|
2004-04-23 22:53:39 +00:00
|
|
|
QFS_FilelistAdd (list, name, strip ? ext : 0);
|
2004-04-20 22:25:52 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-08-24 23:26:31 +00:00
|
|
|
dir_ptr = opendir (va ("%s/%s", search->filename, cp));
|
2004-04-20 22:25:52 +00:00
|
|
|
if (!dir_ptr)
|
|
|
|
continue;
|
|
|
|
while ((dirent = readdir (dir_ptr)))
|
|
|
|
if (!fnmatch (va("*.%s", ext), dirent->d_name, 0)
|
|
|
|
|| !fnmatch (va("*.%s.gz", ext), dirent->d_name, 0))
|
2004-04-23 22:53:39 +00:00
|
|
|
QFS_FilelistAdd (list, dirent->d_name, strip ? ext : 0);
|
2004-04-20 22:25:52 +00:00
|
|
|
closedir (dir_ptr);
|
|
|
|
}
|
|
|
|
}
|
2010-08-24 23:26:31 +00:00
|
|
|
free (cpath);
|
2004-04-20 22:25:52 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2004-04-20 22:25:52 +00:00
|
|
|
QFS_FilelistFree (filelist_t *list)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < list->count; i++)
|
|
|
|
free (list->list[i]);
|
|
|
|
free (list->list);
|
|
|
|
free (list);
|
|
|
|
}
|