From da4f9bd13d6b9e951860d3c4c83eabfee6648302 Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Sat, 18 Oct 2025 17:54:19 +0100 Subject: [PATCH] Fix demo command file completion --- code/client/cl_console.c | 2 +- code/client/cl_main.c | 6 +++--- code/qcommon/cmd.c | 2 +- code/qcommon/common.c | 9 +++++---- code/qcommon/files.c | 37 +++++++++++++++++++++++-------------- code/qcommon/qcommon.h | 7 ++++--- code/server/sv_ccmds.c | 2 +- 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/code/client/cl_console.c b/code/client/cl_console.c index 6a65bb79..1748e047 100644 --- a/code/client/cl_console.c +++ b/code/client/cl_console.c @@ -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 ); } } diff --git a/code/client/cl_main.c b/code/client/cl_main.c index 1a493bce..7cb92f6c 100644 --- a/code/client/cl_main.c +++ b/code/client/cl_main.c @@ -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 ); } } diff --git a/code/qcommon/cmd.c b/code/qcommon/cmd.c index b6b5a83c..ed94517f 100644 --- a/code/qcommon/cmd.c +++ b/code/qcommon/cmd.c @@ -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 ); } } diff --git a/code/qcommon/common.c b/code/qcommon/common.c index c07def02..9e6bf597 100644 --- a/code/qcommon/common.c +++ b/code/qcommon/common.c @@ -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 ); } /* diff --git a/code/qcommon/files.c b/code/qcommon/files.c index 9f073476..5326bfd7 100644 --- a/code/qcommon/files.c +++ b/code/qcommon/files.c @@ -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 ); diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h index 61bcfdf9..d7e26459 100644 --- a/code/qcommon/qcommon.h +++ b/code/qcommon/qcommon.h @@ -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 ); diff --git a/code/server/sv_ccmds.c b/code/server/sv_ccmds.c index 03600ba9..1ef5db6f 100644 --- a/code/server/sv_ccmds.c +++ b/code/server/sv_ccmds.c @@ -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 ); } }