Skip to content

fix: load selected file with correct extension for multi-file roms#3844

Merged
gantoine merged 4 commits into
masterfrom
fix/multi-file-rom-emulator-extension
Jul 20, 2026
Merged

fix: load selected file with correct extension for multi-file roms#3844
gantoine merged 4 commits into
masterfrom
fix/multi-file-rom-emulator-extension

Conversation

@gantoine

Copy link
Copy Markdown
Member

Description

Multi-file roms (multi-disk games grouped in a subfolder, e.g. floppy-based Amiga games) failed to launch in the EmulatorJS player with the overlay error Unsupported file format: ''. Single-file roms on the same platform worked fine.

Root cause

EmulatorJS derives the filename it writes into the emulator's virtual filesystem from the last path segment of the game URL (getBaseFileName(true)gameUrl.split("/").pop().split("?")[0]), and the libretro core (e.g. puae) determines the disk format from that filename's extension.

getDownloadPath built that URL using the ROM-level fs_name:

/api/roms/24/content/B.A.T.?file_ids=29
  • Single-file rom: fs_name is the file name and carries the extension (Maniac Mansion (1989).adf) → core sees .adf → works.
  • Multi-file rom: the rom is a folder, so fs_name is the folder name with no extension (B.A.T., whose fs_extension is "" by design) → the core gets an extension-less file → Unsupported file format: ''.

The backend was already correct: for a single file_ids value it serves the actual raw file, and the path segment is only used for zip/m3u naming.

Fix

When exactly one file is selected, use that file's real name (extension included) as the content path segment instead of the folder-level fs_name. This is the single shared helper used by all EmulatorJS entry points (v1/v2 Player.vue and the console Play.vue) as well as download buttons. Multi-file/zip downloads and no-selection cases fall back to fs_name unchanged.

Scope note

This fixes loading the selected disk. In-emulator disk swapping across all disks via an m3u playlist is a separate feature and is not addressed here.

AI assistance disclosure

This change was written with AI assistance (Claude Code). The AI investigated the issue, traced the EmulatorJS 4.2.3 file-loading path, implemented the fix, and added unit tests. Changes were reviewed by the author.

Checklist

  • I've tested the changes locally
  • I've updated relevant comments
  • I've assigned reviewers for this PR
  • I've added unit tests that cover the changes

Verification run: vitest (4 new cases pass), npm run typecheck clean, trunk fmt / trunk check clean. Not yet browser-tested end-to-end with a real multi-disk rom.

Fixes #3746

🤖 Generated with Claude Code

Multi-file roms (e.g. multi-disk Amiga games) failed to launch in the
EmulatorJS player with "Unsupported file format: ''", while single-file
roms on the same platform worked.

EmulatorJS derives the on-disk filename it writes to the emulator FS from
the last path segment of the game URL, and the core determines the disk
format from that filename's extension. getDownloadPath used the ROM-level
fs_name for that segment. For multi-file roms the rom is a folder, so
fs_name has no extension, and the core received an extension-less file.

When a single file is selected, use that file's real name (extension
included) as the content path segment instead of fs_name. The backend
already serves the correct file for a single file_ids value and only uses
the path segment for zip/m3u naming, so multi-file and no-selection cases
are unchanged.

Fixes #3746

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 20, 2026 01:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR gives single selected ROM files their real extension in EmulatorJS content URLs. The main changes are:

  • Use the selected file name for one-file requests.
  • Preserve the ROM-level name for other requests.
  • Add tests for selection and fallback behavior.

Confidence Score: 4/5

The selected-file URL path needs filename encoding before merging.

  • The selected file lookup matches the backend's file-ID behavior.
  • Reserved filename characters can remove the file-ID query or change the route.
  • The tests cover selection counts and unknown IDs, but not URL delimiters.

frontend/src/utils/index.ts

Important Files Changed

Filename Overview
frontend/src/utils/index.ts Uses the selected file name for single-file URLs, but does not encode reserved path characters.
frontend/src/utils/index.test.ts Covers the main selection branches but not filenames containing URL delimiters.

Fix All in Claude Code

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
frontend/src/utils/index.ts:138
**Filename Delimiters Corrupt The URL**

When a selected file is named `Disk #1.adf`, the browser treats `#1.adf?file_ids=29` as a fragment, so the backend receives neither the full filename nor `file_ids`. It can then return the complete multi-file ROM instead of the selected disk; `?` and `/` in filenames can similarly alter query parsing or routing. Encode the selected filename as one path component.

```suggestion
  const contentName = selectedFile
    ? encodeURIComponent(selectedFile.file_name)
    : rom.fs_name;
```

Reviews (1): Last reviewed commit: "fix: load selected file with correct ext..." | Re-trigger Greptile

Comment thread frontend/src/utils/index.ts Outdated
gantoine and others added 3 commits July 19, 2026 22:07
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
The greptile suggestion added encodeURIComponent to the selected file
name in getDownloadPath, but the test still expected a literal space.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gantoine
gantoine merged commit b0a7d59 into master Jul 20, 2026
11 checks passed
@gantoine
gantoine deleted the fix/multi-file-rom-emulator-extension branch July 20, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-file ROMs fail to load with "Unsupported file format" — HEAD request never followed by GET

2 participants