Multiple manager improvements and bug fixes

This commit is contained in:
Pax1601 2024-03-10 18:38:55 +01:00
parent 8c7f6abb1c
commit 396c061a3e
7 changed files with 154 additions and 53 deletions

View File

@ -19,21 +19,21 @@
<span>Game Master Password<img src="./icons/circle-info-solid.svg"
title="This password is used to access Olympus as Game Master with full privileges.">
</span>
<input type="password" minlength="8" onchange="signal('onGameMasterPasswordChanged', this.value)" placeholder="<%= !activeInstance["installed"] || activeInstance["gameMasterPasswordEdited"]? '': 'Keep old password'%>">
<input type="password" minlength="8" onchange="signal('onGameMasterPasswordChanged', this.value)" placeholder="<%= state === 'INSTALL' || activeInstance["gameMasterPasswordEdited"]? '': 'Keep old password'%>">
</div>
<div class="input-group blue-commander">
<span>Blue Commander Password<img src="./icons/circle-info-solid.svg"
title="This password is used to access Olympus as blue coalition Commander.">
</span>
<input type="password" minlength="8" onchange="signal('onBlueCommanderPasswordChanged', this.value)" placeholder="<%= !activeInstance["installed"] || activeInstance["blueCommanderPasswordEdited"]? '': 'Keep old password'%>">
<input type="password" minlength="8" onchange="signal('onBlueCommanderPasswordChanged', this.value)" placeholder="<%= state === 'INSTALL' || activeInstance["blueCommanderPasswordEdited"]? '': 'Keep old password'%>">
</div>
<div class="input-group red-commander">
<span>Red Commander Password<img src="./icons/circle-info-solid.svg"
title="This password is used to access Olympus as red coalition Commander.">
</span>
<input type="password" minlength="8" onchange="signal('onRedCommanderPasswordChanged', this.value)" placeholder="<%= !activeInstance["installed"] || activeInstance["redCommanderPasswordEdited"]? '': 'Keep old password'%>">
<input type="password" minlength="8" onchange="signal('onRedCommanderPasswordChanged', this.value)" placeholder="<%= state === 'INSTALL' || activeInstance["redCommanderPasswordEdited"]? '': 'Keep old password'%>">
</div>
<div class="<%= activeInstance["installed"]? '': 'hide' %>" style="color: var(--offwhite); font-size: var(--normal); color: var(--lightgray);">
<div class="<%= state !== 'INSTALL'? '': 'hide' %>" style="color: var(--offwhite); font-size: var(--normal); color: var(--lightgray);">
Note: to keep the old passwords, click <b>Next</b> without editing any value.
</div>
</div>

View File

