First functionally-working commit, UI to be implemented
This commit is contained in:
parent
e8568d8590
commit
30f05ab934
42
src/main.js
42
src/main.js
@ -238,7 +238,7 @@ function getPlutoniumSession(game, token) {
|
||||
|
||||
userInfo = data;
|
||||
|
||||
mainWindow.loadFile(path.join(__dirname, "src", "views", "games.html"));
|
||||
mainWindow.loadFile(path.join(__dirname, "views", "games.html"));
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
@ -254,14 +254,14 @@ function getPlutoniumSession(game, token) {
|
||||
});
|
||||
}
|
||||
|
||||
function launch(plutoniumInstallDirectory, game, gameInstallDirectory, online) {
|
||||
function launch(plutoniumInstallDir, game, gameInstallDirectory, online) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
getPlutoniumSession(game, userInfo.token).then(function (data) {
|
||||
if (!data.successful) {
|
||||
return reject(new Error("Authentication has failed."));
|
||||
}
|
||||
|
||||
let bootstrapperBinary = path.join(plutoniumInstallDirectory, "bin", "plutonium-bootstrapper-win32.exe");
|
||||
let bootstrapperBinary = path.join(plutoniumInstallDir, "bin", "plutonium-bootstrapper-win32.exe");
|
||||
let bootstrapperArguments = [game, gameInstallDirectory];
|
||||
|
||||
if (online) {
|
||||
@ -273,8 +273,9 @@ function launch(plutoniumInstallDirectory, game, gameInstallDirectory, online) {
|
||||
bootstrapperArguments.push("-lan");
|
||||
}
|
||||
|
||||
fsPromises.chmod(bootstrapperBinary, 0o755).then(function () {
|
||||
let gameProcess = child_process.spawn(bootstrapperBinary, bootstrapperArguments, {
|
||||
"cwd": plutoniumInstallDirectory,
|
||||
"cwd": plutoniumInstallDir,
|
||||
"detached": true,
|
||||
"stdio": "ignore"
|
||||
});
|
||||
@ -285,6 +286,9 @@ function launch(plutoniumInstallDirectory, game, gameInstallDirectory, online) {
|
||||
gameProcess.on("error", function (error) {
|
||||
reject(error);
|
||||
});
|
||||
}).catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -312,7 +316,7 @@ electron.app.once("ready", function () {
|
||||
});
|
||||
}
|
||||
|
||||
mainWindow.loadFile(path.join(__dirname, "src", "views", "games.html"));
|
||||
mainWindow.loadFile(path.join(__dirname, "views", "games.html"));
|
||||
});
|
||||
}
|
||||
}).catch(function (error) {
|
||||
@ -379,7 +383,7 @@ electron.ipcMain.handle("login", function (event, username, password) {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
mainWindow.loadFile(path.join(__dirname, "src", "views", "games.html"));
|
||||
mainWindow.loadFile(path.join(__dirname, "views", "games.html"));
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
@ -397,10 +401,32 @@ electron.ipcMain.handle("login", function (event, username, password) {
|
||||
|
||||
electron.ipcMain.handle("launch", function (event, game, online = true) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (!(game in config["game-directories"])) {
|
||||
let gameConfig;
|
||||
switch (game) {
|
||||
case "iw5mp":
|
||||
case "iw5sp":
|
||||
gameConfig = "iw5";
|
||||
break;
|
||||
case "t4mp":
|
||||
case "t4sp":
|
||||
gameConfig = "t4";
|
||||
break;
|
||||
case "t5mp":
|
||||
case "t5sp":
|
||||
gameConfig = "t5";
|
||||
break;
|
||||
case "t6mp":
|
||||
case "t6zm":
|
||||
gameConfig = "t6";
|
||||
break;
|
||||
default:
|
||||
return reject(new Error("Unknown game : " + game));
|
||||
}
|
||||
|
||||
if (!(gameConfig in config["game-directories"])) {
|
||||
return resolve(false);
|
||||
}
|
||||
let gameInstallDirectory = config["game-directories"][game];
|
||||
let gameInstallDirectory = config["game-directories"][gameConfig];
|
||||
|
||||
update.checkFiles(plutoniumManifest, plutoniumInstallDirectory).then(function (fileList) {
|
||||
let filesToUpdate = fileList.filter(function (file) {
|
||||
|
@ -3,3 +3,7 @@ const electron = require("electron");
|
||||
electron.contextBridge.exposeInMainWorld("login", function (username, password) {
|
||||
return electron.ipcRenderer.invoke("login", username, password);
|
||||
});
|
||||
|
||||
electron.contextBridge.exposeInMainWorld("launch", function (game, online) {
|
||||
return electron.ipcRenderer.invoke("launch", game, online);
|
||||
});
|
||||
|
@ -3,6 +3,9 @@ const fs = require("node:fs");
|
||||
const crypto = require("node:crypto");
|
||||
const https = require("node:https");
|
||||
|
||||
let runningDownloads = 0;
|
||||
let downloadQueue = [];
|
||||
|
||||
function checkFileAgainstSHA1(baseDirectory, fileEntry) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let filePath = path.join(baseDirectory, fileEntry.name);
|
||||
@ -19,6 +22,11 @@ function checkFileAgainstSHA1(baseDirectory, fileEntry) {
|
||||
|
||||
let fileInputStream = fs.createReadStream(filePath);
|
||||
|
||||
fileInputStream.on("error", function (error) {
|
||||
fileInputStream.close();
|
||||
reject(error);
|
||||
});
|
||||
|
||||
hash.on("readable", function () {
|
||||
let data = hash.read();
|
||||
if (data) {
|
||||
@ -35,6 +43,12 @@ function checkFileAgainstSHA1(baseDirectory, fileEntry) {
|
||||
|
||||
function downloadFile(url, filePath) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let dirPath = path.dirname(filePath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, {
|
||||
"recursive": true
|
||||
});
|
||||
}
|
||||
let fileOutputStream = fs.createWriteStream(filePath);
|
||||
|
||||
let request = https.request(url, {
|
||||
@ -42,7 +56,7 @@ function downloadFile(url, filePath) {
|
||||
}, function (response) {
|
||||
if (response.statusCode !== 200) return reject(new Error("Got a non-OK response while trying to download a file."));
|
||||
|
||||
fileOutputStream.on("end", function () {
|
||||
fileOutputStream.on("close", function () {
|
||||
resolve(true);
|
||||
});
|
||||
|
||||
@ -59,17 +73,18 @@ function downloadFile(url, filePath) {
|
||||
|
||||
function processDownloadQueue(baseDirectory, baseURL, fileEntries) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let runningDownloads = 0;
|
||||
let queue = [...fileEntries];
|
||||
queue = [...fileEntries];
|
||||
|
||||
let finishCallback = function () {
|
||||
runningDownloads--;
|
||||
|
||||
if (queue.length > 0 && runningDownloads < module.exports.concurrentDownloads) {
|
||||
let currentEntry = queue.shift();
|
||||
let currentEntry = queue.shift().entry;
|
||||
|
||||
downloadFile(baseURL + currentEntry.hash, path.join(baseDirectory, currentEntry.name)).then(finishCallback).catch((errorCallback).bind(currentEntry));
|
||||
} else {
|
||||
}
|
||||
|
||||
if (queue.length < 1 && runningDownloads < 1) {
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
@ -83,13 +98,20 @@ function processDownloadQueue(baseDirectory, baseURL, fileEntries) {
|
||||
if (this.retries > 3) return reject(error);
|
||||
|
||||
this.retries++;
|
||||
queue.push(this);
|
||||
queue.push({
|
||||
"entry": this,
|
||||
"ok": false
|
||||
});
|
||||
};
|
||||
|
||||
if (fileEntries.length < 1) {
|
||||
return resolve();
|
||||
}
|
||||
|
||||
for (let d = 0; d < module.exports.concurrentDownloads; d++) {
|
||||
if (queue.length < 1) break;
|
||||
|
||||
let currentEntry = queue.shift();
|
||||
let currentEntry = queue.shift().entry;
|
||||
|
||||
runningDownloads++;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user