1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
const path = require("path");
const fs = require("fs-extra");
const ipcMain = require("electron").ipcMain;
const win = require("../win");
const json = require("./json");
const settings = require("./settings");
let version = {};
// sends the version info back to the renderer
ipcMain.on("get-version", () => {
version.send_info();
})
// retrieves various local version numbers and sends them to the renderer
version.send_info = () => {
win().send("version", {
ns: version.northstar(),
tf2: version.titanfall(),
vp: "v" + version.viper()
})
}
// 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").trim();
} else {
return "unknown";
}
}
// returns Viper's current version, taken from `package.json`
version.viper = () => {
return json(
path.join(__dirname, "../../package.json")
).version;
}
module.exports = version;
|