From 59b560b553d1dbb657faed20c142ad203de783da Mon Sep 17 00:00:00 2001 From: Skylot <118523+skylot@users.noreply.github.com> Date: Thu, 29 May 2025 17:58:25 +0100 Subject: [PATCH] fix: lazily create dirs in default file getter implementation --- .../core/plugins/files/TempFilesGetter.java | 23 +++++++++++-------- .../src/main/java/jadx/gui/JadxWrapper.java | 2 +- .../gui/utils/plugins/CollectPlugins.java | 3 ++- 3 files changed, 17 insertions(+), 11 deletions(-) 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 97c09b662..602c9b958 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 @@ -9,15 +9,20 @@ public class TempFilesGetter implements IJadxFilesGetter { public static final TempFilesGetter INSTANCE = new TempFilesGetter(); - private final Path tempRootDir; + private static final class TempRootHolder { + public static final Path TEMP_ROOT_DIR; + + static { + try { + TEMP_ROOT_DIR = Files.createTempDirectory("jadx-temp-"); + TEMP_ROOT_DIR.toFile().deleteOnExit(); + } catch (Exception e) { + throw new RuntimeException("Failed to create temp directory", e); + } + } + } private TempFilesGetter() { - try { - tempRootDir = Files.createTempDirectory("jadx-temp-"); - tempRootDir.toFile().deleteOnExit(); - } catch (Exception e) { - throw new RuntimeException("Failed to create temp directory", e); - } } @Override @@ -32,11 +37,11 @@ public class TempFilesGetter implements IJadxFilesGetter { @Override public Path getTempDir() { - return tempRootDir; + return makeSubDir("tmp"); } private Path makeSubDir(String subDir) { - Path dir = tempRootDir.resolve(subDir); + Path dir = TempRootHolder.TEMP_ROOT_DIR.resolve(subDir); FileUtils.makeDirs(dir); return dir; } diff --git a/jadx-gui/src/main/java/jadx/gui/JadxWrapper.java b/jadx-gui/src/main/java/jadx/gui/JadxWrapper.java index fbdcf4180..15d2b0fe6 100644 --- a/jadx-gui/src/main/java/jadx/gui/JadxWrapper.java +++ b/jadx-gui/src/main/java/jadx/gui/JadxWrapper.java @@ -150,7 +150,7 @@ public class JadxWrapper { decompiler.getPluginManager().registerAddPluginListener(pluginContext -> { AppContext appContext = new AppContext(); appContext.setGuiContext(guiPluginsContext.buildForPlugin(pluginContext)); - appContext.setFilesGetter(JadxFilesGetter.INSTANCE); + appContext.setFilesGetter(decompiler.getArgs().getFilesGetter()); pluginContext.setAppContext(appContext); }); return guiPluginsContext; diff --git a/jadx-gui/src/main/java/jadx/gui/utils/plugins/CollectPlugins.java b/jadx-gui/src/main/java/jadx/gui/utils/plugins/CollectPlugins.java index edefbb3c2..c1ef92eed 100644 --- a/jadx-gui/src/main/java/jadx/gui/utils/plugins/CollectPlugins.java +++ b/jadx-gui/src/main/java/jadx/gui/utils/plugins/CollectPlugins.java @@ -34,12 +34,13 @@ public class CollectPlugins { // collect and init not loaded plugins in new temp context Runnable closeable = null; JadxArgs jadxArgs = mainWindow.getSettings().toJadxArgs(); + jadxArgs.setFilesGetter(JadxFilesGetter.INSTANCE); try (JadxDecompiler decompiler = new JadxDecompiler(jadxArgs)) { JadxPluginManager pluginManager = decompiler.getPluginManager(); pluginManager.registerAddPluginListener(pluginContext -> { AppContext appContext = new AppContext(); appContext.setGuiContext(null); // load temp plugins without UI context - appContext.setFilesGetter(JadxFilesGetter.INSTANCE); + appContext.setFilesGetter(jadxArgs.getFilesGetter()); pluginContext.setAppContext(appContext); }); pluginManager.load(new JadxExternalPluginsLoader());