From 8886d5111aa4ae75f54f46c93f09fa7548979969 Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Fri, 9 Jul 2021 00:37:48 +0200 Subject: Fixes --- app.js | 138 +++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 71 insertions(+), 67 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index 3135b2c..8e4ea52 100644 --- a/app.js +++ b/app.js @@ -302,7 +302,7 @@ const { app, BrowserWindow } = require('electron'); resizable: false, maximizable: false, frame: false, - show: true, + show: false, enableLargerThanScreen: true, icon: "logo/logo.png", backgroundColor: "#4b4e50", @@ -316,82 +316,86 @@ const { app, BrowserWindow } = require('electron'); } }) load.loadFile("./views/load.html"); - setTimeout(() => { - console.log(" * Checking signatures"); - - sigdb = require("./bin/signatures.json"); - total = Object.keys(sigdb["v1"]).length * 3; - processed = 0; - for (file in sigdb["v1"]) { - if (fs.existsSync(file)) { - try { - hash = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('base64'); - if (hash !== sigdb["v1"][file]) { - require('electron').dialog.showMessageBoxSync( - { - type: "warning", - title: "Source modification detected", - message: "File " + file + " has been flagged as modified (signing V1). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v1"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!" - } - ) + load.webContents.once('dom-ready', () => { + console.log(" * Showing splash screen"); + load.show(); + setTimeout(() => { + console.log(" * Checking signatures"); + + sigdb = require("./bin/signatures.json"); + total = Object.keys(sigdb["v1"]).length * 3; + processed = 0; + for (file in sigdb["v1"]) { + if (fs.existsSync(file)) { + try { + hash = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('base64'); + if (hash !== sigdb["v1"][file]) { + require('electron').dialog.showMessageBoxSync( + { + type: "warning", + title: "Source modification detected", + message: "File " + file + " has been flagged as modified (signing V1). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v1"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!" + } + ) + } + } catch (e) { + console.warn(" ! Could not V1 compute hash for " + file); } - } catch (e) { - console.warn(" ! Could not V1 compute hash for " + file); } - } - processed++; - load.webContents.send('progress', (processed/total)*100); - } - for (file in sigdb["v2"]) { - if (fs.existsSync(file)) { - try { - hash = require('crypto').createHash('sha1').update(fs.readFileSync(file)).digest('base64'); - if (hash !== sigdb["v2"][file]) { - require('electron').dialog.showMessageBoxSync( - { - type: "warning", - title: "Source modification detected", - message: "File " + file + " has been flagged as modified (signing V2). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v2"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!" - } - ) + processed++; + load.webContents.send('progress', (processed/total)*100); + } + for (file in sigdb["v2"]) { + if (fs.existsSync(file)) { + try { + hash = require('crypto').createHash('sha1').update(fs.readFileSync(file)).digest('base64'); + if (hash !== sigdb["v2"][file]) { + require('electron').dialog.showMessageBoxSync( + { + type: "warning", + title: "Source modification detected", + message: "File " + file + " has been flagged as modified (signing V2). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v2"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!" + } + ) + } + } catch (e) { + console.warn(" ! Could not compute V2 hash for " + file); } - } catch (e) { - console.warn(" ! Could not compute V2 hash for " + file); } - } - processed++; - load.webContents.send('progress', (processed/total)*100); - } - for (file in sigdb["v3"]) { - if (fs.existsSync(file)) { - try { - hash = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('base64'); - if (hash !== sigdb["v3"][file]) { - require('electron').dialog.showMessageBoxSync( - { - type: "warning", - title: "Source modification detected", - message: "File " + file + " has been flagged as modified (signing V3). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v3"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!" - } - ) + processed++; + load.webContents.send('progress', (processed/total)*100); + } + for (file in sigdb["v3"]) { + if (fs.existsSync(file)) { + try { + hash = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('base64'); + if (hash !== sigdb["v3"][file]) { + require('electron').dialog.showMessageBoxSync( + { + type: "warning", + title: "Source modification detected", + message: "File " + file + " has been flagged as modified (signing V3). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v3"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!" + } + ) + } + } catch (e) { + console.warn(" ! Could not compute V3 hash for " + file); } - } catch (e) { - console.warn(" ! Could not compute V3 hash for " + file); } - } - processed++; - load.webContents.send('progress', (processed/total)*100); - } + processed++; + load.webContents.send('progress', (processed/total)*100); + } - console.log(" * Generating resources pack"); - require('./modding/resources'); - console.log(" * Starting Kartik Modding Platform"); - require('./modding/parser'); - createWindow(); - }, 5000) + console.log(" * Generating resources pack"); + require('./modding/resources'); + console.log(" * Starting Kartik Modding Platform"); + require('./modding/parser'); + createWindow(); + }, 5000) + }) }) app.on('window-all-closed', () => { -- cgit From c3b756f987ffd8ca981c1e6f23435c74aad36aea Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Sat, 10 Jul 2021 16:03:26 +0200 Subject: Fixes --- app.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index 8e4ea52..30b2439 100644 --- a/app.js +++ b/app.js @@ -269,17 +269,29 @@ const { app, BrowserWindow } = require('electron'); win.webContents.send('setmusic', value); } }) - musicIpc.on('prefademusic', (event, value) => { - win.webContents.send('fademusic', value); - }) - musicIpc.on('preunfademusic', (event, value) => { - win.webContents.send('unfademusic', value); - }) + + const LevelsAPI = require('./views/script/global_levelsapi'); + const lvl = new LevelsAPI(); stats = require(homedir + "/.kartik/stats.json"); 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), () => {}); + + 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; + + if (level !== auth.level) { + auth.level = level + fs.writeFileSync(homedir + "/.kartik/authentication.json", JSON.stringify(auth)); + if (level < 200) { + win.webContents.send("notification", {title: lang.polymer.levelup[0], message: lang.polymer.levelup[1] + " " + level + " " + lang.polymer.levelup[2]}); + } else { + win.webContents.send("notification", {title: lang.polymer.finished[0], message: lang.polymer.finished[1]}); + } + } + } }) musicIpc.on('addstatsandclose', (event, value) => { stats[value.catalog][value.key] = stats[value.catalog][value.key] + value.add; -- cgit From 0f0e3de9353c06dfaabc00682b4c2fd9c5f48924 Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:12:14 +0200 Subject: Kartik Fox Nest! --- app.js | 95 +++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 51 insertions(+), 44 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index 30b2439..be9900e 100644 --- a/app.js +++ b/app.js @@ -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(); }) }) -- cgit From 44210691ee8444509ac466a362337af77f2bcd49 Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Tue, 20 Jul 2021 01:30:23 +0200 Subject: Commit --- app.js | 559 ++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 293 insertions(+), 266 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index be9900e..8e0c6a4 100644 --- a/app.js +++ b/app.js @@ -17,52 +17,14 @@ switch (require('./package.json').channel) { break; } -if (process.argv[2] === "m") { - console.log(" * *******************************************"); - console.log(" * * DATA MITIGATION MODE *"); - console.log(" * * *"); - console.log(" * * Unless you ABSOLUTELY need this, please *"); - console.log(" * * consider starting Kartik normally. *"); - console.log(" * *******************************************"); - if (!require('fs').existsSync(__dirname + "/data")) { - require('fs').mkdirSync(__dirname + "/data"); - } - global.homedir = __dirname + "/data"; -} else { - global.homedir = require('os').userInfo().homedir; -}; - global.start = new Date(); global.KartikRoot = __dirname; global.shouldExitIfClosed = false; const { app, BrowserWindow } = require('electron'); (async () => { - console.log(" * Gathering language"); - slpm = require('os-locale'); - slpw = await slpm(); - slpo = slpw.substr(0, 2); - slng = require('./lang/languages.json'); - if (Object.keys(slng).includes(slpo)) { - dlp = slpo; - } else { - 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"); + console.log(" * Starting recovery procedure: E_ERROR: " + error.message); id = new Date().toISOString().replaceAll(":", "-"); require('fs').writeFileSync(require('os').userInfo().homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash\n\n" + error.stack); @@ -77,7 +39,7 @@ const { app, BrowserWindow } = require('electron'); }) process.on('unhandledRejection', (reason) => { - console.log(" * Starting recovery procedure: E_PROMISE"); + console.log(" * Starting recovery procedure: E_PROMISE: " + reason); id = new Date().toISOString(); require('fs').writeFileSync(homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash (in promise)\n\n" + reason); @@ -91,228 +53,303 @@ const { app, BrowserWindow } = require('electron'); process.exit(2); }) + if (process.argv[2] === "m") { + console.log(" * *******************************************"); + console.log(" * * DATA MITIGATION MODE *"); + console.log(" * * *"); + console.log(" * * Unless you ABSOLUTELY need this, please *"); + console.log(" * * consider starting Kartik normally. *"); + console.log(" * *******************************************"); + if (!require('fs').existsSync(__dirname + "/data")) { + require('fs').mkdirSync(__dirname + "/data"); + } + global.homedir = __dirname + "/data"; + } else { + global.homedir = require('os').userInfo().homedir; + } + /* --------------------- */ - console.log(" * Creating configuration"); + console.log(" * Preparing application paths"); + app.setAppLogsPath(homedir + "/.kartik/logs"); + app.setPath("crashDumps", homedir + "/.kartik/dumps"); + app.setPath('userData', homedir + "/.kartik/storage"); + app.whenReady().then(async () => { + if (require('./package.json').channel !== "stable" && require('./package.json').channel !== "git") { + console.log(" * Opening save data conversion dialog"); + global.converting = true; + btn = require('electron').dialog.showMessageBoxSync( + { + type: "warning", + title: "Migrating save data to Kartik Fox Nest required", + message: "Your save data needs to be converted", + buttons: [ + "Use a new game directory (recommended)", + "Convert existing save data", + "Quit without doing anything" + ], + cancelId: 2, + detail: "Kartik Fox Nest (the new save data format) has been introduced in this version, and it requires converting from the old save data format. Because it is not possible to downgrade from Kartik Fox Nest to the old save data format, you have to choose what to do." + } + ) + + switch (btn) { + case 2: + process.exit(2); + break; + case 1: + break; + case 0: + if (process.argv[2] === "m") { + console.log(" * *******************************************"); + console.log(" * * DATA MITIGATION MODE *"); + console.log(" * * *"); + console.log(" * * Unless you ABSOLUTELY need this, please *"); + console.log(" * * consider starting Kartik normally. *"); + console.log(" * *******************************************"); + if (!require('fs').existsSync(__dirname + "/data")) { + require('fs').mkdirSync(__dirname + "/data"); + } + global.homedir = __dirname + "/data/.KartikStaging$"; + } else { + global.homedir = require('os').userInfo().homedir + "/.KartikStaging$"; + } + app.setAppLogsPath(homedir + "/.kartik/logs"); + app.setPath("crashDumps", homedir + "/.kartik/dumps"); + app.setPath('userData', homedir + "/.kartik/storage"); + if (!require('fs').existsSync(homedir)) { + require('fs').mkdirSync(homedir); + } + break; + } + } - const fs = require('fs'); - const Nest = require('./nest/abi'); + console.log(" * Gathering language"); + slpm = require('os-locale'); + slpw = await slpm(); + slpo = slpw.substr(0, 2); + slng = require('./lang/languages.json'); + if (Object.keys(slng).includes(slpo)) { + dlp = slpo; + } else { + dlp = "en"; + } - /*if (!fs.existsSync(homedir + "/.kartik")) { - fs.mkdirSync(homedir + "/.kartik"); - } - if (!fs.existsSync(homedir + "/.kartik/config")) { - fs.mkdirSync(homedir + "/.kartik/config"); - } - if (!fs.existsSync(homedir + "/.kartik/crashes")) { - fs.mkdirSync(homedir + "/.kartik/crashes"); - } - if (!fs.existsSync(homedir + "/.kartik/logs")) { - fs.mkdirSync(homedir + "/.kartik/logs"); - } - if (!fs.existsSync(homedir + "/.kartik/dumps")) { - fs.mkdirSync(homedir + "/.kartik/dumps"); - } - if (!fs.existsSync(homedir + "/.kartik/mods")) { - fs.mkdirSync(homedir + "/.kartik/mods"); - } - if (!fs.existsSync(homedir + "/.kartik/storage")) { - fs.mkdirSync(homedir + "/.kartik/storage"); - } - fs.writeFileSync(homedir + "/.kartik/config/scale.txt", "1.2"); - if (!fs.existsSync(homedir + "/.kartik/config/lang.txt")) { - fs.writeFileSync(homedir + "/.kartik/config/lang.txt", dlp); - } - if (!fs.existsSync(homedir + "/.kartik/config/music.txt")) { - fs.writeFileSync(homedir + "/.kartik/config/music.txt", "1"); - } - if (!fs.existsSync(homedir + "/.kartik/config/online.txt")) { - fs.writeFileSync(homedir + "/.kartik/config/online.txt", "1"); - } - if (!fs.existsSync(homedir + "/.kartik/config/voice.txt")) { - fs.writeFileSync(homedir + "/.kartik/config/voice.txt", "0"); - }*/ + console.log(" * Saving to " + homedir); - 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"); + if (!require('fs').existsSync(homedir + "/.kartik")) { + require('fs').mkdirSync(homedir + "/.kartik") } - } - 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); + if (!require('fs').existsSync(homedir + "/.kartik/crashes")) { + require('fs').mkdirSync(homedir + "/.kartik/crashes") + } - currentNest._version = require('./package.json').version; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); + if (!require('fs').existsSync(homedir + "/.kartik/mods")) { + require('fs').mkdirSync(homedir + "/.kartik/mods") + } - /* --------------------- */ + if (require('fs').existsSync(homedir + "/.kartik/build")) { + require('fs').rmSync(homedir + "/.kartik/build", { recursive: true }) + } + require('fs').mkdirSync(homedir + "/.kartik/build") + + console.log(" * Creating configuration"); + + const fs = require('fs'); + const Nest = require('./nest/abi'); - console.log(" * Checking channel"); - require('@electron/remote/main').initialize(); - - function createWindow () { - if (require('./package.json').channel === "stable") { - logo = "logo/logo.png"; - channel = " "; - global.dimg = "official"; - global.dimga = "stable"; - global.dchan = "Kartik Stable"; - } else if (require('./package.json').channel === "beta") { - logo = "logo/logo-beta.png"; - channel = " Beta "; - global.dimg = "beta"; - global.dimga = "beta"; - global.dchan = "Kartik Beta"; - } else if (require('./package.json').channel === "nightly") { - logo = "logo/logo-nightly.png"; - channel = " Nightly "; - global.dimg = "nightly"; - global.dimga = "nightly"; - global.dchan = "Kartik Nightly"; - } else if (require('./package.json').channel === "eap") { - logo = "logo/logo-eap.png"; - channel = " EAP "; - global.dimg = "eap"; - global.dimga = "eap"; - global.dchan = "Kartik EAP"; - } else if (require('./package.json').channel === "git") { - logo = "logo/logo-git.png"; - channel = " Trunk "; - global.dimg = "git"; - global.dimga = "git"; - global.dchan = "Kartik Trunk"; - try { - pk = require('./package.json'); - pk.version = require('fs').readFileSync("./.git/refs/heads/trunk").toString().substr(0, 7); - fs.writeFileSync("./package.json", JSON.stringify(pk, 2)) - } catch (e) {} + 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"); + } else { + fs.copyFileSync(homedir + "/.kartik/current.kfn", homedir + "/.kartik/latest.kfn"); + } } - console.log(" * Checking configuration"); - - lp = currentNest.config.lang - - time = new Date() - start; - console.log(" * Started successfully in " + Math.round(time/1000) + " seconds"); - console.log(" * Why are you EVEN reading this?"); - load.close(); - console.log(" * Starting recovery procedure: E_PROMISE"); - global.win = new BrowserWindow({ - width: 1220, - height: 720, - minWidth: 720, - minHeight: 540, - resizeable: true, - resizable: true, - maximizable: true, - show: false, - enableLargerThanScreen: true, - icon: logo, - backgroundColor: "#000000", - title: "Kartik", - webPreferences: { - nodeIntegration: true, - contextIsolation: false, - enableRemoteModule: true, - webviewTag: true, - disableBlinkFeatures: "MediaSessionService", + 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"); + require('@electron/remote/main').initialize(); + + function createWindow () { + if (require('./package.json').channel === "stable") { + logo = "logo/logo.png"; + channel = " "; + global.dimg = "official"; + global.dimga = "stable"; + global.dchan = "Kartik Stable"; + } else if (require('./package.json').channel === "beta") { + logo = "logo/logo-beta.png"; + channel = " Beta "; + global.dimg = "beta"; + global.dimga = "beta"; + global.dchan = "Kartik Beta"; + } else if (require('./package.json').channel === "nightly") { + logo = "logo/logo-nightly.png"; + channel = " Nightly "; + global.dimg = "nightly"; + global.dimga = "nightly"; + global.dchan = "Kartik Nightly"; + } else if (require('./package.json').channel === "eap") { + logo = "logo/logo-eap.png"; + channel = " EAP "; + global.dimg = "eap"; + global.dimga = "eap"; + global.dchan = "Kartik EAP"; + } else if (require('./package.json').channel === "git") { + logo = "logo/logo-git.png"; + channel = " Trunk "; + global.dimg = "git"; + global.dimga = "git"; + global.dchan = "Kartik Trunk"; + try { + pk = require('./package.json'); + pk.version = require('fs').readFileSync("./.git/refs/heads/trunk").toString().substr(0, 7); + fs.writeFileSync("./package.json", JSON.stringify(pk, 2)) + } catch (e) {} } - }) - global.shouldExitIfClosed = true; - - console.log(" * Starting IPC engine"); - 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; - win.webview = null; - win.dstate = "Kartik"; - win.ddetails = "Kartik"; - win.mods = mods; - - win.homedir = homedir; - - win.lp = lp; - win.music = currentNest.config.music; - win.voice = currentNest.config.voice; - - win.online = currentNest.config.online; - win.nest = currentNest; - - win.resources = resources; - global.currentSongValue = null; - - console.log(" * Starting language preloader"); - require('./lang/preload.js'); - console.log(" * Starting Discord RPC"); - require('./discord/client.js'); - - console.log(" * Loading view"); - win.loadFile('./index.html') - win.setMenu(null); - - if (win.debug) { - console.log(" * *******************************************"); - console.log(" * * KARTIK DEBUG MODE *"); - console.log(" * *******************************************"); - win.openDevTools(); - } - - win.webContents.on('dom-ready', () => { - musicIpc = require('electron').ipcMain; - musicIpc.on('newmusic', (event, value) => { - if (music) { - win.webContents.send('setmusic', value); + console.log(" * Checking configuration"); + + lp = currentNest.config.lang + + time = new Date() - start; + console.log(" * Started successfully in " + Math.round(time/1000) + " seconds"); + console.log(" * Why are you EVEN reading this?"); + try { load.close(); } catch (e) {} + console.log(" * Starting recovery procedure: E_PROMISE"); + global.win = new BrowserWindow({ + width: 1220, + height: 720, + minWidth: 720, + minHeight: 540, + resizeable: true, + resizable: true, + maximizable: true, + show: false, + enableLargerThanScreen: true, + icon: logo, + backgroundColor: "#000000", + title: "Kartik", + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + enableRemoteModule: true, + webviewTag: true, + disableBlinkFeatures: "MediaSessionService", } }) - const LevelsAPI = require('./views/script/global_levelsapi'); - const lvl = new LevelsAPI(); - - stats = currentNest.stats; - musicIpc.on('addstats', (event, value) => { - 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 = currentNest.auth; - level = lvl.correspond(currentNest.stats["ingame"]["laps"], "256") - 1 + 1; - - if (level !== auth.level) { - 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 { - win.webContents.send("notification", {title: lang.polymer.finished[0], message: lang.polymer.finished[1]}); + global.shouldExitIfClosed = true; + + console.log(" * Starting IPC engine"); + win.pwidth = 720; + win.pheight = 540; + win.log = console.log; + + win.debug = process.argv[2] === "d"; + win.channel = channel; + win.cmdlineargs = process.argv; + win.scale = 1.2; + win.update = dimga; + win.gamepads = []; + win.controllerAttached = false; + win.webview = null; + win.dstate = "Kartik"; + win.ddetails = "Kartik"; + win.mods = mods; + + win.invalidfiles = invalidfiles; + win.modsfiles = compiledTypeScriptFiles; + win.homedir = homedir; + + win.lp = lp; + win.music = currentNest.config.music; + win.voice = currentNest.config.voice; + + win.online = currentNest.config.online; + win.nest = currentNest; + + win.resources = resources; + global.currentSongValue = null; + + console.log(" * Starting language preloader"); + require('./lang/preload.js'); + console.log(" * Starting Discord RPC"); + require('./discord/client.js'); + + console.log(" * Loading view"); + win.loadFile('./index.html') + win.setMenu(null); + + if (win.debug) { + console.log(" * *******************************************"); + console.log(" * * KARTIK DEBUG MODE *"); + console.log(" * *******************************************"); + win.openDevTools(); + } + + win.webContents.on('dom-ready', () => { + musicIpc = require('electron').ipcMain; + musicIpc.on('newmusic', (event, value) => { + if (music) { + win.webContents.send('setmusic', value); + } + }) + + musicIpc.on('reloadNest', (event) => { + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + }) + + const LevelsAPI = require('./views/script/global_levelsapi'); + const lvl = new LevelsAPI(); + + stats = currentNest.stats; + musicIpc.on('addstats', (event, value) => { + currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + + if (value.key === "laps" && currentNest.auth) { + auth = currentNest.auth; + level = lvl.correspond(currentNest.stats["ingame"]["laps"], "256") - 1 + 1; + + if (level !== auth.level) { + currentNest.auth.level = level; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + if (level < 200) { + win.webContents.send("notification", {title: lang.polymer.levelup[0], message: lang.polymer.levelup[1] + " " + level + " " + lang.polymer.levelup[2]}); + } else { + win.webContents.send("notification", {title: lang.polymer.finished[0], message: lang.polymer.finished[1]}); + } } } - } + }) + musicIpc.on('addstatsandclose', (event, value) => { + currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + win.destroy(); + }) }) - musicIpc.on('addstatsandclose', (event, value) => { - currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - win.destroy(); - }) - }) - } + } - console.log(" * Preparing application paths"); - app.setAppLogsPath(homedir + "/.kartik/logs"); - app.setPath("crashDumps", homedir + "/.kartik/dumps"); - app.setPath('userData', homedir + "/.kartik/storage"); - app.whenReady().then(() => { console.log(" * Starting splash screen"); global.load = new BrowserWindow({ width: 640, @@ -341,24 +378,20 @@ const { app, BrowserWindow } = require('electron'); setTimeout(() => { console.log(" * Checking signatures"); + invalidfiles = []; + sigdb = require("./bin/signatures.json"); total = Object.keys(sigdb["v1"]).length * 3; processed = 0; for (file in sigdb["v1"]) { - if (fs.existsSync(file)) { + if (fs.existsSync(file) && !invalidfiles.includes(file)) { try { hash = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('base64'); if (hash !== sigdb["v1"][file]) { - require('electron').dialog.showMessageBoxSync( - { - type: "warning", - title: "Source modification detected", - message: "File " + file + " has been flagged as modified (signing V1). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v1"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!" - } - ) + invalidfiles.push(file); } } catch (e) { - console.warn(" ! Could not V1 compute hash for " + file); + console.warn(" ! Could not compute V1 hash for " + file); } } @@ -366,17 +399,11 @@ const { app, BrowserWindow } = require('electron'); load.webContents.send('progress', (processed/total)*100); } for (file in sigdb["v2"]) { - if (fs.existsSync(file)) { + if (fs.existsSync(file) && !invalidfiles.includes(file)) { try { hash = require('crypto').createHash('sha1').update(fs.readFileSync(file)).digest('base64'); if (hash !== sigdb["v2"][file]) { - require('electron').dialog.showMessageBoxSync( - { - type: "warning", - title: "Source modification detected", - message: "File " + file + " has been flagged as modified (signing V2). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v2"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!" - } - ) + invalidfiles.push(file); } } catch (e) { console.warn(" ! Could not compute V2 hash for " + file); @@ -387,17 +414,11 @@ const { app, BrowserWindow } = require('electron'); load.webContents.send('progress', (processed/total)*100); } for (file in sigdb["v3"]) { - if (fs.existsSync(file)) { + if (fs.existsSync(file) && !invalidfiles.includes(file)) { try { hash = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('base64'); if (hash !== sigdb["v3"][file]) { - require('electron').dialog.showMessageBoxSync( - { - type: "warning", - title: "Source modification detected", - message: "File " + file + " has been flagged as modified (signing V3). If this is normal, please run the signing process again.\n\nExpected: " + sigdb["v3"][file] + "\nGot: " + hash + "\n\nYou are running a modified version of Kartik, do not expect to get support!" - } - ) + invalidfiles.push(file); } } catch (e) { console.warn(" ! Could not compute V3 hash for " + file); @@ -408,10 +429,16 @@ const { app, BrowserWindow } = require('electron'); load.webContents.send('progress', (processed/total)*100); } + global.importedTypeScriptFiles = []; + global.compiledTypeScriptFiles = []; console.log(" * Generating resources pack"); require('./modding/resources'); console.log(" * Starting Kartik Modding Platform"); require('./modding/parser'); + console.log(" * Compiling KMP API TypeScript files"); + require('./modding/compiler'); + console.log(" * Loading KMP TypeScript mods"); + require('./typescript/preloader'); createWindow(); }, 5000) }) -- cgit From d5a620cf09b835db2bccd99556525c90b458719f Mon Sep 17 00:00:00 2001 From: Minteck Date: Thu, 5 Aug 2021 17:21:23 +0200 Subject: i18n for 21.08 --- app.js | 906 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 453 insertions(+), 453 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index 8e0c6a4..47a7901 100644 --- a/app.js +++ b/app.js @@ -1,453 +1,453 @@ -console.log(" _ __ _ _ _ \n| |/ /__ _ _ __| |_(_) | __\n| ' // _` | '__| __| | |/ /\n| . \\ (_| | | | |_| | < \n|_|\\_\\__,_|_| \\__|_|_|\\_\\\n "); -switch (require('./package.json').channel) { - case "stable": - console.log(" Kartik " + require('./package.json').version + " (Official Release) [stable]\n"); - break; - case "eap": - console.log(" Kartik " + require('./package.json').version + " (Early Access Release) [eap]\n"); - break; - case "nightly": - console.log(" Kartik " + require('./package.json').version + " (Rawhide Release) [nightly]\n"); - break; - case "beta": - console.log(" Kartik " + require('./package.json').version + " (Branched Release) [beta]\n"); - break; - case "git": - console.log(" Kartik " + require('./package.json').version + " (Trunk Build) [git]\n"); - break; -} - -global.start = new Date(); -global.KartikRoot = __dirname; -global.shouldExitIfClosed = false; -const { app, BrowserWindow } = require('electron'); - -(async () => { - process.on('uncaughtException', (error) => { - console.log(" * Starting recovery procedure: E_ERROR: " + error.message); - id = new Date().toISOString().replaceAll(":", "-"); - - require('fs').writeFileSync(require('os').userInfo().homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash\n\n" + error.stack); - if (require('os').platform() === "win32") { - require('child_process').exec("runtime\\kartik-crash.bat " + id); - } else if (require('os').platform() === "darwin") { - require('child_process').exec("./runtime/kartik-crash-mac.sh " + id); - } else { - require('child_process').exec("./runtime/kartik-crash.sh " + id); - } - process.exit(2); - }) - - process.on('unhandledRejection', (reason) => { - console.log(" * Starting recovery procedure: E_PROMISE: " + reason); - id = new Date().toISOString(); - - require('fs').writeFileSync(homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash (in promise)\n\n" + reason); - if (require('os').platform() === "win32") { - require('child_process').exec("runtime\\kartik-crash.bat"); - } else if (require('os').platform() === "darwin") { - require('child_process').exec("./runtime/kartik-crash-mac.sh"); - } else { - require('child_process').exec("./runtime/kartik-crash.sh"); - } - process.exit(2); - }) - - if (process.argv[2] === "m") { - console.log(" * *******************************************"); - console.log(" * * DATA MITIGATION MODE *"); - console.log(" * * *"); - console.log(" * * Unless you ABSOLUTELY need this, please *"); - console.log(" * * consider starting Kartik normally. *"); - console.log(" * *******************************************"); - if (!require('fs').existsSync(__dirname + "/data")) { - require('fs').mkdirSync(__dirname + "/data"); - } - global.homedir = __dirname + "/data"; - } else { - global.homedir = require('os').userInfo().homedir; - } - - /* --------------------- */ - - console.log(" * Preparing application paths"); - app.setAppLogsPath(homedir + "/.kartik/logs"); - app.setPath("crashDumps", homedir + "/.kartik/dumps"); - app.setPath('userData', homedir + "/.kartik/storage"); - app.whenReady().then(async () => { - if (require('./package.json').channel !== "stable" && require('./package.json').channel !== "git") { - console.log(" * Opening save data conversion dialog"); - global.converting = true; - btn = require('electron').dialog.showMessageBoxSync( - { - type: "warning", - title: "Migrating save data to Kartik Fox Nest required", - message: "Your save data needs to be converted", - buttons: [ - "Use a new game directory (recommended)", - "Convert existing save data", - "Quit without doing anything" - ], - cancelId: 2, - detail: "Kartik Fox Nest (the new save data format) has been introduced in this version, and it requires converting from the old save data format. Because it is not possible to downgrade from Kartik Fox Nest to the old save data format, you have to choose what to do." - } - ) - - switch (btn) { - case 2: - process.exit(2); - break; - case 1: - break; - case 0: - if (process.argv[2] === "m") { - console.log(" * *******************************************"); - console.log(" * * DATA MITIGATION MODE *"); - console.log(" * * *"); - console.log(" * * Unless you ABSOLUTELY need this, please *"); - console.log(" * * consider starting Kartik normally. *"); - console.log(" * *******************************************"); - if (!require('fs').existsSync(__dirname + "/data")) { - require('fs').mkdirSync(__dirname + "/data"); - } - global.homedir = __dirname + "/data/.KartikStaging$"; - } else { - global.homedir = require('os').userInfo().homedir + "/.KartikStaging$"; - } - app.setAppLogsPath(homedir + "/.kartik/logs"); - app.setPath("crashDumps", homedir + "/.kartik/dumps"); - app.setPath('userData', homedir + "/.kartik/storage"); - if (!require('fs').existsSync(homedir)) { - require('fs').mkdirSync(homedir); - } - break; - } - } - - console.log(" * Gathering language"); - slpm = require('os-locale'); - slpw = await slpm(); - slpo = slpw.substr(0, 2); - slng = require('./lang/languages.json'); - if (Object.keys(slng).includes(slpo)) { - dlp = slpo; - } else { - dlp = "en"; - } - - console.log(" * Saving to " + homedir); - - if (!require('fs').existsSync(homedir + "/.kartik")) { - require('fs').mkdirSync(homedir + "/.kartik") - } - - if (!require('fs').existsSync(homedir + "/.kartik/crashes")) { - require('fs').mkdirSync(homedir + "/.kartik/crashes") - } - - if (!require('fs').existsSync(homedir + "/.kartik/mods")) { - require('fs').mkdirSync(homedir + "/.kartik/mods") - } - - if (require('fs').existsSync(homedir + "/.kartik/build")) { - require('fs').rmSync(homedir + "/.kartik/build", { recursive: true }) - } - require('fs').mkdirSync(homedir + "/.kartik/build") - - console.log(" * Creating configuration"); - - const fs = require('fs'); - const Nest = require('./nest/abi'); - - 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"); - } else { - fs.copyFileSync(homedir + "/.kartik/current.kfn", homedir + "/.kartik/latest.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"); - require('@electron/remote/main').initialize(); - - function createWindow () { - if (require('./package.json').channel === "stable") { - logo = "logo/logo.png"; - channel = " "; - global.dimg = "official"; - global.dimga = "stable"; - global.dchan = "Kartik Stable"; - } else if (require('./package.json').channel === "beta") { - logo = "logo/logo-beta.png"; - channel = " Beta "; - global.dimg = "beta"; - global.dimga = "beta"; - global.dchan = "Kartik Beta"; - } else if (require('./package.json').channel === "nightly") { - logo = "logo/logo-nightly.png"; - channel = " Nightly "; - global.dimg = "nightly"; - global.dimga = "nightly"; - global.dchan = "Kartik Nightly"; - } else if (require('./package.json').channel === "eap") { - logo = "logo/logo-eap.png"; - channel = " EAP "; - global.dimg = "eap"; - global.dimga = "eap"; - global.dchan = "Kartik EAP"; - } else if (require('./package.json').channel === "git") { - logo = "logo/logo-git.png"; - channel = " Trunk "; - global.dimg = "git"; - global.dimga = "git"; - global.dchan = "Kartik Trunk"; - try { - pk = require('./package.json'); - pk.version = require('fs').readFileSync("./.git/refs/heads/trunk").toString().substr(0, 7); - fs.writeFileSync("./package.json", JSON.stringify(pk, 2)) - } catch (e) {} - } - - console.log(" * Checking configuration"); - - lp = currentNest.config.lang - - time = new Date() - start; - console.log(" * Started successfully in " + Math.round(time/1000) + " seconds"); - console.log(" * Why are you EVEN reading this?"); - try { load.close(); } catch (e) {} - console.log(" * Starting recovery procedure: E_PROMISE"); - global.win = new BrowserWindow({ - width: 1220, - height: 720, - minWidth: 720, - minHeight: 540, - resizeable: true, - resizable: true, - maximizable: true, - show: false, - enableLargerThanScreen: true, - icon: logo, - backgroundColor: "#000000", - title: "Kartik", - webPreferences: { - nodeIntegration: true, - contextIsolation: false, - enableRemoteModule: true, - webviewTag: true, - disableBlinkFeatures: "MediaSessionService", - } - }) - - global.shouldExitIfClosed = true; - - console.log(" * Starting IPC engine"); - win.pwidth = 720; - win.pheight = 540; - win.log = console.log; - - win.debug = process.argv[2] === "d"; - win.channel = channel; - win.cmdlineargs = process.argv; - win.scale = 1.2; - win.update = dimga; - win.gamepads = []; - win.controllerAttached = false; - win.webview = null; - win.dstate = "Kartik"; - win.ddetails = "Kartik"; - win.mods = mods; - - win.invalidfiles = invalidfiles; - win.modsfiles = compiledTypeScriptFiles; - win.homedir = homedir; - - win.lp = lp; - win.music = currentNest.config.music; - win.voice = currentNest.config.voice; - - win.online = currentNest.config.online; - win.nest = currentNest; - - win.resources = resources; - global.currentSongValue = null; - - console.log(" * Starting language preloader"); - require('./lang/preload.js'); - console.log(" * Starting Discord RPC"); - require('./discord/client.js'); - - console.log(" * Loading view"); - win.loadFile('./index.html') - win.setMenu(null); - - if (win.debug) { - console.log(" * *******************************************"); - console.log(" * * KARTIK DEBUG MODE *"); - console.log(" * *******************************************"); - win.openDevTools(); - } - - win.webContents.on('dom-ready', () => { - musicIpc = require('electron').ipcMain; - musicIpc.on('newmusic', (event, value) => { - if (music) { - win.webContents.send('setmusic', value); - } - }) - - musicIpc.on('reloadNest', (event) => { - currentNest = Nest.load(homedir + "/.kartik/current.kfn"); - win.nest = currentNest; - }) - - const LevelsAPI = require('./views/script/global_levelsapi'); - const lvl = new LevelsAPI(); - - stats = currentNest.stats; - musicIpc.on('addstats', (event, value) => { - currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - currentNest = Nest.load(homedir + "/.kartik/current.kfn"); - win.nest = currentNest; - - if (value.key === "laps" && currentNest.auth) { - auth = currentNest.auth; - level = lvl.correspond(currentNest.stats["ingame"]["laps"], "256") - 1 + 1; - - if (level !== auth.level) { - currentNest.auth.level = level; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - currentNest = Nest.load(homedir + "/.kartik/current.kfn"); - win.nest = currentNest; - if (level < 200) { - win.webContents.send("notification", {title: lang.polymer.levelup[0], message: lang.polymer.levelup[1] + " " + level + " " + lang.polymer.levelup[2]}); - } else { - win.webContents.send("notification", {title: lang.polymer.finished[0], message: lang.polymer.finished[1]}); - } - } - } - }) - musicIpc.on('addstatsandclose', (event, value) => { - currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - currentNest = Nest.load(homedir + "/.kartik/current.kfn"); - win.nest = currentNest; - win.destroy(); - }) - }) - } - - console.log(" * Starting splash screen"); - global.load = new BrowserWindow({ - width: 640, - height: 400, - resizeable: false, - resizable: false, - maximizable: false, - frame: false, - show: false, - enableLargerThanScreen: true, - icon: "logo/logo.png", - backgroundColor: "#4b4e50", - title: "Kartik", - webPreferences: { - nodeIntegration: true, - contextIsolation: false, - enableRemoteModule: true, - webviewTag: true, - disableBlinkFeatures: "MediaSessionService", - } - }) - load.loadFile("./views/load.html"); - load.webContents.once('dom-ready', () => { - console.log(" * Showing splash screen"); - load.show(); - setTimeout(() => { - console.log(" * Checking signatures"); - - invalidfiles = []; - - sigdb = require("./bin/signatures.json"); - total = Object.keys(sigdb["v1"]).length * 3; - processed = 0; - for (file in sigdb["v1"]) { - if (fs.existsSync(file) && !invalidfiles.includes(file)) { - try { - hash = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('base64'); - if (hash !== sigdb["v1"][file]) { - invalidfiles.push(file); - } - } catch (e) { - console.warn(" ! Could not compute V1 hash for " + file); - } - } - - processed++; - load.webContents.send('progress', (processed/total)*100); - } - for (file in sigdb["v2"]) { - if (fs.existsSync(file) && !invalidfiles.includes(file)) { - try { - hash = require('crypto').createHash('sha1').update(fs.readFileSync(file)).digest('base64'); - if (hash !== sigdb["v2"][file]) { - invalidfiles.push(file); - } - } catch (e) { - console.warn(" ! Could not compute V2 hash for " + file); - } - } - - processed++; - load.webContents.send('progress', (processed/total)*100); - } - for (file in sigdb["v3"]) { - if (fs.existsSync(file) && !invalidfiles.includes(file)) { - try { - hash = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('base64'); - if (hash !== sigdb["v3"][file]) { - invalidfiles.push(file); - } - } catch (e) { - console.warn(" ! Could not compute V3 hash for " + file); - } - } - - processed++; - load.webContents.send('progress', (processed/total)*100); - } - - global.importedTypeScriptFiles = []; - global.compiledTypeScriptFiles = []; - console.log(" * Generating resources pack"); - require('./modding/resources'); - console.log(" * Starting Kartik Modding Platform"); - require('./modding/parser'); - console.log(" * Compiling KMP API TypeScript files"); - require('./modding/compiler'); - console.log(" * Loading KMP TypeScript mods"); - require('./typescript/preloader'); - createWindow(); - }, 5000) - }) - }) - - app.on('window-all-closed', () => { - if (shouldExitIfClosed) { - console.log(" * Bye!"); - app.quit() - } - }) -})(); +console.log(" _ __ _ _ _ \n| |/ /__ _ _ __| |_(_) | __\n| ' // _` | '__| __| | |/ /\n| . \\ (_| | | | |_| | < \n|_|\\_\\__,_|_| \\__|_|_|\\_\\\n "); +switch (require('./package.json').channel) { + case "stable": + console.log(" Kartik " + require('./package.json').version + " (Official Release) [stable]\n"); + break; + case "eap": + console.log(" Kartik " + require('./package.json').version + " (Early Access Release) [eap]\n"); + break; + case "nightly": + console.log(" Kartik " + require('./package.json').version + " (Rawhide Release) [nightly]\n"); + break; + case "beta": + console.log(" Kartik " + require('./package.json').version + " (Branched Release) [beta]\n"); + break; + case "git": + console.log(" Kartik " + require('./package.json').version + " (Trunk Build) [git]\n"); + break; +} + +global.start = new Date(); +global.KartikRoot = __dirname; +global.shouldExitIfClosed = false; +const { app, BrowserWindow } = require('electron'); + +(async () => { + process.on('uncaughtException', (error) => { + console.log(" * Starting recovery procedure: E_ERROR: " + error.message); + id = new Date().toISOString().replaceAll(":", "-"); + + require('fs').writeFileSync(require('os').userInfo().homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash\n\n" + error.stack); + if (require('os').platform() === "win32") { + require('child_process').exec("runtime\\kartik-crash.bat " + id); + } else if (require('os').platform() === "darwin") { + require('child_process').exec("./runtime/kartik-crash-mac.sh " + id); + } else { + require('child_process').exec("./runtime/kartik-crash.sh " + id); + } + process.exit(2); + }) + + process.on('unhandledRejection', (reason) => { + console.log(" * Starting recovery procedure: E_PROMISE: " + reason); + id = new Date().toISOString(); + + require('fs').writeFileSync(homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash (in promise)\n\n" + reason); + if (require('os').platform() === "win32") { + require('child_process').exec("runtime\\kartik-crash.bat"); + } else if (require('os').platform() === "darwin") { + require('child_process').exec("./runtime/kartik-crash-mac.sh"); + } else { + require('child_process').exec("./runtime/kartik-crash.sh"); + } + process.exit(2); + }) + + if (process.argv[2] === "m") { + console.log(" * *******************************************"); + console.log(" * * DATA MITIGATION MODE *"); + console.log(" * * *"); + console.log(" * * Unless you ABSOLUTELY need this, please *"); + console.log(" * * consider starting Kartik normally. *"); + console.log(" * *******************************************"); + if (!require('fs').existsSync(__dirname + "/data")) { + require('fs').mkdirSync(__dirname + "/data"); + } + global.homedir = __dirname + "/data"; + } else { + global.homedir = require('os').userInfo().homedir; + } + + /* --------------------- */ + + console.log(" * Preparing application paths"); + app.setAppLogsPath(homedir + "/.kartik/logs"); + app.setPath("crashDumps", homedir + "/.kartik/dumps"); + app.setPath('userData', homedir + "/.kartik/storage"); + app.whenReady().then(async () => { + if (require('./package.json').channel !== "stable" && require('./package.json').channel !== "git") { + console.log(" * Opening save data conversion dialog"); + global.converting = true; + btn = require('electron').dialog.showMessageBoxSync( + { + type: "warning", + title: "Migrating save data to Kartik Fox Nest required", + message: "Your save data needs to be converted", + buttons: [ + "Use a new game directory (recommended)", + "Convert existing save data", + "Quit without doing anything" + ], + cancelId: 2, + detail: "Kartik Fox Nest (the new save data format) has been introduced in this version, and it requires converting from the old save data format. Because it is not possible to downgrade from Kartik Fox Nest to the old save data format, you have to choose what to do." + } + ) + + switch (btn) { + case 2: + process.exit(2); + break; + case 1: + break; + case 0: + if (process.argv[2] === "m") { + console.log(" * *******************************************"); + console.log(" * * DATA MITIGATION MODE *"); + console.log(" * * *"); + console.log(" * * Unless you ABSOLUTELY need this, please *"); + console.log(" * * consider starting Kartik normally. *"); + console.log(" * *******************************************"); + if (!require('fs').existsSync(__dirname + "/data")) { + require('fs').mkdirSync(__dirname + "/data"); + } + global.homedir = __dirname + "/data/.KartikStaging$"; + } else { + global.homedir = require('os').userInfo().homedir + "/.KartikStaging$"; + } + app.setAppLogsPath(homedir + "/.kartik/logs"); + app.setPath("crashDumps", homedir + "/.kartik/dumps"); + app.setPath('userData', homedir + "/.kartik/storage"); + if (!require('fs').existsSync(homedir)) { + require('fs').mkdirSync(homedir); + } + break; + } + } + + console.log(" * Gathering language"); + slpm = require('os-locale'); + slpw = await slpm(); + slpo = slpw.substr(0, 2); + slng = require('./lang/languages.json'); + if (Object.keys(slng).includes(slpo)) { + dlp = slpo; + } else { + dlp = "en"; + } + + console.log(" * Saving to " + homedir); + + if (!require('fs').existsSync(homedir + "/.kartik")) { + require('fs').mkdirSync(homedir + "/.kartik") + } + + if (!require('fs').existsSync(homedir + "/.kartik/crashes")) { + require('fs').mkdirSync(homedir + "/.kartik/crashes") + } + + if (!require('fs').existsSync(homedir + "/.kartik/mods")) { + require('fs').mkdirSync(homedir + "/.kartik/mods") + } + + if (require('fs').existsSync(homedir + "/.kartik/build")) { + require('fs').rmSync(homedir + "/.kartik/build", { recursive: true }) + } + require('fs').mkdirSync(homedir + "/.kartik/build") + + console.log(" * Creating configuration"); + + const fs = require('fs'); + const Nest = require('./nest/abi'); + + 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"); + } else { + fs.copyFileSync(homedir + "/.kartik/current.kfn", homedir + "/.kartik/latest.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"); + require('@electron/remote/main').initialize(); + + function createWindow () { + if (require('./package.json').channel === "stable") { + logo = "logo/logo.png"; + channel = " "; + global.dimg = "official"; + global.dimga = "stable"; + global.dchan = "Kartik Stable"; + } else if (require('./package.json').channel === "beta") { + logo = "logo/logo-beta.png"; + channel = " Beta "; + global.dimg = "beta"; + global.dimga = "beta"; + global.dchan = "Kartik Beta"; + } else if (require('./package.json').channel === "nightly") { + logo = "logo/logo-nightly.png"; + channel = " Nightly "; + global.dimg = "nightly"; + global.dimga = "nightly"; + global.dchan = "Kartik Nightly"; + } else if (require('./package.json').channel === "eap") { + logo = "logo/logo-eap.png"; + channel = " EAP "; + global.dimg = "eap"; + global.dimga = "eap"; + global.dchan = "Kartik EAP"; + } else if (require('./package.json').channel === "git") { + logo = "logo/logo-git.png"; + channel = " Trunk "; + global.dimg = "git"; + global.dimga = "git"; + global.dchan = "Kartik Trunk"; + try { + pk = require('./package.json'); + pk.version = require('fs').readFileSync("./.git/refs/heads/trunk").toString().substr(0, 7); + fs.writeFileSync("./package.json", JSON.stringify(pk, 2)) + } catch (e) {} + } + + console.log(" * Checking configuration"); + + lp = currentNest.config.lang + + time = new Date() - start; + console.log(" * Started successfully in " + Math.round(time/1000) + " seconds"); + console.log(" * Why are you EVEN reading this?"); + try { load.close(); } catch (e) {} + console.log(" * Starting recovery procedure: E_PROMISE"); + global.win = new BrowserWindow({ + width: 1220, + height: 720, + minWidth: 720, + minHeight: 540, + resizeable: true, + resizable: true, + maximizable: true, + show: false, + enableLargerThanScreen: true, + icon: logo, + backgroundColor: "#000000", + title: "Kartik", + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + enableRemoteModule: true, + webviewTag: true, + disableBlinkFeatures: "MediaSessionService", + } + }) + + global.shouldExitIfClosed = true; + + console.log(" * Starting IPC engine"); + win.pwidth = 720; + win.pheight = 540; + win.log = console.log; + + win.debug = process.argv[2] === "d"; + win.channel = channel; + win.cmdlineargs = process.argv; + win.scale = 1.2; + win.update = dimga; + win.gamepads = []; + win.controllerAttached = false; + win.webview = null; + win.dstate = "Kartik"; + win.ddetails = "Kartik"; + win.mods = mods; + + win.invalidfiles = invalidfiles; + win.modsfiles = compiledTypeScriptFiles; + win.homedir = homedir; + + win.lp = lp; + win.music = currentNest.config.music; + win.voice = currentNest.config.voice; + + win.online = currentNest.config.online; + win.nest = currentNest; + + win.resources = resources; + global.currentSongValue = null; + + console.log(" * Starting language preloader"); + require('./lang/preload.js'); + console.log(" * Starting Discord RPC"); + require('./discord/client.js'); + + console.log(" * Loading view"); + win.loadFile('./index.html') + win.setMenu(null); + + if (win.debug) { + console.log(" * *******************************************"); + console.log(" * * KARTIK DEBUG MODE *"); + console.log(" * *******************************************"); + win.openDevTools(); + } + + win.webContents.on('dom-ready', () => { + musicIpc = require('electron').ipcMain; + musicIpc.on('newmusic', (event, value) => { + if (music) { + win.webContents.send('setmusic', value); + } + }) + + musicIpc.on('reloadNest', (event) => { + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + }) + + const LevelsAPI = require('./views/script/global_levelsapi'); + const lvl = new LevelsAPI(); + + stats = currentNest.stats; + musicIpc.on('addstats', (event, value) => { + currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + + if (value.key === "laps" && currentNest.auth) { + auth = currentNest.auth; + level = lvl.correspond(currentNest.stats["ingame"]["laps"], "256") - 1 + 1; + + if (level !== auth.level) { + currentNest.auth.level = level; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + if (level < 200) { + win.webContents.send("notification", {title: lang.polymer.levelup[0], message: lang.polymer.levelup[1] + " " + level + " " + lang.polymer.levelup[2]}); + } else { + win.webContents.send("notification", {title: lang.polymer.finished[0], message: lang.polymer.finished[1]}); + } + } + } + }) + musicIpc.on('addstatsandclose', (event, value) => { + currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + win.destroy(); + }) + }) + } + + console.log(" * Starting splash screen"); + global.load = new BrowserWindow({ + width: 640, + height: 400, + resizeable: false, + resizable: false, + maximizable: false, + frame: false, + show: false, + enableLargerThanScreen: true, + icon: "logo/logo.png", + backgroundColor: "#4b4e50", + title: "Kartik", + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + enableRemoteModule: true, + webviewTag: true, + disableBlinkFeatures: "MediaSessionService", + } + }) + load.loadFile("./views/load.html"); + load.webContents.once('dom-ready', () => { + console.log(" * Showing splash screen"); + load.show(); + setTimeout(() => { + console.log(" * Checking signatures"); + + invalidfiles = []; + + sigdb = require("./bin/signatures.json"); + total = Object.keys(sigdb["v1"]).length * 3; + processed = 0; + for (file in sigdb["v1"]) { + if (fs.existsSync(file) && !invalidfiles.includes(file)) { + try { + hash = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('base64'); + if (hash !== sigdb["v1"][file]) { + invalidfiles.push(file); + } + } catch (e) { + console.warn(" ! Could not compute V1 hash for " + file); + } + } + + processed++; + load.webContents.send('progress', (processed/total)*100); + } + for (file in sigdb["v2"]) { + if (fs.existsSync(file) && !invalidfiles.includes(file)) { + try { + hash = require('crypto').createHash('sha1').update(fs.readFileSync(file)).digest('base64'); + if (hash !== sigdb["v2"][file]) { + invalidfiles.push(file); + } + } catch (e) { + console.warn(" ! Could not compute V2 hash for " + file); + } + } + + processed++; + load.webContents.send('progress', (processed/total)*100); + } + for (file in sigdb["v3"]) { + if (fs.existsSync(file) && !invalidfiles.includes(file)) { + try { + hash = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('base64'); + if (hash !== sigdb["v3"][file]) { + invalidfiles.push(file); + } + } catch (e) { + console.warn(" ! Could not compute V3 hash for " + file); + } + } + + processed++; + load.webContents.send('progress', (processed/total)*100); + } + + global.importedTypeScriptFiles = []; + global.compiledTypeScriptFiles = []; + console.log(" * Generating resources pack"); + require('./modding/resources'); + console.log(" * Starting Kartik Modding Platform"); + require('./modding/parser'); + console.log(" * Compiling KMP API TypeScript files"); + require('./modding/compiler'); + console.log(" * Loading KMP TypeScript mods"); + require('./typescript/preloader'); + createWindow(); + }, 5000) + }) + }) + + app.on('window-all-closed', () => { + if (shouldExitIfClosed) { + console.log(" * Bye!"); + app.quit() + } + }) +})(); -- cgit