switched to ipc through localhost

This commit is contained in:
FinnHornhoover 2023-10-18 13:01:25 +03:00
parent b2ba0ba1b6
commit 9ee982b53c
2 changed files with 36 additions and 26 deletions

View File

@ -3,6 +3,7 @@ var remotefs = remote.require("fs-extra");
var dns = remote.require("dns"); var dns = remote.require("dns");
var path = remote.require("path"); var path = remote.require("path");
var dialog = remote.require("dialog"); var dialog = remote.require("dialog");
var net = remote.require("net");
var spawn = require("child_process").spawn; var spawn = require("child_process").spawn;
var userData = remote.require("app").getPath("userData"); var userData = remote.require("app").getPath("userData");
@ -340,38 +341,47 @@ function handleCache(mode, versionString, cacheMode, callback) {
"http://cdn.dexlabs.systems/ff/big" : "http://cdn.dexlabs.systems/ff/big" :
path.dirname(versions[0].url); path.dirname(versions[0].url);
var executable = path.join(__dirname, "lib", "cache_handler.exe"); var lastSizes = {};
var args = [
"--mode", (mode === "fix") ? "download" : mode,
"--hash-file", hashPath,
"--playable-root", cacheRoot,
"--offline-root", offlineRoot,
"--user-dir", userData,
"--cdn-root", cdnRoot,
"--cache-mode", (cacheMode) ? cacheMode : "all",
"--cache-version", (versionString) ? versionString : "all"
];
storageLoadingStart(versionString, cacheMode); storageLoadingStart(versionString, cacheMode);
var child = spawn(executable, args, { stdio: [null, null, null, "ipc"] }); var server = net.createServer(function (sock) {
sock.setEncoding("utf8");
var lastSizes = {}; sock.on("data", function (data) {
child.on("message", function (sizes) { data.split("\n").forEach(function (sizeString) {
lastSizes = sizes; if (sizeString === "") return;
storageLoadingUpdate(lastSizes);
lastSizes = JSON.parse(sizeString);
storageLoadingUpdate(lastSizes);
});
});
}); });
child.on("exit", function (code, signal) { server.listen(0, "localhost", function () {
if (code !== 0 || signal) { spawn(path.join(__dirname, "lib", "cache_handler.exe"), [
dialog.showErrorBox( "--mode", (mode === "fix") ? "download" : mode,
"Sorry!", "--hash-file", hashPath,
"Process \"" + mode + "\" failed with code " + code + " and signal " + signal + "." "--playable-root", cacheRoot,
); "--offline-root", offlineRoot,
} "--user-dir", userData,
storageLoadingComplete(lastSizes); "--cdn-root", cdnRoot,
if (callback) "--cache-mode", (cacheMode) ? cacheMode : "all",
callback(lastSizes); "--cache-version", (versionString) ? versionString : "all",
"--port", server.address().port
]).on("exit", function (code, signal) {
if (code !== 0 || signal) {
dialog.showErrorBox(
"Sorry!",
"Process \"" + mode + "\" failed with code " + code + " and signal " + signal + "."
);
}
server.close();
storageLoadingComplete(lastSizes);
if (callback)
callback(lastSizes);
});
}); });
} }

BIN
lib/cache_handler.exe Normal file → Executable file

Binary file not shown.