@@ -235,16 +235,19 @@ static void CL_WriteDemoMessage( msg_t *msg, int headerBytes ) {
235235
236236/*
237237====================
238- CL_StopRecording_f
238+ CL_StopRecord2
239239
240240stop recording a demo
241241====================
242242*/
243- void CL_StopRecord_f ( void ) {
243+ static void CL_StopRecord2 ( const char * prefix ) {
244244
245245 if ( clc .recordfile != FS_INVALID_HANDLE ) {
246246 char tempPath [MAX_OSPATH ];
247247 char finalPath [MAX_OSPATH ];
248+ // Slice of `finalPath`, so writing to this will write to `finalPath`.
249+ char * finalFilename ;
250+ int finalFilenameSize ;
248251 int protocol ;
249252 int len , sequence ;
250253
@@ -268,31 +271,58 @@ void CL_StopRecord_f( void ) {
268271
269272 Com_sprintf ( tempPath , sizeof ( tempPath ), "%s.tmp" , clc .recordName );
270273
271- Com_sprintf ( finalPath , sizeof ( finalPath ), "%s.%s%d" , clc .recordName , DEMOEXT , protocol );
274+ // e.g. `demos/2026123123123`
275+ Q_strncpyz ( finalPath , clc .recordName , sizeof ( finalPath ) );
276+ // From now on leave the `demos/` part as is,
277+ // and override the `2026123123123` part
278+ finalFilename = COM_SkipPath ( finalPath );
279+ finalFilenameSize = sizeof ( finalPath ) - ( finalFilename - finalPath );
280+
281+ Com_sprintf ( finalFilename , finalFilenameSize , "%s%s.%s%d" ,
282+ prefix , COM_SkipPath ( clc .recordName ), DEMOEXT , protocol );
272283
273284 if ( clc .explicitRecordName ) {
274285 FS_Remove ( finalPath );
275286 } else {
276287 // add sequence suffix to avoid overwrite
277288 sequence = 0 ;
278289 while ( FS_FileExists ( finalPath ) && ++ sequence < 1000 ) {
279- Com_sprintf ( finalPath , sizeof ( finalPath ) , "%s-%02d.%s%d" ,
280- clc .recordName , sequence , DEMOEXT , protocol );
290+ Com_sprintf ( finalFilename , finalFilenameSize , "%s %s-%02d.%s%d" ,
291+ prefix , COM_SkipPath ( clc .recordName ) , sequence , DEMOEXT , protocol );
281292 }
282293 }
283294
284295 FS_Rename ( tempPath , finalPath );
296+
297+ Com_Printf ( "Stopped demo recording %s.\n" , finalPath );
285298 }
286299
287300 if ( !clc .demorecording ) {
288301 Com_Printf ( "Not recording a demo.\n" );
289- } else {
290- Com_Printf ( "Stopped demo recording.\n" );
291302 }
292303
293304 clc .demorecording = qfalse ;
294305 clc .spDemoRecording = qfalse ;
295306}
307+ static void CL_StopRecord_f ( void ) {
308+ // User executed the `\stoprecord` command: add a file name prefix
309+ // so that the user can easily tell apart manually clipped demos
310+ // (e.g. created after a highlight) from auto-recorded ones.
311+ const char * prefix = cl_autoRecordDemo -> integer & 0x1
312+ ? "clip-"
313+ : "" ;
314+ CL_StopRecord2 ( prefix );
315+ }
316+ /*
317+ ====================
318+ CL_StopRecord
319+
320+ For stopping the demo automatically, e.g. on game quit.
321+ ====================
322+ */
323+ void CL_StopRecord ( void ) {
324+ CL_StopRecord2 ( "" );
325+ }
296326
297327
298328/*
@@ -1213,7 +1243,7 @@ qboolean CL_Disconnect( qboolean showMainMenu ) {
12131243
12141244 // Stop demo recording
12151245 if ( clc .demorecording ) {
1216- CL_StopRecord_f ();
1246+ CL_StopRecord ();
12171247 }
12181248
12191249 // Stop demo playback
@@ -1788,7 +1818,7 @@ static void CL_Vid_Restart( refShutdownCode_t shutdownCode ) {
17881818 CL_CloseAVI ( qfalse );
17891819
17901820 if ( clc .demorecording )
1791- CL_StopRecord_f ();
1821+ CL_StopRecord ();
17921822
17931823 // clear and mute all sounds until next registration
17941824 S_DisableSounds ();
@@ -3080,7 +3110,7 @@ void CL_Frame( int msec, int realMsec ) {
30803110 }
30813111 else if ( cls .state != CA_ACTIVE && clc .demorecording ) {
30823112 // Recording, but not CA_ACTIVE, so stop recording
3083- CL_StopRecord_f ();
3113+ CL_StopRecord ();
30843114 }
30853115 }
30863116
0 commit comments