summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2006-05-25 22:39:57 +0000
committerSimon Howard2006-05-25 22:39:57 +0000
commit95b8e84325654d5024b602b5e974447bef5e37fd (patch)
treef9af0a43154c1a52e783b0d086d4bdae2866bc92
parent42ebb5bebb6889de52c04a5eb65837b20b489445 (diff)
downloadchocolate-doom-95b8e84325654d5024b602b5e974447bef5e37fd.tar.gz
chocolate-doom-95b8e84325654d5024b602b5e974447bef5e37fd.tar.bz2
chocolate-doom-95b8e84325654d5024b602b5e974447bef5e37fd.zip
Put savegames in separate directories depending on the IWAD.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 531
-rw-r--r--src/d_main.c79
-rw-r--r--src/doomstat.h3
-rw-r--r--src/p_saveg.c6
3 files changed, 77 insertions, 11 deletions
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<sizeof(iwads) / sizeof(*iwads); ++i)
+ {
+ if (gamemission == iwads[i].mission)
+ {
+ strcat(savegamedir, "/");
+ strcat(savegamedir, iwads[i].name);
+ strcat(savegamedir, "/");
+ MakeDirectory(savegamedir);
+ break;
+ }
+ }
+ }
+}
+
static struct
{
char *description;
@@ -1578,6 +1642,7 @@ void D_DoomMain (void)
IdentifyVersion();
InitGameVersion();
SetGameDescription();
+ SetSaveGameDir();
// Check for -file in shareware
if (modifiedgame)
diff --git a/src/doomstat.h b/src/doomstat.h
index 6a220c1c..0632d416 100644
--- a/src/doomstat.h
+++ b/src/doomstat.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: doomstat.h 475 2006-05-05 19:49:34Z fraggle $
+// $Id: doomstat.h 531 2006-05-25 22:39:57Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -253,6 +253,7 @@ extern int maxammo[NUMAMMO];
// File handling stuff.
extern char * configdir;
+extern char * savegamedir;
extern char basedefault[1024];
extern FILE* debugfile;
diff --git a/src/p_saveg.c b/src/p_saveg.c
index c7bfefcb..8bced8ec 100644
--- a/src/p_saveg.c
+++ b/src/p_saveg.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: p_saveg.c 485 2006-05-19 20:03:49Z fraggle $
+// $Id: p_saveg.c 531 2006-05-25 22:39:57Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -60,7 +60,7 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: p_saveg.c 485 2006-05-19 20:03:49Z fraggle $";
+rcsid[] = "$Id: p_saveg.c 531 2006-05-25 22:39:57Z fraggle $";
#include <stdio.h>
@@ -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;
}