shithub: choc

Download patch

ref: 309a199f761549c53219e88a1040948a1b9a71f9
parent: 69cd2345e29316f8bfb247b2f1f97c4076b47d27
author: Simon Howard <[email protected]>
date: Mon Aug 6 21:19:49 EDT 2007

Autodetect IWADs installed by Steam.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 945

--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -140,6 +140,24 @@
     "Ultimate Doom",
 };
 
+// Location where Steam is installed
+
+static registry_value_t steam_install_location =
+{
+    HKEY_LOCAL_MACHINE,
+    "Software\\Valve\\Steam",
+    "InstallPath",
+};
+
+// Subdirs of the steam install directory where IWADs are found
+
+static char *steam_install_subdirs[] =
+{
+    "steamapps\\common\\doom 2",
+    "steamapps\\common\\ultimate doom",
+    "steamapps\\common\\final doom\\base",
+};
+
 static char *GetRegistryString(registry_value_t *reg_val)
 {
     HKEY key;
@@ -251,6 +269,41 @@
     free(install_path);
 }
 
+
+// Check for Doom downloaded via Steam
+
+static void CheckSteamEdition(void)
+{
+    char *install_path;
+    char *subpath;
+    int i;
+
+    install_path = GetRegistryString(&steam_install_location);
+
+    if (install_path == NULL)
+    {
+        return;
+    }
+
+    for (i=0; i<arrlen(steam_install_subdirs); ++i)
+    {
+        subpath = malloc(strlen(install_path) 
+                         + strlen(steam_install_subdirs[i]) + 5);
+
+        sprintf(subpath, "%s%s", install_path, steam_install_subdirs[i]);
+
+        if (M_FileExists(subpath))
+        {
+            AddIWADDir(subpath);
+        }
+        else
+        {
+            free(subpath);
+        }
+    }
+}
+
+
 #endif
 
 static struct 
@@ -417,6 +470,7 @@
 
     CheckUninstallStrings();
     CheckCollectorsEdition();
+    CheckSteamEdition();
 
 #else