@@ -549,12 +549,12 @@ public void actionPerformed(ActionEvent e)
549549 System .setErr (print );
550550 System .setOut (print );
551551 // Runs it using reflection
552- thread = new Thread ( new Runnable ()
552+ if ( DEOBFUSCATOR_VERSION == DeobfuscatorVersion . NEW )
553553 {
554- @ Override
555- public void run ()
554+ thread = new Thread (new Runnable ()
556555 {
557- if (DEOBFUSCATOR_VERSION == DeobfuscatorVersion .NEW )
556+ @ Override
557+ public void run ()
558558 {
559559 try
560560 {
@@ -594,100 +594,91 @@ public void run()
594594 loadClasses [0 ].getDeclaredMethod ("start" ).invoke (deobfuscator );
595595 }catch (Exception e )
596596 {
597- e .printStackTrace (print );
597+ e .printStackTrace ();
598598 }
599- }else
599+ }
600+ });
601+ newFrame .addWindowListener (new WindowAdapter ()
602+ {
603+ @ Override
604+ public void windowClosing (WindowEvent e )
605+ {
606+ btnRun .setEnabled (true );
607+ if (thread != null )
608+ {
609+ thread .stop ();
610+ thread = null ;
611+ }
612+ e .getWindow ().dispose ();
613+ }
614+ });
615+ }else
616+ {
617+ btnRun .setEnabled (false );
618+ // Converts the above into args
619+ List <String > command = new ArrayList <>();
620+ command .add ("java" );
621+ command .add ("-jar" );
622+ command .add (deobfuscatorField .getText ());
623+ command .add ("-input" );
624+ command .add (inputField .getText ());
625+ command .add ("-output" );
626+ command .add (outputField .getText ());
627+ for (int i = 0 ; i < selectedTransformers .getSize (); i ++)
628+ {
629+ command .add ("-transformer" );
630+ command .add (selectedTransformers .get (i ));
631+ }
632+ for (int i = 0 ; i < librariesList .getSize (); i ++)
633+ {
634+ command .add ("-path" );
635+ command .add (librariesList .get (i ));
636+ }
637+ // Start
638+ ProcessBuilder builder = new ProcessBuilder (command );
639+ SwingWorker <Void , String > worker = new SwingWorker <Void , String >()
640+ {
641+ @ Override
642+ protected Void doInBackground () throws Exception
600643 {
601- btnRun .setEnabled (false );
602- // Converts the above into args
603- List <String > command = new ArrayList <>();
604- command .add ("java" );
605- command .add ("-jar" );
606- command .add (deobfuscatorField .getText ());
607- command .add ("-input" );
608- command .add (inputField .getText ());
609- command .add ("-output" );
610- command .add (outputField .getText ());
611- for (int i = 0 ; i < selectedTransformers .getSize (); i ++)
612- {
613- command .add ("-transformer" );
614- command .add (selectedTransformers .get (i ));
615- }
616- for (int i = 0 ; i < librariesList .getSize (); i ++)
644+ builder .redirectErrorStream (true );
645+ Process process = builder .start ();
646+ DeobfuscatorFrame .this .process = process ;
647+ BufferedReader reader = new BufferedReader (
648+ new InputStreamReader (process .getInputStream ()));
649+ String line ;
650+ while ((line = reader .readLine ()) != null )
651+ publish (line );
652+ return null ;
653+ }
654+
655+ @ Override
656+ protected void process (List <String > chunks )
657+ {
658+ for (String line : chunks )
617659 {
618- command . add ( "-path" );
619- command . add ( librariesList . get ( i ) );
660+ area . append ( line );
661+ area . append ( " \n " );
620662 }
621- // Start
622- ProcessBuilder builder = new ProcessBuilder (command );
623- JFrame newFrame = new JFrame ();
624- newFrame .setTitle ("Console" );
625- JTextArea area = new JTextArea ();
626- area .setEditable (false );
627- newFrame .getContentPane ().add (new JScrollPane (area ));
628- newFrame .pack ();
629- newFrame .setSize (800 , 600 );
630- newFrame .setVisible (true );
631- SwingWorker <Void , String > worker = new SwingWorker <Void , String >()
632- {
633- @ Override
634- protected Void doInBackground () throws Exception
635- {
636- builder .redirectErrorStream (true );
637- Process process = builder .start ();
638- DeobfuscatorFrame .this .process = process ;
639- BufferedReader reader = new BufferedReader (
640- new InputStreamReader (process .getInputStream ()));
641- String line ;
642- while ((line = reader .readLine ()) != null )
643- publish (line );
644- return null ;
645- }
646-
647- @ Override
648- protected void process (List <String > chunks )
649- {
650- for (String line : chunks )
651- {
652- area .append (line );
653- area .append ("\n " );
654- }
655- }
656- };
657- worker .execute ();
658- newFrame .addWindowListener (new WindowAdapter ()
659- {
660- @ Override
661- public void windowClosing (WindowEvent e )
662- {
663- btnRun .setEnabled (true );
664- worker .cancel (true );
665- if (process != null )
666- {
667- process .destroyForcibly ();
668- process = null ;
669- }
670- e .getWindow ().dispose ();
671- }
672- });
673663 }
674- }
675- });
676- thread .start ();
677- newFrame .addWindowListener (new WindowAdapter ()
678- {
679- @ Override
680- public void windowClosing (WindowEvent e )
681- {
682- btnRun .setEnabled (true );
683- if (thread != null )
684- {
685- thread .destroy ();
686- thread = null ;
687- }
688- e .getWindow ().dispose ();
689- }
690- });
664+ };
665+ worker .execute ();
666+ newFrame .addWindowListener (new WindowAdapter ()
667+ {
668+ @ Override
669+ public void windowClosing (WindowEvent e )
670+ {
671+ btnRun .setEnabled (true );
672+ worker .cancel (true );
673+ if (process != null )
674+ {
675+ process .destroyForcibly ();
676+ process = null ;
677+ }
678+ e .getWindow ().dispose ();
679+ }
680+ });
681+ }
691682 }
692683 });
693684 }
0 commit comments