11package ui ;
22
33import model .AppState ;
4- import model .CardDetail ;
54import model .DropmixSharedAssets ;
5+ import model .Process ;
66import util .UtilAdb ;
77import util .UtilApk ;
88
1212import java .awt .event .ActionListener ;
1313import java .io .File ;
1414import java .io .IOException ;
15- import java .nio .charset .StandardCharsets ;
1615import java .nio .file .Files ;
1716import java .nio .file .Path ;
1817import java .nio .file .Paths ;
19- import java .util .ArrayList ;
2018import java .util .TreeMap ;
2119
2220public class UIPlaylistActions extends JPanel {
2321 public String verifiedModApk ;
2422 public static final String modDir = "dropmix_modded_src" ;
23+
2524 public UIPlaylistActions () {
2625 setLayout (new GridLayout (5 , 1 ));
2726 try {
@@ -33,14 +32,23 @@ public void renderActions() {
3332 removeAll ();
3433 AppState as = AppState .getInstance ();
3534
35+ JButton resignedApkBtn = SwingFactory .buildButton ("Build Re-Signed APK" , new ActionListener () {
36+ @ Override
37+ public void actionPerformed (ActionEvent e ) {
38+ freshDecompile (false );
39+ }
40+ });
41+ resignedApkBtn .setEnabled (verifiedModApk == null && as .currentProcess .equals (Process .NONE ) && as .playlistSwap .isEmpty ());
42+ add (resignedApkBtn );
43+
3644 JButton modApkBtn = SwingFactory .buildButton ("Validate Modified APK" , new ActionListener () {
3745 @ Override
3846 public void actionPerformed (ActionEvent e ) {
39- modApk ( );
47+ freshDecompile ( true );
4048 System .out .println ("Modified dropmix generated" );
4149 }
4250 });
43- modApkBtn .setEnabled (as .playlistSwap .size () > 0 && verifiedModApk == null );
51+ modApkBtn .setEnabled (as .playlistSwap .size () > 0 && verifiedModApk == null && as . currentProcess . equals ( Process . NONE ) );
4452 add (modApkBtn );
4553
4654 JButton installApkBtn = SwingFactory .buildButton ("Install APK" , new ActionListener () {
@@ -81,31 +89,77 @@ public void actionPerformed(ActionEvent e) {
8189 add (installApkBtn );
8290 add (saveApk );
8391 }
84- public String modApk ( ) {
92+ private void freshDecompile ( boolean useMod ) {
8593 AppState as = AppState .getInstance ();
8694 Path tempDir = Paths .get (modDir ).toAbsolutePath ();
87- UtilApk .decompileApk (
88- as .apkFile .getAbsolutePath (),
89- tempDir .toString ()
90- );
91- TreeMap <String , String > swapObj = AppState .getCardSwapFromPlaylist (as .playlistSwap );
92-
93- byte [] modBytes = as .assetsHandler .applySwap (swapObj );
94- Path assetsPath = Paths .get (tempDir .toString () + DropmixSharedAssets .assetsRelativePath );
95- try {
96- System .out .println ("writing to " + assetsPath .toAbsolutePath ().toString ());
97- Files .deleteIfExists (assetsPath );
98- Files .write (assetsPath , modBytes );
99- Files .write (Paths .get ("moddedFile" ), modBytes );
100- System .out .println ("mod applied" );
101- } catch (IOException e ) {
102- System .out .println ("mod write fail" );
103- }
104- String output = UtilApk .recompile (tempDir .toAbsolutePath ().toString (), "Dropmix190mod.apk" );
105- this .verifiedModApk = output ;
106- this .renderActions ();
107- return output ;
95+ AppState .setCurrentProcess (Process .DECOMPILING );
96+ SwingWorker decompile = new SwingWorker () {
97+ @ Override
98+ protected Object doInBackground () throws Exception {
99+ renderActions ();
100+ UtilApk .decompileApk (as .apkFile .getAbsolutePath (), tempDir .toString ());
101+ if (useMod ) {
102+ AppState .switchCurrentProcess (Process .DECOMPILING , Process .GENERATING_MOD );
103+ freshModify ();
104+ } else {
105+ AppState .switchCurrentProcess (Process .DECOMPILING , Process .RECOMPILING );
106+ recompile (useMod );
107+ }
108+ return null ;
109+ }
110+ };
111+ decompile .execute ();
108112 }
113+ // apply mod
114+ private void freshModify () {
115+ AppState as = AppState .getInstance ();
116+ SwingWorker modify = new SwingWorker () {
117+ @ Override
118+ protected Object doInBackground () throws Exception {
119+ renderActions ();
120+ TreeMap <String , String > swapObj = AppState .getCardSwapFromPlaylist (as .playlistSwap );
121+ Path tempDir = Paths .get (modDir ).toAbsolutePath ();
122+ byte [] modBytes = as .assetsHandler .applySwap (swapObj );
123+ Path assetsPath = Paths .get (tempDir + DropmixSharedAssets .assetsRelativePath );
124+ try {
125+ System .out .println ("writing to " + assetsPath .toAbsolutePath ().toString ());
126+ Files .deleteIfExists (assetsPath );
127+ Files .write (assetsPath , modBytes );
128+ Files .write (Paths .get ("moddedFile" ), modBytes );
129+ System .out .println ("mod applied" );
130+ AppState .switchCurrentProcess (Process .GENERATING_MOD , Process .RECOMPILING );
131+ recompile (true );
132+ } catch (IOException e ) {
133+ System .out .println ("mod write fail" );
134+ }
135+ return null ;
136+ }
137+ };
138+ modify .execute ();
139+ }
140+ // recompile and sign
141+ public void recompile (boolean useMod ) {
142+ UIPlaylistActions that = this ;
143+ SwingWorker sw = new SwingWorker () {
144+ @ Override
145+ protected Object doInBackground () throws Exception {
146+ renderActions ();
147+ Path tempDir = Paths .get (modDir ).toAbsolutePath ();
148+ String output = UtilApk .recompile (tempDir .toAbsolutePath ().toString (), "Dropmix190mod.apk" );
149+ that .verifiedModApk = output ;
150+ that .renderActions ();
151+ AppState .switchCurrentProcess (Process .RECOMPILING , Process .NONE );
152+ if (useMod ) {
153+ System .out .println ("Modified APK is now ready" );
154+ } else {
155+ System .out .println ("Re-signed APK generated" );
156+ }
157+ return output ;
158+ }
159+ };
160+ sw .execute ();
161+ }
162+
109163 public void clearState () {
110164 try {
111165 if (this .verifiedModApk != null ) {
0 commit comments