Skip to content

Commit

Permalink
Fix saves; Use upstream desmume
Browse files Browse the repository at this point in the history
  • Loading branch information
Namaneo committed Aug 17, 2023
1 parent 35f740d commit a388d0d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 44 deletions.
4 changes: 1 addition & 3 deletions cores/cores.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"makefile": "Makefile.libretro",
"systems": [
{
"name": "A libretro port of the famous game",
"name": "Get to the 2048 tile!",
"standalone": true
}
]
Expand Down Expand Up @@ -38,8 +38,6 @@
"desmume": {
"name": "DeSmuME",
"directory": "desmume/src/frontend/libretro",
"owner": "Namaneo",
"branch": "advsc_has-database",
"systems": [
{
"name": "Nintendo DS",
Expand Down
Binary file modified cores/libdesmume.a
Binary file not shown.
2 changes: 1 addition & 1 deletion ui/sources/entities/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Save {

const game = system.games.find(game => game.rom == `${this.game}.${system.extension}`);
if (!game)
return false;
return system.standalone;

return true;
}
Expand Down
77 changes: 37 additions & 40 deletions ui/sources/services/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

export default class Filesystem {
/** @type {{ [path: string]: FileSystemSyncAccessHandle }} */
#handles = [];
static #handles = [];

/**
* @param {string} path
* @returns {{ directories: string[], filename: string }}
*/
#parse(path) {
if (path.startsWith('/'))
path = path.substring(1);

static #parse(path) {
if (path.indexOf('/') == -1)
return { directories: [], filename: path };

Expand All @@ -25,9 +22,9 @@ export default class Filesystem {
* @param {string} path
* @returns {Promise<FileSystemDirectoryHandle>}
*/
async #directory(path, create) {
static async #directory(path, create) {
let directory = await navigator.storage.getDirectory();
for (const component of this.#parse(path).directories)
for (const component of Filesystem.#parse(path).directories)
directory = await directory.getDirectoryHandle(component, { create });
return directory;
}
Expand All @@ -37,7 +34,7 @@ export default class Filesystem {
* @param {string} path
* @returns {Promise<string[]>}
*/
async #list(root, path) {
static async #list(root, path) {
if (!root) root = await navigator.storage.getDirectory();
if (!path) path = '';

Expand All @@ -47,40 +44,35 @@ export default class Filesystem {
files.push(`${path}/${handle.name}`);

if (handle.kind == 'directory')
files.push(...await this.#list(handle, `${path}/${handle.name}`));
files.push(...await Filesystem.#list(handle, `${path}/${handle.name}`));
}
return files;
};

/**
* @param {string} path
* @returns {Promise<FileSystemFileHandle>}
*/
async #file(path, create) {
const directory = await this.#directory(path, create);
const filename = this.#parse(path).filename;
return await directory.getFileHandle(filename, { create });
}

/**
* @param {string} path
* @param {(file: FileSystemSyncAccessHandle) => number} action
* @returns {Promise<number>}
*/
async #exec(path, create, action) {
if (!this.#handles[path]) {
const handle = await this.#file(path, create);
this.#handles[path] = await handle.createSyncAccessHandle();
static async #exec(path, create, action) {
if (path.startsWith('/'))
path = path.substring(1);

if (!Filesystem.#handles[path]) {
const directory = await Filesystem.#directory(path, create);
const filename = Filesystem.#parse(path).filename;
const handle = await directory.getFileHandle(filename, { create });
Filesystem.#handles[path] = await handle.createSyncAccessHandle();
}

return action(this.#handles[path]);
return action(Filesystem.#handles[path]);
}

/**
* @param {() => Promise<number>} action
* @returns {Promise<number>}
*/
async #catch(action, err_val) {
static async #catch(action, err_val) {
try {
return await action();

Expand All @@ -93,8 +85,8 @@ export default class Filesystem {
* @returns {string[] | Promise<string[]>}
*/
list() {
return this.#catch(async () => {
return await this.#list();
return Filesystem.#catch(() => {
return Filesystem.#list();
}, []);
}

Expand All @@ -103,30 +95,32 @@ export default class Filesystem {
* @returns {number | Promise<number>}
*/
size(path) {
return this.#catch(async () => {
return await this.#exec(path, false, (file) => file.getSize());
return Filesystem.#catch(() => {
return Filesystem.#exec(path, false, (file) => file.getSize());
}, -1);
}

/**
* @param {string} path
* @param {Uint8Array} buffer
* @param {number} offset
* @returns {number | Promise<number>}
*/
read(path, buffer, offset) {
return this.#catch(async () => {
return await this.#exec(path, false, (file) => file.read(buffer, { at: offset }));
return Filesystem.#catch(() => {
return Filesystem.#exec(path, false, (file) => file.read(buffer, { at: offset }));
}, -1);
}

/**
* @param {string} path
* @param {Uint8Array} buffer
* @param {number} offset
* @returns {number | Promise<number>}
*/
write(path, buffer, offset) {
return this.#catch(async () => {
return await this.#exec(path, true, (file) => file.write(buffer, { at: offset }));
return Filesystem.#catch(() => {
return Filesystem.#exec(path, true, (file) => file.write(buffer, { at: offset }));
}, -1);
}

Expand All @@ -135,15 +129,18 @@ export default class Filesystem {
* @returns {number | Promise<number>}
*/
remove(path) {
return this.#catch(async () => {
if (this.#handles[path]) {
this.#handles[path].flush();
this.#handles[path].close();
delete this.#handles[path];
return Filesystem.#catch(async () => {
if (path.startsWith('/'))
path = path.substring(1);

if (Filesystem.#handles[path]) {
Filesystem.#handles[path].flush();
Filesystem.#handles[path].close();
delete Filesystem.#handles[path];
}

const handle = await this.#directory(path);
await handle.removeEntry(this.#parse(path).filename);
const handle = await Filesystem.#directory(path);
await handle.removeEntry(Filesystem.#parse(path).filename);

return 0;
}, -1);
Expand Down

0 comments on commit a388d0d

Please sign in to comment.