fix: load selected file with correct extension for multi-file roms#3844
Merged
Conversation
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>
Contributor
Greptile SummaryThis PR gives single selected ROM files their real extension in EmulatorJS content URLs. The main changes are:
Confidence Score: 4/5The selected-file URL path needs filename encoding before merging.
frontend/src/utils/index.ts Important Files Changed
Prompt To Fix All With AIFix 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 |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.getDownloadPathbuilt that URL using the ROM-levelfs_name:fs_nameis the file name and carries the extension (Maniac Mansion (1989).adf) → core sees.adf→ works.fs_nameis the folder name with no extension (B.A.T., whosefs_extensionis""by design) → the core gets an extension-less file →Unsupported file format: ''.The backend was already correct: for a single
file_idsvalue 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/v2Player.vueand the consolePlay.vue) as well as download buttons. Multi-file/zip downloads and no-selection cases fall back tofs_nameunchanged.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
Verification run:
vitest(4 new cases pass),npm run typecheckclean,trunk fmt/trunk checkclean. Not yet browser-tested end-to-end with a real multi-disk rom.Fixes #3746
🤖 Generated with Claude Code