Bump version, adjust current license in package.json, add error handling and use built-in checksum computation library
This commit is contained in:
parent
4134f25d39
commit
b3e33c7d75
55
index.js
55
index.js
@ -2,7 +2,7 @@ const fs = require("node:fs");
|
|||||||
const https = require("node:https");
|
const https = require("node:https");
|
||||||
const path = require("node:path");
|
const path = require("node:path");
|
||||||
const child_process = require("node:child_process");
|
const child_process = require("node:child_process");
|
||||||
const checksum = require("checksum");
|
const crypto = require("node:crypto");
|
||||||
|
|
||||||
const manifestURL = "https://cdn.plutonium.pw/updater/prod/info.json";
|
const manifestURL = "https://cdn.plutonium.pw/updater/prod/info.json";
|
||||||
|
|
||||||
@ -66,7 +66,24 @@ function httpsDownload(url, filePath) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkFiles(manifest) {
|
function getFileSHA1(filePath) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
var fileStream = fs.createReadStream(filePath);
|
||||||
|
|
||||||
|
var hash = crypto.createHash("sha1");
|
||||||
|
hash.setEncoding("hex");
|
||||||
|
|
||||||
|
fileStream.on("end", function () {
|
||||||
|
hash.end();
|
||||||
|
|
||||||
|
resolve(hash.read());
|
||||||
|
});
|
||||||
|
|
||||||
|
fileStream.pipe(hash);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkFiles(manifest) {
|
||||||
var filesToDownload = [];
|
var filesToDownload = [];
|
||||||
|
|
||||||
for (var f = 0; f < manifest.files.length; f++) {
|
for (var f = 0; f < manifest.files.length; f++) {
|
||||||
@ -79,9 +96,7 @@ function checkFiles(manifest) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sum = checksum(filePath, {
|
var sum = await getFileSHA1(filePath);
|
||||||
"algorithm": "sha1"
|
|
||||||
});
|
|
||||||
|
|
||||||
if (sum !== file.hash) {
|
if (sum !== file.hash) {
|
||||||
console.log("File " + file.name + " needs to be downloaded again. ");
|
console.log("File " + file.name + " needs to be downloaded again. ");
|
||||||
@ -125,14 +140,28 @@ httpsGet(manifestURL).then(async function (response) {
|
|||||||
try {
|
try {
|
||||||
var data = JSON.parse(response.body);
|
var data = JSON.parse(response.body);
|
||||||
|
|
||||||
var wrongFiles = checkFiles(data);
|
checkFiles(data).then(function (wrongFiles) {
|
||||||
if (wrongFiles.length > 0) {
|
if (wrongFiles.length > 0) {
|
||||||
console.log("We have " + wrongFiles.length + " files to download");
|
console.log("We have " + wrongFiles.length + " files to download. ");
|
||||||
await downloadFiles(data.baseUrl, wrongFiles);
|
downloadFiles(data.baseUrl, wrongFiles).then(function () {
|
||||||
}
|
launchLauncher().then(function () {
|
||||||
|
|
||||||
await launchLauncher();
|
}).catch(function (error) {
|
||||||
} catch (error) {
|
console.error("An error has occurred while opening the launcher. \n" + error.stack);
|
||||||
console.error(error);
|
});
|
||||||
}
|
|
||||||
|
}).catch(function (error) {
|
||||||
|
console.error("An error has occurred while downloading a file. \n" + error.stack);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("All files seem good ! ");
|
||||||
|
}
|
||||||
|
}).catch(function (error) {
|
||||||
|
console.error("An error has occurred while checking the files. \n" + error.stack);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("An error has occurred while decoding the main manifest. \n" + error.stack);
|
||||||
|
}
|
||||||
|
}).catch(function (error) {
|
||||||
|
console.error("An error has occurred while getting the main manifest. \n" + error.stack);
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
|
||||||
"checksum": "^1.0.0"
|
|
||||||
},
|
|
||||||
"name": "open-plutonium-updater",
|
"name": "open-plutonium-updater",
|
||||||
"version": "0.0.1",
|
"version": "0.2.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "X3F200C",
|
"author": "X3F200C",
|
||||||
"license": "MIT",
|
"license": "GPL-3.0"
|
||||||
"private": true
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user