foxygit / doom Log in
commit f0c5cc898d993d3388dfbce5833e8ccca7b2f03f
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sun Mar 8 23:46:09 2009 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Mar 8 23:46:09 2009 +0000

    Fix -cdrom command line parameter to work with Heretic and Hexen;
    compiles now work on Windows.

    Subversion-branch: /branches/raven-branch
    Subversion-revision: 1452
---
 src/doom/d_main.c    | 24 ++++++++++++++++-
 src/heretic/d_main.c | 39 +++++++++++++++++++--------
 src/hexen/h2_main.c  | 28 +++++++++++++++++---
 src/m_config.c       | 74 +++++++++++++++++++++++++++-------------------------
 src/m_config.h       |  2 +-
 src/setup/mainmenu.c |  2 +-
 6 files changed, 116 insertions(+), 53 deletions(-)

diff --git a/src/doom/d_main.c b/src/doom/d_main.c
index 0bda5cbf..daa62209 100644
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1187,7 +1187,29 @@ void D_DoomMain (void)

     // find which dir to use for config files

-    M_SetConfigDir();
+#ifdef _WIN32
+
+    //!
+    // @platform windows
+    // @vanilla
+    //
+    // Save configuration data and savegames in c:\doomdata,
+    // allowing play from CD.
+    //
+
+    if (M_CheckParm("-cdrom") > 0)
+    {
+        printf(D_CDROM);
+
+        M_SetConfigDir("c:\\doomdata\\");
+    }
+    else
+#endif
+    {
+        // Auto-detect the configuration dir.
+
+        M_SetConfigDir(NULL);
+    }

     //!
     // @arg <x>
diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c
index 9e4558c1..273b3f26 100644
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -812,16 +812,6 @@ void D_DoomMain(void)
     startmap = 1;
     autostart = false;

-    // Check for -CDROM
-    cdrom = false;
-#ifdef __WATCOMC__
-    if (M_CheckParm("-cdrom"))
-    {
-        cdrom = true;
-        mkdir("c:\\heretic.cd");
-    }
-#endif
-
 //
 // get skill / episode / map from parms
 //
@@ -859,7 +849,34 @@ void D_DoomMain(void)
     printf("V_Init: allocate screens.\n");
     V_Init();

-    M_SetConfigDir();
+    // Check for -CDROM
+
+    cdrom = false;
+
+#ifdef _WIN32
+
+    //!
+    // @platform windows
+    // @vanilla
+    //
+    // Save configuration data and savegames in c:\heretic.cd,
+    // allowing play from CD.
+    //
+
+    if (M_CheckParm("-cdrom"))
+    {
+        cdrom = true;
+    }
+#endif
+
+    if (cdrom)
+    {
+        M_SetConfigDir("c:\\heretic.cd\\");
+    }
+    else
+    {
+        M_SetConfigDir(NULL);
+    }

     // Load defaults before initing other systems
     printf("M_LoadDefaults: Load system defaults.\n");
diff --git a/src/hexen/h2_main.c b/src/hexen/h2_main.c
index 166c3064..042128db 100644
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -116,7 +116,7 @@ boolean respawnparm;            // checkparm of -respawn
 boolean randomclass;            // checkparm of -randclass
 boolean debugmode;              // checkparm of -debug
 boolean ravpic;                 // checkparm of -ravpic
-boolean cdrom;                  // true if cd-rom mode active
+boolean cdrom = false;          // true if cd-rom mode active
 boolean cmdfrag;                // true if a CMD_FRAG packet should be sent out
 boolean singletics;             // debug flag to cancel adaptiveness
 boolean artiskip;               // whether shift-enter skips an artifact
@@ -246,7 +246,29 @@ void D_DoomMain(void)
     // Load defaults before initing other systems
     ST_Message("M_LoadDefaults: Load system defaults.\n");
     D_BindVariables();
-    M_SetConfigDir();
+
+#ifdef _WIN32
+
+    //!
+    // @platform windows
+    // @vanilla
+    //
+    // Save configuration data and savegames in c:\hexndata,
+    // allowing play from CD.
+    //
+
+    cdrom = M_ParmExists("-cdrom");
+#endif
+
+    if (cdrom)
+    {
+        M_SetConfigDir("c:\\hexndata\\");
+    }
+    else
+    {
+        M_SetConfigDir(NULL);
+    }
+
     D_SetDefaultSavePath();
     M_SetConfigFilenames("hexen.cfg", PROGRAM_PREFIX "hexen.cfg");
     M_LoadDefaults();
