From d98a8476ebddd1bf05197cce949646f2116ee1a6 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Sat, 20 Jul 2024 12:53:53 +0200 Subject: [PATCH] check for existing savegame files ignoring case (#1797) * check for existing savegame files ignoring case * variable naming --- src/g_game.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 79f3039d..ba2da058 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2159,14 +2159,39 @@ char* G_SaveGameName(int slot) char buf[16] = {0}; sprintf(buf, "%.7s%d.dsg", savegamename, 10*savepage+slot); - return M_StringJoin(basesavegame, DIR_SEPARATOR_S, buf); + char *filepath = M_StringJoin(basesavegame, DIR_SEPARATOR_S, buf); + char *existing = M_FileCaseExists(filepath); + + if (existing) + { + free(filepath); + return existing; + } + else + { + char *filename = (char *)M_BaseName(filepath); + M_StringToLower(filename); + return filepath; + } } char* G_MBFSaveGameName(int slot) { - char buf[16] = {0}; - sprintf(buf, "MBFSAV%d.dsg", 10*savepage+slot); - return M_StringJoin(basesavegame, DIR_SEPARATOR_S, buf); + char buf[16] = {0}; + sprintf(buf, "MBFSAV%d.dsg", 10*savepage+slot); + + char *filepath = M_StringJoin(basesavegame, DIR_SEPARATOR_S, buf); + char *existing = M_FileCaseExists(filepath); + + if (existing) + { + free(filepath); + return existing; + } + else + { + return filepath; + } } // killough 12/98: