Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle unzip errors #249

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/app/js/toasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ toasts.dismiss = (id) => {
}

ipcRenderer.on("toast", (_, properties) => {
Toast(properties);
toasts.show(properties);
})

module.exports = toasts;
32 changes: 30 additions & 2 deletions src/app/js/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ ipcRenderer.on("ns-update-event", (event, options) => {
.innerText = `(${lang(key)})`;
}

let delay, now;

switch(key) {
case "cli.update.uptodate_short":
case "cli.update.no_internet":
// initial value
let delay = 0;
delay = 0;

// get current time
let now = new Date().getTime();
now = new Date().getTime();

// check if `update.ns.last_checked` was less than 500ms
// since now, this variable is set when `update.ns()` is
Expand All @@ -73,6 +75,32 @@ ipcRenderer.on("ns-update-event", (event, options) => {
}, delay)

break;
case "cli.update.failed":
// initial value
delay = 0;

// get current time
now = new Date().getTime();

// check if `update.ns.last_checked` was less than 500ms
// since now, this variable is set when `update.ns()` is
// called
if (now - update.ns.last_checked < 500) {
// if less than 500ms has passed, set `delay` to the
// amount of milliseconds missing until we've hit that
// 500ms threshold
delay = 500 - (now - update.ns.last_checked);
}

// Request version number
// this will also handle the play button label for us
ipcRenderer.send("get-version");

setTimeout(() => {
update_btn();
set_buttons(true);
update.ns.progress(false);
}, delay)
default:
update_btn();

Expand Down
4 changes: 3 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"checking": "Checking for updates...",
"download_done": "Download done! Extracting...",
"finished": "Installation/Update finished!",
"failed": "Installation/Update failed!",
"uptodate": "Latest version (%s) is already installed, skipping update.",
"uptodate_short": "Up-to-date",
"no_internet": "No Internet connection"
Expand Down Expand Up @@ -275,7 +276,8 @@
"missing_launch_command": "There's currently no custom launch command set, one has to be configured to launch",
"missing_steam": "Can't launch with Steam directly, as it doesn't seem to be installed",
"missing_flatpak": "Can't launch with Flatpak, as it doesn't seem to be installed",
"missing_flatpak_steam": "Can't launch with the Flatpak version of Steam, as it doesn't seem to be installed"
"missing_flatpak_steam": "Can't launch with the Flatpak version of Steam, as it doesn't seem to be installed",
"permission_denied": "Unable to extract Northstar to your game directory"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/modules/gamepath.js
Jan200101 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ gamepath.has_perms = (folder) => {
fs.constants.R_OK | fs.constants.W_OK
)

let test_file_path = path.join(folder || settings().gamepath, ".viper_test");
fs.writeFileSync(test_file_path, "");
fs.unlinkSync(test_file_path);

return true;
} catch (err) {
return false;
Expand Down
29 changes: 28 additions & 1 deletion src/modules/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,36 @@ update.northstar = async (force_install) => {

console.ok(lang("cli.update.download_done"));

let destination = unzip.Extract({path: settings().gamepath});

// If we receive multiple errors of the same type we ignore them
let received_errors = [];
destination.on("error", (err) => {
if (received_errors.indexOf(err.code) >= 0)
return;

received_errors.push(err.code);
extract.close();
update.northstar.updating = false;

let description = lang("gui.toast.desc.unknown_error") + " (" + err.code + ")";

if (err.code == "EACCES") {
description = lang("gui.toast.desc.permission_denied");
}

win().toast({
scheme: "error",
title: lang("gui.toast.title.failed"),
description: description
})

win().send("ns-update-event", "cli.update.failed");
})

// extracts the zip, this is the part where we're actually
// installing Northstar.
extract.pipe(unzip.Extract({path: settings().gamepath}))
extract.pipe(destination)

let extracted = 0;
let size = received;
Expand Down