fix: lazily create dirs in default file getter implementation

This commit is contained in:
Skylot
2025-05-29 17:58:25 +01:00
parent 8b08ac3806
commit 59b560b553
3 changed files with 17 additions and 11 deletions
@@ -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;
}
@@ -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;
@@ -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());