未验证 提交 98c0416b 编写于 作者: S Skylot

fix(gui): correct close and reopen for decompiler and cache

上级 fa41874e
......@@ -12,6 +12,9 @@ import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.api.args.DeobfuscationMapFileMode;
import jadx.api.data.ICodeData;
import jadx.api.impl.AnnotatedCodeWriter;
......@@ -19,6 +22,7 @@ import jadx.api.impl.InMemoryCodeCache;
import jadx.core.utils.files.FileUtils;
public class JadxArgs {
private static final Logger LOG = LoggerFactory.getLogger(JadxArgs.class);
public static final int DEFAULT_THREADS_COUNT = Math.max(1, Runtime.getRuntime().availableProcessors() / 2);
......@@ -122,6 +126,19 @@ public class JadxArgs {
setOutDirRes(new File(rootDir, DEFAULT_RES_DIR));
}
public void close() {
try {
inputFiles.clear();
if (codeCache != null) {
codeCache.close();
}
} catch (Exception e) {
LOG.error("Failed to close JadxArgs", e);
} finally {
codeCache = null;
}
}
public List<File> getInputFiles() {
return inputFiles;
}
......
......@@ -161,8 +161,13 @@ public final class JadxDecompiler implements Closeable {
classesMap.clear();
methodsMap.clear();
fieldsMap.clear();
}
@Override
public void close() {
reset();
closeInputs();
args.close();
}
private void closeInputs() {
......@@ -176,11 +181,6 @@ public final class JadxDecompiler implements Closeable {
loadedInputs.clear();
}
@Override
public void close() {
reset();
}
private void loadPlugins(JadxArgs args) {
pluginManager.providesSuggestion("java-input", args.isUseDxInput() ? "java-convert" : "java-input");
pluginManager.load();
......
......@@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.api.ICodeCache;
import jadx.api.JadxArgs;
import jadx.api.JadxDecompiler;
import jadx.api.JavaClass;
......@@ -19,7 +18,6 @@ import jadx.api.ResourceFile;
import jadx.api.impl.InMemoryCodeCache;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.ProcessState;
import jadx.core.utils.exceptions.JadxRuntimeException;
import jadx.core.utils.files.FileUtils;
import jadx.gui.settings.JadxProject;
import jadx.gui.settings.JadxSettings;
......@@ -40,7 +38,6 @@ public class JadxWrapper {
public JadxWrapper(MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.decompiler = new JadxDecompiler(new JadxArgs());
}
public void open() {
......@@ -53,7 +50,7 @@ public class JadxWrapper {
this.decompiler = new JadxDecompiler(jadxArgs);
this.decompiler.load();
initCodeCache(jadxArgs);
initCodeCache();
} catch (Exception e) {
LOG.error("Jadx init error", e);
close();
......@@ -71,23 +68,27 @@ public class JadxWrapper {
public void close() {
try {
decompiler.close();
closeCodeCache();
if (decompiler != null) {
decompiler.close();
mainWindow.getCacheObject().reset();
}
} catch (Exception e) {
LOG.error("jadx decompiler close error", e);
LOG.error("Jadx decompiler close error", e);
} finally {
decompiler = null;
}
}
private void initCodeCache(JadxArgs jadxArgs) {
private void initCodeCache() {
switch (getSettings().getCodeCacheMode()) {
case MEMORY:
jadxArgs.setCodeCache(new InMemoryCodeCache());
getArgs().setCodeCache(new InMemoryCodeCache());
break;
case DISK_WITH_CACHE:
jadxArgs.setCodeCache(new CodeStringCache(buildBufferedDiskCache()));
getArgs().setCodeCache(new CodeStringCache(buildBufferedDiskCache()));
break;
case DISK:
jadxArgs.setCodeCache(buildBufferedDiskCache());
getArgs().setCodeCache(buildBufferedDiskCache());
break;
}
}
......@@ -97,17 +98,6 @@ public class JadxWrapper {
return new BufferCodeCache(diskCache);
}
public void closeCodeCache() {
ICodeCache codeCache = getArgs().getCodeCache();
if (codeCache != null) {
try {
codeCache.close();
} catch (Exception e) {
throw new JadxRuntimeException("Error on cache close", e);
}
}
}
/**
* Get the complete list of classes
*/
......
......@@ -387,6 +387,8 @@ public class MainWindow extends JFrame {
}
public void reopen() {
saveAll();
closeAll();
loadFiles(EMPTY_RUNNABLE);
}
......@@ -431,6 +433,7 @@ public class MainWindow extends JFrame {
private void closeAll() {
cancelBackgroundJobs();
clearTree();
resetCache();
LogCollector.getInstance().reset();
wrapper.close();
tabbedPane.closeAllTabs();
......@@ -606,7 +609,6 @@ public class MainWindow extends JFrame {
private void clearTree() {
tabbedPane.reset();
resetCache();
treeRoot = null;
treeModel.setRoot(null);
treeModel.reload();
......@@ -1329,7 +1331,7 @@ public class MainWindow extends JFrame {
}
private void closeWindow() {
saveOpenTabs();
saveAll();
if (!ensureProjectIsSaved()) {
return;
}
......@@ -1339,13 +1341,11 @@ public class MainWindow extends JFrame {
if (debuggerPanel != null) {
saveSplittersInfo();
}
cancelBackgroundJobs();
wrapper.close();
heapUsageBar.reset();
dispose();
closeAll();
BreakpointManager.saveAndExit();
FileUtils.deleteTempRootDir();
dispose();
System.exit(0);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册