aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json17
-rw-r--r--package-lock.json11
-rw-r--r--package.json1
-rw-r--r--src/utils.js71
4 files changed, 97 insertions, 3 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..ef3f9b3
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,17 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Debug Main Process",
+ "type": "node",
+ "request": "launch",
+ "cwd": "${workspaceFolder}",
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
+ "windows": {
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
+ },
+ "args" : ["."],
+ "outputCapture": "std"
+ }
+ ]
+ } \ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index bfdbd43..2a396b9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -15,6 +15,7 @@
"fs-extra": "^10.0.0",
"marked": "^4.0.10",
"marked-man": "^0.7.0",
+ "simple-vdf": "^1.1.1",
"unzipper": "^0.10.11"
},
"devDependencies": {
@@ -2671,6 +2672,11 @@
"integrity": "sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==",
"dev": true
},
+ "node_modules/simple-vdf": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/simple-vdf/-/simple-vdf-1.1.1.tgz",
+ "integrity": "sha1-B+LE3sBs9hTtb0IRsYzOEjyT/Kk="
+ },
"node_modules/slice-ansi": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz",
@@ -5271,6 +5277,11 @@
"integrity": "sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==",
"dev": true
},
+ "simple-vdf": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/simple-vdf/-/simple-vdf-1.1.1.tgz",
+ "integrity": "sha1-B+LE3sBs9hTtb0IRsYzOEjyT/Kk="
+ },
"slice-ansi": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz",
diff --git a/package.json b/package.json
index 4e9fe07..eb772d7 100644
--- a/package.json
+++ b/package.json
@@ -54,6 +54,7 @@
"fs-extra": "^10.0.0",
"marked": "^4.0.10",
"marked-man": "^0.7.0",
+ "simple-vdf": "^1.1.1",
"unzipper": "^0.10.11"
},
"devDependencies": {
diff --git a/src/utils.js b/src/utils.js
index 50ffed0..11f7dcb 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -1,5 +1,6 @@
const path = require("path");
const fs = require("fs-extra");
+const os = require("os")
const copy = require("copy-dir");
const { app, dialog, ipcMain, Notification } = require("electron");
@@ -14,6 +15,7 @@ const unzip = require("unzipper");
const run = require("child_process").spawn;
const exec = require("child_process").exec;
const { https } = require("follow-redirects");
+const vdf = require('simple-vdf');
process.chdir(app.getPath("appData"));
@@ -119,6 +121,68 @@ function setpath(win) {
if (! win) { // CLI
settings.gamepath = cli.param("setpath");
} else { // GUI
+ // Autodetect path
+
+
+ // Windows only using powershell and windows registery
+ // Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2\
+ // https://nodejs.org/api/os.html#osplatform
+ if (os.platform() == "win32")
+ {
+ // TODO
+ }
+
+ // Detect using
+ // Windows: C:\Program Files (x86)\Steam\steamapps
+ // Linux: ~/.steam/steam/steamapps/
+ // Mac: ~/Library/Application\ Support/Steam/steamapps
+
+ function read_libraryfolders(read_data)
+ {
+ // Parse read_data
+ data = vdf.parse(read_data);
+
+ //data['libraryfolders']
+ // `.length - 1` This is because the last value is `contentstatsid`
+ for (let pathIterator = 0; pathIterator < Object.values(data['libraryfolders']).length - 1; pathIterator++) {
+ let data_array = Object.values(data['libraryfolders'][pathIterator])
+
+ 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);
+
+ saveSettings();
+ cli.exit();
+ // Return 1 if success
+ return 1;
+ }
+ }
+ }
+
+ switch (os.platform()) {
+ case "win32":
+ if (fs.existsSync( "C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf"))
+ {
+ let read_data = fs.readFileSync("C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf")
+ if (read_libraryfolders(read_data.toString()) == 1)
+ return
+ }
+ break;
+ case "linux":
+ if (fs.existsSync( os.homedir() + "/.steam/steam/steamapps/libraryfolders.vdf"))
+ {
+ let read_data = fs.readFileSync(os.homedir() + "/.steam/steam/steamapps/libraryfolders.vdf")
+ if (read_libraryfolders(read_data.toString()) == 1)
+ return
+ }
+ break;
+ }
+
+ // Let user choose manually
dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => {
if (res.canceled) {
ipcMain.emit("newpath", null, false);
@@ -134,11 +198,12 @@ function setpath(win) {
saveSettings();
win.webContents.send("newpath", settings.gamepath);
ipcMain.emit("newpath", null, settings.gamepath);
+
+ saveSettings();
+ cli.exit();
+ return;
}).catch(err => {console.error(err)})
}
-
- saveSettings();
- cli.exit();
}
// As to not have to do the same one liner a million times, this