[FIX] Sort files in installAuthlib

This commit is contained in:
microwin7 2024-03-09 14:24:12 +03:00
parent 3002371fad
commit ef5f932afb
1 changed files with 6 additions and 12 deletions

View File

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