fix: recursive WAD detection + write BOTH DEFAULT.CFG and DOOM2.CFG
Build & Deploy / build-and-deploy (push) Successful in 49s
Build & Deploy / build-and-deploy (push) Successful in 49s
Previous injectDoomConfig used Files.list() which only checks the top-level directory — if the WAD was in a subdirectory, detection failed silently and no config was written. Switched to Files.walk() for recursive search. Also: - Write BOTH DEFAULT.CFG AND DOOM2.CFG (Doom II reads DOOM2.CFG first as game-specific config, falling back to DEFAULT.CFG) - Always overwrite (don't skip if file exists — the ZIP might contain a stock DEFAULT.CFG with arrow-key defaults)
This commit is contained in:
@@ -340,26 +340,27 @@ public class UploadResource {
|
||||
|
||||
/**
|
||||
* Detect Doom-engine games and inject a DEFAULT.CFG with WASD controls.
|
||||
* Checks for DOOM.WAD or DOOM2.WAD in the source, then writes the
|
||||
* config to the destination if it doesn't already have one.
|
||||
* Searches recursively for DOOM.WAD / DOOM2.WAD in source, then writes
|
||||
* config files to the destination root (where the game will look for them).
|
||||
*/
|
||||
private void injectDoomConfig(Path srcDir, Path dstDir) throws IOException {
|
||||
boolean hasDoom = false;
|
||||
try (var stream = Files.list(srcDir)) {
|
||||
for (Path f : (Iterable<Path>) stream::iterator) {
|
||||
String name = f.getFileName().toString().toUpperCase();
|
||||
if (name.equals("DOOM.WAD") || name.equals("DOOM2.WAD")) {
|
||||
hasDoom = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
try (var walk = Files.walk(srcDir)) {
|
||||
hasDoom = walk.anyMatch(p -> {
|
||||
String name = p.getFileName().toString().toUpperCase();
|
||||
return name.equals("DOOM.WAD") || name.equals("DOOM2.WAD");
|
||||
});
|
||||
}
|
||||
if (!hasDoom) return;
|
||||
// Don't overwrite an existing config
|
||||
Path cfg = dstDir.resolve("DEFAULT.CFG");
|
||||
if (Files.exists(cfg)) return;
|
||||
Files.write(cfg, buildDoomDefaultCfg());
|
||||
LOG.info("Doom detected — injected DEFAULT.CFG with WASD controls");
|
||||
if (!hasDoom) {
|
||||
LOG.info("No Doom WAD found in upload");
|
||||
return;
|
||||
}
|
||||
LOG.info("Doom detected — injecting WASD config");
|
||||
byte[] cfg = buildDoomDefaultCfg();
|
||||
Files.write(dstDir.resolve("DEFAULT.CFG"), cfg);
|
||||
// Doom II also reads DOOM2.CFG (game-specific, takes priority over DEFAULT)
|
||||
Files.write(dstDir.resolve("DOOM2.CFG"), cfg);
|
||||
LOG.info("Injected DEFAULT.CFG + DOOM2.CFG with WASD controls");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user