@ -1,4 +1,5 @@
const { getManager } = require('./managerfactory')
const { dialog } = require('@electron/remote');
var regedit = require('regedit').promisified;
var fs = require('fs')
var path = require('path')
@ -23,8 +24,8 @@ class DCSInstance {
* @returns The list of DCS instances
*/
static async getInstances(force = false) {
if (this.instances === null || force)
DCSInstance.instances = this.findInstances();
if (this.instances === null || force)
DCSInstance.instances = this.findInstances();
return DCSInstance.instances;
}
@ -49,29 +50,45 @@ class DCSInstance {
var result = await regedit.list(shellFoldersKey);
/* Check that the registry read was successfull */
if (result[shellFoldersKey] !== undefined && result[shellFoldersKey]["exists"] && result[shellFoldersKey]['values'][saveGamesKey] !== undefined && result[shellFoldersKey]['values'][saveGamesKey]['value'] !== undefined) {
/* Read all the folders in Saved Games */
const searchpath = result[shellFoldersKey]['values'][saveGamesKey]['value'];
var folders = fs.readdirSync(searchpath).map((folder) => {return path.join(searchpath, folder);});
var instances = [];
folders = folders.concat(getManager().getAdditionalDCSInstances());
/* A DCS Instance is created if either the appsettings.lua or serversettings.lua file is detected */
for (let i = 0; i < folders.length; i++) {
const folder = folders[i];
if (fs.existsSync(path.join(folder, "Config", "appsettings.lua")) || fs.existsSync(path.join(folder, "Config", "serversettings.lua")) || getManager().getAdditionalDCSInstances().includes(folder)) {
logger.log(`Found instance in ${folder}, checking for Olympus`)
var newInstance = new DCSInstance(path.join(folder));
let customSavedGamesFolder = (await getManager().getOptions()).savedGamesFolder;
console.log((await getManager().getOptions()))
if (customSavedGamesFolder !== undefined || (result[shellFoldersKey] !== undefined && result[shellFoldersKey]["exists"] && result[shellFoldersKey]['values'][saveGamesKey] !== undefined && result[shellFoldersKey]['values'][saveGamesKey]['value'] !== undefined)) {
try {
/* Read all the folders in Saved Games */
const searchpath = customSavedGamesFolder !== undefined ? customSavedGamesFolder : result[shellFoldersKey]['values'][saveGamesKey]['value'];
var folders = fs.readdirSync(searchpath).map((folder) => { return path.join(searchpath, folder); });
var instances = [];
folders = folders.concat(getManager().getAdditionalDCSInstances());
/* Check if Olympus is already installed */
getManager().setLoadingProgress(`Found instance in ${folder}, checking for Olympus...`, (i + 1) / folders.length * 100);
await newInstance.checkInstallation();
instances.push(newInstance);
/* A DCS Instance is created if either the appsettings.lua or serversettings.lua file is detected */
for (let i = 0; i < folders.length; i++) {
const folder = folders[i];
if (fs.existsSync(path.join(folder, "Config", "appsettings.lua")) || fs.existsSync(path.join(folder, "Config", "serversettings.lua")) || getManager().getAdditionalDCSInstances().includes(folder)) {
logger.log(`Found instance in ${folder}, checking for Olympus`)
var newInstance = new DCSInstance(path.join(folder));
/* Check if Olympus is already installed */
getManager().setLoadingProgress(`Found instance in ${folder}, checking for Olympus...`, (i + 1) / folders.length * 100);
await newInstance.checkInstallation();
instances.push(newInstance);
}
}
} catch (err) {
showErrorPopup(`<div class='main-message'>A critical error has occurred while detecting your DCS Instances locations. </div><div class='sub-message'>You can find more info in ${path.join(__dirname, "..", "manager.log")}</div>`)
logger.error(err)
}
} else {
logger.error("An error occured while trying to fetch the location of the DCS instances.")
showErrorPopup(`<div class='main-message'>An error occured while trying to fetch the location of the DCS instances. </div><div class='sub-message'> You can find more info in ${getManager().getLogLocation()} </div>`);
showErrorPopup(`<div class='main-message'>An error occured while trying to fetch the location of the DCS instances. </div><div class='sub-message'> After clicking <b>Close</b>, please select the location of your Saved Games folder. </div>`, async () => {
let res = await dialog.showOpenDialog({ properties: ["openDirectory"] });
if (!res.canceled) {
getManager().setSavedGamesFolder(res.filePaths[0]);
}
else {
window.location.reload();
}
});
}
getManager().setLoadingProgress(`All DCS instances found!`, 100);
@ -104,7 +121,7 @@ class DCSInstance {
setPopupLoadingProgress(`Installing hook scripts in ${instance.folder}...`, (i * 4 + 4) / (instancesToFix.length * 4) * 100);
await sleep(100);
await installHooks(instance.folder);
await installHooks(instance.folder);
}
setPopupLoadingProgress(`All instances fixed!`, 100);
@ -114,7 +131,7 @@ class DCSInstance {
folder = "";
name = "";
frontendPort = 3000;
backendPort = 3001;
backendPort = 4512;
backendAddress = "localhost";
gameMasterPassword = "";
blueCommanderPassword = "";
@ -156,10 +173,10 @@ class DCSInstance {
this.installationType = 'singleplayer';
this.connectionsType = 'auto';
this.installCameraPlugin = 'install';
/* Check if the olympus.json file is detected. If true, Olympus is considered to be installed */
if (fs.existsSync(path.join(this.folder, "Config", "olympus.json"))) {
getManager().setLoadingProgress(`Olympus installed in ${this.folder}`);
try {
/* Read the olympus.json */
@ -459,7 +476,7 @@ class DCSInstance {
/** Stop any node process running on the server port. This will stop either the server or the client depending on what is running
*
*/
*/
stop() {
find('port', this.frontendPort)
.then((list) => {
@ -494,24 +511,34 @@ class DCSInstance {
await sleep(500);
await applyConfiguration(getManager().getActiveInstance().folder, getManager().getActiveInstance());
if (getManager().getActiveInstance().installCameraPlugin === 'install') {
setPopupLoadingProgress("Installing camera plugin...", 50);
await sleep(100);
await installCameraPlugin(getManager().getActiveInstance().folder);
} else {
setPopupLoadingProgress("Removing camera plugin (if installed)...", 50);
await sleep(100);
await deleteCameraPlugin(getManager().getActiveInstance().folder);
}
setPopupLoadingProgress("Editing completed!", 100);
await sleep(1500);
logger.log(`Editing completed successfully`);
hidePopup();
getManager().getMode() === "basic"? getManager().settingsPage.show(): getManager().instancesPage.show();
getManager().getMode() === "basic" ? getManager().settingsPage.show() : getManager().instancesPage.show();
} catch (err) {
logger.log(`An error occurred during editing: ${err}`);
getManager().getActiveInstance().error = true;
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().getLogLocation()} for more info. </div>`)
getManager().getMode() === "basic"? getManager().settingsPage.show(): getManager().instancesPage.show();
getManager().getMode() === "basic" ? getManager().settingsPage.show() : getManager().instancesPage.show();
}
}
/** Install this instance
*
*/
*/
async install() {
showWaitLoadingPopup(`<span>Please wait while Olympus is being installed in <i>${this.name}</i></span>`);
try {
@ -540,6 +567,10 @@ class DCSInstance {
setPopupLoadingProgress("Installing camera plugin...", 83);
await sleep(100);
await installCameraPlugin(getManager().getActiveInstance().folder);
} else {
setPopupLoadingProgress("Removing camera plugin (if installed)...", 83);
await sleep(100);
await deleteCameraPlugin(getManager().getActiveInstance().folder);
}
setPopupLoadingProgress("Installation completed!", 100);
@ -605,9 +636,9 @@ class DCSInstance {
hidePopup();
await getManager().reload();
if (getManager().getMode() === 'basic')
if (getManager().getMode() === 'basic')
getManager().settingsPage.show();
else
else
getManager().instancesPage.show();
return true;
} catch (err) {
@ -616,12 +647,12 @@ class DCSInstance {
/* Nested popup calls need to wait for animation to complete */
await sleep(300);
showErrorPopup(`<div class='main-message'>An error has occurred while uninstalling the Olympus instance. </div><div class='sub-message'> Make sure Olympus and DCS are not running. </div><div class='sub-message'>You can find more info in ${path.join(__dirname, "..", "manager.log")} </div>`, () => {
if (getManager().getMode() === 'basic')
if (getManager().getMode() === 'basic')
getManager().settingsPage.show();
else
else
getManager().instancesPage.show();
});
}
}
}, () => {
getManager().setState('IDLE');
});

View File

@ -163,9 +163,15 @@ async function applyConfiguration(folder, instance) {
config["frontend"]["port"] = instance.frontendPort;
config["backend"]["port"] = instance.backendPort;
config["backend"]["address"] = instance.backendAddress;
config["authentication"]["gameMasterPassword"] = sha256(instance.gameMasterPassword);
config["authentication"]["blueCommanderPassword"] = sha256(instance.blueCommanderPassword);
config["authentication"]["redCommanderPassword"] = sha256(instance.redCommanderPassword);
if (instance.gameMasterPassword !== "")
config["authentication"]["gameMasterPassword"] = sha256(instance.gameMasterPassword);
if (instance.blueCommanderPassword !== "")
config["authentication"]["blueCommanderPassword"] = sha256(instance.blueCommanderPassword);
if (instance.redCommanderPassword !== "")
config["authentication"]["redCommanderPassword"] = sha256(instance.redCommanderPassword);
await fsp.writeFile(path.join(folder, "Config", "olympus.json"), JSON.stringify(config, null, 4));
logger.log(`Config succesfully applied in ${folder}`)

View File

@ -2,7 +2,7 @@ const path = require("path")
const fs = require("fs");
const DCSInstance = require('./dcsinstance');
const { showErrorPopup, showWaitPopup, showConfirmPopup } = require('./popup');
const { showErrorPopup, showConfirmPopup } = require('./popup');
const { logger } = require("./filesystem")
const ManagerPage = require("./managerpage");
@ -236,6 +236,17 @@ class Manager {
location.reload();
}
async setSavedGamesFolder(folder) {
var options = JSON.parse(fs.readFileSync("options.json"));
options.savedGamesFolder = folder;
fs.writeFileSync("options.json", JSON.stringify(options, null, 2));
location.reload();
}
async getOptions() {
return JSON.parse(fs.readFileSync("options.json"));
}
/************************************************/
/* CALLBACKS */
/************************************************/
@ -341,8 +352,8 @@ class Manager {
/* When the camera control installation is selected */
async onInstallCameraControlClicked(type) {
this.connectionsTypePage.getElement().querySelector(`.install`).classList.toggle("selected", type === 'install');
this.connectionsTypePage.getElement().querySelector(`.no-install`).classList.toggle("selected", type === 'no-install');
this.cameraPage.getElement().querySelector(`.install`).classList.toggle("selected", type === 'install');
this.cameraPage.getElement().querySelector(`.no-install`).classList.toggle("selected", type === 'no-install');
if (this.getActiveInstance())
this.getActiveInstance().installCameraPlugin = type;
else {
@ -406,13 +417,33 @@ class Manager {
}
/* Installation type page */
} else if (this.activePage == this.cameraPage) {
this.activePage.hide();
this.getState() === 'INSTALL' ? this.getActiveInstance().install() : this.getActiveInstance().edit();
if (await this.checkDCSRunning()) {
showConfirmPopup(`<div class='main-message'>DCS is running!</div><div class='sub-message'> Please stop the DCS instance you are trying to add Olympus to, then select <b>Accept</b></div>`, async () => {
/* Nested popup calls need to wait for animation to complete */
await sleep(300);
this.activePage.hide();
this.getState() === 'INSTALL' ? this.getActiveInstance().install() : this.getActiveInstance().edit();
});
} else {
this.activePage.hide();
this.getState() === 'INSTALL' ? this.getActiveInstance().install() : this.getActiveInstance().edit();
}
/* Expert settings page */
} else if (this.activePage == this.expertSettingsPage) {
if (await this.checkPorts() && await this.checkPasswords()) {
this.activePage.hide();
this.getState() === 'INSTALL' ? this.getActiveInstance().install() : this.getActiveInstance().edit();
if (await this.checkDCSRunning()) {
showConfirmPopup(`<div class='main-message'>DCS is running!</div><div class='sub-message'> Please stop the DCS instance you are trying to add Olympus to, then select <b>Accept</b></div>`, async () => {
/* Nested popup calls need to wait for animation to complete */
await sleep(300);
this.activePage.hide();
this.getState() === 'INSTALL' ? this.getActiveInstance().install() : this.getActiveInstance().edit();
});
} else {
this.activePage.hide();
this.getState() === 'INSTALL' ? this.getActiveInstance().install() : this.getActiveInstance().edit();
}
}
}
}
@ -541,7 +572,7 @@ class Manager {
async checkPasswords() {
if (this.getActiveInstance()) {
if (this.getActiveInstance().installed && !this.getActiveInstance().arePasswordsEdited()) {
if (this.getState() === 'EDIT' && !this.getActiveInstance().arePasswordsEdited()) {
return true;
}
else {
@ -609,10 +640,20 @@ class Manager {
var instance = await this.getClickedInstance(name);
this.setActiveInstance(instance);
await this.setState('UNINSTALL');
if (instance.webserverOnline || instance.backendOnline)
if (instance.webserverOnline || instance.backendOnline) {
showErrorPopup("<div class='main-message'>The selected Olympus instance is currently active </div><div class='sub-message'> Please stop DCS and Olympus Server/Client before removing it! </div>")
else
await instance.uninstall();
} else {
if (await this.checkDCSRunning()) {
showConfirmPopup(`<div class='main-message'>DCS is running!</div><div class='sub-message'> Please stop the DCS instance you are trying to remove Olympus from, then select <b>Accept</b></div>`, async () => {
/* Nested popup calls need to wait for animation to complete */
await sleep(300);
await instance.uninstall();
});
} else {
await instance.uninstall();
}
}
}
async onLinkClicked(url) {
@ -758,6 +799,24 @@ class Manager {
this.setActiveInstance(undefined);
}
async checkDCSRunning() {
let ps = new Promise((res, rej) => {
exec('tasklist', function(err, stdout, stderr) {
console.log(stdout)
if (stdout.toLowerCase().includes("dcs.exe") || stdout.includes("dcs_server.exe")) {
res(true);
} else {
res(false);
}
});
})
try {
return await ps;
} catch {
return false; // An error occurred, let's hope DCS is not running!
}
}
/** Get the currently active instance, i.e. the instance that is being edited/installed/removed
*
* @returns The active instance

View File

@ -8,6 +8,8 @@ let window;
/* Add the System32 folder to the environment for the shortcuts creation to work properly */
process.env['PATH'] = process.env['PATH'] + "%WINDIR%\\System32;"
require('@electron/remote/main').initialize()
function createWindow() {
const window = new electronBrowserWindow({
width: 1200,
@ -18,11 +20,13 @@ function createWindow() {
webPreferences: {
contextIsolation: true,
preload: path.join(__dirname, "javascripts", 'preload.js'),
nodeIntegration: true,
nodeIntegration: true
},
icon: "./../img/olympus_configurator.ico"
});
require("@electron/remote/main").enable(window.webContents);
window.loadFile('index.html').then(() => { window.show(); });
window.on("maximize", () => {

View File

@ -10,6 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@electron/remote": "^2.1.2",
"adm-zip": "^0.5.10",
"create-desktop-shortcuts": "^1.10.1",
"dir-compare": "^4.2.0",

View File

@ -1,7 +1,7 @@
{
"backend": {
"address": "localhost",
"port": 3001
"port": 4512
},
"authentication": {
"gameMasterPassword": "4b8823ed9e5c2392ab4a791913bb8ce41956ea32e308b760eefb97536746dd33",