2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-22 01:45:19 +01:00

filesystem: dir: move searchpath initialization to dir.c, make all DIR functions static

This commit is contained in:
Alibek Omarov 2022-12-15 00:52:09 +03:00
parent f20fddee1c
commit 48c17d08d9
3 changed files with 63 additions and 45 deletions

View File

@ -27,14 +27,17 @@ GNU General Public License for more details.
#include "xash3d_mathlib.h"
#include "common/com_strings.h"
void FS_Close_DIR( searchpath_t *search ) {}
static void FS_Close_DIR( searchpath_t *search )
{
void FS_PrintInfo_DIR( searchpath_t *search, char *dst, size_t size )
}
static void FS_PrintInfo_DIR( searchpath_t *search, char *dst, size_t size )
{
Q_strncpy( dst, search->filename, size );
}
int FS_FindFile_DIR( searchpath_t *search, const char *path )
static int FS_FindFile_DIR( searchpath_t *search, const char *path )
{
char netpath[MAX_SYSPATH];
@ -46,7 +49,7 @@ int FS_FindFile_DIR( searchpath_t *search, const char *path )
return -1;
}
void FS_Search_DIR( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive )
static void FS_Search_DIR( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive )
{
string netpath, temp;
stringlist_t dirlist;
@ -95,7 +98,7 @@ void FS_Search_DIR( searchpath_t *search, stringlist_t *list, const char *patter
Mem_Free( basepath );
}
int FS_FileTime_DIR( searchpath_t *search, const char *filename )
static int FS_FileTime_DIR( searchpath_t *search, const char *filename )
{
char path[MAX_SYSPATH];
@ -103,10 +106,53 @@ int FS_FileTime_DIR( searchpath_t *search, const char *filename )
return FS_SysFileTime( path );
}
file_t *FS_OpenFile_DIR( searchpath_t *search, const char *filename, const char *mode, int pack_ind )
static file_t *FS_OpenFile_DIR( searchpath_t *search, const char *filename, const char *mode, int pack_ind )
{
char path[MAX_SYSPATH];
Q_snprintf( path, sizeof( path ), "%s%s", search->filename, filename );
return FS_SysOpen( path, mode );
}
}
void FS_InitDirectorySearchpath( searchpath_t *search, const char *path, int flags )
{
memset( search, 0, sizeof( searchpath_t ));
Q_strncpy( search->filename, path, sizeof( search->filename ));
search->type = SEARCHPATH_PLAIN;
search->flags = flags;
search->printinfo = FS_PrintInfo_DIR;
search->close = FS_Close_DIR;
search->openfile = FS_OpenFile_DIR;
search->filetime = FS_FileTime_DIR;
search->findfile = FS_FindFile_DIR;
search->search = FS_Search_DIR;
}
qboolean FS_AddDir_Fullpath( const char *path, qboolean *already_loaded, int flags )
{
searchpath_t *search;
for( search = fs_searchpaths; search; search = search->next )
{
if( search->type == SEARCHPATH_PLAIN && !Q_stricmp( search->filename, path ))
{
if( already_loaded )
*already_loaded = true;
return true;
}
}
if( already_loaded )
*already_loaded = false;
search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ));
FS_InitDirectorySearchpath( search, path, flags );
search->next = fs_searchpaths;
fs_searchpaths = search;
Con_Printf( "Adding directory: %s\n", path );
return true;
}

View File

@ -464,20 +464,7 @@ void FS_AddGameDirectory( const char *dir, uint flags )
// add the directory to the search path
// (unpacked files have the priority over packed files)
search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ));
Q_strncpy( search->filename, dir, sizeof ( search->filename ));
search->next = fs_searchpaths;
search->type = SEARCHPATH_PLAIN;
search->flags = flags;
search->printinfo = FS_PrintInfo_DIR;
search->close = FS_Close_DIR;
search->openfile = FS_OpenFile_DIR;
search->filetime = FS_FileTime_DIR;
search->findfile = FS_FindFile_DIR;
search->search = FS_Search_DIR;
fs_searchpaths = search;
FS_AddDir_Fullpath( dir, NULL, flags );
}
/*
@ -1155,7 +1142,7 @@ void FS_AddGameHierarchy( const char *dir, uint flags )
{
if( !Q_strnicmp( FI.games[i]->gamefolder, dir, 64 ))
{
Con_Reportf( "FS_AddGameHierarchy: %d %s %s\n", i, FI.games[i]->gamefolder, FI.games[i]->basedir );
Con_Reportf( "FS_AddGameHierarchy: adding recursive basedir %s\n", FI.games[i]->basedir );
if( !FI.games[i]->added && Q_stricmp( FI.games[i]->gamefolder, FI.games[i]->basedir ))
{
FI.games[i]->added = true;
@ -1212,6 +1199,7 @@ void FS_Rescan( void )
FS_AddArchive_Fullpath( str, NULL, extrasFlags );
#endif
if( Q_stricmp( GI->basedir, GI->gamefolder ))
FS_AddGameHierarchy( GI->basedir, 0 );
if( Q_stricmp( GI->basedir, GI->falldir ) && Q_stricmp( GI->gamefolder, GI->falldir ))
@ -1821,29 +1809,17 @@ searchpath_t *FS_FindFile( const char *name, int *index, qboolean gamedironly )
if( fs_ext_path )
{
char netpath[MAX_SYSPATH];
// clear searchpath
search = &fs_directpath;
memset( search, 0, sizeof( searchpath_t ));
// root folder has a more priority than netpath
Q_strncpy( search->filename, fs_rootdir, sizeof( search->filename ));
Q_strcat( search->filename, PATH_SPLITTER );
Q_snprintf( netpath, sizeof( netpath ), "%s%s", search->filename, name );
char netpath[MAX_SYSPATH], dirpath[MAX_SYSPATH];
Q_snprintf( dirpath, sizeof( dirpath ), "%s" PATH_SPLITTER, fs_rootdir );
Q_snprintf( netpath, sizeof( netpath ), "%s%s", dirpath, name );
if( FS_SysFileExists( netpath, true ))
{
search->printinfo = FS_PrintInfo_DIR;
search->close = FS_Close_DIR;
search->openfile = FS_OpenFile_DIR;
search->filetime = FS_FileTime_DIR;
search->findfile = FS_FindFile_DIR;
search->search = FS_Search_DIR;
FS_InitDirectorySearchpath( &fs_directpath, dirpath, 0 );
if( index != NULL )
*index = -1;
return search;
return &fs_directpath;
}
}

View File

@ -223,12 +223,8 @@ qboolean FS_AddZip_Fullpath( const char *zipfile, qboolean *already_loaded, int
//
// dir.c
//
void FS_PrintInfo_DIR( searchpath_t *search, char *dst, size_t size );
void FS_Close_DIR( searchpath_t *search );
file_t *FS_OpenFile_DIR( searchpath_t *search, const char *filename, const char *mode, int pack_ind );
int FS_FileTime_DIR( searchpath_t *search, const char *filename );
int FS_FindFile_DIR( searchpath_t *search, const char *path );
void FS_Search_DIR( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive );
qboolean FS_AddDir_Fullpath( const char *path, qboolean *already_loaded, int flags );
void FS_InitDirectorySearchpath( searchpath_t *search, const char *path, int flags );
#ifdef __cplusplus
}