From c21cabcba787c38462141b5a45dc5d35611e6c4b Mon Sep 17 00:00:00 2001 From: Skylot <118523+skylot@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:31:06 +0100 Subject: [PATCH] fix: use temp dir env var only in apps --- jadx-cli/src/main/java/jadx/cli/JadxCLI.java | 2 - .../jadx/cli/plugins/JadxFilesGetter.java | 4 +- .../src/test/java/jadx/cli/TestInput.java | 63 +++++++------------ .../java/jadx/commons/app/JadxTempFiles.java | 31 +++++++++ .../main/java/jadx/api/JadxDecompiler.java | 2 + .../core/plugins/files/TempFilesGetter.java | 24 +++++-- .../java/jadx/core/utils/files/FileUtils.java | 57 ++++++++--------- .../java/jadx/core/utils/files/ZipFile.java | 5 +- .../api/JadxArgsValidatorOutDirsTest.java | 21 +++++-- .../java/jadx/api/JadxDecompilerTest.java | 11 ++-- .../java/jadx/tests/api/IntegrationTest.java | 16 +++-- .../jadx/tests/api/utils/TestFilesGetter.java | 35 +++++++++++ .../java/jadx/gui/jobs/DecompileTask.java | 4 +- .../src/main/java/jadx/gui/ui/MainWindow.java | 1 - .../src/main/java/jadx/gui/utils/UiUtils.java | 8 --- 15 files changed, 172 insertions(+), 112 deletions(-) create mode 100644 jadx-commons/jadx-app-commons/src/main/java/jadx/commons/app/JadxTempFiles.java create mode 100644 jadx-core/src/test/java/jadx/tests/api/utils/TestFilesGetter.java diff --git a/jadx-cli/src/main/java/jadx/cli/JadxCLI.java b/jadx-cli/src/main/java/jadx/cli/JadxCLI.java index 35b62ff0..2959c23e 100644 --- a/jadx-cli/src/main/java/jadx/cli/JadxCLI.java +++ b/jadx-cli/src/main/java/jadx/cli/JadxCLI.java @@ -16,7 +16,6 @@ import jadx.cli.LogHelper.LogLevelEnum; import jadx.cli.plugins.JadxFilesGetter; import jadx.commons.app.JadxCommonEnv; import jadx.core.utils.exceptions.JadxArgsValidateException; -import jadx.core.utils.files.FileUtils; import jadx.plugins.tools.JadxExternalPluginsLoader; public class JadxCLI { @@ -33,7 +32,6 @@ public class JadxCLI { LOG.error("Process error:", e); result = 1; } finally { - FileUtils.deleteTempRootDir(); System.exit(result); } } diff --git a/jadx-cli/src/main/java/jadx/cli/plugins/JadxFilesGetter.java b/jadx-cli/src/main/java/jadx/cli/plugins/JadxFilesGetter.java index 6c8320bb..27cb3b2c 100644 --- a/jadx-cli/src/main/java/jadx/cli/plugins/JadxFilesGetter.java +++ b/jadx-cli/src/main/java/jadx/cli/plugins/JadxFilesGetter.java @@ -3,8 +3,8 @@ package jadx.cli.plugins; import java.nio.file.Path; import jadx.commons.app.JadxCommonFiles; +import jadx.commons.app.JadxTempFiles; import jadx.core.plugins.files.IJadxFilesGetter; -import jadx.core.utils.files.FileUtils; public class JadxFilesGetter implements IJadxFilesGetter { @@ -22,7 +22,7 @@ public class JadxFilesGetter implements IJadxFilesGetter { @Override public Path getTempDir() { - return FileUtils.getTempRootDir(); + return JadxTempFiles.getTempRootDir(); } private JadxFilesGetter() { diff --git a/jadx-cli/src/test/java/jadx/cli/TestInput.java b/jadx-cli/src/test/java/jadx/cli/TestInput.java index 2e5e035b..b8e3adec 100644 --- a/jadx-cli/src/test/java/jadx/cli/TestInput.java +++ b/jadx-cli/src/test/java/jadx/cli/TestInput.java @@ -12,13 +12,11 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jadx.core.utils.files.FileUtils; - import static org.assertj.core.api.Assertions.assertThat; public class TestInput { @@ -29,6 +27,9 @@ public class TestInput { return true; }; + @TempDir + Path testDir; + @Test public void testHelp() { int result = JadxCLI.execute(new String[] { "--help" }); @@ -37,83 +38,68 @@ public class TestInput { @Test public void testDexInput() throws Exception { - decompile("dex", "samples/hello.dex"); + decompile("samples/hello.dex"); } @Test public void testSmaliInput() throws Exception { - decompile("smali", "samples/HelloWorld.smali"); + decompile("samples/HelloWorld.smali"); } @Test public void testClassInput() throws Exception { - decompile("class", "samples/HelloWorld.class"); + decompile("samples/HelloWorld.class"); } @Test public void testMultipleInput() throws Exception { - decompile("multi", "samples/hello.dex", "samples/HelloWorld.smali"); + decompile("samples/hello.dex", "samples/HelloWorld.smali"); } @Test public void testFallbackMode() throws Exception { - Path tempDir = FileUtils.createTempDir("fallback"); - List args = buildArgs(tempDir, "samples/hello.dex"); - args.add(0, "-f"); - - int result = JadxCLI.execute(args.toArray(new String[0])); + int result = JadxCLI.execute(buildArgs(List.of("-f"), "samples/hello.dex")); assertThat(result).isEqualTo(0); - List files = collectJavaFilesInDir(tempDir); + List files = collectJavaFilesInDir(testDir); assertThat(files).hasSize(1); } @Test public void testSimpleMode() throws Exception { - Path tempDir = FileUtils.createTempDir("simple"); - List args = buildArgs(tempDir, "samples/hello.dex"); - args.add(0, "--decompilation-mode"); - args.add(1, "simple"); - - int result = JadxCLI.execute(args.toArray(new String[0])); + int result = JadxCLI.execute(buildArgs(List.of("--decompilation-mode", "simple"), "samples/hello.dex")); assertThat(result).isEqualTo(0); - List files = collectJavaFilesInDir(tempDir); + List files = collectJavaFilesInDir(testDir); assertThat(files).hasSize(1); } @Test public void testResourceOnly() throws Exception { - Path tempDir = FileUtils.createTempDir("resourceOnly"); - List args = buildArgs(tempDir, "samples/resources-only.apk"); - - int result = JadxCLI.execute(args.toArray(new String[0])); + int result = JadxCLI.execute(buildArgs(List.of(), "samples/resources-only.apk")); assertThat(result).isEqualTo(0); - List files = collectFilesInDir(tempDir, + List files = collectFilesInDir(testDir, path -> path.getFileName().toString().equalsIgnoreCase("AndroidManifest.xml")); assertThat(files).isNotEmpty(); } - private void decompile(String tmpDirName, String... inputSamples) throws URISyntaxException, IOException { - Path tempDir = FileUtils.createTempDir(tmpDirName); - List args = buildArgs(tempDir, inputSamples); - - int result = JadxCLI.execute(args.toArray(new String[0])); + private void decompile(String... inputSamples) throws URISyntaxException, IOException { + int result = JadxCLI.execute(buildArgs(List.of(), inputSamples)); assertThat(result).isEqualTo(0); - List resultJavaFiles = collectJavaFilesInDir(tempDir); + List resultJavaFiles = collectJavaFilesInDir(testDir); assertThat(resultJavaFiles).isNotEmpty(); // do not copy input files as resources - for (Path path : collectFilesInDir(tempDir, LOG_ALL_FILES)) { + for (Path path : collectFilesInDir(testDir, LOG_ALL_FILES)) { for (String inputSample : inputSamples) { assertThat(path.toAbsolutePath().toString()).doesNotContain(inputSample); } } } - private List buildArgs(Path tempDir, String... inputSamples) throws URISyntaxException { - List args = new ArrayList<>(); + private String[] buildArgs(List options, String... inputSamples) throws URISyntaxException { + List args = new ArrayList<>(options); args.add("-v"); args.add("-d"); - args.add(tempDir.toAbsolutePath().toString()); + args.add(testDir.toAbsolutePath().toString()); for (String inputSample : inputSamples) { URL resource = getClass().getClassLoader().getResource(inputSample); @@ -121,7 +107,7 @@ public class TestInput { String sampleFile = resource.toURI().getRawPath(); args.add(sampleFile); } - return args; + return args.toArray(new String[0]); } private static List collectJavaFilesInDir(Path dir) throws IOException { @@ -137,9 +123,4 @@ public class TestInput { .collect(Collectors.toList()); } } - - @AfterAll - public static void cleanup() { - FileUtils.clearTempRootDir(); - } } diff --git a/jadx-commons/jadx-app-commons/src/main/java/jadx/commons/app/JadxTempFiles.java b/jadx-commons/jadx-app-commons/src/main/java/jadx/commons/app/JadxTempFiles.java new file mode 100644 index 00000000..e4122ab9 --- /dev/null +++ b/jadx-commons/jadx-app-commons/src/main/java/jadx/commons/app/JadxTempFiles.java @@ -0,0 +1,31 @@ +package jadx.commons.app; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class JadxTempFiles { + private static final String JADX_TMP_INSTANCE_PREFIX = "jadx-instance-"; + + private static final Path TEMP_ROOT_DIR = createTempRootDir(); + + public static Path getTempRootDir() { + return TEMP_ROOT_DIR; + } + + private static Path createTempRootDir() { + try { + String jadxTmpDir = System.getenv("JADX_TMP_DIR"); + Path dir; + if (jadxTmpDir != null) { + dir = Files.createTempDirectory(Paths.get(jadxTmpDir), JADX_TMP_INSTANCE_PREFIX); + } else { + dir = Files.createTempDirectory(JADX_TMP_INSTANCE_PREFIX); + } + dir.toFile().deleteOnExit(); + return dir; + } catch (Exception e) { + throw new RuntimeException("Failed to create temp root directory", e); + } + } +} diff --git a/jadx-core/src/main/java/jadx/api/JadxDecompiler.java b/jadx-core/src/main/java/jadx/api/JadxDecompiler.java index b0b2c755..1b0c1a52 100644 --- a/jadx-core/src/main/java/jadx/api/JadxDecompiler.java +++ b/jadx-core/src/main/java/jadx/api/JadxDecompiler.java @@ -111,6 +111,7 @@ public final class JadxDecompiler implements Closeable { reset(); JadxArgsValidator.validate(this); LOG.info("loading ..."); + FileUtils.updateTempRootDir(args.getFilesGetter().getTempDir()); loadPlugins(); loadInputFiles(); @@ -174,6 +175,7 @@ public final class JadxDecompiler implements Closeable { closeInputs(); closeLoaders(); args.close(); + FileUtils.deleteTempRootDir(); } private void closeInputs() { diff --git a/jadx-core/src/main/java/jadx/core/plugins/files/TempFilesGetter.java b/jadx-core/src/main/java/jadx/core/plugins/files/TempFilesGetter.java index ce9c3180..97c09b66 100644 --- a/jadx-core/src/main/java/jadx/core/plugins/files/TempFilesGetter.java +++ b/jadx-core/src/main/java/jadx/core/plugins/files/TempFilesGetter.java @@ -1,5 +1,6 @@ package jadx.core.plugins.files; +import java.nio.file.Files; import java.nio.file.Path; import jadx.core.utils.files.FileUtils; @@ -8,22 +9,35 @@ public class TempFilesGetter implements IJadxFilesGetter { public static final TempFilesGetter INSTANCE = new TempFilesGetter(); + private final Path tempRootDir; + + private TempFilesGetter() { + try { + tempRootDir = Files.createTempDirectory("jadx-temp-"); + tempRootDir.toFile().deleteOnExit(); + } catch (Exception e) { + throw new RuntimeException("Failed to create temp directory", e); + } + } + @Override public Path getConfigDir() { - return FileUtils.getTempRootDir().resolve("config"); + return makeSubDir("config"); } @Override public Path getCacheDir() { - return FileUtils.getTempRootDir().resolve("cache"); + return makeSubDir("cache"); } @Override public Path getTempDir() { - return FileUtils.getTempRootDir().resolve("temp"); + return tempRootDir; } - private TempFilesGetter() { - // singleton + private Path makeSubDir(String subDir) { + Path dir = tempRootDir.resolve(subDir); + FileUtils.makeDirs(dir); + return dir; } } diff --git a/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java b/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java index e5b71a28..6f2719cb 100644 --- a/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java @@ -45,7 +45,31 @@ public class FileUtils { public static final String JADX_TMP_INSTANCE_PREFIX = "jadx-instance-"; public static final String JADX_TMP_PREFIX = "jadx-tmp-"; + private static Path tempRootDir = createTempRootDir(); + private FileUtils() { + // utility class + } + + public static synchronized Path updateTempRootDir(Path newTempRootDir) { + try { + Path dir = Files.createTempDirectory(newTempRootDir, JADX_TMP_INSTANCE_PREFIX); + tempRootDir = dir; + dir.toFile().deleteOnExit(); + return dir; + } catch (Exception e) { + throw new JadxRuntimeException("Failed to update temp root directory", e); + } + } + + private static Path createTempRootDir() { + try { + Path dir = Files.createTempDirectory(JADX_TMP_INSTANCE_PREFIX); + dir.toFile().deleteOnExit(); + return dir; + } catch (Exception e) { + throw new JadxRuntimeException("Failed to create temp root directory", e); + } } public static List expandDirs(List paths) { @@ -150,40 +174,13 @@ public class FileUtils { } } - private static final Path TEMP_ROOT_DIR = createTempRootDir(); - - private static Path createTempRootDir() { - try { - String jadxTmpDir = System.getenv("JADX_TMP_DIR"); - Path dir; - if (jadxTmpDir != null) { - dir = Files.createTempDirectory(Paths.get(jadxTmpDir), "jadx-instance-"); - } else { - dir = Files.createTempDirectory(JADX_TMP_INSTANCE_PREFIX); - } - dir.toFile().deleteOnExit(); - return dir; - } catch (Exception e) { - throw new JadxRuntimeException("Failed to create temp root directory", e); - } - } - - public static Path getTempRootDir() { - return TEMP_ROOT_DIR; - } - public static void deleteTempRootDir() { - deleteDirIfExists(TEMP_ROOT_DIR); - } - - public static void clearTempRootDir() { - deleteDirIfExists(TEMP_ROOT_DIR); - makeDirs(TEMP_ROOT_DIR); + deleteDirIfExists(tempRootDir); } public static Path createTempDir(String prefix) { try { - Path dir = Files.createTempDirectory(TEMP_ROOT_DIR, prefix); + Path dir = Files.createTempDirectory(tempRootDir, prefix); dir.toFile().deleteOnExit(); return dir; } catch (Exception e) { @@ -193,7 +190,7 @@ public class FileUtils { public static Path createTempFile(String suffix) { try { - Path path = Files.createTempFile(TEMP_ROOT_DIR, JADX_TMP_PREFIX, suffix); + Path path = Files.createTempFile(tempRootDir, JADX_TMP_PREFIX, suffix); path.toFile().deleteOnExit(); return path; } catch (Exception e) { diff --git a/jadx-core/src/main/java/jadx/core/utils/files/ZipFile.java b/jadx-core/src/main/java/jadx/core/utils/files/ZipFile.java index c23755d6..571ad787 100644 --- a/jadx-core/src/main/java/jadx/core/utils/files/ZipFile.java +++ b/jadx-core/src/main/java/jadx/core/utils/files/ZipFile.java @@ -8,7 +8,6 @@ import java.io.RandomAccessFile; import java.lang.reflect.UndeclaredThrowableException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -126,14 +125,12 @@ public class ZipFile extends java.util.zip.ZipFile { } private static File copyFile(File file) throws IOException { - var newFile = Files.createTempFile(file.getName(), ".apk").toFile(); - + var newFile = FileUtils.createTempFile(file.getName()).toFile(); try (var in = new FileInputStream(file)) { try (var out = new FileOutputStream(newFile)) { in.transferTo(out); } } - return newFile; } diff --git a/jadx-core/src/test/java/jadx/api/JadxArgsValidatorOutDirsTest.java b/jadx-core/src/test/java/jadx/api/JadxArgsValidatorOutDirsTest.java index f1ec8370..d9c1c6d9 100644 --- a/jadx-core/src/test/java/jadx/api/JadxArgsValidatorOutDirsTest.java +++ b/jadx-core/src/test/java/jadx/api/JadxArgsValidatorOutDirsTest.java @@ -1,19 +1,24 @@ package jadx.api; +import java.nio.file.Files; +import java.nio.file.Path; + import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import jadx.core.utils.files.FileUtils; - import static jadx.core.utils.files.FileUtils.toFile; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class JadxArgsValidatorOutDirsTest { - private static final Logger LOG = LoggerFactory.getLogger(JadxArgsValidatorOutDirsTest.class); + public JadxArgs args; + @TempDir + Path testDir; + @Test public void checkAllSet() { setOutDirs("r", "s", "r"); @@ -64,8 +69,12 @@ public class JadxArgsValidatorOutDirsTest { } private JadxArgs makeArgs() { - JadxArgs args = new JadxArgs(); - args.getInputFiles().add(FileUtils.createTempFile("some.apk").toFile()); - return args; + try { + JadxArgs args = new JadxArgs(); + args.getInputFiles().add(Files.createTempFile(testDir, "test-", ".apk").toFile()); + return args; + } catch (Exception e) { + throw new RuntimeException(e); + } } } diff --git a/jadx-core/src/test/java/jadx/api/JadxDecompilerTest.java b/jadx-core/src/test/java/jadx/api/JadxDecompilerTest.java index c2ff2425..73fc4e8d 100644 --- a/jadx-core/src/test/java/jadx/api/JadxDecompilerTest.java +++ b/jadx-core/src/test/java/jadx/api/JadxDecompilerTest.java @@ -8,8 +8,8 @@ import java.net.URL; import java.util.List; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; -import jadx.core.utils.files.FileUtils; import jadx.core.xmlgen.ResContainer; import jadx.plugins.input.dex.DexInputPlugin; @@ -17,15 +17,17 @@ import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class JadxDecompilerTest { + @TempDir + File testDir; + @Test public void testExampleUsage() { File sampleApk = getFileFromSampleDir("app-with-fake-dex.apk"); - File outDir = FileUtils.createTempDir("jadx-usage-example").toFile(); // test simple apk loading JadxArgs args = new JadxArgs(); args.getInputFiles().add(sampleApk); - args.setOutDir(outDir); + args.setOutDir(testDir); try (JadxDecompiler jadx = new JadxDecompiler(args)) { jadx.load(); @@ -59,11 +61,10 @@ public class JadxDecompilerTest { @Test public void testResourcesLoad() { File sampleApk = getFileFromSampleDir("app-with-fake-dex.apk"); - File outDir = FileUtils.createTempDir("jadx-usage-example-2").toFile(); JadxArgs args = new JadxArgs(); args.getInputFiles().add(sampleApk); - args.setOutDir(outDir); + args.setOutDir(testDir); args.setSkipSources(true); try (JadxDecompiler jadx = new JadxDecompiler(args)) { jadx.load(); diff --git a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java index 16497a5f..a1ddaa8e 100644 --- a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java +++ b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java @@ -30,6 +30,7 @@ import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,12 +54,12 @@ import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.RootNode; import jadx.core.utils.Utils; import jadx.core.utils.exceptions.JadxRuntimeException; -import jadx.core.utils.files.FileUtils; import jadx.core.xmlgen.ResourceStorage; import jadx.core.xmlgen.entry.ResourceEntry; import jadx.tests.api.compiler.CompilerOptions; import jadx.tests.api.compiler.JavaUtils; import jadx.tests.api.compiler.TestCompiler; +import jadx.tests.api.utils.TestFilesGetter; import jadx.tests.api.utils.TestUtils; import static org.apache.commons.lang3.StringUtils.leftPad; @@ -115,6 +116,9 @@ public abstract class IntegrationTest extends TestUtils { protected JadxDecompiler jadxDecompiler; + @TempDir + Path testDir; + @BeforeEach public void init() { this.compile = true; @@ -124,7 +128,7 @@ public abstract class IntegrationTest extends TestUtils { this.useJavaInput = null; args = new JadxArgs(); - args.setOutDir(new File("test-out-tmp")); + args.setOutDir(testDir.toFile()); args.setShowInconsistentCode(true); args.setThreadsCount(1); args.setSkipResources(true); @@ -132,6 +136,7 @@ public abstract class IntegrationTest extends TestUtils { args.setDeobfuscationOn(false); args.setGeneratedRenamesMappingFileMode(GeneratedRenamesMappingFileMode.IGNORE); args.setRunDebugChecks(true); + args.setFilesGetter(new TestFilesGetter(testDir)); // use the same values on all systems args.setFsCaseSensitive(false); @@ -144,7 +149,6 @@ public abstract class IntegrationTest extends TestUtils { close(jadxDecompiler); close(sourceCompiler); close(decompiledCompiler); - FileUtils.clearTempRootDir(); } private void close(Closeable closeable) throws IOException { @@ -154,7 +158,7 @@ public abstract class IntegrationTest extends TestUtils { } public void setOutDirSuffix(String suffix) { - args.setOutDir(new File("test-out-" + suffix + "-tmp")); + args.setOutDir(new File(testDir.toFile(), suffix)); } public String getTestName() { @@ -499,7 +503,7 @@ public abstract class IntegrationTest extends TestUtils { } private List compileSourceFiles(List compileFileList) throws IOException { - Path outTmp = FileUtils.createTempDir("jadx-tmp-classes"); + Path outTmp = Files.createTempDirectory(testDir, "jadx-tmp-classes"); sourceCompiler = new TestCompiler(compilerOptions); List files = sourceCompiler.compileFiles(compileFileList, outTmp); if (saveTestJar) { @@ -509,7 +513,7 @@ public abstract class IntegrationTest extends TestUtils { } private void saveToJar(List files, Path baseDir) throws IOException { - Path jarFile = Files.createTempFile("tests-" + getTestName() + '-', ".jar"); + Path jarFile = Files.createTempFile(testDir, "tests-" + getTestName() + '-', ".jar"); try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(jarFile))) { for (File file : files) { Path fullPath = file.toPath(); diff --git a/jadx-core/src/test/java/jadx/tests/api/utils/TestFilesGetter.java b/jadx-core/src/test/java/jadx/tests/api/utils/TestFilesGetter.java new file mode 100644 index 00000000..395c16eb --- /dev/null +++ b/jadx-core/src/test/java/jadx/tests/api/utils/TestFilesGetter.java @@ -0,0 +1,35 @@ +package jadx.tests.api.utils; + +import java.nio.file.Path; + +import jadx.core.plugins.files.IJadxFilesGetter; +import jadx.core.utils.files.FileUtils; + +public class TestFilesGetter implements IJadxFilesGetter { + private final Path testDir; + + public TestFilesGetter(Path testDir) { + this.testDir = testDir; + } + + @Override + public Path getConfigDir() { + return makeSubDir("config"); + } + + @Override + public Path getCacheDir() { + return makeSubDir("cache"); + } + + @Override + public Path getTempDir() { + return testDir; + } + + private Path makeSubDir(String config) { + Path dir = testDir.resolve(config); + FileUtils.makeDirs(dir); + return dir; + } +} diff --git a/jadx-gui/src/main/java/jadx/gui/jobs/DecompileTask.java b/jadx-gui/src/main/java/jadx/gui/jobs/DecompileTask.java index 79cd6634..a44feb8a 100644 --- a/jadx-gui/src/main/java/jadx/gui/jobs/DecompileTask.java +++ b/jadx-gui/src/main/java/jadx/gui/jobs/DecompileTask.java @@ -13,16 +13,16 @@ import org.slf4j.LoggerFactory; import jadx.api.ICodeCache; import jadx.api.JavaClass; import jadx.api.utils.tasks.ITaskExecutor; +import jadx.commons.app.JadxCommonEnv; import jadx.core.utils.tasks.TaskExecutor; import jadx.gui.JadxWrapper; import jadx.gui.ui.MainWindow; import jadx.gui.utils.NLS; -import jadx.gui.utils.UiUtils; public class DecompileTask extends CancelableBackgroundTask { private static final Logger LOG = LoggerFactory.getLogger(DecompileTask.class); - private static final int CLS_LIMIT = Integer.parseInt(UiUtils.getEnvVar("JADX_CLS_PROCESS_LIMIT", "50")); + private static final int CLS_LIMIT = JadxCommonEnv.getInt("JADX_CLS_PROCESS_LIMIT", 50); public static int calcDecompileTimeLimit(int classCount) { return classCount * CLS_LIMIT + 5000; diff --git a/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java b/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java index cc6c8db1..e3aa3efe 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java @@ -1549,7 +1549,6 @@ public class MainWindow extends JFrame { heapUsageBar.reset(); closeAll(); - FileUtils.deleteTempRootDir(); dispose(); System.exit(0); } diff --git a/jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java b/jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java index 80b9881d..63bb4ffc 100644 --- a/jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java +++ b/jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java @@ -337,14 +337,6 @@ public class UiUtils { return null; } - public static String getEnvVar(String varName, String defValue) { - String envVal = System.getenv(varName); - if (envVal == null) { - return defValue; - } - return envVal; - } - public static void showMessageBox(Component parent, String msg) { JOptionPane.showMessageDialog(parent, msg); }