filesystem: add utility function FS_CheckForQuakePak that parses Quake PAK file and looks for specific files in it's root
Used to properly detect Quake game dirs.
This commit is contained in:
parent
83b5edea88
commit
ceb2b0c5e4
2 changed files with 45 additions and 0 deletions
|
@ -230,6 +230,7 @@ qboolean FS_FullPathToRelativePath( char *dst, const char *src, size_t size );
|
||||||
//
|
//
|
||||||
// pak.c
|
// pak.c
|
||||||
//
|
//
|
||||||
|
qboolean FS_CheckForQuakePak( const char *pakfile, const char *files[], size_t num_files );
|
||||||
searchpath_t *FS_AddPak_Fullpath( const char *pakfile, int flags );
|
searchpath_t *FS_AddPak_Fullpath( const char *pakfile, int flags );
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -105,6 +105,8 @@ static pack_t *FS_LoadPackPAK( const char *packfile, int *error )
|
||||||
|
|
||||||
// TODO: use FS_Open to allow PK3 to be included into other archives
|
// TODO: use FS_Open to allow PK3 to be included into other archives
|
||||||
// Currently, it doesn't work with rodir due to FS_FindFile logic
|
// Currently, it doesn't work with rodir due to FS_FindFile logic
|
||||||
|
// when it will use FS_Open, check that FS_CheckForQuakePak correctly
|
||||||
|
// detects Quake gamedirs in RoDir
|
||||||
packhandle = FS_SysOpen( packfile, "rb" );
|
packhandle = FS_SysOpen( packfile, "rb" );
|
||||||
|
|
||||||
if( packhandle == NULL )
|
if( packhandle == NULL )
|
||||||
|
@ -364,3 +366,45 @@ searchpath_t *FS_AddPak_Fullpath( const char *pakfile, int flags )
|
||||||
|
|
||||||
return search;
|
return search;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
================
|
||||||
|
FS_CheckForQuakePak
|
||||||
|
|
||||||
|
To generate fake gameinfo for Quake directory, we need to parse pak0.pak
|
||||||
|
and find progs.dat in it
|
||||||
|
================
|
||||||
|
*/
|
||||||
|
qboolean FS_CheckForQuakePak( const char *pakfile, const char *files[], size_t num_files )
|
||||||
|
{
|
||||||
|
qboolean is_quake = false;
|
||||||
|
pack_t *pak;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pak = FS_LoadPackPAK( pakfile, NULL );
|
||||||
|
if( !pak )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for( i = 0; i < num_files; i++ )
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
|
||||||
|
for( j = 0; j < pak->numfiles; j++ )
|
||||||
|
{
|
||||||
|
if( Q_strchr( pak->files[j].name, '/' ))
|
||||||
|
continue; // exclude subdirectories
|
||||||
|
|
||||||
|
if( !Q_stricmp( pak->files[j].name, files[i] ))
|
||||||
|
{
|
||||||
|
is_quake = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( is_quake )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mem_Free( pak );
|
||||||
|
return is_quake;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue