foxygit / doom Log in
commit ae1aeffdfe96a0ee9ea8f8b11914a79e1a0e0b15
Author:     Mike Swanson <mikeonthecomputer@gmail.com>
AuthorDate: Sat Aug 29 00:58:10 2015 -0700
Commit:     Mike Swanson <mikeonthecomputer@gmail.com>
CommitDate: Sat Aug 29 00:58:10 2015 -0700

    Search GOG.com installation directories for IWADs

    The game is sold on GOG.com now for the Windows platform.  This should
    add support for finding the IWADs installed through it.

    I've repurposed the Collector's Edition functions for this, the basic
    principle for finding the directories is the same between the two, and
    it keeps the code duplication low.

    resolves #600
---
 src/d_iwad.c | 81 +++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 58 insertions(+), 23 deletions(-)

diff --git a/src/d_iwad.c b/src/d_iwad.c
index 3777bab6..5f938c79 100644
--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -142,22 +142,53 @@ static registry_value_t uninstall_values[] =
     },
 };

-// Value installed by the Collector's Edition when it is installed
+// Values installed by the GOG.com and Collector's Edition versions

-static registry_value_t collectors_edition_value =
+static registry_value_t gogcom_collectors_edition_values[] =
 {
-    HKEY_LOCAL_MACHINE,
-    SOFTWARE_KEY "\\Activision\\DOOM Collector's Edition\\v1.0",
-    "INSTALLPATH",
+    // Doom Collector's Edition
+
+    {
+        HKEY_LOCAL_MACHINE,
+        SOFTWARE_KEY "\\Activision\\DOOM Collector's Edition\\v1.0",
+        "INSTALLPATH",
+    },
+
+    // Ultimate Doom
+
+    {
+        HKEY_LOCAL_MACHINE,
+        SOFTWARE_KEY "\\GOG.com\\Games\\1435827232",
+        "PATH",
+    },
+
+    // Doom II
+
+    {
+        HKEY_LOCAL_MACHINE,
+        SOFTWARE_KEY "\\GOG.com\\Games\\1435848814",
+        "PATH",
+    },
+
+    // Final Doom
+
+    {
+        HKEY_LOCAL_MACHINE,
+        SOFTWARE_KEY "\\GOG.com\\Games\\1435848742",
+        "PATH",
+    },
 };

 // Subdirectories of the above install path, where IWADs are installed.

-static char *collectors_edition_subdirs[] =
+static char *gogcom_collectors_edition_subdirs[] =
 {
+    ".",
     "Doom2",
     "Final Doom",
     "Ultimate Doom",
+    "TNT",
+    "Plutonia",
 };

 // Location where Steam is installed
@@ -268,30 +299,34 @@ static void CheckUninstallStrings(void)
     }
 }

-// Check for Doom: Collector's Edition
+// Check for GOG.com and Doom: Collector's Edition

-static void CheckCollectorsEdition(void)
+static void CheckGOGcomCollectorsEdition(void)
 {
-    char *install_path;
-    char *subpath;
     unsigned int i;

-    install_path = GetRegistryString(&collectors_edition_value);
-
-    if (install_path == NULL)
+    for (i=0; i<arrlen(gogcom_collectors_edition_values); ++i)
     {
-        return;
-    }
+        char *install_path;
+        char *subpath;
+        unsigned int j;

-    for (i=0; i<arrlen(collectors_edition_subdirs); ++i)
-    {
-        subpath = M_StringJoin(install_path, DIR_SEPARATOR_S,
-                               collectors_edition_subdirs[i], NULL);
+        install_path = GetRegistryString(&gogcom_collectors_edition_values[i]);

-        AddIWADDir(subpath);
-    }
+        if (install_path == NULL)
+        {
+            continue;
+        }

-    free(install_path);
+        for (j=0; j<arrlen(gogcom_collectors_edition_subdirs); ++j)
+        {
+            subpath = M_StringJoin(install_path, DIR_SEPARATOR_S,
+                                   gogcom_collectors_edition_subdirs[j], NULL);
+            AddIWADDir(subpath);
+        }
+
+        free(install_path);
+    }
 }


@@ -635,7 +670,7 @@ static void BuildIWADDirList(void)
     // Search the registry and find where IWADs have been installed.

     CheckUninstallStrings();
-    CheckCollectorsEdition();
+    CheckGOGcomCollectorsEdition();
     CheckSteamEdition();
     CheckDOSDefaults();