Fix demo command file completion

This commit is contained in:
Tim Angus 2025-10-18 17:54:19 +01:00
parent 8cc9eb5eff
commit da4f9bd13d
7 changed files with 38 additions and 27 deletions

View File

@ -343,7 +343,7 @@ Cmd_CompleteTxtName
*/
void Cmd_CompleteTxtName( char *args, int argNum ) {
if( argNum == 2 ) {
Field_CompleteFilename( "", "txt", qfalse, qtrue );
Field_CompleteFilename( "", "txt", NULL, qfalse, qtrue );
}
}

View File

@ -1052,10 +1052,10 @@ static void CL_CompleteDemoName( char *args, int argNum )
{
if( argNum == 2 )
{
char demoExt[ 16 ];
char demoFilter[ 16 ];
Com_sprintf(demoExt, sizeof(demoExt), ".%s%d", DEMOEXT, com_protocol->integer);
Field_CompleteFilename( "demos", demoExt, qtrue, qtrue );
Com_sprintf( demoFilter, sizeof(demoFilter), "*.%s*", DEMOEXT );
Field_CompleteFilename( "demos", "", demoFilter, qfalse, qtrue );
}
}

View File

@ -848,7 +848,7 @@ Cmd_CompleteCfgName
*/
void Cmd_CompleteCfgName( char *args, int argNum ) {
if( argNum == 2 ) {
Field_CompleteFilename( "", "cfg", qfalse, qtrue );
Field_CompleteFilename( "", "cfg", NULL, qfalse, qtrue );
}
}

View File

@ -3451,16 +3451,17 @@ void Field_CompleteKeyname( void )
Field_CompleteFilename
===============
*/
void Field_CompleteFilename( const char *dir,
const char *ext, qboolean stripExt, qboolean allowNonPureFilesOnDisk )
void Field_CompleteFilename( const char *dir, const char *ext,
char *filter, qboolean stripExt,
qboolean allowNonPureFilesOnDisk )
{
matchCount = 0;
shortestMatch[ 0 ] = 0;
FS_FilenameCompletion( dir, ext, stripExt, FindMatches, allowNonPureFilesOnDisk );
FS_FilenameCompletion( dir, ext, filter, stripExt, FindMatches, allowNonPureFilesOnDisk );
if( !Field_Complete( ) )
FS_FilenameCompletion( dir, ext, stripExt, PrintMatches, allowNonPureFilesOnDisk );
FS_FilenameCompletion( dir, ext, filter, stripExt, PrintMatches, allowNonPureFilesOnDisk );
}
/*

View File

@ -2146,7 +2146,9 @@ Returns a uniqued list of files that match the given criteria
from all search paths
===============
*/
char **FS_ListFilteredFiles( const char *path, const char *extension, char *filter, int *numfiles, qboolean allowNonPureFilesOnDisk ) {
char **FS_ListFilteredFiles( const char *path, const char *extension,
char *filter, int *numfiles, qboolean stripPath,
qboolean allowNonPureFilesOnDisk ) {
int nfiles;
char **listCopy;
char *list[MAX_FOUND_FILES];
@ -2154,7 +2156,7 @@ char **FS_ListFilteredFiles( const char *path, const char *extension, char *filt
int i;
int pathLength;
int extensionLength;
int length, pathDepth, temp;
int length, pathDepth, pathSkip;
pack_t *pak;
fileInPack_t *buildBuffer;
char zpath[MAX_ZPATH];
@ -2201,13 +2203,23 @@ char **FS_ListFilteredFiles( const char *path, const char *extension, char *filt
// check for directory match
name = buildBuffer[i].name;
//
if (stripPath) {
pathSkip = pathLength;
if (pathLength) {
pathSkip++; // include the '/'
}
} else {
pathSkip = 0;
}
if (filter) {
// case insensitive
if (!Com_FilterPath( filter, name, qfalse ))
continue;
// unique the match
nfiles = FS_AddFileToList( name, list, nfiles );
nfiles = FS_AddFileToList( name + pathSkip, list, nfiles );
}
else {
@ -2226,13 +2238,9 @@ char **FS_ListFilteredFiles( const char *path, const char *extension, char *filt
if ( Q_stricmp( name + length - extensionLength, extension ) ) {
continue;
}
// unique the match
temp = pathLength;
if (pathLength) {
temp++; // include the '/'
}
nfiles = FS_AddFileToList( name + temp, list, nfiles );
// unique the match
nfiles = FS_AddFileToList( name + pathSkip, list, nfiles );
}
}
} else if (search->dir) { // scan for files in the filesystem
@ -2279,7 +2287,7 @@ FS_ListFiles
=================
*/
char **FS_ListFiles( const char *path, const char *extension, int *numfiles ) {
return FS_ListFilteredFiles( path, extension, NULL, numfiles, qfalse );
return FS_ListFilteredFiles( path, extension, NULL, numfiles, qtrue, qfalse );
}
/*
@ -2686,7 +2694,7 @@ void FS_NewDir_f( void ) {
Com_Printf( "---------------\n" );
dirnames = FS_ListFilteredFiles( "", "", filter, &ndirs, qfalse );
dirnames = FS_ListFilteredFiles( "", "", filter, &ndirs, qfalse, qfalse );
FS_SortFileList(dirnames, ndirs);
@ -4239,14 +4247,15 @@ void FS_Flush( fileHandle_t f ) {
fflush(fsh[f].handleFiles.file.o);
}
void FS_FilenameCompletion( const char *dir, const char *ext,
void FS_FilenameCompletion( const char *dir, const char *ext, char *filter,
qboolean stripExt, void(*callback)(const char *s), qboolean allowNonPureFilesOnDisk ) {
char **filenames;
int nfiles;
int i;
char filename[ MAX_STRING_CHARS ];
filenames = FS_ListFilteredFiles( dir, ext, NULL, &nfiles, allowNonPureFilesOnDisk );
filenames = FS_ListFilteredFiles( dir, ext, filter,
&nfiles, qtrue, allowNonPureFilesOnDisk );
FS_SortFileList( filenames, nfiles );

View File

@ -727,7 +727,7 @@ qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring );
void FS_Remove( const char *osPath );
void FS_HomeRemove( const char *homePath );
void FS_FilenameCompletion( const char *dir, const char *ext,
void FS_FilenameCompletion( const char *dir, const char *ext, char *filter,
qboolean stripExt, void(*callback)(const char *s), qboolean allowNonPureFilesOnDisk );
const char *FS_GetCurrentGameDir(void);
@ -752,8 +752,9 @@ typedef struct {
void Field_Clear( field_t *edit );
void Field_AutoComplete( field_t *edit );
void Field_CompleteKeyname( void );
void Field_CompleteFilename( const char *dir,
const char *ext, qboolean stripExt, qboolean allowNonPureFilesOnDisk );
void Field_CompleteFilename( const char *dir, const char *ext,
char *filter, qboolean stripExt,
qboolean allowNonPureFilesOnDisk );
void Field_CompleteCommand( char *cmd,
qboolean doCommands, qboolean doCvars );
void Field_CompletePlayerName( const char **names, int count );

View File

@ -1466,7 +1466,7 @@ SV_CompleteMapName
*/
static void SV_CompleteMapName( char *args, int argNum ) {
if( argNum == 2 ) {
Field_CompleteFilename( "maps", "bsp", qtrue, qfalse );
Field_CompleteFilename( "maps", "bsp", NULL, qtrue, qfalse );
}
}