Skip to content

Commit

Permalink
feat(gui): add export dialog with options (PR #2378)
Browse files Browse the repository at this point in the history
fix(gui):add export dialog with options (#1983)
  • Loading branch information
MrIkso authored Dec 21, 2024
1 parent 73966fd commit a46e35c
Show file tree
Hide file tree
Showing 15 changed files with 372 additions and 36 deletions.
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/JadxGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import jadx.gui.logs.LogCollector;
import jadx.gui.settings.JadxSettings;
import jadx.gui.settings.JadxSettingsAdapter;
import jadx.gui.ui.ExceptionDialog;
import jadx.gui.ui.MainWindow;
import jadx.gui.ui.dialog.ExceptionDialog;
import jadx.gui.utils.LafManager;
import jadx.gui.utils.NLS;
import jadx.gui.utils.SystemInfo;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package jadx.gui.settings;

public class ExportProjectProperties {
private boolean skipSources;
private boolean skipResources;
private boolean asGradleMode;
private boolean useGradleKts;
private String exportPath;

public ExportProjectProperties() {

}

public boolean isSkipSources() {
return skipSources;
}

public void setSkipSources(boolean skipSources) {
this.skipSources = skipSources;
}

public boolean isSkipResources() {
return skipResources;
}

public void setSkipResources(boolean skipResources) {
this.skipResources = skipResources;
}

public boolean isAsGradleMode() {
return asGradleMode;
}

public void setAsGradleMode(boolean asGradleMode) {
this.asGradleMode = asGradleMode;
}

public boolean isUseGradleKts() {
return useGradleKts;
}

public void setUseGradleKts(boolean useGradleKts) {
this.useGradleKts = useGradleKts;
}

public String getExportPath() {
return exportPath;
}

public void setExportPath(String exportPath) {
this.exportPath = exportPath;
}
}
41 changes: 23 additions & 18 deletions jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
Expand Down Expand Up @@ -107,6 +108,7 @@
import jadx.gui.logs.LogPanel;
import jadx.gui.plugins.mappings.RenameMappingsGui;
import jadx.gui.plugins.quark.QuarkDialog;
import jadx.gui.settings.ExportProjectProperties;
import jadx.gui.settings.JadxProject;
import jadx.gui.settings.JadxSettings;
import jadx.gui.settings.ui.JadxSettingsWindow;
Expand All @@ -126,6 +128,8 @@
import jadx.gui.ui.codearea.EditorViewState;
import jadx.gui.ui.dialog.ADBDialog;
import jadx.gui.ui.dialog.AboutDialog;
import jadx.gui.ui.dialog.ExceptionDialog;
import jadx.gui.ui.dialog.ExportProjectDialog;
import jadx.gui.ui.dialog.LogViewerDialog;
import jadx.gui.ui.dialog.SearchDialog;
import jadx.gui.ui.filedialog.FileDialogWrapper;
Expand Down Expand Up @@ -160,7 +164,7 @@
import jadx.gui.utils.ui.ActionHandler;
import jadx.gui.utils.ui.NodeLabel;

public class MainWindow extends JFrame {
public class MainWindow extends JFrame implements ExportProjectDialog.ExportProjectDialogListener {
private static final Logger LOG = LoggerFactory.getLogger(MainWindow.class);

private static final String DEFAULT_TITLE = "jadx-gui";
Expand Down Expand Up @@ -798,23 +802,23 @@ public void cancelBackgroundJobs() {
backgroundExecutor.cancelAll();
}

private void saveAll(boolean export) {
FileDialogWrapper fileDialog = new FileDialogWrapper(this, FileOpenMode.EXPORT);
List<Path> saveDirs = fileDialog.show();
if (saveDirs.isEmpty()) {
return;
}
private void exportProject() {
ExportProjectDialog dialog = new ExportProjectDialog(this, this);
dialog.setVisible(true);
}

private void saveAll(ExportProjectProperties exportProjectProperties) {
JadxArgs decompilerArgs = wrapper.getArgs();
decompilerArgs.setExportAsGradleProject(export);
if (export) {
decompilerArgs.setExportAsGradleProject(exportProjectProperties.isAsGradleMode());
if (exportProjectProperties.isAsGradleMode()) {
decompilerArgs.setSkipSources(false);
decompilerArgs.setSkipResources(false);
} else {
decompilerArgs.setSkipSources(settings.isSkipSources());
decompilerArgs.setSkipResources(settings.isSkipResources());
decompilerArgs.setSkipSources(exportProjectProperties.isSkipSources());
decompilerArgs.setSkipResources(exportProjectProperties.isSkipResources());
}
settings.setLastSaveFilePath(fileDialog.getCurrentDir());
backgroundExecutor.execute(new ExportTask(this, wrapper, saveDirs.get(0).toFile()));

backgroundExecutor.execute(new ExportTask(this, wrapper, new File(exportProjectProperties.getExportPath())));
}

public void initTree() {
Expand Down Expand Up @@ -1069,8 +1073,7 @@ private void initMenuAndToolbar() {
liveReloadMenuItem = new JCheckBoxMenuItem(liveReloadAction);
liveReloadMenuItem.setState(project.isEnableLiveReload());

JadxGuiAction saveAllAction = new JadxGuiAction(ActionModel.SAVE_ALL, () -> saveAll(false));
JadxGuiAction exportAction = new JadxGuiAction(ActionModel.EXPORT, () -> saveAll(true));
JadxGuiAction exportAction = new JadxGuiAction(ActionModel.EXPORT, this::exportProject);

JMenu recentProjects = new JadxMenu(NLS.str("menu.recent_projects"), shortcutsController);
recentProjects.addMenuListener(new RecentProjectsMenuListener(this, recentProjects));
Expand Down Expand Up @@ -1161,7 +1164,6 @@ private void initMenuAndToolbar() {
file.add(liveReloadMenuItem);
renameMappings.addMenuActions(file);
file.addSeparator();
file.add(saveAllAction);
file.add(exportAction);
file.addSeparator();
file.add(recentProjects);
Expand Down Expand Up @@ -1245,7 +1247,6 @@ public void actionPerformed(ActionEvent e) {
toolbar.addSeparator();
toolbar.add(reloadAction);
toolbar.addSeparator();
toolbar.add(saveAllAction);
toolbar.add(exportAction);
toolbar.addSeparator();
toolbar.add(syncAction);
Expand Down Expand Up @@ -1292,7 +1293,6 @@ public void actionPerformed(ActionEvent e) {
forwardAction.setEnabled(loaded);
forwardVariantAction.setEnabled(loaded);
syncAction.setEnabled(loaded);
saveAllAction.setEnabled(loaded);
exportAction.setEnabled(loaded);
saveProjectAsAction.setEnabled(loaded);
reloadAction.setEnabled(loaded);
Expand Down Expand Up @@ -1790,4 +1790,9 @@ public CacheManager getCacheManager() {
public JadxGuiEventsImpl events() {
return events;
}

@Override
public void onProjectExportCalled(ExportProjectProperties exportProjectProperties) {
saveAll(exportProjectProperties);
}
}
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/action/ActionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public enum ActionModel {
Shortcut.keyboard(KeyEvent.VK_F5, InputEvent.SHIFT_DOWN_MASK)),
SAVE_ALL(MENU_TOOLBAR, "file.save_all", "file.save_all", "ui/menu-saveall",
Shortcut.keyboard(KeyEvent.VK_E, UiUtils.ctrlButton())),
EXPORT(MENU_TOOLBAR, "file.export_gradle", "file.export_gradle", "ui/export",
EXPORT(MENU_TOOLBAR, "file.export", "file.export", "ui/export",
Shortcut.keyboard(KeyEvent.VK_E, UiUtils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK)),
PREFS(MENU_TOOLBAR, "menu.preferences", "menu.preferences", "ui/settings",
Shortcut.keyboard(KeyEvent.VK_P, UiUtils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jadx.gui.ui;
package jadx.gui.ui.dialog;

import java.awt.BorderLayout;
import java.awt.Color;
Expand All @@ -18,7 +18,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.swing.JButton;
import javax.swing.JComponent;
Expand Down Expand Up @@ -46,7 +45,7 @@ public class ExceptionDialog extends JDialog {
private static final String FMT_DETAIL_LENGTH = "-13";

public static void registerUncaughtExceptionHandler() {
Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> showExceptionDialog(thread, ex));
Thread.setDefaultUncaughtExceptionHandler(ExceptionDialog::showExceptionDialog);
}

public static void showExceptionDialog(Thread thread, Throwable ex) {
Expand Down Expand Up @@ -78,7 +77,7 @@ public ExceptionDialog(Thread thread, Throwable ex) {
try {
// TODO: Use ProcessHandle.current().info().commandLine() once min Java is 9+
List<String> args = ManagementFactory.getRuntimeMXBean().getInputArguments();
details.put("Program args", args.stream().collect(Collectors.joining(" ")));
details.put("Program args", String.join(" ", args));
} catch (Throwable t) {
LOG.error("failed to get program arguments", t);
}
Expand All @@ -89,7 +88,7 @@ public ExceptionDialog(Thread thread, Throwable ex) {

String issueTitle;
try {
issueTitle = URLEncoder.encode(ex.toString(), StandardCharsets.UTF_8.toString());
issueTitle = URLEncoder.encode(ex.toString(), StandardCharsets.UTF_8);
} catch (Exception e) {
LOG.error("URL encoding of title failed", e);
issueTitle = ex.getClass().getSimpleName();
Expand All @@ -105,7 +104,7 @@ public ExceptionDialog(Thread thread, Throwable ex) {

String issueBody;
try {
issueBody = URLEncoder.encode(body, StandardCharsets.UTF_8.toString());
issueBody = URLEncoder.encode(body, StandardCharsets.UTF_8);
} catch (Exception e) {
LOG.error("URL encoding of body failed", e);
issueBody = "Please copy the displayed text in the Jadx error dialog and paste it here";
Expand All @@ -126,7 +125,7 @@ public ExceptionDialog(Thread thread, Throwable ex) {
StringBuilder detailsTextBuilder = new StringBuilder();
details.forEach((key, value) -> detailsTextBuilder.append(String.format("%" + FMT_DETAIL_LENGTH + "s: %s\n", key, value)));

messageArea.setText(detailsTextBuilder.toString() + "\n" + stackTrace);
messageArea.setText(detailsTextBuilder + "\n" + stackTrace);

JPanel buttonPanel = new JPanel();
JButton exitButton = new JButton("Terminate Jadx");
Expand Down
Loading

0 comments on commit a46e35c

Please sign in to comment.