From 6aa4a690d6cabd49dcc0466165fb863cc4968d2f Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 13 Mar 2002 18:09:33 +0000 Subject: [PATCH] demo auto-naming patch from RvB --- qw/source/cl_demo.c | 52 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/qw/source/cl_demo.c b/qw/source/cl_demo.c index 082998488..c0719168f 100644 --- a/qw/source/cl_demo.c +++ b/qw/source/cl_demo.c @@ -41,7 +41,8 @@ static const char rcsid[] = #endif #include - +#include + #include "QF/console.h" #include "QF/cmd.h" #include "QF/cvar.h" @@ -414,19 +415,25 @@ CL_WriteSetDemoMessage (void) void CL_Record_f (void) { - char buf_data[MAX_MSGLEN + 10]; // + 10 for header + char buf_data[MAX_MSGLEN + 10]; // + 10 for header char name[MAX_OSPATH]; - char *s; - int c, n, i, j; - int seq = 1; + char *s; + char timestring[20]; + char mapname[MAX_OSPATH]; + + int c, n, i, j, k, l=0; + int seq = 1; entity_t *ent; entity_state_t *es, blankes; player_info_t *player; - sizebuf_t buf; + sizebuf_t buf; + time_t tim; c = Cmd_Argc (); - if (c != 2) { - Con_Printf ("record \n"); + if (c > 2) { + /* we use a demo name like year-month-day-hours-minutes-mapname.qwd + if there is no argument */ + Con_Printf ("record [demoname]\n"); return; } @@ -438,7 +445,34 @@ CL_Record_f (void) if (cls.demorecording) CL_Stop_f (); - snprintf (name, sizeof (name), "%s/%s", com_gamedir, Cmd_Argv (1)); + if (c < 2) { + // Get time to a useable format + time (&tim); + strftime (timestring, 19, "%Y-%m-%d-%H-%M", localtime (&tim)); + + // the leading path-name is to be removed from cl.worldmodel->name + for (k = 0; k <= strlen (cl.worldmodel->name); k++) { + if (cl.worldmodel->name[k] == '/') { + l = 0; + mapname[l] = '\0'; + continue; + } + mapname[l] = cl.worldmodel->name[k]; + l++; + } + + // the map name is cut off after any "." because this would prevent + // ".qwd" from being appended + + for (k = 0; k <= strlen (mapname); k++) + if (mapname[k] == '.') + mapname[k] = '\0'; + + snprintf (name, sizeof (name), "%s/%s-%s", com_gamedir, + timestring, mapname); + } else { + snprintf (name, sizeof (name), "%s/%s", com_gamedir, Cmd_Argv(1)); + } // open the demo file COM_DefaultExtension (name, ".qwd");