diff --git a/src/com/jpexs/decompiler/flash/SWF.java b/src/com/jpexs/decompiler/flash/SWF.java index 57ed6c952..b6bad2db8 100644 --- a/src/com/jpexs/decompiler/flash/SWF.java +++ b/src/com/jpexs/decompiler/flash/SWF.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash; +import SevenZip.Compression.LZMA.Decoder; import SevenZip.Compression.LZMA.Encoder; import com.jpacker.JPacker; import com.jpexs.decompiler.flash.abc.ABC; @@ -447,6 +448,9 @@ public final class SWF implements TreeItem, Timelined { for (int i = 0; i < 4; i++) { dictionarySize += ((int) (lzmaProperties[1 + i]) & 0xFF) << (i * 8); } + if (Configuration.lzmaFastBytes.get() > 0) { + enc.SetNumFastBytes(Configuration.lzmaFastBytes.get()); + } enc.SetDictionarySize(dictionarySize); enc.SetLcLpPb(lc, lp, pb); baos = new ByteArrayOutputStream(); @@ -459,7 +463,7 @@ public final class SWF implements TreeItem, Timelined { udata[2] = (byte) ((data.length >> 16) & 0xFF); udata[3] = (byte) ((data.length >> 24) & 0xFF); os.write(udata); - os.write(lzmaProperties); + enc.WriteCoderProperties(os); } else if (compression == SWFCompression.ZLIB) { os = new DeflaterOutputStream(os); } @@ -770,7 +774,7 @@ public final class SWF implements TreeItem, Timelined { if (lzmaProperties.length != propertiesSize) { throw new IOException("LZMA:input .lzma file is too short"); } - SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder(); + Decoder decoder = new Decoder(); if (!decoder.SetDecoderProperties(lzmaProperties)) { throw new IOException("LZMA:Incorrect stream properties"); } diff --git a/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 57aa2a581..4e03c6799 100644 --- a/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -323,6 +323,9 @@ public class Configuration { @ConfigurationCategory("export") public static final ConfigurationItem textExportExportFontFace = null; + @ConfigurationDefaultInt(128) + public static final ConfigurationItem lzmaFastBytes = null; + private enum OSId { WINDOWS, OSX, UNIX diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java index 5d6c59efe..98ae89e6a 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java @@ -482,43 +482,47 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener { break; case ACTION_SAVE: { SWF swf = mainFrame.panel.getCurrentSwf(); - SWFNode snode = ((TagTreeModel) mainFrame.panel.tagTree.getModel()).getSwfNode(swf); - boolean saved = false; - if (snode.binaryData != null) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - swf.saveTo(baos); - snode.binaryData.binaryData = baos.toByteArray(); - snode.binaryData.setModified(true); - saved = true; - } catch (IOException ex) { - Logger.getLogger(MainFrameRibbonMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); + if (swf != null) { + SWFNode snode = ((TagTreeModel) mainFrame.panel.tagTree.getModel()).getSwfNode(swf); + boolean saved = false; + if (snode.binaryData != null) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + swf.saveTo(baos); + snode.binaryData.binaryData = baos.toByteArray(); + snode.binaryData.setModified(true); + saved = true; + } catch (IOException ex) { + Logger.getLogger(MainFrameRibbonMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); + } + } else if (swf.file == null) { + saved = saveAs(swf, SaveFileMode.SAVEAS); + } else { + try { + Main.saveFile(swf, swf.file); + } catch (IOException ex) { + Logger.getLogger(MainFrameClassicMenu.class.getName()).log(Level.SEVERE, null, ex); + View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE); + } } - } else if (swf.file == null) { - saved = saveAs(swf, SaveFileMode.SAVEAS); - } else { - try { - Main.saveFile(swf, swf.file); - } catch (IOException ex) { - Logger.getLogger(MainFrameClassicMenu.class.getName()).log(Level.SEVERE, null, ex); - View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE); + if (saved) { + swf.clearModified(); } } - if (saved) { - swf.clearModified(); - } } break; case ACTION_SAVE_AS: { SWF swf = mainFrame.panel.getCurrentSwf(); - if (saveAs(swf, SaveFileMode.SAVEAS)) { + if (swf != null && saveAs(swf, SaveFileMode.SAVEAS)) { swf.clearModified(); } } break; case ACTION_SAVE_AS_EXE: { SWF swf = mainFrame.panel.getCurrentSwf(); - saveAs(swf, SaveFileMode.EXE); + if (swf != null) { + saveAs(swf, SaveFileMode.EXE); + } } break; case ACTION_OPEN: diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index 6f072e559..c32dbf13b 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -711,44 +711,48 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener { break; case ACTION_SAVE: { SWF swf = mainFrame.panel.getCurrentSwf(); - SWFNode snode = ((TagTreeModel) mainFrame.panel.tagTree.getModel()).getSwfNode(swf); - boolean saved = false; - if (snode.binaryData != null) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - swf.saveTo(baos); - snode.binaryData.binaryData = baos.toByteArray(); - snode.binaryData.setModified(true); - saved = true; - } catch (IOException ex) { - Logger.getLogger(MainFrameRibbonMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); + if (swf != null) { + SWFNode snode = ((TagTreeModel) mainFrame.panel.tagTree.getModel()).getSwfNode(swf); + boolean saved = false; + if (snode.binaryData != null) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + swf.saveTo(baos); + snode.binaryData.binaryData = baos.toByteArray(); + snode.binaryData.setModified(true); + saved = true; + } catch (IOException ex) { + Logger.getLogger(MainFrameRibbonMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); + } + } else if (swf.file == null) { + saved = saveAs(swf, SaveFileMode.SAVEAS); + } else { + try { + Main.saveFile(swf, swf.file); + saved = true; + } catch (IOException ex) { + Logger.getLogger(MainFrameRibbonMenu.class.getName()).log(Level.SEVERE, null, ex); + View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE); + } } - } else if (swf.file == null) { - saved = saveAs(swf, SaveFileMode.SAVEAS); - } else { - try { - Main.saveFile(swf, swf.file); - saved = true; - } catch (IOException ex) { - Logger.getLogger(MainFrameRibbonMenu.class.getName()).log(Level.SEVERE, null, ex); - View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE); + if (saved) { + swf.clearModified(); } } - if (saved) { - swf.clearModified(); - } } break; case ACTION_SAVE_AS: { SWF swf = mainFrame.panel.getCurrentSwf(); - if (saveAs(swf, SaveFileMode.SAVEAS)) { + if (swf != null && saveAs(swf, SaveFileMode.SAVEAS)) { swf.clearModified(); } } break; case ACTION_SAVE_AS_EXE: { SWF swf = mainFrame.panel.getCurrentSwf(); - saveAs(swf, SaveFileMode.EXE); + if (swf != null) { + saveAs(swf, SaveFileMode.EXE); + } } break; case ACTION_OPEN: diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 7f93e81c5..801d73292 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1131,6 +1131,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } else if (treePanelMode == TreePanelMode.DUMP_TREE) { DumpInfo dumpInfo = (DumpInfo) dumpTree.getLastSelectedPathComponent(); + if (dumpInfo == null) { + return null; + } + return DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf(); } @@ -1297,6 +1301,9 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } public void renameOneIdentifier(final SWF swf) { + if (swf == null) { + return; + } if (swf.fileAttributes != null && swf.fileAttributes.actionScript3) { final int multiName = abcPanel.decompiledTextArea.getMultinameUnderCursor(); final List abcList = swf.abcList; @@ -1345,6 +1352,9 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } public void exportFla(final SWF swf) { + if (swf == null) { + return; + } JFileChooser fc = new JFileChooser(); String selDir = Configuration.lastOpenDir.get(); fc.setCurrentDirectory(new File(selDir)); @@ -1731,6 +1741,9 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } public void renameIdentifiers(final SWF swf) { + if (swf == null) { + return; + } if (confirmExperimental()) { final RenameType renameType = new RenameDialog().display(); if (renameType != null) { @@ -1835,6 +1848,9 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } public void removeNonScripts(SWF swf) { + if (swf == null) { + return; + } List tags = new ArrayList<>(swf.tags); for (Tag tag : tags) { System.out.println(tag.getClass()); diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index 660f0f955..554d42cbb 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -257,3 +257,6 @@ config.description.packJavaScripts = Run JavaScript packer on scripts created on config.name.textExportExportFontFace = Use font-face in SVG export config.description.textExportExportFontFace = Embed font files in SVG using font-face instead of shapes + +config.name.lzmaFastBytes = LZMA fast bytes +config.description.lzmaFastBytes = Fast bytes parameter of the LZMA encoder diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties index 82eade973..a3618986d 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties @@ -257,3 +257,6 @@ config.description.packJavaScripts = JavaScript csomagol\u00f3 futtat\u00e1sa V\ config.name.textExportExportFontFace = Font-face haszn\u00e1lata SVG export\u00e1l\u00e1skor config.description.textExportExportFontFace = Bet\u0171t\u00edpus f\u00e1jlok be\u00e1gyaz\u00e1sa az SVG f\u00e1jlokba \u00e9s font-face haszn\u00e1lata alakzatok helyett + +config.name.lzmaFastBytes = LZMA fast bytes +config.description.textExportExportFontFace = Az LZMA t\u00f6m\u00f6r\u00edt\u0151 "Fast bytes" param\u00e9tere