From de9e978e555ca9a45b6f7185282ad27e49728e65 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 3 Jun 2026 09:45:04 +0200 Subject: [PATCH] fix: mount .bin directly instead of .cue to avoid case mismatch .cue files contain an internal FILE reference (e.g. FILE "z.BIN") that may not match the actual filename on disk (e.g. z.bin) due to case differences. In js-dos's case-sensitive WASM filesystem, this causes the imgmount to fail silently. Changes: - Added .bin to CD_EXT so findCdImages detects bin files - When both .cue and .bin exist in the same directory, only the .bin is mounted (with -fs iso flag for direct filesystem access) - .cue files without a matching .bin are still mounted as before - Deduplication prevents mounting both .cue and .bin from same dir --- .../java/com/dostalgia/UploadResource.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dostalgia/UploadResource.java b/src/main/java/com/dostalgia/UploadResource.java index c170c36..e3a18ce 100644 --- a/src/main/java/com/dostalgia/UploadResource.java +++ b/src/main/java/com/dostalgia/UploadResource.java @@ -391,7 +391,7 @@ public class UploadResource { /** File extensions that DOSBox can mount as CD-ROM via imgmount. */ private static final java.util.Set CD_EXT = java.util.Set.of( - ".iso", ".cue", ".img", ".ccd" + ".iso", ".cue", ".img", ".ccd", ".bin" ); /** Find mountable CD image files in the extracted game directory. @@ -584,10 +584,30 @@ public class UploadResource { sb.append("[autoexec]\n"); sb.append("@echo off\n"); sb.append("mount c .\n"); - // Mount CD images as D:, E:, … so games can find their CD + // Mount CD images as D:, E:, … so games can find their CD. + // Prefer .bin over .cue from the same directory to avoid case-mismatch + // between the .cue's internal FILE reference and the actual filename. + // .bin files are mounted with -fs iso for direct filesystem access. + Set seenDirs = new java.util.HashSet<>(); char driveLetter = 'D'; for (String img : cdImages) { - sb.append("imgmount ").append(driveLetter).append(" \"").append(img).append("\" -t cdrom\n"); + // Deduplicate by directory — prefer .bin over .cue + int slashIdx = img.lastIndexOf('/'); + String parentDir = slashIdx >= 0 ? img.substring(0, slashIdx) : ""; + String imgLower = img.toLowerCase(); + if (seenDirs.contains(parentDir)) continue; + if (imgLower.endsWith(".cue")) { + // Check if a .bin exists in the same directory + boolean hasBin = cdImages.stream().anyMatch(i -> { + int is = i.lastIndexOf('/'); + String ip = is >= 0 ? i.substring(0, is) : ""; + return ip.equals(parentDir) && i.toLowerCase().endsWith(".bin"); + }); + if (hasBin) continue; // .bin will be mounted instead (lower in list) + } + seenDirs.add(parentDir); + String flags = imgLower.endsWith(".bin") ? " -t cdrom -fs iso" : " -t cdrom"; + sb.append("imgmount ").append(driveLetter).append(" \"").append(img).append("\"").append(flags).append("\n"); driveLetter++; } sb.append("c:\n");