mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2026-02-06 11:17:36 +00:00
Add directory listing method and enhance configuration handling
This commit is contained in:
parent
21b83ca54d
commit
d9909fea89
@ -463,6 +463,24 @@ IF EXIST AUTORUN.BAT AUTORUN.BAT
|
||||
setAltKeyEnabled(enabled) {
|
||||
this.functions.setKeyboardEnabled(enabled === true ? 3 : 2);
|
||||
}
|
||||
listDir(path, indent = "") {
|
||||
try {
|
||||
const entries = this.FS.readdir(path);
|
||||
for (const entry of entries) {
|
||||
if (entry === "." || entry === "..") continue;
|
||||
const fullPath = path === "/" ? `/${entry}` : `${path}/${entry}`;
|
||||
const stat = this.FS.stat(fullPath);
|
||||
if (this.FS.isDir(stat.mode)) {
|
||||
console.log(`${indent}[DIR] ${fullPath}`);
|
||||
this.listDir(fullPath, indent + " ");
|
||||
} else {
|
||||
console.log(`${indent}${fullPath}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error reading directory:", path, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.EJS_GameManager = EJS_GameManager;
|
||||
|
||||
@ -63,7 +63,7 @@ class EJS_Download {
|
||||
try {
|
||||
const headResp = await fetch(url, { method: "HEAD", headers });
|
||||
lastModified = headResp.headers.get("Last-Modified");
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
if (lastModified) {
|
||||
const lastModTime = Date.parse(lastModified);
|
||||
if (!isNaN(lastModTime) && lastModTime <= cached.added) {
|
||||
@ -106,10 +106,18 @@ class EJS_Download {
|
||||
const exp = Date.parse(expires);
|
||||
if (!isNaN(exp)) cacheExpiry = exp;
|
||||
} else {
|
||||
// default to 5 days if no cache headers present
|
||||
cacheExpiry = now + 5 * 24 * 60 * 60 * 1000;
|
||||
}
|
||||
if (responseType === "arraybuffer") {
|
||||
const contentLength = parseInt(resp.headers.get("Content-Length") || "0");
|
||||
let contentLength = 0;
|
||||
if (resp.headers.get("Content-Length")) {
|
||||
try {
|
||||
contentLength = parseInt(resp.headers.get("Content-Length"));
|
||||
} catch (e) {
|
||||
// swallow any errors parseing content length
|
||||
}
|
||||
}
|
||||
const reader = resp.body.getReader();
|
||||
let received = 0;
|
||||
let chunks = [];
|
||||
@ -162,21 +170,21 @@ class EJS_Download {
|
||||
} else {
|
||||
// for non-arraybuffer types, just store the raw data as a single file
|
||||
files = [new EJS_FileItem(filename, data)];
|
||||
if (typeof data === "string") {
|
||||
// Encode string as UTF-8 Uint8Array
|
||||
const encoder = new TextEncoder();
|
||||
files = [new EJS_FileItem(filename, encoder.encode(data))];
|
||||
} else if (data instanceof Uint8Array) {
|
||||
files = [new EJS_FileItem(filename, data)];
|
||||
} else if (data instanceof ArrayBuffer) {
|
||||
files = [new EJS_FileItem(filename, new Uint8Array(data))];
|
||||
} else {
|
||||
// Fallback: try to convert to string then encode
|
||||
const encoder = new TextEncoder();
|
||||
files = [new EJS_FileItem(filename, encoder.encode(String(data)))];
|
||||
if (typeof data === "string") {
|
||||
// Encode string as UTF-8 Uint8Array
|
||||
const encoder = new TextEncoder();
|
||||
files = [new EJS_FileItem(filename, encoder.encode(data))];
|
||||
} else if (data instanceof Uint8Array) {
|
||||
files = [new EJS_FileItem(filename, data)];
|
||||
} else if (data instanceof ArrayBuffer) {
|
||||
files = [new EJS_FileItem(filename, new Uint8Array(data))];
|
||||
} else {
|
||||
// Fallback: try to convert to string then encode
|
||||
const encoder = new TextEncoder();
|
||||
files = [new EJS_FileItem(filename, encoder.encode(String(data)))];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (onProgress) onProgress("complete", 100, data.byteLength || 0, data.byteLength || 0);
|
||||
|
||||
// Store in cache if available
|
||||
|
||||
@ -412,6 +412,9 @@ class EmulatorJS {
|
||||
if (typeof this.config.cacheConfig.cacheMaxAgeMins !== "number" || this.config.cacheConfig.cacheMaxAgeMins <= 0) {
|
||||
this.config.cacheConfig.cacheMaxAgeMins = cacheConfigDefaults.cacheMaxAgeMins;
|
||||
}
|
||||
if (this.config.disableDatabases === true) {
|
||||
this.config.cacheConfig.enabled = false;
|
||||
}
|
||||
|
||||
// Populate downloadTypes
|
||||
this.downloadType = {
|
||||
@ -1233,27 +1236,8 @@ class EmulatorJS {
|
||||
|
||||
// debug list directory structure
|
||||
if (this.debug && this.gameManager && this.gameManager.FS) {
|
||||
const FS = this.gameManager.FS;
|
||||
console.log("File system directory");
|
||||
function listDir(path, indent = "") {
|
||||
try {
|
||||
const entries = FS.readdir(path);
|
||||
for (const entry of entries) {
|
||||
if (entry === "." || entry === "..") continue;
|
||||
const fullPath = path === "/" ? `/${entry}` : `${path}/${entry}`;
|
||||
const stat = FS.stat(fullPath);
|
||||
if (FS.isDir(stat.mode)) {
|
||||
console.log(`${indent}[DIR] ${fullPath}`);
|
||||
listDir(fullPath, indent + " ");
|
||||
} else {
|
||||
console.log(`${indent}${fullPath}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error reading directory:", path, e);
|
||||
}
|
||||
}
|
||||
listDir("/");
|
||||
this.gameManager.listDir("/");
|
||||
}
|
||||
} catch(e) {
|
||||
console.warn("Failed to start game", e);
|
||||
@ -2637,9 +2621,10 @@ class EmulatorJS {
|
||||
list.style.width = "100%";
|
||||
list.style["padding-left"] = "10px";
|
||||
list.style["text-align"] = "left";
|
||||
body.appendChild(list);
|
||||
|
||||
list.appendChild(thead);
|
||||
list.appendChild(tbody);
|
||||
body.appendChild(list);
|
||||
|
||||
const getSize = function (size) {
|
||||
let i = -1;
|
||||
|
||||
@ -398,7 +398,6 @@
|
||||
window.EJS_gameName = parts.shift();
|
||||
window.EJS_biosUrl = biosUrl;
|
||||
window.EJS_gameUrl = url;
|
||||
// window.EJS_gameUrl = "smb.zip";
|
||||
window.EJS_core = core;
|
||||
window.EJS_pathtodata = "data/";
|
||||
window.EJS_startOnLoaded = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user