From 4536aad2c4f19d32569d84a7082e8636a2be6985 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sat, 4 Mar 2023 23:16:56 +0100 Subject: modularized getXXVersion() functions Both getTF2Version() and getNSVersion() are now in version.js --- src/modules/mods.js | 11 +++---- src/modules/version.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/modules/version.js (limited to 'src/modules') diff --git a/src/modules/mods.js b/src/modules/mods.js index 9aa2c81..22865c2 100644 --- a/src/modules/mods.js +++ b/src/modules/mods.js @@ -6,6 +6,7 @@ const { app, ipcMain } = require("electron"); const { https } = require("follow-redirects"); const json = require("./json"); +const version = require("./version"); const settings = require("./settings"); const cli = require("../cli"); @@ -29,7 +30,7 @@ function update_path() { mods.list = () => { update_path(); - if (utils.getNSVersion() == "unknown") { + if (version.northstar() == "unknown") { utils.winLog(lang("general.notinstalled")); console.log("error: " + lang("general.notinstalled")); cli.exit(1); @@ -106,7 +107,7 @@ mods.list = () => { mods.get = (mod) => { update_path(); - if (utils.getNSVersion() == "unknown") { + if (version.northstar() == "unknown") { utils.winLog(lang("general.notinstalled")); console.log("error: " + lang("general.notinstalled")); cli.exit(1); @@ -221,7 +222,7 @@ mods.install = (mod, opts) => { mods.dupe_msg_sent = false; } - if (utils.getNSVersion() == "unknown") { + if (version.northstar() == "unknown") { utils.winLog(lang("general.notinstalled")); console.log("error: " + lang("general.notinstalled")); cli.exit(1); @@ -462,7 +463,7 @@ mods.installFromURL = (url, author) => { mods.remove = (mod) => { update_path(); - if (utils.getNSVersion() == "unknown") { + if (version.northstar() == "unknown") { utils.winLog(lang("general.notinstalled")); console.log("error: " + lang("general.notinstalled")); cli.exit(1); @@ -523,7 +524,7 @@ mods.remove = (mod) => { mods.toggle = (mod, fork) => { update_path(); - if (utils.getNSVersion() == "unknown") { + if (version.northstar() == "unknown") { utils.winLog(lang("general.notinstalled")); console.log("error: " + lang("general.notinstalled")); cli.exit(1); diff --git a/src/modules/version.js b/src/modules/version.js new file mode 100644 index 0000000..73e7bed --- /dev/null +++ b/src/modules/version.js @@ -0,0 +1,79 @@ +const path = require("path"); +const fs = require("fs-extra"); + +const json = require("./json"); +const settings = require("./settings"); + +let version = {}; + +// Returns the current Northstar version +// If not installed it'll return "unknown" +version.northstar = () => { + // if NorthstarLauncher.exe doesn't exist, always return "unknown" + if (! fs.existsSync(path.join(settings.gamepath, "NorthstarLauncher.exe"))) { + return "unknown"; + } + + // mods to check version of + var versionFiles = [ + "Northstar.Client", + "Northstar.Custom", + "Northstar.CustomServers" + ] + + var versions = []; + + + let add = (version) => { + versions.push(version) + } + + // checks version of mods + for (let i = 0; i < versionFiles.length; i++) { + var versionFile = path.join(settings.gamepath, "R2Northstar/mods/", versionFiles[i],"/mod.json"); + if (fs.existsSync(versionFile)) { + if (! fs.statSync(versionFile).isFile()) { + add("unknown"); + } + + try { + add("v" + json(versionFile).Version); + }catch(err) { + add("unknown"); + } + } else { + add("unknown"); + } + } + + if (versions.includes("unknown")) {return "unknown"} + + // verifies all mods have the same version number + let mismatch = false; + let baseVersion = versions[0]; + for (let i = 0; i < versions.length; i++) { + if (versions[i] != baseVersion) { + mismatch = true; + break + } + } + + if (mismatch) {return "unknown"} + return baseVersion; +} + +// Returns the Titanfall 2 version from gameversion.txt file. +// If it fails it simply returns "unknown" +// +// TODO: This file is present on Origin install, should check if it's +// present with Steam install as well. +version.titanfall = () => { + var versionFilePath = path.join(settings.gamepath, "gameversion.txt"); + if (fs.existsSync(versionFilePath)) { + return fs.readFileSync(versionFilePath, "utf8"); + } else { + return "unknown"; + } +} + +module.exports = version; -- cgit v1.2.3