aboutsummaryrefslogtreecommitdiff
path: root/src/extras/findgame.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-01-23 01:56:27 +0100
committer0neGal <mail@0negal.com>2022-01-23 01:56:27 +0100
commit4f8884ea68c1360a7b0adec2386c60c7dc65c281 (patch)
treeb39d3be6ffa189769a19e93bf57a78aed1e1f43e /src/extras/findgame.js
parenta6dae7791e2f1a82e9f37e6a41961d77698c9a77 (diff)
downloadViper-4f8884ea68c1360a7b0adec2386c60c7dc65c281.tar.gz
Viper-4f8884ea68c1360a7b0adec2386c60c7dc65c281.zip
moved modules into extras/
I moved requests.js into extras and made the function for finding the potentional gamepath into it's own module. I also made the exec() called Promise based.
Diffstat (limited to 'src/extras/findgame.js')
-rw-r--r--src/extras/findgame.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/extras/findgame.js b/src/extras/findgame.js
new file mode 100644
index 0000000..029914a
--- /dev/null
+++ b/src/extras/findgame.js
@@ -0,0 +1,64 @@
+const fs = require("fs");
+const path = require("path");
+const vdf = require("simple-vdf");
+
+const util = require("util");
+const exec = util.promisify(require("child_process").exec);
+
+module.exports = () => {
+ 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 {
+ exec("Get-Item -Path Registry::HKEY_LOCAL_MACHINE\\SOFTWARE\\Respawn\\Titanfall2\\", {"shell":"powershell.exe"}, (err, stdout) => {
+ 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);
+
+ //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")) {
+ return data_array[0] + "/steamapps/common/Titanfall2";
+ }
+ }
+ }
+
+ switch (process.platform) {
+ 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())) {return data.toString()}
+ }
+ 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())) {return data.toString()}
+ }
+ break;
+ }
+
+ if (gamepath) {
+ return gamepath;
+ } else {
+ return false;
+ }
+}