Skip to content

Commit

Permalink
fix(gui): remove output directories from persistent settings (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Feb 20, 2019
1 parent bcadc28 commit f8acc31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
28 changes: 12 additions & 16 deletions jadx-core/src/main/java/jadx/api/JadxArgsValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ private static void validateOutDirs(JadxArgs args) {
} else {
outDir = makeDirFromInput(args);
}
args.setOutDir(outDir);
}
if (srcDir == null) {
args.setOutDirSrc(new File(args.getOutDir(), JadxArgs.DEFAULT_SRC_DIR));
}
if (resDir == null) {
args.setOutDirRes(new File(args.getOutDir(), JadxArgs.DEFAULT_RES_DIR));
}
args.setOutDir(outDir);
setFromOut(args);

checkDir(args.getOutDir());
checkDir(args.getOutDirSrc());
checkDir(args.getOutDirRes());
checkDir(args.getOutDir(), "Output");
checkDir(args.getOutDirSrc(), "Source output");
checkDir(args.getOutDirRes(), "Resources output");
}

@NotNull
Expand All @@ -79,15 +84,6 @@ private static File makeDirFromInput(JadxArgs args) {
return outDir;
}

private static void setFromOut(JadxArgs args) {
if (args.getOutDirSrc() == null) {
args.setOutDirSrc(new File(args.getOutDir(), JadxArgs.DEFAULT_SRC_DIR));
}
if (args.getOutDirRes() == null) {
args.setOutDirRes(new File(args.getOutDir(), JadxArgs.DEFAULT_RES_DIR));
}
}

private static void checkFile(File file) {
if (!file.exists()) {
throw new JadxArgsValidateException("File not found " + file.getAbsolutePath());
Expand All @@ -97,9 +93,9 @@ private static void checkFile(File file) {
}
}

private static void checkDir(File dir) {
private static void checkDir(File dir, String desc) {
if (dir != null && dir.exists() && !dir.isDirectory()) {
throw new JadxArgsValidateException("Output directory exists as file " + dir);
throw new JadxArgsValidateException(desc + " directory exists as file " + dir);
}
}

Expand Down
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/JadxWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void openFile(File file) {
this.decompiler.getArgs().setInputFiles(Collections.singletonList(file));
this.decompiler.load();
} catch (Exception e) {
LOG.error("Error load file: {}", file, e);
LOG.error("Jadx init error", e);
}
}

Expand Down
10 changes: 8 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class JadxSettings extends JadxCLIArgs {

private static final String USER_HOME = System.getProperty("user.home");
private static final int RECENT_FILES_COUNT = 15;
private static final int CURRENT_SETTINGS_VERSION = 7;
private static final int CURRENT_SETTINGS_VERSION = 8;

private static final Font DEFAULT_FONT = new RSyntaxTextArea().getFont();

static final Set<String> SKIP_FIELDS = new HashSet<>(Arrays.asList(
"files", "input", "outputDir", "verbose", "printHelp"
"files", "input", "outDir", "outDirSrc", "outDirRes", "verbose", "printVersion", "printHelp"
));
private String lastOpenFilePath = USER_HOME;
private String lastSaveFilePath = USER_HOME;
Expand Down Expand Up @@ -323,6 +323,12 @@ private void upgradeSettings(int fromVersion) {
if (getFont().getFontName().equals("Hack Regular")) {
setFont(null);
}
fromVersion++;
}
if (fromVersion == 7) {
outDir = null;
outDirSrc = null;
outDirRes = null;
}
settingsVersion = CURRENT_SETTINGS_VERSION;
sync();
Expand Down

0 comments on commit f8acc31

Please sign in to comment.