mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 08:31:07 +03:00
[FEATURE] Sort jar files, before patching in installAuthlib
This commit is contained in:
parent
998db80837
commit
3002371fad
1 changed files with 9 additions and 2 deletions
|
@ -15,6 +15,7 @@
|
|||
|
||||
public class InstallAuthlib {
|
||||
private static final Map<String, LibrariesHashFileModifier> modifierMap;
|
||||
private static final String LaunchAuthLibName = "authlib.jar";
|
||||
static {
|
||||
modifierMap = new HashMap<>();
|
||||
modifierMap.put("META-INF/libraries.list", new LibrariesLstModifier());
|
||||
|
@ -26,7 +27,7 @@ public void run(String... args) throws Exception {
|
|||
boolean deleteAuthlibAfterInstall = false;
|
||||
InstallAuthlibContext context = new InstallAuthlibContext();
|
||||
if(args[0].startsWith("http://") || args[0].startsWith("https://")) {
|
||||
Path tempAuthlib = Paths.get("authlib.jar");
|
||||
Path tempAuthlib = Paths.get(LaunchAuthLibName);
|
||||
LogHelper.info("Download %s to %s", args[0], tempAuthlib);
|
||||
try(InputStream input = IOHelper.newInput(new URL(args[0]))) {
|
||||
IOHelper.transfer(input, tempAuthlib);
|
||||
|
@ -44,12 +45,14 @@ public void run(String... args) throws Exception {
|
|||
IOHelper.walk(context.workdir, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||
if (file.getFileName().toString().endsWith(".jar")) {
|
||||
if (file.getFileName().toString().endsWith(".jar") && !file.getFileName().toString().equals(LaunchAuthLibName)) {
|
||||
context.files.add(file);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}, true);
|
||||
context.files.sort(Comparator.comparingInt((Path path) -> - countSlashes(path.toString()))
|
||||
.thenComparing(Comparator.naturalOrder()));
|
||||
LogHelper.info("Search authlib in %d files", context.files.size());
|
||||
for(Path path : context.files) {
|
||||
boolean foundAuthlib = false;
|
||||
|
@ -215,6 +218,10 @@ private byte[] repackAuthlibJar(byte[] data, Path path) throws IOException {
|
|||
}
|
||||
}
|
||||
|
||||
private static int countSlashes(String s) {
|
||||
return (int) s.chars().filter(c -> c == '/').count();
|
||||
}
|
||||
|
||||
public static class RepackInfo {
|
||||
public Path path;
|
||||
public String prefix;
|
||||
|
|
Loading…
Reference in a new issue