3 Commits

Author SHA1 Message Date
mmvanheusden
2bd8dc7c41 2.0.1 2022-07-09 09:30:23 +02:00
mmvanheusden
b8eb915788 Add a hacky fix for Windows portable builds
Signed-off-by: mmvanheusden <50550545+mmvanheusden@users.noreply.github.com>
2022-07-09 09:26:40 +02:00
mmvanheusden
5c0fe6fc9a fix badge 2022-07-08 22:05:54 +02:00
5 changed files with 47 additions and 20 deletions

View File

@@ -5,7 +5,7 @@
<img alt="GitHub all releases" src="https://img.shields.io/github/downloads/mmvanheusden/SteamDepotDownloaderGUI/total?color=orange&label=downloads">
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/mmvanheusden/SteamDepotDownloaderGUI?color=crimson">
<img alt="Visitor Count" src="https://visitor-badge.glitch.me/badge?page_id=mmvanheusden.SteamDepotDownloaderGUI">
<a href="https://www.codefactor.io/repository/github/mmvanheusden/steamdepotdownloadergui/overview/rewrite"><img src="https://www.codefactor.io/repository/github/mmvanheusden/steamdepotdownloadergui/badge/rewrite" alt="CodeFactor" /></a>
<a href="https://www.codefactor.io/repository/github/mmvanheusden/steamdepotdownloadergui/overview/rewrite"><img src="https://www.codefactor.io/repository/github/mmvanheusden/steamdepotdownloadergui/badge/master" alt="CodeFactor" /></a>
</p>
<p align="center">
<img alt="Screenshot" src="screenshot.png" />
@@ -34,4 +34,4 @@ Pull requests are welcome. For major changes, please open an issue first to disc
Please make sure to keep code consistent and cross-platform compatible.
![License](license.png)
![License](license.png)

View File

