aboutsummaryrefslogtreecommitdiff
path: root/src/modules/gamepath.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-12-20 13:08:59 +0100
committerGitHub <noreply@github.com>2024-12-20 13:08:59 +0100
commit8fddf38701f50015ee8f61ce7bc8978f1dcebfd3 (patch)
treea94eb7a0a5b1e469839a6a14400e15be2b61c5b2 /src/modules/gamepath.js
parent14c12f9bf74f7ae7e9b4b873e67b8e9769cdad1e (diff)
parent4ae37f2f520c8082a00cc52f33ea0c1877709d6f (diff)
downloadViper-8fddf38701f50015ee8f61ce7bc8978f1dcebfd3.tar.gz
Viper-8fddf38701f50015ee8f61ce7bc8978f1dcebfd3.zip
Merge pull request #249 from Jan200101/PR/handle-permission-error
feat: handle unzip errors
Diffstat (limited to 'src/modules/gamepath.js')
-rw-r--r--src/modules/gamepath.js16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/modules/gamepath.js b/src/modules/gamepath.js
index 5a5f922..65676a4 100644
--- a/src/modules/gamepath.js
+++ b/src/modules/gamepath.js
@@ -45,18 +45,20 @@ 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");
})
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");
}
@@ -80,17 +82,21 @@ 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, ".viper_test");
+ fs.writeFileSync(test_file_path, "");
+ fs.unlinkSync(test_file_path);
+
return true;
} catch (err) {
return false;
@@ -163,6 +169,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;