summaryrefslogtreecommitdiff
path: root/Startup.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-07-03 14:23:25 +0200
committerMinteck <contact@minteck.org>2022-07-03 14:23:25 +0200
commitd25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc (patch)
treea8e538a8e32b66fece6a10c198fe700866d1e233 /Startup.js
downloadstrawberry-os-d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc.tar.gz
strawberry-os-d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc.tar.bz2
strawberry-os-d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc.zip
Initial commit
Diffstat (limited to 'Startup.js')
-rwxr-xr-xStartup.js139
1 files changed, 139 insertions, 0 deletions
diff --git a/Startup.js b/Startup.js
new file mode 100755
index 0000000..3a77fb5
--- /dev/null
+++ b/Startup.js
@@ -0,0 +1,139 @@
+global.chalk = require('./Library/SDK/node_modules/chalk');
+const fs = require('fs');
+
+global._STRAWBERRY_SYSTEM_ROOT = __dirname;
+global._STRAWBERRY_APPLICATIONS_ROOT = __dirname + "/StrawKit/Applications";
+global._STRAWBERRY_SYSTEMAPPS_ROOT = __dirname + "/Applications";
+global._STRAWBERRY_APPMENU_OPEN = false;
+global._STRAWBERRY_EMULATED = false;
+
+let fileList = [];
+function files(dir) {
+ for (let file of fs.readdirSync(dir)) {
+ if (fs.lstatSync(dir + "/" + file).isDirectory()) {
+ files(dir + "/" + file);
+ } else {
+ fileList.push(dir + "/" + file);
+ }
+ }
+}
+
+if (process.argv[2] === "emu") {
+ require('./Library/SDK/node_modules/hide-terminal-cursor')();
+ global._STRAWBERRY_EMULATED = true;
+
+ global.center = (text) => {
+ let out = "";
+ global.vertical = Math.round(process.stdout.rows / 2 + 1);
+ let horizontal = Math.round(process.stdout.columns / 2 - (1 + (text.length / 2)));
+
+ for (let n = 0; n < vertical - 1; n++) {
+ out += "\n" + " ".repeat(process.stdout.columns);
+ }
+
+ out += " ".repeat(horizontal) + text + " ".repeat(process.stdout.columns - horizontal - text.length);
+
+ for (let n = 0; n < vertical - 1; n++) {
+ out += "\n" + " ".repeat(process.stdout.columns);
+ }
+
+ return chalk.bgWhite.black(out);
+ }
+} else {
+ global._STRAWBERRY_APPLICATIONS_ROOT = "/Strawberry/Applications";
+ global._STRAWBERRY_SYSTEMAPPS_ROOT = "/Strawberry/System/Applications";
+
+ if (global.loadInterval && global.loadInterval2) {} else {
+ console.log("This system doesn't seem to be running a Strawberry or compatible bootloader. Try:");
+ console.log(" " + process.argv.join(" ") + " emu");
+ process.exit(2);
+ }
+
+ clearInterval(global.loadInterval);
+ clearInterval(global.loadInterval2);
+}
+
+console.clear();
+console.log(center("Welcome to Strawberry OS!"));
+process.stdout.cursorTo(0, 0);
+
+function setProgressPercentage(perc) {
+ let s1 = "▏";
+ let s2 = "▎";
+ let s3 = "▌";
+ let s4 = "▊";
+ let s5 = "█";
+
+ let val = perc / 2.5;
+ let parts = val.toFixed(2).split(".").map((i) => { return parseInt(i); });
+ let p2 = Math.round(parts[1] / 20);
+
+ let hz = Math.round(process.stdout.columns / 2 - 21);
+ process.stdout.cursorTo(hz, vertical - 2);
+
+ let part2 = "";
+ switch (p2) {
+ case 0:
+ break;
+
+ case 1:
+ part2 = s1;
+ break;
+
+ case 2:
+ part2 = s2;
+ break;
+
+ case 3:
+ part2 = s3;
+ break;
+
+ case 4:
+ part2 = s4;
+ break;
+
+ case 5:
+ part2 = s5;
+ break;
+ }
+
+ process.stdout.write(chalk.cyan(s5.repeat(parts[0]) + part2));
+ process.stdout.cursorTo(0, 0);
+}
+
+setTimeout(() => {
+ let hz = Math.round(process.stdout.columns / 2 - 21);
+ process.stdout.cursorTo(hz, vertical - 2);
+ process.stdout.write(chalk.gray(" ".repeat(40)));
+ process.stdout.cursorTo(0, 0);
+
+ files(global._STRAWBERRY_SYSTEM_ROOT);
+ let max = fileList.length * 3;
+ let curr = 0;
+
+ for (let file of fileList) {
+ let md5 = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('hex');
+ curr++;
+ setProgressPercentage((curr / max) * 100);
+
+ require('child_process').execSync("sleep 0.01");
+
+ let sha256 = require('crypto').createHash('sha256').update(fs.readFileSync(file)).digest('hex');
+ curr++;
+ setProgressPercentage((curr / max) * 100);
+
+ require('child_process').execSync("sleep 0.01");
+
+ let sha512 = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('hex');
+ curr++;
+ setProgressPercentage((curr / max) * 100);
+
+ require('child_process').execSync("sleep 0.01");
+
+ if ((curr / max) * 100 >= 100) {
+ require("./Library/SystemSoftware");
+ }
+ }
+}, 2000);
+
+setInterval(() => {}) \ No newline at end of file