engine: filesystem: fixed FS_Search algorithm for ZIP files (fix #796)

This commit is contained in:
SNMetamorph 2022-03-15 22:49:50 +04:00 committed by a1batross
parent cd2720ba81
commit 65d624140e
1 changed files with 37 additions and 0 deletions

View File

@ -3658,6 +3658,7 @@ search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
searchpath_t *searchpath;
pack_t *pak;
wfile_t *wad;
zip_t *zip;
int i, basepathlength, numfiles, numchars;
int resultlistindex, dirlistindex;
const char *slash, *backslash, *colon, *separator;
@ -3725,6 +3726,42 @@ search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
}
}
}
else if( searchpath->zip )
{
zip = searchpath->zip;
for( i = 0; i < zip->numfiles; i++ )
{
Q_strncpy( temp, zip->files[i].name, sizeof(temp) );
while( temp[0] )
{
if( matchpattern( temp, (char *)pattern, true ))
{
for( resultlistindex = 0; resultlistindex < resultlist.numstrings; resultlistindex++ )
{
if( !Q_strcmp( resultlist.strings[resultlistindex], temp ))
break;
}
if( resultlistindex == resultlist.numstrings )
stringlistappend( &resultlist, temp );
}
// strip off one path element at a time until empty
// this way directories are added to the listing if they match the pattern
slash = Q_strrchr( temp, '/' );
backslash = Q_strrchr( temp, '\\' );
colon = Q_strrchr( temp, ':' );
separator = temp;
if( separator < slash )
separator = slash;
if( separator < backslash )
separator = backslash;
if( separator < colon )
separator = colon;
*((char *)separator) = 0;
}
}
}
else if( searchpath->wad )
{
string wadpattern, wadname, temp2;