gui: fix incorrect settings loading

This commit is contained in:
Skylot 2017-12-17 13:01:23 +03:00
parent 001fa639be
commit 118fa98ca9
4 changed files with 12 additions and 3 deletions

View File

@ -11,7 +11,7 @@ import org.slf4j.LoggerFactory;
public class JadxCLI { public class JadxCLI {
private static final Logger LOG = LoggerFactory.getLogger(JadxCLI.class); private static final Logger LOG = LoggerFactory.getLogger(JadxCLI.class);
public static void main(String[] args) throws JadxException { public static void main(String[] args) {
try { try {
JadxCLIArgs jadxArgs = new JadxCLIArgs(); JadxCLIArgs jadxArgs = new JadxCLIArgs();
if (processArgs(jadxArgs, args)) { if (processArgs(jadxArgs, args)) {

View File

@ -25,6 +25,8 @@ import com.beust.jcommander.ParameterException;
public class JadxCLIArgs implements IJadxArgs { public class JadxCLIArgs implements IJadxArgs {
protected static final int DEFAULT_THREADS_COUNT = Math.max(1, Runtime.getRuntime().availableProcessors() / 2);
@Parameter(description = "<input file> (.dex, .apk, .jar or .class)") @Parameter(description = "<input file> (.dex, .apk, .jar or .class)")
protected List<String> files; protected List<String> files;
@ -32,7 +34,7 @@ public class JadxCLIArgs implements IJadxArgs {
protected String outDirName; protected String outDirName;
@Parameter(names = {"-j", "--threads-count"}, description = "processing threads count") @Parameter(names = {"-j", "--threads-count"}, description = "processing threads count")
protected int threadsCount = Math.max(1, Runtime.getRuntime().availableProcessors() / 2); protected int threadsCount = DEFAULT_THREADS_COUNT;
@Parameter(names = {"-r", "--no-res"}, description = "do not decode resources") @Parameter(names = {"-r", "--no-res"}, description = "do not decode resources")
protected boolean skipResources = false; protected boolean skipResources = false;
@ -108,7 +110,7 @@ public class JadxCLIArgs implements IJadxArgs {
} }
try { try {
if (threadsCount <= 0) { if (threadsCount <= 0) {
throw new JadxException("Threads count must be positive"); throw new JadxException("Threads count must be positive, got: " + threadsCount);
} }
if (files != null) { if (files != null) {
for (String fileName : files) { for (String fileName : files) {

View File

@ -43,6 +43,12 @@ public class JadxSettings extends JadxCLIArgs {
JadxSettingsAdapter.store(this); JadxSettingsAdapter.store(this);
} }
public void fixOnLoad() {
if (threadsCount <= 0) {
threadsCount = DEFAULT_THREADS_COUNT;
}
}
public String getLastOpenFilePath() { public String getLastOpenFilePath() {
return lastOpenFilePath; return lastOpenFilePath;
} }

View File

@ -50,6 +50,7 @@ public class JadxSettingsAdapter {
return new JadxSettings(); return new JadxSettings();
} }
LOG.debug("Loaded settings: {}", makeString(settings)); LOG.debug("Loaded settings: {}", makeString(settings));
settings.fixOnLoad();
return settings; return settings;
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error load settings", e); LOG.error("Error load settings", e);