diff options
author | Simon Howard | 2011-09-05 21:57:23 +0000 |
---|---|---|
committer | Simon Howard | 2011-09-05 21:57:23 +0000 |
commit | 9ff63977237ba7d7edb7f863c9a6ad4dd5b07cbe (patch) | |
tree | 24897cb4eb0e08f5e53ce2248c87603542e4f5fd /src | |
parent | b2318d4849a6cd033372ef9164cd06b74c78583c (diff) | |
download | chocolate-doom-9ff63977237ba7d7edb7f863c9a6ad4dd5b07cbe.tar.gz chocolate-doom-9ff63977237ba7d7edb7f863c9a6ad4dd5b07cbe.tar.bz2 chocolate-doom-9ff63977237ba7d7edb7f863c9a6ad4dd5b07cbe.zip |
Refactor savegamedir calculation code to work the same as trunk.
Subversion-branch: /branches/raven-branch
Subversion-revision: 2360
Diffstat (limited to 'src')
-rw-r--r-- | src/d_iwad.c | 28 | ||||
-rw-r--r-- | src/d_iwad.h | 1 | ||||
-rw-r--r-- | src/doom/d_main.c | 57 | ||||
-rw-r--r-- | src/m_config.c | 37 | ||||
-rw-r--r-- | src/m_config.h | 1 |
5 files changed, 89 insertions, 35 deletions
diff --git a/src/d_iwad.c b/src/d_iwad.c index 72e3e3ad..5cc31738 100644 --- a/src/d_iwad.c +++ b/src/d_iwad.c @@ -727,3 +727,31 @@ iwad_t **D_FindAllIWADs(int mask) return result; } +// +// Get the IWAD name used for savegames. +// + +char *D_SaveGameIWADName(GameMission_t gamemission) +{ + size_t i; + + // Determine the IWAD name to use for savegames. + // This determines the directory the savegame files get put into. + // + // Note that we match on gamemission rather than on IWAD name. + // This ensures that doom1.wad and doom.wad saves are stored + // in the same place. + + for (i=0; i<arrlen(iwads); ++i) + { + if (gamemission == iwads[i].mission) + { + return iwads[i].name; + } + } + + // Default fallback: + + return "unknown.wad"; +} + diff --git a/src/d_iwad.h b/src/d_iwad.h index f95b4258..f3a6c2d8 100644 --- a/src/d_iwad.h +++ b/src/d_iwad.h @@ -48,6 +48,7 @@ char *D_FindWADByName(char *filename); char *D_TryFindWADByName(char *filename); char *D_FindIWAD(int mask, GameMission_t *mission); iwad_t **D_FindAllIWADs(int mask); +char *D_SaveGameIWADName(GameMission_t gamemission); #endif diff --git a/src/doom/d_main.c b/src/doom/d_main.c index f626d408..0e5324b4 100644 --- a/src/doom/d_main.c +++ b/src/doom/d_main.c @@ -786,40 +786,6 @@ void D_SetGameDescription(void) } } -static void SetSaveGameDir(char *iwad_filename) -{ - char *sep; - char *basefile; - - // Extract the base filename - - sep = strrchr(iwad_filename, DIR_SEPARATOR); - - if (sep == NULL) - { - basefile = iwad_filename; - } - else - { - basefile = sep + 1; - } - - // ~/.chocolate-doom/savegames/ - - savegamedir = Z_Malloc(strlen(configdir) + 30, PU_STATIC, 0); - sprintf(savegamedir, "%ssavegames%c", configdir, - DIR_SEPARATOR); - - M_MakeDirectory(savegamedir); - - // eg. ~/.chocolate-doom/savegames/doom2.wad/ - - sprintf(savegamedir + strlen(savegamedir), "%s%c", - basefile, DIR_SEPARATOR); - - M_MakeDirectory(savegamedir); -} - // Check if the IWAD file is the Chex Quest IWAD. // Returns true if this is chex.wad. @@ -1121,6 +1087,27 @@ static void LoadHacxDeh(void) } } +// Figure out what IWAD name to use for savegames. + +static char *SaveGameIWADName(void) +{ + // Chex quest hack + + if (gameversion == exe_chex) + { + return "chex.wad"; + } + + // Hacx hack + + if (gameversion == exe_hacx) + { + return "hacx.wad"; + } + + return D_SaveGameIWADName(gamemission); +} + // // D_DoomMain // @@ -1439,7 +1426,7 @@ void D_DoomMain (void) LoadChexDeh(); LoadHacxDeh(); D_SetGameDescription(); - SetSaveGameDir(iwadfile); + savegamedir = M_GetSaveGameDir(SaveGameIWADName()); // Check for -file in shareware if (modifiedgame) diff --git a/src/m_config.c b/src/m_config.c index a0f97dc2..52718018 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -1577,3 +1577,40 @@ void M_SetConfigDir(char *dir) M_MakeDirectory(configdir); } +// +// Calculate the path to the directory to use to store save games. +// Creates the directory as necessary. +// + +char *M_GetSaveGameDir(char *iwadname) +{ + char *savegamedir; + + // If not "doing" a configuration directory (Windows), don't "do" + // a savegame directory, either. + + if (!strcmp(configdir, "")) + { + savegamedir = strdup(""); + } + else + { + // ~/.chocolate-doom/savegames/ + + savegamedir = malloc(strlen(configdir) + 30); + sprintf(savegamedir, "%ssavegames%c", configdir, + DIR_SEPARATOR); + + M_MakeDirectory(savegamedir); + + // eg. ~/.chocolate-doom/savegames/doom2.wad/ + + sprintf(savegamedir + strlen(savegamedir), "%s%c", + iwadname, DIR_SEPARATOR); + + M_MakeDirectory(savegamedir); + } + + return savegamedir; +} + diff --git a/src/m_config.h b/src/m_config.h index ff772bea..999b50ae 100644 --- a/src/m_config.h +++ b/src/m_config.h @@ -34,6 +34,7 @@ void M_SaveDefaultsAlternate(char *main, char *extra); void M_SetConfigDir(char *dir); void M_BindVariable(char *name, void *variable); void M_SetConfigFilenames(char *main_config, char *extra_config); +char *M_GetSaveGameDir(char *iwadname); extern char *configdir; |