Refactoring the search path magic, step 3: Remove now used code.

Remove all functions that are no longer used:

* FS_AddGameDirectory()
* FS_SetGameDir()
* FS_AddHomeAsGameDirectory()
* FS_AddBinaryDirAsGameDirectory()

While at it try remove as much global variables from filesystem.c as
possible. Also fix a small, longstandig bug: The download code should
treat .zip and .pk3 files as pak files and not as normal directories.
This commit is contained in:
Yamagi Burmeister 2017-07-22 18:15:03 +02:00
parent 0c8e65bb68
commit 9efd831312
3 changed files with 7 additions and 291 deletions

View file

@ -114,25 +114,14 @@ fsPackTypes_t fs_packtypes[] = {
};
char fs_gamedir[MAX_OSPATH];
qboolean file_from_pak;
static char fs_fileInPath[MAX_OSPATH];
static qboolean fs_fileInPack;
/* Set by FS_FOpenFile. */
int file_from_pak = 0;
#ifdef ZIP
int file_from_pk3 = 0;
char file_from_pk3_name[MAX_QPATH];
#endif
cvar_t *fs_homepath;
cvar_t *fs_basedir;
cvar_t *fs_cddir;
cvar_t *fs_gamedirvar;
cvar_t *fs_debug;
fsHandle_t *FS_GetFileByHandle(fileHandle_t f);
char *Sys_GetCurrentDirectory(void);
/*
* All of Quake's data access is through a hierchal file system, but the
@ -363,11 +352,7 @@ FS_FOpenFile(const char *name, fileHandle_t *f, qboolean gamedir_only)
fsSearchPath_t *search;
int i;
file_from_pak = 0;
#ifdef ZIP
file_from_pk3 = 0;
#endif
file_from_pak = false;
handle = FS_HandleForFile(name, f);
Q_strlcpy(handle->name, name, sizeof(handle->name));
handle->mode = FS_READ;
@ -393,9 +378,6 @@ FS_FOpenFile(const char *name, fileHandle_t *f, qboolean gamedir_only)
if (Q_stricmp(pack->files[i].name, handle->name) == 0)
{
/* Found it! */
Com_FilePath(pack->name, fs_fileInPath, sizeof(fs_fileInPath));
fs_fileInPack = true;
if (fs_debug->value)
{
Com_Printf("FS_FOpenFile: '%s' (found in '%s').\n",
@ -405,7 +387,7 @@ FS_FOpenFile(const char *name, fileHandle_t *f, qboolean gamedir_only)
if (pack->pak)
{
/* PAK */
file_from_pak = 1;
file_from_pak = true;
handle->file = fopen(pack->name, "rb");
if (handle->file)
@ -418,8 +400,7 @@ FS_FOpenFile(const char *name, fileHandle_t *f, qboolean gamedir_only)
else if (pack->pk3)
{
/* PK3 */
file_from_pk3 = 1;
Q_strlcpy(file_from_pk3_name, strrchr(pack->name, '/') + 1, sizeof(file_from_pk3_name));
file_from_pak = true;
handle->zip = unzOpen(pack->name);
if (handle->zip)
@ -461,10 +442,6 @@ FS_FOpenFile(const char *name, fileHandle_t *f, qboolean gamedir_only)
if (handle->file)
{
/* Found it! */
Q_strlcpy(fs_fileInPath, search->path, sizeof(fs_fileInPath));
fs_fileInPack = false;
if (fs_debug->value)
{
Com_Printf("FS_FOpenFile: '%s' (found in '%s').\n",
@ -475,11 +452,6 @@ FS_FOpenFile(const char *name, fileHandle_t *f, qboolean gamedir_only)
}
}
}
/* Not found! */
fs_fileInPath[0] = 0;
fs_fileInPack = false;
if (fs_debug->value)
{
Com_Printf("FS_FOpenFile: couldn't find '%s'.\n", handle->name);
@ -821,171 +793,6 @@ FS_LoadPK3(const char *packPath)
}
#endif
/*
* Adds the directory to the head of the path, then loads and adds pak1.pak
* pak2.pak ...
*
* Extended all functionality to include Quake III .pk3
*/
void
FS_AddGameDirectory(const char *dir)
{
char **list; /* File list. */
char path[MAX_OSPATH]; /* Path to PAK / PK3. */
int i, j; /* Loop counters. */
int nfiles; /* Number of files in list. */
fsSearchPath_t *search; /* Search path. */
fsPack_t *pack; /* PAK / PK3 file. */
pack = NULL;
/* Set game directory. */
Q_strlcpy(fs_gamedir, dir, sizeof(fs_gamedir));
/* Create directory if it does not exist. */
FS_CreatePath(fs_gamedir);
/* Add the directory to the search path. */
search = Z_Malloc(sizeof(fsSearchPath_t));
Q_strlcpy(search->path, dir, sizeof(search->path));
search->next = fs_searchPaths;
fs_searchPaths = search;
/* Add numbered pack files in sequence. */
for (i = 0; i < sizeof(fs_packtypes) / sizeof(fs_packtypes[0]); i++)
{
for (j = 0; j < MAX_PAKS; j++)
{
Com_sprintf(path, sizeof(path), "%s/pak%d.%s",
dir, j, fs_packtypes[i].suffix);
switch (fs_packtypes[i].format)
{
case PAK:
pack = FS_LoadPAK(path);
break;
#ifdef ZIP
case PK3:
pack = FS_LoadPK3(path);
break;
#endif
}
if (pack == NULL)
{
continue;
}
search = Z_Malloc(sizeof(fsSearchPath_t));
search->pack = pack;
search->next = fs_searchPaths;
fs_searchPaths = search;
}
}
/* Add not numbered pack files. */
for (i = 0; i < sizeof(fs_packtypes) / sizeof(fs_packtypes[0]); i++)
{
Com_sprintf(path, sizeof(path), "%s/*.%s", dir, fs_packtypes[i].suffix);
if ((list = FS_ListFiles(path, &nfiles, 0, SFF_SUBDIR)) == NULL)
{
continue;
}
Com_sprintf(path, sizeof(path), "%s/pak*.%s",
dir, fs_packtypes[i].suffix);
for (j = 0; j < nfiles - 1; j++)
{
/* Skip all packs starting with "pak" */
if (glob_match(path, list[j]))
{
continue;
}
switch (fs_packtypes[i].format)
{
case PAK:
pack = FS_LoadPAK(list[j]);
break;
#ifdef ZIP
case PK3:
pack = FS_LoadPK3(list[j]);
break;
#endif
}
if (pack == NULL)
{
continue;
}
search = Z_Malloc(sizeof(fsSearchPath_t));
search->pack = pack;
search->next = fs_searchPaths;
fs_searchPaths = search;
}
FS_FreeList(list, nfiles);
}
}
/*
* Use ~/.quake2/dir as fs_gamedir.
*/
void
FS_AddHomeAsGameDirectory(char *dir)
{
char *home;
char gdir[MAX_OSPATH];
size_t len;
if (portable->value)
{
return;
}
home = Sys_GetHomeDir();
if (home == NULL)
{
return;
}
len = snprintf(gdir, sizeof(gdir), "%s%s/", home, dir);
FS_CreatePath(gdir);
if ((len > 0) && (len < sizeof(gdir)) && (gdir[len - 1] == '/'))
{
gdir[len - 1] = 0;
}
Q_strlcpy(fs_gamedir, gdir, sizeof(fs_gamedir));
FS_AddGameDirectory(gdir);
}
void FS_AddBinaryDirAsGameDirectory(const char* dir)
{
char gdir[MAX_OSPATH];
const char *datadir = Sys_GetBinaryDir();
if(datadir[0] == '\0')
{
return;
}
int len = snprintf(gdir, sizeof(gdir), "%s%s/", datadir, dir);
printf("Using binary dir %s to fetch paks\n", gdir);
if ((len > 0) && (len < sizeof(gdir)) && (gdir[len - 1] == '/'))
{
gdir[len - 1] = 0;
}
FS_AddGameDirectory(gdir);
}
/*
* Allows enumerating all of the directories in the search path.
*/
@ -1072,97 +879,6 @@ FS_Path_f(void)
#endif
}
/*
* Sets the gamedir and path to a different directory.
*/
void
FS_SetGamedir(char *dir)
{
int i;
fsSearchPath_t *next;
if (!*dir || !strcmp(dir, ".") || strstr(dir, "..") || strstr(dir, "/"))
{
Com_Printf("Gamedir should be a single filename, not a path.\n");
return;
}
/* Do not set BASEDIR as gamedir. It was already set by FS_InitFilesystem()
* and setting it again f*cks the search pathes up. Yes, this a hack. */
if(!Q_stricmp(dir, BASEDIRNAME))
{
return;
}
/* Free up any current game dir info. */
while (fs_searchPaths != fs_baseSearchPaths)
{
if (fs_searchPaths->pack)
{
if (fs_searchPaths->pack->pak)
{
fclose(fs_searchPaths->pack->pak);
}
#ifdef ZIP
if (fs_searchPaths->pack->pk3)
{
unzClose(fs_searchPaths->pack->pk3);
}
#endif
Z_Free(fs_searchPaths->pack->files);
Z_Free(fs_searchPaths->pack);
}
next = fs_searchPaths->next;
Z_Free(fs_searchPaths);
fs_searchPaths = next;
}
/* Close open files for game dir. */
for (i = 0; i < MAX_HANDLES; i++)
{
if (strstr(fs_handles[i].name, dir) &&
((fs_handles[i].file != NULL)
#ifdef ZIP
|| (fs_handles[i].zip != NULL)
#endif
))
{
FS_FCloseFile(i);
}
}
/* Flush all data, so it will be forced to reload. */
if ((dedicated != NULL) && (dedicated->value != 1))
{
Cbuf_AddText("vid_restart\nsnd_restart\n");
}
Com_sprintf(fs_gamedir, sizeof(fs_gamedir), "%s/%s",
fs_basedir->string, dir);
if ((strcmp(dir, BASEDIRNAME) == 0) || (*dir == 0))
{
Cvar_FullSet("gamedir", "", CVAR_SERVERINFO | CVAR_NOSET);
Cvar_FullSet("game", "", CVAR_LATCH | CVAR_SERVERINFO);
}
else
{
Cvar_FullSet("gamedir", dir, CVAR_SERVERINFO | CVAR_NOSET);
if (fs_cddir->string[0] == '\0')
{
FS_AddGameDirectory(va("%s/%s", fs_cddir->string, dir));
}
FS_AddGameDirectory(va("%s/%s", fs_basedir->string, dir));
FS_AddBinaryDirAsGameDirectory(dir);
FS_AddHomeAsGameDirectory(dir);
}
}
/*
* Creates a filelink_t.
*/

View file

@ -643,7 +643,7 @@ void Pmove(pmove_t *pmove);
#define SFF_INPACK 0x20
extern int file_from_pak;
extern qboolean file_from_pak;
typedef int fileHandle_t;

View file

@ -296,7 +296,7 @@ SV_BeginDownload_f(void)
extern cvar_t *allow_download_models;
extern cvar_t *allow_download_sounds;
extern cvar_t *allow_download_maps;
extern int file_from_pak;
extern qboolean file_from_pak;
int offset = 0;
name = Cmd_Argv(1);