@@ -399,7 +421,7 @@ static void HandleArgs(void)
     artiskip = M_ParmExists("-artiskip");
     debugmode = M_ParmExists("-debug");
     deathmatch = M_ParmExists("-deathmatch");
-    cdrom = M_ParmExists("-cdrom");
+
     cmdfrag = M_ParmExists("-cmdfrag");

     // Process command line options
diff --git a/src/m_config.c b/src/m_config.c
index cfdf12a5..38ec8e00 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -1104,20 +1104,17 @@ void M_BindVariable(char *name, void *location)
     variable->bound = true;
 }

-//
-// SetConfigDir:
-//
-// Sets the location of the configuration directory, where configuration
-// files are stored - default.cfg, chocolate-doom.cfg, savegames, etc.
-//
+// Get the path to the default configuration dir to use, if NULL
+// is passed to M_SetConfigDir.

-void M_SetConfigDir(void)
+static char *GetDefaultConfigDir(void)
 {
 #ifndef _WIN32
-    // Ignore the HOME environment variable on Windows - just behave
-    // like Vanilla Doom.
+    // On Unix systems we put configuration into ~/.chocolate-doom, but
+    // on Windows we just use the current directory, like Vanilla.

     char *homedir;
+    char *result;

     homedir = getenv("HOME");

@@ -1126,39 +1123,44 @@ void M_SetConfigDir(void)
         // put all configuration in a config directory off the
         // homedir

-        configdir = malloc(strlen(homedir) + strlen(PACKAGE_TARNAME) + 5);
-
-        sprintf(configdir, "%s%c.%s%c", homedir, DIR_SEPARATOR,
-			                PACKAGE_TARNAME, DIR_SEPARATOR);
-
-        // make the directory if it doesnt already exist
+        result = malloc(strlen(homedir) + strlen(PACKAGE_TARNAME) + 5);

-        M_MakeDirectory(configdir);
+        sprintf(result, "%s%c.%s%c", homedir, DIR_SEPARATOR,
+                                     PACKAGE_TARNAME, DIR_SEPARATOR);
     }
     else
 #endif /* #ifndef _WIN32 */
     {
-#ifdef _WIN32
-        //!
-        // @platform windows
-        // @vanilla
-        //
-        // Save configuration data and savegames in c:\doomdata,
-        // allowing play from CD.
-        //
-
-        if (M_CheckParm("-cdrom") > 0)
-        {
-            printf(D_CDROM);
-            configdir = strdup("c:\\doomdata\\");
+        // On Windows, we just use the current directory.

-            M_MakeDirectory(configdir);
-        }
-        else
-#endif
-        {
-            configdir = strdup("");
-        }
+        return strdup("");
+    }
+}
+
+//
+// SetConfigDir:
+//
+// Sets the location of the configuration directory, where configuration
+// files are stored - default.cfg, chocolate-doom.cfg, savegames, etc.
+//
+
+void M_SetConfigDir(char *dir)
+{
+    // Use the directory that was passed, or find the default.
+
+    if (dir != NULL)
+    {
+        configdir = dir;
+    }
+    else
+    {
+        configdir = GetDefaultConfigDir();
     }
+
+    printf("Using %s for configuration and saves\n", configdir);
+
+    // Make the directory if it doesn't already exist:
+
+    M_MakeDirectory(configdir);
 }

diff --git a/src/m_config.h b/src/m_config.h
index 6f2bb894..ff772bea 100644
--- a/src/m_config.h
+++ b/src/m_config.h
@@ -31,7 +31,7 @@
 void M_LoadDefaults(void);
 void M_SaveDefaults(void);
 void M_SaveDefaultsAlternate(char *main, char *extra);
-void M_SetConfigDir(void);
+void M_SetConfigDir(char *dir);
 void M_BindVariable(char *name, void *variable);
 void M_SetConfigFilenames(char *main_config, char *extra_config);

diff --git a/src/setup/mainmenu.c b/src/setup/mainmenu.c
index 90bda7de..d7b8e676 100644
--- a/src/setup/mainmenu.c
+++ b/src/setup/mainmenu.c
@@ -178,7 +178,7 @@ static void InitConfig(void)
     SetChatMacroDefaults();
     SetPlayerNameDefault();

-    M_SetConfigDir();
+    M_SetConfigDir(NULL);
     M_LoadDefaults();
 }