forked from shoaib-jamal/rebornxp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload.js
148 lines (139 loc) · 4.26 KB
/
load.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var scripts = [
'core.js',
'window-api.js',
'contextmenus.js',
'filesystem.js',
'xp.js',
'jquery.terminal-2.0.0.min.js',
'unix_formatting.js',
'terminal.js',
'script.js',
'explorer.js',
'help.js',
'browser.js',
'notepad.js',
'imageviewer.js',
'mediaplayer.js',
'config.js',
'controlpanel.js',
'uac.js',
'audio.js',
'lambda.js',
'minesweeper.js',
'//xpstore.glitch.me/appstore.js',
'boot.js'
];
var stylesheets = [
'fonts.css',
'xp.css',
'icons.css',
'widgets.css',
'window.css',
'contextmenus.css',
'cursors.css',
'desktop.css',
'startmenu.css',
'explorer.css',
'jquery.terminal-2.0.0.min.css'
];
var requiredDirectories = [];
$(function() {
$('windows').html(`
<div class="_ui_boot">
<div class="_ui_boot_copyright"></div>
<div class="_ui_boot_companylogo"></div>
<center class="_ui_boot_logo">
<div class="_ui_boot_winlogo"></div>
<div class="_ui_boot_progress"></div>
<!--<div style="bottom:0;position:absolute;width:100%;" id="loadingstatus"></div>-->
</center>
</div>`);
console.log('Loading scripts and stylesheets...');
$('<link/>', {rel: 'stylesheet', href: 'boot.css'}).appendTo('head');
var scriptsindex = 0;
var stylesindex = 0;
function loadStylesheets() {
$.ajax({
url: stylesheets[stylesindex],
dataType: "script",
success: function(data){
$("head").append("<style>" + data + "</style>");
stylesindex ++;
if (stylesindex < stylesheets.length) {
loadStylesheets();
} else {
loadScripts();
}
}
});
}
function loadScripts() {
$.ajax({
url: scripts[scriptsindex],
dataType: "script",
success: function(data){
scriptsindex ++;
if (scriptsindex < scripts.length) {
loadScripts();
} else {
console.log('Finished loading');
console.log('Checking for necessary directories');
function checkDir(path, callback) {
var times = 0;
xp.filesystem.listDir(path, (e) => {
if (times === 0)
callback(typeof e === 'string');
times ++;
});
}
var i = 0;
function checkNextDir(t) {
var dirToCreate = requiredDirectories[i];
if (dirToCreate !== undefined) {
xp.filesystem.createDir(dirToCreate, (e) => {
i ++;
checkNextDir();
});
} else {
xp.audio.init();
var event = new Event('xpboot');
window.dispatchEvent(event);
console.log('Dispatched boot event');
$('windows').html('<div class="_ui_wallpaper fullscreen"><img class="_ui_wallpaper_image" src="https://i.redd.it/p0j4iwha2q351.png"/></div>');
$.getScript('login.js');
xp.audio.playURL('https://cdn.glitch.com/01d2e04f-e49d-4304-aa9e-55b9849b4cce%2FWindows%20XP%20Startup.wav?1522620562681');
}
}
xp.filesystem.create(512*1024*1024, () => {
xp.filesystem.fs.root.getDirectory('/', {create: false}, function(dirEntry) {
var dirReader = dirEntry.createReader();
var entries = [];
function readEntries() {
dirReader.readEntries (function(results) {
if (results.length === 0) {
$('._ui_boot').remove();
$('windows').html('<div class="_ui_wallpaper fullscreen"><img class="_ui_wallpaper_image" src="https://i.redd.it/p0j4iwha2q351.png"/></div>');
$.getScript('setup.js');
} else {
xp.filesystem.createDir('/WINDOWS', (e) => {
requiredDirectories = [
'/WINDOWS',
'/WINDOWS/system32',
'/WINDOWS/startup',
'/Program Files',
'/Documents and Settings'
];
checkNextDir();
});
}
}, console.error);
};
readEntries();
}, console.error);
});
}
}
});
}
loadStylesheets();
});