From c517903761b7ee4f592174c1f71f1a604596c6fe Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Tue, 22 Jun 2021 15:23:36 +0200 Subject: [PATCH] Fix Krakatau optional libraries Fixes #298 --- .../decompilers/KrakatauDecompiler.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDecompiler.java index 38a6df80..c08523fb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDecompiler.java @@ -6,6 +6,8 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.Arrays; +import java.util.stream.Collectors; import me.konloch.kontainer.io.DiskReader; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; @@ -45,8 +47,19 @@ public class KrakatauDecompiler extends Decompiler { public String quick() { if (Configuration.library.isEmpty()) return ""; - else + + File dir = new File(Configuration.library); + if (!dir.exists()) + return ""; + if (!dir.isDirectory()) return ";" + Configuration.library; + + File[] files = dir.listFiles(); + if (files == null || files.length == 0) + return ""; + + return ";" + Arrays.stream(files).filter(File::isFile) + .map(File::getAbsolutePath).collect(Collectors.joining(";")); } public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) { @@ -159,9 +172,9 @@ public class KrakatauDecompiler extends Decompiler { final File tempDirectory = new File(Constants.tempDirectory + fs + MiscUtils.randomString(32) + fs); tempDirectory.mkdir(); final File tempJar = new File(Constants.tempDirectory + fs + "temp" + MiscUtils.randomString(32) + ".jar"); - + JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); - + BytecodeViewer.sm.stopBlocking(); try {