fix: preserve CD image mounts when changing executable
Build & Deploy / build-and-deploy (push) Successful in 36s
Build & Deploy / build-and-deploy (push) Successful in 36s
GameService.buildDosboxConfBytes() was rebuilding dosbox.conf with only the executable path — CD image mount lines were lost. - Added findCdImagesInBundle() to scan a .jsdos ZIP for CD images - buildDosboxConfBytes() now accepts List<String> cdImages and generates imgmount lines (same logic as UploadResource) - Both setExecutable() and streamSetupBundle() now scan for and include CD images when regenerating config
This commit is contained in:
@@ -166,8 +166,9 @@ public class GameService {
|
|||||||
throw new NoSuchFileException("Bundle not found: " + bundleFile);
|
throw new NoSuchFileException("Bundle not found: " + bundleFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build new config entries
|
// Build new config entries — preserve any CD images in the bundle
|
||||||
byte[] newDosboxConf = buildDosboxConfBytes(executable);
|
List<String> cdImages = findCdImagesInBundle(bundlePath);
|
||||||
|
byte[] newDosboxConf = buildDosboxConfBytes(executable, cdImages);
|
||||||
byte[] newJsdosJson = buildJsdosJsonBytes(executable);
|
byte[] newJsdosJson = buildJsdosJsonBytes(executable);
|
||||||
|
|
||||||
// Patch the ZIP: read old, write new with modified config entries
|
// Patch the ZIP: read old, write new with modified config entries
|
||||||
@@ -203,8 +204,28 @@ public class GameService {
|
|||||||
save(game);
|
save(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build a dosbox.conf for a given executable path. */
|
/** Scan a .jsdos bundle for CD image files (preserves the case from the ZIP entry). */
|
||||||
private byte[] buildDosboxConfBytes(String relExe) {
|
private List<String> findCdImagesInBundle(Path bundlePath) throws IOException {
|
||||||
|
Set<String> cdExt = Set.of(".iso", ".cue", ".img", ".ccd", ".bin");
|
||||||
|
List<String> cds = new ArrayList<>();
|
||||||
|
try (var zis = new java.util.zip.ZipInputStream(Files.newInputStream(bundlePath))) {
|
||||||
|
java.util.zip.ZipEntry entry;
|
||||||
|
while ((entry = zis.getNextEntry()) != null) {
|
||||||
|
if (entry.isDirectory()) continue;
|
||||||
|
String name = entry.getName().toLowerCase();
|
||||||
|
int dot = name.lastIndexOf('.');
|
||||||
|
if (dot >= 0 && cdExt.contains(name.substring(dot))) {
|
||||||
|
cds.add(entry.getName()); // preserve original filename casing
|
||||||
|
}
|
||||||
|
zis.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cds.sort(String::compareTo);
|
||||||
|
return cds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Build a dosbox.conf for a given executable path and optional CD images. */
|
||||||
|
private byte[] buildDosboxConfBytes(String relExe, List<String> cdImages) {
|
||||||
var parts = splitExePath(relExe);
|
var parts = splitExePath(relExe);
|
||||||
String dir = parts[0];
|
String dir = parts[0];
|
||||||
String exe = parts[1];
|
String exe = parts[1];
|
||||||
@@ -214,7 +235,16 @@ public class GameService {
|
|||||||
sb.append("[mixer]\nnosound=false\nrate=44100\n\n");
|
sb.append("[mixer]\nnosound=false\nrate=44100\n\n");
|
||||||
sb.append("[sblaster]\nsbtype=sb16\nirq=7\ndma=1\nhdma=5\n\n");
|
sb.append("[sblaster]\nsbtype=sb16\nirq=7\ndma=1\nhdma=5\n\n");
|
||||||
sb.append("[dos]\nxms=true\nems=true\numb=true\n\n");
|
sb.append("[dos]\nxms=true\nems=true\numb=true\n\n");
|
||||||
sb.append("[autoexec]\n@echo off\nmount c .\nc:\n");
|
sb.append("[autoexec]\n@echo off\nmount c .\n");
|
||||||
|
// Mount CD images as D:, E:, … so games can find their CD
|
||||||
|
char driveLetter = 'D';
|
||||||
|
for (String img : cdImages) {
|
||||||
|
String imgLower = img.toLowerCase();
|
||||||
|
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");
|
||||||
if (dir != null) {
|
if (dir != null) {
|
||||||
sb.append("path=c:\\\n");
|
sb.append("path=c:\\\n");
|
||||||
sb.append("cd ").append(dir).append("\n");
|
sb.append("cd ").append(dir).append("\n");
|
||||||
@@ -299,7 +329,9 @@ public class GameService {
|
|||||||
throw new NoSuchFileException("Bundle not found: " + game.getBundleFile());
|
throw new NoSuchFileException("Bundle not found: " + game.getBundleFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] newDosboxConf = buildDosboxConfBytes(setupExe);
|
// Build new config entries — preserve any CD images in the bundle
|
||||||
|
List<String> cdImages = findCdImagesInBundle(bundlePath);
|
||||||
|
byte[] newDosboxConf = buildDosboxConfBytes(setupExe, cdImages);
|
||||||
byte[] newJsdosJson = buildJsdosJsonBytes(setupExe);
|
byte[] newJsdosJson = buildJsdosJsonBytes(setupExe);
|
||||||
|
|
||||||
try (var zis = new java.util.zip.ZipInputStream(Files.newInputStream(bundlePath));
|
try (var zis = new java.util.zip.ZipInputStream(Files.newInputStream(bundlePath));
|
||||||
|
|||||||
Reference in New Issue
Block a user