2121import me .konloch .kontainer .io .DiskReader ;
2222import org .jd .core .v1 .ClassFileToJavaSourceDecompiler ;
2323import org .objectweb .asm .tree .ClassNode ;
24- import the .bytecode .club .bytecodeviewer .BytecodeViewer ;
2524import the .bytecode .club .bytecodeviewer .Constants ;
2625import the .bytecode .club .bytecodeviewer .api .ExceptionUI ;
2726import the .bytecode .club .bytecodeviewer .decompilers .AbstractDecompiler ;
3130import the .bytecode .club .bytecodeviewer .decompilers .jdgui .PlainTextPrinter ;
3231import the .bytecode .club .bytecodeviewer .translation .TranslatedStrings ;
3332import the .bytecode .club .bytecodeviewer .util .ExceptionUtils ;
34- import the .bytecode .club .bytecodeviewer .util .MiscUtils ;
3533import the .bytecode .club .bytecodeviewer .util .TempFile ;
3634
3735import java .io .*;
3836
3937import static the .bytecode .club .bytecodeviewer .Constants .FS ;
4038import 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