mirror of
https://github.com/mmvanheusden/SteamDepotDownloaderGUI.git
synced 2026-02-04 05:31:19 +01:00
Merge pull request #31 from mmvanheusden/predownloadcheck
Rewrite the pre download check and add a empty fields check
This commit is contained in:
@@ -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)
|
||||
|
||||
15
index.html
15
index.html
@@ -4,20 +4,20 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta content="width=device-width, initial-scale=1" name="viewport"/>
|
||||
<link href="https://unpkg.com/@primer/css@20.4.5/dist/primer.css" rel="stylesheet"/>
|
||||
<link href="https://unpkg.com/@primer/css@20.4.6/dist/primer.css" rel="stylesheet"/>
|
||||
<title>SteamDepotDownloaderGUI</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="downloader.js"></script>
|
||||
<div class="mx-auto">
|
||||
<div hidden id="dotnetwarning">
|
||||
<div class="flash flash-error mx-2 mt-2 color-shadow-medium" id="alert">
|
||||
<div class="flash flash-error mx-2 mt-2 color-shadow-medium" id="dotnetalert">
|
||||
<svg class="octicon" height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM0 8a8 8 0 1116 0A8 8 0 010 8zm6.5-.25A.75.75 0 017.25 7h1a.75.75 0 01.75.75v2.75h.25a.75.75 0 010 1.5h-2a.75.75 0 010-1.5h.25v-2h-.25a.75.75 0 01-.75-.75zM8 6a1 1 0 100-2 1 1 0 000 2z"
|
||||
fill-rule="evenodd"></path>
|
||||
</svg>
|
||||
<code><span class="text-italic">dotnet</span></code> was not found.
|
||||
<button class="btn btn-sm flash-action" id="alertbtn">
|
||||
<button class="btn btn-sm flash-action" id="dotnetalertbtn">
|
||||
<svg class="octicon" height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M7.47 10.78a.75.75 0 001.06 0l3.75-3.75a.75.75 0 00-1.06-1.06L8.75 8.44V1.75a.75.75 0 00-1.5
|
||||
0v6.69L4.78 5.97a.75.75 0 00-1.06 1.06l3.75 3.75zM3.75 13a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5z"
|
||||
@@ -27,6 +27,15 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div hidden id="emptywarning">
|
||||
<div class="flash flash-warn mx-2 mt-2 color-shadow-medium" id="emptyalert">
|
||||
<svg class="octicon" height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM0 8a8 8 0 1116 0A8 8 0 010 8zm6.5-.25A.75.75 0 017.25 7h1a.75.75 0 01.75.75v2.75h.25a.75.75 0 010 1.5h-2a.75.75 0 010-1.5h.25v-2h-.25a.75.75 0 01-.75-.75zM8 6a1 1 0 100-2 1 1 0 000 2z"
|
||||
fill-rule="evenodd"></path>
|
||||
</svg>Please fill in all fields.
|
||||
</div>
|
||||
</div>
|
||||
<div class="f0-light text-center">Steam Depot Downloader</div>
|
||||
|
||||
<form id="theform">
|
||||
|
||||
27
utils.js
27
utils.js
@@ -2,30 +2,45 @@
|
||||
* Checks if dotnet is installed in the system path
|
||||
* @returns {Promise<unknown>} A promise that resolves to true if dotnet is installed, false otherwise
|
||||
*/
|
||||
function checkDotnet() {
|
||||
return new Promise((resolve) => {
|
||||
function preDownloadCheck() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let username = document.forms["theform"]["username"].value
|
||||
let password = document.forms["theform"]["password"].value
|
||||
let appid = document.forms["theform"]["appid"].value
|
||||
let depotid = document.forms["theform"]["depotid"].value
|
||||
let manifestid = document.forms["theform"]["manifestid"].value
|
||||
|
||||
// Check if all fields are filled
|
||||
if (username === "" || password === "" || appid === "" || depotid === "" || manifestid === "") {
|
||||
// Reject before even checking if dotnet is installed
|
||||
reject("emptyField")
|
||||
return
|
||||
}
|
||||
|
||||
// Check if dotnet is installed, depending on the platform
|
||||
if (process.platform.toString().includes("win")) {
|
||||
// Windows
|
||||
const {exec} = require("child_process")
|
||||
const command = "dotnet.exe --version"
|
||||
exec(command, function (error) {
|
||||
if (error) {
|
||||
resolve(false)
|
||||
reject("noDotnet")
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// Linux
|
||||
const {exec} = require("child_process")
|
||||
const command = "dotnet --version"
|
||||
exec(command, function (error) {
|
||||
if (error) {
|
||||
resolve(false)
|
||||
reject("noDotnet")
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -193,4 +208,4 @@ const platformpath = () => {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {checkDotnet, download, createCommand, runCommand, removeDir, removeFile, unzip, platformpath}
|
||||
module.exports = {preDownloadCheck, download, createCommand, runCommand, removeDir, removeFile, unzip, platformpath}
|
||||
Reference in New Issue
Block a user