switched to ipc through localhost

This commit is contained in:
FinnHornhoover 2023-10-18 13:01:25 +03:00
parent 48efd00a4a
commit 600b33a230
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 path = remote.require("path");
var dialog = remote.require("dialog");
var net = remote.require("net");
var spawn = require("child_process").spawn;
var userData = remote.require("app").getPath("userData");
@ -340,8 +341,25 @@ function handleCache(mode, versionString, cacheMode, callback) {
"http://cdn.dexlabs.systems/ff/big" :
path.dirname(versions[0].url);
var executable = path.join(__dirname, "lib", "cache_handler.exe");
var args = [
var lastSizes = {};
storageLoadingStart(versionString, cacheMode);
var server = net.createServer(function (sock) {
sock.setEncoding("utf8");
sock.on("data", function (data) {
data.split("\n").forEach(function (sizeString) {
if (sizeString === "") return;
lastSizes = JSON.parse(sizeString);
storageLoadingUpdate(lastSizes);
});
});
});
server.listen(0, "localhost", function () {
spawn(path.join(__dirname, "lib", "cache_handler.exe"), [
"--mode", (mode === "fix") ? "download" : mode,
"--hash-file", hashPath,
"--playable-root", cacheRoot,
@ -349,30 +367,22 @@ function handleCache(mode, versionString, cacheMode, callback) {
"--user-dir", userData,
"--cdn-root", cdnRoot,
"--cache-mode", (cacheMode) ? cacheMode : "all",
"--cache-version", (versionString) ? versionString : "all"
];
storageLoadingStart(versionString, cacheMode);
var child = spawn(executable, args, { stdio: [null, null, null, "ipc"] });
var lastSizes = {};
child.on("message", function (sizes) {
lastSizes = sizes;
storageLoadingUpdate(lastSizes);
});
child.on("exit", function (code, signal) {
"--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);
});
});
}
function loadCacheList() {

BIN
lib/cache_handler.exe Normal file → Executable file

Binary file not shown.