ref: 77094ab901ee37f19399cf26b9f527d509e3c778
parent: 939cbfeb115338cf7868e516019a4ae832b1ebde
parent: 98f798dd4b926ff8e97ed0b058c750ba2d5e2b06
author: Simon Howard <fraggle+github@gmail.com>
date: Mon Jan 2 10:02:32 EST 2017
Merge pull request #823 from CapnClever/commandline-savedir d_main.c: Add "-savedir" command line parameter
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,9 @@
+## HEAD
+
+### General
+ * A new parameter -savedir allows users to specify a directory from
+ which to load and save games. (thanks CapnClever)
+
## 2.3.0 (2016-12-29)
### General
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1614,17 +1614,7 @@
// we've finished loading Dehacked patches.
D_SetGameDescription();
-#ifdef _WIN32
- // In -cdrom mode, we write savegames to c:\doomdata as well as configs.
- if (M_ParmExists("-cdrom"))
- {
- savegamedir = configdir;
- }
- else
-#endif
- {
- savegamedir = M_GetSaveGameDir(D_SaveGameIWADName(gamemission));
- }
+ savegamedir = M_GetSaveGameDir(D_SaveGameIWADName(gamemission));
// Check for -file in shareware
if (modifiedgame && (gamevariant != freedoom))
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -120,6 +120,7 @@
static int demosequence;
static int pagetic;
static char *pagename;
+static char *SavePathConfig;
// CODE --------------------------------------------------------------------
@@ -164,7 +165,7 @@
M_BindIntVariable("vanilla_savegame_limit", &vanilla_savegame_limit);
M_BindIntVariable("vanilla_demo_limit", &vanilla_demo_limit);
- M_BindStringVariable("savedir", &SavePath);
+ M_BindStringVariable("savedir", &SavePathConfig);
// Multiplayer chat macros
@@ -183,15 +184,31 @@
{
SavePath = M_GetSaveGameDir("hexen.wad");
- // If we are not using a savegame path (probably because we are on
- // Windows and not using a config dir), behave like Vanilla Hexen
- // and use hexndata/:
-
if (!strcmp(SavePath, ""))
{
- SavePath = malloc(10);
- M_snprintf(SavePath, 10, "hexndata%c", DIR_SEPARATOR);
+ // only get hexen.cfg path if one is not already found
+
+ if (!strcmp(SavePathConfig, ""))
+ {
+ // If we are not using a savegame path (probably because we are on
+ // Windows and not using a config dir), behave like Vanilla Hexen
+ // and use hexndata/:
+
+ SavePath = malloc(10);
+ M_snprintf(SavePath, 10, "hexndata%c", DIR_SEPARATOR);
+ }
+ else
+ {
+ SavePath = M_StringDuplicate(SavePathConfig);
+ }
}
+
+ // only set hexen.cfg path if using default handling
+
+ if (!M_ParmExists("-savedir") && !M_ParmExists("-cdrom"))
+ {
+ SavePathConfig = SavePath;
+ }
}
// The Mac version of the Hexen IWAD is different to the "normal" DOS
@@ -374,14 +391,14 @@
M_SetConfigDir(NULL);
}
- D_SetDefaultSavePath();
M_SetConfigFilenames("hexen.cfg", PROGRAM_PREFIX "hexen.cfg");
M_LoadDefaults();
+ D_SetDefaultSavePath();
+
I_AtExit(M_SaveDefaults, false);
-
- // Now that the savedir is loaded from .CFG, make sure it exists
+ // Now that the savedir is loaded, make sure it exists
CreateSavePath();
ST_Message("Z_Init: Init zone memory allocation daemon.\n");
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -2172,11 +2172,41 @@
{
char *savegamedir;
char *topdir;
+ int p;
+ //!
+ // @arg <directory>
+ //
+ // Specify a path from which to load and save games. If the directory
+ // does not exist then it will automatically be created.
+ //
+
+ p = M_CheckParmWithArgs("-savedir", 1);
+ if (p)
+ {
+ savegamedir = myargv[p + 1];
+ if (!M_FileExists(savegamedir))
+ {
+ M_MakeDirectory(savegamedir);
+ }
+
+ // add separator at end just in case
+ savegamedir = M_StringJoin(savegamedir, DIR_SEPARATOR_S, NULL);
+
+ printf("Save directory changed to %s.\n", savegamedir);
+ }
+#ifdef _WIN32
+ // In -cdrom mode, we write savegames to a specific directory
+ // in addition to configs.
+
+ else if (M_ParmExists("-cdrom"))
+ {
+ savegamedir = configdir;
+ }
+#endif
// If not "doing" a configuration directory (Windows), don't "do"
// a savegame directory, either.
-
- if (!strcmp(configdir, ""))
+ else if (!strcmp(configdir, ""))
{
savegamedir = M_StringDuplicate("");
}