mirror of
https://github.com/rommapp/romm.git
synced 2026-12-05 23:44:11 +01:00
Merge pull request #4741 from yiannias/fix/amiga-puae-kickstart-firmware
fix(player): make all Amiga Kickstarts available to PUAE
This commit is contained in:
@@ -32,6 +32,7 @@ import {
|
||||
areThreadsRequiredForEJSCore,
|
||||
getDownloadPath,
|
||||
} from "@/utils";
|
||||
import { firmwareExternalFiles } from "@/v2/utils/playerFirmware";
|
||||
import {
|
||||
buildStateFormData,
|
||||
resolveScreenshot,
|
||||
@@ -471,8 +472,10 @@ async function boot() {
|
||||
window.EJS_biosUrl = bios
|
||||
? `/api/firmware/${bios.id}/content/${bios.file_name}`
|
||||
: "";
|
||||
window.EJS_externalFiles = firmwareExternalFiles(core, firmware);
|
||||
} catch {
|
||||
window.EJS_biosUrl = "";
|
||||
window.EJS_externalFiles = {};
|
||||
}
|
||||
|
||||
window.EJS_player = "#game";
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveInitialFirmware } from "./playerFirmware";
|
||||
import {
|
||||
firmwareExternalFiles,
|
||||
resolveInitialFirmware,
|
||||
} from "./playerFirmware";
|
||||
|
||||
// Only these three fields are read; minimal stubs stand in for FirmwareSchema.
|
||||
const fw = (id: number, file_name: string, missing_from_fs = false) => ({
|
||||
@@ -96,3 +99,43 @@ describe("resolveInitialFirmware", () => {
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
const firmware = [
|
||||
fw(1, "kick34005.A500"),
|
||||
fw(2, "kick40068.A1200"),
|
||||
fw(3, "gone.rom", true),
|
||||
fw(4, "bios.zip"),
|
||||
];
|
||||
|
||||
describe("firmwareExternalFiles", () => {
|
||||
it("places every available Kickstart in the PUAE system directory", () => {
|
||||
expect(firmwareExternalFiles("puae", firmware)).toEqual({
|
||||
"/home/web_user/retroarch/userdata/system/kick34005.A500":
|
||||
"/api/firmware/1/content/kick34005.A500",
|
||||
"/home/web_user/retroarch/userdata/system/kick40068.A1200":
|
||||
"/api/firmware/2/content/kick40068.A1200",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not change firmware loading for another core", () => {
|
||||
expect(firmwareExternalFiles("pcsx_rearmed", firmware)).toEqual({});
|
||||
});
|
||||
|
||||
it("ignores unsafe filenames", () => {
|
||||
expect(
|
||||
firmwareExternalFiles("puae", [
|
||||
fw(1, "../other.rom"),
|
||||
fw(2, "folder\\file.rom"),
|
||||
fw(3, ".."),
|
||||
fw(4, "."),
|
||||
]),
|
||||
).toEqual({});
|
||||
});
|
||||
|
||||
it("encodes the name in the URL but keeps it verbatim in the path", () => {
|
||||
expect(firmwareExternalFiles("puae", [fw(5, "kick #1?.rom")])).toEqual({
|
||||
"/home/web_user/retroarch/userdata/system/kick #1?.rom":
|
||||
"/api/firmware/5/content/kick%20%231%3F.rom",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,3 +34,32 @@ export function resolveInitialFirmware<T extends FirmwareLike>({
|
||||
|
||||
return fromStorage ?? fromConfig ?? fromSingleOption ?? null;
|
||||
}
|
||||
|
||||
const SYSTEM_DIRECTORY = "/home/web_user/retroarch/userdata/system";
|
||||
const UNSAFE_FILE_NAME = /^\.{1,2}$|[\\/]/;
|
||||
// EJS_externalFiles writes an archive to a file key raw (4.2.3) or as its first
|
||||
// entry (nightly), so archives keep loading through EJS_biosUrl.
|
||||
const ARCHIVE_EXTENSION = /\.(zip|7z|rar)$/i;
|
||||
|
||||
/** Every platform firmware file for PUAE, as EJS_externalFiles entries. */
|
||||
export function firmwareExternalFiles(
|
||||
core: string,
|
||||
firmware: readonly FirmwareLike[],
|
||||
): Record<string, string> {
|
||||
// PUAE picks among several Kickstarts by name for each game.
|
||||
if (core !== "puae") return {};
|
||||
|
||||
return Object.fromEntries(
|
||||
firmware
|
||||
.filter(
|
||||
({ file_name, missing_from_fs }) =>
|
||||
!missing_from_fs &&
|
||||
!UNSAFE_FILE_NAME.test(file_name) &&
|
||||
!ARCHIVE_EXTENSION.test(file_name),
|
||||
)
|
||||
.map(({ id, file_name }) => [
|
||||
`${SYSTEM_DIRECTORY}/${file_name}`,
|
||||
`/api/firmware/${id}/content/${encodeURIComponent(file_name)}`,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1084,6 +1084,7 @@ const saveSlot = computed(() => chosenSlot(slotChoice.value, customSlot.value));
|
||||
:save-slot="saveSlot"
|
||||
:load-state-label="t('rom.load-save-or-state')"
|
||||
:bios="selectedFirmware"
|
||||
:firmware="firmwareOptions"
|
||||
:core="selectedCore"
|
||||
:disc="bootDiscId(selectedDisc)"
|
||||
/>
|
||||
|
||||
@@ -629,6 +629,7 @@ function openCacheDialog() {
|
||||
:state="selectedState"
|
||||
:save="selectedSave"
|
||||
:bios="selectedFirmware"
|
||||
:firmware="firmwareOptions"
|
||||
:core="selectedCore"
|
||||
:disc="selectedDisc"
|
||||
/>
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
getDownloadPath,
|
||||
} from "@/utils";
|
||||
import { useSnackbar, type SnackbarTone } from "@/v2/composables/useSnackbar";
|
||||
import { firmwareExternalFiles } from "@/v2/utils/playerFirmware";
|
||||
import {
|
||||
saveSave,
|
||||
captureScreenshot,
|
||||
@@ -78,6 +79,7 @@ const props = defineProps<{
|
||||
save: SaveSchema | null;
|
||||
state: StateSchema | null;
|
||||
bios: FirmwareSchema | null;
|
||||
firmware: FirmwareSchema[];
|
||||
core: string | null;
|
||||
disc: number | null;
|
||||
/** Slot for new saves when the loaded save has none; defaults to autosave. */
|
||||
@@ -335,6 +337,10 @@ window.EJS_gameUrl = getDownloadPath({
|
||||
window.EJS_biosUrl = props.bios
|
||||
? `/api/firmware/${props.bios.id}/content/${props.bios.file_name}`
|
||||
: "";
|
||||
window.EJS_externalFiles = firmwareExternalFiles(
|
||||
window.EJS_core,
|
||||
props.firmware,
|
||||
);
|
||||
window.EJS_player = "#game";
|
||||
window.EJS_color = "#A453FF";
|
||||
window.EJS_alignStartButton = "center";
|
||||
|
||||
Reference in New Issue
Block a user