Browse Source

filesystem: make all archive searchpath functions private

pull/2/head
Alibek Omarov 2 years ago
parent
commit
08f834cd82
  1. 17
      filesystem/filesystem_internal.h
  2. 193
      filesystem/pak.c
  3. 341
      filesystem/wad.c
  4. 173
      filesystem/zip.c

17
filesystem/filesystem_internal.h

@ -182,22 +182,11 @@ searchpath_t *FS_FindFile( const char *name, int *index, qboolean gamedironly );
// //
// pak.c // pak.c
// //
int FS_FileTime_PAK( searchpath_t *search, const char *filename );
int FS_FindFile_PAK( searchpath_t *search, const char *path );
void FS_PrintInfo_PAK( searchpath_t *search, char *dst, size_t size );
void FS_Close_PAK( searchpath_t *search );
void FS_Search_PAK( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive );
file_t *FS_OpenFile_PAK( searchpath_t *search, const char *filename, const char *mode, int pack_ind );
qboolean FS_AddPak_Fullpath( const char *pakfile, qboolean *already_loaded, int flags ); qboolean FS_AddPak_Fullpath( const char *pakfile, qboolean *already_loaded, int flags );
// //
// wad.c // wad.c
// //
int FS_FileTime_WAD( searchpath_t *search, const char *filename );
int FS_FindFile_WAD( searchpath_t *search, const char *path );
void FS_PrintInfo_WAD( searchpath_t *search, char *dst, size_t size );
void FS_Close_WAD( searchpath_t *search );
void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive );
byte *FS_LoadWADFile( const char *path, fs_offset_t *sizeptr, qboolean gamedironly ); byte *FS_LoadWADFile( const char *path, fs_offset_t *sizeptr, qboolean gamedironly );
qboolean FS_AddWad_Fullpath( const char *wadfile, qboolean *already_loaded, int flags ); qboolean FS_AddWad_Fullpath( const char *wadfile, qboolean *already_loaded, int flags );
@ -211,13 +200,7 @@ void FS_WatchFrame( void );
// //
// zip.c // zip.c
// //
int FS_FileTime_ZIP( searchpath_t *search, const char *filename );
int FS_FindFile_ZIP( searchpath_t *search, const char *path );
void FS_PrintInfo_ZIP( searchpath_t *search, char *dst, size_t size );
void FS_Close_ZIP( searchpath_t *search );
void FS_Search_ZIP( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive );
byte *FS_LoadZIPFile( const char *path, fs_offset_t *sizeptr, qboolean gamedironly ); byte *FS_LoadZIPFile( const char *path, fs_offset_t *sizeptr, qboolean gamedironly );
file_t *FS_OpenFile_ZIP( searchpath_t *search, const char *filename, const char *mode, int pack_ind );
qboolean FS_AddZip_Fullpath( const char *zipfile, qboolean *already_loaded, int flags ); qboolean FS_AddZip_Fullpath( const char *zipfile, qboolean *already_loaded, int flags );
// //

193
filesystem/pak.c

