fix: detect CD images once, pass into createBundle
Build & Deploy / build-and-deploy (push) Successful in 44s

CD-only games were failing because the second findCdImages() call
inside createBundle returned empty. Now detection happens once in
the upload method and the result is passed to createBundle.
This commit is contained in:
Hermes Agent
2026-06-03 12:15:10 +02:00
parent 85b0aa8c0c
commit 632fd7f554
@@ -82,10 +82,13 @@ public class UploadResource {
// Find main executable // Find main executable
String mainExe = findMainExe(extractDir); String mainExe = findMainExe(extractDir);
// Detect CD images once (used for both CD-only detection and config generation)
List<String> cdImages = findCdImages(extractDir);
if (mainExe == null) { if (mainExe == null) {
// No executable on the filesystem — check if CD images exist instead // No executable on the filesystem — check if CD images exist instead
List<String> cdOnlyImages = findCdImages(extractDir); if (cdImages.isEmpty()) {
if (cdOnlyImages.isEmpty()) {
return Response.status(400) return Response.status(400)
.entity(Map.of("error", "No executable (.exe/.com/.bat) found in the archive")) .entity(Map.of("error", "No executable (.exe/.com/.bat) found in the archive"))
.build(); .build();
@@ -103,7 +106,7 @@ public class UploadResource {
// Create .jsdos bundle inside the game directory // Create .jsdos bundle inside the game directory
String bundleFile = gameId + "/" + gameId + ".jsdos"; String bundleFile = gameId + "/" + gameId + ".jsdos";
Path bundlePath = gameDir.resolve(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 // Detect platform (DOS vs Windows) by reading the main EXE header
String platform = mainExe != null ? detectPlatform(Path.of(mainExe)) : "dos"; String platform = mainExe != null ? detectPlatform(Path.of(mainExe)) : "dos";
@@ -441,12 +444,10 @@ public class UploadResource {
"zoo", "arc", "ha", "cab" // others "zoo", "arc", "ha", "cab" // others
); );
private void createBundle(Path extractDir, String exePath, Path bundlePath) throws IOException { private void createBundle(Path extractDir, String exePath, List<String> cdImages, Path bundlePath) throws IOException {
// Write .jsdos config directly into the extract directory // Write .jsdos config directly into the extract directory
Path jsdos = extractDir.resolve(".jsdos"); Path jsdos = extractDir.resolve(".jsdos");
Files.createDirectories(jsdos); Files.createDirectories(jsdos);
// Find CD images for DOSBox imgmount (mountable via D:, E:, …)
List<String> cdImages = findCdImages(extractDir);
if (exePath != null) { if (exePath != null) {
String relExe = extractDir.relativize(Path.of(exePath)).toString(); String relExe = extractDir.relativize(Path.of(exePath)).toString();
Files.writeString(jsdos.resolve("dosbox.conf"), buildDosboxConf(relExe, cdImages)); Files.writeString(jsdos.resolve("dosbox.conf"), buildDosboxConf(relExe, cdImages));