From 733aa33b2aa5accf3304abce3dd670f3e1be1ff0 Mon Sep 17 00:00:00 2001 From: Raphix Date: Sat, 29 Apr 2023 20:05:31 +0200 Subject: [PATCH] 2.0.8 PreRelease Version --- main.js | 2 +- package.json | 2 +- sub-log.js | 86 +++++++++++++++++++++++++++++++++++++ sublog.js | 114 ------------------------------------------------- updatetools.js | 18 ++++---- 5 files changed, 97 insertions(+), 125 deletions(-) create mode 100644 sub-log.js delete mode 100644 sublog.js diff --git a/main.js b/main.js index 6b71ca4..1cc30f1 100644 --- a/main.js +++ b/main.js @@ -3,7 +3,7 @@ const path = require("path") const fs = require("fs") const ipc = ipcMain const { io } = require("socket.io-client"); -const log = require("./sublog"); +const log = require("./sub-log"); const updater = require("./updatetools") // [Function] Main Window Function diff --git a/package.json b/package.json index ef1720b..c920794 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "subsonics-manager", - "version": "2.0.7", + "version": "2.0.8", "description": "Manager for subsonics", "main": "main.js", "scripts": { diff --git a/sub-log.js b/sub-log.js new file mode 100644 index 0000000..8fddc6e --- /dev/null +++ b/sub-log.js @@ -0,0 +1,86 @@ +const fs = require("fs") + + +if(!fs.existsSync("logs/")) { + fs.mkdirSync("logs") + +} + + +var logStream = fs.createWriteStream("logs/" + getDate() + ".log", { + flags: 'a' +}); + +logStream.write("[" + require("./package.json").name + "@" + require("./package.json").version + "] - [" + getDate() + "]" + "\n") +logStream.write("Submanager by Raphix" + "\n") +logStream.write("----------------------------------------------------------------" + "\n") + + + +module.exports.client = (message) => { + + logStream.write("[Subsonics-Client] - " + getDate() + " - " + message + "\n") + console.log("[Subsonics-Client] - " + getDate() + " - " + message) +} + +module.exports.client.error = (message) => { + + logStream.write("[Subsonics-Client] - [ERROR] - " + getDate() + " - " + message + "\n") + console.error("[Subsonics-Client] - [ERROR] - " + getDate() + " - " + message) +} + +module.exports.update = (message) => { + + + logStream.write("[Subsonics-Update] - " + getDate() + " - " + message + "\n") + console.error("[Subsonics-Update] - " + getDate() + " - " + message) +} + + +function getDate() { + + var date = new Date() + + // [Date Format] - Format de la date + + var gmonth = date.getMonth() + var gday = date.getDate() + var gHour = date.getHours() + var gMinute = date.getMinutes() + var gSecondes = date.getSeconds() + + + if(date.getMonth() + 1 <= 9) { + gmonth = "0" + (date.getMonth() + 1) + } + + if(date.getDate() + 1 <= 9) { + gday = "0" + date.getDate() + } + + if(date.getHours() + 1 <= 9) { + gHour = "0" + date.getHours() + } + + if(date.getMinutes() + 1 <= 9) { + gMinute = "0" + date.getMinutes() + } + + if(date.getSeconds() + 1 <= 9) { + gSecondes = "0" + date.getSeconds() + } + + return date.getFullYear() + "-" + gmonth + "-" + gday + "-" + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s" +} + +process.on('uncaughtException', (err) => { + logStream.write("[" + getDate() + "] - ["+ "FATAL" + "] - [ Subsonics-Manager ]" + " The programm has encountered an error ! Please Restart ! #E = " + err + "\n") + logStream.end( "["+ "UNCAUGHT_EXCEPTION" + "]" + " - [END OF LOGS] - [" + getDate() + ']') + logStream.close() + +}); + +process.on('beforeExit', () => { + logStream.end( "["+ "NORMAL_END" + "]" + " - [END OF LOGS] - [" + getDate() + ']') + logStream.close() +}); diff --git a/sublog.js b/sublog.js deleted file mode 100644 index b52379f..0000000 --- a/sublog.js +++ /dev/null @@ -1,114 +0,0 @@ -module.exports.client = (message) => { - - var date = new Date() - - // [Date Format] - Format de la date - - var gmonth = date.getMonth() - var gday = date.getDate() - var gHour = date.getHours() - var gMinute = date.getMinutes() - var gSecondes = date.getSeconds() - - - if(date.getMonth() + 1 <= 9) { - gmonth = "0" + (date.getMonth() + 1) - } - - if(date.getDate() + 1 <= 9) { - gday = "0" + date.getDate() - } - - if(date.getHours() + 1 <= 9) { - gHour = "0" + date.getHours() - } - - if(date.getMinutes() + 1 <= 9) { - gMinute = "0" + date.getMinutes() - } - - if(date.getSeconds() + 1 <= 9) { - gSecondes = "0" + date.getSeconds() - } - - var currentDate = date.getFullYear() + "-" + gmonth + "-" + gday + "-" + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s" - - console.log("[Subsonics-Client] - " + currentDate + " - " + message) -} - -module.exports.client.error = (message) => { - - var date = new Date() - - // [Date Format] - Format de la date - - var gmonth = date.getMonth() - var gday = date.getDate() - var gHour = date.getHours() - var gMinute = date.getMinutes() - var gSecondes = date.getSeconds() - - - if(date.getMonth() + 1 <= 9) { - gmonth = "0" + (date.getMonth() + 1) - } - - if(date.getDate() + 1 <= 9) { - gday = "0" + date.getDate() - } - - if(date.getHours() + 1 <= 9) { - gHour = "0" + date.getHours() - } - - if(date.getMinutes() + 1 <= 9) { - gMinute = "0" + date.getMinutes() - } - - if(date.getSeconds() + 1 <= 9) { - gSecondes = "0" + date.getSeconds() - } - - var currentDate = date.getFullYear() + "-" + gmonth + "-" + gday + "-" + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s" - - console.error("[Subsonics-Client] - [ERROR] - " + currentDate + " - " + message) -} - -module.exports.update = (message) => { - - var date = new Date() - - // [Date Format] - Format de la date - - var gmonth = date.getMonth() - var gday = date.getDate() - var gHour = date.getHours() - var gMinute = date.getMinutes() - var gSecondes = date.getSeconds() - - - if(date.getMonth() + 1 <= 9) { - gmonth = "0" + (date.getMonth() + 1) - } - - if(date.getDate() + 1 <= 9) { - gday = "0" + date.getDate() - } - - if(date.getHours() + 1 <= 9) { - gHour = "0" + date.getHours() - } - - if(date.getMinutes() + 1 <= 9) { - gMinute = "0" + date.getMinutes() - } - - if(date.getSeconds() + 1 <= 9) { - gSecondes = "0" + date.getSeconds() - } - - var currentDate = date.getFullYear() + "-" + gmonth + "-" + gday + "-" + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s" - - console.error("[Subsonics-Update] - " + currentDate + " - " + message) -} - diff --git a/updatetools.js b/updatetools.js index 95907b5..58263b2 100644 --- a/updatetools.js +++ b/updatetools.js @@ -1,4 +1,4 @@ -const log = require("./sublog") +const log = require("./sub-log") const { BrowserWindow, app, ipcMain } = require("electron") const https = require('https'); const fs = require('fs'); @@ -43,7 +43,7 @@ function update() { app.quit() }) - log.update("Telechargement de la mise à jour ... Processing !") + log.update("Telechargement de la mise a jour ... Processing !") if(fs.existsSync(__dirname + path.sep + "update.tar.gz")) { @@ -57,14 +57,14 @@ function update() { // after download completed close filestream updatePack.on("finish", () => { updatePack.close(); - log.update("Telechargement de la mise à jour ... Finish !") + log.update("Telechargement de la mise a jour ... Finish !") install(__dirname + path.sep + "update.tar.gz") }); updatePack.on("error", (err) => { - log.update("Erreur lors du telechargement de la mise à jour !") + log.update("Erreur lors du telechargement de la mise a jour !") updatePack.close(); console.log(err) @@ -81,10 +81,10 @@ function update() { function install(filename) { - log.update("Extraction de la mise à jour ... Processing !") + log.update("Extraction de la mise a jour ... Processing !") decompress(filename, __dirname).then(files => { - log.update("Extraction de la mise à jour ... Finish !") - log.update("Installation de la mise à jour ... Processing !") + log.update("Extraction de la mise a jour ... Finish !") + log.update("Installation de la mise a jour ... Processing !") fse.copy(__dirname + path.sep + "manager", __dirname, { overwrite: true }, () => { fs.rm(filename, () => { fs.rm(__dirname + path.sep + "manager", { recursive: true, force: true }, (err) => { @@ -94,8 +94,8 @@ function install(filename) { console.log(err) } - log.update("Installation de la mise à jour ... Finish !") - log.update("Rédémarrage de l'application.") + log.update("Installation de la mise a jour ... Finish !") + log.update("Redemarrage de l'application.") app.relaunch() app.exit() })