From a8985a64fd1e4060cbc6b8136216d19ff2ae23d9 Mon Sep 17 00:00:00 2001 From: MasterIO02 <40836390+MasterIO02@users.noreply.github.com> Date: Wed, 26 Jul 2023 18:53:46 +0200 Subject: [PATCH] Fix client auto updater It was using the wrong unzipping library, now we can just use the wget-improved and AdmZip local wrappers --- files/clientUpdater.js | 39 ++++++++------------------------------- files/util.js | 3 +-- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/files/clientUpdater.js b/files/clientUpdater.js index ffb4f1a..26c6461 100644 --- a/files/clientUpdater.js +++ b/files/clientUpdater.js @@ -1,36 +1,13 @@ const path = require("path") -const wget = require("wget-improved") -const fs = require("fs") -const unzipper = require("unzipper") -const { exit } = require("./util") +const { exit, asyncDownload, asyncExtract } = require("./util") module.exports = async () => { - var link = `https://dl.issou.best/ordr/client-latest.zip` - const output = path.resolve("files/client-latest.zip") + let link = `https://dl.issou.best/ordr/client-latest.zip` + const outputZip = path.resolve("files/client-latest.zip") - let download = wget.download(link, output) - download.on("error", async err => { - console.log(err) - await exit() - }) - download.on("start", fileSize => { - console.log(`Downloading the client update at ${link}, ${fileSize} bytes to download...`) - }) - download.on("end", async () => { - try { - fs.createReadStream(output) - .pipe( - unzipper.Extract({ - path: `.` - }) - ) - .on("close", async () => { - console.log(`Finished updating the client. You can now restart it.`) - await exit() - }) - } catch (err) { - console.log("An error occured while unpacking: " + err) - await exit() - } - }) + await asyncDownload(link, outputZip, "client-latest", "file") + await asyncExtract(outputZip, ".", "client-latest", "file") + + console.log("Finished updating the client. You can now restart it.") + await exit() } diff --git a/files/util.js b/files/util.js index 45fc1b3..967df6b 100644 --- a/files/util.js +++ b/files/util.js @@ -1,7 +1,6 @@ const wget = require("wget-improved") const AdmZip = require("adm-zip") const fs = require("fs") -const readline = require("readline") exports.exit = async () => { process.stdin.setRawMode(true) @@ -47,7 +46,7 @@ exports.asyncExtract = async (input, output, filename, type) => { if (filename !== "librespeed") console.log(`Finished unpacking ${type} ${filename}.`) resolve() } catch (err) { - console.log("An error occured while unpacking the skin: " + err) + console.log(`An error occured while unpacking ${type}`, err) ;async () => { this.exit() }