LZMA encoding fast bytes parameter

This commit is contained in:
honfika
2014-08-01 22:50:12 +02:00
parent 1b6bf416e8
commit 8ad45b379b
7 changed files with 88 additions and 51 deletions

View File

@@ -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");
}

View File

@@ -323,6 +323,9 @@ public class Configuration {
@ConfigurationCategory("export")
public static final ConfigurationItem<Boolean> textExportExportFontFace = null;
@ConfigurationDefaultInt(128)
public static final ConfigurationItem<Integer> lzmaFastBytes = null;
private enum OSId {
WINDOWS, OSX, UNIX

View File

@@ -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:

View File

@@ -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:

View File

@@ -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<ABCContainerTag> 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<Tag> tags = new ArrayList<>(swf.tags);
for (Tag tag : tags) {
System.out.println(tag.getClass());

View File

@@ -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

View File

@@ -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