diff options
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 95 |
1 files changed, 51 insertions, 44 deletions
@@ -49,6 +49,18 @@ const { app, BrowserWindow } = require('electron'); dlp = "en"; } + if (!require('fs').existsSync(require('os').userInfo().homedir + "/.kartik")) { + require('fs').mkdirSync(require('os').userInfo().homedir + "/.kartik") + } + + if (!require('fs').existsSync(require('os').userInfo().homedir + "/.kartik/crashes")) { + require('fs').mkdirSync(require('os').userInfo().homedir + "/.kartik/crashes") + } + + if (!require('fs').existsSync(require('os').userInfo().homedir + "/.kartik/mods")) { + require('fs').mkdirSync(require('os').userInfo().homedir + "/.kartik/mods") + } + process.on('uncaughtException', (error) => { console.log(" * Starting recovery procedure: E_ERROR"); id = new Date().toISOString().replaceAll(":", "-"); @@ -84,8 +96,9 @@ const { app, BrowserWindow } = require('electron'); console.log(" * Creating configuration"); const fs = require('fs'); + const Nest = require('./nest/abi'); - if (!fs.existsSync(homedir + "/.kartik")) { + /*if (!fs.existsSync(homedir + "/.kartik")) { fs.mkdirSync(homedir + "/.kartik"); } if (!fs.existsSync(homedir + "/.kartik/config")) { @@ -118,8 +131,24 @@ const { app, BrowserWindow } = require('electron'); } if (!fs.existsSync(homedir + "/.kartik/config/voice.txt")) { fs.writeFileSync(homedir + "/.kartik/config/voice.txt", "0"); + }*/ + + if (fs.existsSync(homedir + "/.kartik/config") && fs.existsSync(homedir + "/.kartik/config/voice.txt") && fs.existsSync(homedir + "/.kartik/config/online.txt") && fs.existsSync(homedir + "/.kartik/config/music.txt") && fs.existsSync(homedir + "/.kartik/config/lang.txt") && fs.existsSync(homedir + "/.kartik/stats.json")) { + console.log(" * Found complete Config V1, migrating to Kartik Fox Nest..."); + Nest.convert(homedir + "/.kartik/current.kfn", homedir + "/.kartik"); + } else { + if (!fs.existsSync(homedir + "/.kartik/current.kfn")) { + console.log(" * No Kartik Fox Nest found, generating one..."); + Nest.generate(homedir + "/.kartik/current.kfn"); + } } + global.currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + console.log(" * Kartik Fox Nest loaded, " + fs.readFileSync(homedir + "/.kartik/current.kfn").toString().length + " bytes, last loaded in Kartik " + currentNest._version); + + currentNest._version = require('./package.json').version; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + /* --------------------- */ console.log(" * Checking channel"); @@ -165,29 +194,7 @@ const { app, BrowserWindow } = require('electron'); console.log(" * Checking configuration"); - scale = fs.readFileSync(homedir + "/.kartik/config/scale.txt").toString().trim() - 1 + 1 - lp = fs.readFileSync(homedir + "/.kartik/config/lang.txt").toString().trim() - - if (fs.readFileSync(homedir + "/.kartik/config/online.txt").toString().trim() === "0") { - fs.writeFileSync(homedir + "/.kartik/config/online.txt", "1"); - } - - if (scale !== 1 - && scale !== 0.9 - && scale !== 1.1 - && scale !== 1.2 - && scale !== 1.3 - && scale !== 1.4 - && scale !== 1.5 - && scale !== 1.6 - && scale !== 1.7 - && scale !== 1.8 - && scale !== 1.9 - && scale !== 2 - ) { - fs.writeFileSync(homedir + "/.kartik/config/scale.txt", "1.2"); - scale = 1; - } + lp = currentNest.config.lang time = new Date() - start; console.log(" * Started successfully in " + Math.round(time/1000) + " seconds"); @@ -195,10 +202,10 @@ const { app, BrowserWindow } = require('electron'); load.close(); console.log(" * Starting recovery procedure: E_PROMISE"); global.win = new BrowserWindow({ - width: Math.round(720 * scale), - height: Math.round(540 * scale), - minWidth: Math.round(720 * scale), - minHeight: Math.round(540 * scale), + width: 1220, + height: 720, + minWidth: 720, + minHeight: 540, resizeable: true, resizable: true, maximizable: true, @@ -218,14 +225,14 @@ const { app, BrowserWindow } = require('electron'); global.shouldExitIfClosed = true; - console.log(" * Starting IPC engine"); - win.pwidth = Math.round(720 * scale); - win.pheight = Math.round(540 * scale); + win.pwidth = 720; + win.pheight = 540; win.log = console.log; win.debug = process.argv[2] === "d"; win.channel = channel; + win.scale = 1.2; win.update = dimga; win.gamepads = []; win.controllerAttached = false; @@ -236,12 +243,12 @@ const { app, BrowserWindow } = require('electron'); win.homedir = homedir; - win.scale = scale; win.lp = lp; - win.music = fs.readFileSync(homedir + "/.kartik/config/music.txt").toString().trim() === "1"; - win.voice = fs.readFileSync(homedir + "/.kartik/config/voice.txt").toString().trim() === "2"; + win.music = currentNest.config.music; + win.voice = currentNest.config.voice; - win.online = fs.readFileSync(homedir + "/.kartik/config/online.txt").toString().trim() === "1"; + win.online = currentNest.config.online; + win.nest = currentNest; win.resources = resources; global.currentSongValue = null; @@ -273,18 +280,18 @@ const { app, BrowserWindow } = require('electron'); const LevelsAPI = require('./views/script/global_levelsapi'); const lvl = new LevelsAPI(); - stats = require(homedir + "/.kartik/stats.json"); + stats = currentNest.stats; musicIpc.on('addstats', (event, value) => { - stats[value.catalog][value.key] = stats[value.catalog][value.key] + value.add; - fs.writeFile(homedir + "/.kartik/stats.json", JSON.stringify(stats), () => {}); + currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); if (value.key === "laps" && fs.existsSync(homedir + "/.kartik/authentication.json")) { - auth = JSON.parse(fs.readFileSync(homedir + "/.kartik/authentication.json").toString()); - level = lvl.correspond(stats["ingame"]["laps"], "256") - 1 + 1; + auth = currentNest.auth; + level = lvl.correspond(currentNest.stats["ingame"]["laps"], "256") - 1 + 1; if (level !== auth.level) { - auth.level = level - fs.writeFileSync(homedir + "/.kartik/authentication.json", JSON.stringify(auth)); + currentNest.auth.level = level + Nest.export(homedir + "/.kartik/current.kfn", currentNest); if (level < 200) { win.webContents.send("notification", {title: lang.polymer.levelup[0], message: lang.polymer.levelup[1] + " " + level + " " + lang.polymer.levelup[2]}); } else { @@ -294,8 +301,8 @@ const { app, BrowserWindow } = require('electron'); } }) musicIpc.on('addstatsandclose', (event, value) => { - stats[value.catalog][value.key] = stats[value.catalog][value.key] + value.add; - fs.writeFile(homedir + "/.kartik/stats.json", JSON.stringify(stats), () => {}); + currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); win.destroy(); }) }) |