From 6eb212d8bfeb77e4376806e62bc54039db5b8ffc Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 1 Aug 2012 09:47:43 +0200 Subject: [PATCH] get rid of FS_DefaultExtension, add FS_SetExtension which may set if missing, or always override, the extension depending on parameter. For now, override in all cases. --- cl_demo.c | 4 ++-- fs.c | 14 +++++++------- fs.h | 2 +- host_cmd.c | 4 ++-- sv_demo.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cl_demo.c b/cl_demo.c index 1584cb7b..9adb0de5 100644 --- a/cl_demo.c +++ b/cl_demo.c @@ -370,7 +370,7 @@ void CL_Record_f (void) // get the demo name strlcpy (name, Cmd_Argv(1), sizeof (name)); - FS_DefaultExtension (name, ".dem", sizeof (name)); + FS_SetExtension (name, ".dem", sizeof (name), true); // start the map up if (c > 2) @@ -417,7 +417,7 @@ void CL_PlayDemo_f (void) // open the demo file strlcpy (name, Cmd_Argv(1), sizeof (name)); - FS_DefaultExtension (name, ".dem", sizeof (name)); + FS_SetExtension (name, ".dem", sizeof (name), true); f = FS_OpenVirtualFile(name, false); if (!f) { diff --git a/fs.c b/fs.c index e21a5839..927b198a 100644 --- a/fs.c +++ b/fs.c @@ -3266,10 +3266,10 @@ void FS_StripExtension (const char *in, char *out, size_t size_out) /* ================== -FS_DefaultExtension +FS_SetExtension ================== */ -void FS_DefaultExtension (char *path, const char *extension, size_t size_path) +void FS_SetExtension (char *path, const char *extension, size_t size_path, qboolean forceextension) { const char *src; @@ -3277,12 +3277,12 @@ void FS_DefaultExtension (char *path, const char *extension, size_t size_path) // (extension should include the .) src = path + strlen(path) - 1; - while (*src != '/' && src != path) - { - if (*src == '.') - return; // it has an extension + while (*src != '/' && *src != '.' && src != path) src--; - } + + if (*src == '.') + if(!forceextension || !strcasecmp(src, extension)) + return; // it has an (or the) extension strlcat (path, extension, size_path); } diff --git a/fs.h b/fs.h index cd1979a2..f38ddbae 100644 --- a/fs.h +++ b/fs.h @@ -118,7 +118,7 @@ qboolean FS_WriteFile (const char *filename, const void *data, fs_offset_t len); // ------ Other functions ------ // void FS_StripExtension (const char *in, char *out, size_t size_out); -void FS_DefaultExtension (char *path, const char *extension, size_t size_path); +void FS_SetExtension (char *path, const char *extension, size_t size_path, qboolean forceextension); #define FS_FILETYPE_NONE 0 #define FS_FILETYPE_FILE 1 diff --git a/host_cmd.c b/host_cmd.c index d25f61e5..1a8112b8 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -741,7 +741,7 @@ static void Host_Savegame_f (void) } strlcpy (name, Cmd_Argv(1), sizeof (name)); - FS_DefaultExtension (name, ".sav", sizeof (name)); + FS_SetExtension (name, ".sav", sizeof (name), true); Host_Savegame_to(prog, name); } @@ -778,7 +778,7 @@ static void Host_Loadgame_f (void) } strlcpy (filename, Cmd_Argv(1), sizeof(filename)); - FS_DefaultExtension (filename, ".sav", sizeof (filename)); + FS_SetExtension (filename, ".sav", sizeof (filename), true); Con_Printf("Loading game from %s...\n", filename); diff --git a/sv_demo.c b/sv_demo.c index cc94a2c0..63d919a4 100644 --- a/sv_demo.c +++ b/sv_demo.c @@ -12,7 +12,7 @@ void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrac return; // we already have a demo strlcpy(name, filename, sizeof(name)); - FS_DefaultExtension(name, ".dem", sizeof(name)); + FS_SetExtension(name, ".dem", sizeof(name), true); Con_Printf("Recording demo for # %d (%s) to %s\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress, name); -- 2.39.2