From 95b8e84325654d5024b602b5e974447bef5e37fd Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 25 May 2006 22:39:57 +0000 Subject: Put savegames in separate directories depending on the IWAD. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 531 --- src/d_main.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ src/doomstat.h | 3 ++- src/p_saveg.c | 6 ++--- 3 files changed, 77 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/d_main.c b/src/d_main.c index 78781ea9..6038cdca 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: d_main.c 510 2006-05-22 18:51:21Z fraggle $ +// $Id: d_main.c 531 2006-05-25 22:39:57Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -184,7 +184,7 @@ //----------------------------------------------------------------------------- -static const char rcsid[] = "$Id: d_main.c 510 2006-05-22 18:51:21Z fraggle $"; +static const char rcsid[] = "$Id: d_main.c 531 2006-05-25 22:39:57Z fraggle $"; #define BGCOLOR 7 #define FGCOLOR 8 @@ -264,6 +264,10 @@ void D_DoomLoop (void); char * configdir; +// Location where savegames are stored + +char * savegamedir; + // location of IWAD and WAD files char * iwadfile; @@ -1184,6 +1188,16 @@ void PrintDehackedBanners(void) } } +static void MakeDirectory(char *path) +{ +#ifdef _WIN32 + mkdir(path); +#else + mkdir(path, 0755); +#endif +} + + // // SetConfigDir: // @@ -1207,11 +1221,10 @@ static void SetConfigDir(void) sprintf(configdir, "%s/.%s/", homedir, PACKAGE_TARNAME); // make the directory if it doesnt already exist -#ifdef _WIN32 - mkdir(configdir); -#else - mkdir(configdir, 0755); -#endif + + MakeDirectory(configdir); + + } else { @@ -1232,6 +1245,57 @@ static void SetConfigDir(void) } } +// +// SetSaveGameDir +// +// Chooses the directory used to store saved games. +// + +static void SetSaveGameDir(void) +{ + int i; + + if (!strcmp(configdir, "")) + { + // Use the current directory, just like configdir. + + savegamedir = strdup(""); + } + else + { + // Directory for savegames + + savegamedir = malloc(strlen(configdir) + 30); + sprintf(savegamedir, "%ssavegames", configdir); + + MakeDirectory(savegamedir); + + // Find what subdirectory to use for savegames + // + // They should be stored in something like + // ~/.chocolate-doom/savegames/doom.wad/ + // + // The directory depends on the IWAD, so that savegames for + // different IWADs are kept separate. + // + // 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 @@ -88,7 +88,7 @@ char *P_SaveGameFile(int slot) sprintf(basename, DEH_String(SAVEGAMENAME "%d.dsg"), slot); - sprintf(filename, "%s%s", configdir, basename); + sprintf(filename, "%s%s", savegamedir, basename); return filename; } -- cgit v1.2.3