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
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) {
// No executable on the filesystem — check if CD images exist instead
List<String> 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<String> 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<String> cdImages = findCdImages(extractDir);
if (exePath != null) {
String relExe = extractDir.relativize(Path.of(exePath)).toString();
Files.writeString(jsdos.resolve("dosbox.conf"), buildDosboxConf(relExe, cdImages));