mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 18:42:34 +01:00
fix(jsdos): only offer the player for .jsdos bundles
js-dos boots exactly one format. Its `url` option runs the file through emulators.bundleConfig(), which requires an archive carrying `.jsdos/dosbox.conf`; handed an ordinary scanned game it panics with "Broken bundle, .jsdos/dosbox.conf not found" and the player never starts. Gate canPlayJsDos on the file extension so Play is offered only for files the player can actually boot, instead of routing a win3x/win9x ROM to a dead screen. The platform-level check is unchanged: usePlatformPlayable knows only a slug, and a win3x platform is still playable in browser given a bundle. Booting unbundled games would mean supplying `dosboxConf` and `initFs` ourselves, which needs entrypoint detection and, for Win9x, a system image. That is a feature in its own right, not a fix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,11 @@ import { describe, expect, it } from "vitest";
|
||||
import type { Config } from "@/stores/config";
|
||||
import type { Heartbeat } from "@/stores/heartbeat";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import { getDownloadPath, isJsDosEmulationSupported } from "./index";
|
||||
import {
|
||||
getDownloadPath,
|
||||
isJsDosBundle,
|
||||
isJsDosEmulationSupported,
|
||||
} from "./index";
|
||||
|
||||
function makeRom(overrides: Partial<SimpleRom>): SimpleRom {
|
||||
return {
|
||||
@@ -142,3 +146,25 @@ describe("isJsDosEmulationSupported", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isJsDosBundle", () => {
|
||||
const withExt = (fs_extension: string) =>
|
||||
makeRom({ fs_extension } as Partial<SimpleRom>);
|
||||
|
||||
it("accepts a .jsdos bundle regardless of case", () => {
|
||||
expect(isJsDosBundle(withExt("jsdos"))).toBe(true);
|
||||
expect(isJsDosBundle(withExt("JSDOS"))).toBe(true);
|
||||
});
|
||||
|
||||
// js-dos panics with "Broken bundle" on anything that is not its own format.
|
||||
it("rejects plain archives, bare executables and folders", () => {
|
||||
expect(isJsDosBundle(withExt("zip"))).toBe(false);
|
||||
expect(isJsDosBundle(withExt("exe"))).toBe(false);
|
||||
expect(isJsDosBundle(withExt(""))).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects a missing rom", () => {
|
||||
expect(isJsDosBundle(null)).toBe(false);
|
||||
expect(isJsDosBundle(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -702,6 +702,9 @@ export function isRuffleEmulationSupported(
|
||||
return ["flash", "browser"].includes(slug.toLowerCase());
|
||||
}
|
||||
|
||||
/** File extension of a js-dos bundle. */
|
||||
export const JSDOS_BUNDLE_EXTENSION = "jsdos";
|
||||
|
||||
/**
|
||||
* Check if js-dos emulation is supported for a given platform.
|
||||
*
|
||||
@@ -721,6 +724,21 @@ export function isJsDosEmulationSupported(
|
||||
return ["win3x", "win9x"].includes(slug.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a ROM file is a js-dos bundle.
|
||||
*
|
||||
* js-dos boots only its own bundle format: an archive carrying
|
||||
* `.jsdos/dosbox.conf`. Handed a bare game folder or a plain archive it panics
|
||||
* with "Broken bundle", so the play routes gate on the extension rather than
|
||||
* offering a player that cannot start.
|
||||
*
|
||||
* @param rom The ROM to check.
|
||||
* @returns True if the file is a js-dos bundle, false otherwise.
|
||||
*/
|
||||
export function isJsDosBundle(rom: SimpleRom | null | undefined) {
|
||||
return rom?.fs_extension.toLowerCase() === JSDOS_BUNDLE_EXTENSION;
|
||||
}
|
||||
|
||||
export type PlayingStatus =
|
||||
RomUserStatus | "backlogged" | "now_playing" | "hidden";
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ const support = vi.hoisted(() => ({
|
||||
ejs: vi.fn(() => false),
|
||||
jsDos: vi.fn(() => false),
|
||||
ruffle: vi.fn(() => false),
|
||||
// js-dos also demands its own bundle format; on by default so the engine
|
||||
// stubs stay the only variable.
|
||||
jsDosBundle: vi.fn(() => true),
|
||||
}));
|
||||
|
||||
const heartbeat = ref({});
|
||||
@@ -22,6 +25,7 @@ vi.mock("@/utils", () => ({
|
||||
isEJSEmulationSupported: support.ejs,
|
||||
isJsDosEmulationSupported: support.jsDos,
|
||||
isRuffleEmulationSupported: support.ruffle,
|
||||
isJsDosBundle: support.jsDosBundle,
|
||||
}));
|
||||
|
||||
function makeRom(overrides: Partial<SimpleRom> = {}): SimpleRom {
|
||||
@@ -38,9 +42,11 @@ beforeEach(() => {
|
||||
support.ejs.mockReturnValue(false);
|
||||
support.jsDos.mockReturnValue(false);
|
||||
support.ruffle.mockReturnValue(false);
|
||||
support.jsDosBundle.mockReturnValue(true);
|
||||
support.ejs.mockClear();
|
||||
support.jsDos.mockClear();
|
||||
support.ruffle.mockClear();
|
||||
support.jsDosBundle.mockClear();
|
||||
});
|
||||
|
||||
describe("useCanPlay", () => {
|
||||
@@ -85,6 +91,17 @@ describe("useCanPlay", () => {
|
||||
expect(canPlayRuffle.value).toBe(false);
|
||||
});
|
||||
|
||||
// A bare game folder or plain archive makes js-dos panic with
|
||||
// "Broken bundle", so offering Play would hand the user a dead player.
|
||||
it("refuses js-dos for a rom that is not a bundle", () => {
|
||||
support.jsDos.mockReturnValue(true);
|
||||
support.jsDosBundle.mockReturnValue(false);
|
||||
const { canPlay, canPlayJsDos } = useCanPlay(() => makeRom());
|
||||
|
||||
expect(canPlayJsDos.value).toBe(false);
|
||||
expect(canPlay.value).toBe(false);
|
||||
});
|
||||
|
||||
it("stays unplayable when no engine supports the platform", () => {
|
||||
const { canPlay } = useCanPlay(() => makeRom());
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
// "Playable" means EJS, js-dos, or Ruffle can run the platform on this
|
||||
// server (admin toggles + platform support + WebGL availability), and
|
||||
// there is a file to boot: a physical game or one missing from the
|
||||
// filesystem has nothing to hand the emulator. The individual flags are
|
||||
// exposed so the play action can pick the right route.
|
||||
// filesystem has nothing to hand the emulator. js-dos additionally needs
|
||||
// the file to be one of its own bundles. The individual flags are exposed
|
||||
// so the play action can pick the right route.
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, type ComputedRef } from "vue";
|
||||
import storeConfig from "@/stores/config";
|
||||
@@ -15,6 +16,7 @@ import storeHeartbeat from "@/stores/heartbeat";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import {
|
||||
isEJSEmulationSupported,
|
||||
isJsDosBundle,
|
||||
isJsDosEmulationSupported,
|
||||
isRuffleEmulationSupported,
|
||||
} from "@/utils";
|
||||
@@ -37,9 +39,15 @@ export function useCanPlay(getRom: () => SimpleRom | null | undefined): {
|
||||
});
|
||||
|
||||
const canPlayEJS = supportedBy(isEJSEmulationSupported);
|
||||
const canPlayJsDos = supportedBy(isJsDosEmulationSupported);
|
||||
const canPlayRuffle = supportedBy(isRuffleEmulationSupported);
|
||||
|
||||
// js-dos boots only its own `.jsdos` bundle, so the platform alone would
|
||||
// offer Play on files the player panics on.
|
||||
const onJsDosPlatform = supportedBy(isJsDosEmulationSupported);
|
||||
const canPlayJsDos = computed(
|
||||
() => onJsDosPlatform.value && isJsDosBundle(getRom()),
|
||||
);
|
||||
|
||||
const canPlay = computed(
|
||||
() => canPlayEJS.value || canPlayJsDos.value || canPlayRuffle.value,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user