mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 00:10:59 +00:00
simplify TagTree nodes 11
This commit is contained in:
@@ -938,12 +938,11 @@ public final class SWF implements TreeItem, Timelined {
|
|||||||
list2.addAll(tags);
|
list2.addAll(tags);
|
||||||
List<TreeNode> list = createASTagList(list2, this);
|
List<TreeNode> list = createASTagList(list2, this);
|
||||||
|
|
||||||
TagNode.setExport(list, true);
|
|
||||||
if (!outdir.endsWith(File.separator)) {
|
if (!outdir.endsWith(File.separator)) {
|
||||||
outdir += File.separator;
|
outdir += File.separator;
|
||||||
}
|
}
|
||||||
outdir += "scripts" + File.separator;
|
outdir += "scripts" + File.separator;
|
||||||
ret.addAll(TagNode.exportNodeAS(handler, list, outdir, exportMode, evl));
|
ret.addAll(TagNode.exportNodeAS(handler, list, list, outdir, exportMode, evl));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1036,38 +1035,31 @@ public final class SWF implements TreeItem, Timelined {
|
|||||||
|
|
||||||
public static List<TreeNode> createASTagList(List<? extends ContainerItem> list, Timelined parent) {
|
public static List<TreeNode> createASTagList(List<? extends ContainerItem> list, Timelined parent) {
|
||||||
List<TreeNode> ret = new ArrayList<>();
|
List<TreeNode> ret = new ArrayList<>();
|
||||||
int frame = 1;
|
int frame = 0;
|
||||||
List<TreeNode> frames = new ArrayList<>();
|
List<TreeNode> frames = new ArrayList<>();
|
||||||
|
|
||||||
List<ExportAssetsTag> exportAssetsTags = new ArrayList<>();
|
|
||||||
for (ContainerItem t : list) {
|
for (ContainerItem t : list) {
|
||||||
if (t instanceof ExportAssetsTag) {
|
|
||||||
exportAssetsTags.add((ExportAssetsTag) t);
|
|
||||||
}
|
|
||||||
TreeNode addNode = null;
|
TreeNode addNode = null;
|
||||||
if (t instanceof ShowFrameTag) {
|
if (t instanceof ShowFrameTag) {
|
||||||
// do not add PlaceObjects (+etc) to script nodes
|
// do not add PlaceObjects (+etc) to script nodes
|
||||||
FrameNode tti = new FrameNode(new FrameNodeItem(t.getSwf(), frame, parent, false), null, true);
|
FrameNode tti = new FrameNode(new FrameNodeItem(t.getSwf(), frame, parent, false), null, true);
|
||||||
|
|
||||||
for (int r = ret.size() - 1; r >= 0; r--) {
|
for (int r = ret.size() - 1; r >= 0; r--) {
|
||||||
if (!(ret.get(r).getItem() instanceof DefineSpriteTag)) {
|
TreeNode node = ret.get(r);
|
||||||
if (!(ret.get(r).getItem() instanceof DefineButtonTag)) {
|
TreeItem item = node.getItem();
|
||||||
if (!(ret.get(r).getItem() instanceof DefineButton2Tag)) {
|
if (!(item instanceof DefineSpriteTag
|
||||||
if (!(ret.get(r).getItem() instanceof DoInitActionTag)) {
|
|| item instanceof DefineButtonTag
|
||||||
if (!(ret.get(r).getItem() instanceof AS2PackageNodeItem)) {
|
|| item instanceof DefineButton2Tag
|
||||||
tti.subNodes.add(ret.get(r));
|
|| item instanceof DoInitActionTag
|
||||||
ret.remove(r);
|
|| item instanceof AS2PackageNodeItem)) {
|
||||||
}
|
tti.subNodes.add(node);
|
||||||
}
|
ret.remove(r);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
frame++;
|
frame++;
|
||||||
frames.add(tti);
|
frames.add(tti);
|
||||||
} else if (t instanceof ASMSource) {
|
} else if (t instanceof ASMSource) {
|
||||||
ContainerNode tti = new ContainerNode(t);
|
ContainerNode tti = new ContainerNode(t);
|
||||||
//ret.add(tti);
|
|
||||||
addNode = tti;
|
addNode = tti;
|
||||||
} else if (t instanceof Container) {
|
} else if (t instanceof Container) {
|
||||||
if (((Container) t).getItemCount() > 0) {
|
if (((Container) t).getItemCount() > 0) {
|
||||||
@@ -1078,7 +1070,6 @@ public final class SWF implements TreeItem, Timelined {
|
|||||||
Timelined timelined = t instanceof Timelined ? (Timelined) t : null;
|
Timelined timelined = t instanceof Timelined ? (Timelined) t : null;
|
||||||
tti.subNodes = createASTagList(subItems, timelined);
|
tti.subNodes = createASTagList(subItems, timelined);
|
||||||
addNode = tti;
|
addNode = tti;
|
||||||
//ret.add(tti);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (addNode != null) {
|
if (addNode != null) {
|
||||||
@@ -1088,24 +1079,15 @@ public final class SWF implements TreeItem, Timelined {
|
|||||||
if (path == null) {
|
if (path == null) {
|
||||||
path = "";
|
path = "";
|
||||||
}
|
}
|
||||||
String[] pathParts;
|
String[] pathParts = path.contains(".") ? path.split("\\.") : new String[]{ path };
|
||||||
if (path.contains(".")) {
|
|
||||||
pathParts = path.split("\\.");
|
|
||||||
} else {
|
|
||||||
pathParts = new String[]{path};
|
|
||||||
}
|
|
||||||
List<TreeNode> items = ret;
|
List<TreeNode> items = ret;
|
||||||
int pos = 0;
|
for (int pos = 0; pos < pathParts.length - 1; pos++) {
|
||||||
TreeNode selNode = null;
|
String pathPart = pathParts[pos];
|
||||||
do {
|
TreeNode selNode = null;
|
||||||
if (pos == pathParts.length - 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
selNode = null;
|
|
||||||
for (TreeNode node : items) {
|
for (TreeNode node : items) {
|
||||||
if (node.getItem() instanceof AS2PackageNodeItem) {
|
if (node.getItem() instanceof AS2PackageNodeItem) {
|
||||||
AS2PackageNodeItem pkg = (AS2PackageNodeItem) node.getItem();
|
AS2PackageNodeItem pkg = (AS2PackageNodeItem) node.getItem();
|
||||||
if (pkg.packageName.equals(pathParts[pos])) {
|
if (pkg.packageName.equals(pathPart)) {
|
||||||
selNode = node;
|
selNode = node;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1114,8 +1096,8 @@ public final class SWF implements TreeItem, Timelined {
|
|||||||
int pkgCount = 0;
|
int pkgCount = 0;
|
||||||
for (; pkgCount < items.size(); pkgCount++) {
|
for (; pkgCount < items.size(); pkgCount++) {
|
||||||
if (items.get(pkgCount).getItem() instanceof AS3PackageNodeItem) {
|
if (items.get(pkgCount).getItem() instanceof AS3PackageNodeItem) {
|
||||||
AS2PackageNodeItem pkg = (AS2PackageNodeItem) items.get(pkgCount).getItem();
|
AS3PackageNodeItem pkg = (AS3PackageNodeItem) items.get(pkgCount).getItem();
|
||||||
if (pkg.packageName.compareTo(pathParts[pos]) > 0) {
|
if (pkg.packageName.compareTo(pathPart) > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1123,16 +1105,14 @@ public final class SWF implements TreeItem, Timelined {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (selNode == null) {
|
if (selNode == null) {
|
||||||
items.add(pkgCount, selNode = new AS2PackageNode(new AS2PackageNodeItem(pathParts[pos], t.getSwf())));
|
items.add(pkgCount, selNode = new AS2PackageNode(new AS2PackageNodeItem(pathPart, t.getSwf())));
|
||||||
}
|
}
|
||||||
pos++;
|
pos++;
|
||||||
if (selNode != null) {
|
items = selNode.subNodes;
|
||||||
items = selNode.subNodes;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} while (selNode != null);
|
|
||||||
|
|
||||||
int clsCount = 0;
|
int clsCount = 0;
|
||||||
|
String addNodeName = addNode.getItem().getClass().getName() + "_" + pathParts[pathParts.length - 1];
|
||||||
for (; clsCount < items.size(); clsCount++) {
|
for (; clsCount < items.size(); clsCount++) {
|
||||||
if (items.get(clsCount).getItem() instanceof CharacterIdTag) {
|
if (items.get(clsCount).getItem() instanceof CharacterIdTag) {
|
||||||
CharacterIdTag ct = (CharacterIdTag) items.get(clsCount).getItem();
|
CharacterIdTag ct = (CharacterIdTag) items.get(clsCount).getItem();
|
||||||
@@ -1143,7 +1123,7 @@ public final class SWF implements TreeItem, Timelined {
|
|||||||
if (expName.contains(".")) {
|
if (expName.contains(".")) {
|
||||||
expName = expName.substring(expName.lastIndexOf('.') + 1);
|
expName = expName.substring(expName.lastIndexOf('.') + 1);
|
||||||
}
|
}
|
||||||
if ((ct.getClass().getName() + "_" + expName).compareTo(addNode.getItem().getClass().getName() + "_" + pathParts[pos]) > 0) {
|
if ((ct.getClass().getName() + "_" + expName).compareTo(addNodeName) > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1157,25 +1137,15 @@ public final class SWF implements TreeItem, Timelined {
|
|||||||
}
|
}
|
||||||
ret.addAll(frames);
|
ret.addAll(frames);
|
||||||
for (int i = ret.size() - 1; i >= 0; i--) {
|
for (int i = ret.size() - 1; i >= 0; i--) {
|
||||||
if (ret.get(i).getItem() instanceof DefineSpriteTag) {
|
TreeNode node = ret.get(i);
|
||||||
((DefineSpriteTag) ret.get(i).getItem()).exportAssetsTags = exportAssetsTags;
|
TreeItem item = node.getItem();
|
||||||
}
|
if (item instanceof ASMSource) {
|
||||||
if (ret.get(i).getItem() instanceof DefineButtonTag) {
|
ASMSource ass = (ASMSource) item;
|
||||||
((DefineButtonTag) ret.get(i).getItem()).exportAssetsTags = exportAssetsTags;
|
|
||||||
}
|
|
||||||
if (ret.get(i).getItem() instanceof DefineButton2Tag) {
|
|
||||||
((DefineButton2Tag) ret.get(i).getItem()).exportAssetsTags = exportAssetsTags;
|
|
||||||
}
|
|
||||||
/*if (ret.get(i).tag instanceof DoInitActionTag) {
|
|
||||||
//((DoInitActionTag) ret.get(i).tag).exportAssetsTags = exportAssetsTags;
|
|
||||||
}*/
|
|
||||||
if (ret.get(i).getItem() instanceof ASMSource) {
|
|
||||||
ASMSource ass = (ASMSource) ret.get(i).getItem();
|
|
||||||
if (ass.containsSource()) {
|
if (ass.containsSource()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret.get(i).subNodes.isEmpty()) {
|
if (node.subNodes.isEmpty()) {
|
||||||
ret.remove(i);
|
ret.remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,6 +205,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource {
|
|||||||
return pathParts[pathParts.length - 1];
|
return pathParts[pathParts.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GraphTextWriter getActionSourcePrefix(GraphTextWriter writer) {
|
public GraphTextWriter getActionSourcePrefix(GraphTextWriter writer) {
|
||||||
return writer;
|
return writer;
|
||||||
|
|||||||
@@ -12,16 +12,13 @@
|
|||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library.␍ */
|
* License along with this library.
|
||||||
|
*/
|
||||||
package com.jpexs.decompiler.flash.tags.base;
|
package com.jpexs.decompiler.flash.tags.base;
|
||||||
|
|
||||||
import com.jpexs.decompiler.flash.SWF;
|
import com.jpexs.decompiler.flash.SWF;
|
||||||
import com.jpexs.decompiler.flash.tags.ExportAssetsTag;
|
|
||||||
import com.jpexs.decompiler.flash.tags.Tag;
|
import com.jpexs.decompiler.flash.tags.Tag;
|
||||||
import com.jpexs.decompiler.flash.types.annotations.Internal;
|
|
||||||
import com.jpexs.helpers.ByteArrayRange;
|
import com.jpexs.helpers.ByteArrayRange;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -34,11 +31,7 @@ public abstract class CharacterIdTag extends Tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract int getCharacterId();
|
public abstract int getCharacterId();
|
||||||
/**
|
|
||||||
* List of ExportAssetsTag used for converting to String
|
|
||||||
*/
|
|
||||||
@Internal
|
|
||||||
public List<ExportAssetsTag> exportAssetsTags = new ArrayList<>();
|
|
||||||
protected String exportName;
|
protected String exportName;
|
||||||
|
|
||||||
public void setExportName(String exportName) {
|
public void setExportName(String exportName) {
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library.␍ */
|
* License along with this library.
|
||||||
|
*/
|
||||||
package com.jpexs.decompiler.flash.treeitems;
|
package com.jpexs.decompiler.flash.treeitems;
|
||||||
|
|
||||||
import com.jpexs.decompiler.flash.SWF;
|
import com.jpexs.decompiler.flash.SWF;
|
||||||
@@ -48,7 +49,7 @@ public class FrameNodeItem implements TreeItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "frame " + frame;
|
return "frame " + (frame + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFrame() {
|
public int getFrame() {
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library.␍ */
|
* License along with this library.
|
||||||
|
*/
|
||||||
package com.jpexs.decompiler.flash.treenodes;
|
package com.jpexs.decompiler.flash.treenodes;
|
||||||
|
|
||||||
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
|
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
|
||||||
@@ -51,39 +52,30 @@ public class TagNode extends ContainerNode {
|
|||||||
return (Tag) item;
|
return (Tag) item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setExport(List<TreeNode> nodeList, boolean export) {
|
|
||||||
for (TreeNode node : nodeList) {
|
|
||||||
node.export = export;
|
|
||||||
setExport(node.subNodes, export);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getTagCountRecursive(List<TreeNode> nodeList) {
|
public static int getTagCountRecursive(List<TreeNode> nodeList) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
for (TreeNode node : nodeList) {
|
for (TreeNode node : nodeList) {
|
||||||
if (node.subNodes.isEmpty()) {
|
if (node.item instanceof ASMSource) {
|
||||||
if ((node.item instanceof ASMSource) && (node.export)) {
|
count += 1;
|
||||||
count += 1;
|
}
|
||||||
}
|
if (!node.subNodes.isEmpty()) {
|
||||||
} else {
|
|
||||||
count += getTagCountRecursive(node.subNodes);
|
count += getTagCountRecursive(node.subNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> exportNodeAS(final AbortRetryIgnoreHandler handler, final List<TreeNode> nodeList, final String outdir, final ScriptExportMode exportMode, final EventListener ev) throws IOException {
|
public static List<File> exportNodeAS(final AbortRetryIgnoreHandler handler, final List<TreeNode> nodesList, final List<TreeNode> nodesToExport, final String outdir, final ScriptExportMode exportMode, final EventListener ev) throws IOException {
|
||||||
try {
|
try {
|
||||||
List<File> result = CancellableWorker.call(new Callable<List<File>>() {
|
List<File> result = CancellableWorker.call(new Callable<List<File>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<File> call() throws Exception {
|
public List<File> call() throws Exception {
|
||||||
AtomicInteger cnt = new AtomicInteger(1);
|
AtomicInteger cnt = new AtomicInteger(1);
|
||||||
int totalCount = TagNode.getTagCountRecursive(nodeList);
|
int totalCount = TagNode.getTagCountRecursive(nodesToExport);
|
||||||
return exportNodeAS(handler, nodeList, outdir, exportMode, cnt, totalCount, ev);
|
return exportNodeAS(handler, nodesList, nodesToExport, false, outdir, exportMode, cnt, totalCount, ev);
|
||||||
}
|
}
|
||||||
}, Configuration.exportTimeout.get(), TimeUnit.SECONDS);
|
}, Configuration.exportTimeout.get(), TimeUnit.SECONDS);
|
||||||
return result;
|
return result;
|
||||||
@@ -92,14 +84,14 @@ public class TagNode extends ContainerNode {
|
|||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<File> exportNodeAS(AbortRetryIgnoreHandler handler, List<TreeNode> nodeList, String outdir, ScriptExportMode exportMode, AtomicInteger index, int count, EventListener ev) throws IOException {
|
private static List<File> exportNodeAS(AbortRetryIgnoreHandler handler, List<TreeNode> nodesList, List<TreeNode> nodesToExport, boolean exportAll, String outdir, ScriptExportMode exportMode, AtomicInteger index, int count, EventListener ev) throws IOException {
|
||||||
File dir = new File(outdir);
|
File dir = new File(outdir);
|
||||||
List<File> ret = new ArrayList<>();
|
List<File> ret = new ArrayList<>();
|
||||||
if (!outdir.endsWith(File.separator)) {
|
if (!outdir.endsWith(File.separator)) {
|
||||||
outdir += File.separator;
|
outdir += File.separator;
|
||||||
}
|
}
|
||||||
List<String> existingNames = new ArrayList<>();
|
List<String> existingNames = new ArrayList<>();
|
||||||
for (TreeNode node : nodeList) {
|
for (TreeNode node : nodesList) {
|
||||||
String name = "";
|
String name = "";
|
||||||
if (node.item instanceof Exportable) {
|
if (node.item instanceof Exportable) {
|
||||||
name = Helper.makeFileName(((Exportable) node.item).getExportFileName());
|
name = Helper.makeFileName(((Exportable) node.item).getExportFileName());
|
||||||
@@ -113,76 +105,76 @@ public class TagNode extends ContainerNode {
|
|||||||
name = baseName + "_" + i;
|
name = baseName + "_" + i;
|
||||||
}
|
}
|
||||||
existingNames.add(name);
|
existingNames.add(name);
|
||||||
if (node.subNodes.isEmpty()) {
|
boolean exportNode = nodesToExport.contains(node);
|
||||||
if ((node.item instanceof ASMSource) && (node.export)) {
|
if (node.item instanceof ASMSource && (exportAll || exportNode)) {
|
||||||
boolean retry;
|
boolean retry;
|
||||||
do {
|
do {
|
||||||
retry = false;
|
retry = false;
|
||||||
try {
|
try {
|
||||||
int currentIndex = index.getAndIncrement();
|
int currentIndex = index.getAndIncrement();
|
||||||
|
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
if (!dir.mkdirs()) {
|
if (!dir.mkdirs()) {
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
throw new IOException("Cannot create directory " + outdir);
|
throw new IOException("Cannot create directory " + outdir);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String f = outdir + name + ".as";
|
|
||||||
if (ev != null) {
|
|
||||||
ev.handleEvent("exporting", "Exporting " + currentIndex + "/" + count + " " + f);
|
|
||||||
}
|
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
File file = new File(f);
|
|
||||||
ASMSource asm = ((ASMSource) node.item);
|
|
||||||
try (FileTextWriter writer = new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(f))) {
|
|
||||||
if (exportMode == ScriptExportMode.HEX) {
|
|
||||||
asm.getActionSourcePrefix(writer);
|
|
||||||
asm.getActionBytesAsHex(writer);
|
|
||||||
asm.getActionSourceSuffix(writer);
|
|
||||||
} else if (exportMode != ScriptExportMode.AS) {
|
|
||||||
asm.getActionSourcePrefix(writer);
|
|
||||||
asm.getASMSource(exportMode, writer, null);
|
|
||||||
asm.getActionSourceSuffix(writer);
|
|
||||||
} else {
|
|
||||||
List<Action> as = asm.getActions();
|
|
||||||
Action.setActionsAddresses(as, 0);
|
|
||||||
Action.actionsToSource(asm, as, ""/*FIXME*/, writer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long stopTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
if (ev != null) {
|
|
||||||
long time = stopTime - startTime;
|
|
||||||
ev.handleEvent("exported", "Exported " + currentIndex + "/" + count + " " + f + ", " + Helper.formatTimeSec(time));
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.add(file);
|
|
||||||
} catch (InterruptedException ex) {
|
|
||||||
} catch (IOException | OutOfMemoryError | TranslateException | StackOverflowError ex) {
|
|
||||||
Logger.getLogger(TagNode.class.getName()).log(Level.SEVERE, "Decompilation error in file: " + name + ".as", ex);
|
|
||||||
if (handler != null) {
|
|
||||||
int action = handler.getNewInstance().handle(ex);
|
|
||||||
switch (action) {
|
|
||||||
case AbortRetryIgnoreHandler.ABORT:
|
|
||||||
throw ex;
|
|
||||||
case AbortRetryIgnoreHandler.RETRY:
|
|
||||||
retry = true;
|
|
||||||
break;
|
|
||||||
case AbortRetryIgnoreHandler.IGNORE:
|
|
||||||
retry = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (retry);
|
|
||||||
}
|
String f = outdir + name + ".as";
|
||||||
} else {
|
if (ev != null) {
|
||||||
ret.addAll(exportNodeAS(handler, node.subNodes, outdir + name, exportMode, index, count, ev));
|
ev.handleEvent("exporting", "Exporting " + currentIndex + "/" + count + " " + f);
|
||||||
|
}
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
File file = new File(f);
|
||||||
|
ASMSource asm = ((ASMSource) node.item);
|
||||||
|
try (FileTextWriter writer = new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(f))) {
|
||||||
|
if (exportMode == ScriptExportMode.HEX) {
|
||||||
|
asm.getActionSourcePrefix(writer);
|
||||||
|
asm.getActionBytesAsHex(writer);
|
||||||
|
asm.getActionSourceSuffix(writer);
|
||||||
|
} else if (exportMode != ScriptExportMode.AS) {
|
||||||
|
asm.getActionSourcePrefix(writer);
|
||||||
|
asm.getASMSource(exportMode, writer, null);
|
||||||
|
asm.getActionSourceSuffix(writer);
|
||||||
|
} else {
|
||||||
|
List<Action> as = asm.getActions();
|
||||||
|
Action.setActionsAddresses(as, 0);
|
||||||
|
Action.actionsToSource(asm, as, ""/*FIXME*/, writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long stopTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (ev != null) {
|
||||||
|
long time = stopTime - startTime;
|
||||||
|
ev.handleEvent("exported", "Exported " + currentIndex + "/" + count + " " + f + ", " + Helper.formatTimeSec(time));
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.add(file);
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
} catch (IOException | OutOfMemoryError | TranslateException | StackOverflowError ex) {
|
||||||
|
Logger.getLogger(TagNode.class.getName()).log(Level.SEVERE, "Decompilation error in file: " + name + ".as", ex);
|
||||||
|
if (handler != null) {
|
||||||
|
int action = handler.getNewInstance().handle(ex);
|
||||||
|
switch (action) {
|
||||||
|
case AbortRetryIgnoreHandler.ABORT:
|
||||||
|
throw ex;
|
||||||
|
case AbortRetryIgnoreHandler.RETRY:
|
||||||
|
retry = true;
|
||||||
|
break;
|
||||||
|
case AbortRetryIgnoreHandler.IGNORE:
|
||||||
|
retry = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (retry);
|
||||||
|
}
|
||||||
|
if (!node.subNodes.isEmpty()) {
|
||||||
|
ret.addAll(exportNodeAS(handler, node.subNodes, nodesToExport, exportAll || exportNode, outdir + name, exportMode, index, count, ev));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library.␍ */
|
* License along with this library.
|
||||||
|
*/
|
||||||
package com.jpexs.decompiler.flash.treenodes;
|
package com.jpexs.decompiler.flash.treenodes;
|
||||||
|
|
||||||
import com.jpexs.decompiler.flash.treeitems.TreeItem;
|
import com.jpexs.decompiler.flash.treeitems.TreeItem;
|
||||||
@@ -28,7 +29,6 @@ import java.util.logging.Logger;
|
|||||||
public abstract class TreeNode {
|
public abstract class TreeNode {
|
||||||
|
|
||||||
protected TreeItem item;
|
protected TreeItem item;
|
||||||
public boolean export = false;
|
|
||||||
public List<TreeNode> subNodes;
|
public List<TreeNode> subNodes;
|
||||||
|
|
||||||
public TreeNode(TreeItem item) {
|
public TreeNode(TreeItem item) {
|
||||||
@@ -51,13 +51,4 @@ public abstract class TreeNode {
|
|||||||
}
|
}
|
||||||
return item.toString();
|
return item.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TreeNode> getAllSubs() {
|
|
||||||
List<TreeNode> ret = new ArrayList<>();
|
|
||||||
ret.addAll(subNodes);
|
|
||||||
for (TreeNode n : subNodes) {
|
|
||||||
ret.addAll(n.getAllSubs());
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1060,7 +1060,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
|
|||||||
|
|
||||||
FrameNodeItem fni = (FrameNodeItem) d.getItem();
|
FrameNodeItem fni = (FrameNodeItem) d.getItem();
|
||||||
Timelined parent = fni.getParent();
|
Timelined parent = fni.getParent();
|
||||||
int frame = fni.getFrame() - 1; //Fix to zero based
|
int frame = fni.getFrame();
|
||||||
int parentId = 0;
|
int parentId = 0;
|
||||||
if (parent instanceof CharacterTag) {
|
if (parent instanceof CharacterTag) {
|
||||||
parentId = ((CharacterTag) parent).getCharacterId();
|
parentId = ((CharacterTag) parent).getCharacterId();
|
||||||
@@ -1109,25 +1109,17 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
|
|||||||
new FramesExportSettings(export.getValue(FramesExportMode.class), export.getZoom())));
|
new FramesExportSettings(export.getValue(FramesExportMode.class), export.getZoom())));
|
||||||
}
|
}
|
||||||
List<ABCContainerTag> abcList = swf.abcList;
|
List<ABCContainerTag> abcList = swf.abcList;
|
||||||
if (abcPanel != null) {
|
if (swf.isAS3) {
|
||||||
for (int i = 0; i < as3scripts.size(); i++) {
|
for (int i = 0; i < as3scripts.size(); i++) {
|
||||||
ScriptPack tls = as3scripts.get(i);
|
ScriptPack tls = as3scripts.get(i);
|
||||||
Main.startWork(translate("work.exporting") + " " + (i + 1) + "/" + as3scripts.size() + " " + tls.getPath() + " ...");
|
Main.startWork(translate("work.exporting") + " " + (i + 1) + "/" + as3scripts.size() + " " + tls.getPath() + " ...");
|
||||||
ret.add(tls.export(selFile, abcList, scriptMode, Configuration.parallelSpeedUp.get()));
|
ret.add(tls.export(selFile, abcList, scriptMode, Configuration.parallelSpeedUp.get()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<TreeNode> allNodes = new ArrayList<>();
|
TagTreeModel ttm = (TagTreeModel) tagTree.getModel();
|
||||||
List<TreeNode> allAs12Scripts = new ArrayList<>();
|
List<TreeNode> scriptNodeList = new ArrayList<>(1);
|
||||||
|
scriptNodeList.add(ttm.getSwfNode(swf).scriptsNode);
|
||||||
if (abcPanel == null) {
|
ret.addAll(TagNode.exportNodeAS(handler, scriptNodeList, as12scripts, selFile, scriptMode, null));
|
||||||
allAs12Scripts = getASTreeNodes(tagTree);
|
|
||||||
}
|
|
||||||
for (TreeNode asn : allAs12Scripts) {
|
|
||||||
allNodes.add(asn);
|
|
||||||
TagNode.setExport(allNodes, false);
|
|
||||||
TagNode.setExport(as12scripts, true);
|
|
||||||
ret.addAll(TagNode.exportNodeAS(handler, allNodes, selFile, scriptMode, null));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@@ -2417,7 +2409,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
|
|||||||
totalFrameCount = parentSprite.frameCount;
|
totalFrameCount = parentSprite.frameCount;
|
||||||
timelined = parentSprite;
|
timelined = parentSprite;
|
||||||
}
|
}
|
||||||
previewPanel.showImagePanel(timelined, swf, fn.getFrame() - 1);
|
previewPanel.showImagePanel(timelined, swf, fn.getFrame());
|
||||||
} else if ((tagObj instanceof SoundTag)) { //&& isInternalFlashViewerSelected() && (Arrays.asList("mp3", "wav").contains(((SoundTag) tagObj).getExportFormat())))) {
|
} else if ((tagObj instanceof SoundTag)) { //&& isInternalFlashViewerSelected() && (Arrays.asList("mp3", "wav").contains(((SoundTag) tagObj).getExportFormat())))) {
|
||||||
showCard(CARDPREVIEWPANEL);
|
showCard(CARDPREVIEWPANEL);
|
||||||
previewPanel.showImagePanel(new SerializableImage(View.loadImage("sound32")));
|
previewPanel.showImagePanel(new SerializableImage(View.loadImage("sound32")));
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ public class PreviewImage extends JPanel {
|
|||||||
if (treeItem instanceof FrameNodeItem) {
|
if (treeItem instanceof FrameNodeItem) {
|
||||||
FrameNodeItem fn = (FrameNodeItem) treeItem;
|
FrameNodeItem fn = (FrameNodeItem) treeItem;
|
||||||
RECT rect = swf.displayRect;
|
RECT rect = swf.displayRect;
|
||||||
imgSrc = SWF.frameToImageGet(swf.getTimeline(), fn.getFrame() - 1, 0, null, 0, rect, new Matrix(), new ColorTransform(), null, true, 1.0);
|
imgSrc = SWF.frameToImageGet(swf.getTimeline(), fn.getFrame(), 0, null, 0, rect, new Matrix(), new ColorTransform(), null, true, 1.0);
|
||||||
width = (imgSrc.getWidth());
|
width = (imgSrc.getWidth());
|
||||||
height = (imgSrc.getHeight());
|
height = (imgSrc.getHeight());
|
||||||
} else if (treeItem instanceof ImageTag) {
|
} else if (treeItem instanceof ImageTag) {
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
|
|||||||
Timelined parent = fn.getParent();
|
Timelined parent = fn.getParent();
|
||||||
List<Tag> subs = parent.getTimeline().tags;
|
List<Tag> subs = parent.getTimeline().tags;
|
||||||
List<Integer> doneCharacters = new ArrayList<>();
|
List<Integer> doneCharacters = new ArrayList<>();
|
||||||
int frameCnt = 1;
|
int frameCnt = 0;
|
||||||
for (ContainerItem item : subs) {
|
for (ContainerItem item : subs) {
|
||||||
if (item instanceof ShowFrameTag) {
|
if (item instanceof ShowFrameTag) {
|
||||||
frameCnt++;
|
frameCnt++;
|
||||||
|
|||||||
@@ -499,7 +499,7 @@ public class TagTree extends JTree implements ActionListener {
|
|||||||
tagsToRemove.add((Tag) tag);
|
tagsToRemove.add((Tag) tag);
|
||||||
} else if (tag instanceof FrameNodeItem) {
|
} else if (tag instanceof FrameNodeItem) {
|
||||||
FrameNodeItem frameNode = (FrameNodeItem) tag;
|
FrameNodeItem frameNode = (FrameNodeItem) tag;
|
||||||
Frame frame = frameNode.getParent().getTimeline().frames.get(frameNode.getFrame() - 1);
|
Frame frame = frameNode.getParent().getTimeline().frames.get(frameNode.getFrame());
|
||||||
if (frame.showFrameTag != null) {
|
if (frame.showFrameTag != null) {
|
||||||
tagsToRemove.add(frame.showFrameTag);
|
tagsToRemove.add(frame.showFrameTag);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -89,9 +89,7 @@ public class TagTreeModel implements TreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SWFNode createSwfNode(SWF swf) {
|
public SWFNode createSwfNode(SWF swf) {
|
||||||
ClassesListTreeModel classTreeModel = new ClassesListTreeModel(swf);
|
SWFNode swfNode = createTagList(swf.tags, swf);
|
||||||
SWFNode swfNode = new SWFNode(swf, swf.getShortFileName());
|
|
||||||
swfNode.list = createTagList(swf.tags, swf, swfNode, classTreeModel);
|
|
||||||
swfToSwfNode.put(swf, swfNode);
|
swfToSwfNode.put(swf, swfNode);
|
||||||
return swfNode;
|
return swfNode;
|
||||||
}
|
}
|
||||||
@@ -110,10 +108,13 @@ public class TagTreeModel implements TreeModel {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TreeNode> createTagList(List<Tag> list, SWF swf, SWFNode swfNode, ClassesListTreeModel classTreeModel) {
|
private SWFNode createTagList(List<Tag> list, SWF swf) {
|
||||||
|
ClassesListTreeModel classTreeModel = new ClassesListTreeModel(swf);
|
||||||
|
SWFNode swfNode = new SWFNode(swf, swf.getShortFileName());
|
||||||
|
|
||||||
boolean hasAbc = swf.abcList != null && !swf.abcList.isEmpty();
|
boolean hasAbc = swf.abcList != null && !swf.abcList.isEmpty();
|
||||||
|
|
||||||
List<TreeNode> ret = new ArrayList<>();
|
List<TreeNode> nodeList = new ArrayList<>();
|
||||||
List<TreeNode> frames = new ArrayList<>();
|
List<TreeNode> frames = new ArrayList<>();
|
||||||
List<TreeNode> shapes = new ArrayList<>();
|
List<TreeNode> shapes = new ArrayList<>();
|
||||||
List<TreeNode> morphShapes = new ArrayList<>();
|
List<TreeNode> morphShapes = new ArrayList<>();
|
||||||
@@ -176,7 +177,7 @@ public class TagTreeModel implements TreeModel {
|
|||||||
|
|
||||||
Timeline timeline = swf.getTimeline();
|
Timeline timeline = swf.getTimeline();
|
||||||
for (int i = 0; i < timeline.getFrameCount(); i++) {
|
for (int i = 0; i < timeline.getFrameCount(); i++) {
|
||||||
frames.add(new FrameNode(new FrameNodeItem(swf, i + 1, swf, true), timeline.frames.get(i).innerTags, false));
|
frames.add(new FrameNode(new FrameNodeItem(swf, i, swf, true), timeline.frames.get(i).innerTags, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < sounds.size(); i++) {
|
for (int i = 0; i < sounds.size(); i++) {
|
||||||
@@ -239,50 +240,51 @@ public class TagTreeModel implements TreeModel {
|
|||||||
}
|
}
|
||||||
swfNode.scriptsNode = actionScriptNode;
|
swfNode.scriptsNode = actionScriptNode;
|
||||||
|
|
||||||
ret.add(new HeaderNode(new HeaderItem(swf, AppStrings.translate("node.header"))));
|
nodeList.add(new HeaderNode(new HeaderItem(swf, AppStrings.translate("node.header"))));
|
||||||
|
|
||||||
if (!shapesNode.subNodes.isEmpty()) {
|
if (!shapesNode.subNodes.isEmpty()) {
|
||||||
ret.add(shapesNode);
|
nodeList.add(shapesNode);
|
||||||
}
|
}
|
||||||
if (!morphShapesNode.subNodes.isEmpty()) {
|
if (!morphShapesNode.subNodes.isEmpty()) {
|
||||||
ret.add(morphShapesNode);
|
nodeList.add(morphShapesNode);
|
||||||
}
|
}
|
||||||
if (!spritesNode.subNodes.isEmpty()) {
|
if (!spritesNode.subNodes.isEmpty()) {
|
||||||
ret.add(spritesNode);
|
nodeList.add(spritesNode);
|
||||||
}
|
}
|
||||||
if (!textsNode.subNodes.isEmpty()) {
|
if (!textsNode.subNodes.isEmpty()) {
|
||||||
ret.add(textsNode);
|
nodeList.add(textsNode);
|
||||||
}
|
}
|
||||||
if (!imagesNode.subNodes.isEmpty()) {
|
if (!imagesNode.subNodes.isEmpty()) {
|
||||||
ret.add(imagesNode);
|
nodeList.add(imagesNode);
|
||||||
}
|
}
|
||||||
if (!moviesNode.subNodes.isEmpty()) {
|
if (!moviesNode.subNodes.isEmpty()) {
|
||||||
ret.add(moviesNode);
|
nodeList.add(moviesNode);
|
||||||
}
|
}
|
||||||
if (!soundsNode.subNodes.isEmpty()) {
|
if (!soundsNode.subNodes.isEmpty()) {
|
||||||
ret.add(soundsNode);
|
nodeList.add(soundsNode);
|
||||||
}
|
}
|
||||||
if (!buttonsNode.subNodes.isEmpty()) {
|
if (!buttonsNode.subNodes.isEmpty()) {
|
||||||
ret.add(buttonsNode);
|
nodeList.add(buttonsNode);
|
||||||
}
|
}
|
||||||
if (!fontsNode.subNodes.isEmpty()) {
|
if (!fontsNode.subNodes.isEmpty()) {
|
||||||
ret.add(fontsNode);
|
nodeList.add(fontsNode);
|
||||||
}
|
}
|
||||||
if (!binaryDataNode.subNodes.isEmpty()) {
|
if (!binaryDataNode.subNodes.isEmpty()) {
|
||||||
ret.add(binaryDataNode);
|
nodeList.add(binaryDataNode);
|
||||||
}
|
}
|
||||||
if (!framesNode.subNodes.isEmpty()) {
|
if (!framesNode.subNodes.isEmpty()) {
|
||||||
ret.add(framesNode);
|
nodeList.add(framesNode);
|
||||||
}
|
}
|
||||||
if (!otherNode.subNodes.isEmpty()) {
|
if (!otherNode.subNodes.isEmpty()) {
|
||||||
ret.add(otherNode);
|
nodeList.add(otherNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!actionScriptNode.subNodes.isEmpty()) || hasAbc) {
|
if ((!actionScriptNode.subNodes.isEmpty()) || hasAbc) {
|
||||||
ret.add(actionScriptNode);
|
nodeList.add(actionScriptNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
swfNode.list = nodeList;
|
||||||
|
return swfNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TreeNode> createSubTagList(List<Tag> list, Timelined parent, SWF swf, List<Tag> actionScriptTags) {
|
private List<TreeNode> createSubTagList(List<Tag> list, Timelined parent, SWF swf, List<Tag> actionScriptTags) {
|
||||||
@@ -305,7 +307,7 @@ public class TagTreeModel implements TreeModel {
|
|||||||
|
|
||||||
Timeline timeline = ((Timelined) parent).getTimeline();
|
Timeline timeline = ((Timelined) parent).getTimeline();
|
||||||
for (int i = 0; i < timeline.getFrameCount(); i++) {
|
for (int i = 0; i < timeline.getFrameCount(); i++) {
|
||||||
frames.add(new FrameNode(new FrameNodeItem(swf, i + 1, parent, true), timeline.frames.get(i).innerTags, false));
|
frames.add(new FrameNode(new FrameNodeItem(swf, i, parent, true), timeline.frames.get(i).innerTags, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.addAll(frames);
|
ret.addAll(frames);
|
||||||
|
|||||||
Reference in New Issue
Block a user