From 5ae62ca65db09112f608892e595334e50b8cd4f7 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sun, 4 Aug 2024 23:45:15 +0200 Subject: feat: add error handler for streaming unzip --- src/modules/update.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/update.js b/src/modules/update.js index c001ba8..c792217 100644 --- a/src/modules/update.js +++ b/src/modules/update.js @@ -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; -- cgit v1.2.3 From 8fc85282633a622866f3e6e38140084a17dee38f Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Mon, 5 Aug 2024 19:33:38 +0200 Subject: feat: test gamepath permissions by creating a file --- src/modules/gamepath.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/modules') diff --git a/src/modules/gamepath.js b/src/modules/gamepath.js index 5a5f922..0209d1b 100644 --- a/src/modules/gamepath.js +++ b/src/modules/gamepath.js @@ -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; -- cgit v1.2.3 From 83cc8a62ca9773bdf194175f6e6c6b80a7795f90 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Mon, 5 Aug 2024 19:54:38 +0200 Subject: chore: set default folder argument --- src/modules/gamepath.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/src/modules/gamepath.js b/src/modules/gamepath.js index 0209d1b..1e1153e 100644 --- a/src/modules/gamepath.js +++ b/src/modules/gamepath.js @@ -80,18 +80,18 @@ gamepath.exists = (folder) => { // returns false if the user doesn't have read/write permissions to the // selected gamepath, if no gamepath is set, then this will always // return `false`, handle that correctly! -gamepath.has_perms = (folder) => { +gamepath.has_perms = (folder = settings().gamepath) => { if (! gamepath.exists(folder)) { return false; } try { fs.accessSync( - folder || settings().gamepath, + folder, fs.constants.R_OK | fs.constants.W_OK ) - let test_file_path = path.join(folder || settings().gamepath, ".viper_test"); + let test_file_path = path.join(folder, ".viper_test"); fs.writeFileSync(test_file_path, ""); fs.unlinkSync(test_file_path); -- cgit v1.2.3 From 94714507d6132518a498ee373cfae77153aa3221 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sat, 10 Aug 2024 10:18:30 +0200 Subject: chore: prevent gamepath permission alert from reopening on same gamepath Co-authored-by: 0neGal --- src/modules/gamepath.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/gamepath.js b/src/modules/gamepath.js index 1e1153e..db669c1 100644 --- a/src/modules/gamepath.js +++ b/src/modules/gamepath.js @@ -55,8 +55,8 @@ ipcMain.on("missing-perms", async (e, selected_gamepath) => { }) ipcMain.on("gamepath-lost-perms", async (e, selected_gamepath) => { - if (! gamepath.setting) { - gamepath.setting = true; + if (! gamepath.setting && gamepath.lost_perms != selected_gamepath) { + gamepath.lost_perms = selected_gamepath; await win().alert(lang("gui.gamepath.lost_perms") + selected_gamepath); ipcMain.emit("setpath"); } @@ -167,6 +167,8 @@ gamepath.set = async (win, force_dialog) => { return gamepath.setting = false; } + delete gamepath.lost_perms; + if (! fs.existsSync(path.join(res.filePaths[0], "Titanfall2.exe"))) { ipcMain.emit("wrong-path"); return gamepath.setting = false; -- cgit v1.2.3 From 7f90d57abc197930ef4e4bfd65b83fdc5934d1d5 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Mon, 5 Aug 2024 20:50:55 +0200 Subject: fix: prevent multiple missing-perms routines from starting --- src/modules/gamepath.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/modules') diff --git a/src/modules/gamepath.js b/src/modules/gamepath.js index db669c1..65676a4 100644 --- a/src/modules/gamepath.js +++ b/src/modules/gamepath.js @@ -45,11 +45,13 @@ ipcMain.on("wrong-path", () => { }) ipcMain.on("found-missing-perms", async (e, selected_gamepath) => { + gamepath.setting = true; await win().alert(lang("gui.gamepath.found_missing_perms") + selected_gamepath); ipcMain.emit("setpath", null, false, true); }) ipcMain.on("missing-perms", async (e, selected_gamepath) => { + gamepath.setting = true; await win().alert(lang("gui.gamepath.missing_perms") + selected_gamepath); ipcMain.emit("setpath"); }) -- cgit v1.2.3 From 846b7c915e96402da4c3b12e1d02276b4f158634 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sat, 10 Aug 2024 19:58:44 +0200 Subject: revert some localization changes --- src/lang/en.json | 3 +-- src/modules/update.js | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) (limited to 'src/modules') diff --git a/src/lang/en.json b/src/lang/en.json index e95d890..bf147ab 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -276,8 +276,7 @@ "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", - "permission_denied": "Unable to extract Northstar to your game directory" + "missing_flatpak_steam": "Can't launch with the Flatpak version of Steam, as it doesn't seem to be installed" } } }, diff --git a/src/modules/update.js b/src/modules/update.js index c792217..7469e02 100644 --- a/src/modules/update.js +++ b/src/modules/update.js @@ -415,10 +415,6 @@ update.northstar = async (force_install) => { 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"), -- cgit v1.2.3