Projects STRLCPY jadx Commits 18070eb7
🤬
  • fix(gui): allow to select file on mapping export

  • Loading...
  • Skylot committed 2 years ago
    18070eb7
    1 parent 84868917
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • jadx-gui/libs/mapping-io-0.4.0-SNAPSHOT.jar
    Binary file.
  • ■ ■ ■ ■ ■ ■
    jadx-gui/src/main/java/jadx/gui/settings/JadxProject.java
    skipped 56 lines
    57 57   this.mainWindow = mainWindow;
    58 58   }
    59 59   
     60 + public @Nullable Path getWorkingDir() {
     61 + if (projectPath != null) {
     62 + return projectPath.toAbsolutePath().getParent();
     63 + }
     64 + List<Path> files = data.getFiles();
     65 + if (!files.isEmpty()) {
     66 + Path path = files.get(0);
     67 + return path.toAbsolutePath().getParent();
     68 + }
     69 + return null;
     70 + }
     71 + 
    60 72   @Nullable
    61 73   public Path getProjectPath() {
    62 74   return projectPath;
    skipped 103 lines
    166 178   Path path = files.get(0);
    167 179   return path.resolveSibling(path.getFileName() + ".cache");
    168 180   }
    169  - throw new JadxRuntimeException("Can't get working dir");
     181 + throw new JadxRuntimeException("Failed to build cache dir");
    170 182   }
    171 183   
    172 184   public boolean isEnableLiveReload() {
    skipped 98 lines
  • ■ ■ ■ ■ ■ ■
    jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
    skipped 43 lines
    44 44  import javax.swing.Box;
    45 45  import javax.swing.ImageIcon;
    46 46  import javax.swing.JCheckBoxMenuItem;
     47 +import javax.swing.JFileChooser;
    47 48  import javax.swing.JFrame;
    48 49  import javax.swing.JMenu;
    49 50  import javax.swing.JMenuBar;
    skipped 35 lines
    85 86  import jadx.api.ResourceFile;
    86 87  import jadx.api.plugins.utils.CommonFileUtils;
    87 88  import jadx.core.Jadx;
    88  -import jadx.core.dex.nodes.RootNode;
    89 89  import jadx.core.utils.ListUtils;
    90 90  import jadx.core.utils.StringUtils;
    91 91  import jadx.core.utils.files.FileUtils;
    skipped 270 lines
    362 362   }
    363 363   
    364 364   private void exportMappings(MappingFormat mappingFormat) {
    365  - RootNode rootNode = wrapper.getDecompiler().getRoot();
    366  - 
    367  - Thread exportThread = new Thread(() -> {
    368  - new MappingExporter(rootNode).exportMappings(
    369  - Paths.get(project.getProjectPath().getParent().toString(),
    370  - "mappings" + (mappingFormat.hasSingleFile() ? "." + mappingFormat.fileExt : "")),
    371  - project.getCodeData(), mappingFormat);
    372  - });
    373  - 
    374  - backgroundExecutor.execute(NLS.str("progress.export_mappings"), exportThread);
    375  - update();
     365 + FileDialog fileDialog = new FileDialog(this, FileDialog.OpenMode.CUSTOM_SAVE);
     366 + fileDialog.setTitle(NLS.str("file.export_mappings_as"));
     367 + Path workingDir = project.getWorkingDir();
     368 + Path baseDir = workingDir != null ? workingDir : settings.getLastSaveFilePath();
     369 + if (mappingFormat.hasSingleFile()) {
     370 + fileDialog.setSelectedFile(baseDir.resolve("mappings." + mappingFormat.fileExt));
     371 + fileDialog.setFileExtList(Collections.singletonList(mappingFormat.fileExt));
     372 + fileDialog.setSelectionMode(JFileChooser.FILES_ONLY);
     373 + } else {
     374 + fileDialog.setCurrentDir(baseDir);
     375 + fileDialog.setSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     376 + }
     377 + List<Path> paths = fileDialog.show();
     378 + if (paths.size() != 1) {
     379 + return;
     380 + }
     381 + Path savePath = paths.get(0);
     382 + LOG.info("Export mappings to: {}", savePath.toAbsolutePath());
     383 + backgroundExecutor.execute(NLS.str("progress.export_mappings"),
     384 + () -> new MappingExporter(wrapper.getDecompiler().getRoot())
     385 + .exportMappings(savePath, project.getCodeData(), mappingFormat),
     386 + s -> update());
    376 387   }
    377 388   
    378 389   void open(List<Path> paths) {
    skipped 1194 lines
  • ■ ■ ■ ■ ■
    jadx-gui/src/main/java/jadx/gui/ui/dialog/FileDialog.java
    skipped 26 lines
    27 27  public class FileDialog {
    28 28   
    29 29   public enum OpenMode {
    30  - OPEN, ADD, SAVE_PROJECT, EXPORT
     30 + OPEN,
     31 + ADD,
     32 + SAVE_PROJECT,
     33 + EXPORT,
     34 + CUSTOM_SAVE,
     35 + CUSTOM_OPEN
    31 36   }
    32 37   
    33 38   private final MainWindow mainWindow;
    skipped 10 lines
    44 49   initForMode(mode);
    45 50   }
    46 51   
     52 + public void setTitle(String title) {
     53 + this.title = title;
     54 + }
     55 + 
     56 + public void setFileExtList(List<String> fileExtList) {
     57 + this.fileExtList = fileExtList;
     58 + }
     59 + 
     60 + public void setSelectionMode(int selectionMode) {
     61 + this.selectionMode = selectionMode;
     62 + }
     63 + 
     64 + public void setSelectedFile(Path path) {
     65 + this.selectedFile = path;
     66 + }
     67 + 
     68 + public void setCurrentDir(Path currentDir) {
     69 + this.currentDir = currentDir;
     70 + }
     71 + 
    47 72   public List<Path> show() {
    48 73   FileChooser fileChooser = buildFileChooser();
    49 74   int ret = isOpen ? fileChooser.showOpenDialog(mainWindow) : fileChooser.showSaveDialog(mainWindow);
    skipped 14 lines
    64 89   
    65 90   public Path getCurrentDir() {
    66 91   return currentDir;
    67  - }
    68  - 
    69  - public void setSelectedFile(Path path) {
    70  - this.selectedFile = path;
    71 92   }
    72 93   
    73 94   private void initForMode(OpenMode mode) {
    skipped 27 lines
    101 122   currentDir = mainWindow.getSettings().getLastSaveFilePath();
    102 123   isOpen = false;
    103 124   break;
     125 + 
     126 + case CUSTOM_SAVE:
     127 + isOpen = false;
     128 + break;
     129 + 
     130 + case CUSTOM_OPEN:
     131 + isOpen = true;
     132 + break;
    104 133   }
    105 134   }
    106 135   
    skipped 3 lines
    110 139   fileChooser.setFileSelectionMode(selectionMode);
    111 140   fileChooser.setMultiSelectionEnabled(isOpen);
    112 141   fileChooser.setAcceptAllFileFilterUsed(true);
    113  - if (!fileExtList.isEmpty()) {
     142 + if (Utils.notEmpty(fileExtList)) {
    114 143   String description = NLS.str("file_dialog.supported_files") + ": (" + Utils.listToString(fileExtList) + ')';
    115 144   fileChooser.setFileFilter(new FileNameExtensionFilter(description, fileExtList.toArray(new String[0])));
    116 145   }
    skipped 48 lines
Please wait...
Page is in error, reload to recover