diff --git a/src/main/java/com/dostalgia/UploadResource.java b/src/main/java/com/dostalgia/UploadResource.java index b4490d1..81ecb04 100644 --- a/src/main/java/com/dostalgia/UploadResource.java +++ b/src/main/java/com/dostalgia/UploadResource.java @@ -82,10 +82,13 @@ public class UploadResource { // Find main executable String mainExe = findMainExe(extractDir); + + // Detect CD images once (used for both CD-only detection and config generation) + List cdImages = findCdImages(extractDir); + if (mainExe == null) { // No executable on the filesystem — check if CD images exist instead - List cdOnlyImages = findCdImages(extractDir); - if (cdOnlyImages.isEmpty()) { + if (cdImages.isEmpty()) { return Response.status(400) .entity(Map.of("error", "No executable (.exe/.com/.bat) found in the archive")) .build(); @@ -103,7 +106,7 @@ public class UploadResource { // Create .jsdos bundle inside the game directory String bundleFile = gameId + "/" + gameId + ".jsdos"; Path bundlePath = gameDir.resolve(gameId + ".jsdos"); - createBundle(extractDir, mainExe, bundlePath); + createBundle(extractDir, mainExe, cdImages, bundlePath); // Detect platform (DOS vs Windows) by reading the main EXE header String platform = mainExe != null ? detectPlatform(Path.of(mainExe)) : "dos"; @@ -441,12 +444,10 @@ public class UploadResource { "zoo", "arc", "ha", "cab" // others ); - private void createBundle(Path extractDir, String exePath, Path bundlePath) throws IOException { + private void createBundle(Path extractDir, String exePath, List cdImages, Path bundlePath) throws IOException { // Write .jsdos config directly into the extract directory Path jsdos = extractDir.resolve(".jsdos"); Files.createDirectories(jsdos); - // Find CD images for DOSBox imgmount (mountable via D:, E:, …) - List cdImages = findCdImages(extractDir); if (exePath != null) { String relExe = extractDir.relativize(Path.of(exePath)).toString(); Files.writeString(jsdos.resolve("dosbox.conf"), buildDosboxConf(relExe, cdImages));