Added log file

This commit is contained in:
Pax1601
2024-01-04 12:10:01 +01:00
parent 38027b6ff3
commit 7686a60bfd
13 changed files with 135 additions and 106 deletions

View File

@@ -9,6 +9,7 @@ const { spawn } = require('child_process');
const find = require('find-process');
const { uninstallInstance } = require('./filesystem')
const { showErrorPopup, showConfirmPopup } = require('./popup')
const { logger } = require("./filesystem")
class DCSInstance {
static instances = null;
@@ -51,7 +52,7 @@ class DCSInstance {
res(instances);
} else {
console.error("An error occured while trying to fetch the location of the DCS instances.")
logger.error("An error occured while trying to fetch the location of the DCS instances.")
rej("An error occured while trying to fetch the location of the DCS instances.");
}
}
@@ -92,7 +93,7 @@ class DCSInstance {
this.backendAddress = config["server"]["address"];
this.gameMasterPasswordHash = config["authentication"]["gameMasterPassword"];
} catch (err) {
console.error(err)
logger.error(err)
}
/* Compare the contents of the installed Olympus instance and the one in the root folder. Exclude the databases folder, which users can edit.
@@ -112,7 +113,7 @@ class DCSInstance {
err1 = res1.differences !== 0;
err2 = res2.differences !== 0;
} catch (e) {
console.log(e);
logger.log(e);
}
if (err1 || err2) {
@@ -155,7 +156,7 @@ class DCSInstance {
*/
async setClientPort(newPort) {
if (await this.checkClientPort(newPort)) {
console.log(`Instance ${this.folder} client port set to ${newPort}`)
logger.log(`Instance ${this.folder} client port set to ${newPort}`)
this.clientPort = newPort;
return true;
}
@@ -167,7 +168,7 @@ class DCSInstance {
*/
async setBackendPort(newPort) {
if (await this.checkBackendPort(newPort)) {
console.log(`Instance ${this.folder} client port set to ${newPort}`)
logger.log(`Instance ${this.folder} client port set to ${newPort}`)
this.backendPort = newPort;
return true;
}
@@ -212,12 +213,12 @@ class DCSInstance {
portFree = !(await DCSInstance.getInstances()).some((instance) => {
if (instance !== this && instance.installed) {
if (instance.clientPort === port || instance.backendPort === port) {
console.log(`Port ${port} already selected by other instance`);
logger.log(`Port ${port} already selected by other instance`);
return true;
}
} else {
if (instance.backendPort === port) {
console.log(`Port ${port} equal to backend port`);
logger.log(`Port ${port} equal to backend port`);
return true;
}
}
@@ -225,7 +226,7 @@ class DCSInstance {
})
}
else {
console.log(`Port ${port} currently in use`);
logger.log(`Port ${port} currently in use`);
}
res(portFree);
})
@@ -243,19 +244,19 @@ class DCSInstance {
portFree = !(await DCSInstance.getInstances()).some((instance) => {
if (instance !== this && instance.installed) {
if (instance.clientPort === port || instance.backendPort === port) {
console.log(`Port ${port} already selected by other instance`);
logger.log(`Port ${port} already selected by other instance`);
return true;
}
} else {
if (instance.clientPort === port) {
console.log(`Port ${port} equal to client port`);
logger.log(`Port ${port} equal to client port`);
return true;
}
}
return false;
})
} else {
console.log(`Port ${port} currently in use`);
logger.log(`Port ${port} currently in use`);
}
res(portFree);
})
@@ -291,13 +292,15 @@ class DCSInstance {
}, () => {
this.backendOnline = false;
}).then((text) => {
var data = JSON.parse(text);
this.fps = data.frameRate;
this.load = data.load;
if (text !== undefined) {
var data = JSON.parse(text);
this.fps = data.frameRate;
this.load = data.load;
}
}, (err) => {
console.warn(err);
logger.warn(err);
}).catch((err) => {
console.warn(err);
logger.warn(err);
});
}
}
@@ -306,7 +309,7 @@ class DCSInstance {
*
*/
startServer() {
console.log(`Starting server for instance at ${this.folder}`)
logger.log(`Starting server for instance at ${this.folder}`)
const out = fs.openSync(`./${this.name}.log`, 'a');
const err = fs.openSync(`./${this.name}.log`, 'a');
const sub = spawn('cscript.exe', ['server.vbs', path.join(this.folder, "Config", "olympus.json")], {
@@ -322,7 +325,7 @@ class DCSInstance {
*
*/
startClient() {
console.log(`Starting client for instance at ${this.folder}`)
logger.log(`Starting client for instance at ${this.folder}`)
const out = fs.openSync(`./${this.name}.log`, 'a');
const err = fs.openSync(`./${this.name}.log`, 'a');
const sub = spawn('cscript.exe', ['client.vbs', path.join(this.folder, "Config", "olympus.json")], {
@@ -339,10 +342,10 @@ class DCSInstance {
find('port', this.clientPort)
.then((list) => {
if (list.length !== 1) {
list.length === 0 ? console.error("No processes found on the specified port") : console.error("Too many processes found on the specified port");
list.length === 0 ? logger.error("No processes found on the specified port") : logger.error("Too many processes found on the specified port");
} else {
if (list[0].name.includes("node.exe")) {
console.log(`Killing process ${list[0].name}`)
logger.log(`Killing process ${list[0].name}`)
try {
process.kill(list[0].pid);
process.kill(list[0].ppid);
@@ -351,12 +354,12 @@ class DCSInstance {
}
}
else {
console.log(list[0])
console.error(`The process listening on the specified port has an incorrect name: ${list[0].name}`)
logger.log(list[0])
logger.error(`The process listening on the specified port has an incorrect name: ${list[0].name}`)
}
}
}, () => {
console.error("Error retrieving list of processes")
logger.error("Error retrieving list of processes")
})
}
@@ -368,8 +371,8 @@ class DCSInstance {
location.reload();
},
(err) => {
console.error(err)
showErrorPopup("An error has occurred while uninstalling the Olympus instance. Make sure Olympus and DCS are not running.", () => {
logger.error(err)
showErrorPopup(`An error has occurred while uninstalling the Olympus instance. Make sure Olympus and DCS are not running. <br><br> You can find more info in ${path.join(__dirname, "..", "manager.log")}`, () => {
location.reload();
});
}