diff --git a/src/main/java/com/dostalgia/UploadResource.java b/src/main/java/com/dostalgia/UploadResource.java index 58ca640..67374f8 100644 --- a/src/main/java/com/dostalgia/UploadResource.java +++ b/src/main/java/com/dostalgia/UploadResource.java @@ -235,7 +235,7 @@ public class UploadResource { // ─── Executable Detection ──────────────────────────────────── 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 candidates = new ArrayList<>(); Files.walkFileTree(dir, new SimpleFileVisitor<>() { @@ -253,17 +253,25 @@ public class UploadResource { boolean installer = name.contains("install") || name.contains("setup") || name.contains("config"); 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; } }); if (candidates.isEmpty()) return null; + // Prefer: non-installer → DOS platform → shallow depth → larger file 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) - .thenComparingLong(c -> -c.size())); // larger files first + .thenComparingLong(c -> -c.size())); return candidates.getFirst().path(); }