Added #1822, #1803 AS3 direct editation - optional using AIR (airglobal.swc) to compile

This commit is contained in:
Jindra Petřík
2022-11-20 22:12:19 +01:00
parent 1e535a4472
commit 854ed24b7c
16 changed files with 195 additions and 39 deletions
@@ -150,6 +150,8 @@ public class ActionScript3Parser {
// private final AbcIndexing otherABCs;
//private static final List<ABC> playerABCs = new ArrayList<>();
private static AbcIndexing playerGlobalAbcIndex;
private static AbcIndexing airGlobalAbcIndex;
private long uniqId() {
uniqLast++;
@@ -2591,10 +2593,10 @@ public class ActionScript3Parser {
addScriptFromTree(allOpenedNamespaces, traits, classPos);
}
public ActionScript3Parser(ABC abc, List<ABC> otherAbcs) throws IOException, InterruptedException {
public ActionScript3Parser(ABC abc, List<ABC> otherAbcs, boolean air) throws IOException, InterruptedException {
initPlayer();
abcIndex = new AbcIndexing(playerGlobalAbcIndex);
abcIndex = new AbcIndexing(air ? airGlobalAbcIndex : playerGlobalAbcIndex);
for (ABC a : otherAbcs) {
abcIndex.addAbc(a);
}
@@ -2612,12 +2614,20 @@ public class ActionScript3Parser {
SWF swf = new SWF(swc.getSWF("library.swf"), true);
playerGlobalAbcIndex = new AbcIndexing(swf);
}
if (airGlobalAbcIndex == null) {
if (Configuration.getAirSWC() == null) {
return;
}
SWC swc = new SWC(new FileInputStream(Configuration.getAirSWC()));
SWF swf = new SWF(swc.getSWF("library.swf"), true);
airGlobalAbcIndex = new AbcIndexing(swf);
}
}
public static void compile(String src, ABC abc, List<ABC> otherABCs, String fileName, int classPos, int scriptIndex) throws AVM2ParseException, IOException, InterruptedException, CompilationException {
public static void compile(String src, ABC abc, List<ABC> otherABCs, String fileName, int classPos, int scriptIndex, boolean air) throws AVM2ParseException, IOException, InterruptedException, CompilationException {
//List<ABC> parABCs = new ArrayList<>();
initPlayer();
ActionScript3Parser parser = new ActionScript3Parser(abc, otherABCs);
ActionScript3Parser parser = new ActionScript3Parser(abc, otherABCs, air);
boolean success = false;
ABC originalAbc = ((ABCContainerTag) ((Tag) abc.parentTag).cloneTag()).getABC();
try {
@@ -2638,12 +2648,12 @@ public class ActionScript3Parser {
}
}
public static void compile(SWF swf, String src, String dst, int classPos, int scriptIndex) {
public static void compile(SWF swf, String src, String dst, int classPos, int scriptIndex, boolean air) {
System.err.println("WARNING: AS3 compiler is not finished yet. This is only used for debuggging!");
try {
initPlayer();
ABC abc = new ABC(null);
ActionScript3Parser parser = new ActionScript3Parser(abc, new ArrayList<>());
ActionScript3Parser parser = new ActionScript3Parser(abc, new ArrayList<>(), air);
parser.addScript(new String(Helper.readFile(src), Utf8Helper.charset), src, classPos, scriptIndex);
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(dst)))) {
abc.saveToStream(fos);
@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.helpers.CodeFormatting;
import com.jpexs.decompiler.flash.helpers.FontHelper;
import com.jpexs.decompiler.flash.importers.TextImportResizeTextBoundsMode;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.Path;
import java.awt.Font;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -791,6 +792,11 @@ public final class Configuration {
@ConfigurationDefaultInt(5 * 60 * 1000)
@ConfigurationCategory("limit")
public static ConfigurationItem<Integer> maxCachedTime = null;
@ConfigurationDefaultString("")
@ConfigurationCategory("paths")
@ConfigurationFile(".*\\.swc$")
public static ConfigurationItem<String> airLibLocation = null;
private enum OSId {
WINDOWS, OSX, UNIX
@@ -1071,6 +1077,12 @@ public final class Configuration {
playerLibLocation.set(swcFile.getAbsolutePath());
}
}
if (airLibLocation.get("").isEmpty()) {
File swcFile = getAirSwcOld();
if (swcFile != null) {
airLibLocation.set(swcFile.getAbsolutePath());
}
}
}
public static Object getDefaultValue(Field field) {
@@ -1211,7 +1223,33 @@ public final class Configuration {
}
return ret;
}
public static File getAirSWC() {
String libLocation = airLibLocation.get("");
File ret = null;
if (!libLocation.isEmpty()) {
ret = new File(libLocation);
}
if (ret == null || !ret.exists()) {
ret = getAirSwcOld();
if (ret != null) {
airLibLocation.set(ret.getAbsolutePath());
}
}
return ret;
}
private static File getAirSwcOld() {
File libsDir = getFlashLibPath();
if (libsDir != null && libsDir.exists()) {
File airFile = new File(Path.combine(libsDir.getAbsolutePath(), "airglobal.swc"));
if (airFile.exists()) {
return airFile;
}
}
return null;
}
private static File getPlayerSwcOld() {
File libsDir = getFlashLibPath();
if (libsDir != null && libsDir.exists()) {
@@ -8,4 +8,5 @@ public class CustomConfigurationKeys {
public static final String KEY_LAST_SELECTED_PATH_RESOURCES = "lastSelectedPath.resources";
public static final String KEY_LAST_SELECTED_PATH_TAGLIST = "lastSelectedPath.taglist";
public static final String KEY_CHARSET = "charset";
public static final String KEY_LIBRARY = "library";
}
@@ -21,8 +21,10 @@ import com.jpexs.decompiler.flash.flexsdk.MxmlcAs3ScriptReplacer;
public class As3ScriptReplacerFactory {
public static As3ScriptReplacerInterface createByConfig() {
if (Configuration.useFlexAs3Compiler.get()) {
public static As3ScriptReplacerInterface createByConfig(boolean air) {
if (air) {
return createFFDecAir();
} else if (Configuration.useFlexAs3Compiler.get()) {
return createFlex();
} else {
return createFFDec();
@@ -34,6 +36,10 @@ public class As3ScriptReplacerFactory {
}
public static As3ScriptReplacerInterface createFFDec() {
return new FFDecAs3ScriptReplacer();
return new FFDecAs3ScriptReplacer(false);
}
public static As3ScriptReplacerInterface createFFDecAir() {
return new FFDecAs3ScriptReplacer(true);
}
}
@@ -33,6 +33,14 @@ import java.util.List;
public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface {
private boolean air;
public FFDecAs3ScriptReplacer(boolean air) {
this.air = air;
}
@Override
public void replaceScript(ScriptPack pack, String text) throws As3ScriptReplaceException, IOException, InterruptedException {
ABC abc = pack.abc;
@@ -63,7 +71,7 @@ public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface {
otherAbcs.remove(abc);
abc.script_info.get(oldIndex).delete(abc, true);
ActionScript3Parser.compile(text, abc, otherAbcs, scriptName, newClassIndex, oldIndex);
ActionScript3Parser.compile(text, abc, otherAbcs, scriptName, newClassIndex, oldIndex, air);
if (pack.isSimple) {
// Move newly added script to its position
abc.script_info.set(oldIndex, abc.script_info.get(newIndex));
@@ -84,11 +92,17 @@ public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface {
}
@Override
public boolean isAvailable() {
File swc = Configuration.getPlayerSWC();
public boolean isAvailable() {
File swc = air ? Configuration.getAirSWC() : Configuration.getPlayerSWC();
return !(swc == null || !swc.exists());
}
public boolean isAir() {
return air;
}
@Override
public void initReplacement(ScriptPack pack) {
//empty