mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-22 10:49:02 +00:00
make config persistent and allow upload of additional data even if RA has loaded
This commit is contained in:
parent
79612b2d8c
commit
e55fe20da1
@ -5,107 +5,115 @@ var firstRun = true;
|
||||
|
||||
function setupFolders()
|
||||
{
|
||||
if (Modernizr.localstorage) {
|
||||
console.log("local storage available");
|
||||
|
||||
if(localStorage.getItem("initialized")!="true")
|
||||
|
||||
{
|
||||
FS.createFolder('/data','content',true,true);
|
||||
FS.createFolder('/data','saves',true,true);
|
||||
FS.createFolder('/data','states',true,true);
|
||||
FS.createFolder('/data','system',true,true);
|
||||
localStorage.setItem("initialized","true");
|
||||
console.log(localStorage.getItem("initialized"));
|
||||
}
|
||||
console.log("setupFolders");
|
||||
|
||||
if(localStorage.getItem("folders_inited")!="true")
|
||||
{
|
||||
FS.createFolder('/home','web_user',true,true);
|
||||
FS.createFolder('/home/web_user','retroarch',true,true);
|
||||
FS.createFolder('/home/web_user/retroarch','saves',true,true);
|
||||
FS.createFolder('/home/web_user/retroarch','states',true,true);
|
||||
FS.createFolder('/home/web_user/retroarch','system',true,true);
|
||||
FS.createFolder('/home/web_user/retroarch','cheat',true,true);
|
||||
FS.createFolder('/home/web_user/retroarch','remap',true,true);
|
||||
FS.createFolder('/home/web_user','.config',true,true);
|
||||
FS.createFolder('/home/web_user/.config','retroarch',true,true);
|
||||
|
||||
localStorage.setItem("folders_inited","true");
|
||||
console.log('Folders initialized: ' + localStorage.getItem("folders_inited"));
|
||||
}
|
||||
}
|
||||
|
||||
function setupBFS() {
|
||||
var lsfs = new BrowserFS.FileSystem.LocalStorage();
|
||||
BrowserFS.initialize(lsfs);
|
||||
var BFS = new BrowserFS.EmscriptenFS();
|
||||
FS.createFolder(FS.root, 'data', true, true);
|
||||
FS.mount(BFS, {root: '/'}, '/data');
|
||||
function createConfig()
|
||||
{
|
||||
console.log("createConfig");
|
||||
|
||||
if(localStorage.getItem("cfg_inited")!="true")
|
||||
{
|
||||
var config = 'input_player1_select = shift\n';
|
||||
config += 'audio_latency = 96\n'
|
||||
config += 'video_font_size = 16\n'
|
||||
config += 'rgui_browser_directory = /content\n';
|
||||
config += 'savefile_directory = /home/web_user/retroarch/saves/\n';
|
||||
config += 'savestate_directory = /home/web_user/retroarch/states/\n';
|
||||
config += 'system_directory = /home/web_user/retroarch/system/\n';
|
||||
config += 'rgui_config_directory = /home/web_user/.config/retroarch/\n';
|
||||
config += 'input_remapping_directory = /home/web_user/retroarch/remap/\n';
|
||||
config += 'cheat_database_path = /home/web_user/retroarch/cheat/\n';
|
||||
FS.writeFile('/home/web_user/.config/retroarch/retroarch.cfg',config);
|
||||
|
||||
localStorage.setItem("cfg_inited","true");
|
||||
console.log('Config initialized: ' + localStorage.getItem("cfg_inited"));
|
||||
}
|
||||
}
|
||||
|
||||
function setupFileSystem()
|
||||
{
|
||||
console.log("setupFileSystem");
|
||||
|
||||
if(localStorage.getItem("fs_inited")!="true")
|
||||
{
|
||||
var lsfs = new BrowserFS.FileSystem.LocalStorage();
|
||||
BrowserFS.initialize(lsfs);
|
||||
var BFS = new BrowserFS.EmscriptenFS();
|
||||
|
||||
FS.mount(BFS, {root: '/'}, '/home');
|
||||
|
||||
localStorage.setItem("fs_inited","true");
|
||||
console.log('Filesystem initialized: ' + localStorage.getItem("fs_inited"));
|
||||
}
|
||||
}
|
||||
|
||||
function runEmulator(files)
|
||||
{
|
||||
console.log("runEmulator");
|
||||
setupBFS();
|
||||
|
||||
if (Modernizr.localstorage)
|
||||
{
|
||||
setupFileSystem();
|
||||
}
|
||||
|
||||
setupFolders();
|
||||
createConfig();
|
||||
|
||||
if(firstRun)
|
||||
{
|
||||
setupFolders();
|
||||
|
||||
Module.FS_createFolder('/', 'etc', true, true);
|
||||
Module.FS_createFolder('/', 'retroarch', true, true);
|
||||
firstRun = false;
|
||||
}
|
||||
|
||||
FS.createFolder('/','content',true,true);
|
||||
|
||||
count = files.length;
|
||||
for (var i = 0; i < files.length; i++)
|
||||
for (var i = 0; i < files.length; i++)
|
||||
{
|
||||
filereader = new FileReader();
|
||||
filereader.file_name = files[i].name;
|
||||
filereader.onload = function(){initFromData(this.result, '/retroarch/' + this.file_name)};
|
||||
filereader.readAsArrayBuffer(files[i]);
|
||||
|
||||
|
||||
if(firstRun)
|
||||
{
|
||||
filereader.onload = function(){uploadContent(this.result, '/content/' + this.file_name)};
|
||||
firstRun = false;
|
||||
initFromData();
|
||||
}
|
||||
else
|
||||
filereader.onload = function(){uploadContent(this.result, '/content/' + this.file_name)};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function uploadSaveFiles(files)
|
||||
|
||||
function uploadContent(data, name)
|
||||
{
|
||||
console.log("uploadSaveFiles");
|
||||
|
||||
count = files.length;
|
||||
for (var i = 0; i < files.length; i++)
|
||||
{
|
||||
filereader = new FileReader();
|
||||
filereader.file_name = files[i].name;
|
||||
filereader.onload = function(){initFromData(this.result, '/data/saves/' + this.file_name)};
|
||||
filereader.readAsArrayBuffer(files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function initFromData(data, name)
|
||||
{
|
||||
|
||||
console.log("initFromData");
|
||||
|
||||
var dataView = new Uint8Array(data);
|
||||
Module.FS_createDataFile('/', name, dataView, true, false);
|
||||
Module.FS_createDataFile('/', name, dataView, true, false);
|
||||
}
|
||||
|
||||
function initFromData()
|
||||
{
|
||||
|
||||
count--;
|
||||
if (count === 0)
|
||||
if (count === 0)
|
||||
{
|
||||
var config = 'input_player1_select = shift\n';
|
||||
var latency = parseInt(document.getElementById('latency').value, 10);
|
||||
if (isNaN(latency))
|
||||
latency = 96;
|
||||
|
||||
config += 'audio_latency = ' + latency + '\n'
|
||||
if (document.getElementById('vsync').checked)
|
||||
config += 'video_vsync = true\n';
|
||||
else
|
||||
config += 'video_vsync = false\n';
|
||||
config += 'rgui_browser_directory = /retroarch/\n';
|
||||
config += 'savefile_directory = /data/saves\n';
|
||||
config += 'savestate_directory = /data/states\n';
|
||||
config += 'system_directory = /data/system/\n';
|
||||
Module.FS_createDataFile('/etc', 'retroarch.cfg', config, true, true);
|
||||
document.getElementById('canvas_div').style.display = 'block';
|
||||
document.getElementById('vsync').disabled = true;
|
||||
document.getElementById('vsync-label').style.color = 'gray';
|
||||
document.getElementById('latency').disabled = true;
|
||||
document.getElementById('latency-label').style.color = 'gray';
|
||||
Module['callMain'](Module['arguments']);
|
||||
}
|
||||
}
|
||||
|
||||
var Module =
|
||||
var Module =
|
||||
{
|
||||
noInitialRun: true,
|
||||
arguments: ["--verbose", "--menu"],
|
||||
@ -115,7 +123,7 @@ var Module =
|
||||
{
|
||||
var element = document.getElementById('output');
|
||||
element.value = ''; // clear browser cache
|
||||
return function(text)
|
||||
return function(text)
|
||||
{
|
||||
text = Array.prototype.slice.call(arguments).join(' ');
|
||||
// These replacements are necessary if you render to raw HTML
|
||||
@ -127,31 +135,31 @@ var Module =
|
||||
element.scrollTop = 99999; // focus on bottom
|
||||
};
|
||||
})(),
|
||||
|
||||
printErr: function(text)
|
||||
|
||||
printErr: function(text)
|
||||
{
|
||||
var text = Array.prototype.slice.call(arguments).join(' ');
|
||||
var element = document.getElementById('output');
|
||||
element.value += text + "\n";
|
||||
element.scrollTop = 99999; // focus on bottom
|
||||
},
|
||||
|
||||
|
||||
canvas: document.getElementById('canvas'),
|
||||
setStatus: function(text)
|
||||
setStatus: function(text)
|
||||
{
|
||||
if (Module.setStatus.interval)
|
||||
if (Module.setStatus.interval)
|
||||
clearInterval(Module.setStatus.interval);
|
||||
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
|
||||
var statusElement = document.getElementById('status');
|
||||
var progressElement = document.getElementById('progress');
|
||||
if (m)
|
||||
if (m)
|
||||
{
|
||||
text = m[1];
|
||||
progressElement.value = parseInt(m[2])*100;
|
||||
progressElement.max = parseInt(m[4])*100;
|
||||
progressElement.hidden = false;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
progressElement.value = null;
|
||||
progressElement.max = null;
|
||||
@ -161,7 +169,7 @@ var Module =
|
||||
},
|
||||
|
||||
totalDependencies: 0,
|
||||
monitorRunDependencies: function(left)
|
||||
monitorRunDependencies: function(left)
|
||||
{
|
||||
this.totalDependencies = Math.max(this.totalDependencies, left);
|
||||
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
|
||||
|
Loading…
Reference in New Issue
Block a user