From 4558e4bc25393b7e9015d12e66bcb4a92998bc88 Mon Sep 17 00:00:00 2001 From: mmvanheusden <50550545+mmvanheusden@users.noreply.github.com> Date: Wed, 5 Oct 2022 08:43:41 +0200 Subject: [PATCH] Rewrite the pre download check and add a empty fields check Signed-off-by: mmvanheusden <50550545+mmvanheusden@users.noreply.github.com> --- downloader.js | 56 ++++++++++++++++++++++++++++++--------------------- index.html | 15 +++++++++++--- utils.js | 27 +++++++++++++++++++------ 3 files changed, 66 insertions(+), 32 deletions(-) diff --git a/downloader.js b/downloader.js index 2d0a1241..3e1b9d3b 100644 --- a/downloader.js +++ b/downloader.js @@ -1,5 +1,5 @@ const { - checkDotnet, + preDownloadCheck, download, createCommand, runCommand, @@ -9,28 +9,35 @@ const { } = require("./utils") function submitForm() { - checkDotnet().then(async function (result) { - if (!result) { - console.error("dotnet not found in PATH") + // Check if the form is filled in and if dotnet is installed + preDownloadCheck().then(async function () { + document.getElementById("dotnetwarning").hidden = true + document.getElementById("emptywarning").hidden = true + console.info("dotnet found in PATH") + + // Remove the old depotdownloader directory + await removeDir("depotdownloader") + + // Download the DepotDownloader binary, so it doesn't have to be included in the source code + await download("https://github.com/SteamRE/DepotDownloader/releases/download/DepotDownloader_2.4.7/depotdownloader-2.4.7.zip") + + // Unzip the DepotDownloader binary + await unzip("depotdownloader-2.4.7.zip", "depotdownloader") + + // Clean up the old files + await removeFile("depotdownloader-2.4.7.zip") + + // Run the final command + await runCommand(createCommand()) + }).catch(function (error) { + if (error === "noDotnet") { + console.error("Dotnet not found in PATH") + document.getElementById("emptywarning").hidden = true document.getElementById("dotnetwarning").hidden = false - } else { - - console.info("dotnet found in PATH") - - // Remove the old depotdownloader directory - await removeDir("depotdownloader") - - // Download the DepotDownloader binary, so it doesn't have to be included in the source code - await download("https://github.com/SteamRE/DepotDownloader/releases/download/DepotDownloader_2.4.7/depotdownloader-2.4.7.zip") - - // Unzip the DepotDownloader binary - await unzip("depotdownloader-2.4.7.zip", "depotdownloader") - - // Clean up the old files - await removeFile("depotdownloader-2.4.7.zip") - - // Run the final command - await runCommand(createCommand().toString()) + } else if (error === "emptyField") { + console.error("Fill in all the fields") + document.getElementById("dotnetwarning").hidden = true + document.getElementById("emptywarning").hidden = false } }) } @@ -66,8 +73,11 @@ function openSteamDB() { void electron.shell.openExternal("https://steamdb.info/instantsearch/") } +/* Everything below this line runs when the page is loaded */ + +// Add event listeners to the buttons window.addEventListener("DOMContentLoaded", () => { - document.getElementById("alertbtn").addEventListener("click", submitDotnet) + document.getElementById("dotnetalertbtn").addEventListener("click", submitDotnet) document.getElementById("downloadbtn").addEventListener("click", submitForm) document.getElementById("smbtn1").addEventListener("click", openGitHubIssues) document.getElementById("smbtn2").addEventListener("click", openSteamDB) diff --git a/index.html b/index.html index 300df102..57022575 100644 --- a/index.html +++ b/index.html @@ -4,20 +4,20 @@ - + SteamDepotDownloaderGUI