foxygit / doom Log in
commit 005b2ccbc37e080e3651fbdac896cf28098bc920
Author:     Thomas A. Birkel <capnclever@gmail.com>
AuthorDate: Wed Nov 30 19:27:48 2016 -0500
Commit:     Thomas A. Birkel <capnclever@gmail.com>
CommitDate: Wed Nov 30 19:27:48 2016 -0500

    d_main.c: Add "-savedir" command line parameter

    Directory is created if it does not exist. Setting this parameter will not
    affect the "savedir" config variable in hexen.cfg.

    Fix for #792
---
 src/doom/d_main.c    | 25 +++++++++++++++++++++++++
 src/heretic/d_main.c | 25 +++++++++++++++++++++++++
 src/hexen/h2_main.c  | 26 ++++++++++++++++++++++++--
 src/strife/d_main.c  | 26 ++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/src/doom/d_main.c b/src/doom/d_main.c
index 4c669b18..b273fa71 100644
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1614,6 +1614,31 @@ void D_DoomMain (void)
     // we've finished loading Dehacked patches.
     D_SetGameDescription();

+    //!
+    // @arg <directory>
+    //
+    // Specify a path from which to load and save games. If the directory
+    // does not exist then it will automatically be created.
+    // NOTE TO WINDOWS USERS: Do not end a path with a backslash ("\") if it
+    // requires quote-wrapping (e.g., "C:\pa th\") as this will be
+    // misinterpreted by the command line.
+    //
+
+    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);
+    }
+    else
 #ifdef _WIN32
     // In -cdrom mode, we write savegames to c:\doomdata as well as configs.
     if (M_ParmExists("-cdrom"))
diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c
index b63a2489..7a7ae746 100644
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -1068,6 +1068,31 @@ void D_DoomMain(void)

     savegamedir = M_GetSaveGameDir("heretic.wad");

+    //!
+    // @arg <directory>
+    //
+    // Specify a path from which to load and save games. If the directory
+    // does not exist then it will automatically be created.
+    // NOTE TO WINDOWS USERS: Do not end a path with a backslash ("\") if it
+    // requires quote-wrapping (e.g., "C:\pa th\") as this will be
+    // misinterpreted by the command line.
+    //
+
+    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);
+    }
+
     I_PrintStartupBanner(gamedescription);

     if (M_ParmExists("-testcontrols"))
diff --git a/src/hexen/h2_main.c b/src/hexen/h2_main.c
index ef6ea9e9..46a965ca 100644
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -120,6 +120,7 @@ static int WarpMap;
 static int demosequence;
 static int pagetic;
 static char *pagename;
+static char *SavePathConfig;

 // CODE --------------------------------------------------------------------

@@ -164,7 +165,7 @@ void D_BindVariables(void)
     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

@@ -377,11 +378,32 @@ void D_DoomMain(void)
     D_SetDefaultSavePath();
     M_SetConfigFilenames("hexen.cfg", PROGRAM_PREFIX "hexen.cfg");
     M_LoadDefaults();
+    SavePath = SavePathConfig;

     I_AtExit(M_SaveDefaults, false);

+    //!
+    // @arg <directory>
+    //
+    // Specify a path from which to load and save games. If the directory
+    // does not exist then it will automatically be created.
+    // NOTE TO WINDOWS USERS: Do not end a path with a backslash ("\") if it
+    // requires quote-wrapping (e.g., "C:\pa th\") as this will be
+    // misinterpreted by the command line.
+    //
+
+    p = M_CheckParmWithArgs("-savedir", 1);
+    if (p)
+    {
+        SavePath = myargv[p + 1];
+
+        // add separator at end just in case
+        SavePath = M_StringJoin(SavePath, DIR_SEPARATOR_S, NULL);
+
+        printf("Save directory changed to %s.\n", SavePath);
+    }

-    // 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");
diff --git a/src/strife/d_main.c b/src/strife/d_main.c
index 240cc064..fcfcd482 100644
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -1658,8 +1658,34 @@ void D_DoomMain (void)
     D_IdentifyVersion();
     InitGameVersion();
     D_SetGameDescription();
+
     savegamedir = M_GetSaveGameDir("strife1.wad");

+    //!
+    // @arg <directory>
+    //
+    // Specify a path from which to load and save games. If the directory
+    // does not exist then it will automatically be created.
+    // NOTE TO WINDOWS USERS: Do not end a path with a backslash ("\") if it
+    // requires quote-wrapping (e.g., "C:\pa th\") as this will be
+    // misinterpreted by the command line.
+    //
+
+    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);
+    }
+
     // fraggle 20130405: I_InitTimer is needed here for the netgame
     // startup. Start low-level sound init here too.
     I_InitTimer();