mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-18 02:50:33 +00:00
filesystem: properly support compressed archives in FS_LoadFile
This commit is contained in:
parent
152f6d154c
commit
e791d44dd8
@ -2265,34 +2265,42 @@ Always appends a 0 byte.
|
||||
*/
|
||||
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly )
|
||||
{
|
||||
file_t *file;
|
||||
byte *buf = NULL;
|
||||
fs_offset_t filesize = 0;
|
||||
searchpath_t *search;
|
||||
file_t *file;
|
||||
char netpath[MAX_SYSPATH];
|
||||
int pack_ind;
|
||||
|
||||
file = FS_Open( path, "rb", gamedironly );
|
||||
if( !fs_searchpaths || FS_CheckNastyPath( path ))
|
||||
return NULL;
|
||||
|
||||
search = FS_FindFile( path, &pack_ind, netpath, sizeof( netpath ), gamedironly );
|
||||
|
||||
if( !search )
|
||||
return NULL;
|
||||
|
||||
// custom load file function for compressed files
|
||||
if( search->pfnLoadFile )
|
||||
return search->pfnLoadFile( search, netpath, pack_ind, filesizeptr );
|
||||
|
||||
file = search->pfnOpenFile( search, netpath, "rb", pack_ind );
|
||||
|
||||
if( file )
|
||||
{
|
||||
filesize = file->real_length;
|
||||
fs_offset_t filesize = file->real_length;
|
||||
byte *buf;
|
||||
|
||||
buf = (byte *)Mem_Malloc( fs_mempool, filesize + 1 );
|
||||
buf[filesize] = '\0';
|
||||
FS_Read( file, buf, filesize );
|
||||
FS_Close( file );
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = FS_LoadWADFile( path, &filesize, gamedironly );
|
||||
|
||||
if( !buf )
|
||||
buf = FS_LoadZIPFile( path, &filesize, gamedironly );
|
||||
if( filesizeptr )
|
||||
*filesizeptr = filesize;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
if( filesizeptr )
|
||||
*filesizeptr = filesize;
|
||||
|
||||
return buf;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
qboolean CRC32_File( dword *crcvalue, const char *filename )
|
||||
|
@ -90,6 +90,7 @@ typedef struct searchpath_s
|
||||
int (*pfnFileTime)( struct searchpath_s *search, const char *filename );
|
||||
int (*pfnFindFile)( struct searchpath_s *search, const char *path, char *fixedname, size_t len );
|
||||
void (*pfnSearch)( struct searchpath_s *search, stringlist_t *list, const char *pattern, int caseinsensitive );
|
||||
byte *(*pfnLoadFile)( struct searchpath_s *search, const char *path, int pack_ind, fs_offset_t *filesize );
|
||||
} searchpath_t;
|
||||
|
||||
extern fs_globals_t FI;
|
||||
@ -196,20 +197,11 @@ qboolean FS_AddPak_Fullpath( const char *pakfile, qboolean *already_loaded, int
|
||||
//
|
||||
// wad.c
|
||||
//
|
||||
byte *FS_LoadWADFile( const char *path, fs_offset_t *sizeptr, qboolean gamedironly );
|
||||
qboolean FS_AddWad_Fullpath( const char *wadfile, qboolean *already_loaded, int flags );
|
||||
|
||||
//
|
||||
// watch.c
|
||||
//
|
||||
qboolean FS_WatchInitialize( void );
|
||||
int FS_AddWatch( const char *path, fs_event_callback_t callback );
|
||||
void FS_WatchFrame( void );
|
||||
|
||||
//
|
||||
// zip.c
|
||||
//
|
||||
byte *FS_LoadZIPFile( const char *path, fs_offset_t *sizeptr, qboolean gamedironly );
|
||||
qboolean FS_AddZip_Fullpath( const char *zipfile, qboolean *already_loaded, int flags );
|
||||
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user