mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-23 04:52:07 +00:00
Build a raw search path at startup. Use it to build the actual paths.
A new linked list fs_rawPath with nodes of type fsRawPath_t is added. The new function FS_BuildRawPath() fills it at filesystem initialization with the raw search path directories. Later FS_BuildGenericSearchPath() and FS_BuildGameSpecificSearchPath() use it to derive the actual search directories.
This commit is contained in:
parent
e4b9f6884f
commit
3ba9729946
1 changed files with 90 additions and 72 deletions
|
@ -123,6 +123,21 @@ cvar_t *fs_debug;
|
||||||
|
|
||||||
fsHandle_t *FS_GetFileByHandle(fileHandle_t f);
|
fsHandle_t *FS_GetFileByHandle(fileHandle_t f);
|
||||||
|
|
||||||
|
// --------
|
||||||
|
|
||||||
|
// Raw search path, the actual search
|
||||||
|
// bath is build from this one.
|
||||||
|
typedef struct fsRawPath_s {
|
||||||
|
char path[MAX_OSPATH];
|
||||||
|
qboolean create;
|
||||||
|
qboolean screenshot;
|
||||||
|
struct fsRawPath_s *next;
|
||||||
|
} fsRawPath_t;
|
||||||
|
|
||||||
|
fsRawPath_t *fs_rawPath;
|
||||||
|
|
||||||
|
// --------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All of Quake's data access is through a hierchal file system, but the
|
* All of Quake's data access is through a hierchal file system, but the
|
||||||
* contents of the file system can be transparently merged from several
|
* contents of the file system can be transparently merged from several
|
||||||
|
@ -1374,47 +1389,22 @@ void FS_BuildGenericSearchPath(void) {
|
||||||
// a maximum path size of 4096...
|
// a maximum path size of 4096...
|
||||||
char path[MAX_OSPATH];
|
char path[MAX_OSPATH];
|
||||||
|
|
||||||
// The CD must be the last directory of the path,
|
fsRawPath_t *search = fs_rawPath;
|
||||||
// otherwise we cannot be sure that the game won't
|
|
||||||
// stream the videos from the CD.
|
|
||||||
if (fs_cddir->string[0] != '\0') {
|
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", fs_cddir->string, BASEDIRNAME);
|
|
||||||
FS_AddDirToSearchPath(path, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add $basedir/baseq2
|
while (search != NULL) {
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", fs_basedir->string, BASEDIRNAME);
|
Com_sprintf(path, sizeof(path), "%s/%s", search->path, BASEDIRNAME);
|
||||||
FS_AddDirToSearchPath(path, false);
|
FS_AddDirToSearchPath(path, search->create);
|
||||||
|
|
||||||
// Add SYSTEMDIR/baseq2
|
|
||||||
#ifdef SYSTEMWIDE
|
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", SYSTEMDIR, BASEDIRNAME);
|
|
||||||
FS_AddDirToSearchPath(path, false);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Add $binarydir/baseq2
|
|
||||||
const char *binarydir = Sys_GetBinaryDir();
|
|
||||||
|
|
||||||
if(!binarydir[0] == '\0')
|
|
||||||
{
|
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", binarydir, BASEDIRNAME);
|
|
||||||
FS_AddDirToSearchPath(path, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add $HOME/.yq2/baseq2
|
|
||||||
// (MUST be the last dir!)
|
|
||||||
const char *homedir = Sys_GetHomeDir();
|
|
||||||
|
|
||||||
if (homedir != NULL) {
|
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", homedir, BASEDIRNAME);
|
|
||||||
FS_AddDirToSearchPath(path, true);
|
|
||||||
|
|
||||||
// We need to create the screenshot directory since the
|
// We need to create the screenshot directory since the
|
||||||
// render dll doesn't link the filesystem stuff.
|
// render dll doesn't link the filesystem stuff.
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s/scrnshot", homedir, BASEDIRNAME);
|
if (search->screenshot) {
|
||||||
|
Com_sprintf(path, sizeof(path), "%s/%s/scrnshot", search->path, BASEDIRNAME);
|
||||||
Sys_Mkdir(path);
|
Sys_Mkdir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
search = search->next;
|
||||||
|
}
|
||||||
|
|
||||||
// Until here we've added the generic directories to the
|
// Until here we've added the generic directories to the
|
||||||
// search path. Save the current head node so we can
|
// search path. Save the current head node so we can
|
||||||
// distinguish generic and specialized directories.
|
// distinguish generic and specialized directories.
|
||||||
|
@ -1424,8 +1414,12 @@ void FS_BuildGenericSearchPath(void) {
|
||||||
void
|
void
|
||||||
FS_BuildGameSpecificSearchPath(char *dir)
|
FS_BuildGameSpecificSearchPath(char *dir)
|
||||||
{
|
{
|
||||||
|
// We may not use the va() function from shared.c
|
||||||
|
// since it's buffersize is 1024 while most OS have
|
||||||
|
// a maximum path size of 4096...
|
||||||
char path[MAX_OSPATH];
|
char path[MAX_OSPATH];
|
||||||
int i;
|
int i;
|
||||||
|
fsRawPath_t *search;
|
||||||
fsSearchPath_t *next;
|
fsSearchPath_t *next;
|
||||||
|
|
||||||
// This is against PEBCAK. The user may give us paths like
|
// This is against PEBCAK. The user may give us paths like
|
||||||
|
@ -1503,51 +1497,74 @@ FS_BuildGameSpecificSearchPath(char *dir)
|
||||||
// TODO: Set fs_gamedir
|
// TODO: Set fs_gamedir
|
||||||
} else {
|
} else {
|
||||||
Cvar_FullSet("gamedir", dir, CVAR_SERVERINFO | CVAR_NOSET);
|
Cvar_FullSet("gamedir", dir, CVAR_SERVERINFO | CVAR_NOSET);
|
||||||
|
search = fs_rawPath;
|
||||||
|
|
||||||
// The CD must be the last directory of the path,
|
while (search != NULL) {
|
||||||
// otherwise we cannot be sure that the game won't
|
Com_sprintf(path, sizeof(path), "%s/%s", search->path, dir);
|
||||||
// stream the videos from the CD.
|
FS_AddDirToSearchPath(path, search->create);
|
||||||
if (fs_cddir->string[0] == '\0')
|
|
||||||
{
|
// We need to create the screenshot directory since the
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", fs_cddir->string, dir);
|
// render dll doesn't link the filesystem stuff.
|
||||||
FS_AddDirToSearchPath(path, false);
|
if (search->screenshot) {
|
||||||
|
Com_sprintf(path, sizeof(path), "%s/%s/scrnshot", search->path, dir);
|
||||||
|
Sys_Mkdir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add $basedir/$game
|
search = search->next;
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", fs_basedir->string, dir);
|
}
|
||||||
FS_AddDirToSearchPath(path, false);
|
}
|
||||||
|
|
||||||
// Add SYSTEMDIR/$game
|
|
||||||
#ifdef SYSTEMWIDE
|
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", SYSTEMDIR, dir);
|
|
||||||
FS_AddDirToSearchPath(path, false);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Add $binarydir/$game
|
|
||||||
const char *binarydir = Sys_GetBinaryDir();
|
|
||||||
|
|
||||||
if(!binarydir[0] == '\0')
|
|
||||||
{
|
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", binarydir, dir);
|
|
||||||
FS_AddDirToSearchPath(path, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add $HOME/.yq2/$game
|
// --------
|
||||||
|
|
||||||
|
void FS_AddDirToRawPath (const char *dir, qboolean create, qboolean screenshot) {
|
||||||
|
fsRawPath_t *search;
|
||||||
|
|
||||||
|
// Add the directory
|
||||||
|
search = Z_Malloc(sizeof(fsRawPath_t));
|
||||||
|
Q_strlcpy(search->path, dir, sizeof(search->path));
|
||||||
|
search->create = create;
|
||||||
|
search->screenshot = screenshot;
|
||||||
|
search->next = fs_rawPath;
|
||||||
|
fs_rawPath = search;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FS_BuildRawPath(void) {
|
||||||
|
// Add $HOME/.yq2/baseq2
|
||||||
// (MUST be the last dir!)
|
// (MUST be the last dir!)
|
||||||
const char *homedir = Sys_GetHomeDir();
|
const char *homedir = Sys_GetHomeDir();
|
||||||
|
|
||||||
if (homedir != NULL) {
|
if (homedir != NULL) {
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s", homedir, dir);
|
FS_AddDirToRawPath(homedir, true, true);
|
||||||
FS_AddDirToSearchPath(path, true);
|
}
|
||||||
|
|
||||||
// We need to create the screenshot directory since the
|
// Add $binarydir/baseq2
|
||||||
// render dll doesn't link the filesystem stuff.
|
const char *binarydir = Sys_GetBinaryDir();
|
||||||
Com_sprintf(path, sizeof(path), "%s/%s/scrnshot", homedir, dir);
|
|
||||||
Sys_Mkdir(path);
|
if(!binarydir[0] == '\0')
|
||||||
}
|
{
|
||||||
|
FS_AddDirToRawPath(binarydir, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add $basedir/
|
||||||
|
FS_AddDirToRawPath(fs_basedir->string, false, false);
|
||||||
|
|
||||||
|
// Add SYSTEMDIR/baseq2
|
||||||
|
#ifdef SYSTEMWIDE
|
||||||
|
FS_AddDirToRawPath(SYSTEMDIR, false);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// The CD must be the last directory of the path,
|
||||||
|
// otherwise we cannot be sure that the game won't
|
||||||
|
// stream the videos from the CD.
|
||||||
|
if (fs_cddir->string[0] != '\0') {
|
||||||
|
FS_AddDirToRawPath(fs_cddir->string, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------
|
||||||
|
|
||||||
void
|
void
|
||||||
FS_InitFilesystem(void)
|
FS_InitFilesystem(void)
|
||||||
{
|
{
|
||||||
|
@ -1563,6 +1580,7 @@ FS_InitFilesystem(void)
|
||||||
fs_debug = Cvar_Get("fs_debug", "0", 0);
|
fs_debug = Cvar_Get("fs_debug", "0", 0);
|
||||||
|
|
||||||
// Build search path
|
// Build search path
|
||||||
|
FS_BuildRawPath();
|
||||||
FS_BuildGenericSearchPath();
|
FS_BuildGenericSearchPath();
|
||||||
|
|
||||||
if (fs_gamedirvar->string[0] != '\0')
|
if (fs_gamedirvar->string[0] != '\0')
|
||||||
|
|
Loading…
Reference in a new issue