From 9a4e87d044a36b770ca5bffdcd8b90254cb3d3bc Mon Sep 17 00:00:00 2001 From: David Alvarez Date: Wed, 27 May 2026 09:30:49 +0200 Subject: [PATCH] fix: recursive WAD detection + write BOTH DEFAULT.CFG and DOOM2.CFG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../java/com/dostalgia/UploadResource.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/dostalgia/UploadResource.java b/src/main/java/com/dostalgia/UploadResource.java index 59fef2b..18408dc 100644 --- a/src/main/java/com/dostalgia/UploadResource.java +++ b/src/main/java/com/dostalgia/UploadResource.java @@ -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) 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"); } /**