Added Label that flex compiler is used (when it's enabled in settings)

Fixed #2111 Flex AS3 editation - use SWF dependencies defined in GUI
Fixed SWF dependencies label was not updated on startup
This commit is contained in:
Jindra Petřík
2023-11-14 22:05:40 +01:00
parent 237b9ba1dc
commit 8c61cebc06
19 changed files with 141 additions and 49 deletions

View File

@@ -1855,8 +1855,8 @@ public class ABC implements Openable {
method_info.remove(index);
}
public boolean replaceScriptPack(As3ScriptReplacerInterface replacer, ScriptPack pack, String as) throws As3ScriptReplaceException, IOException, InterruptedException {
replacer.replaceScript(pack, as);
public boolean replaceScriptPack(As3ScriptReplacerInterface replacer, ScriptPack pack, String as, List<SWF> dependencies) throws As3ScriptReplaceException, IOException, InterruptedException {
replacer.replaceScript(pack, as, dependencies);
((Tag) parentTag).setModified(true);
return pack.isSimple;
}

View File

@@ -66,6 +66,8 @@ public final class Configuration {
public static final Level logLevel;
public static boolean showStat;
public static final String ABC_DEPS_SEPARATOR = "{*sep*}";
@ConfigurationDefaultBoolean(true)
@ConfigurationCategory("ui")

View File

@@ -255,8 +255,6 @@ public class SwfToSwcExporter {
printDelay("swc.recompile2", t3, t4);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(0);
throw new RuntimeException(ex);
}

View File

@@ -24,6 +24,8 @@ import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitClass;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.configuration.CustomConfigurationKeys;
import com.jpexs.decompiler.flash.configuration.SwfSpecificCustomConfiguration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.exporters.script.AS3ScriptExporter;
import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings;
@@ -43,6 +45,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -56,6 +59,7 @@ public class MxmlcAs3ScriptReplacer extends MxmlcRunner implements As3ScriptRepl
private File tempDir;
private File pkgDir;
private File swcFile;
private List<File> dependenciesSwcFiles = new ArrayList<>();
public MxmlcAs3ScriptReplacer(String flexSdkPath) {
super(flexSdkPath);
@@ -115,13 +119,13 @@ public class MxmlcAs3ScriptReplacer extends MxmlcRunner implements As3ScriptRepl
}
@Override
public synchronized void replaceScript(ScriptPack pack, String text) throws As3ScriptReplaceException, IOException, InterruptedException {
public synchronized void replaceScript(ScriptPack pack, String text, List<SWF> dependencies) throws As3ScriptReplaceException, IOException, InterruptedException {
if (!pack.isSimple) {
throw new IOException("Cannot compile such file"); //Alchemy, etc. TODO: handle better
}
if (!isInited(pack)) {
initReplacement(pack);
initReplacement(pack, dependencies);
}
File scriptFileToCompile = new File(pkgDir, pack.getClassPath().className + ".as");
@@ -131,7 +135,21 @@ public class MxmlcAs3ScriptReplacer extends MxmlcRunner implements As3ScriptRepl
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());
List<String> args = new ArrayList<>(Arrays.asList("-strict=false",
"-include-inheritance-dependencies-only",
"-warnings=false",
"-library-path", swcFile.getAbsolutePath()));
for (File depSwcFile : dependenciesSwcFiles) {
args.add("-library-path");
args.add(depSwcFile.getAbsolutePath());
}
args.addAll(Arrays.asList("-source-path", tempDir.getAbsolutePath(),
"-output", compiledSwfFile.getAbsolutePath(),
"-debug=true",
scriptFileToCompile.getAbsolutePath()));
mxmlc(args);
} catch (MxmlcException ex1) {
//String compiledFilePath = scriptFileToCompile.getAbsolutePath();
Pattern errPattern = Pattern.compile("^" + Pattern.quote(tempDir.getAbsolutePath()) + "(?<file>.*)\\((?<line>[0-9]+)\\): col: (?<col>[0-9]+) (?<message>.*)$");
@@ -149,7 +167,13 @@ public class MxmlcAs3ScriptReplacer extends MxmlcRunner implements As3ScriptRepl
errorItems.add(new As3ScriptReplaceExceptionItem(errFile, errMsg, errLine, errCol));
}
}
throw new As3ScriptReplaceException(errorItems);
As3ScriptReplaceException ex;
if (errorItems.isEmpty()) {
ex = new As3ScriptReplaceException(err);
} else {
ex = new As3ScriptReplaceException(errorItems);
}
throw ex;
}
try (FileInputStream fis = new FileInputStream(compiledSwfFile)) {
@@ -248,7 +272,7 @@ public class MxmlcAs3ScriptReplacer extends MxmlcRunner implements As3ScriptRepl
}
@Override
public synchronized void initReplacement(ScriptPack pack) {
public synchronized void initReplacement(ScriptPack pack, List<SWF> dependencies) {
if (tempDir != null) {
deinitReplacement(pack);
}
@@ -262,11 +286,11 @@ public class MxmlcAs3ScriptReplacer extends MxmlcRunner implements As3ScriptRepl
}
pkgDir.mkdirs();
swcFile = new File(pkgDir, "out.swc");
swcFile = new File(tempDir, "out.swc");
//Make copy without the old script
Openable openable = pack.getOpenable();
SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC) openable).getSwf();
SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC) openable).getSwf();
SWF swfCopy = recompileSWF(swf);
List<ABC> modAbcs = new ArrayList<>();
@@ -309,7 +333,15 @@ public class MxmlcAs3ScriptReplacer extends MxmlcRunner implements As3ScriptRepl
//Flex then uses the code already present in the SWC, no need to decompile it (hurray!)
SwfToSwcExporter swcExport = new SwfToSwcExporter();
swcExport.exportSwf(swfCopy, swcFile, true);
dependenciesSwcFiles = new ArrayList<>();
int i = 0;
for (SWF depSwf : dependencies) {
i++;
File depSwcFile = new File(tempDir, "dep" + i + ".swc");
swcExport.exportSwf(depSwf, depSwcFile, false);
dependenciesSwcFiles.add(depSwcFile);
}
} catch (IOException iex) {
//ignore
} catch (InterruptedException ex) {

View File

@@ -20,6 +20,7 @@ import com.jpexs.helpers.Helper;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class MxmlcRunner {
@@ -51,10 +52,12 @@ public class MxmlcRunner {
return null;
}
public void mxmlc(String... arguments) throws MxmlcException, InterruptedException, IOException {
String[] runArgs = new String[arguments.length + 1];
public void mxmlc(List<String> arguments) throws MxmlcException, InterruptedException, IOException {
String[] runArgs = new String[arguments.size() + 1];
runArgs[0] = getMxmlcPath(flexSdkPath);
System.arraycopy(arguments, 0, runArgs, 1, arguments.length);
for (int i = 0; i < arguments.size(); i++) {
runArgs[i + 1] = arguments.get(i);
}
//System.out.println("" + String.join(" ", runArgs));
Process proc = null;
try {

View File

@@ -37,11 +37,11 @@ public class AS3ScriptImporter {
private static final Logger logger = Logger.getLogger(AS3ScriptImporter.class.getName());
public int importScripts(As3ScriptReplacerInterface scriptReplacer, String scriptsFolder, List<ScriptPack> packs) throws InterruptedException {
return importScripts(scriptReplacer, scriptsFolder, packs, null);
public int importScripts(As3ScriptReplacerInterface scriptReplacer, String scriptsFolder, List<ScriptPack> packs, List<SWF> dependencies) throws InterruptedException {
return importScripts(scriptReplacer, scriptsFolder, packs, null, dependencies);
}
public int importScripts(As3ScriptReplacerInterface scriptReplacer, String scriptsFolder, List<ScriptPack> packs, ScriptImporterProgressListener listener) throws InterruptedException {
public int importScripts(As3ScriptReplacerInterface scriptReplacer, String scriptsFolder, List<ScriptPack> packs, ScriptImporterProgressListener listener, List<SWF> dependencies) throws InterruptedException {
if (!scriptsFolder.endsWith(File.separator)) {
scriptsFolder += File.separator;
}
@@ -64,7 +64,7 @@ public class AS3ScriptImporter {
String txt = Helper.readTextFile(fileName);
try {
pack.abc.replaceScriptPack(scriptReplacer, pack, txt);
pack.abc.replaceScriptPack(scriptReplacer, pack, txt, dependencies);
} catch (As3ScriptReplaceException asre) {
for (As3ScriptReplaceExceptionItem item : asre.getExceptionItems()) {
logger.log(Level.SEVERE, "%error% on line %line%, column %col%, file: %file%".replace("%error%", item.getMessage()).replace("%line%", Long.toString(item.getLine())).replace("%file%", fileName).replace("%col%", "" + item.getCol()));

View File

@@ -27,12 +27,25 @@ public class As3ScriptReplaceException extends Exception {
private List<As3ScriptReplaceExceptionItem> exceptionItems;
public As3ScriptReplaceException(String message) {
super(message);
}
public As3ScriptReplaceException(List<As3ScriptReplaceExceptionItem> exceptionItems) {
super("Script replace exception");
this.exceptionItems = exceptionItems;
}
public As3ScriptReplaceException(As3ScriptReplaceExceptionItem exceptionItem) {
this.exceptionItems = new ArrayList<>();
this.exceptionItems.add(exceptionItem);
}
@Override
public String getMessage() {
if (exceptionItems.isEmpty()) {
return super.getMessage();
}
StringBuilder sb = new StringBuilder();
for (As3ScriptReplaceExceptionItem item : exceptionItems) {
sb.append(item.toString()).append("\r\n");
@@ -43,15 +56,9 @@ public class As3ScriptReplaceException extends Exception {
@Override
public String getLocalizedMessage() {
return getMessage();
}
public As3ScriptReplaceException(As3ScriptReplaceExceptionItem exceptionItem) {
this.exceptionItems = new ArrayList<>();
this.exceptionItems.add(exceptionItem);
}
}
public List<As3ScriptReplaceExceptionItem> getExceptionItems() {
return exceptionItems;
}
}

View File

@@ -16,16 +16,18 @@
*/
package com.jpexs.decompiler.flash.importers;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import java.io.IOException;
import java.util.List;
public interface As3ScriptReplacerInterface {
public boolean isAvailable();
public void initReplacement(ScriptPack pack);
public void initReplacement(ScriptPack pack, List<SWF> dependencies);
public void replaceScript(ScriptPack pack, String text) throws As3ScriptReplaceException, IOException, InterruptedException;
public void replaceScript(ScriptPack pack, String text, List<SWF> dependencies) throws As3ScriptReplaceException, IOException, InterruptedException;
public void deinitReplacement(ScriptPack pack);
}

View File

@@ -41,7 +41,7 @@ public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface {
}
@Override
public void replaceScript(ScriptPack pack, String text) throws As3ScriptReplaceException, IOException, InterruptedException {
public void replaceScript(ScriptPack pack, String text, List<SWF> dependencies) throws As3ScriptReplaceException, IOException, InterruptedException {
ABC abc = pack.abc;
SWF swf = pack.abc.getSwf();
String scriptName = pack.getPathScriptName() + ".as";
@@ -103,7 +103,7 @@ public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface {
}
@Override
public void initReplacement(ScriptPack pack) {
public void initReplacement(ScriptPack pack, List<SWF> dependencies) {
//empty
}