From 314cc5bd61cd89ba6a9ca326955dfd01eb30bc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 23 Sep 2023 20:00:01 +0200 Subject: [PATCH] Added Exporting ByteArrayRange in the raw editor with the Export button --- CHANGELOG.md | 1 + .../generictageditors/BinaryDataEditor.java | 48 +++++++++++++++++-- .../flash/gui/locales/MainFrame.properties | 4 +- .../flash/gui/locales/MainFrame_cs.properties | 4 +- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e8c42ea7..f9c5a07b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - [#2073] Editing of frame count in SWF header (with warning that it won't update ShowFrame count) - Show font AS linkage class in its name in the tree (besides font name) - [#2057] Show all assigned AS linkage classes in the item name (instead just one) +- Exporting ByteArrayRange in the raw editor with the Export button ### Fixed - [#2043] StartSound2 tag handling diff --git a/src/com/jpexs/decompiler/flash/gui/generictageditors/BinaryDataEditor.java b/src/com/jpexs/decompiler/flash/gui/generictageditors/BinaryDataEditor.java index 9370f711b..def097cf6 100644 --- a/src/com/jpexs/decompiler/flash/gui/generictageditors/BinaryDataEditor.java +++ b/src/com/jpexs/decompiler/flash/gui/generictageditors/BinaryDataEditor.java @@ -16,26 +16,41 @@ */ package com.jpexs.decompiler.flash.gui.generictageditors; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.gui.AppStrings; import com.jpexs.decompiler.flash.gui.MainPanel; +import com.jpexs.decompiler.flash.gui.ViewMessages; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; import com.jpexs.helpers.ReflectionTools; import java.awt.Component; +import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import java.lang.reflect.Field; import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.JPanel; /** * * @author JPEXS */ -public class BinaryDataEditor extends JButton implements GenericTagEditor { +public class BinaryDataEditor extends JPanel implements GenericTagEditor { private final MainPanel mainPanel; + + private final JButton replaceButton; + + private final JButton exportButton; private final Object obj; @@ -57,8 +72,14 @@ public class BinaryDataEditor extends JButton implements GenericTagEditor { this.index = index; this.type = type; this.fieldName = fieldName; - setText(AppStrings.translate("button.replace")); - addActionListener(this::buttonActionPerformed); + exportButton = new JButton(AppStrings.translate("button.export")); + replaceButton = new JButton(AppStrings.translate("button.replace")); + + setLayout(new FlowLayout()); + add(exportButton); + add(replaceButton); + exportButton.addActionListener(this::exportActionPerformed); + replaceButton.addActionListener(this::replaceActionPerformed); reset(); } @@ -84,7 +105,24 @@ public class BinaryDataEditor extends JButton implements GenericTagEditor { } } - private void buttonActionPerformed(ActionEvent evt) { + private void exportActionPerformed(ActionEvent evt) { + if (value == null) { + return; + } + JFileChooser fc = new JFileChooser(); + fc.setCurrentDirectory(new File(Configuration.lastExportDir.get())); + if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { + File selfile = Helper.fixDialogFile(fc.getSelectedFile()); + ByteArrayRange br = (ByteArrayRange)value; + try(FileOutputStream fos = new FileOutputStream(selfile)) { + fos.write(br.getArray(), br.getPos(), br.getLength()); + } catch (IOException ex) { + ViewMessages.showMessageDialog(mainPanel, ex.getMessage(), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); + } + } + } + + private void replaceActionPerformed(ActionEvent evt) { File selectedFile = mainPanel.showImportFileChooser("", false); if (selectedFile != null) { File selfile = Helper.fixDialogFile(selectedFile); @@ -117,7 +155,7 @@ public class BinaryDataEditor extends JButton implements GenericTagEditor { @Override public void addChangeListener(final ChangeListener l) { final GenericTagEditor t = this; - addActionListener(new ActionListener() { + replaceButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 631985a97..e2026b2be 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -1145,4 +1145,6 @@ warning.edit.headerframecount = WARNING: Editing frame count in the header does neccessary number of ShowFrame tags on SWF timeline.\r\nTo add new frames, you should better use right click context menu on SWF -> Add frames,\r\n\ which will update the frame count in the header accordingly. -warning.icon = Click to show related warning \ No newline at end of file +warning.icon = Click to show related warning + +button.export = Export \ No newline at end of file diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties index dec6b00ea..5ceef3322 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_cs.properties @@ -1130,4 +1130,6 @@ warning.edit.headerframecount = VAROV\u00c1N\u00cd: Editace po\u010dtu sn\u00edm pot\u0159ebn\u00fd po\u010det ShowFrame tag\u016f na SWF \u010dasov\u00e9 ose.\r\nPro p\u0159id\u00e1n\u00ed nov\u00fdch sn\u00edmk\u016f byste m\u011bl rad\u011bji pou\u017e\u00edt kontextov\u00e9 menu o prav\u00e9m kliknu na SWF -> P\u0159idat sn\u00edmky,\r\n\ co\u017e aktualizuje podle toho i po\u010det sn\u00edmk\u016f v hlavi\u010dce. -warning.icon = Klikn\u011bte pro zobrazen\u00ed souvisej\u00edc\u00edho varov\u00e1n\u00ed \ No newline at end of file +warning.icon = Klikn\u011bte pro zobrazen\u00ed souvisej\u00edc\u00edho varov\u00e1n\u00ed + +button.export = Exportovat \ No newline at end of file