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"); } /**