update to the newest BrowserFS

This commit is contained in:
Daniel Brooks
2016-08-04 00:17:05 -07:00
parent 70ad117a20
commit ad53da596c
3 changed files with 47 additions and 42 deletions
+8 -6
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+38 -36
View File
@@ -772,7 +772,7 @@ var Module = null;
// If the browser supports IndexedDB storage, mirror writes to that storage
// for persistence purposes.
if (BrowserFS.FileSystem.IndexedDB.isAvailable()) {
var AsyncMirrorFS = BrowserFS.FileSystem.AsyncMirrorFS,
var AsyncMirrorFS = BrowserFS.FileSystem.AsyncMirror,
IndexedDB = BrowserFS.FileSystem.IndexedDB;
deltaFS = new AsyncMirrorFS(deltaFS,
new IndexedDB(function(e, fs) {
@@ -781,7 +781,7 @@ var Module = null;
finish();
} else {
// Initialize deltaFS by copying files from async storage to sync storage.
deltaFS.initialize(function(e) {
deltaFS.initialize(function (e) {
if (e) {
reject(e);
} else {
@@ -804,45 +804,47 @@ var Module = null;
// while being able to "write" to them.
game_data.fs = new BrowserFS.FileSystem.OverlayFS(deltaFS,
new BrowserFS.FileSystem.MountableFileSystem());
var Buffer = BrowserFS.BFSRequire('buffer').Buffer;
game_data.fs.initialize(function (e) {
var Buffer = BrowserFS.BFSRequire('buffer').Buffer;
function fetch(file) {
if ('data' in file && file.data !== null && typeof file.data !== 'undefined') {
return Promise.resolve(file.data);
function fetch(file) {
if ('data' in file && file.data !== null && typeof file.data !== 'undefined') {
return Promise.resolve(file.data);
}
return fetch_file(file.title, file.url, 'arraybuffer', file.optional);
}
return fetch_file(file.title, file.url, 'arraybuffer', file.optional);
}
function mountat(drive) {
return function (data) {
if (data !== null) {
drive = drive.toLowerCase();
var mountpoint = '/'+ drive;
// Mount into RO MFS.
game_data.fs.getOverlayedFileSystems().readable.mount(mountpoint, BFSOpenZip(new Buffer(data)));
}
};
}
function mountat(drive) {
return function (data) {
if (data !== null) {
drive = drive.toLowerCase();
var mountpoint = '/'+ drive;
// Mount into RO MFS.
game_data.fs.getOverlayedFileSystems().readable.mount(mountpoint, BFSOpenZip(new Buffer(data)));
}
};
}
function saveat(filename) {
return function (data) {
if (data !== null) {
game_data.fs.writeFileSync('/'+ filename, new Buffer(data), null, flag_w, 0x1a4);
}
};
}
Promise.all(game_data.files
.map(function (f) {
if (f && f.file) {
if (f.drive) {
return fetch(f.file).then(mountat(f.drive));
} else if (f.mountpoint) {
return fetch(f.file).then(saveat(f.mountpoint));
function saveat(filename) {
return function (data) {
if (data !== null) {
game_data.fs.writeFileSync('/'+ filename, new Buffer(data), null, flag_w, 0x1a4);
}
};
}
Promise.all(game_data.files
.map(function (f) {
if (f && f.file) {
if (f.drive) {
return fetch(f.file).then(mountat(f.drive));
} else if (f.mountpoint) {
return fetch(f.file).then(saveat(f.mountpoint));
}
}
}
return null;
}))
.then(resolve, reject);
return null;
}))
.then(resolve, reject);
});
}
});
})