foxygit / doom Log in
commit 97f0be5d839ae5ec5b4c4d28dcf850f7afe08555
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Fri May 8 19:15:25 2009 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Fri May 8 19:15:25 2009 +0000

    Choose appropriate executable depending on game type.

    Subversion-branch: /branches/raven-branch
    Subversion-revision: 1514
---
 src/setup/execute.c | 17 ++---------------
 src/setup/mode.c    | 40 ++++++++++++++++++++++++++++++++++++----
 src/setup/mode.h    |  1 +
 3 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/src/setup/execute.c b/src/setup/execute.c
index 9846cd20..a43c3220 100644
--- a/src/setup/execute.c
+++ b/src/setup/execute.c
@@ -39,23 +39,10 @@

 #include "config.h"
 #include "execute.h"
+#include "mode.h"
 #include "m_argv.h"
 #include "m_config.h"

-#ifdef _WIN32
-#define DOOM_BINARY PACKAGE_TARNAME ".exe"
-#else
-#define DOOM_BINARY INSTALL_DIR "/" PACKAGE_TARNAME
-#endif
-
-#ifdef _WIN32
-#define DIR_SEPARATOR '\\'
-#define PATH_SEPARATOR ';'
-#else
-#define DIR_SEPARATOR '/'
-#define PATH_SEPARATOR ':'
-#endif
-
 struct execute_context_s
 {
     char *response_file;
@@ -196,7 +183,7 @@ int ExecuteDoom(execute_context_t *context)
     response_file_arg = malloc(strlen(context->response_file) + 2);
     sprintf(response_file_arg, "@%s", context->response_file);

-    argv[0] = DOOM_BINARY;
+    argv[0] = GetExecutableName();
     argv[1] = response_file_arg;
     argv[2] = NULL;

diff --git a/src/setup/mode.c b/src/setup/mode.c
index d5a396ac..9426e10a 100644
--- a/src/setup/mode.c
+++ b/src/setup/mode.c
@@ -19,8 +19,11 @@
 // 02111-1307, USA.
 //

+#include <stdlib.h>
 #include <string.h>

+#include "doomtype.h"
+
 #include "config.h"
 #include "textscreen.h"

@@ -52,6 +55,7 @@ typedef struct
     char *name;
     char *config_file;
     char *extra_config_file;
+    char *executable;
 } mission_config_t;

 // Default mission to fall back on, if no IWADs are found at all:
@@ -66,7 +70,8 @@ static mission_config_t mission_configs[] =
         IWAD_MASK_DOOM,
         "doom",
         "default.cfg",
-        PROGRAM_PREFIX "doom.cfg"
+        PROGRAM_PREFIX "doom.cfg",
+        PROGRAM_PREFIX "doom"
     },
     {
         "Heretic",
@@ -74,7 +79,8 @@ static mission_config_t mission_configs[] =
         IWAD_MASK_HERETIC,
         "heretic",
         "heretic.cfg",
-        PROGRAM_PREFIX "heretic.cfg"
+        PROGRAM_PREFIX "heretic.cfg",
+        PROGRAM_PREFIX "heretic"
     },
     {
         "Hexen",
@@ -82,7 +88,8 @@ static mission_config_t mission_configs[] =
         IWAD_MASK_HEXEN,
         "hexen",
         "hexen.cfg",
-        PROGRAM_PREFIX "hexen.cfg"
+        PROGRAM_PREFIX "hexen.cfg",
+        PROGRAM_PREFIX "hexen"
     }
 };

@@ -94,6 +101,7 @@ static int showMessages = 1;
 static int screenblocks = 9;
 static int detailLevel = 0;
 static char *savedir = NULL;
+static char *executable = NULL;

 static void BindMiscVariables(void)
 {
@@ -144,9 +152,28 @@ void InitBindings(void)
     BindMultiplayerVariables();
 }

+// Set the name of the executable program to run the game:
+
+static void SetExecutable(mission_config_t *config)
+{
+    free(executable);
+
+#ifdef _WIN32
+    executable = malloc(strlen(config->executable) + 5);
+    sprintf(executable, "%s.exe", config->executable);
+#else
+    executable = malloc(strlen(INSTALL_DIR) + strlen(config->executable) + 2);
+    sprintf(executable, "%s%c%s", INSTALL_DIR, DIR_SEPARATOR,
+                                  config->executable);
+#endif
+
+puts(executable);
+}
+
 static void SetMission(mission_config_t *config)
 {
     gamemission = config->mission;
+    SetExecutable(config);
     M_SetConfigFilenames(config->config_file, config->extra_config_file);
 }

@@ -175,7 +202,7 @@ static void GameSelected(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(config))

 static void OpenGameSelectDialog(GameSelectCallback callback)
 {
-    mission_config_t *mission;
+    mission_config_t *mission = NULL;
     txt_window_t *window;
     iwad_t **iwads;
     int num_games;
@@ -267,3 +294,8 @@ void SetupMission(GameSelectCallback callback)
     }
 }

+char *GetExecutableName(void)
+{
+    return executable;
+}
+
diff --git a/src/setup/mode.h b/src/setup/mode.h
index a78a5bc2..1abd7d38 100644
--- a/src/setup/mode.h
+++ b/src/setup/mode.h
@@ -29,6 +29,7 @@ extern GameMission_t gamemission;

 void SetupMission(GameSelectCallback callback);
 void InitBindings(void);
+char *GetExecutableName(void);

 #endif /* #ifndef SETUP_MODE_H */