@ -230,7 +230,7 @@ FS_OpenPackedFile
Open a packed file using its package file descriptor Open a packed file using its package file descriptor
=========== ===========
*/ */
file_t *FS_OpenFile_PAK( searchpath_t *search, const char *filename, const char *mode, int pack_ind ) static file_t *FS_OpenFile_PAK( searchpath_t *search, const char *filename, const char *mode, int pack_ind )
{ {
dpackfile_t *pfile; dpackfile_t *pfile;
@ -240,83 +240,12 @@ file_t *FS_OpenFile_PAK( searchpath_t *search, const char *filename, const char
} }
/* /*
================ ===========
FS_AddPak_Fullpath FS_FindFile_PAK
Adds the given pack to the search path.
The pack type is autodetected by the file extension.
Returns true if the file was successfully added to the
search path or if it was already included.
If keep_plain_dirs is set, the pack will be added AFTER the first sequence of ===========
plain directories.
================
*/ */
qboolean FS_AddPak_Fullpath( const char *pakfile, qboolean *already_loaded, int flags ) static int FS_FindFile_PAK( searchpath_t *search, const char *path )
{
searchpath_t *search;
pack_t *pak = NULL;
const char *ext = COM_FileExtension( pakfile );
int i, errorcode = PAK_LOAD_COULDNT_OPEN;
for( search = fs_searchpaths; search; search = search->next )
{
if( search->type == SEARCHPATH_PAK && !Q_stricmp( search->pack->filename, pakfile ))
{
if( already_loaded ) *already_loaded = true;
return true; // already loaded
}
}
if( already_loaded )
*already_loaded = false;
if( !Q_stricmp( ext, "pak" ))
pak = FS_LoadPackPAK( pakfile, &errorcode );
if( pak )
{
string fullpath;
search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ));
search->pack = pak;
search->type = SEARCHPATH_PAK;
search->next = fs_searchpaths;
search->flags |= flags;
search->printinfo = FS_PrintInfo_PAK;
search->close = FS_Close_PAK;
search->openfile = FS_OpenFile_PAK;
search->filetime = FS_FileTime_PAK;
search->findfile = FS_FindFile_PAK;
search->search = FS_Search_PAK;
fs_searchpaths = search;
Con_Reportf( "Adding pakfile: %s (%i files)\n", pakfile, pak->numfiles );
// time to add in search list all the wads that contains in current pakfile (if do)
for( i = 0; i < pak->numfiles; i++ )
{
if( !Q_stricmp( COM_FileExtension( pak->files[i].name ), "wad" ))
{
Q_snprintf( fullpath, MAX_STRING, "%s/%s", pakfile, pak->files[i].name );
FS_AddWad_Fullpath( fullpath, NULL, flags );
}
}
return true;
}
else
{
if( errorcode != PAK_LOAD_NO_FILES )
Con_Reportf( S_ERROR "FS_AddPak_Fullpath: unable to load pak \"%s\"\n", pakfile );
return false;
}
}
int FS_FindFile_PAK( searchpath_t *search, const char *path )
{ {
int left, right, middle; int left, right, middle;
@ -345,7 +274,13 @@ int FS_FindFile_PAK( searchpath_t *search, const char *path )
return -1; return -1;
} }
void FS_Search_PAK( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive ) /*
===========
FS_Search_PAK
===========
*/
static void FS_Search_PAK( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive )
{ {
string temp; string temp;
const char *slash, *backslash, *colon, *separator; const char *slash, *backslash, *colon, *separator;
@ -385,21 +320,117 @@ void FS_Search_PAK( searchpath_t *search, stringlist_t *list, const char *patter
} }
} }
int FS_FileTime_PAK( searchpath_t *search, const char *filename ) /*
===========
FS_FileTime_PAK
===========
*/
static int FS_FileTime_PAK( searchpath_t *search, const char *filename )
{ {
return search->pack->filetime; return search->pack->filetime;
} }
void FS_PrintInfo_PAK( searchpath_t *search, char *dst, size_t size ) /*
===========
FS_PrintInfo_PAK
===========
*/
static void FS_PrintInfo_PAK( searchpath_t *search, char *dst, size_t size )
{ {
Q_snprintf( dst, size, "%s (%i files)", search->pack->filename, search->pack->numfiles ); Q_snprintf( dst, size, "%s (%i files)", search->pack->filename, search->pack->numfiles );
} }
void FS_Close_PAK( searchpath_t *search ) /*
===========
FS_Close_PAK
===========
*/
static void FS_Close_PAK( searchpath_t *search )
{ {
if( search->pack->files ) if( search->pack->files )
Mem_Free( search->pack->files ); Mem_Free( search->pack->files );
if( search->pack->handle >= 0 ) if( search->pack->handle >= 0 )
close( search->pack->handle ); close( search->pack->handle );
Mem_Free( search->pack ); Mem_Free( search->pack );
} }
/*
================
FS_AddPak_Fullpath
Adds the given pack to the search path.
The pack type is autodetected by the file extension.
Returns true if the file was successfully added to the
search path or if it was already included.
If keep_plain_dirs is set, the pack will be added AFTER the first sequence of
plain directories.
================
*/
qboolean FS_AddPak_Fullpath( const char *pakfile, qboolean *already_loaded, int flags )
{
searchpath_t *search;
pack_t *pak = NULL;
const char *ext = COM_FileExtension( pakfile );
int i, errorcode = PAK_LOAD_COULDNT_OPEN;
for( search = fs_searchpaths; search; search = search->next )
{
if( search->type == SEARCHPATH_PAK && !Q_stricmp( search->pack->filename, pakfile ))
{
if( already_loaded ) *already_loaded = true;
return true; // already loaded
}
}
if( already_loaded )
*already_loaded = false;
if( !Q_stricmp( ext, "pak" ))
pak = FS_LoadPackPAK( pakfile, &errorcode );
if( pak )
{
string fullpath;
search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ));
search->pack = pak;
search->type = SEARCHPATH_PAK;
search->next = fs_searchpaths;
search->flags |= flags;
search->printinfo = FS_PrintInfo_PAK;
search->close = FS_Close_PAK;
search->openfile = FS_OpenFile_PAK;
search->filetime = FS_FileTime_PAK;
search->findfile = FS_FindFile_PAK;
search->search = FS_Search_PAK;
fs_searchpaths = search;
Con_Reportf( "Adding pakfile: %s (%i files)\n", pakfile, pak->numfiles );
// time to add in search list all the wads that contains in current pakfile (if do)
for( i = 0; i < pak->numfiles; i++ )
{
if( !Q_stricmp( COM_FileExtension( pak->files[i].name ), "wad" ))
{
Q_snprintf( fullpath, MAX_STRING, "%s/%s", pakfile, pak->files[i].name );
FS_AddWad_Fullpath( fullpath, NULL, flags );
}
}
return true;
}
else
{
if( errorcode != PAK_LOAD_NO_FILES )
Con_Reportf( S_ERROR "FS_AddPak_Fullpath: unable to load pak \"%s\"\n", pakfile );
return false;
}
}

