From 6acbc093bf352ff4f0b893e7b87c42b0fb0b2204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 19 May 2013 07:26:27 +0200 Subject: [PATCH] FLA export from menu --- .../jpexs/decompiler/flash/gui/MainFrame.java | 65 ++++++++++++++++++- .../decompiler/flash/xfl/XFLConverter.java | 19 +++++- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index bccc87f34..350e0d149 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -261,7 +261,13 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi miSaveAs.setIcon(View.getIcon("saveas16")); miSaveAs.setActionCommand("SAVEAS"); miSaveAs.addActionListener(this); - JMenuItem menuExportAll = new JMenuItem("Export all"); + + JMenuItem menuExportFla = new JMenuItem("Export to FLA"); + menuExportFla.setActionCommand("EXPORTFLA"); + menuExportFla.addActionListener(this); + menuExportFla.setIcon(View.getIcon("flash16")); + + JMenuItem menuExportAll = new JMenuItem("Export all parts"); menuExportAll.setActionCommand("EXPORT"); menuExportAll.addActionListener(this); JMenuItem menuExportSel = new JMenuItem("Export selection"); @@ -275,6 +281,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi menuFile.add(miOpen); menuFile.add(miSave); menuFile.add(miSaveAs); + menuFile.add(menuExportFla); menuFile.add(menuExportAll); menuFile.add(menuExportSel); menuFile.addSeparator(); @@ -1276,8 +1283,62 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi Main.openFileDialog(); } + if (e.getActionCommand().equals("EXPORTFLA")) { + JFileChooser fc = new JFileChooser(); + String selDir = (String) Configuration.getConfig("lastOpenDir", "."); + fc.setCurrentDirectory(new File(selDir)); + if (!selDir.endsWith(File.separator)) { + selDir += File.separator; + } + String fileName = (new File(Main.file).getName()); + fileName = fileName.substring(0, fileName.length() - 4) + ".fla"; + fc.setSelectedFile(new File(selDir + fileName)); + FileFilter fla = new FileFilter() { + @Override + public boolean accept(File f) { + return f.isDirectory() || (f.getName().toLowerCase().endsWith(".fla")); + } - if (e.getActionCommand().startsWith("EXPORT")) { + @Override + public String getDescription() { + return "Flash CS 6 Document (*.fla)"; + } + }; + FileFilter xfl = new FileFilter() { + @Override + public boolean accept(File f) { + return f.isDirectory() || (f.getName().toLowerCase().endsWith(".xfl")); + } + + @Override + public String getDescription() { + return "Flash CS 6 Uncompressed Document (*.xfl)"; + } + }; + fc.setFileFilter(fla); + fc.addChoosableFileFilter(xfl); + fc.setAcceptAllFileFilterUsed(false); + JFrame f = new JFrame(); + View.setWindowIcon(f); + int returnVal = fc.showSaveDialog(f); + if (returnVal == JFileChooser.APPROVE_OPTION) { + Configuration.setConfig("lastOpenDir", Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath()); + final File selfile = Helper.fixDialogFile(fc.getSelectedFile()); + Main.startWork("Exporting FLA..."); + final boolean compressed = fc.getFileFilter() == fla; + (new Thread() { + @Override + public void run() { + if (compressed) { + swf.exportFla(selfile.getAbsolutePath(), new File(Main.file).getName()); + } else { + swf.exportXfl(selfile.getAbsolutePath(), new File(Main.file).getName()); + } + Main.stopWork(); + } + }).start(); + } + } else if (e.getActionCommand().startsWith("EXPORT")) { final ExportDialog export = new ExportDialog(); export.setVisible(true); if (!export.cancelled) { diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index a432d64c9..02eb395f6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -1007,11 +1007,17 @@ public class XFLConverter { symbolStr += " trackAsMenu=\"true\""; } } + boolean linkageExportForAS = false; if (characterClasses.containsKey(symbol.getCharacterID())) { - symbolStr += " linkageExportForAS=\"true\" linkageClassName=\"" + characterClasses.get(symbol.getCharacterID()) + "\""; + linkageExportForAS = true; + symbolStr += " linkageClassName=\"" + characterClasses.get(symbol.getCharacterID()) + "\""; } if (characterVariables.containsKey(symbol.getCharacterID())) { - symbolStr += " linkageExportForAS=\"true\" linkageIdentifier=\"" + characterVariables.get(symbol.getCharacterID()) + "\""; + linkageExportForAS = true; + symbolStr += " linkageIdentifier=\"" + characterVariables.get(symbol.getCharacterID()) + "\""; + } + if (linkageExportForAS) { + symbolStr += " linkageExportForAS=\"true\""; } symbolStr += ">"; symbolStr += ""; @@ -2303,6 +2309,15 @@ public class XFLConverter { writeFile("PROXY-CS5".getBytes(), outfile); } + if (useAS3) { + File outF = new File(outfile); + File outDir = outF.getParentFile(); + try { + swf.exportActionScript(outDir.getAbsolutePath(), false); + } catch (Exception ex) { + Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, "Error during ActionScript3 export", ex); + } + } } private static int normHue(double h) {