aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/index.html15
-rw-r--r--src/app/lang.js12
-rw-r--r--src/app/main.css7
-rw-r--r--src/app/main.js21
-rw-r--r--src/cli.js14
-rw-r--r--src/index.js13
-rw-r--r--src/lang.js29
-rw-r--r--src/lang/en.json34
-rw-r--r--src/lang/fr.json34
-rw-r--r--src/utils.js80
10 files changed, 226 insertions, 33 deletions
diff --git a/src/app/index.html b/src/app/index.html
index 67d2e5c..426b4c5 100644
--- a/src/app/index.html
+++ b/src/app/index.html
@@ -6,22 +6,23 @@
<body>
<div class="lines">
<div class="line">
- <div class="text">Welcome to Viper!</div>
+ <div class="text">%%gui.welcome%%</div>
<div class="buttons">
- <button id="exit" onclick="exit()">Exit</button>
- <button id="update" onclick="update()">Update</button>
- <button id="setpath" onclick="setpath()">Game Path</button>
+ <button id="exit" onclick="exit()">%%gui.exit%%</button>
+ <button id="update" onclick="update()">%%gui.update%%</button>
+ <button id="setpath" onclick="setpath()">%%gui.setpath%%</button>
</div>
</div>
<div class="line">
- <div class="text">Launch:</div>
+ <div class="text">%%gui.launch%%:</div>
<div class="buttons">
- <button id="vanilla" onclick="launchVanilla()">Vanilla</button>
- <button id="northstar" onclick="launch()">Northstar</button>
+ <button id="vanilla" onclick="launchVanilla()">%%gui.launchvanilla%%</button>
+ <button id="northstar" onclick="launch()">%%gui.launchnorthstar%%</button>
</div>
</div>
</div>
+ <script src="lang.js"></script>
<script src="main.js"></script>
</body>
</html>
diff --git a/src/app/lang.js b/src/app/lang.js
new file mode 100644
index 0000000..5cc9708
--- /dev/null
+++ b/src/app/lang.js
@@ -0,0 +1,12 @@
+function setlang() {
+ html = document.body.innerHTML.split("%%");
+
+ for (let i = 0; i < html.length; i++) {
+ if (html[i][0] != " " &&
+ html[i][html[i].length - 1] != " ") {
+ html[i] = lang(html[i])
+ }
+ }
+
+ document.body.innerHTML = html.join("");
+}
diff --git a/src/app/main.css b/src/app/main.css
index 854c47a..f49cc98 100644
--- a/src/app/main.css
+++ b/src/app/main.css
@@ -28,16 +28,22 @@ body, button, input {
font-family: "Roboto Mono", monospace;
}
+nobr {white-space: nowrap}
+
.line {
display: flex;
margin-top: 15px;
}
.buttons {
+ text-align: right;
margin-left: auto;
margin-right: 7px;
}
+.text {max-width: 38vw}
+.buttons {max-width: 55vw}
+
button, .text {
border: none;
outline: none;
@@ -47,6 +53,7 @@ button, .text {
}
button {
+ margin-bottom: 10px;
color: var(--btnforeground);
-webkit-app-region: no-drag;
}
diff --git a/src/app/main.js b/src/app/main.js
index 17389b2..9bafaa5 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -2,17 +2,25 @@ const fs = require("fs");
const path = require("path");
const { ipcRenderer } = require("electron");
+const lang = require("../lang");
+
var settings = {
gamepath: "",
- file: "viper.json",
zip: "/northstar.zip",
+ lang: navigator.language,
+ excludes: [
+ "ns_startup_args.txt",
+ "ns_startup_args_dedi.txt"
+ ]
}
-if (fs.existsSync(settings.file)) {
- settings = {...settings, ...JSON.parse(fs.readFileSync(settings.file, "utf8"))};
+ipcRenderer.send("setlang", settings.lang);
+
+if (fs.existsSync("viper.json")) {
+ settings = {...settings, ...JSON.parse(fs.readFileSync("viper.json", "utf8"))};
settings.zip = path.join(settings.gamepath + "/northstar.zip");
} else {
- alert("Game path is not set! Please select the path!");
+ alert(lang("gui.missinggamepath"));
setpath();
}
@@ -26,3 +34,8 @@ function launchVanilla() {ipcRenderer.send("launchVanilla")}
ipcRenderer.on("newpath", (event, newpath) => {
settings.gamepath = newpath;
})
+
+setlang();
+setInterval(() => {
+ ipcRenderer.send("setsize", document.querySelector(".lines").offsetHeight + 20);
+}, 150)
diff --git a/src/cli.js b/src/cli.js
index e5fe042..8593117 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -5,6 +5,7 @@ const Emitter = require("events");
const events = new Emitter();
const cli = app.commandLine;
+const lang = require("./lang");
function hasArgs() {
if (cli.hasSwitch("cli") ||
@@ -24,12 +25,12 @@ function exit(code) {
async function init() {
if (cli.hasSwitch("help")) {
console.log(`options:
- --help shows this help message
- --debug opens the dev/debug tools
+ --help ${lang("cli.help.help")}
+ --debug ${lang("cli.help.debug")}
- --cli forces the CLI to enable
- --update updates Northstar from your set game path
- --setpath sets your game path`)
+ --cli ${lang("cli.help.cli")}
+ --update ${lang("cli.help.update")}
+ --setpath ${lang("cli.help.setpath")}`)
// In the future --setpath should be able to understand
// relative paths, instead of just absolute ones.
exit();
@@ -43,7 +44,8 @@ async function init() {
if (cli.getSwitchValue("setpath") != "") {
ipcMain.emit("setpathcli", cli.getSwitchValue("setpath"));
} else {
- console.error("error: No argumment provided for --setpath");
+ console.error(`error: ${lang("cli.setpath.noarg")}`);
+ exit(1);
}
}
diff --git a/src/index.js b/src/index.js
index 3d50cee..8343ba9 100644
--- a/src/index.js
+++ b/src/index.js
@@ -9,8 +9,9 @@ const utils = require("./utils");
const cli = require("./cli");
function start() {
+ let width = 600;
win = new BrowserWindow({
- width: 600,
+ width: width,
height: 115,
show: false,
title: "Viper",
@@ -27,13 +28,19 @@ function start() {
win.removeMenu();
win.loadFile(__dirname + "/app/index.html");
- win.webContents.once("dom-ready", () => {win.show()});
- ipcMain.on("setpath", (event) => {utils.setpath(win)})
ipcMain.on("exit", (event) => {process.exit(0)})
+ ipcMain.on("setpath", (event) => {utils.setpath(win)})
+ ipcMain.on("setsize", (event, height) => {
+ win.setSize(width, height);
+ if (! win.isVisible()) {
+ win.show();
+ }
+ })
}
ipcMain.on("launch", (event) => {utils.launch()})
+ipcMain.on("setlang", (event, lang) => {utils.setlang(lang)})
ipcMain.on("launchVanilla", (event) => {utils.launch("vanilla")})
ipcMain.on("update", (event) => {utils.update()})
diff --git a/src/lang.js b/src/lang.js
new file mode 100644
index 0000000..d404e8e
--- /dev/null
+++ b/src/lang.js
@@ -0,0 +1,29 @@
+const fs = require("fs");
+
+var lang = "en";
+var langDef = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8"));
+if (fs.existsSync("viper.json")) {
+ lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang;
+ if (! lang) {lang = "en"}
+ if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) {
+ if (fs.existsSync(__dirname + `/lang/${lang.replace(/-.*$/, "")}.json`)) {
+ lang = lang.replace(/-.*$/, "");
+ } else {
+ lang = "en";
+ }
+ }
+}
+
+var langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8"));
+
+module.exports = (string) => {
+ if (langObj[string]) {
+ return langObj[string];
+ } else {
+ if (langDef[string]) {
+ return langDef[string];
+ } else {
+ return string;
+ }
+ }
+}
diff --git a/src/lang/en.json b/src/lang/en.json
new file mode 100644
index 0000000..e88079e
--- /dev/null
+++ b/src/lang/en.json
@@ -0,0 +1,34 @@
+{
+ "cli.help.help": "shows this help message",
+ "cli.help.debug": "opens the dev/debug tools",
+ "cli.help.cli": "forces the CLI to enable",
+ "cli.help.update": "updates Northstar from your set game path",
+ "cli.help.setpath": "sets your game path",
+
+ "cli.setpath.noarg": "No argument provided for --setpath",
+
+ "cli.update.current": "Current version:",
+ "cli.update.downloading": "Downloading:",
+ "cli.update.checking": "Checking for updates...",
+ "cli.update.downloaddone": "Download done! Extracting...",
+ "cli.update.finished": "Installation/Update finished!",
+ "cli.update.uptodate": "Latest version (%s) is already installed, skipping update.",
+
+ "cli.launch.linuxerror": "Launching the game is not currently supported on Linux",
+
+ "gui.welcome": "Welcome to Viper!",
+ "gui.exit": "Exit",
+ "gui.update": "Update",
+ "gui.setpath": "Game Path",
+
+ "gui.launch": "Launch",
+ "gui.launchvanilla": "Vanilla",
+ "gui.launchnorthstar": "Northstar",
+
+ "gui.selectpath": "Please select the path!",
+ "gui.missinggamepath": "Game path is not set!",
+
+
+ "general.launching": "Launching",
+ "general.missingpath": "Game path is not set!"
+}
diff --git a/src/lang/fr.json b/src/lang/fr.json
new file mode 100644
index 0000000..0dd9f99
--- /dev/null
+++ b/src/lang/fr.json
@@ -0,0 +1,34 @@
+{
+ "cli.help.help": "affiche ce message d'aide",
+ "cli.help.debug": "affiche les outils de développement",
+ "cli.help.cli": "force l'activation de la CLI",
+ "cli.help.update": "met à jour Northstar sur le chemin du jeu précisé",
+ "cli.help.setpath": "enregistre le chemin du client de jeu",
+
+ "cli.setpath.noarg": "Aucun argument donné à --setpath",
+
+ "cli.update.current": "Version actuelle :",
+ "cli.update.downloading": "Téléchargement en cours :",
+ "cli.update.checking": "Vérification des mises à jour ...",
+ "cli.update.downloaddone": "Téléchargement terminé ! Extraction des fichiers...",
+ "cli.update.finished": "Mise à jour terminée !",
+ "cli.update.uptodate": "La dernière version (%s) est déjà installée.",
+
+ "cli.launch.linuxerror": "Le support du jeu sur Linux n'est pas encore implémenté.",
+
+ "gui.welcome": "Bienvenue sur Viper !",
+ "gui.exit": "Fermer",
+ "gui.update": "Mise à jour",
+ "gui.setpath": "Chemin du jeu",
+
+ "gui.launch": "Jouer",
+ "gui.launchvanilla": "Vanilla",
+ "gui.launchnorthstar": "Northstar",
+
+ "gui.selectpath": "Veuillez sélectionner le dossier où se trouve le client Titanfall 2.",
+ "gui.missinggamepath": "Le chemin du client n'est pas défini !",
+
+
+ "general.launching": "Lancement",
+ "general.missingpath": "Le chemin du client n'est pas défini !"
+}
diff --git a/src/utils.js b/src/utils.js
index 85cc26e..7e9dbac 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -6,6 +6,7 @@ const Emitter = require("events");
const events = new Emitter();
const cli = require("./cli");
+const lang = require("./lang");
const unzip = require("unzipper");
const request = require("request");
@@ -16,18 +17,21 @@ process.chdir(app.getPath("appData"));
var settings = {
gamepath: "",
- file: "viper.json",
+ lang: "en-US",
zip: "/northstar.zip",
+ excludes: [
+ "ns_startup_args.txt",
+ "ns_startup_args_dedi.txt"
+ ]
}
-if (fs.existsSync(settings.file)) {
- settings = {...settings, ...JSON.parse(fs.readFileSync(settings.file, "utf8"))};
+if (fs.existsSync("viper.json")) {
+ settings = {...settings, ...JSON.parse(fs.readFileSync("viper.json", "utf8"))};
settings.zip = path.join(settings.gamepath + "/northstar.zip");
} else {
- console.log("Game path is not set! Please select the path.");
+ console.log(lang("gui.missinggamepath"));
}
-
function setpath(win) {
if (! win) {
settings.gamepath = cli.param("setpath");
@@ -35,32 +39,78 @@ function setpath(win) {
dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => {
settings.gamepath = res.filePaths[0];
settings.zip = path.join(settings.gamepath + "/northstar.zip");
-
+ saveSettings();
win.webContents.send("newpath", settings.gamepath);
}).catch(err => {console.error(err)})
}
- fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({...settings}));
+ fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify(settings));
cli.exit();
}
+function saveSettings() {
+ fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify(settings));
+}
+
+function getInstalledVersion() {
+ const versionFilePath = path.join(settings.gamepath, "ns_version.txt");
+
+ if (fs.existsSync(versionFilePath)) {
+ return fs.readFileSync(versionFilePath, "utf8");
+ } else {
+ fs.writeFileSync(versionFilePath, "unknown");
+ return "unknown";
+ }
+}
+
function update() {
- console.log("Downloading...");
+ for (let i = 0; i < settings.excludes.length; i++) {
+ let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]);
+ if (fs.existsSync(exclude)) {
+ fs.renameSync(exclude, exclude + ".excluded")
+ }
+ }
+
+ console.log(lang("cli.update.checking"));
+ const version = getInstalledVersion();
+
request({
json: true,
headers: {"User-Agent": "Viper"},
url: "https://api.github.com/repos/R2Northstar/Northstar/releases/latest",
}, (error, response, body) => {
+ var tag = body["tag_name"];
+
+ if (version === tag) {
+ console.log(lang("cli.update.uptodate"), version);
+ return;
+ } else {
+ if (version != "unknown") {
+ console.log(lang("cli.update.current"), version);
+ }; console.log(lang("cli.update.downloading"), tag);
+ }
+
https.get(body.assets[0].browser_download_url, (res) => {
let stream = fs.createWriteStream(settings.zip);
res.pipe(stream);
stream.on("finish", () => {
stream.close();
- console.log("Download done! Extracting...");
+ console.log(lang("cli.update.downloaddone"));
fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath}))
.on("finish", () => {
- console.log("Installation/Update finished!");
+ console.log(lang("cli.update.finished"));
+
+ fs.writeFileSync(path.join(settings.gamepath, "ns_version.txt"), tag);
+
events.emit("updated");
+
+ for (let i = 0; i < settings.excludes.length; i++) {
+ let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]);
+ if (fs.existsSync(exclude + ".excluded")) {
+ fs.renameSync(exclude + ".excluded", exclude)
+ }
+ }
+
cli.exit();
});
})
@@ -70,18 +120,18 @@ function update() {
function launch(version) {
if (process.platform == "linux") {
- console.error("error: Launching the game is not currently supported on Linux")
+ console.error("error:", lang("cli.launch.linuxerror"))
cli.exit(1);
}
process.chdir(settings.gamepath);
switch(version) {
case "vanilla":
- console.log("Launching Vanilla...")
+ console.log(lang("general.launching"), "Vanilla...")
exec(path.join(settings.gamepath + "/Titanfall2.exe"))
break;
default:
- console.log("Launching Northstar...")
+ console.log(lang("general.launching"), "Northstar...")
exec(path.join(settings.gamepath + "/NorthstarLauncher.exe"))
break;
}
@@ -92,4 +142,8 @@ module.exports = {
update,
setpath,
settings,
+ setlang: (lang) => {
+ settings.lang = lang;
+ saveSettings();
+ },
}