I have taken on a personal challenge. i want to expand my knowledge by creating a digital, online, custom OS Simulator, Heres how it works and whats my goal.
it will be uploaded online when complete. it uses javascript for functionality, html for GUI, CSS For theming and visuals, and XML For data storage. you will be able to export the XML as a custom user system. heres the kicker, i know how to use alert and const in js. nothing else. i have my reason though. ive been using google gemini to help me make it. except we are both stuck. i want to be able to go back to the code and learn from it. while coding it, were stuck with the virtual file system. it stores it on memory until exported which (hasnt been implimented yet) will be able to be exported into an XML Containing the computer itself. the worse part of the challenge is im not only on chromeos but on a school laptop. i cannot access inspect. a console. or half the online resources i want. im hellbent on dooing it though so im here for help once again.
File structure project
project
here is the code
<!--XML Base System Structure-->
<?xml version="1.0" encoding="UTF-8"?>
<SYSTEM>
<Boot>
<EMMEM>8000</EMMEM><!--Simulated memory in KB-->
<EMSTR>12</EMSTR><!--Simulated Storage in GB-->
<!--Warn when user exports the system. WARNING:True file size is only apparant when you export your system, if your using all simulated system space. and you dont have enough storage on your device. our system may save improporly or not at all-->
<DevMode>True</DevMode><!--Activated dev mode, on while i code-->
<!--Any other boot info-->
<setup>True</setup><!--If this is set to false the setup mode will activate-->
</Boot>
<FileSystem><!--Emulated FileSystem-->
<ROOT>
<prog>
<info>
<name>Setup</name>
<size>???</size>
<dates>
<created>0/0/0 00:00<!--Users timezone would be here--></created><!--Date file was created w/ time-->
<modified>0/0/0 00:00<!--Users timezone would be here--></modified><!--Date file was last modified w/ time-->
<!--Dates will be last update to website. ect. ect. these can be left blank for now-->
</dates>
<flags>
<flag>SystemApp</flag>
<flag>RunFullScreen</flag>
<!--Flags for the system to run by-->
</flags>
</info>
<progfiles>
<html></html>
<css></css>
<script></script>
<xmd></xmd><!--Data stored in an xml format for app specific things.-->
</progfiles>
</prog>
<USERS>
<Administrator>
<DisplayName>Administrator</DisplayName>
<Password>0000<!--We will add a encryption and decryption process for this later-->
<PERSONALFS>
<Desktop>
<Shortcut><!--Shortcut like an INK or Symlink file-->
<display>Documents</display>
<SPath>curusr/Documents</SPath><!--curusr/Documents >> CurrentUser(curusr)/ Documents-->
</Shortcut>
</Desktop>
<Documents>
<!--File-->
<file>
<name>Hello World</name>
<type>txt</type>
<contents>Hello mighty world!n This simulated os was helped designed by ai cuz im bad at code!!!</contents>
<size></size>
<dates>
<created>0/0/0 00:00<!--Users timezone would be here--></created><!--Date file was created w/ time-->
<modified>0/0/0 00:00<!--Users timezone would be here--></modified><!--Date file was last modified w/ time-->
</dates>
</file>
</Documents>
</PERSONALFS><!--User Specific FileSystem-->
</Administrator>
</USERS>
</ROOT>
</FileSystem>
</SYSTEM>
HTML
inhtmlconsole = document.getElementById('innerconsole')
window.console = {
log: function(message) {
inhtmlconsole.innerText += message + 'n';
},
logas: function(thing, message) {
inhtmlconsole.innerText += "[" + thing + "] > " + message + 'n';
},
error: function(message) {
inhtmlconsole.innerText += "[ERROR] > " + message + 'n';
},
warn: function(message) {
inhtmlconsole.innerText += "[WARN] > " + message + 'n';
},
issue: function(message) {
inhtmlconsole.innerText += "[ISSUE] > " + message + 'n';
}
};
console.log("Log Working")
function readSingleFile(e) {
console.logas("DATA LOADER", "readSingleFile function started");
var file = e.target.files[0];
if (!file) {
console.logas("DATA LOADER", "No file selected");
return;
}
var reader = new FileReader();
reader.onload = function(e) {
console.logas("DATA LOADER", "File loaded");
var contents = e.target.result;
displayContents(contents);
};
reader.readAsText(file);
console.logas("DATA LOADER", "Reading file");
}
function displayContents(contents) {
console.logas("DATA DISPLAYER", "displayContents function started");
var element = document.getElementById('file-content');
element.textContent = contents;
parse(contents);
}
document.getElementById('file-input')
.addEventListener('change', readSingleFile, false);
function parse(content) {
console.logas("BOOTDATAPARSER", "parse function started");
// Create a parser
var parser = new DOMParser();
console.logas("BOOTDATAPARSER", "Parser created");
xmlDoc = parser.parseFromString(content, "text/xml");
console.logas("BOOTDATAPARSER", "XML Parsed");
if(!xmlDoc || !xmlDoc.documentElement) {
console.error("XML Document could not be parsed", xmlDoc)
}else{
console.logas("XML", "documentElement: " + xmlDoc.documentElement.nodeName);
console.logas("XML","xmlDoc.documentElement.children: " + xmlDoc.documentElement.children)
if(xmlDoc.documentElement.children){
const children = Array.from(xmlDoc.documentElement.children);
children.forEach(child => {
console.logas("XML", "Child nodeName:" + child.nodeName);
});
}
}
let EMMEM = 'Not found';
let EMSTR = 'Not found';
let DEVMODE = 'Not found';
let SETUP = 'Not found';
try {
const emmemNode = xmlDoc.evaluate("//SYSTEM/Boot/EMMEM", xmlDoc).iterateNext();
console.logas("BOOTDATAPARSER", "EMMEM Node retrieved " + emmemNode);
EMMEM = emmemNode ? emmemNode.textContent : 'Not found';
} catch (err) {
console.error("Error getting EMMEM" , err);
}
try {
const emstrNode = xmlDoc.evaluate("//SYSTEM/Boot/EMSTR", xmlDoc).iterateNext();
console.logas("BOOTDATAPARSER","EMSTR Node retrieved " + emstrNode);
EMSTR = emstrNode ? emstrNode.textContent : 'Not found';
} catch (err) {
console.error("Error getting EMSTR" , err);
}
try {
const devModeNode = xmlDoc.evaluate("//SYSTEM/Boot/DevMode", xmlDoc).iterateNext();
console.logas("BOOTDATAPARSER","DEVMODE Node retrieved " + devModeNode);
DEVMODE = devModeNode ? devModeNode.textContent : 'Not found';
} catch (err) {
console.error("Error getting Developer Mode State", err);
}
try {
const setupNode = xmlDoc.querySelector("SYSTEM > Boot > setup");
console.logas("BOOTDATAPARSER", "SETUP Node retrieved " + setupNode?.textContent);
SETUP = setupNode ? setupNode.textContent : 'Not found';
} catch (err) {
console.error("Error getting Setup Status", err);
}
document.getElementById("EMMEM").innerText = "Simulated Memory: " + EMMEM + "KB";
document.getElementById("EMSTR").innerText = "Simulated Storage: " + EMSTR + "GB";
document.getElementById("DevMode").innerText = "Running in DevMode? : " + DEVMODE;
document.getElementById("Setup").innerText = "Is Setup?: " + SETUP;
console.logas("BOOTDATAPARSER","After setting InnerText");
//________________The issue code is below________________________
window.fileSystem = createInMemoryFileSystem(xmlDoc)
console.logas("FSYS", "File System created: " + JSON.stringify(window.fileSystem, null, 2))
try {
const helloWorldFile = window.fileSystem.root.USERS.Administrator.Documents["Hello World"];
console.logas("FSYS","Hello world file: " + helloWorldFile)
if(helloWorldFile){
document.getElementById('innerconsole').innerText += "n" + helloWorldFile.content
}
} catch (error) {
console.error("Could not access file:", error)
}
}
function createInMemoryFileSystem(xmlDoc) {
console.logas("FSYS","createInMemoryFileSystem started");
let xmlElement;
if (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.nodeName === "HTML") {
console.logas("FSYS","XML is within HTML element")
xmlElement = xmlDoc.querySelector('SYSTEM')
}else{
console.logas("FSYS","XML is the root element");
xmlElement = xmlDoc;
}
fileSystem = {};
const fileSystemRoot = xmlElement.querySelector("FileSystem > ROOT")
console.logas("FSYS","fileSystemRoot: " + fileSystemRoot);
if(fileSystemRoot){
function processElement(element, parent) {
const nodeType = element.nodeName;
if (nodeType === "ROOT" ) {
parent.type = "folder";
parent.name = "root";
parent.children = {};
console.logas("FSYS","ROOT Folder Found");
for (const child of element.children) {
processElement(child, parent.children);
}
}else if (nodeType === "prog" || nodeType === "USERS" || nodeType === "Administrator" || nodeType === "PERSONALFS" ) {
console.logas("FSYS","processing Folder: " + nodeType);
const folder = {};
folder.type = "folder";
folder.name = nodeType;
folder.children = {};
for (const child of element.children) {
processElement(child, folder.children);
}
parent[nodeType] = folder
}else if (nodeType === "Desktop" || nodeType === "Documents" ) {
console.logas("FSYS","processing Folder: " + nodeType);
const folder = {};
folder.type = "folder";
folder.name = nodeType;
folder.children = {};
for (const child of element.children) {
processElement(child, folder.children);
}
parent[nodeType] = folder
}
else if(nodeType === "file"){
console.logas("FSYS","processing File: " + nodeType);
const file = {}
file.type = "file"
file.name = element.querySelector('name')?.textContent || 'Unnamed File';
file.content = element.querySelector('contents')?.textContent || '';
file.size = element.querySelector('size')?.textContent || '';
file.dates = {
created: element.querySelector('dates > created')?.textContent || '',
modified: element.querySelector('dates > modified')?.textContent || ''
}
parent[file.name] = file;
}else if(nodeType === "Shortcut"){
console.logas("FSYS","processing Shortcut: " + nodeType);
const shortcut = {};
shortcut.type = "file";
shortcut.name = "shortcut";
shortcut.content = {
display: element.querySelector('display')?.textContent || 'Unnamed File',
SPath: element.querySelector('SPath')?.textContent || ''
}
parent[shortcut.name] = shortcut;
}else{
console.logas("FSYS","other element: " + nodeType)
}
}
processElement(fileSystemRoot, fileSystem);
}else{
console.error("Error no file system root found");
}
console.logas("FSYS","createInMemoryFileSystem finished");
return fileSystem;
//___________________problem code end__________________
}
HTML
<!DOCTYPE HTML>
<link href="boot.css" rel="stylesheet">
<p>Booting...</p>
<input type="file" id="file-input" />
<div id="EMMEM">Simulated Memory: </div>
<div id="EMSTR">Simulated storage: </div>
<div id="DevMode">In Dev Mode?: </div>
<div id="Setup">Is Setup?: </div>
<p style="color: aliceblue; background-color: black;" id="innerconsole">Console<br></p>
<h3>Contents of the file:</h3>
<pre id="file-content"></pre>
<script src="boot.js"></script>
CSS
body {
background-color: blue;
}
text {
color: aliceblue;
}
since the only way i can view the html of the page without inspect is downloading the page as an mhtml here is the data
From: <Saved by Blink>
Snapshot-Content-Location: ___
Subject:
Date: Mon, 6 Jan 2025 19:11:00 -0500
MIME-Version: 1.0
Content-Type: multipart/related;
type="text/html";
boundary="----MultipartBoundary--AptXrjHXhKeP8Y05qusXmVHzTL2WgLvzs1Yu3FK5LC----"
------MultipartBoundary--AptXrjHXhKeP8Y05qusXmVHzTL2WgLvzs1Yu3FK5LC----
Content-Type: text/html
Content-ID: <[email protected]>
Content-Transfer-Encoding: quoted-printable
Content-Location: ___
<!DOCTYPE html><html><head><meta http-equiv=3D"Content-Type" content=3D"tex=
t/html; charset=3Dwindows-1252"><link href=3D"___" rel=3D"stylesheet">
</head><body><p>Booting...</p>
<input type=3D"file" id=3D"file-input">
<div id=3D"EMMEM">Simulated Memory: 8000KB</div>
<div id=3D"EMSTR">Simulated Storage: 12GB</div>
<div id=3D"DevMode">Running in DevMode? : True</div>
<div id=3D"Setup">Is Setup?: True</div>
<p style=3D"color: aliceblue; background-color: black;" id=3D"innerconsole"=
>Console<br>Log Working<br>[DATA LOADER] > readSingleFile function start=
ed<br>[DATA LOADER] > Reading file<br>[DATA LOADER] > File loaded<br>=
[DATA DISPLAYER] > displayContents function started<br>[BOOTDATAPARSER] =
> parse function started<br>[BOOTDATAPARSER] > Parser created<br>[BOO=
TDATAPARSER] > XML Parsed<br>[XML] > documentElement: SYSTEM<br>[XML]=
> xmlDoc.documentElement.children: [object HTMLCollection]<br>[XML] >=
; Child nodeName:parsererror<br>[XML] > Child nodeName:Boot<br>[XML] >=
; Child nodeName:FileSystem<br>[BOOTDATAPARSER] > EMMEM Node retrieved [=
object Element]<br>[BOOTDATAPARSER] > EMSTR Node retrieved [object Eleme=
nt]<br>[BOOTDATAPARSER] > DEVMODE Node retrieved [object Element]<br>[BO=
OTDATAPARSER] > SETUP Node retrieved True<br>[BOOTDATAPARSER] > After=
setting InnerText<br>[FSYS] > createInMemoryFileSystem started<br>[FSYS=
] > XML is the root element<br>[FSYS] > fileSystemRoot: [object Eleme=
nt]<br>[FSYS] > ROOT Folder Found<br>[FSYS] > processing Folder: prog=
<br>[FSYS] > other element: info<br>[FSYS] > other element: progfiles=
<br>[FSYS] > processing Folder: USERS<br>[FSYS] > processing Folder: =
Administrator<br>[FSYS] > other element: DisplayName<br>[FSYS] > othe=
r element: Password<br>[FSYS] > createInMemoryFileSystem finished<br>[FS=
YS] > File System created: {<br>"type": "folder",<br>"name": "root",<br>=
"children": {<br>"prog": {<br>"type": "folder",<br>"name": "prog",<br>"chil=
dren": {}<br>},<br>"USERS": {<br>"type": "folder",<br>"name": "USERS",<br>"=
children": {<br>"Administrator": {<br>"type": "folder",<br>"name": "Adminis=
trator",<br>"children": {}<br>}<br>}<br>}<br>}<br>}<br>[ERROR] > Could n=
ot access file:<br></p>
<h3>Contents of the file:</h3>
<pre id=3D"file-content"><?xml version=3D"1.0" encoding=3D"UTF-8"?>
<SYSTEM>
<Boot>
<EMMEM>8000</EMMEM><!--Simulated memory in KB-->
<EMSTR>12</EMSTR><!--Simulated Storage in GB-->
<!--Warn when user exports the system. WARNING:True file size is=
only apparant when you export your system, if your using all simulated sy=
stem space. and you dont have enough storage on your device. our system ma=
y save improporly or not at all-->
<DevMode>True</DevMode><!--Activated dev mode, on wh=
ile i code-->
<!--Any other boot info-->
<setup>True</setup><!--If this is set to false the s=
etup mode will activate-->
</Boot>
<FileSystem><!--Emulated FileSystem-->
<ROOT>
<prog>
<info>
<name>Setup</name>
<size>???</size>
<dates>
<created>0/0/0 00:00<!--Users timezone wou=
ld be here--></created><!--Date file was created w/ time-->
<modified>0/0/0 00:00<!--Users timezone wo=
uld be here--></modified><!--Date file was last modified w/ tim=
e-->
<!--Dates will be last update to website. ect. e=
ct. these can be left blank for now-->
</dates>
<flags>
<flag>SystemApp</flag>
<flag>RunFullScreen</flag>
<!--Flags for the system to run by-->
</flags>
</info>
<progfiles>
<html></html>
<css></css>
<script></script>
<xmd></xmd><!--Data stored in an xml for=
mat for app specific things.-->
</progfiles>
</prog>
<USERS>
<Administrator>
<DisplayName>Administrator</DisplayName>
<Password>0000<!--We will add a encryption and=
decryption process for this later-->
<PERSONALFS>
<Desktop>
<Shortcut><!--Shortcut like an INK or =
Symlink file-->
<display>Documents</display>
<SPath>curusr/Documents</SPath>=
<!--curusr/Documents >> CurrentUser(curusr)/ Documents-->
</Shortcut>
</Desktop>
<Documents>
<!--File-->
<file>
<name>Hello World</name>
<type>txt</type>
<contents>Hello mighty world!n This =
simulated os was helped designed by ai cuz im bad at code!!!</contents&g=
t;
<size></size>
<dates>
<created>0/0/0 00:00<!--Users =
timezone would be here--></created><!--Date file was created w/=
time-->
<modified>0/0/0 00:00<!--Users=
timezone would be here--></modified><!--Date file was last mod=
ified w/ time-->
</dates>
</file>
</Documents>
</PERSONALFS><!--User Specific FileSystem-->=
;
</Administrator>
</USERS>
</ROOT>
</FileSystem>
</SYSTEM></pre>
</body></html>
------MultipartBoundary--AptXrjHXhKeP8Y05qusXmVHzTL2WgLvzs1Yu3FK5LC----
Content-Type: text/css
Content-Transfer-Encoding: quoted-printable
Content-Location: ____
@charset "windows-1252";
body { background-color: blue; }
text { color: aliceblue; }
------MultipartBoundary--AptXrjHXhKeP8Y05qusXmVHzTL2WgLvzs1Yu3FK5LC------
built in console output
Console
Log Working
[DATA LOADER] > readSingleFile function started
[DATA LOADER] > Reading file
[DATA LOADER] > File loaded
[DATA DISPLAYER] > displayContents function started
[BOOTDATAPARSER] > parse function started
[BOOTDATAPARSER] > Parser created
[BOOTDATAPARSER] > XML Parsed
[XML] > documentElement: SYSTEM
[XML] > xmlDoc.documentElement.children: [object HTMLCollection]
[XML] > Child nodeName:parsererror
[XML] > Child nodeName:Boot
[XML] > Child nodeName:FileSystem
[BOOTDATAPARSER] > EMMEM Node retrieved [object Element]
[BOOTDATAPARSER] > EMSTR Node retrieved [object Element]
[BOOTDATAPARSER] > DEVMODE Node retrieved [object Element]
[BOOTDATAPARSER] > SETUP Node retrieved True
[BOOTDATAPARSER] > After setting InnerText
[FSYS] > createInMemoryFileSystem started
[FSYS] > XML is the root element
[FSYS] > fileSystemRoot: [object Element]
[FSYS] > ROOT Folder Found
[FSYS] > processing Folder: prog
[FSYS] > other element: info
[FSYS] > other element: progfiles
[FSYS] > processing Folder: USERS
[FSYS] > processing Folder: Administrator
[FSYS] > other element: DisplayName
[FSYS] > other element: Password
[FSYS] > createInMemoryFileSystem finished
[FSYS] > File System created: {
"type": "folder",
"name": "root",
"children": {
"prog": {
"type": "folder",
"name": "prog",
"children": {}
},
"USERS": {
"type": "folder",
"name": "USERS",
"children": {
"Administrator": {
"type": "folder",
"name": "Administrator",
"children": {}
}
}
}
}
}
THE ISSUE,
we are able to access everything up until PersonalFS.
after reviewing it I see that the processElement function is failing to build the PERSONALFS part of the file system structure.
Me and the ai have tried like 50 variations of the code. we CANNOT figure it out :/