From 934bc686f643898d76d3878551fa301ce0d0ff00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 1 Aug 2024 14:24:54 +0200 Subject: [PATCH] Changed: Run/Debug command - executed SWF temp files (`~ffdec_run...swf` etc.) are now generated in the directory where original SWF resides to allow loading relative assets --- CHANGELOG.md | 2 ++ src/com/jpexs/decompiler/flash/gui/Main.java | 32 ++++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cec2f1bc7..645f97bb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,8 @@ All notable changes to this project will be documented in this file. - Information in the tag node title - separated exportName from assigned class - ImportAssets tag reorganized - now imported items are not in the tag tree, but when referenced it works - [PR194] Default directory for storing config on Linux changed to `~/.config/FFDec`, when `~/.FFDec` does not exist yet +- Run/Debug command - executed SWF temp files (`~ffdec_run...swf` etc.) are now generated + in the directory where original SWF resides to allow loading relative assets ## [20.1.0] - 2023-12-30 ### Added diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index bd86c4ece..75654a2ea 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -535,7 +535,7 @@ public class Main { } } - private static void prepareSwf(SwfPreparation prep, File toPrepareFile, File origFile, List tempFiles) throws IOException, InterruptedException { + private static void prepareSwf(SwfPreparation prep, File toPrepareFile, File origFile, File tempFilesDir, List tempFiles) throws IOException, InterruptedException { SWF instrSWF = null; try (FileInputStream fis = new FileInputStream(toPrepareFile)) { instrSWF = new SWF(fis, toPrepareFile.getAbsolutePath(), origFile == null ? "unknown.swf" : origFile.getName(), false); @@ -550,12 +550,12 @@ public class Main { String url = it.getUrl(); File importedFile = new File(origFile.getParentFile(), url); if (importedFile.exists()) { - File newTempFile = File.createTempFile("ffdec_run_import_", ".swf"); + File newTempFile = createTempFileInDir(tempFilesDir, "~ffdec_run_import_", ".swf"); it.setUrl("./" + newTempFile.getName()); byte[] impData = Helper.readFile(importedFile.getAbsolutePath()); Helper.writeFile(newTempFile.getAbsolutePath(), impData); tempFiles.add(newTempFile); - prepareSwf(prep, newTempFile, importedFile, tempFiles); + prepareSwf(prep, newTempFile, importedFile, tempFilesDir, tempFiles); } } } @@ -568,6 +568,17 @@ public class Main { } } } + + private static File createTempFileInDir(File tempFilesDir, String prefix, String suffix) throws IOException { + if (!tempFilesDir.isDirectory()) { + return File.createTempFile(prefix, suffix); + } + try { + return File.createTempFile(prefix, suffix, tempFilesDir); + } catch (IOException ex) { + return File.createTempFile(prefix, suffix); + } + } public static void runAsync(File swfFile) { String playerLocation = Configuration.playerLocation.get(); @@ -602,10 +613,12 @@ public class Main { if (swf == null) { return; } + File tempRunDir = swf.getFile() == null ? null : new File(swf.getFile()).getParentFile(); + File tempFile; - List tempFiles = new ArrayList<>(); + List tempFiles = new ArrayList<>(); try { - tempFile = File.createTempFile("ffdec_run_", ".swf"); + tempFile = createTempFileInDir(tempRunDir, "~ffdec_run_", ".swf"); SWF swfToSave = swf; if (swf.gfx) { @@ -615,7 +628,7 @@ public class Main { swfToSave.saveTo(fos, false, swf.gfx); } - prepareSwf(new SwfRunPrepare(), tempFile, swf.getFile() == null ? null : new File(swf.getFile()), tempFiles); + prepareSwf(new SwfRunPrepare(), tempFile, swf.getFile() == null ? null : new File(swf.getFile()), tempRunDir, tempFiles); } catch (IOException ex) { return; @@ -643,11 +656,12 @@ public class Main { if (swf == null) { return; } - debugHandler.setDebuggedSwf(swf); + debugHandler.setDebuggedSwf(swf); + File tempRunDir = swf.getFile() == null ? null : new File(swf.getFile()).getParentFile(); File tempFile = null; try { - tempFile = File.createTempFile("ffdec_debug_", ".swf"); + tempFile = createTempFileInDir(tempRunDir, "~ffdec_debug_", ".swf"); } catch (Exception ex) { //ignored } @@ -666,7 +680,7 @@ public class Main { try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(fTempFile))) { swfToSave.saveTo(fos, false, swf.gfx); } - prepareSwf(new SwfDebugPrepare(doPCode), fTempFile, swf.getFile() == null ? null : new File(swf.getFile()), tempFiles); + prepareSwf(new SwfDebugPrepare(doPCode), fTempFile, swf.getFile() == null ? null : new File(swf.getFile()), tempRunDir, tempFiles); return null; }