341
filesystem/wad.c

@ -154,6 +154,48 @@ static const char *W_ExtFromType( signed char lumptype )
return ""; return "";
} }
/*
===========
W_FindLump
Serach for already existed lump
===========
*/
static dlumpinfo_t *W_FindLump( wfile_t *wad, const char *name, const signed char matchtype )
{
int left, right;
if( !wad || !wad->lumps || matchtype == TYP_NONE )
return NULL;
// look for the file (binary search)
left = 0;
right = wad->numlumps - 1;
while( left <= right )
{
int middle = (left + right) / 2;
int diff = Q_stricmp( wad->lumps[middle].name, name );
if( !diff )
{
if(( matchtype == TYP_ANY ) || ( matchtype == wad->lumps[middle].type ))
return &wad->lumps[middle]; // found
else if( wad->lumps[middle].type < matchtype )
diff = 1;
else if( wad->lumps[middle].type > matchtype )
diff = -1;
else break; // not found
}
// if we're too far in the list
if( diff > 0 ) right = middle - 1;
else left = middle + 1;
}
return NULL;
}
/* /*
==================== ====================
W_AddFileToWad W_AddFileToWad
@ -362,184 +404,35 @@ static wfile_t *W_Open( const char *filename, int *error )
return wad; return wad;
} }
/*
====================
FS_AddWad_Fullpath
====================
*/
qboolean FS_AddWad_Fullpath( const char *wadfile, qboolean *already_loaded, int flags )
{
searchpath_t *search;
wfile_t *wad = NULL;
const char *ext = COM_FileExtension( wadfile );
int errorcode = WAD_LOAD_COULDNT_OPEN;
for( search = fs_searchpaths; search; search = search->next )
{
if( search->type == SEARCHPATH_WAD && !Q_stricmp( search->wad->filename, wadfile ))
{
if( already_loaded ) *already_loaded = true;
return true; // already loaded
}
}
if( already_loaded )
*already_loaded = false;
if( !Q_stricmp( ext, "wad" ))
wad = W_Open( wadfile, &errorcode );
if( wad )
{
search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ));
search->wad = wad;
search->type = SEARCHPATH_WAD;
search->next = fs_searchpaths;
search->flags |= flags;
search->printinfo = FS_PrintInfo_WAD;
search->close = FS_Close_WAD;
search->openfile = FS_OpenFile_WAD;
search->filetime = FS_FileTime_WAD;
search->findfile = FS_FindFile_WAD;
search->search = FS_Search_WAD;
fs_searchpaths = search;
Con_Reportf( "Adding wadfile: %s (%i files)\n", wadfile, wad->numlumps );
return true;
}
else
{
if( errorcode != WAD_LOAD_NO_FILES )
Con_Reportf( S_ERROR "FS_AddWad_Fullpath: unable to load wad \"%s\"\n", wadfile );
return false;
}
}
/*
=============================================================================
WADSYSTEM PRIVATE ROUTINES
=============================================================================
*/
/* /*
=========== ===========
W_FindLump FS_FileTime_WAD
Serach for already existed lump
=========== ===========
*/ */
static dlumpinfo_t *W_FindLump( wfile_t *wad, const char *name, const signed char matchtype ) static int FS_FileTime_WAD( searchpath_t *search, const char *filename )
{ {
int left, right; return search->wad->filetime;
if( !wad || !wad->lumps || matchtype == TYP_NONE )
return NULL;
// look for the file (binary search)
left = 0;
right = wad->numlumps - 1;
while( left <= right )
{
int middle = (left + right) / 2;
int diff = Q_stricmp( wad->lumps[middle].name, name );
if( !diff )
{
if(( matchtype == TYP_ANY ) || ( matchtype == wad->lumps[middle].type ))
return &wad->lumps[middle]; // found
else if( wad->lumps[middle].type < matchtype )
diff = 1;
else if( wad->lumps[middle].type > matchtype )
diff = -1;
else break; // not found
}
// if we're too far in the list
if( diff > 0 ) right = middle - 1;
else left = middle + 1;
}
return NULL;
} }
/* /*
=========== ===========
W_ReadLump FS_PrintInfo_WAD
reading lump into temp buffer
=========== ===========
*/ */
static byte *W_ReadLump( wfile_t *wad, dlumpinfo_t *lump, fs_offset_t *lumpsizeptr ) static void FS_PrintInfo_WAD( searchpath_t *search, char *dst, size_t size )
{ {
size_t oldpos, size = 0; Q_snprintf( dst, size, "%s (%i files)", search->wad->filename, search->wad->numlumps );
byte *buf;
// assume error
if( lumpsizeptr ) *lumpsizeptr = 0;
// no wads loaded
if( !wad || !lump ) return NULL;
oldpos = FS_Tell( wad->handle ); // don't forget restore original position
if( FS_Seek( wad->handle, lump->filepos, SEEK_SET ) == -1 )
{
Con_Reportf( S_ERROR "W_ReadLump: %s is corrupted\n", lump->name );
FS_Seek( wad->handle, oldpos, SEEK_SET );
return NULL;
}
buf = (byte *)Mem_Malloc( wad->mempool, lump->disksize );
size = FS_Read( wad->handle, buf, lump->disksize );
if( size < lump->disksize )
{
Con_Reportf( S_WARN "W_ReadLump: %s is probably corrupted\n", lump->name );
FS_Seek( wad->handle, oldpos, SEEK_SET );
Mem_Free( buf );
return NULL;
}
if( lumpsizeptr ) *lumpsizeptr = lump->disksize;
FS_Seek( wad->handle, oldpos, SEEK_SET );
return buf;
} }
/* /*
=========== ===========
FS_LoadWADFile FS_FindFile_WAD
loading lump into the tmp buffer
=========== ===========
*/ */
byte *FS_LoadWADFile( const char *path, fs_offset_t *lumpsizeptr, qboolean gamedironly ) static int FS_FindFile_WAD( searchpath_t *search, const char *path )
{
searchpath_t *search;
int index;
search = FS_FindFile( path, &index, gamedironly );
if( search && search->type == SEARCHPATH_WAD )
return W_ReadLump( search->wad, &search->wad->lumps[index], lumpsizeptr );
return NULL;
}
int FS_FileTime_WAD( searchpath_t *search, const char *filename )
{
return search->wad->filetime;
}
void FS_PrintInfo_WAD( searchpath_t *search, char *dst, size_t size )
{
Q_snprintf( dst, size, "%s (%i files)", search->wad->filename, search->wad->numlumps );
}
int FS_FindFile_WAD( searchpath_t *search, const char *path )
{ {
dlumpinfo_t *lump; dlumpinfo_t *lump;
signed char type = W_TypeFromExt( path ); signed char type = W_TypeFromExt( path );
@ -582,10 +475,15 @@ int FS_FindFile_WAD( searchpath_t *search, const char *path )
} }
return -1; return -1;
} }
void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive ) /*
===========
FS_Search_WAD
===========
*/
static void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive )
{ {
string wadpattern, wadname, temp2; string wadpattern, wadname, temp2;
signed char type = W_TypeFromExt( pattern ); signed char type = W_TypeFromExt( pattern );
@ -662,3 +560,128 @@ void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char *patter
} }
} }
} }
/*
====================
FS_AddWad_Fullpath
====================
*/
qboolean FS_AddWad_Fullpath( const char *wadfile, qboolean *already_loaded, int flags )
{
searchpath_t *search;
wfile_t *wad = NULL;
const char *ext = COM_FileExtension( wadfile );
int errorcode = WAD_LOAD_COULDNT_OPEN;
for( search = fs_searchpaths; search; search = search->next )
{
if( search->type == SEARCHPATH_WAD && !Q_stricmp( search->wad->filename, wadfile ))
{
if( already_loaded ) *already_loaded = true;
return true; // already loaded
}
}
if( already_loaded )
*already_loaded = false;
if( !Q_stricmp( ext, "wad" ))
wad = W_Open( wadfile, &errorcode );
if( wad )
{
search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ));
search->wad = wad;
search->type = SEARCHPATH_WAD;
search->next = fs_searchpaths;
search->flags |= flags;
search->printinfo = FS_PrintInfo_WAD;
search->close = FS_Close_WAD;
search->openfile = FS_OpenFile_WAD;
search->filetime = FS_FileTime_WAD;
search->findfile = FS_FindFile_WAD;
search->search = FS_Search_WAD;
fs_searchpaths = search;
Con_Reportf( "Adding wadfile: %s (%i files)\n", wadfile, wad->numlumps );
return true;
}
else
{
if( errorcode != WAD_LOAD_NO_FILES )
Con_Reportf( S_ERROR "FS_AddWad_Fullpath: unable to load wad \"%s\"\n", wadfile );
return false;
}
}
/*
=============================================================================
WADSYSTEM PRIVATE ROUTINES
=============================================================================
*/
/*
===========
W_ReadLump
reading lump into temp buffer
===========
*/
static byte *W_ReadLump( wfile_t *wad, dlumpinfo_t *lump, fs_offset_t *lumpsizeptr )
{
size_t oldpos, size = 0;
byte *buf;
// assume error
if( lumpsizeptr ) *lumpsizeptr = 0;
// no wads loaded
if( !wad || !lump ) return NULL;
oldpos = FS_Tell( wad->handle ); // don't forget restore original position
if( FS_Seek( wad->handle, lump->filepos, SEEK_SET ) == -1 )
{
Con_Reportf( S_ERROR "W_ReadLump: %s is corrupted\n", lump->name );
FS_Seek( wad->handle, oldpos, SEEK_SET );
return NULL;
}
buf = (byte *)Mem_Malloc( wad->mempool, lump->disksize );
size = FS_Read( wad->handle, buf, lump->disksize );
if( size < lump->disksize )
{
Con_Reportf( S_WARN "W_ReadLump: %s is probably corrupted\n", lump->name );
FS_Seek( wad->handle, oldpos, SEEK_SET );
Mem_Free( buf );
return NULL;
}
if( lumpsizeptr ) *lumpsizeptr = lump->disksize;
FS_Seek( wad->handle, oldpos, SEEK_SET );
return buf;
}
/*
===========
FS_LoadWADFile
loading lump into the tmp buffer
===========
*/
byte *FS_LoadWADFile( const char *path, fs_offset_t *lumpsizeptr, qboolean gamedironly )
{
searchpath_t *search;
int index;
search = FS_FindFile( path, &index, gamedironly );
if( search && search->type == SEARCHPATH_WAD )
return W_ReadLump( search->wad, &search->wad->lumps[index], lumpsizeptr );
return NULL;
}

