mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Add ability to load files to custom paths
This commit is contained in:
parent
806623af69
commit
1a8e57982d
3 changed files with 42 additions and 8 deletions
|
@ -31,18 +31,12 @@ class EJS_GameManager {
|
||||||
setSlowMotionRatio: this.Module.cwrap('set_sm_ratio', 'null', ['number']),
|
setSlowMotionRatio: this.Module.cwrap('set_sm_ratio', 'null', ['number']),
|
||||||
getFrameNum: this.Module.cwrap('get_current_frame_count', 'number', [''])
|
getFrameNum: this.Module.cwrap('get_current_frame_count', 'number', [''])
|
||||||
}
|
}
|
||||||
this.mkdir("/home");
|
this.writeFile("/home/web_user/retroarch/userdata/config/Beetle PSX HW/Beetle PSX HW.opt", 'beetle_psx_hw_renderer = "software"\n');
|
||||||
this.mkdir("/home/web_user");
|
|
||||||
this.mkdir("/home/web_user/retroarch");
|
|
||||||
this.mkdir("/home/web_user/retroarch/userdata");
|
|
||||||
this.mkdir("/home/web_user/retroarch/userdata/config");
|
|
||||||
this.mkdir("/home/web_user/retroarch/userdata/config/Beetle PSX HW");
|
|
||||||
this.FS.writeFile("/home/web_user/retroarch/userdata/config/Beetle PSX HW/Beetle PSX HW.opt", 'beetle_psx_hw_renderer = "software"\n');
|
|
||||||
|
|
||||||
this.mkdir("/data");
|
this.mkdir("/data");
|
||||||
this.mkdir("/data/saves");
|
this.mkdir("/data/saves");
|
||||||
|
|
||||||
this.FS.writeFile("/home/web_user/retroarch/userdata/retroarch.cfg", this.getRetroArchCfg());
|
this.writeFile("/home/web_user/retroarch/userdata/retroarch.cfg", this.getRetroArchCfg());
|
||||||
|
|
||||||
this.FS.mount(IDBFS, {}, '/data/saves');
|
this.FS.mount(IDBFS, {}, '/data/saves');
|
||||||
this.FS.syncfs(true, () => {});
|
this.FS.syncfs(true, () => {});
|
||||||
|
@ -54,6 +48,44 @@ class EJS_GameManager {
|
||||||
this.FS.syncfs(() => {});
|
this.FS.syncfs(() => {});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
loadExternalFiles() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (this.EJS.config.externalFiles && this.EJS.config.externalFiles.constructor.name === 'Object') {
|
||||||
|
for (const key in this.EJS.config.externalFiles) {
|
||||||
|
let path = key;
|
||||||
|
if (key.trim().endsWith("/")) {
|
||||||
|
const invalidCharacters = /[#<$+%>!`&*'|{}/\\?"=@:^\r\n]/ig;
|
||||||
|
let name = this.EJS.config.externalFiles[key].split("/").pop().split("#")[0].split("?")[0].replace(invalidCharacters, "").trim();
|
||||||
|
if (!name) continue;
|
||||||
|
path += name;
|
||||||
|
}
|
||||||
|
this.EJS.downloadFile(this.EJS.config.externalFiles[key], (res) => {
|
||||||
|
if (res === -1) {
|
||||||
|
if (this.EJS.debug) console.warn("Failed to fetch file from '" + this.EJS.config.externalFiles[key] + "'. Make sure the file exists.");
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.writeFile(path, this.EJS.config.externalFiles[key]);
|
||||||
|
} catch(e) {
|
||||||
|
if (this.EJS.debug) console.warn("Failed to write file to '" + path + "'. Make sure there are no conflicting files.");
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
}, null, true, {responseType: "text", method: "GET"});
|
||||||
|
|
||||||
|
}
|
||||||
|
} else resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
writeFile(path, data) {
|
||||||
|
const parts = path.split("/");
|
||||||
|
let current = "/";
|
||||||
|
for (let i=0; i<parts.length-1; i++) {
|
||||||
|
if (!parts[i].trim()) continue;
|
||||||
|
current += parts[i] + "/";
|
||||||
|
this.mkdir(current);
|
||||||
|
}
|
||||||
|
this.FS.writeFile(path, data);
|
||||||
|
}
|
||||||
mkdir(path) {
|
mkdir(path) {
|
||||||
try {
|
try {
|
||||||
this.FS.mkdir(path);
|
this.FS.mkdir(path);
|
||||||
|
|
|
@ -1040,6 +1040,7 @@ class EmulatorJS {
|
||||||
downloadFiles() {
|
downloadFiles() {
|
||||||
(async () => {
|
(async () => {
|
||||||
this.gameManager = new window.EJS_GameManager(this.Module, this);
|
this.gameManager = new window.EJS_GameManager(this.Module, this);
|
||||||
|
await this.gameManager.loadExternalFiles();
|
||||||
if (this.getCore() === "ppsspp") {
|
if (this.getCore() === "ppsspp") {
|
||||||
await this.gameManager.loadPpssppAssets();
|
await this.gameManager.loadPpssppAssets();
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,7 @@
|
||||||
config.startBtnName = window.EJS_startButtonName;
|
config.startBtnName = window.EJS_startButtonName;
|
||||||
config.softLoad = window.EJS_softLoad;
|
config.softLoad = window.EJS_softLoad;
|
||||||
config.screenRecording = window.EJS_screenRecording;
|
config.screenRecording = window.EJS_screenRecording;
|
||||||
|
config.externalFiles = window.EJS_externalFiles;
|
||||||
|
|
||||||
if (typeof window.EJS_language === "string" && window.EJS_language !== "en-US") {
|
if (typeof window.EJS_language === "string" && window.EJS_language !== "en-US") {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue