syncing the rootfs to dropbox works now

This commit is contained in:
radius 2016-08-04 01:08:50 -05:00
parent 664d37f943
commit 7fcee63d02

View File

@ -28,8 +28,7 @@
<button id="btnLoad" onclick="document.getElementById('rom').click()">Upload Content</button> <button id="btnLoad" onclick="document.getElementById('rom').click()">Upload Content</button>
<input style="display: none" type="file" id="rom" name="upload" onclick="document.getElementById('btnLoad').click();" onchange="selectFiles(event.target.files)" multiple /> <input style="display: none" type="file" id="rom" name="upload" onclick="document.getElementById('btnLoad').click();" onchange="selectFiles(event.target.files)" multiple />
<button id="btnStart" onclick="startRetroArch()">Start RetroArch</button> <button id="btnStart" onclick="startRetroArch()">Start RetroArch</button>
<button id="btnAuth" onclick="dropboxInit()">Link to Dropbox</button> <button id="btnAuth" onclick="dropboxInit()">Use DropBox</button>
<button id="btnBack" onclick="dropboxCopy()">Backup Config to Dropbox</button>
</div> </div>
<hr/> <hr/>
<div class="webplayer"> <div class="webplayer">
@ -91,6 +90,8 @@
function dropboxInit() function dropboxInit()
{ {
document.getElementById('btnStart').disabled = true;
document.getElementById('btnAuth').disabled = true;
client.authDriver(new Dropbox.AuthDriver.Redirect()); client.authDriver(new Dropbox.AuthDriver.Redirect());
client.authenticate({ rememberUser: true }, function(error, client) client.authenticate({ rememberUser: true }, function(error, client)
{ {
@ -98,25 +99,62 @@
{ {
return showError(error); return showError(error);
} }
dropboxSync(client, success);
});
}
function success()
{
document.getElementById('btnStart').disabled = false;
console.log("WEBPLAYER: Sync successful");
}
function dropboxSync(dropboxClient, cb)
{
var dbfs = new BrowserFS.FileSystem.Dropbox(dropboxClient);
// Wrap in AsyncMirrorFS.
var asyncMirror = new BrowserFS.FileSystem.AsyncMirror(
new BrowserFS.FileSystem.InMemory(), dbfs);
asyncMirror.initialize(function(err)
{
// Initialize it as the root file system.
BrowserFS.initialize(asyncMirror);
cb();
}); });
} }
var count = 0; var count = 0;
function setupFileSystem() function setupFileSystem()
{ {
console.log(client.isAuthenticated()); console.log("WEBPLAYER: Initializing Filesystem");
if(localStorage.getItem("fs_inited")!="true") if(!client.isAuthenticated())
{ {
var lsfs = new BrowserFS.FileSystem.LocalStorage(); console.log("WEBPLAYER: Initializing LocalStorage");
if(localStorage.getItem("fs_inited")!="true")
{
var lsfs = new BrowserFS.FileSystem.LocalStorage();
BrowserFS.initialize(lsfs); BrowserFS.initialize(lsfs);
var BFS = new BrowserFS.EmscriptenFS(); var BFS = new BrowserFS.EmscriptenFS();
FS.mount(BFS, {root: '/'}, '/home'); FS.mount(BFS, {root: '/'}, '/home');
console.log('WEBPLAYER: Filesystem initialized'); console.log('WEBPLAYER: Filesystem initialized');
}
else
{
console.log('WEBPLAYER: Filesystem already initialized');
}
} }
else else
{ {
console.log('WEBPLAYER: Filesystem already initialized'); console.log("WEBPLAYER: Initializing DropBoxFS");
// Grab the BrowserFS Emscripten FS plugin.
var BFS = new BrowserFS.EmscriptenFS();
// Create the folder that we'll turn into a mount point.
FS.createPath(FS.root, 'home', true, true);
// Mount BFS's root folder into the '/data' folder.
console.log('WEBPLAYER: Mounting');
FS.mount(BFS, {root: '/'}, '/home');
console.log('WEBPLAYER: DropBox initialized');
} }
} }
@ -130,8 +168,6 @@
FS.createPath('/', '/home/web_user/saves', true, true); FS.createPath('/', '/home/web_user/saves', true, true);
FS.createPath('/', '/home/web_user/states', true, true); FS.createPath('/', '/home/web_user/states', true, true);
FS.createPath('/', '/home/web_user/system', true, true); FS.createPath('/', '/home/web_user/system', true, true);
FS.createPath('/', '/data/test', true, true);
} }
function stat(path) function stat(path)