Skip to content

Commit

Permalink
feat(gui): allow to load multiple files, button for add files (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Nov 2, 2020
1 parent 8ca3cd3 commit 278c5f6
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 62 deletions.
19 changes: 14 additions & 5 deletions jadx-gui/src/main/java/jadx/gui/JadxWrapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jadx.gui;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -21,23 +22,25 @@
import jadx.api.ResourceFile;
import jadx.gui.settings.JadxSettings;

import static jadx.gui.utils.FileUtils.toFiles;

public class JadxWrapper {
private static final Logger LOG = LoggerFactory.getLogger(JadxWrapper.class);

private final JadxSettings settings;
private JadxDecompiler decompiler;
private File openFile;
private List<Path> openPaths = Collections.emptyList();

public JadxWrapper(JadxSettings settings) {
this.settings = settings;
}

public void openFile(File file) {
public void openFile(List<Path> paths) {
close();
this.openFile = file;
this.openPaths = paths;
try {
JadxArgs jadxArgs = settings.toJadxArgs();
jadxArgs.setInputFile(file);
jadxArgs.setInputFiles(toFiles(paths));

this.decompiler = new JadxDecompiler(jadxArgs);
this.decompiler.load();
Expand All @@ -55,6 +58,7 @@ public void close() {
LOG.error("jadx decompiler close error", e);
}
}
this.openPaths = Collections.emptyList();
}

public void saveAll(File dir, ProgressMonitor progressMonitor) {
Expand Down Expand Up @@ -139,8 +143,13 @@ public List<ResourceFile> getResources() {
return decompiler.getResources();
}

@Deprecated
public File getOpenFile() {
return openFile;
return openPaths.get(0).toFile();
}

public List<Path> getOpenPaths() {
return openPaths;
}

public JadxDecompiler getDecompiler() {
Expand Down
10 changes: 5 additions & 5 deletions jadx-gui/src/main/java/jadx/gui/settings/JadxProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ private void setProjectPath(Path projectPath) {
changed();
}

public Path getFilePath() {
return filesPath == null ? null : filesPath.get(0);
public List<Path> getFilePaths() {
return filesPath;
}

public void setFilePath(Path filePath) {
if (!filePath.equals(getFilePath())) {
this.filesPath = Arrays.asList(filePath);
public void setFilePath(List<Path> files) {
if (!files.equals(getFilePaths())) {
this.filesPath = files;
changed();
}
}
Expand Down
15 changes: 10 additions & 5 deletions jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -152,8 +153,8 @@ public void setCheckForUpdates(boolean checkForUpdates) {
sync();
}

public Iterable<Path> getRecentProjects() {
return recentProjects;
public List<Path> getRecentProjects() {
return Collections.unmodifiableList(recentProjects);
}

public void addRecentProject(Path projectPath) {
Expand Down Expand Up @@ -194,11 +195,15 @@ public boolean loadWindowPos(Window window) {
}

private static boolean isContainedInAnyScreen(WindowLocation pos) {
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
if (gd.getDefaultConfiguration().getBounds().contains(pos.getBounds())) {
return true;
Rectangle bounds = pos.getBounds();
if (bounds.getX() > 0 && bounds.getY() > 0) {
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
if (gd.getDefaultConfiguration().getBounds().contains(bounds)) {
return true;
}
}
}
LOG.debug("Window saved position was ignored: {}", pos);
return false;
}

Expand Down
12 changes: 10 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jadx.gui.treemodel;

import java.io.File;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
Expand Down Expand Up @@ -124,7 +125,14 @@ public int getLine() {

@Override
public String makeString() {
File file = wrapper.getOpenFile();
return file != null ? file.getName() : "File not open";
List<Path> paths = wrapper.getOpenPaths();
int count = paths.size();
if (count == 0) {
return "File not open";
}
if (count == 1) {
return paths.get(0).getFileName().toString();
}
return count + " files";
}
}
5 changes: 3 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/ui/MainDropTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static jadx.gui.utils.FileUtils.toPaths;

/**
* Enables drop support from external applications for the {@link MainWindow} (load dropped APK
* file)
Expand Down Expand Up @@ -62,8 +64,7 @@ public void drop(DropTargetDropEvent dtde) {
List<File> transferData = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
if (!transferData.isEmpty()) {
dtde.dropComplete(true);
// load first file
mainWindow.open(transferData.get(0).toPath());
mainWindow.open(toPaths(transferData));
}
} catch (Exception e) {
LOG.error("File drop operation failed", e);
Expand Down
Loading

0 comments on commit 278c5f6

Please sign in to comment.