foxygit / doom Log in
commit 0083adaa40f4af7d44a3744ca315edb8d87c6bd8
Author:     Thomas A. Birkel <capnclever@gmail.com>
AuthorDate: Thu Dec 1 01:12:08 2016 -0500
Commit:     Thomas A. Birkel <capnclever@gmail.com>
CommitDate: Thu Dec 1 01:12:08 2016 -0500

    m_config.c: Merge "-savedir", "-cdrom" usage into M_GetSaveGameDir()

    Adding "-cdrom" logic to M_GetSaveGameDir() fixed vanilla behavior for
    non-Doom games. Hexen-specific logic involving hexen.cfg "savedir" was
    added to D_SetDefaultSavePath().
---
 src/doom/d_main.c    | 37 +-----------------------------------
 src/heretic/d_main.c | 25 -------------------------
 src/hexen/h2_main.c  | 53 ++++++++++++++++++++++++----------------------------
 src/m_config.c       | 34 +++++++++++++++++++++++++++++++--
 src/strife/d_main.c  | 26 --------------------------
 5 files changed, 57 insertions(+), 118 deletions(-)

diff --git a/src/doom/d_main.c b/src/doom/d_main.c
index b273fa71..b7270c8b 100644
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1614,42 +1614,7 @@ 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"))
-    {
-        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))
diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c
index 7a7ae746..b63a2489 100644
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -1068,31 +1068,6 @@ 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 46a965ca..dde561db 100644
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -184,14 +184,30 @@ static void D_SetDefaultSavePath(void)
 {
     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;
     }
 }

@@ -375,33 +391,12 @@ void D_DoomMain(void)
         M_SetConfigDir(NULL);
     }

-    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);
+    D_SetDefaultSavePath();

-        printf("Save directory changed to %s.\n", SavePath);
-    }
+    I_AtExit(M_SaveDefaults, false);

     // Now that the savedir is loaded, make sure it exists
     CreateSavePath();
diff --git a/src/m_config.c b/src/m_config.c
index 5619926e..cad39ebb 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -2172,11 +2172,41 @@ char *M_GetSaveGameDir(char *iwadname)
 {
     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("");
     }
diff --git a/src/strife/d_main.c b/src/strife/d_main.c
index fcfcd482..240cc064 100644
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -1658,34 +1658,8 @@ 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();