As3ScriptReplacer as interface

Better handling missing directories
Tip for directories in advanced setting refactored - link to Flex SDK
Use Flex SDK switch in Advanced settings
This commit is contained in:
Jindra Petřík
2016-08-16 23:31:12 +02:00
parent 95785ba218
commit c4e1879b79
21 changed files with 316 additions and 154 deletions
@@ -90,6 +90,7 @@ import com.jpexs.decompiler.flash.exporters.settings.SpriteExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings;
import com.jpexs.decompiler.flash.exporters.swf.SwfToSwcExporter;
import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter;
import com.jpexs.decompiler.flash.flexsdk.MxmlcAs3ScriptReplacer;
import com.jpexs.decompiler.flash.gui.AppStrings;
import com.jpexs.decompiler.flash.gui.Main;
import com.jpexs.decompiler.flash.gui.SearchInMemory;
@@ -101,7 +102,10 @@ import com.jpexs.decompiler.flash.helpers.FileTextWriter;
import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin;
import com.jpexs.decompiler.flash.importers.AS2ScriptImporter;
import com.jpexs.decompiler.flash.importers.AS3ScriptImporter;
import com.jpexs.decompiler.flash.importers.As3ScriptReplacerFactory;
import com.jpexs.decompiler.flash.importers.As3ScriptReplacerInterface;
import com.jpexs.decompiler.flash.importers.BinaryDataImporter;
import com.jpexs.decompiler.flash.importers.FFDecAs3ScriptReplacer;
import com.jpexs.decompiler.flash.importers.FontImporter;
import com.jpexs.decompiler.flash.importers.ImageImporter;
import com.jpexs.decompiler.flash.importers.MorphShapeImporter;
@@ -3421,7 +3425,7 @@ public class CommandLineArgumentParser {
SWF swf = new SWF(is, Configuration.parallelSpeedUp.get());
String scriptsFolder = Path.combine(args.pop(), ScriptExportSettings.EXPORT_FOLDER_NAME);
new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true));
new AS3ScriptImporter().importScripts(scriptsFolder, swf.getAS3Packs());
new AS3ScriptImporter().importScripts(As3ScriptReplacerFactory.createByConfig(), scriptsFolder, swf.getAS3Packs());
try {
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) {
@@ -3552,18 +3556,31 @@ public class CommandLineArgumentParser {
private static void replaceAS3(String as, ScriptPack pack) throws IOException, InterruptedException {
System.out.println("Replace AS3");
System.out.println("Warning: This feature is EXPERIMENTAL");
File swc = Configuration.getPlayerSWC();
if (swc == null) {
final String adobePage = "http://www.adobe.com/support/flashplayer/downloads.html";
System.err.println("For ActionScript 3 direct editation, a library called \"PlayerGlobal.swc\" needs to be downloaded from Adobe homepage:");
System.err.println(adobePage);
System.err.println("Download the library called PlayerGlobal(.swc), and place it to directory");
System.err.println(Configuration.getFlashLibPath().getAbsolutePath());
As3ScriptReplacerInterface scriptReplacer = As3ScriptReplacerFactory.createByConfig();
if (!scriptReplacer.isAvailable()) {
System.err.println("Current script replacer is not available.");
if (scriptReplacer instanceof FFDecAs3ScriptReplacer) {
System.err.println("Current replacer: FFDec");
final String adobePage = "http://www.adobe.com/support/flashplayer/downloads.html";
System.err.println("For ActionScript 3 direct editation, a library called \"PlayerGlobal.swc\" needs to be downloaded from Adobe homepage:");
System.err.println(adobePage);
System.err.println("Download the library called PlayerGlobal(.swc), and place it to directory");
System.err.println(Configuration.getFlashLibPath().getAbsolutePath());
} else if (scriptReplacer instanceof MxmlcAs3ScriptReplacer) {
System.err.println("Current replacer: Flex SDK");
final String flexPage = "http://www.adobe.com/devnet/flex/flex-sdk-download.html";
System.err.println("For ActionScript 3 direct editation, Flex SDK needs to be download");
System.err.println(flexPage);
System.err.println("Download FLEX Sdk, unzip it to some directory and set its directory path in the configuration");
} else {
}
System.exit(1);
}
try {
pack.abc.replaceScriptPack(pack, as);
pack.abc.replaceScriptPack(scriptReplacer, pack, as);
} catch (AVM2ParseException ex) {
System.err.println("%error% on line %line%".replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)));
System.exit(1);
@@ -57,6 +57,7 @@ import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
@@ -68,6 +69,8 @@ import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.WindowConstants;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.table.DefaultTableModel;
import org.pushingpixels.substance.api.ColorSchemeAssociationKind;
@@ -479,24 +482,19 @@ public class AdvancedSettingsDialog extends AppDialog {
itemCount, 2, //rows, cols
6, 6, //initX, initY
6, 6); //xPad, yPad
//https://www.adobe.com/support/flashplayer/debug_downloads.html
if (resourceBundle.containsKey("config.group.tip." + cat)) {
String tip = resourceBundle.getString("config.group.tip." + cat);
String url = null;
String urls[] = new String[0];
if (resourceBundle.containsKey("config.group.link." + cat)) {
url = resourceBundle.getString("config.group.link." + cat);
urls = resourceBundle.getString("config.group.link." + cat).split(" ");
}
for (int i = 0; i < urls.length; i++) {
tip = tip.replace("%link" + (i + 1) + "%", urls[i]);
}
JPanel p = new JPanel(new BorderLayout());
p.add(configPanel, BorderLayout.CENTER);
JPanel tipPanel = new JPanel(new FlowLayout());
tipPanel.add(new JLabel("<html><b>" + resourceBundle.getString("tip") + "</b>" + tip + "</html>"));
if (url != null) {
String linkText = url;
if (resourceBundle.containsKey("config.group.linkText." + cat)) {
linkText = resourceBundle.getString("config.group.linkText." + cat);
}
tipPanel.add(new LinkLabel(linkText, url));
}
tipPanel.add(new HtmlLabel("<b>" + resourceBundle.getString("tip") + "</b>" + tip));
p.add(tipPanel, BorderLayout.SOUTH);
configPanel = p;
}
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2016 Jindra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui;
import java.awt.Color;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.event.HyperlinkEvent;
public class HtmlLabel extends JEditorPane {
private JLabel label = new JLabel();
private String rawText;
public HtmlLabel() {
this("");
}
public HtmlLabel(String text) {
super("text/html", "");
setText(text);
setEditable(false);
setFocusable(false);
setOpaque(false);
addHyperlinkListener((HyperlinkEvent hle) -> {
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
View.navigateUrl(hle.getURL().toString());
}
});
}
@Override
public void setText(String t) {
String modText = t;
if (!t.equals("")) {
Color fgColor = label.getForeground();
modText = "<body style=\"font-size:" + label.getFont().getSize() + "pt; font-family: " + label.getFont().getFamily() + "; color:rgb(" + fgColor.getRed() + "," + fgColor.getGreen() + "," + fgColor.getBlue() + ");\">" + t + "</body>";
}
this.rawText = t;
super.setText(modText);
}
@Override
public String getText() {
return rawText;
}
}
@@ -73,6 +73,7 @@ import com.jpexs.decompiler.flash.exporters.settings.SpriteExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings;
import com.jpexs.decompiler.flash.exporters.swf.SwfJavaExporter;
import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter;
import com.jpexs.decompiler.flash.flexsdk.MxmlcAs3ScriptReplacer;
import com.jpexs.decompiler.flash.gui.abc.ABCPanel;
import com.jpexs.decompiler.flash.gui.abc.ABCPanelSearchResult;
import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel;
@@ -94,7 +95,10 @@ import com.jpexs.decompiler.flash.helpers.FileTextWriter;
import com.jpexs.decompiler.flash.helpers.Freed;
import com.jpexs.decompiler.flash.importers.AS2ScriptImporter;
import com.jpexs.decompiler.flash.importers.AS3ScriptImporter;
import com.jpexs.decompiler.flash.importers.As3ScriptReplacerFactory;
import com.jpexs.decompiler.flash.importers.As3ScriptReplacerInterface;
import com.jpexs.decompiler.flash.importers.BinaryDataImporter;
import com.jpexs.decompiler.flash.importers.FFDecAs3ScriptReplacer;
import com.jpexs.decompiler.flash.importers.ImageImporter;
import com.jpexs.decompiler.flash.importers.ShapeImporter;
import com.jpexs.decompiler.flash.importers.SwfXmlImporter;
@@ -861,11 +865,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
? translate("message.confirm.closeAll")
: translate("message.confirm.close").replace("{swfName}", swfList.toString());
if (View.showConfirmDialog(this, message, translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, Configuration.showCloseConfirmation, JOptionPane.OK_OPTION) != JOptionPane.OK_OPTION) {
return false;
}
return true;
return View.showConfirmDialog(this, message, translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, Configuration.showCloseConfirmation, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION;
}
public boolean isModified() {
@@ -2143,15 +2143,32 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
}
public void importScript(final SWF swf) {
public As3ScriptReplacerInterface getAs3ScriptReplacer() {
As3ScriptReplacerInterface r = As3ScriptReplacerFactory.createByConfig();
if (!r.isAvailable()) {
if (r instanceof MxmlcAs3ScriptReplacer) {
if (View.showConfirmDialog(null, AppStrings.translate("message.flexpath.notset"), AppStrings.translate("error"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
Main.advancedSettings("paths");
}
} else if (r instanceof FFDecAs3ScriptReplacer) {
if (View.showConfirmDialog(this, AppStrings.translate("message.playerpath.lib.notset"), AppStrings.translate("message.action.playerglobal.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
Main.advancedSettings("paths");
}
} else {
//Not translated yet - just in case there are more Script replacers in the future. Unused now.
View.showConfirmDialog(this, "Current script replacer is not available", "Script replacer not available", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE);
}
return null;
}
return r;
}
String flexLocation = Configuration.flexSdkLocation.get();
if (flexLocation.isEmpty() || (!new File(flexLocation).exists())) {
View.showMessageDialog(null, AppStrings.translate("message.flexpath.notset"), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
Main.advancedSettings("paths");
public void importScript(final SWF swf) {
As3ScriptReplacerInterface as3ScriptReplacer = getAs3ScriptReplacer();
if (as3ScriptReplacer == null) {
return;
}
String flexLocation = Configuration.flexSdkLocation.get();
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File(Configuration.lastExportDir.get()));
chooser.setDialogTitle(translate("import.select.directory"));
@@ -2162,7 +2179,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
String scriptsFolder = Path.combine(selFile, ScriptExportSettings.EXPORT_FOLDER_NAME);
int countAs2 = new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true));
int countAs3 = new AS3ScriptImporter().importScripts(scriptsFolder, swf.getAS3Packs());
int countAs3 = new AS3ScriptImporter().importScripts(as3ScriptReplacer, scriptsFolder, swf.getAS3Packs());
if (countAs3 > 0) {
updateClassesList();
@@ -69,6 +69,7 @@ import com.jpexs.decompiler.flash.gui.abc.tablemodels.UIntTableModel;
import com.jpexs.decompiler.flash.gui.controls.JPersistentSplitPane;
import com.jpexs.decompiler.flash.gui.editor.LinkHandler;
import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel;
import com.jpexs.decompiler.flash.importers.As3ScriptReplacerFactory;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
@@ -1150,17 +1151,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABC
}
private void editDecompiledButtonActionPerformed(ActionEvent evt) {
File swc = Configuration.getPlayerSWC();
if (swc == null || !swc.exists()) {
if (View.showConfirmDialog(this, AppStrings.translate("message.playerpath.lib.notset"), AppStrings.translate("message.action.playerglobal.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.OK_OPTION) {
Main.advancedSettings("paths");
return;
}
}
String flexLocation = Configuration.flexSdkLocation.get();
if (flexLocation.isEmpty() || (!new File(flexLocation).exists())) {
View.showMessageDialog(null, AppStrings.translate("message.flexpath.notset"), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
Main.advancedSettings("paths");
if (mainPanel.getAs3ScriptReplacer() == null) {
return;
}
if (View.showConfirmDialog(null, AppStrings.translate("message.confirm.experimental.function"), AppStrings.translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, Configuration.warningExperimentalAS3Edit, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION) {
@@ -1180,7 +1171,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABC
try {
String oldSp = pack.getClassPath().toRawString();
String as = decompiledTextArea.getText();
abc.replaceScriptPack(pack, as);
abc.replaceScriptPack(mainPanel.getAs3ScriptReplacer(), pack, as);
lastDecompiled = as;
setDecompiledEditMode(false);
mainPanel.updateClassesList();
@@ -379,9 +379,8 @@ config.description.lastSessionFileTitles = Contains the opened file titles from
config.group.name.paths = Paths
config.group.description.paths = Location of needed files
config.group.tip.paths = You can download these files on adobe webpage
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html
config.group.linkText.paths = [visit]
config.group.tip.paths = Download projector and Playerglobal on <a href="%link1%">adobe webpage</a>. Flex SDK can be downloaded on <a href="%link2%">adobe devnet</a>.
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html http://www.adobe.com/devnet/flex/flex-sdk-download.html
config.name.playerLocation = 1) Flash Player projector path
config.description.playerLocation = Location of standalone flash player executable. Used for Run action.
@@ -435,3 +434,6 @@ config.description.resetLetterSpacingOnTextImport = Useful for cyrillic fonts, b
config.name.flexSdkLocation = 4) Flex SDK directory path
config.description.flexSdkLocation = Location of Adobe Flex SDK. It is used mostly for AS3 compilation.
config.name.useFlexAs3Compiler = Use Flex SDK AS3 compiler
config.description.useFlexAs3Compiler = Use AS3 compiler from Flex SDK while ActionScript direct editation (Flex SDK directory needs to be set)
@@ -363,9 +363,8 @@ config.description.lastSessionFileTitles = Obsahuje titulky souboru z naposledy
config.group.name.paths = Cesty
config.group.description.paths = Um\u00edst\u011bn\u00ed pot\u0159ebn\u00fdch soubor\u016f
config.group.tip.paths = Tyto soubory m\u016f\u017eete st\u00e1hnout na str\u00e1nk\u00e1ch adobe
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html
config.group.linkText.paths = [nav\u0161t\u00edvit]
config.group.tip.paths = Stahn\u011bte si projector a Playerglobal na <a href="%link1%">str\u00e1nk\u00e1ch adobe</a>. Flex SDK lze stahnout na <a href="%link2%">webu adobe devnet</a>.
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html http://www.adobe.com/devnet/flex/flex-sdk-download.html
config.name.playerLocation = 1) Cesta k Flash Player projectoru
config.description.playerLocation = Um\u00edst\u011bn\u00ed spustiteln\u00e9ho flash playeru. Pou\u017e\u00edvan\u00e9 pro akci Spustit.
@@ -379,9 +379,10 @@ config.description.lastSessionFileTitles = Contiene los t\u00edtulos de archivoa
config.group.name.paths = Rutas
config.group.description.paths = Ubicaci\u00f3n de los archivos necesarios
config.group.tip.paths = Usted puede bajar estos archivos desde la p\u00e1gina web de Adobe
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html
config.group.linkText.paths = [visita]
#config.group.tip.paths = Usted puede bajar estos archivos desde la p\u00e1gina web de Adobe
#TODO: translate again:
config.group.tip.paths = Download projector and Playerglobal on <a href="%link1%">adobe webpage</a>. Flex SDK can be downloaded on <a href="%link2%">adobe devnet</a>.
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html http://www.adobe.com/devnet/flex/flex-sdk-download.html
config.name.playerLocation = 1) Ruta de Flash Player projector
config.description.playerLocation = Ubicaci\u00f3n del ejecutable aut\u00f3nomo de Flash Player. Utilizado para la acci\u00f3n Correr.
@@ -379,9 +379,10 @@ config.description.lastSessionFileTitles = Comprend les titres des fichiers ouve
config.group.name.paths = Chemins
config.group.description.paths = Location des fichiers demand\u00e9s
config.group.tip.paths = Vous pouvez t\u00e9l\u00e9charger ces fichiers depuis le site web d'Adobe
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html
config.group.linkText.paths = [visiter]
#config.group.tip.paths = Vous pouvez t\u00e9l\u00e9charger ces fichiers depuis le site web d'Adobe
#TODO: translate again:
config.group.tip.paths = Download projector and Playerglobal on <a href="%link1%">adobe webpage</a>. Flex SDK can be downloaded on <a href="%link2%">adobe devnet</a>.
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html http://www.adobe.com/devnet/flex/flex-sdk-download.html
config.name.playerLocation = 1) Chemin du lecteur Flash
config.description.playerLocation = Location du lecteur autonome de fichier ex\u00e9cutable Flash. Used for Run action.
@@ -379,9 +379,10 @@ config.description.lastSessionFileTitles = Tartalmazza az utols\u00f3 munkamenet
config.group.name.paths = \u00datvonalak
config.group.description.paths = A sz\u00fcks\u00e9ges f\u00e1jlok el\u00e9rhet\u0151s\u00e9gei
config.group.tip.paths = Ezeket a f\u00e1jlokat az Adobe honlapj\u00e1r\u00f3l t\u00f6ltheti le
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html
config.group.linkText.paths = [visit]
#config.group.tip.paths = Ezeket a f\u00e1jlokat az Adobe honlapj\u00e1r\u00f3l t\u00f6ltheti le
#TODO: translate again:
config.group.tip.paths = Download projector and Playerglobal on <a href="%link1%">adobe webpage</a>. Flex SDK can be downloaded on <a href="%link2%">adobe devnet</a>.
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html http://www.adobe.com/devnet/flex/flex-sdk-download.html
config.name.playerLocation = 1) Flash Player projector \u00fatvonal
config.description.playerLocation = Standalone flash player helye. A Futtat\u00e1shoz sz\u00fcks\u00e9ges.
@@ -379,9 +379,10 @@ config.description.lastSessionFileTitles = Contiene i titoli dei file aperti nel
config.group.name.paths = Percorsi
config.group.description.paths = Ubicazione dei file richiesti
config.group.tip.paths = \ufffd possibile ottenere questi file dal sito Adobe
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html
config.group.linkText.paths = [apri]
#config.group.tip.paths = possibile ottenere questi file dal sito Adobe
#TODO: translate again:
config.group.tip.paths = Download projector and Playerglobal on <a href="%link1%">adobe webpage</a>. Flex SDK can be downloaded on <a href="%link2%">adobe devnet</a>.
config.group.link.paths = https://www.adobe.com/support/flashplayer/debug_downloads.html http://www.adobe.com/devnet/flex/flex-sdk-download.html
config.name.playerLocation = 1) Percorso Flash Player
config.description.playerLocation = Posizione eseguibile Flash Player. Utilizzato per l'azione Esegui.