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

View File

@@ -61,9 +61,10 @@ import com.jpexs.decompiler.flash.dumpview.DumpInfo;
import com.jpexs.decompiler.flash.dumpview.DumpInfoSpecial;
import com.jpexs.decompiler.flash.dumpview.DumpInfoSpecialType;
import com.jpexs.decompiler.flash.exporters.script.LinkReportExporter;
import com.jpexs.decompiler.flash.flexsdk.As3ScriptReplacer;
import com.jpexs.decompiler.flash.flexsdk.MxmlcAs3ScriptReplacer;
import com.jpexs.decompiler.flash.flexsdk.MxmlcException;
import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin;
import com.jpexs.decompiler.flash.importers.As3ScriptReplacerInterface;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.types.annotations.Internal;
@@ -1404,66 +1405,10 @@ public class ABC {
method_info.remove(index);
}
public boolean replaceScriptPack(ScriptPack pack, String as) throws AVM2ParseException, CompilationException, IOException, InterruptedException {
final boolean USE_FLEX = true;
boolean isSimple = pack.isSimple;
if (USE_FLEX) {
if (!pack.isSimple) {
return false;
}
As3ScriptReplacer asr = new As3ScriptReplacer(Configuration.flexSdkLocation.get(), new LinkReportExporter());
try {
asr.replaceScript(pack.getSwf(), pack, as);
} catch (MxmlcException ex) {
throw new AVM2ParseException(ex.getMxmlcErrorOutput(), 0);
}
} else {
String scriptName = pack.getPathScriptName() + ".as";
int oldIndex = pack.scriptIndex;
int newIndex = script_info.size();
String documentClass = getSwf().getDocumentClass();
boolean isDocumentClass = documentClass != null && documentClass.equals(pack.getClassPath().toString());
ScriptInfo si = script_info.get(oldIndex);
if (isSimple) {
si.delete(this, true);
} else {
for (int t : pack.traitIndices) {
si.traits.traits.get(t).delete(this, true);
}
}
int newClassIndex = instance_info.size();
for (int t : pack.traitIndices) {
if (si.traits.traits.get(t) instanceof TraitClass) {
TraitClass tc = (TraitClass) si.traits.traits.get(t);
newClassIndex = tc.class_info + 1;
}
}
List<ABC> otherAbcs = new ArrayList<>(pack.allABCs);
otherAbcs.remove(this);
ActionScript3Parser.compile(as, this, otherAbcs, isDocumentClass, scriptName, newClassIndex, oldIndex);
if (isSimple) {
// Move newly added script to its position
script_info.set(oldIndex, script_info.get(newIndex));
script_info.remove(newIndex);
} else {
script_info.get(newIndex).setModified(true);
//Note: Is deleting traits safe?
List<Integer> todel = new ArrayList<>(new TreeSet<>(pack.traitIndices));
for (int i = todel.size() - 1; i >= 0; i--) {
si.traits.traits.remove((int) todel.get(i));
}
}
script_info.get(oldIndex).setModified(true);
}
public boolean replaceScriptPack(As3ScriptReplacerInterface replacer, ScriptPack pack, String as) throws AVM2ParseException, CompilationException, IOException, InterruptedException {
replacer.replaceScript(pack, as);
((Tag) parentTag).setModified(true);
return !isSimple;
return pack.isSimple;
}
private void packMethods() {

View File

@@ -613,6 +613,10 @@ public class Configuration {
@ConfigurationInternal
public static final ConfigurationItem<Double> guiAvm2DocsSplitPaneDividerLocationPercent = null;
@ConfigurationDefaultBoolean(false)
@ConfigurationCategory("script")
public static final ConfigurationItem<Boolean> useFlexAs3Compiler = null;
private enum OSId {
WINDOWS, OSX, UNIX

View File

@@ -3,6 +3,7 @@ package com.jpexs.decompiler.flash.flexsdk;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;
import com.jpexs.decompiler.flash.abc.types.InstanceInfo;
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
@@ -15,6 +16,7 @@ import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings;
import com.jpexs.decompiler.flash.exporters.swf.SwfToSwcExporter;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.DottedChain;
import com.jpexs.helpers.Helper;
import java.io.ByteArrayInputStream;
@@ -28,12 +30,13 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.jpexs.decompiler.flash.importers.As3ScriptReplacerInterface;
public class As3ScriptReplacer extends MxmlcRunner {
public class MxmlcAs3ScriptReplacer extends MxmlcRunner implements As3ScriptReplacerInterface {
private LinkReportExporter linkReporter;
public As3ScriptReplacer(String flexSdkPath, LinkReportExporter linkReporter) {
public MxmlcAs3ScriptReplacer(String flexSdkPath, LinkReportExporter linkReporter) {
super(flexSdkPath);
this.linkReporter = linkReporter;
}
@@ -87,8 +90,9 @@ public class As3ScriptReplacer extends MxmlcRunner {
return false;
}
public void replaceScript(SWF swf, ScriptPack oldPack, String txt) throws IOException, MxmlcException, InterruptedException {
if (!oldPack.isSimple) {
@Override
public void replaceScript(ScriptPack pack, String text) throws AVM2ParseException, CompilationException, IOException, InterruptedException {
if (!pack.isSimple) {
throw new IOException("Cannot compile such file"); //Alchemy, etc.
}
@@ -96,23 +100,23 @@ public class As3ScriptReplacer extends MxmlcRunner {
try {
tempDir = Files.createTempDirectory("ffdec-mxmlc-replace").toFile();
File pkgDir = tempDir;
for (String pkgPart : oldPack.getClassPath().packageStr.toList()) {
for (String pkgPart : pack.getClassPath().packageStr.toList()) {
if (!pkgPart.isEmpty()) {
pkgDir = new File(pkgDir, pkgPart);
}
}
pkgDir.mkdirs();
File scriptFileToCompile = new File(pkgDir, oldPack.getClassPath().className + ".as");
File scriptFileToCompile = new File(pkgDir, pack.getClassPath().className + ".as");
File compiledSwfFile = new File(pkgDir, "out.swf");
File swcFile = new File(pkgDir, "out.swc");
//Make copy without the old script
SWF swfCopy = recompileSWF(swf);
SWF swfCopy = recompileSWF(pack.getSwf());
List<ABC> modAbcs = new ArrayList<>();
List<ScriptPack> copyPacks = swfCopy.getAS3Packs();
for (ScriptPack sp : copyPacks) {
if (sp.getClassPath().equals(oldPack.getClassPath())) {
if (sp.getClassPath().equals(pack.getClassPath())) {
sp.abc.script_info.get(sp.scriptIndex).delete(sp.abc, true);
((Tag) sp.abc.parentTag).setModified(true);
modAbcs.add(sp.abc);
@@ -151,18 +155,22 @@ public class As3ScriptReplacer extends MxmlcRunner {
swcExport.exportSwf(swfCopy, swcFile, true);
//Write new script
Helper.writeFile(scriptFileToCompile.getAbsolutePath(), txt.getBytes("UTF-8"));
Helper.writeFile(scriptFileToCompile.getAbsolutePath(), text.getBytes("UTF-8"));
//Compile it (and subclasses stubs)
mxmlc("-strict=false", "-include-inheritance-dependencies-only", "-warnings=false", "-library-path", swcFile.getAbsolutePath(), "-source-path", tempDir.getAbsolutePath(), "-output", compiledSwfFile.getAbsolutePath(), "-debug=true", scriptFileToCompile.getAbsolutePath());
try {
//Compile it (and subclasses stubs)
mxmlc("-strict=false", "-include-inheritance-dependencies-only", "-warnings=false", "-library-path", swcFile.getAbsolutePath(), "-source-path", tempDir.getAbsolutePath(), "-output", compiledSwfFile.getAbsolutePath(), "-debug=true", scriptFileToCompile.getAbsolutePath());
} catch (MxmlcException ex1) {
throw new AVM2ParseException(ex1.getMxmlcErrorOutput(), 0);
}
try (FileInputStream fis = new FileInputStream(compiledSwfFile)) {
SWF newSWF = new SWF(fis, false, false);
List<ABCContainerTag> newTags = newSWF.getAbcList();
int oldScriptIndex = oldPack.scriptIndex;
int oldScriptIndex = pack.scriptIndex;
int oldClassIndex = -1;
ScriptInfo oldScriptInfo = oldPack.abc.script_info.get(oldPack.scriptIndex);
ScriptInfo oldScriptInfo = pack.abc.script_info.get(pack.scriptIndex);
for (Trait t : oldScriptInfo.traits.traits) {
if (t instanceof TraitClass) {
int traitClassIndex = ((TraitClass) t).class_info;
@@ -171,18 +179,18 @@ public class As3ScriptReplacer extends MxmlcRunner {
}
}
}
if (oldPack.isSimple) {
oldScriptInfo.delete(oldPack.abc, true);
if (pack.isSimple) {
oldScriptInfo.delete(pack.abc, true);
} else {
//NOO
}
oldPack.abc.pack(); // removes old classes/methods/scripts
pack.abc.pack(); // removes old classes/methods/scripts
ABCContainerTag newTagsLast = newTags.get(newTags.size() - 1);
ABC newLastAbc = newTagsLast.getABC();
Map<Integer, Integer> classesMap = new HashMap<>();
Map<Integer, Integer> scriptsMap = new HashMap<>();
oldPack.abc.mergeABC(newLastAbc,
pack.abc.mergeABC(newLastAbc,
new HashMap<>(),
new HashMap<>(),
new HashMap<>(),
@@ -207,10 +215,10 @@ public class As3ScriptReplacer extends MxmlcRunner {
List<ScriptInfo> addedScripts = new ArrayList<>();
for (int i = addedScriptIndices.size() - 1; i >= 0; i--) {
int newScriptIndex = addedScriptIndices.get(i);
addedScripts.add(0, oldPack.abc.script_info.remove(newScriptIndex));
addedScripts.add(0, pack.abc.script_info.remove(newScriptIndex));
}
for (int i = 0; i < addedScripts.size(); i++) {
oldPack.abc.script_info.add(oldScriptIndex + i, addedScripts.get(i));
pack.abc.script_info.add(oldScriptIndex + i, addedScripts.get(i));
}
//IMPORTANT: Map newly created classes to their position as they
@@ -219,7 +227,7 @@ public class As3ScriptReplacer extends MxmlcRunner {
if (oldClassIndex > -1) {
List<Integer> addedClassIndices = new ArrayList<>(classesMap.values());
Collections.sort(addedClassIndices);
int totalClassCount = oldPack.abc.class_info.size();
int totalClassCount = pack.abc.class_info.size();
Map<Integer, Integer> classesRemap = new HashMap<>();
for (int i = 0; i < addedClassIndices.size(); i++) {
classesRemap.put(addedClassIndices.get(i), oldClassIndex + i);
@@ -236,14 +244,20 @@ public class As3ScriptReplacer extends MxmlcRunner {
}
}
}
oldPack.abc.reorganizeClasses(classesRemap);
pack.abc.reorganizeClasses(classesRemap);
}
((Tag) oldPack.abc.parentTag).setModified(true);
((Tag) pack.abc.parentTag).setModified(true);
}
} finally {
if (tempDir != null && tempDir.exists()) {
//deleteFolder(tempDir);
deleteFolder(tempDir);
}
}
}
@Override
public boolean isAvailable() {
String flexLocation = Configuration.flexSdkLocation.get();
return !(flexLocation.isEmpty() || (!new File(MxmlcRunner.getMxmlcPath(flexLocation)).exists()));
}
}

View File

@@ -15,14 +15,14 @@ public class MxmlcRunner {
this.flexSdkPath = flexSdkPath;
}
public String getMxmlcPath() {
public static String getMxmlcPath(String flexSdkPath) {
boolean isWin = System.getProperty("os.name").toLowerCase().contains("win");
return flexSdkPath + File.separator + "bin" + File.separator + "mxmlc" + (isWin ? ".exe" : "");
}
public void mxmlc(String... arguments) throws MxmlcException, InterruptedException, IOException {
String runArgs[] = new String[arguments.length + 1];
runArgs[0] = getMxmlcPath();
runArgs[0] = getMxmlcPath(flexSdkPath);
System.arraycopy(arguments, 0, runArgs, 1, arguments.length);
System.out.println("" + String.join(" ", runArgs));
Process proc = null;

View File

@@ -36,7 +36,7 @@ public class AS3ScriptImporter {
private static final Logger logger = Logger.getLogger(AS3ScriptImporter.class.getName());
public int importScripts(String scriptsFolder, List<ScriptPack> packs) {
public int importScripts(As3ScriptReplacerInterface scriptReplacer, String scriptsFolder, List<ScriptPack> packs) {
if (!scriptsFolder.endsWith(File.separator)) {
scriptsFolder += File.separator;
}
@@ -50,7 +50,7 @@ public class AS3ScriptImporter {
String txt = Helper.readTextFile(fileName);
try {
pack.abc.replaceScriptPack(pack, txt);
pack.abc.replaceScriptPack(scriptReplacer, pack, txt);
} catch (AVM2ParseException ex) {
logger.log(Level.SEVERE, "%error% on line %line%, file: %file%".replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)).replace("%file%", fileName));
} catch (CompilationException ex) {

View File

@@ -0,0 +1,24 @@
package com.jpexs.decompiler.flash.importers;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.script.LinkReportExporter;
import com.jpexs.decompiler.flash.flexsdk.MxmlcAs3ScriptReplacer;
public class As3ScriptReplacerFactory {
public static As3ScriptReplacerInterface createByConfig() {
if (Configuration.useFlexAs3Compiler.get()) {
return createFlex();
} else {
return createFFDec();
}
}
public static As3ScriptReplacerInterface createFlex() {
return new MxmlcAs3ScriptReplacer(Configuration.flexSdkLocation.get(), new LinkReportExporter());
}
public static As3ScriptReplacerInterface createFFDec() {
return new FFDecAs3ScriptReplacer();
}
}

View File

@@ -0,0 +1,13 @@
package com.jpexs.decompiler.flash.importers;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;
import com.jpexs.decompiler.graph.CompilationException;
import java.io.IOException;
public interface As3ScriptReplacerInterface {
public boolean isAvailable();
public void replaceScript(ScriptPack pack, String text) throws AVM2ParseException, CompilationException, IOException, InterruptedException;
}

View File

@@ -0,0 +1,72 @@
package com.jpexs.decompiler.flash.importers;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScript3Parser;
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.flash.abc.types.traits.TraitClass;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.graph.CompilationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;
import javax.swing.JOptionPane;
public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface {
@Override
public void replaceScript(ScriptPack pack, String text) throws AVM2ParseException, CompilationException, IOException, InterruptedException {
ABC abc = pack.abc;
SWF swf = pack.abc.getSwf();
String scriptName = pack.getPathScriptName() + ".as";
int oldIndex = pack.scriptIndex;
int newIndex = abc.script_info.size();
String documentClass = swf.getDocumentClass();
boolean isDocumentClass = documentClass != null && documentClass.equals(pack.getClassPath().toString());
ScriptInfo si = abc.script_info.get(oldIndex);
if (pack.isSimple) {
si.delete(abc, true);
} else {
for (int t : pack.traitIndices) {
si.traits.traits.get(t).delete(abc, true);
}
}
int newClassIndex = abc.instance_info.size();
for (int t : pack.traitIndices) {
if (si.traits.traits.get(t) instanceof TraitClass) {
TraitClass tc = (TraitClass) si.traits.traits.get(t);
newClassIndex = tc.class_info + 1;
}
}
List<ABC> otherAbcs = new ArrayList<>(pack.allABCs);
otherAbcs.remove(abc);
ActionScript3Parser.compile(text, abc, otherAbcs, isDocumentClass, scriptName, newClassIndex, oldIndex);
if (pack.isSimple) {
// Move newly added script to its position
abc.script_info.set(oldIndex, abc.script_info.get(newIndex));
abc.script_info.remove(newIndex);
} else {
abc.script_info.get(newIndex).setModified(true);
//Note: Is deleting traits safe?
List<Integer> todel = new ArrayList<>(new TreeSet<>(pack.traitIndices));
for (int i = todel.size() - 1; i >= 0; i--) {
si.traits.traits.remove((int) todel.get(i));
}
}
abc.script_info.get(oldIndex).setModified(true);
}
@Override
public boolean isAvailable() {
File swc = Configuration.getPlayerSWC();
return !(swc == null || !swc.exists());
}
}

View File

@@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.CodeFormatting;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.importers.FFDecAs3ScriptReplacer;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.graph.CompilationException;
@@ -90,7 +91,7 @@ public class DirectEditingTest extends FileTestBase {
try {
en.toSource(htw, abc.script_info.get(s).traits.traits, new ConvertData(), ScriptExportMode.AS, false);
String original = htw.toString();
abc.replaceScriptPack(en, original);
abc.replaceScriptPack(new FFDecAs3ScriptReplacer() /*TODO: test the otherone*/, en, original);
} catch (Exception ex) {
fail("Exception during decompilation - file: " + filePath + " class: " + classPathString, ex);
throw ex;

View File

@@ -9,15 +9,13 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.testng.annotations.Test;
public class As3ScriptReplacerTest {
@Test
public void testReplace() throws IOException, InterruptedException, Exception {
As3ScriptReplacer replacer = new As3ScriptReplacer(Configuration.flexSdkLocation.get(), new LinkReportExporter());
MxmlcAs3ScriptReplacer replacer = new MxmlcAs3ScriptReplacer(Configuration.flexSdkLocation.get(), new LinkReportExporter());
SWF swf = new SWF(new BufferedInputStream(new FileInputStream("testdata/as3/as3.swf")), false);
String replacement = "package classes\n"
+ "{\n"
@@ -43,7 +41,7 @@ public class As3ScriptReplacerTest {
classNames.add("classes.TestClass1");
List<ScriptPack> packs = swf.getScriptPacksByClassNames(classNames);
for (ScriptPack sp : packs) {
replacer.replaceScript(swf, sp, replacement);
replacer.replaceScript(sp, replacement);
return;
}
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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)

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.