[FIX] Sort files in installAuthlib

This commit is contained in:
microwin7 2024-03-09 14:24:12 +03:00
parent 3002371fad
commit ef5f932afb

View file

@ -15,7 +15,7 @@
public class InstallAuthlib {
private static final Map<String, LibrariesHashFileModifier> modifierMap;
private static final String LaunchAuthLibName = "authlib.jar";
private static final String tempLaunchAuthLibName = "authlib.jar";
static {
modifierMap = new HashMap<>();
modifierMap.put("META-INF/libraries.list", new LibrariesLstModifier());
@ -27,32 +27,30 @@ 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(LaunchAuthLibName);
Path tempAuthlib = Paths.get(tempLaunchAuthLibName);
LogHelper.info("Download %s to %s", args[0], tempAuthlib);
try(InputStream input = IOHelper.newInput(new URL(args[0]))) {
IOHelper.transfer(input, tempAuthlib);
}
context.pathToAuthlib = tempAuthlib;
context.pathToAuthlib = tempAuthlib.toAbsolutePath();
deleteAuthlibAfterInstall = true;
} else {
context.pathToAuthlib = Paths.get(args[0]);
context.pathToAuthlib = Paths.get(args[0]).toAbsolutePath();
}
if(Files.notExists(context.pathToAuthlib)) {
throw new FileNotFoundException(context.pathToAuthlib.toString());
}
context.workdir = IOHelper.WORKING_DIR;
LogHelper.info("Search .jar files in %s", context.workdir.toAbsolutePath());
IOHelper.walk(context.workdir, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (file.getFileName().toString().endsWith(".jar") && !file.getFileName().toString().equals(LaunchAuthLibName)) {
if (file.getFileName().toString().endsWith(".jar") && !file.equals(context.pathToAuthlib)) {
context.files.add(file);
}
return FileVisitResult.CONTINUE;
}
}, true);
context.files.sort(Comparator.comparingInt((Path path) -> - countSlashes(path.toString()))
.thenComparing(Comparator.naturalOrder()));
context.files.sort(Comparator.comparingInt((Path path) -> - path.getNameCount()));
LogHelper.info("Search authlib in %d files", context.files.size());
for(Path path : context.files) {
boolean foundAuthlib = false;
@ -218,10 +216,6 @@ 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;