ref: 95b8e84325654d5024b602b5e974447bef5e37fd
parent: 42ebb5bebb6889de52c04a5eb65837b20b489445
author: Simon Howard <fraggle@gmail.com>
date: Thu May 25 18:39:57 EDT 2006
Put savegames in separate directories depending on the IWAD. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 531
--- 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 @@
char * configdir;
+// Location where savegames are stored
+
+char * savegamedir;
+
// location of IWAD and WAD files
char * iwadfile;
@@ -1184,6 +1188,16 @@
}
}
+static void MakeDirectory(char *path)
+{
+#ifdef _WIN32
+ mkdir(path);
+#else
+ mkdir(path, 0755);
+#endif
+}
+
+
//
// SetConfigDir:
//
@@ -1207,11 +1221,10 @@
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 @@
}
}
+//
+// 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 @@
IdentifyVersion();
InitGameVersion();
SetGameDescription();
+ SetSaveGameDir();
// Check for -file in shareware
if (modifiedgame)
--- 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 @@
// File handling stuff.
extern char * configdir;
+extern char * savegamedir;
extern char basedefault[1024];
extern FILE* debugfile;
--- 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 @@
sprintf(basename, DEH_String(SAVEGAMENAME "%d.dsg"), slot);
- sprintf(filename, "%s%s", configdir, basename);
+ sprintf(filename, "%s%s", savegamedir, basename);
return filename;
}