fix: check version jar manifest before assuming correct module - force overwrite vanilla jar with SRG jar if missing Automatic-Module-Name: minecraft - broaden SRG client jar search to multiple paths
This commit is contained in:
+66
-13
@@ -692,8 +692,12 @@ public class LaunchCommandBuilder {
|
||||
Path targetJar = targetDir.resolve(versionId + ".jar");
|
||||
|
||||
if (Files.exists(targetJar) && isValidJar(targetJar)) {
|
||||
System.out.println(ZAnsi.green(" Version jar already exists: " + targetJar));
|
||||
return;
|
||||
if (hasMinecraftModuleName(targetJar)) {
|
||||
System.out.println(ZAnsi.green(" Version jar already exists with correct module name: " + targetJar));
|
||||
return;
|
||||
}
|
||||
System.out.println(ZAnsi.yellow(" Version jar exists but missing Automatic-Module-Name: minecraft — overwriting with SRG jar"));
|
||||
Files.delete(targetJar);
|
||||
}
|
||||
|
||||
Files.createDirectories(targetDir);
|
||||
@@ -725,23 +729,72 @@ public class LaunchCommandBuilder {
|
||||
*/
|
||||
private Path findSrgClientJar() {
|
||||
Path librariesDir = instance.getPath().resolve("libraries");
|
||||
Path mcDir = librariesDir.resolve("net/minecraftforge/client");
|
||||
if (!Files.exists(mcDir)) return null;
|
||||
if (!Files.exists(librariesDir)) return null;
|
||||
|
||||
String mcVersion = instance.getMinecraftVersion();
|
||||
try (var stream = Files.list(mcDir)) {
|
||||
return stream
|
||||
.filter(Files::isDirectory)
|
||||
.filter(dir -> dir.getFileName().toString().startsWith(mcVersion + "-"))
|
||||
.flatMap(dir -> {
|
||||
try { return Files.list(dir); } catch (Exception e) { return java.util.stream.Stream.empty(); }
|
||||
})
|
||||
.filter(p -> p.getFileName().toString().endsWith("-srg.jar"))
|
||||
String[] searchDirs = {
|
||||
"net/minecraftforge/client",
|
||||
"net/minecraft/client",
|
||||
"net/minecraftforge/forge"
|
||||
};
|
||||
|
||||
for (String subdir : searchDirs) {
|
||||
Path dir = librariesDir.resolve(subdir);
|
||||
if (!Files.exists(dir)) continue;
|
||||
try (var stream = Files.list(dir)) {
|
||||
Path found = stream
|
||||
.filter(Files::isDirectory)
|
||||
.filter(d -> d.getFileName().toString().startsWith(mcVersion + "-"))
|
||||
.flatMap(d -> {
|
||||
try { return Files.list(d); } catch (Exception e) { return java.util.stream.Stream.empty(); }
|
||||
})
|
||||
.filter(p -> p.getFileName().toString().endsWith("-srg.jar"))
|
||||
.filter(this::isValidJar)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (found != null) {
|
||||
System.out.println(ZAnsi.green(" Found SRG client jar: " + found + " (module name: " + getModuleName(found) + ")"));
|
||||
return found;
|
||||
}
|
||||
} catch (Exception e) { /* continue */ }
|
||||
}
|
||||
|
||||
// Fallback: scan libraries root for any *-srg.jar matching mcVersion
|
||||
try {
|
||||
Path found = java.nio.file.Files.walk(librariesDir, 5)
|
||||
.filter(p -> p.toString().endsWith("-srg.jar"))
|
||||
.filter(p -> p.toString().contains(mcVersion))
|
||||
.filter(this::isValidJar)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (found != null) {
|
||||
System.out.println(ZAnsi.green(" Found SRG client jar (fallback scan): " + found + " (module name: " + getModuleName(found) + ")"));
|
||||
return found;
|
||||
}
|
||||
} catch (Exception e) { /* continue */ }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getModuleName(Path jar) {
|
||||
try (var jarFile = new java.util.jar.JarFile(jar.toFile())) {
|
||||
var manifest = jarFile.getManifest();
|
||||
if (manifest == null) return "null manifest";
|
||||
String name = manifest.getMainAttributes().getValue("Automatic-Module-Name");
|
||||
return name != null ? name : "not set";
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
return "error: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasMinecraftModuleName(Path jar) {
|
||||
try (var jarFile = new java.util.jar.JarFile(jar.toFile())) {
|
||||
var manifest = jarFile.getManifest();
|
||||
if (manifest == null) return false;
|
||||
String moduleName = manifest.getMainAttributes().getValue("Automatic-Module-Name");
|
||||
return "minecraft".equals(moduleName);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user