Make file hash checker

This commit is contained in:
X3F200C 2024-11-09 01:27:47 -05:00
parent a1aa7e67e4
commit 60d6e4c0eb
2 changed files with 49 additions and 0 deletions

View File

@ -29,6 +29,14 @@ let plutoniumManifest = {
"baseUrl": "https://cdn.plutonium.pw/updater/prod/files/", "baseUrl": "https://cdn.plutonium.pw/updater/prod/files/",
"files": [] "files": []
}; };
let userInfo = {
"token": "V3ryS3cr3t4uth3nt1c4t10nT0k3n",
"userId": -1,
"username": "AnonGuest",
"email": "guest@neverla.nd",
"emailVerified": false,
"avatar": "https://forum.plutonium.pw/assets/uploads/system/avatar-default.png"
};
function createMainWindow() { function createMainWindow() {
mainWindow = new electron.BrowserWindow({ mainWindow = new electron.BrowserWindow({
@ -142,6 +150,8 @@ electron.ipcMain.handle("login", function (event, username, password) {
...data ...data
}); });
userInfo = data;
mainWindow.loadFile(path.join(__dirname, "src", "views", "games.html")); mainWindow.loadFile(path.join(__dirname, "src", "views", "games.html"));
} catch (error) { } catch (error) {
reject(error); reject(error);

39
src/update.js Normal file
View File

@ -0,0 +1,39 @@
const path = require("node:path");
const fs = require("node:fs");
const crypto = require("node:crypto");
function checkFileAgainstSHA1(baseDirectory, fileEntry) {
return new Promise(function (resolve, reject) {
let filePath = path.join(baseDirectory, fileEntry.name);
if (!fs.existsSync(filePath)) {
return resolve({
"entry": fileEntry,
"ok": false
});
}
let hash = crypto.createHash("sha1");
hash.setEncoding("hex");
let fileInputStream = fs.createReadStream(filePath);
hash.on("readable", function () {
let data = hash.read();
if (data) {
resolve({
"entry": fileEntry,
"ok": data == fileEntry.hash
});
}
});
fileInputStream.pipe(hash);
});
}
module.exports = {
"checkFiles": function (manifest) {
}
};