forked from pkage/pkage.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.js
315 lines (274 loc) · 8.09 KB
/
fs.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
class Folder {
constructor(data) {
this.parent = null
this.children = {}
this.data = {
name: 'folder',
icon: 'img/desktop/Folder.png',
title: 'Folder',
contents: [],
}
if (data !== undefined) {
this.data = {
...this.data,
...data
}
}
}
calculatePath() {
if (this.parent === null) {
return ['C:']
}
return [
...this.parent.calculatePath(),
this.getName()
]
}
getName() {
return this.data.name
}
getIcon() {
return this.data.icon
}
getContents() {
return this.data.contents
}
getChildren() {
return this.children
}
addChild(child) {
child.parent = this
this.children[child.getName()] = child
}
async getChild(name) {
if (!(name in this.children)) {
return null
}
return this.children[name]
}
hasChild(name) {
return (name in this.children)
}
}
class Filesystem {
constructor() {
this.root = new Folder({name: 'C:', title: 'C:'})
}
async get(path) {
const segs = path.split('/')
if (segs.length === 1) {
return this.root
}
const searcher = async (segs, folder) => {
if (folder === null) return null
if (segs.length === 0) {
return folder
}
const next = await folder.getChild(segs[0])
return await searcher(segs.slice(1), next)
}
return await searcher(segs.slice(1), this.root)
}
addChild(folder) {
this.root.addChild(folder)
}
async loadFilesystem() {
// file extension -> thumb image helpers
const get_extension = name => name.split('.').slice(-1).pop().toLowerCase()
const extension_map = {
'exe': 'img/desktop/EXE.png',
'com': 'img/desktop/EXE.png',
'ini': 'img/desktop/INI.png',
'cfg': 'img/desktop/INI.png',
'txt': 'img/desktop/TextFile.png',
'wav': 'img/desktop/WavFile.png',
'dll': 'img/desktop/DLL.png',
'bat': 'img/desktop/BatchFile.png',
'bmp': 'img/desktop/Bitmap.png',
'sys': 'img/desktop/SystemFile.png'
}
const get_thumb = name => {
const ext = get_extension(name)
if (ext in extension_map) {
return extension_map[ext]
}
return 'img/desktop/File.png'
}
// recursion helper through the fs dump
const recurse_helper = (folder, info) => {
// if there are files ...
if ('_files' in info) {
// ... hydrate them
folder.data.contents = info._files.map( name => ({
img: get_thumb(name),
title: name,
launch: 'dialog:Error|Disk Error|Disk read error!<br/>Please insert the Windows 98 installation floppy to continue.|ARI'
}))
}
const forbidden = ['.fseventsd', '_files']
for (let key in info) {
// skip forbidden file names (leftover from scrapes)
if (forbidden.indexOf(key) !== -1) {
continue
}
// don't stomp on default filesystem
if (folder.hasChild(key)) {
continue
}
// make a new folder ...
const new_folder = new Folder({
title: key,
name: key
})
// ... populate it ...
recurse_helper(new_folder, info[key])
// ... and add it to this folder
folder.addChild(new_folder)
}
}
const fs_scrape = await fetch('/data/filesystem.json').then(r => r.json())
recurse_helper(this.root, fs_scrape)
}
}
window.fs = new Filesystem()
/* --- DEFAULT FILESYSTEM --- */
window.fs.addChild(new Folder({
icon: 'img/desktop/MyDocuments.png',
name: 'My Documents',
contents: [
{
img: 'img/desktop/WordPad.png',
title: 'Resume.pdf',
launch: 'resume'
},
{
img: 'img/desktop/WordPad.png',
title: 'CV.pdf',
launch: 'cv'
},
{
img: 'img/desktop/InternetExplorer.png',
title: 'GitHub',
shortcut: true,
launch: 'web:https://github.com/pkage'
},
{
img: 'img/desktop/InternetExplorer.png',
title: 'LinkedIn',
shortcut: true,
launch: 'web:https://www.linkedin.com/in/patrick-kage-652ba8122/'
},
{
img: 'img/desktop/InternetExplorer.png',
title: 'Keybase',
shortcut: true,
launch: 'web:https://keybase.io/pkage'
},
{
img: 'img/desktop/InternetExplorer.png',
title: 'My Blog',
shortcut: true,
launch: 'web:https://ka.ge/blog/'
},
{
img: 'img/desktop/Email.png',
title: 'Email',
shortcut: true,
launch: 'email'
},
{
img: 'img/desktop/MyBriefcase.png',
title: 'My Portfolio',
shortcut: true,
launch: 'portfolio'
},
{
img: 'img/special/ORCID.png',
title: 'ORCID',
shortcut: true,
launch: 'web:https://orcid.org/0000-0002-5639-1237'
},
{
img: 'img/desktop/SystemFile.png',
title: 'Welcome',
shortcut: true,
launch: 'welcome'
}
]
}))
window.fs.addChild(new Folder({
name: 'Recycling Bin',
icon: 'img/desktop/RecyclingBin.png',
contents: [
{
img: 'img/desktop/InternetExplorer.png',
title: 'Twitter',
shortcut: true,
launch: 'web:https://twitter.com/patrick_kage'
},
{
img: 'img/desktop/WavFile.png',
title: 'roll.wav',
shortcut: true,
launch: 'web:https://www.youtube.com/watch?v=dQw4w9WgXcQ'
}
]
}))
window.fs.addChild(new Folder({
name: 'Network Neighborhood',
icon: 'img/desktop/NetworkNeighborhood.png',
contents: [
{
img: 'img/desktop/NetDrive.png',
title: 'Host Computer',
launch: `dialog:img/dialog/Attention.png|Just kidding.|Just kidding.<br>But that'd be pretty cool though, right?|Yeah.`
},
{
img: 'img/desktop/Web Folders.png',
title: 'Web Folders',
launch: 'nop'
},
{
img: 'img/desktop/Entire Internet.png',
title: 'Entire Internet',
launch: 'nop'
}
]
}))
window.fs.root.children['My Documents'].addChild(new Folder({
name: 'My Papers',
icon: 'img/desktop/Favorites.png',
contents: [
{
img: 'img/special/ArXivFile.png',
title: 'Class Introspection...',
shortcut: true,
launch: 'web:https://arxiv.org/abs/2107.01657'
},
{
img: 'img/desktop/WordPad.png',
title: 'Honours Project',
shortcut: true,
launch: 'web:https://misc.ka.ge/honours.pdf'
}
]
}))
window.fs.root.children['My Documents'].addChild(new Folder({
name: 'My Talks',
icon: 'img/desktop/Favorites.png',
contents: [
{
img: 'img/desktop/Mplayer.png',
title: 'KRHCAI: Class Introspection',
shortcut: true,
launch: 'web:https://www.youtube.com/watch?v=i2gULufLnf8'
},
{
img: 'img/desktop/Mplayer.png',
title: 'HACKCON: Discord For Hackathons',
shortcut: true,
launch: 'web:https://www.youtube.com/watch?v=9bSudnnyQ5w'
}
]
}))
window.fs.loadFilesystem()