mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +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 {
|
public class InstallAuthlib {
|
||||||
private static final Map<String, LibrariesHashFileModifier> modifierMap;
|
private static final Map<String, LibrariesHashFileModifier> modifierMap;
|
||||||
|
private static final String LaunchAuthLibName = "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());
|
||||||
|
@ -26,7 +27,7 @@ public void run(String... args) throws Exception {
|
||||||
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("authlib.jar");
|
Path tempAuthlib = Paths.get(LaunchAuthLibName);
|
||||||
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);
|
||||||
|
@ -44,12 +45,14 @@ public void run(String... args) throws Exception {
|
||||||
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")) {
|
if (file.getFileName().toString().endsWith(".jar") && !file.getFileName().toString().equals(LaunchAuthLibName)) {
|
||||||
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()))
|
||||||
|
.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;
|
||||||
|
@ -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 static class RepackInfo {
|
||||||
public Path path;
|
public Path path;
|
||||||
public String prefix;
|
public String prefix;
|
||||||
|
|
Loading…
Reference in a new issue