fix(gui): allow to select file on mapping export
This commit is contained in:
Binary file not shown.
@@ -57,6 +57,18 @@ public class JadxProject {
|
||||
this.mainWindow = mainWindow;
|
||||
}
|
||||
|
||||
public @Nullable Path getWorkingDir() {
|
||||
if (projectPath != null) {
|
||||
return projectPath.toAbsolutePath().getParent();
|
||||
}
|
||||
List<Path> files = data.getFiles();
|
||||
if (!files.isEmpty()) {
|
||||
Path path = files.get(0);
|
||||
return path.toAbsolutePath().getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Path getProjectPath() {
|
||||
return projectPath;
|
||||
@@ -166,7 +178,7 @@ public class JadxProject {
|
||||
Path path = files.get(0);
|
||||
return path.resolveSibling(path.getFileName() + ".cache");
|
||||
}
|
||||
throw new JadxRuntimeException("Can't get working dir");
|
||||
throw new JadxRuntimeException("Failed to build cache dir");
|
||||
}
|
||||
|
||||
public boolean isEnableLiveReload() {
|
||||
|
||||
@@ -44,6 +44,7 @@ import javax.swing.Action;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
@@ -85,7 +86,6 @@ import jadx.api.JavaNode;
|
||||
import jadx.api.ResourceFile;
|
||||
import jadx.api.plugins.utils.CommonFileUtils;
|
||||
import jadx.core.Jadx;
|
||||
import jadx.core.dex.nodes.RootNode;
|
||||
import jadx.core.utils.ListUtils;
|
||||
import jadx.core.utils.StringUtils;
|
||||
import jadx.core.utils.files.FileUtils;
|
||||
@@ -362,17 +362,28 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
private void exportMappings(MappingFormat mappingFormat) {
|
||||
RootNode rootNode = wrapper.getDecompiler().getRoot();
|
||||
|
||||
Thread exportThread = new Thread(() -> {
|
||||
new MappingExporter(rootNode).exportMappings(
|
||||
Paths.get(project.getProjectPath().getParent().toString(),
|
||||
"mappings" + (mappingFormat.hasSingleFile() ? "." + mappingFormat.fileExt : "")),
|
||||
project.getCodeData(), mappingFormat);
|
||||
});
|
||||
|
||||
backgroundExecutor.execute(NLS.str("progress.export_mappings"), exportThread);
|
||||
update();
|
||||
FileDialog fileDialog = new FileDialog(this, FileDialog.OpenMode.CUSTOM_SAVE);
|
||||
fileDialog.setTitle(NLS.str("file.export_mappings_as"));
|
||||
Path workingDir = project.getWorkingDir();
|
||||
Path baseDir = workingDir != null ? workingDir : settings.getLastSaveFilePath();
|
||||
if (mappingFormat.hasSingleFile()) {
|
||||
fileDialog.setSelectedFile(baseDir.resolve("mappings." + mappingFormat.fileExt));
|
||||
fileDialog.setFileExtList(Collections.singletonList(mappingFormat.fileExt));
|
||||
fileDialog.setSelectionMode(JFileChooser.FILES_ONLY);
|
||||
} else {
|
||||
fileDialog.setCurrentDir(baseDir);
|
||||
fileDialog.setSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
}
|
||||
List<Path> paths = fileDialog.show();
|
||||
if (paths.size() != 1) {
|
||||
return;
|
||||
}
|
||||
Path savePath = paths.get(0);
|
||||
LOG.info("Export mappings to: {}", savePath.toAbsolutePath());
|
||||
backgroundExecutor.execute(NLS.str("progress.export_mappings"),
|
||||
() -> new MappingExporter(wrapper.getDecompiler().getRoot())
|
||||
.exportMappings(savePath, project.getCodeData(), mappingFormat),
|
||||
s -> update());
|
||||
}
|
||||
|
||||
void open(List<Path> paths) {
|
||||
|
||||
@@ -27,7 +27,12 @@ import jadx.gui.utils.NLS;
|
||||
public class FileDialog {
|
||||
|
||||
public enum OpenMode {
|
||||
OPEN, ADD, SAVE_PROJECT, EXPORT
|
||||
OPEN,
|
||||
ADD,
|
||||
SAVE_PROJECT,
|
||||
EXPORT,
|
||||
CUSTOM_SAVE,
|
||||
CUSTOM_OPEN
|
||||
}
|
||||
|
||||
private final MainWindow mainWindow;
|
||||
@@ -44,6 +49,26 @@ public class FileDialog {
|
||||
initForMode(mode);
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setFileExtList(List<String> fileExtList) {
|
||||
this.fileExtList = fileExtList;
|
||||
}
|
||||
|
||||
public void setSelectionMode(int selectionMode) {
|
||||
this.selectionMode = selectionMode;
|
||||
}
|
||||
|
||||
public void setSelectedFile(Path path) {
|
||||
this.selectedFile = path;
|
||||
}
|
||||
|
||||
public void setCurrentDir(Path currentDir) {
|
||||
this.currentDir = currentDir;
|
||||
}
|
||||
|
||||
public List<Path> show() {
|
||||
FileChooser fileChooser = buildFileChooser();
|
||||
int ret = isOpen ? fileChooser.showOpenDialog(mainWindow) : fileChooser.showSaveDialog(mainWindow);
|
||||
@@ -66,10 +91,6 @@ public class FileDialog {
|
||||
return currentDir;
|
||||
}
|
||||
|
||||
public void setSelectedFile(Path path) {
|
||||
this.selectedFile = path;
|
||||
}
|
||||
|
||||
private void initForMode(OpenMode mode) {
|
||||
switch (mode) {
|
||||
case OPEN:
|
||||
@@ -101,6 +122,14 @@ public class FileDialog {
|
||||
currentDir = mainWindow.getSettings().getLastSaveFilePath();
|
||||
isOpen = false;
|
||||
break;
|
||||
|
||||
case CUSTOM_SAVE:
|
||||
isOpen = false;
|
||||
break;
|
||||
|
||||
case CUSTOM_OPEN:
|
||||
isOpen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +139,7 @@ public class FileDialog {
|
||||
fileChooser.setFileSelectionMode(selectionMode);
|
||||
fileChooser.setMultiSelectionEnabled(isOpen);
|
||||
fileChooser.setAcceptAllFileFilterUsed(true);
|
||||
if (!fileExtList.isEmpty()) {
|
||||
if (Utils.notEmpty(fileExtList)) {
|
||||
String description = NLS.str("file_dialog.supported_files") + ": (" + Utils.listToString(fileExtList) + ')';
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter(description, fileExtList.toArray(new String[0])));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user