Prefer DOS executables over Windows in findMainExe
Build & Deploy / build-and-deploy (push) Successful in 46s

When a ZIP contains both a DOS version (FALLOUT.EXE) and a Windows
version (FALLOUTW.EXE), the sort now prefers DOS executables.
This reads the EXE header during candidate collection and ranks:
  non-installer → DOS platform → depth → size

Fixes Fallout being mis-detected as a Windows game.
This commit is contained in:
Hermes Agent
2026-05-29 09:34:57 +02:00
parent fa1804dc65
commit dee37b3f01
@@ -235,7 +235,7 @@ public class UploadResource {
// ─── Executable Detection ──────────────────────────────────── // ─── Executable Detection ────────────────────────────────────
private String findMainExe(Path dir) throws IOException { private String findMainExe(Path dir) throws IOException {
record Candidate(int depth, boolean isInstaller, long size, String path) {} record Candidate(int depth, boolean isInstaller, long size, String path, String platform) {}
List<Candidate> candidates = new ArrayList<>(); List<Candidate> candidates = new ArrayList<>();
Files.walkFileTree(dir, new SimpleFileVisitor<>() { Files.walkFileTree(dir, new SimpleFileVisitor<>() {
@@ -253,17 +253,25 @@ public class UploadResource {
boolean installer = name.contains("install") || name.contains("setup") || name.contains("config"); boolean installer = name.contains("install") || name.contains("setup") || name.contains("config");
int depth = f.getNameCount() - dir.getNameCount(); int depth = f.getNameCount() - dir.getNameCount();
candidates.add(new Candidate(depth, installer, a.size(), f.toString())); String platform = detectPlatform(f);
candidates.add(new Candidate(depth, installer, a.size(), f.toString(), platform));
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
}); });
if (candidates.isEmpty()) return null; if (candidates.isEmpty()) return null;
// Prefer: non-installer → DOS platform → shallow depth → larger file
candidates.sort(Comparator candidates.sort(Comparator
.comparingInt((Candidate c) -> c.isInstaller() ? 1 : 0) // non-installer first .comparingInt((Candidate c) -> c.isInstaller() ? 1 : 0)
.thenComparingInt(c -> {
// Prefer DOS over unknown over Windows
if ("dos".equals(c.platform())) return 0;
if (c.platform() == null) return 1;
return 2; // "windows"
})
.thenComparingInt(Candidate::depth) .thenComparingInt(Candidate::depth)
.thenComparingLong(c -> -c.size())); // larger files first .thenComparingLong(c -> -c.size()));
return candidates.getFirst().path(); return candidates.getFirst().path();
} }