shithub: choc

Download patch

ref: 005b2ccbc37e080e3651fbdac896cf28098bc920
parent: dc4eb0ba8d0bac8059c060b5965db13f5c86dd12
author: Thomas A. Birkel <capnclever@gmail.com>
date: Wed Nov 30 14:27:48 EST 2016

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

--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1614,6 +1614,31 @@
     // 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"))
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -1068,6 +1068,31 @@
 
     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"))
--- 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
 
@@ -377,11 +378,32 @@
     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.
+    //
 
-    // Now that the savedir is loaded from .CFG, make sure it exists
+    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, make sure it exists
     CreateSavePath();
 
     ST_Message("Z_Init: Init zone memory allocation daemon.\n");
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -1658,7 +1658,33 @@
     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.