fix: recursive WAD detection + write BOTH DEFAULT.CFG and DOOM2.CFG
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:
David Alvarez
2026-05-27 09:30:49 +02:00
parent 655d3e83cd
commit 9a4e87d044
+16 -15
View File
@@ -340,26 +340,27 @@ public class UploadResource {
/** /**
* Detect Doom-engine games and inject a DEFAULT.CFG with WASD controls. * 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 * Searches recursively for DOOM.WAD / DOOM2.WAD in source, then writes
* config to the destination if it doesn't already have one. * config files to the destination root (where the game will look for them).
*/ */
private void injectDoomConfig(Path srcDir, Path dstDir) throws IOException { private void injectDoomConfig(Path srcDir, Path dstDir) throws IOException {
boolean hasDoom = false; boolean hasDoom = false;
try (var stream = Files.list(srcDir)) { try (var walk = Files.walk(srcDir)) {
for (Path f : (Iterable<Path>) stream::iterator) { hasDoom = walk.anyMatch(p -> {
String name = f.getFileName().toString().toUpperCase(); String name = p.getFileName().toString().toUpperCase();
if (name.equals("DOOM.WAD") || name.equals("DOOM2.WAD")) { return name.equals("DOOM.WAD") || name.equals("DOOM2.WAD");
hasDoom = true; });
break;
} }
if (!hasDoom) {
LOG.info("No Doom WAD found in upload");
return;
} }
} LOG.info("Doom detected — injecting WASD config");
if (!hasDoom) return; byte[] cfg = buildDoomDefaultCfg();
// Don't overwrite an existing config Files.write(dstDir.resolve("DEFAULT.CFG"), cfg);
Path cfg = dstDir.resolve("DEFAULT.CFG"); // Doom II also reads DOOM2.CFG (game-specific, takes priority over DEFAULT)
if (Files.exists(cfg)) return; Files.write(dstDir.resolve("DOOM2.CFG"), cfg);
Files.write(cfg, buildDoomDefaultCfg()); LOG.info("Injected DEFAULT.CFG + DOOM2.CFG with WASD controls");
LOG.info("Doom detected — injected DEFAULT.CFG with WASD controls");
} }
/** /**