From 23d4cae1230bd60da2f0497ecac9d4a32a326f5b Mon Sep 17 00:00:00 2001
From: Ven <vendicated@riseup.net>
Date: Sat, 22 Oct 2022 02:36:49 +0200
Subject: [PATCH] Installer: add custom path option (#77)

---
 scripts/patcher/common.js | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/scripts/patcher/common.js b/scripts/patcher/common.js
index 840c842e..3217d5c7 100644
--- a/scripts/patcher/common.js
+++ b/scripts/patcher/common.js
@@ -95,13 +95,12 @@ async function getMenuItem(installations) {
         info,
     }));
 
-    if (menuItems.length === 0) {
-        console.log("No Discord installations found.");
-        process.exit(1);
-    }
-
     const result = await menu(
-        [...menuItems, { title: "Exit without patching", exit: true }],
+        [
+            ...menuItems,
+            { title: "Specify custom path", info: "custom" },
+            { title: "Exit without patching", exit: true }
+        ],
         {
             header: "Select a Discord installation to patch:",
             border: true,
@@ -116,6 +115,33 @@ async function getMenuItem(installations) {
         process.exit(0);
     }
 
+    if (result.info === "custom") {
+        const customPath = await question("Please enter the path: ");
+        if (!customPath || !fs.existsSync(customPath)) {
+            console.log("No such Path or not specifed.");
+            process.exit();
+        }
+
+        const resourceDir = path.join(customPath, "resources");
+        if (!fs.existsSync(path.join(resourceDir, "app.asar"))) {
+            console.log("Unsupported Install. resources/app.asar not found");
+            process.exit();
+        }
+
+        const appDir = path.join(resourceDir, "app");
+        result.info = {
+            branch: "unknown",
+            patched: fs.existsSync(appDir),
+            location: customPath,
+            versions: [{
+                path: appDir,
+                name: null
+            }],
+            arch: process.platform === "linux" ? "linux" : "win32",
+            isFlatpak: false,
+        };
+    }
+
     if (result.info.patched) {
         const answer = await question(
             "This installation has already been modified. Overwrite? [Y/n]: "