diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/index.js | 8 | ||||
-rw-r--r-- | src/modules/mods.js | 11 | ||||
-rw-r--r-- | src/modules/version.js | 79 | ||||
-rw-r--r-- | src/utils.js | 91 |
4 files changed, 99 insertions, 90 deletions
diff --git a/src/index.js b/src/index.js index 638bebb..991717b 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ const utils = require("./utils"); const cli = require("./cli"); const json = require("./modules/json"); const mods = require("./modules/mods"); +const version = require("./modules/version"); const settings = require("./modules/settings"); const requests = require("./modules/requests"); @@ -179,8 +180,8 @@ ipcMain.on("setpath", (event, value) => { // retrieves various local version numbers function sendVersionsInfo() { send("version", { - ns: utils.getNSVersion(), - tf2: utils.getTF2Version(), + ns: version.northstar(), + tf2: version.titanfall(), vp: "v" + require("../package.json").version }); } @@ -191,7 +192,8 @@ ipcMain.on("get-version", () => {sendVersionsInfo()}); // prints out version info for the CLI ipcMain.on("version-cli", () => { log("Viper: v" + require("../package.json").version); - log("Northstar: " + utils.getNSVersion()); + log("Titanfall 2: " + version.titanfall()); + log("Northstar: " + version.northstar()); log("Node: " + process.version); log("Electron: v" + process.versions.electron); cli.exit(); 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; diff --git a/src/utils.js b/src/utils.js index 9beaa3e..5ba98e6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -8,6 +8,7 @@ const events = new Emitter(); const cli = require("./cli"); const lang = require("./lang"); const json = require("./modules/json"); +const version = require("./modules/version"); const settings = require("./modules/settings"); const requests = require("./modules/requests"); const findgame = require("./modules/findgame"); @@ -105,7 +106,7 @@ function handleNorthstarUpdating() { } async function _checkForUpdates() { - let localVersion = getNSVersion(); + let localVersion = version.northstar(); let distantVersion = await requests.getLatestNsVersion(); if (distantVersion == false) { return; } console.log(lang("cli.autoupdates.checking")); @@ -194,78 +195,6 @@ async function setpath(win, forcedialog) { } } -// Returns the current Northstar version -// If not installed it'll return "unknown" -function getNSVersion() { - // 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. -function getTF2Version() { - var versionFilePath = path.join(settings.gamepath, "gameversion.txt"); - if (fs.existsSync(versionFilePath)) { - return fs.readFileSync(versionFilePath, "utf8"); - } else { - return "unknown"; - } -} - - // Renames excluded files to their original name function restoreExcludedFiles() { for (let i = 0; i < settings.excludes.length; i++) { @@ -292,7 +221,7 @@ async function updateNorthstar() { ipcMain.emit("ns-update-event", "cli.update.checking"); console.log(lang("cli.update.checking")); - var version = getNSVersion(); + var ns_version = version.northstar(); const latestAvailableVersion = await requests.getLatestNsVersion(); console.log(latestAvailableVersion) @@ -302,16 +231,16 @@ async function updateNorthstar() { } // Makes sure it is not already the latest version - if (version === latestAvailableVersion) { + if (ns_version === latestAvailableVersion) { ipcMain.emit("ns-update-event", "cli.update.uptodate.short"); - console.log(lang("cli.update.uptodate"), version); + console.log(lang("cli.update.uptodate"), ns_version); winLog(lang("gui.update.uptodate")); cli.exit(); return; } else { - if (version != "unknown") { - console.log(lang("cli.update.current"), version); + if (ns_version != "unknown") { + console.log(lang("cli.update.current"), ns_version); }; console.log(lang("cli.update.downloading") + ":", latestAvailableVersion); ipcMain.emit("ns-update-event", "cli.update.downloading"); @@ -413,7 +342,7 @@ function updateViper(autoinstall) { // // Either Northstar or Vanilla. Linux support is not currently a thing, // however it'll be added at some point. -function launch(version) { +function launch(game_version) { if (process.platform == "linux") { winAlert(lang("cli.launch.linuxerror")); console.error("error:", lang("cli.launch.linuxerror")); @@ -422,7 +351,7 @@ function launch(version) { } process.chdir(settings.gamepath); - switch(version) { + switch(game_version) { case "vanilla": console.log(lang("general.launching"), "Vanilla..."); exec("Titanfall2.exe", {cwd: settings.gamepath}); @@ -456,8 +385,6 @@ module.exports = { winLog, updateViper, - getNSVersion, - getTF2Version, updateNorthstar, handleNorthstarUpdating, |