From fc306a620c6a209270a0c4c6187877487cc90ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 15 Feb 2021 20:49:40 +0100 Subject: [PATCH] Changed: #1565, #1407, #1350 On BinaryData SWF save, parent SWF is saved Fixed notifying about file change on bundle save. --- CHANGELOG.md | 3 ++ src/com/jpexs/decompiler/flash/gui/Main.java | 35 ++++++++++++------- .../decompiler/flash/gui/MainFrameMenu.java | 24 +++++++------ 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecc3b7fc3..e34c773bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ All notable changes to this project will be documented in this file. - Only last DoInitAction tag displayed - #1606 Run/Debug SWF that is embedded (has no file associated) +### Changed +- #1565, #1407, #1350 On BinaryData SWF save, parent SWF is saved + ## [13.0.3] - 2021-02-12 ### Added - #1594 Option to disable AS3 P-code indentation, label on separate line diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index da96573ef..d968561d7 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -188,6 +188,26 @@ public class Main { private static List savedFiles = Collections.synchronizedList(new ArrayList<>()); + //This method makes file watcher to shut up during our own file saving + public static void startSaving(File savedFile) { + savedFiles.add(savedFile); + } + + public static void stopSaving(File savedFile) { + View.execInEventDispatchLater(new Runnable() { + @Override + public void run() { + //TODO: handle this better + try { + Thread.sleep(2000); + } catch (InterruptedException ex) { + //ignore + } + savedFiles.remove(savedFile); + } + }); + } + public static void freeRun() { synchronized (Main.class) { if (runTempFile != null) { @@ -972,7 +992,7 @@ public class Main { public static void saveFile(SWF swf, String outfile, SaveFileMode mode, ExeExportMode exeExportMode) throws IOException { File savedFile = new File(outfile); - savedFiles.add(savedFile); + startSaving(savedFile); if (mode == SaveFileMode.SAVEAS && swf.swfList != null /*SWF in binarydata has null*/ && !swf.swfList.isBundle()) { swf.setFile(outfile); swf.swfList.sourceInfo.setFile(outfile); @@ -1050,18 +1070,7 @@ public class Main { } else { throw new IOException("Output not found"); } - View.execInEventDispatchLater(new Runnable() { - @Override - public void run() { - //TODO: handle this better - try { - Thread.sleep(2000); - } catch (InterruptedException ex) { - //ignore - } - savedFiles.remove(savedFile); - } - }); + stopSaving(savedFile); } private static class OpenFileWorker extends SwingWorker { diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 80deb7b66..152a3da2a 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -44,6 +44,7 @@ import java.awt.event.KeyEvent; import java.awt.event.WindowEvent; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.io.UnsupportedEncodingException; @@ -123,14 +124,12 @@ public abstract class MainFrameMenu implements MenuBuilder { return true; } - protected boolean saveActionPerformed(ActionEvent evt) { - if (Main.isWorking()) { - return false; - } - + private boolean saveSwf(SWF swf) { + boolean saved = false; if (swf != null) { - boolean saved = false; if (swf.swfList != null && swf.swfList.isBundle()) { + File savedFile = new File(swf.swfList.sourceInfo.getFile()); + Main.startSaving(savedFile); SWFBundle bundle = swf.swfList.bundle; if (!bundle.isReadOnly()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -141,13 +140,14 @@ public abstract class MainFrameMenu implements MenuBuilder { Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); } } + Main.stopSaving(savedFile); } else if (swf.binaryData != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { swf.saveTo(baos); swf.binaryData.binaryData = new ByteArrayRange(baos.toByteArray()); swf.binaryData.setModified(true); - saved = true; + saved = saveSwf(swf.binaryData.getSwf()); //save parent swf } catch (IOException ex) { Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); } @@ -166,11 +166,15 @@ public abstract class MainFrameMenu implements MenuBuilder { swf.clearModified(); mainFrame.getPanel().refreshTree(swf); } - - return true; } + return saved; + } - return false; + protected boolean saveActionPerformed(ActionEvent evt) { + if (Main.isWorking()) { + return false; + } + return saveSwf(swf); } protected boolean saveAsActionPerformed(ActionEvent evt) {