aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-01-22 19:10:08 +0100
committer0neGal <mail@0negal.com>2022-01-22 19:10:08 +0100
commitb1b7d260a1a333618c045d3c43b7af5573c274a3 (patch)
tree4f968f58da54047fcc1095b0e1bf6e9e5257eed6
parent6a0fe7b963a7934741d06416f5161e854505f36a (diff)
downloadViper-b1b7d260a1a333618c045d3c43b7af5573c274a3.tar.gz
Viper-b1b7d260a1a333618c045d3c43b7af5573c274a3.zip
initial review of VDF parsing
-rw-r--r--src/utils.js46
1 files changed, 15 insertions, 31 deletions
diff --git a/src/utils.js b/src/utils.js
index 86ea5ae..521931d 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -1,6 +1,5 @@
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");
@@ -11,11 +10,11 @@ const cli = require("./cli");
const lang = require("./lang");
const requests = require("./requests");
+const vdf = require("simple-vdf");
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"));
@@ -122,30 +121,19 @@ function setpath(win) {
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
+ if (process.platform == "win32") {/* TODO */}
- function read_libraryfolders(read_data)
- {
+ // Detect using Steam VDF
+ function readvdf(data) {
// Parse read_data
- data = vdf.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])
+ 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
@@ -163,26 +151,22 @@ function setpath(win) {
}
}
- switch (os.platform()) {
+ switch (process.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
+ 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}
}
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
+ 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}
}
break;
}
- // Let user choose manually
+ // Fallback to manual selection
dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => {
if (res.canceled) {
ipcMain.emit("newpath", null, false);