Added #2113 Commandline - allow -onerror abort argument on -importScript

This commit is contained in:
Jindra Petřík
2023-11-05 20:00:02 +01:00
parent aecd10f630
commit cc0050f155
7 changed files with 79 additions and 18 deletions

View File

@@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
advance value (add to the font advance + calculated letterspacing)
- DefineEditText display - letterspacing, kerning, indent, relative font size
- FLA export - DefineEditText autokern attribute
- [#2113] Commandline - allow `-onerror abort` argument on `-importScript`
### Fixed
- [#1306], [#1768] Maximizing window on other than main monitor
@@ -3250,6 +3251,7 @@ Major version of SWF to XML export changed to 2.
[#2005]: https://www.free-decompiler.com/flash/issues/2005
[#2105]: https://www.free-decompiler.com/flash/issues/2105
[#1799]: https://www.free-decompiler.com/flash/issues/1799
[#2113]: https://www.free-decompiler.com/flash/issues/2113
[#1306]: https://www.free-decompiler.com/flash/issues/1306
[#1768]: https://www.free-decompiler.com/flash/issues/1768
[#2013]: https://www.free-decompiler.com/flash/issues/2013

View File

@@ -83,26 +83,38 @@ public class AS2ScriptImporter {
String txt = Helper.readTextFile(fileName);
ActionScript2Parser par = new ActionScript2Parser(asm.getSwf(), asm);
boolean errored = false;
try {
asm.setActions(par.actionsFromString(txt, asm.getSwf().getCharset()));
} catch (ValueTooLargeException ex) {
logger.log(Level.SEVERE, "Script or some of its functions are too large, file: {0}", fileName);
errored = true;
} catch (ActionParseException ex) {
logger.log(Level.SEVERE, "%error% on line %line%, file: %file%".replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)).replace("%file%", fileName), ex);
errored = true;
} catch (CompilationException ex) {
logger.log(Level.SEVERE, "%error% on line %line%, file: %file%".replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)).replace("%file%", fileName), ex);
errored = true;
} catch (IOException ex) {
logger.log(Level.SEVERE, "error during script import, file: %file%".replace("%file%", fileName), ex);
errored = true;
} catch (InterruptedException ex) {
return importCount;
} catch (Exception ex) {
logger.log(Level.SEVERE, "error during script import, file: %file%".replace("%file%", fileName), ex);
errored = true;
}
asm.setModified();
importCount++;
if (listener != null) {
listener.scriptImported();
if (!errored) {
asm.setModified();
importCount++;
if (listener != null) {
listener.scriptImported();
}
} else {
if (listener != null) {
listener.scriptImportError();
}
}
}
@@ -111,18 +123,27 @@ public class AS2ScriptImporter {
asm.getSwf().informListeners("importing_as", fileName);
String txt = Helper.readTextFile(fileName);
boolean errored = false;
try {
asm.setActions(ASMParser.parse(0, true, txt, asm.getSwf().version, false, asm.getSwf().getCharset()));
} catch (IOException ex) {
logger.log(Level.SEVERE, "error during script import, file: %file%".replace("%file%", fileName), ex);
errored = true;
} catch (ActionParseException ex) {
logger.log(Level.SEVERE, "%error% on line %line%, file: %file%".replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)).replace("%file%", fileName), ex);
errored = true;
}
asm.setModified();
importCount++;
if (listener != null) {
listener.scriptImported();
if (!errored) {
asm.setModified();
importCount++;
if (listener != null) {
listener.scriptImported();
}
} else {
if (listener != null) {
listener.scriptImportError();
}
}
}
@@ -144,15 +165,24 @@ public class AS2ScriptImporter {
asm.getSwf().informListeners("importing_as", fileName);
String txt = Helper.readTextFile(fileName);
boolean errored = false;
try {
asm.setConstantPools(Helper.getConstantPoolsFromText(txt));
} catch (ConstantPoolTooBigException ex) {
logger.log(Level.SEVERE, null, ex);
errored = true;
}
asm.setModified();
importCount++;
if (listener != null) {
listener.scriptImported();
if (!errored) {
asm.setModified();
importCount++;
if (listener != null) {
listener.scriptImported();
}
} else {
if (listener != null) {
listener.scriptImportError();
}
}
}
}

View File

@@ -69,6 +69,9 @@ public class AS3ScriptImporter {
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()));
}
if (listener != null) {
listener.scriptImportError();
}
} catch (InterruptedException ex) {
return importCount;
}

View File

@@ -23,4 +23,6 @@ package com.jpexs.decompiler.flash.importers;
public interface ScriptImporterProgressListener {
public void scriptImported();
public void scriptImportError();
}

View File

@@ -122,6 +122,7 @@ import com.jpexs.decompiler.flash.importers.FontImporter;
import com.jpexs.decompiler.flash.importers.ImageImporter;
import com.jpexs.decompiler.flash.importers.MorphShapeImporter;
import com.jpexs.decompiler.flash.importers.MovieImporter;
import com.jpexs.decompiler.flash.importers.ScriptImporterProgressListener;
import com.jpexs.decompiler.flash.importers.ShapeImporter;
import com.jpexs.decompiler.flash.importers.SoundImporter;
import com.jpexs.decompiler.flash.importers.SpriteImporter;
@@ -1140,7 +1141,7 @@ public class CommandLineArgumentParser {
parseImportText(args, charset);
System.exit(0);
} else if (command.equals("importscript")) {
parseImportScript(args, charset, air);
parseImportScript(args, charset, air, handler);
System.exit(0);
} else if (command.equals("as3compiler")) {
ActionScript3Parser.compile(null /*?*/, args.pop(), args.pop(), 0, 0);
@@ -4202,7 +4203,7 @@ public class CommandLineArgumentParser {
}
}
private static void parseImportScript(Stack<String> args, String charset, boolean air) {
private static void parseImportScript(Stack<String> args, String charset, boolean air, AbortRetryIgnoreHandler errorHandler) {
String flexLocation = Configuration.flexSdkLocation.get();
if (Configuration.useFlexAs3Compiler.get() && (flexLocation.isEmpty() || (!new File(flexLocation).exists()))) {
@@ -4226,8 +4227,20 @@ public class CommandLineArgumentParser {
} else {
scriptsFolder = baseFolder;
}
new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true));
new AS3ScriptImporter().importScripts(As3ScriptReplacerFactory.createByConfig(air), scriptsFolder, swf.getAS3Packs());
ScriptImporterProgressListener listener = new ScriptImporterProgressListener() {
@Override
public void scriptImported() {
}
@Override
public void scriptImportError() {
if (errorHandler != null && ((ConsoleAbortRetryIgnoreHandler)errorHandler).errorMode == AbortRetryIgnoreHandler.ABORT) {
System.exit(1);
}
}
};
new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true), listener);
new AS3ScriptImporter().importScripts(As3ScriptReplacerFactory.createByConfig(air), scriptsFolder, swf.getAS3Packs(), listener);
try {
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) {

View File

@@ -53,8 +53,10 @@ public class ConsoleAbortRetryIgnoreHandler implements AbortRetryIgnoreHandler {
return result;
}
Scanner sc = new Scanner(System.in);
Logger.getLogger(ConsoleAbortRetryIgnoreHandler.class.getName()).log(Level.SEVERE, "Error occured", thrown);
System.out.println("Error occured: " + thrown.getLocalizedMessage());
if (thrown != null) {
Logger.getLogger(ConsoleAbortRetryIgnoreHandler.class.getName()).log(Level.SEVERE, "Error occured", thrown);
System.out.println("Error occured: " + thrown.getLocalizedMessage());
}
do {
System.out.print("Select action: (A)bort, (R)Retry, (I)Ignore:");
String n = sc.nextLine();

View File

@@ -3774,6 +3774,11 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
public void scriptImported() {
countAs2++;
}
@Override
public void scriptImportError() {
}
});
List<ScriptPack> packs;
@@ -3791,6 +3796,10 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
public void scriptImported() {
countAs3++;
}
@Override
public void scriptImportError() {
}
}
);