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:
+62
-9
@@ -692,9 +692,13 @@ public class LaunchCommandBuilder {
|
|||||||
Path targetJar = targetDir.resolve(versionId + ".jar");
|
Path targetJar = targetDir.resolve(versionId + ".jar");
|
||||||
|
|
||||||
if (Files.exists(targetJar) && isValidJar(targetJar)) {
|
if (Files.exists(targetJar) && isValidJar(targetJar)) {
|
||||||
System.out.println(ZAnsi.green(" Version jar already exists: " + targetJar));
|
if (hasMinecraftModuleName(targetJar)) {
|
||||||
|
System.out.println(ZAnsi.green(" Version jar already exists with correct module name: " + targetJar));
|
||||||
return;
|
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);
|
Files.createDirectories(targetDir);
|
||||||
|
|
||||||
@@ -725,24 +729,73 @@ public class LaunchCommandBuilder {
|
|||||||
*/
|
*/
|
||||||
private Path findSrgClientJar() {
|
private Path findSrgClientJar() {
|
||||||
Path librariesDir = instance.getPath().resolve("libraries");
|
Path librariesDir = instance.getPath().resolve("libraries");
|
||||||
Path mcDir = librariesDir.resolve("net/minecraftforge/client");
|
if (!Files.exists(librariesDir)) return null;
|
||||||
if (!Files.exists(mcDir)) return null;
|
|
||||||
|
|
||||||
String mcVersion = instance.getMinecraftVersion();
|
String mcVersion = instance.getMinecraftVersion();
|
||||||
try (var stream = Files.list(mcDir)) {
|
String[] searchDirs = {
|
||||||
return stream
|
"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(Files::isDirectory)
|
||||||
.filter(dir -> dir.getFileName().toString().startsWith(mcVersion + "-"))
|
.filter(d -> d.getFileName().toString().startsWith(mcVersion + "-"))
|
||||||
.flatMap(dir -> {
|
.flatMap(d -> {
|
||||||
try { return Files.list(dir); } catch (Exception e) { return java.util.stream.Stream.empty(); }
|
try { return Files.list(d); } catch (Exception e) { return java.util.stream.Stream.empty(); }
|
||||||
})
|
})
|
||||||
.filter(p -> p.getFileName().toString().endsWith("-srg.jar"))
|
.filter(p -> p.getFileName().toString().endsWith("-srg.jar"))
|
||||||
.filter(this::isValidJar)
|
.filter(this::isValidJar)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
} catch (Exception e) {
|
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;
|
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 "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