aboutsummaryrefslogtreecommitdiff
path: root/src/extras/findgame.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-01-26 00:23:30 +0100
committerGitHub <noreply@github.com>2022-01-26 00:23:30 +0100
commit66204f6f58dc90e1e9ee40c7ea691927d0c50b8d (patch)
treeafb0172e5d4a6c4b9e4644513e012fde9efe65f5 /src/extras/findgame.js
parent353db2c99fd26c3c925247b61b30619020a12b5a (diff)
parent6a08872d134f3afa3f81b92fabe51bdbd91f375d (diff)
downloadViper-66204f6f58dc90e1e9ee40c7ea691927d0c50b8d.tar.gz
Viper-66204f6f58dc90e1e9ee40c7ea691927d0c50b8d.zip
Merge pull request #53 from 0neGal/detect-gamepath
Detect gamepath automatically
Diffstat (limited to 'src/extras/findgame.js')
-rw-r--r--src/extras/findgame.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/extras/findgame.js b/src/extras/findgame.js
new file mode 100644
index 0000000..42c9b85
--- /dev/null
+++ b/src/extras/findgame.js
@@ -0,0 +1,67 @@
+const fs = require("fs");
+const path = require("path");
+const vdf = require("simple-vdf");
+const { app } = require("electron");
+
+const util = require("util");
+const exec = util.promisify(require("child_process").exec);
+
+module.exports = async () => {
+ let gamepath = "";
+
+ // Autodetect path
+ // Windows only using powershell and windows registery
+ // Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2\
+ if (process.platform == "win32") {
+ try {
+ const {stdout} = await exec("Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\\SOFTWARE\\Respawn\\Titanfall2\\ -Name \"Install Dir\"", {"shell":"powershell.exe"});
+
+ const gamepath = stdout.split('\n')
+ .filter(r => r.indexOf("Install Dir") !== -1)[0]
+ .replace(/\s+/g,' ')
+ .trim()
+ .replace("Install Dir : ","");
+
+ if (gamepath) {return gamepath}
+ } catch (err) {}
+ }
+
+ // Detect using Steam VDF
+ function readvdf(data) {
+ // Parse read_data
+ data = vdf.parse(data);
+
+ // `.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")) {
+ return data_array[0] + "/steamapps/common/Titanfall2";
+ }
+ }
+ }
+
+ let folder = null;
+ switch (process.platform) {
+ case "win32":
+ folder = "C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf";
+ break
+ case "linux":
+ case "openbsd":
+ case "freebsd":
+ folder = path.join(app.getPath("home"), "/.steam/steam/steamapps/libraryfolders.vdf");
+ break
+ }
+
+ if (fs.existsSync(folder) && folder) {
+ let data = fs.readFileSync(folder)
+ let read_vdf = readvdf(data.toString())
+ if (read_vdf ) {return read_vdf}
+ }
+
+ if (gamepath) {
+ return gamepath;
+ } else {
+ return false;
+ }
+}