single file script export setting added to ScriptExportSettings class

This commit is contained in:
honfika@gmail.com
2015-03-31 21:28:26 +02:00
parent b7a8adc643
commit 9813f62cdf
7 changed files with 56 additions and 43 deletions

View File

@@ -65,6 +65,7 @@ import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.exporters.script.AS2ScriptExporter;
import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings;
import com.jpexs.decompiler.flash.helpers.HighlightedText;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.ImageHelper;
@@ -1131,7 +1132,7 @@ public final class SWF implements SWFContainerItem, Timelined {
return true;
}
public boolean exportAS3Class(String className, String outdir, ScriptExportMode exportMode, boolean parallel, EventListener evl) throws Exception {
public boolean exportAS3Class(String className, String outdir, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) throws Exception {
boolean exported = false;
List<ABCContainerTag> abcList = getAbcList();
@@ -1146,7 +1147,7 @@ public final class SWF implements SWFContainerItem, Timelined {
}
String eventData = cnt + scr.getPath() + " ...";
evl.handleExportingEvent("tag", i + 1, abcList.size(), eventData);
scr.export(outdir, exportMode, parallel);
scr.export(outdir, exportSettings, parallel);
evl.handleExportedEvent("tag", i + 1, abcList.size(), eventData);
exported = true;
}
@@ -1193,7 +1194,7 @@ public final class SWF implements SWFContainerItem, Timelined {
String directory;
ScriptExportMode exportMode;
ScriptExportSettings exportSettings;
ClassPath path;
@@ -1211,10 +1212,10 @@ public final class SWF implements SWFContainerItem, Timelined {
EventListener eventListener;
public ExportPackTask(AbortRetryIgnoreHandler handler, AtomicInteger index, int count, ClassPath path, ScriptPack pack, String directory, ScriptExportMode exportMode, boolean parallel, EventListener evl) {
public ExportPackTask(AbortRetryIgnoreHandler handler, AtomicInteger index, int count, ClassPath path, ScriptPack pack, String directory, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) {
this.pack = pack;
this.directory = directory;
this.exportMode = exportMode;
this.exportSettings = exportSettings;
this.path = path;
this.index = index;
this.count = count;
@@ -1229,7 +1230,7 @@ public final class SWF implements SWFContainerItem, Timelined {
@Override
public void run() throws IOException {
startTime = System.currentTimeMillis();
this.result = pack.export(directory, exportMode, parallel);
this.result = pack.export(directory, exportSettings, parallel);
stopTime = System.currentTimeMillis();
}
};
@@ -1250,7 +1251,7 @@ public final class SWF implements SWFContainerItem, Timelined {
}
}
private List<File> exportActionScript2(AbortRetryIgnoreHandler handler, String outdir, ScriptExportMode exportMode, boolean parallel, EventListener evl) throws IOException {
private List<File> exportActionScript2(AbortRetryIgnoreHandler handler, String outdir, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) throws IOException {
List<File> ret = new ArrayList<>();
if (!outdir.endsWith(File.separator)) {
@@ -1258,11 +1259,11 @@ public final class SWF implements SWFContainerItem, Timelined {
}
outdir += "scripts" + File.separator;
ret.addAll(new AS2ScriptExporter().exportAS2ScriptsTimeout(handler, outdir, getASMs(true), exportMode, evl));
ret.addAll(new AS2ScriptExporter().exportAS2ScriptsTimeout(handler, outdir, getASMs(true), exportSettings, evl));
return ret;
}
private List<File> exportActionScript3(final AbortRetryIgnoreHandler handler, final String outdir, final ScriptExportMode exportMode, final boolean parallel, final EventListener evl) {
private List<File> exportActionScript3(final AbortRetryIgnoreHandler handler, final String outdir, final ScriptExportSettings exportSettings, final boolean parallel, final EventListener evl) {
final AtomicInteger cnt = new AtomicInteger(1);
final List<File> ret = new ArrayList<>();
@@ -1274,7 +1275,7 @@ public final class SWF implements SWFContainerItem, Timelined {
@Override
public Void call() throws Exception {
for (ScriptPack item : packs) {
ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportMode, parallel, evl);
ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportSettings, parallel, evl);
ret.add(task.call());
}
return null;
@@ -1289,7 +1290,7 @@ public final class SWF implements SWFContainerItem, Timelined {
ExecutorService executor = Executors.newFixedThreadPool(Configuration.getParallelThreadCount());
List<Future<File>> futureResults = new ArrayList<>();
for (ScriptPack item : packs) {
Future<File> future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportMode, parallel, evl));
Future<File> future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportSettings, parallel, evl));
futureResults.add(future);
}
@@ -1343,13 +1344,13 @@ public final class SWF implements SWFContainerItem, Timelined {
return evl;
}
public List<File> exportActionScript(AbortRetryIgnoreHandler handler, String outdir, ScriptExportMode exportMode, boolean parallel, EventListener evl) throws IOException {
public List<File> exportActionScript(AbortRetryIgnoreHandler handler, String outdir, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) throws IOException {
List<File> ret = new ArrayList<>();
if (isAS3()) {
ret.addAll(exportActionScript3(handler, outdir, exportMode, parallel, evl));
ret.addAll(exportActionScript3(handler, outdir, exportSettings, parallel, evl));
} else {
ret.addAll(exportActionScript2(handler, outdir, exportMode, parallel, evl));
ret.addAll(exportActionScript2(handler, outdir, exportSettings, parallel, evl));
}
return ret;
}

View File

@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings;
import com.jpexs.decompiler.flash.helpers.FileTextWriter;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
@@ -186,7 +187,7 @@ public class ScriptPack extends AS3ClassTreeItem {
appendTo(writer, traits, exportMode, parallel);
}
public File export(String directory, ScriptExportMode exportMode, boolean parallel) throws IOException {
public File export(String directory, ScriptExportSettings exportSettings, boolean parallel) throws IOException {
String scriptName = getPathScriptName();
String packageName = getPathPackage();
File outDir = new File(directory + File.separatorChar + "scripts" + File.separatorChar + makeDirPath(packageName));
@@ -202,14 +203,14 @@ public class ScriptPack extends AS3ClassTreeItem {
File file = new File(fileName);
try (FileTextWriter writer = new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(file))) {
try {
toSource(writer, abc.script_info.get(scriptIndex).traits.traits, exportMode, parallel);
toSource(writer, abc.script_info.get(scriptIndex).traits.traits, exportSettings.mode, parallel);
} catch (InterruptedException ex) {
Logger.getLogger(ScriptPack.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(ScriptPack.class.getName()).log(Level.SEVERE, "The file path is probably too long", ex);
}
return file;
}

View File

@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.EventListener;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings;
import com.jpexs.decompiler.flash.helpers.FileTextWriter;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.graph.TranslateException;
@@ -49,13 +50,13 @@ public class AS2ScriptExporter {
private static final Logger logger = Logger.getLogger(AS2ScriptExporter.class.getName());
public List<File> exportAS2ScriptsTimeout(final AbortRetryIgnoreHandler handler, final String outdir, final Map<String, ASMSource> asms, final ScriptExportMode exportMode, final EventListener evl) throws IOException {
public List<File> exportAS2ScriptsTimeout(final AbortRetryIgnoreHandler handler, final String outdir, final Map<String, ASMSource> asms, final ScriptExportSettings exportSettings, final EventListener evl) throws IOException {
try {
List<File> result = CancellableWorker.call(new Callable<List<File>>() {
@Override
public List<File> call() throws Exception {
return exportAS2Scripts(handler, outdir, asms, exportMode, evl);
return exportAS2Scripts(handler, outdir, asms, exportSettings, evl);
}
}, Configuration.exportTimeout.get(), TimeUnit.SECONDS);
return result;
@@ -67,7 +68,7 @@ public class AS2ScriptExporter {
return new ArrayList<>();
}
private List<File> exportAS2Scripts(AbortRetryIgnoreHandler handler, String outdir, Map<String, ASMSource> asms, ScriptExportMode exportMode, EventListener evl) throws IOException {
private List<File> exportAS2Scripts(AbortRetryIgnoreHandler handler, String outdir, Map<String, ASMSource> asms, ScriptExportSettings exportSettings, EventListener evl) throws IOException {
List<File> ret = new ArrayList<>();
if (!outdir.endsWith(File.separator)) {
outdir += File.separator;
@@ -95,7 +96,7 @@ public class AS2ScriptExporter {
}
existingNames.add(name);
File f = exportAS2Script(handler, currentOutDir, asm, exportMode, evl, cnt, asms.size(), name);
File f = exportAS2Script(handler, currentOutDir, asm, exportSettings, evl, cnt, asms.size(), name);
if (f != null) {
ret.add(f);
}
@@ -104,7 +105,7 @@ public class AS2ScriptExporter {
return ret;
}
private File exportAS2Script(AbortRetryIgnoreHandler handler, String outdir, ASMSource asm, ScriptExportMode exportMode, EventListener evl, AtomicInteger index, int count, String name) throws IOException {
private File exportAS2Script(AbortRetryIgnoreHandler handler, String outdir, ASMSource asm, ScriptExportSettings exportSettings, EventListener evl, AtomicInteger index, int count, String name) throws IOException {
boolean retry;
do {
retry = false;
@@ -129,6 +130,7 @@ public class AS2ScriptExporter {
File file = new File(f);
try (FileTextWriter writer = new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(f))) {
ScriptExportMode exportMode = exportSettings.mode;
if (exportMode == ScriptExportMode.HEX) {
asm.getActionSourcePrefix(writer);
asm.getActionBytesAsHex(writer);

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library 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
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.exporters.settings;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
@@ -25,7 +26,10 @@ public class ScriptExportSettings {
public ScriptExportMode mode;
public boolean singleFile;
public ScriptExportSettings(ScriptExportMode mode, boolean singleFile) {
this.mode = mode;
this.singleFile = singleFile;
}
}

View File

@@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
import com.jpexs.decompiler.flash.exporters.modes.MovieExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode;
import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.ImageHelper;
import com.jpexs.decompiler.flash.tags.CSMTextSettingsTag;
@@ -3041,7 +3042,8 @@ public class XFLConverter {
}
if (useAS3) {
try {
swf.exportActionScript(handler, outDir.getAbsolutePath(), ScriptExportMode.AS, parallel, null);
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(ScriptExportMode.AS, false);
swf.exportActionScript(handler, outDir.getAbsolutePath(), scriptExportSettings, parallel, null);
} catch (Exception ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, "Error during ActionScript3 export", ex);
}

View File

@@ -63,6 +63,7 @@ import com.jpexs.decompiler.flash.exporters.settings.FramesExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.ImageExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.MorphShapeExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.MovieExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.ShapeExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.SoundExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings;
@@ -733,19 +734,19 @@ public class CommandLineArgumentParser {
System.err.println("stdOut parameter expected");
badArguments();
}
stdOut = args.pop();
}
private static void parseStdErr(Stack<String> args) {
if (args.isEmpty()) {
System.err.println("stdErr parameter expected");
badArguments();
}
stdErr = args.pop();
}
private static void parseAffinity(Stack<String> args) {
if (Platform.isWindows()) {
if (args.isEmpty()) {
@@ -919,18 +920,18 @@ public class CommandLineArgumentParser {
if (stdOut != null) {
System.setOut(new PrintStream(new FileOutputStream(stdOut.replace("{swfFile}", inFileName), true)));
}
if (stdErr != null) {
System.setErr(new PrintStream(new FileOutputStream(stdErr.replace("{swfFile}", inFileName), true)));
Main.initLogging(Configuration.debugMode.get());
}
long startTimeSwf = 0;
if (!singleFile) {
startTimeSwf = System.currentTimeMillis();
System.out.println("Start exporting " + inFile.getName());
}
SWF exfile = new SWF(new FileInputStream(inFile), Configuration.parallelSpeedUp.get());
exfile.swfList = new SWFList();
exfile.swfList.sourceInfo = new SWFSourceInfo(null, inFile.getAbsolutePath(), inFile.getName());
@@ -1052,6 +1053,7 @@ public class CommandLineArgumentParser {
new FrameExporter().exportFrames(handler, outDir + (multipleExportTypes ? File.separator + "frames" : ""), exfile, 0, frames, new FramesExportSettings(enumFromStr(formats.get("frame"), FramesExportMode.class), zoom), evl);
}
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(enumFromStr(formats.get("script"), ScriptExportMode.class), Configuration.textExportSingleFile.get());
if (exportAll || exportFormats.contains("script")) {
System.out.println("Exporting scripts...");
boolean parallel = Configuration.parallelSpeedUp.get();
@@ -1060,10 +1062,10 @@ public class CommandLineArgumentParser {
}
if (!as3classes.isEmpty()) {
for (String as3class : as3classes) {
exportOK = exportOK && exfile.exportAS3Class(as3class, outDir, enumFromStr(formats.get("script"), ScriptExportMode.class), parallel, evl);
exportOK = exportOK && exfile.exportAS3Class(as3class, outDir, scriptExportSettings, parallel, evl);
}
} else {
exportOK = exportOK && exfile.exportActionScript(handler, outDir, enumFromStr(formats.get("script"), ScriptExportMode.class), parallel, evl) != null;
exportOK = exportOK && exfile.exportActionScript(handler, outDir, scriptExportSettings, parallel, evl) != null;
}
}
@@ -1090,7 +1092,7 @@ public class CommandLineArgumentParser {
long time = stopTimeSwf - startTimeSwf;
System.out.println("Export finished: " + inFile.getName() + " Export time: " + Helper.formatTimeSec(time));
}
exfile.clearAllCache();
}
} catch (OutOfMemoryError | Exception ex) {

View File

@@ -56,6 +56,7 @@ import com.jpexs.decompiler.flash.exporters.settings.FramesExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.ImageExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.MorphShapeExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.MovieExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.ShapeExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.SoundExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings;
@@ -1091,7 +1092,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
EventListener evl = swf.getExportEventListener();
final ScriptExportMode scriptMode = export.getValue(ScriptExportMode.class);
ret.addAll(new ImageExporter().exportImages(handler, selFile + File.separator + "images", images,
new ImageExportSettings(export.getValue(ImageExportMode.class)), evl));
ret.addAll(new ShapeExporter().exportShapes(handler, selFile + File.separator + "shapes", shapes,
@@ -1118,15 +1118,16 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
ret.addAll(frameExporter.exportFrames(handler, selFile + File.separator + subFolder, swf, containerId, entry.getValue(), fes, evl));
}
ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), Configuration.textExportSingleFile.get());
if (swf.isAS3()) {
for (int i = 0; i < as3scripts.size(); i++) {
ScriptPack tls = as3scripts.get(i);
Main.startWork(translate("work.exporting") + " " + (i + 1) + "/" + as3scripts.size() + " " + tls.getPath() + " ...");
ret.add(tls.export(selFile, scriptMode, Configuration.parallelSpeedUp.get()));
ret.add(tls.export(selFile, scriptExportSettings, Configuration.parallelSpeedUp.get()));
}
} else {
Map<String, ASMSource> asmsToExport = swf.getASMs(true, as12scripts, false);
ret.addAll(new AS2ScriptExporter().exportAS2ScriptsTimeout(handler, selFile + File.separator + "scripts", asmsToExport, scriptMode, evl));
ret.addAll(new AS2ScriptExporter().exportAS2ScriptsTimeout(handler, selFile + File.separator + "scripts", asmsToExport, scriptExportSettings, evl));
}
}
return ret;
@@ -1161,8 +1162,8 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}
}
ScriptExportMode exportMode = export.getValue(ScriptExportMode.class);
swf.exportActionScript(handler, selFile, exportMode, Configuration.parallelSpeedUp.get(), evl);
ScriptExportSettings exportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), Configuration.textExportSingleFile.get());
swf.exportActionScript(handler, selFile, exportSettings, Configuration.parallelSpeedUp.get(), evl);
}
public List<SWFList> getSwfs() {