Skip to content

Commit f749603

Browse files
committed
JD-GUi Decompiler Update
1 parent 136346d commit f749603

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import me.konloch.kontainer.io.DiskReader;
2222
import org.jd.core.v1.ClassFileToJavaSourceDecompiler;
2323
import org.objectweb.asm.tree.ClassNode;
24-
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
2524
import the.bytecode.club.bytecodeviewer.Constants;
2625
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
2726
import the.bytecode.club.bytecodeviewer.decompilers.AbstractDecompiler;
@@ -31,15 +30,13 @@
3130
import the.bytecode.club.bytecodeviewer.decompilers.jdgui.PlainTextPrinter;
3231
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
3332
import the.bytecode.club.bytecodeviewer.util.ExceptionUtils;
34-
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
3533
import the.bytecode.club.bytecodeviewer.util.TempFile;
3634

3735
import java.io.*;
3836

3937
import static the.bytecode.club.bytecodeviewer.Constants.FS;
4038
import static the.bytecode.club.bytecodeviewer.Constants.NL;
41-
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.ERROR;
42-
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.JDGUI;
39+
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.*;
4340

4441
/**
4542
* JD-Core Decompiler Wrapper
@@ -71,18 +68,7 @@ public String decompileClassNode(ClassNode cn, byte[] bytes)
7168
File tempJavaFile = tempFile.createFileFromExtension(false, false, ".java");
7269

7370
//make any folders for the packages
74-
if (cn.name.contains("/"))
75-
{
76-
String[] raw = cn.name.split("/");
77-
String path = tempFile.getParent().getAbsolutePath() + FS;
78-
79-
for (int i = 0; i < raw.length - 1; i++)
80-
{
81-
path += raw[i] + FS;
82-
File f = new File(path);
83-
f.mkdir();
84-
}
85-
}
71+
makeFolders(tempFile, cn);
8672

8773
try (FileOutputStream fos = new FileOutputStream(tempClassFile))
8874
{
@@ -118,16 +104,21 @@ public boolean isMergeEmptyLines()
118104
decompiler.decompile(loader, printer, internalPath, preferences.getPreferences());
119105
}
120106

107+
//handle simulated errors
108+
if(Constants.DEV_FLAG_DECOMPILERS_SIMULATED_ERRORS)
109+
throw new RuntimeException(DEV_MODE_SIMULATED_ERROR.toString());
110+
111+
//read the java file
121112
return DiskReader.loadAsString(tempJavaFile.getAbsolutePath());
122113
}
123114
catch (Throwable e)
124115
{
125-
exception = NL + NL + ExceptionUtils.exceptionToString(e);
116+
exception = ExceptionUtils.exceptionToString(e);
126117
}
127118
finally
128119
{
129120
if(tempFile != null)
130-
tempFile.delete();
121+
tempFile.cleanup();
131122
}
132123

133124
return JDGUI + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL
@@ -137,6 +128,22 @@ public boolean isMergeEmptyLines()
137128
@Override
138129
public void decompileToZip(String sourceJar, String zipName)
139130
{
140-
//TODO
131+
decompileToZipFallBack(sourceJar, zipName);
132+
}
133+
134+
private void makeFolders(TempFile tempFile, ClassNode cn)
135+
{
136+
if (cn.name.contains("/"))
137+
{
138+
String[] raw = cn.name.split("/");
139+
String path = tempFile.getParent().getAbsolutePath() + FS;
140+
141+
for (int i = 0; i < raw.length - 1; i++)
142+
{
143+
path += raw[i] + FS;
144+
File f = new File(path);
145+
f.mkdir();
146+
}
147+
}
141148
}
142149
}

0 commit comments

Comments
 (0)