aboutsummaryrefslogtreecommitdiff
path: root/src/utils.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-01-22 22:19:16 +0100
committer0neGal <mail@0negal.com>2022-01-22 22:19:16 +0100
commit6a785c3a4c41bb7128508c34a1a2af5df12b9f8e (patch)
treedd12f4c614e62fd9c67ace179467801c163671b5 /src/utils.js
parentb1b7d260a1a333618c045d3c43b7af5573c274a3 (diff)
downloadViper-6a785c3a4c41bb7128508c34a1a2af5df12b9f8e.tar.gz
Viper-6a785c3a4c41bb7128508c34a1a2af5df12b9f8e.zip
implement #52 into #51
Diffstat (limited to 'src/utils.js')
-rw-r--r--src/utils.js36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/utils.js b/src/utils.js
index 521931d..50ad240 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -116,14 +116,33 @@ northstar_auto_updates: {
//
// If running with CLI it takes in the --setpath argument otherwise it
// open the systems file browser for the user to select a path.
-function setpath(win) {
+async function setpath(win) {
if (! win) { // CLI
settings.gamepath = cli.param("setpath");
} else { // GUI
+ function setGamepath(folder) {
+ settings.gamepath = folder + "/steamapps/common/Titanfall2/";
+ settings.zip = path.join(settings.gamepath + "/northstar.zip");
+ saveSettings();
+ win.webContents.send("newpath", settings.gamepath);
+ ipcMain.emit("newpath", null, settings.gamepath);
+ }
+
// Autodetect path
// Windows only using powershell and windows registery
// Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2\
- if (process.platform == "win32") {/* TODO */}
+ if (process.platform == "linux") {
+ try {
+ let {stdout} = await exec("Get-Item -Path Registry::HKEY_LOCAL_MACHINE\\SOFTWARE\\Respawn\\Titanfall2\\", {"shell":"powershell.exe"});
+ let originPath = stdout.split('\n')
+ .filter(r => r.indexOf("Install Dir") !== -1)[0]
+ .replace(/\s+/g,' ')
+ .trim()
+ .replace("Install Dir : ","");
+ setGamepath(originPath)
+ return
+ } catch (err) {}
+ }
// Detect using Steam VDF
function readvdf(data) {
@@ -137,16 +156,11 @@ function setpath(win) {
if (fs.existsSync(data_array[0] + "/steamapps/common/Titanfall2/Titanfall2.exe")) {
// Found the location
- settings.gamepath = data_array[0] + "/steamapps/common/Titanfall2/";
- settings.zip = path.join(settings.gamepath + "/northstar.zip");
- saveSettings();
- win.webContents.send("newpath", settings.gamepath);
- ipcMain.emit("newpath", null, settings.gamepath);
+ setGamepath(data_array[0] + "/steamapps/common/Titanfall2")
saveSettings();
cli.exit();
- // Return 1 if success
- return 1;
+ return true;
}
}
}
@@ -155,13 +169,13 @@ function setpath(win) {
case "win32":
if (fs.existsSync("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf")) {
let data = fs.readFileSync("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf")
- if (readvdf(data.toString()) == 1) {return}
+ if (readvdf(data.toString())) {return}
}
break;
case "linux":
if (fs.existsSync(path.join(app.getPath("home"), "/.steam/steam/steamapps/libraryfolders.vdf"))) {
let data = fs.readFileSync(os.homedir() + "/.steam/steam/steamapps/libraryfolders.vdf")
- if (readvdf(data.toString()) == 1) {return}
+ if (readvdf(data.toString())) {return}
}
break;
}