/* * Vencord, a modification for Discord's desktop app * Copyright (c) 2023 Vendicated and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import "./checkNodeVersion.js"; import { execFileSync, execSync } from "child_process"; import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, cpSync, rmSync } from "fs"; import { dirname, join } from "path"; import { Readable } from "stream"; import { finished } from "stream/promises"; import { fileURLToPath } from "url"; const BASE_URL = "https://github.com/Equicord/Equilotl/releases/latest/download/"; const BASE_DIR = join(dirname(fileURLToPath(import.meta.url)), ".."); const FILE_DIR = join(BASE_DIR, "dist", "Installer"); const ETAG_FILE = join(FILE_DIR, "etag.txt"); function getFilename() { switch (process.platform) { case "win32": return "EquilotlCli.exe"; case "darwin": switch (process.arch) { case "x64": return "EquilotlCli-x64"; case "arm64": return "EquilotlCli-arm64"; default: return "EquilotlCli-universal"; } case "linux": return "EquilotlCli-linux"; default: throw new Error("Unsupported platform: " + process.platform); } } async function ensureBinary() { const filename = getFilename(); console.log("Downloading " + filename); mkdirSync(FILE_DIR, { recursive: true }); const outputFile = join(FILE_DIR, filename); const etag = existsSync(outputFile) && existsSync(ETAG_FILE) ? readFileSync(ETAG_FILE, "utf-8") : null; const res = await fetch(BASE_URL + filename, { headers: { "User-Agent": "Equicord (https://github.com/Equicord/Equicord)", "If-None-Match": etag } }); if (res.status === 304) { console.log("Up to date, not redownloading!"); return outputFile; } if (!res.ok) throw new Error(`Failed to download installer: ${res.status} ${res.statusText}`); writeFileSync(ETAG_FILE, res.headers.get("etag")); const body = Readable.fromWeb(res.body); await finished(body.pipe(createWriteStream(outputFile, { mode: 0o755, autoClose: true }))); console.log("Finished downloading!"); return outputFile; } const installerBin = await ensureBinary(); console.log("Now running Installer..."); const argStart = process.argv.indexOf("--"); const args = argStart === -1 ? [] : process.argv.slice(argStart + 1); try { execFileSync(installerBin, args, { stdio: "inherit", env: { ...process.env, EQUICORD_USER_DATA_DIR: BASE_DIR, EQUICORD_DIRECTORY: join(BASE_DIR, "dist/desktop"), EQUICORD_DEV_INSTALL: "1" } }); } catch { console.error("Something went wrong. Please check the logs above."); }