@@ -1,4 +1,13 @@
const {checkDotnet, download, createCommand, runCommand, removeDir, removeFile, unzip} = require("./utils")
const {
checkDotnet,
download,
createCommand,
runCommand,
removeDir,
removeFile,
unzip,
platformpath
} = require("./utils")
function submitForm() {
checkDotnet().then(async function (result) {
@@ -9,16 +18,16 @@ function submitForm() {
console.info("dotnet found in PATH")
// Remove the old depotdownloader directory
await removeDir("depotdownloader")
await removeDir("depotdownloader", platformpath())
// 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.6/depotdownloader-2.4.6.zip")
await download("https://github.com/SteamRE/DepotDownloader/releases/download/DepotDownloader_2.4.6/depotdownloader-2.4.6.zip", platformpath())
// Unzip the DepotDownloader binary
await unzip("depotdownloader-2.4.6.zip", "depotdownloader")
await unzip("depotdownloader-2.4.6.zip", "depotdownloader", platformpath())
// Clean up the old files
await removeFile("depotdownloader-2.4.6.zip")
await removeFile("depotdownloader-2.4.6.zip", platformpath())
// Run the final command
await runCommand(createCommand().toString())

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "steamdepotdownloadergui",
"version": "2.0.0",
"version": "2.0.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "steamdepotdownloadergui",
"version": "2.0.0",
"version": "2.0.1",
"license": "WTFPL",
"dependencies": {
"follow-redirects": "^1.15.1"

View File

@@ -1,6 +1,6 @@
{
"name": "steamdepotdownloadergui",
"version": "2.0.0",
"version": "2.0.1",
"description": "DepotDownloader Electron frontend",
"main": "main.js",
"scripts": {

View File

@@ -2,6 +2,8 @@
* 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) => {
if (process.platform.toString().includes("win")) {
@@ -32,13 +34,16 @@ function checkDotnet() {
/**
* Download a file from a url, saving it to the current directory (__dirname)
* @param url The url to download from
* @param targetPath The path to save the file to
* @returns {Promise<unknown>} A promise that resolves when the download is finished
*/
function download(url) {
function download(url, targetPath) {
return new Promise((resolve) => {
const {https} = require("follow-redirects")
const fs = require("fs")
const file = fs.createWriteStream(url.split("/").pop().toString())
const path = require("path")
console.log(path.sep)
const file = fs.createWriteStream(targetPath + path.sep + url.split("/").pop())
https.get(url, function (response) {
response.pipe(file)
file.on("finish", function () {
@@ -52,12 +57,14 @@ function download(url) {
/**
* Removes a file from the current directory
* @param file The filename to remove
* @param targetPath The directory the file is located in
* @returns {Promise<unknown>} A promise that resolves when the file is removed (or fails)
*/
function removeFile(file) {
function removeFile(file, targetPath) {
return new Promise((resolve) => {
const fs = require("fs")
fs.unlink(file, function (err) {
const path = require("path")
fs.unlink(targetPath + path.sep + file, function (err) {
if (err) {
console.error(err)
}
@@ -69,12 +76,14 @@ function removeFile(file) {
/**
* Removes a directory from the current directory
* @param dir The directory to remove
* @param targetPath The directory the directory is located in
* @returns {Promise<unknown>} A promise that resolves when the directory is removed (or fails)
*/
function removeDir(dir) {
function removeDir(dir, targetPath) {
return new Promise((resolve) => {
const fs = require("fs")
fs.rm(dir, {recursive: true, force: true}, function (err) {
const path = require("path")
fs.rm(targetPath + path.sep + dir, {recursive: true, force: true}, function (err) {
if (err) {
console.error(err)
}
@@ -87,13 +96,15 @@ function removeDir(dir) {
* Unzip a file to the current directory
* @param file The file to unzip, preferably a .zip file
* @param target The target directory to unzip to
* @param targetPath The directory the file AND the unzip dir is located in
* @returns {Promise<unknown>} A promise that resolves when the unzip is complete (or fails)
*/
function unzip(file, target) {
function unzip(file, target, targetPath) {
const {exec} = require("child_process")
const path = require("path")
return new Promise((resolve) => {
if (process.platform.toString().includes("win")) {
const command = "powershell.exe -Command Expand-Archive -Path " + __dirname + "/" + file + " -Destination " + target
const command = "powershell.exe -Command Expand-Archive -Path " + targetPath + path.sep + file + " -Destination " + targetPath + path.sep + target
exec(command, function (error, stdout, stderr) {
if (error) {
console.error("Unzipping failed with error: " + error)
@@ -138,7 +149,7 @@ const createCommand = () => {
if (osdropdown.options[osdropdown.selectedIndex].text.includes("Gnome")) {
return `gnome-terminal -e 'bash -c "dotnet ./depotdownloader/DepotDownloader.dll -username ${username} -password ${password} -app ${appid} -depot ${depotid} -manifest ${manifestid} -dir ./games/${appid}/ -max-servers 50 -max-downloads 16";bash'`
} else if (osdropdown.options[osdropdown.selectedIndex].text.includes("Windows")) {
return `start cmd.exe /k dotnet ./depotdownloader/DepotDownloader.dll -username ${username} -password ${password} -app ${appid} -depot ${depotid} -manifest ${manifestid} -dir ./games/${appid}/ -max-servers 50 -max-downloads 16`
return `start cmd.exe /k dotnet ${platformpath()}/depotdownloader/DepotDownloader.dll -username ${username} -password ${password} -app ${appid} -depot ${depotid} -manifest ${manifestid} -dir ${platformpath()}/games/${appid}/ -max-servers 50 -max-downloads 16`
} else if (osdropdown.options[osdropdown.selectedIndex].text.includes("macOS")) {
return `osascript -c 'tell application "Terminal" to do script 'dotnet ./depotdownloader/DepotDownloader.dll -username ${username} -password ${password} -app ${appid} -depot ${depotid} -manifest ${manifestid} -dir ./games/${appid}/ -max-servers 50 -max-downloads 16'`
} else if (osdropdown.options[osdropdown.selectedIndex].text.includes("Konsole")) {
@@ -173,4 +184,11 @@ function runCommand(command) {
})
}
module.exports = {checkDotnet, download, createCommand, runCommand, removeDir, removeFile, unzip}
const platformpath = () => {
if (__dirname.includes("AppData") && process.platform.toString().includes("win")) {
return process.env.PORTABLE_EXECUTABLE_DIR
} else
return __dirname
}
module.exports = {checkDotnet, download, createCommand, runCommand, removeDir, removeFile, unzip, platformpath}