173
filesystem/zip.c

@ -146,7 +146,12 @@ static void FS_EnsureOpenZip( zip_t *zip )
static void FS_EnsureOpenZip( zip_t *zip ) {} static void FS_EnsureOpenZip( zip_t *zip ) {}
#endif #endif
void FS_CloseZIP( zip_t *zip ) /*
============
FS_CloseZIP
============
*/
static void FS_CloseZIP( zip_t *zip )
{ {
if( zip->files ) if( zip->files )
Mem_Free( zip->files ); Mem_Free( zip->files );
@ -159,7 +164,12 @@ void FS_CloseZIP( zip_t *zip )
Mem_Free( zip ); Mem_Free( zip );
} }
void FS_Close_ZIP( searchpath_t *search ) /*
============
FS_Close_ZIP
============
*/
static void FS_Close_ZIP( searchpath_t *search )
{ {
FS_CloseZIP( search->zip ); FS_CloseZIP( search->zip );
} }
@ -412,6 +422,12 @@ file_t *FS_OpenFile_ZIP( searchpath_t *search, const char *filename, const char
return FS_OpenHandle( search->zip->filename, search->zip->handle, pfile->offset, pfile->size ); return FS_OpenHandle( search->zip->filename, search->zip->handle, pfile->offset, pfile->size );
} }
/*
===========
FS_LoadZIPFile
===========
*/
byte *FS_LoadZIPFile( const char *path, fs_offset_t *sizeptr, qboolean gamedironly ) byte *FS_LoadZIPFile( const char *path, fs_offset_t *sizeptr, qboolean gamedironly )
{ {
searchpath_t *search; searchpath_t *search;
@ -551,79 +567,34 @@ byte *FS_LoadZIPFile( const char *path, fs_offset_t *sizeptr, qboolean gamediron
return NULL; return NULL;
} }
/*
===========
FS_FileTime_ZIP
qboolean FS_AddZip_Fullpath( const char *zipfile, qboolean *already_loaded, int flags ) ===========
{ */
searchpath_t *search;
zip_t *zip = NULL;
const char *ext = COM_FileExtension( zipfile );
int errorcode = ZIP_LOAD_COULDNT_OPEN;
for( search = fs_searchpaths; search; search = search->next )
{
if( search->type == SEARCHPATH_ZIP && !Q_stricmp( search->zip->filename, zipfile ))
{
if( already_loaded ) *already_loaded = true;
return true; // already loaded
}
}
if( already_loaded ) *already_loaded = false;
if( !Q_stricmp( ext, "pk3" ) )
zip = FS_LoadZip( zipfile, &errorcode );
if( zip )
{
string fullpath;
int i;
search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ) );
search->zip = zip;
search->type = SEARCHPATH_ZIP;
search->next = fs_searchpaths;
search->flags |= flags;
search->printinfo = FS_PrintInfo_ZIP;
search->close = FS_Close_ZIP;
search->openfile = FS_OpenFile_ZIP;
search->filetime = FS_FileTime_ZIP;
search->findfile = FS_FindFile_ZIP;
search->search = FS_Search_ZIP;
fs_searchpaths = search;
Con_Reportf( "Adding zipfile: %s (%i files)\n", zipfile, zip->numfiles );
// time to add in search list all the wads that contains in current pakfile (if do)
for( i = 0; i < zip->numfiles; i++ )
{
if( !Q_stricmp( COM_FileExtension( zip->files[i].name ), "wad" ))
{
Q_snprintf( fullpath, MAX_STRING, "%s/%s", zipfile, zip->files[i].name );
FS_AddWad_Fullpath( fullpath, NULL, flags );
}
}
return true;
}
else
{
if( errorcode != ZIP_LOAD_NO_FILES )
Con_Reportf( S_ERROR "FS_AddZip_Fullpath: unable to load zip \"%s\"\n", zipfile );
return false;
}
}
int FS_FileTime_ZIP( searchpath_t *search, const char *filename ) int FS_FileTime_ZIP( searchpath_t *search, const char *filename )
{ {
return search->zip->filetime; return search->zip->filetime;
} }
/*
===========
FS_PrintInfo_ZIP
===========
*/
void FS_PrintInfo_ZIP( searchpath_t *search, char *dst, size_t size ) void FS_PrintInfo_ZIP( searchpath_t *search, char *dst, size_t size )
{ {
Q_snprintf( dst, size, "%s (%i files)", search->zip->filename, search->zip->numfiles ); Q_snprintf( dst, size, "%s (%i files)", search->zip->filename, search->zip->numfiles );
} }
/*
===========
FS_FindFile_ZIP
===========
*/
int FS_FindFile_ZIP( searchpath_t *search, const char *path ) int FS_FindFile_ZIP( searchpath_t *search, const char *path )
{ {
int left, right, middle; int left, right, middle;
@ -651,6 +622,12 @@ int FS_FindFile_ZIP( searchpath_t *search, const char *path )
return -1; return -1;
} }
/*
===========
FS_Search_ZIP
===========
*/
void FS_Search_ZIP( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive ) void FS_Search_ZIP( searchpath_t *search, stringlist_t *list, const char *pattern, int caseinsensitive )
{ {
string temp; string temp;
@ -691,3 +668,71 @@ void FS_Search_ZIP( searchpath_t *search, stringlist_t *list, const char *patter
} }
} }
/*
===========
FS_AddZip_Fullpath
===========
*/
qboolean FS_AddZip_Fullpath( const char *zipfile, qboolean *already_loaded, int flags )
{
searchpath_t *search;
zip_t *zip = NULL;
const char *ext = COM_FileExtension( zipfile );
int errorcode = ZIP_LOAD_COULDNT_OPEN;
for( search = fs_searchpaths; search; search = search->next )
{
if( search->type == SEARCHPATH_ZIP && !Q_stricmp( search->zip->filename, zipfile ))
{
if( already_loaded ) *already_loaded = true;
return true; // already loaded
}
}
if( already_loaded ) *already_loaded = false;
if( !Q_stricmp( ext, "pk3" ) )
zip = FS_LoadZip( zipfile, &errorcode );
if( zip )
{
string fullpath;
int i;
search = (searchpath_t *)Mem_Calloc( fs_mempool, sizeof( searchpath_t ) );
search->zip = zip;
search->type = SEARCHPATH_ZIP;
search->next = fs_searchpaths;
search->flags |= flags;
search->printinfo = FS_PrintInfo_ZIP;
search->close = FS_Close_ZIP;
search->openfile = FS_OpenFile_ZIP;
search->filetime = FS_FileTime_ZIP;
search->findfile = FS_FindFile_ZIP;
search->search = FS_Search_ZIP;
fs_searchpaths = search;
Con_Reportf( "Adding zipfile: %s (%i files)\n", zipfile, zip->numfiles );
// time to add in search list all the wads that contains in current pakfile (if do)
for( i = 0; i < zip->numfiles; i++ )
{
if( !Q_stricmp( COM_FileExtension( zip->files[i].name ), "wad" ))
{
Q_snprintf( fullpath, MAX_STRING, "%s/%s", zipfile, zip->files[i].name );
FS_AddWad_Fullpath( fullpath, NULL, flags );
}
}
return true;
}
else
{
if( errorcode != ZIP_LOAD_NO_FILES )
Con_Reportf( S_ERROR "FS_AddZip_Fullpath: unable to load zip \"%s\"\n", zipfile );
return false;
}
}

Loading…
Cancel
Save