diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java index 812608953..ca4108e65 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -980,7 +980,7 @@ public class SWFInputStream implements AutoCloseable { public Tag call() throws Exception { DumpInfo di = dumpInfo; try { - Tag t = resolveTag(tag, level, parallel, skipUnusualTags); + Tag t = resolveTag(tag, level, parallel, skipUnusualTags, true); if (dumpInfo != null && t != null) { dumpInfo.name = t.getName(); } @@ -1048,7 +1048,7 @@ public class SWFInputStream implements AutoCloseable { switch (tag.getId()) { case FileAttributesTag.ID: //FileAttributes if (tag instanceof TagStub) { - tag = resolveTag((TagStub) tag, level, parallel, skipUnusualTags); + tag = resolveTag((TagStub) tag, level, parallel, skipUnusualTags, true); } FileAttributesTag fileAttributes = (FileAttributesTag) tag; if (fileAttributes.actionScript3) { @@ -1123,7 +1123,7 @@ public class SWFInputStream implements AutoCloseable { return tags; } - public static Tag resolveTag(TagStub tag, int level, boolean parallel, boolean skipUnusualTags) throws InterruptedException { + public static Tag resolveTag(TagStub tag, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws InterruptedException { Tag ret; ByteArrayRange data = tag.getOriginalRange(); @@ -1139,7 +1139,7 @@ public class SWFInputStream implements AutoCloseable { ret = new ShowFrameTag(swf, data); break; case 2: - ret = new DefineShapeTag(sis, data); + ret = new DefineShapeTag(sis, data, lazy); break; //case 3: FreeCharacter case 4: @@ -1195,7 +1195,7 @@ public class SWFInputStream implements AutoCloseable { ret = new DefineBitsJPEG2Tag(sis, data); break; case 22: - ret = new DefineShape2Tag(sis, data); + ret = new DefineShape2Tag(sis, data, lazy); break; case 23: ret = new DefineButtonCxformTag(sis, data); @@ -1215,7 +1215,7 @@ public class SWFInputStream implements AutoCloseable { //case 30: //case 31: FreeAll case 32: - ret = new DefineShape3Tag(sis, data); + ret = new DefineShape3Tag(sis, data, lazy); break; case 33: ret = new DefineText2Tag(sis, data); @@ -1332,7 +1332,7 @@ public class SWFInputStream implements AutoCloseable { ret = new DoABCDefineTag(sis, data); break; case 83: - ret = new DefineShape4Tag(sis, data); + ret = new DefineShape4Tag(sis, data, lazy); break; case 84: ret = new DefineMorphShape2Tag(sis, data); @@ -1459,7 +1459,7 @@ public class SWFInputStream implements AutoCloseable { if (resolve) { DumpInfo di = dumpInfo; try { - ret = resolveTag(tagStub, level, parallel, skipUnusualTags); + ret = resolveTag(tagStub, level, parallel, skipUnusualTags, true); } catch (Exception ex) { tagDataStream.endDumpLevelUntil(di); logger.log(Level.SEVERE, "Problem in " + timelined.toString(), ex); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java index c42e4bd41..fc6eb4b42 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java @@ -30,6 +30,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; public class DefineShape2Tag extends ShapeTag { @@ -39,6 +41,8 @@ public class DefineShape2Tag extends ShapeTag { public SHAPEWITHSTYLE shapes; public static final int ID = 22; + private ByteArrayRange shapeData; + @Override public int getShapeNum() { return 2; @@ -46,6 +50,17 @@ public class DefineShape2Tag extends ShapeTag { @Override public SHAPEWITHSTYLE getShapes() { + if (shapes == null && shapeData != null) { + try { + SWFInputStream sis = new SWFInputStream(swf, shapeData.getArray(), 0, shapeData.getPos() + shapeData.getLength()); + sis.seek(shapeData.getPos()); + shapes = sis.readSHAPEWITHSTYLE(2, false, "shapes"); + shapeData = null; // not needed anymore, give it to GC + } catch (IOException ex) { + Logger.getLogger(DefineShape2Tag.class.getName()).log(Level.SEVERE, null, ex); + } + } + return shapes; } @@ -84,11 +99,15 @@ public class DefineShape2Tag extends ShapeTag { shapes = SHAPEWITHSTYLE.createEmpty(2); } - public DefineShape2Tag(SWFInputStream sis, ByteArrayRange data) throws IOException { + public DefineShape2Tag(SWFInputStream sis, ByteArrayRange data, boolean lazy) throws IOException { super(sis.getSwf(), ID, "DefineShape2", data); shapeId = sis.readUI16("shapeId"); shapeBounds = sis.readRECT("shapeBounds"); - shapes = sis.readSHAPEWITHSTYLE(2, false, "shapes"); + if (!lazy) { + shapes = sis.readSHAPEWITHSTYLE(2, false, "shapes"); + } else { + shapeData = new ByteArrayRange(data.getArray(), (int) sis.getPos(), sis.available()); + } } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java index 9c22fffb9..96d9e8b36 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java @@ -30,6 +30,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; public class DefineShape3Tag extends ShapeTag { @@ -39,6 +41,8 @@ public class DefineShape3Tag extends ShapeTag { public SHAPEWITHSTYLE shapes; public static final int ID = 32; + private ByteArrayRange shapeData; + @Override public int getShapeNum() { return 3; @@ -46,6 +50,17 @@ public class DefineShape3Tag extends ShapeTag { @Override public SHAPEWITHSTYLE getShapes() { + if (shapes == null && shapeData != null) { + try { + SWFInputStream sis = new SWFInputStream(swf, shapeData.getArray(), 0, shapeData.getPos() + shapeData.getLength()); + sis.seek(shapeData.getPos()); + shapes = sis.readSHAPEWITHSTYLE(3, false, "shapes"); + shapeData = null; // not needed anymore, give it to GC + } catch (IOException ex) { + Logger.getLogger(DefineShape3Tag.class.getName()).log(Level.SEVERE, null, ex); + } + } + return shapes; } @@ -84,11 +99,15 @@ public class DefineShape3Tag extends ShapeTag { shapes = SHAPEWITHSTYLE.createEmpty(3); } - public DefineShape3Tag(SWFInputStream sis, ByteArrayRange data) throws IOException { + public DefineShape3Tag(SWFInputStream sis, ByteArrayRange data, boolean lazy) throws IOException { super(sis.getSwf(), ID, "DefineShape3", data); shapeId = sis.readUI16("shapeId"); shapeBounds = sis.readRECT("shapeBounds"); - shapes = sis.readSHAPEWITHSTYLE(3, false, "shapes"); + if (!lazy) { + shapes = sis.readSHAPEWITHSTYLE(3, false, "shapes"); + } else { + shapeData = new ByteArrayRange(data.getArray(), (int) sis.getPos(), sis.available()); + } } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java index 76bc5ad29..fd780512c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java @@ -31,6 +31,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; public class DefineShape4Tag extends ShapeTag { @@ -47,6 +49,8 @@ public class DefineShape4Tag extends ShapeTag { public SHAPEWITHSTYLE shapes; public static final int ID = 83; + private ByteArrayRange shapeData; + @Override public int getShapeNum() { return 4; @@ -54,6 +58,17 @@ public class DefineShape4Tag extends ShapeTag { @Override public SHAPEWITHSTYLE getShapes() { + if (shapes == null && shapeData != null) { + try { + SWFInputStream sis = new SWFInputStream(swf, shapeData.getArray(), 0, shapeData.getPos() + shapeData.getLength()); + sis.seek(shapeData.getPos()); + shapes = sis.readSHAPEWITHSTYLE(4, false, "shapes"); + shapeData = null; // not needed anymore, give it to GC + } catch (IOException ex) { + Logger.getLogger(DefineShape4Tag.class.getName()).log(Level.SEVERE, null, ex); + } + } + return shapes; } @@ -93,7 +108,7 @@ public class DefineShape4Tag extends ShapeTag { shapes = SHAPEWITHSTYLE.createEmpty(4); } - public DefineShape4Tag(SWFInputStream sis, ByteArrayRange data) throws IOException { + public DefineShape4Tag(SWFInputStream sis, ByteArrayRange data, boolean lazy) throws IOException { super(sis.getSwf(), ID, "DefineShape4", data); shapeId = sis.readUI16("shapeId"); shapeBounds = sis.readRECT("shapeBounds"); @@ -102,7 +117,11 @@ public class DefineShape4Tag extends ShapeTag { usesFillWindingRule = sis.readUB(1, "usesFillWindingRule") == 1; usesNonScalingStrokes = sis.readUB(1, "usesNonScalingStrokes") == 1; usesScalingStrokes = sis.readUB(1, "usesScalingStrokes") == 1; - shapes = sis.readSHAPEWITHSTYLE(4, false, "shapes"); + if (!lazy) { + shapes = sis.readSHAPEWITHSTYLE(4, false, "shapes"); + } else { + shapeData = new ByteArrayRange(data.getArray(), (int) sis.getPos(), sis.available()); + } } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java index 2b9a5fe09..9086c9935 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java @@ -29,6 +29,8 @@ import com.jpexs.helpers.ByteArrayRange; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; public class DefineShapeTag extends ShapeTag { @@ -37,6 +39,8 @@ public class DefineShapeTag extends ShapeTag { public RECT shapeBounds; public SHAPEWITHSTYLE shapes; public static final int ID = 2; + + private ByteArrayRange shapeData; @Override public int getShapeNum() { @@ -45,6 +49,17 @@ public class DefineShapeTag extends ShapeTag { @Override public SHAPEWITHSTYLE getShapes() { + if (shapes == null && shapeData != null) { + try { + SWFInputStream sis = new SWFInputStream(swf, shapeData.getArray(), 0, shapeData.getPos() + shapeData.getLength()); + sis.seek(shapeData.getPos()); + shapes = sis.readSHAPEWITHSTYLE(1, false, "shapes"); + shapeData = null; // not needed anymore, give it to GC + } catch (IOException ex) { + Logger.getLogger(DefineShapeTag.class.getName()).log(Level.SEVERE, null, ex); + } + } + return shapes; } @@ -78,11 +93,15 @@ public class DefineShapeTag extends ShapeTag { shapes = SHAPEWITHSTYLE.createEmpty(1); } - public DefineShapeTag(SWFInputStream sis, ByteArrayRange data) throws IOException { + public DefineShapeTag(SWFInputStream sis, ByteArrayRange data, boolean lazy) throws IOException { super(sis.getSwf(), ID, "DefineShape", data); shapeId = sis.readUI16("shapeId"); shapeBounds = sis.readRECT("shapeBounds"); - shapes = sis.readSHAPEWITHSTYLE(1, false, "shapes"); + if (!lazy) { + shapes = sis.readSHAPEWITHSTYLE(1, false, "shapes"); + } else { + shapeData = new ByteArrayRange(data.getArray(), (int) sis.getPos(), sis.available()); + } } /** diff --git a/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java index ed4340c9e..cf1ec40b4 100644 --- a/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java @@ -30,13 +30,11 @@ import com.jpexs.decompiler.flash.types.ColorTransform; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.helpers.Cache; import com.jpexs.helpers.SerializableImage; -import com.sun.javafx.scene.control.skin.VirtualFlow; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Image; import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -59,7 +57,7 @@ import javax.swing.JPanel; */ public class FolderPreviewPanel extends JPanel { - private static final ExecutorService executor; + private static ExecutorService executor; private List items; private int selectedIndex = -1; @@ -143,6 +141,8 @@ public class FolderPreviewPanel extends JPanel { public synchronized void setItems(List items) { this.items = items; + executor.shutdownNow(); + executor = Executors.newFixedThreadPool(Configuration.parallelSpeedUp.get() ? Configuration.parallelThreadCount.get() : 1); cachedPreviews.clear(); revalidate(); repaint(); diff --git a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java index c44c73bf5..28db1a99b 100644 --- a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java @@ -666,7 +666,7 @@ public class GenericTagTreePanel extends GenericTagPanel { SWFInputStream tagDataStream = new SWFInputStream(swf, data, 0, data.length); TagStub copy = new TagStub(swf, tag.getId(), "Unresolved", tag.getOriginalRange(), tagDataStream); copy.forceWriteAsLong = tag.forceWriteAsLong; - this.editedTag = SWFInputStream.resolveTag(copy, 0, false, true); + this.editedTag = SWFInputStream.resolveTag(copy, 0, false, true, false); } catch (InterruptedException ex) { } catch (IOException ex) { Logger.getLogger(GenericTagTreePanel.class.getName()).log(Level.SEVERE, null, ex); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 46c6801ed..f4ef5dd10 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -630,11 +630,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec showDetail(DETAILCARDEMPTYPANEL); showCard(CARDEMPTYPANEL); updateUi(swf); - - /*if (first && Configuration.gotoMainClassOnStartup.get()) { - gotoDocumentClass(swf); - }*/ - first = false; } } diff --git a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTreeModel.java b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTreeModel.java index ece7e4f7f..c1c762e1f 100644 --- a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTreeModel.java +++ b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTreeModel.java @@ -100,7 +100,7 @@ public class DumpTreeModel implements TreeModel { SWFInputStream sis = tagStub.getDataStream(); sis.seek(tagStub.getDataPos()); sis.dumpInfo = di; - SWFInputStream.resolveTag(tagStub, 0, false, true); + SWFInputStream.resolveTag(tagStub, 0, false, true, false); } catch (InterruptedException | IOException ex) { Logger.getLogger(DumpTreeModel.class.getName()).log(Level.SEVERE, null, ex); }