AS1/2: exporting selection

Flashplayer on/off constant
This commit is contained in:
Jindra Petk
2013-01-13 17:03:07 +01:00
parent 4c9e3231b3
commit 99a98e2d8f
7 changed files with 133 additions and 65 deletions

View File

@@ -77,6 +77,9 @@ public class Main {
return commandLineMode;
}
public static boolean DEBUG_COPY = false;
public static boolean FLASH_PLAYER = true;
/**
* Debug mode = throwing an error when comparing original file and recompiled
*/

View File

@@ -373,57 +373,14 @@ public class SWF {
if (!asV3Found) {
List<Object> list2 = new ArrayList<Object>();
list2.addAll(tags);
return exportNode(TagNode.createTagList(list2), outdir, isPcode);
List<TagNode> list=TagNode.createTagList(list2);
TagNode.setExport(list, true);
return TagNode.exportNode(list, outdir, isPcode);
}
return asV3Found;
}
private boolean exportNode(List<TagNode> nodeList, String outdir, boolean isPcode) {
File dir = new File(outdir);
if (!dir.exists()) {
dir.mkdirs();
}
List<String> existingNames = new ArrayList<String>();
for (TagNode node : nodeList) {
String name = "";
if (node.tag instanceof Tag) {
name = ((Tag) node.tag).getExportName();
}
int i = 1;
String baseName = name;
while (existingNames.contains(name)) {
i++;
name = baseName + "_" + i;
}
existingNames.add(name);
if (node.subItems.isEmpty()) {
if (node.tag instanceof ASMSource) {
try {
String f = outdir + File.separatorChar + name + ".as";
informListeners("export", "Exporting " + f + " ...");
String ret;
if (isPcode) {
ret = ((ASMSource) node.tag).getASMSource(SWF.DEFAULT_VERSION);
} else {
List<com.jpexs.asdec.action.Action> as = ((ASMSource) node.tag).getActions(SWF.DEFAULT_VERSION);
com.jpexs.asdec.action.Action.setActionsAddresses(as, 0, SWF.DEFAULT_VERSION);
ret = (Highlighting.stripHilights(com.jpexs.asdec.action.Action.actionsToSource(as, SWF.DEFAULT_VERSION)));
}
FileOutputStream fos = new FileOutputStream(f);
fos.write(ret.getBytes());
fos.close();
} catch (Exception ex) {
}
}
} else {
exportNode(node.subItems, outdir + File.separatorChar + name, isPcode);
}
}
return true;
}
protected HashSet<EventListener> listeners = new HashSet<EventListener>();
public void addEventListener(EventListener listener) {

View File

@@ -16,14 +16,20 @@
*/
package com.jpexs.asdec.action;
import com.jpexs.asdec.EventListener;
import com.jpexs.asdec.SWF;
import com.jpexs.asdec.helpers.Highlighting;
import com.jpexs.asdec.tags.DefineButton2Tag;
import com.jpexs.asdec.tags.DefineButtonTag;
import com.jpexs.asdec.tags.DefineSpriteTag;
import com.jpexs.asdec.tags.DoInitActionTag;
import com.jpexs.asdec.tags.ExportAssetsTag;
import com.jpexs.asdec.tags.ShowFrameTag;
import com.jpexs.asdec.tags.Tag;
import com.jpexs.asdec.tags.base.ASMSource;
import com.jpexs.asdec.tags.base.Container;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -31,6 +37,7 @@ public class TagNode {
public List<TagNode> subItems;
public Object tag;
public boolean export=false;
public TagNode(Object tag) {
this.tag = tag;
@@ -110,4 +117,65 @@ public class TagNode {
}
return ret;
}
public static void setExport(List<TagNode> nodeList,boolean export){
for(TagNode node:nodeList){
node.export=export;
setExport(node.subItems, export);
}
}
public static boolean exportNode(List<TagNode> nodeList, String outdir, boolean isPcode){
return exportNode(nodeList,outdir,isPcode,null);
}
public static boolean exportNode(List<TagNode> nodeList, String outdir, boolean isPcode, EventListener ev) {
File dir = new File(outdir);
List<String> existingNames = new ArrayList<String>();
for (TagNode node : nodeList) {
String name = "";
if (node.tag instanceof Tag) {
name = ((Tag) node.tag).getExportName();
}else{
name=node.tag.toString();
}
int i = 1;
String baseName = name;
while (existingNames.contains(name)) {
i++;
name = baseName + "_" + i;
}
existingNames.add(name);
if (node.subItems.isEmpty()) {
if ((node.tag instanceof ASMSource)&&(node.export)) {
if (!dir.exists()) {
dir.mkdirs();
}
try {
String f = outdir + File.separatorChar + name + ".as";
if(ev!=null){
ev.handleEvent("export", "Exporting " + f + " ...");
}
String ret;
if (isPcode) {
ret = ((ASMSource) node.tag).getASMSource(SWF.DEFAULT_VERSION);
} else {
List<com.jpexs.asdec.action.Action> as = ((ASMSource) node.tag).getActions(SWF.DEFAULT_VERSION);
com.jpexs.asdec.action.Action.setActionsAddresses(as, 0, SWF.DEFAULT_VERSION);
ret = (Highlighting.stripHilights(com.jpexs.asdec.action.Action.actionsToSource(as, SWF.DEFAULT_VERSION)));
}
FileOutputStream fos = new FileOutputStream(f);
fos.write(ret.getBytes());
fos.close();
} catch (Exception ex) {
}
}
} else {
exportNode(node.subItems, outdir + File.separatorChar + name, isPcode,ev);
}
}
return true;
}
}

View File

@@ -18,6 +18,7 @@ package com.jpexs.asdec.action.gui;
import com.jpexs.asdec.Main;
import com.jpexs.asdec.SWF;
import com.jpexs.asdec.abc.gui.TreeElement;
import com.jpexs.asdec.action.TagNode;
import com.jpexs.asdec.action.parser.ASMParser;
import com.jpexs.asdec.action.parser.ParseException;
@@ -30,12 +31,14 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreePath;
import jsyntaxpane.DefaultSyntaxKit;
public class ActionPanel extends JPanel implements TreeSelectionListener, ActionListener {
@@ -146,6 +149,19 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
splitPane2.setDividerLocation(0.5);
}
public List<TagNode> getSelectedNodes() {
List<TagNode> ret = new ArrayList<TagNode>();
TreePath tps[] = tagTree.getSelectionPaths();
if (tps == null) {
return ret;
}
for (TreePath tp : tps) {
TagNode te = (TagNode) tp.getLastPathComponent();
ret.add(te);
}
return ret;
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("SAVEACTION")) {
TagNode ti = (TagNode) tagTree.getLastSelectedPathComponent();

View File

@@ -34,7 +34,11 @@ public class TagTreeModel implements TreeModel {
list2.addAll(list);
this.list = TagNode.createTagList(list2);
}
public List<TagNode> getNodeList(){
return list;
}
public Object getRoot() {
return root;
}

View File

@@ -215,7 +215,7 @@ public class MainFrame extends JFrame implements ActionListener {
getActionScript3(objs, abcList);
getContentPane().add(tabPane, BorderLayout.CENTER);
if (!abcList.isEmpty()) {
tabPane.addTab("ActionScript3", abcPanel = new ABCPanel(abcList));
} else {
@@ -223,8 +223,9 @@ public class MainFrame extends JFrame implements ActionListener {
if (actionPanel.tagTree.getRowCount() > 1) {
tabPane.addTab("ActionScript", actionPanel);
}
menuDeobfuscation.setEnabled(false);
}
if (!shapes.isEmpty()) {
tabPane.addTab("Shapes", new TagPanel(shapes, swf));
}
@@ -249,7 +250,7 @@ public class MainFrame extends JFrame implements ActionListener {
/*tabPane.addTab("Tags", new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tagTree), new JScrollPane(fPanel)));*/
//tabPane.setTabPlacement(JTabbedPane.TOP);
loadingPanel.setPreferredSize(new Dimension(30, 30));
@@ -589,14 +590,26 @@ public class MainFrame extends JFrame implements ActionListener {
public void run() {
try {
if (onlySel) {
List<TreeLeafScript> tlsList = abcPanel.classTree.getSelectedScripts();
if (tlsList.isEmpty()) {
JOptionPane.showMessageDialog(null, "No script selected!");
}
for (int i = 0; i < tlsList.size(); i++) {
TreeLeafScript tls = tlsList.get(i);
Main.startWork("Exporting " + (i + 1) + "/" + tlsList.size() + " " + tls.abc.script_info[tls.scriptIndex].getPath(tls.abc) + " ...");
tls.abc.script_info[tls.scriptIndex].export(tls.abc, abcPanel.list, selFile, isPcode);
if (abcPanel != null) {
List<TreeLeafScript> tlsList = abcPanel.classTree.getSelectedScripts();
if (tlsList.isEmpty()) {
JOptionPane.showMessageDialog(null, "No script selected!");
}
for (int i = 0; i < tlsList.size(); i++) {
TreeLeafScript tls = tlsList.get(i);
Main.startWork("Exporting " + (i + 1) + "/" + tlsList.size() + " " + tls.abc.script_info[tls.scriptIndex].getPath(tls.abc) + " ...");
tls.abc.script_info[tls.scriptIndex].export(tls.abc, abcPanel.list, selFile, isPcode);
}
} else if(actionPanel!=null) {
List<com.jpexs.asdec.action.TagNode> nodes=actionPanel.getSelectedNodes();
if (nodes.isEmpty()) {
JOptionPane.showMessageDialog(null, "No nodes selected!");
}
com.jpexs.asdec.action.gui.TagTreeModel ttm=(com.jpexs.asdec.action.gui.TagTreeModel)actionPanel.tagTree.getModel();
List<com.jpexs.asdec.action.TagNode> allnodes=ttm.getNodeList();
com.jpexs.asdec.action.TagNode.setExport(allnodes, false);
com.jpexs.asdec.action.TagNode.setExport(nodes, true);
com.jpexs.asdec.action.TagNode.exportNode(allnodes, selFile, isPcode);
}
} else {
Main.swf.exportActionScript(selFile, isPcode);

View File

@@ -16,6 +16,7 @@
*/
package com.jpexs.asdec.gui;
import com.jpexs.asdec.Main;
import com.jpexs.asdec.SWF;
import com.jpexs.asdec.SWFOutputStream;
import com.jpexs.asdec.tags.DefineBitsJPEG2Tag;
@@ -98,9 +99,13 @@ public class TagPanel extends JPanel implements ListSelectionListener {
tagList.setPreferredSize(new Dimension(200, 1));
tagList.setSize(200, 1);
setLayout(new BorderLayout());
flashPanel = new FlashPanel();
if (Main.FLASH_PLAYER) {
flashPanel = new FlashPanel();
}
displayPanel = new JPanel(new CardLayout());
displayPanel.add(flashPanel, CARDFLASHPANEL);
if (Main.FLASH_PLAYER) {
displayPanel.add(flashPanel, CARDFLASHPANEL);
}
imagePanel = new ImagePanel();
CardLayout cl = (CardLayout) (displayPanel.getLayout());
cl.show(displayPanel, CARDEMPTYPANEL);
@@ -166,7 +171,7 @@ public class TagPanel extends JPanel implements ListSelectionListener {
if (tagObj instanceof AloneTag) {
sos2.writeTag(tagObj);
}else{
} else {
for (Tag tag : swf.tags) {
if ((!(tag instanceof PlaceObjectTag))
&& (!(tag instanceof PlaceObject2Tag))
@@ -202,7 +207,7 @@ public class TagPanel extends JPanel implements ListSelectionListener {
mat.translateY = -r.Ymin;
mat.translateX = mat.translateX + width / 2 - r.getWidth() / 2;
mat.translateY = mat.translateY + height / 2 - r.getHeight() / 2;
}else {
} else {
mat.translateX = width / 4;
mat.translateY = height / 4;
}
@@ -259,10 +264,12 @@ public class TagPanel extends JPanel implements ListSelectionListener {
sos.write(data);
fos.close();
showCard(CARDFLASHPANEL);
flashPanel.displaySWF(tempFile.getAbsolutePath());
if (Main.FLASH_PLAYER) {
flashPanel.displaySWF(tempFile.getAbsolutePath());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}