diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 546fcc5e1..9d92e6d59 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -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.script.AS3ScriptExporter; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; import com.jpexs.decompiler.flash.helpers.HighlightedText; import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter; @@ -130,7 +131,6 @@ import com.jpexs.decompiler.graph.TranslateStack; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Cache; -import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.NulStream; import com.jpexs.helpers.ProgressListener; @@ -161,14 +161,6 @@ import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.Stack; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.DeflaterOutputStream; @@ -1204,136 +1196,6 @@ public final class SWF implements SWFContainerItem, Timelined { return displayRect; } - private class ExportPackTask implements Callable { - - ScriptPack pack; - - String directory; - - ScriptExportSettings exportSettings; - - ClassPath path; - - AtomicInteger index; - - int count; - - boolean parallel; - - AbortRetryIgnoreHandler handler; - - long startTime; - - long stopTime; - - EventListener eventListener; - - 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.exportSettings = exportSettings; - this.path = path; - this.index = index; - this.count = count; - this.parallel = parallel; - this.handler = handler; - this.eventListener = evl; - } - - @Override - public File call() throws Exception { - RunnableIOExResult rio = new RunnableIOExResult() { - @Override - public void run() throws IOException { - startTime = System.currentTimeMillis(); - this.result = pack.export(directory, exportSettings, parallel); - stopTime = System.currentTimeMillis(); - } - }; - int currentIndex = index.getAndIncrement(); - if (eventListener != null) { - synchronized (ABC.class) { - eventListener.handleExportingEvent("script", currentIndex, count, path); - } - } - new RetryTask(rio, handler).run(); - if (eventListener != null) { - synchronized (ABC.class) { - long time = stopTime - startTime; - eventListener.handleExportedEvent("script", currentIndex, count, path + ", " + Helper.formatTimeSec(time)); - } - } - return rio.result; - } - } - - private List exportActionScript2(AbortRetryIgnoreHandler handler, String outdir, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) throws IOException { - List ret = new ArrayList<>(); - - if (!outdir.endsWith(File.separator)) { - outdir += File.separator; - } - - ret.addAll(new AS2ScriptExporter().exportAS2ScriptsTimeout(handler, outdir, getASMs(true), exportSettings, evl)); - return ret; - } - - private List exportActionScript3(final AbortRetryIgnoreHandler handler, final String outdir, final ScriptExportSettings exportSettings, final boolean parallel, final EventListener evl) { - final AtomicInteger cnt = new AtomicInteger(1); - - final List ret = new ArrayList<>(); - final List packs = getAS3Packs(); - - if (!parallel || packs.size() < 2) { - try { - CancellableWorker.call(new Callable() { - @Override - public Void call() throws Exception { - for (ScriptPack item : packs) { - ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportSettings, parallel, evl); - ret.add(task.call()); - } - return null; - } - }, Configuration.exportTimeout.get(), TimeUnit.SECONDS); - } catch (TimeoutException ex) { - logger.log(Level.SEVERE, Helper.formatTimeToText(Configuration.exportTimeout.get()) + " ActionScript export limit reached", ex); - } catch (Exception ex) { - logger.log(Level.SEVERE, "Error during ABC export", ex); - } - } else { - ExecutorService executor = Executors.newFixedThreadPool(Configuration.getParallelThreadCount()); - List> futureResults = new ArrayList<>(); - for (ScriptPack item : packs) { - Future future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportSettings, parallel, evl)); - futureResults.add(future); - } - - try { - executor.shutdown(); - if (!executor.awaitTermination(Configuration.exportTimeout.get(), TimeUnit.SECONDS)) { - logger.log(Level.SEVERE, Helper.formatTimeToText(Configuration.exportTimeout.get()) + " ActionScript export limit reached"); - } - } catch (InterruptedException ex) { - } finally { - executor.shutdownNow(); - } - - for (int f = 0; f < futureResults.size(); f++) { - try { - if (futureResults.get(f).isDone()) { - ret.add(futureResults.get(f).get()); - } - } catch (InterruptedException ex) { - } catch (ExecutionException ex) { - logger.log(Level.SEVERE, "Error during ABC export", ex); - } - } - } - - return ret; - } - public EventListener getExportEventListener() { EventListener evl = new EventListener() { @Override @@ -1363,9 +1225,9 @@ public final class SWF implements SWFContainerItem, Timelined { List ret = new ArrayList<>(); if (isAS3()) { - ret.addAll(exportActionScript3(handler, outdir, exportSettings, parallel, evl)); + ret.addAll(new AS3ScriptExporter().exportActionScript3(this, handler, outdir, exportSettings, parallel, evl)); } else { - ret.addAll(exportActionScript2(handler, outdir, exportSettings, parallel, evl)); + ret.addAll(new AS2ScriptExporter().exportAS2ScriptsTimeout(handler, outdir, getASMs(true), exportSettings, evl)); } return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/TextExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/TextExporter.java index a69faa124..e74fb0a50 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/TextExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/TextExporter.java @@ -43,8 +43,6 @@ import java.util.List; */ public class TextExporter { - public static final String TEXT_EXPORT_FOLDER = "texts"; - public static final String TEXT_EXPORT_FILENAME_FORMATTED = "textsformatted.txt"; public static final String TEXT_EXPORT_FILENAME_PLAIN = "textsplain.txt"; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java index a0fa961b1..3fad0d23e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.exporters.script; import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler; import com.jpexs.decompiler.flash.EventListener; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; @@ -51,6 +52,10 @@ public class AS2ScriptExporter { private static final Logger logger = Logger.getLogger(AS2ScriptExporter.class.getName()); + public List exportActionScript2(SWF swf, AbortRetryIgnoreHandler handler, String outdir, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) throws IOException { + return exportAS2ScriptsTimeout(handler, outdir, swf.getASMs(true), exportSettings, evl); + } + public List exportAS2ScriptsTimeout(final AbortRetryIgnoreHandler handler, final String outdir, final Map asms, final ScriptExportSettings exportSettings, final EventListener evl) throws IOException { try { List result = CancellableWorker.call(new Callable>() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java new file mode 100644 index 000000000..6f8a86c5a --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java @@ -0,0 +1,104 @@ +/* + * 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. + */ +package com.jpexs.decompiler.flash.exporters.script; + +import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler; +import com.jpexs.decompiler.flash.EventListener; +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.abc.ScriptPack; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; +import com.jpexs.helpers.CancellableWorker; +import com.jpexs.helpers.Helper; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author JPEXS + */ +public class AS3ScriptExporter { + + private static final Logger logger = Logger.getLogger(AS3ScriptExporter.class.getName()); + + public List exportActionScript3(SWF swf, final AbortRetryIgnoreHandler handler, final String outdir, final ScriptExportSettings exportSettings, final boolean parallel, final EventListener evl) { + final AtomicInteger cnt = new AtomicInteger(1); + + final List ret = new ArrayList<>(); + final List packs = swf.getAS3Packs(); + + if (!parallel || packs.size() < 2) { + try { + CancellableWorker.call(new Callable() { + @Override + public Void call() throws Exception { + for (ScriptPack item : packs) { + ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportSettings, parallel, evl); + ret.add(task.call()); + } + return null; + } + }, Configuration.exportTimeout.get(), TimeUnit.SECONDS); + } catch (TimeoutException ex) { + logger.log(Level.SEVERE, Helper.formatTimeToText(Configuration.exportTimeout.get()) + " ActionScript export limit reached", ex); + } catch (Exception ex) { + logger.log(Level.SEVERE, "Error during ABC export", ex); + } + } else { + ExecutorService executor = Executors.newFixedThreadPool(Configuration.getParallelThreadCount()); + List> futureResults = new ArrayList<>(); + for (ScriptPack item : packs) { + Future future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportSettings, parallel, evl)); + futureResults.add(future); + } + + try { + executor.shutdown(); + if (!executor.awaitTermination(Configuration.exportTimeout.get(), TimeUnit.SECONDS)) { + logger.log(Level.SEVERE, Helper.formatTimeToText(Configuration.exportTimeout.get()) + " ActionScript export limit reached"); + } + } catch (InterruptedException ex) { + } finally { + executor.shutdownNow(); + } + + for (int f = 0; f < futureResults.size(); f++) { + try { + if (futureResults.get(f).isDone()) { + ret.add(futureResults.get(f).get()); + } + } catch (InterruptedException ex) { + } catch (ExecutionException ex) { + logger.log(Level.SEVERE, "Error during ABC export", ex); + } + } + } + + return ret; + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java new file mode 100644 index 000000000..e4898be16 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java @@ -0,0 +1,98 @@ +/* + * 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. + */ +package com.jpexs.decompiler.flash.exporters.script; + +import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler; +import com.jpexs.decompiler.flash.EventListener; +import com.jpexs.decompiler.flash.RetryTask; +import com.jpexs.decompiler.flash.RunnableIOExResult; +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.ClassPath; +import com.jpexs.decompiler.flash.abc.ScriptPack; +import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; +import com.jpexs.helpers.Helper; +import java.io.File; +import java.io.IOException; +import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * + * @author JPEXS + */ +public class ExportPackTask implements Callable { + + ScriptPack pack; + + String directory; + + ScriptExportSettings exportSettings; + + ClassPath path; + + AtomicInteger index; + + int count; + + boolean parallel; + + AbortRetryIgnoreHandler handler; + + long startTime; + + long stopTime; + + EventListener eventListener; + + 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.exportSettings = exportSettings; + this.path = path; + this.index = index; + this.count = count; + this.parallel = parallel; + this.handler = handler; + this.eventListener = evl; + } + + @Override + public File call() throws Exception { + RunnableIOExResult rio = new RunnableIOExResult() { + @Override + public void run() throws IOException { + startTime = System.currentTimeMillis(); + this.result = pack.export(directory, exportSettings, parallel); + stopTime = System.currentTimeMillis(); + } + }; + int currentIndex = index.getAndIncrement(); + if (eventListener != null) { + synchronized (ABC.class) { + eventListener.handleExportingEvent("script", currentIndex, count, path); + } + } + new RetryTask(rio, handler).run(); + if (eventListener != null) { + synchronized (ABC.class) { + long time = stopTime - startTime; + eventListener.handleExportedEvent("script", currentIndex, count, path + ", " + Helper.formatTimeSec(time)); + } + } + return rio.result; + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/ScriptExportSettings.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/ScriptExportSettings.java index d3b5c7bd7..adc967174 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/ScriptExportSettings.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/ScriptExportSettings.java @@ -25,6 +25,8 @@ import com.jpexs.decompiler.flash.helpers.FileTextWriter; */ public class ScriptExportSettings { + public static final String EXPORT_FOLDER_NAME = "scripts"; + public ScriptExportMode mode; public boolean singleFile; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/TextExportSettings.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/TextExportSettings.java index df7aca902..eac51a037 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/TextExportSettings.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/TextExportSettings.java @@ -24,6 +24,8 @@ import com.jpexs.decompiler.flash.exporters.modes.TextExportMode; */ public class TextExportSettings { + public static final String EXPORT_FOLDER_NAME = "texts"; + public TextExportMode mode; public boolean singleFile; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java new file mode 100644 index 000000000..c318c2150 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java @@ -0,0 +1,61 @@ +/* + * 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. + */ +package com.jpexs.decompiler.flash.importers; + +import com.jpexs.decompiler.flash.action.parser.ActionParseException; +import com.jpexs.decompiler.flash.tags.base.ASMSource; +import com.jpexs.decompiler.graph.CompilationException; +import com.jpexs.helpers.Helper; +import com.jpexs.helpers.Path; +import java.io.File; +import java.io.IOException; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author JPEXS + */ +public class ScriptImporter { + + private static final Logger logger = Logger.getLogger(ScriptImporter.class.getName()); + + public void importScripts(String scriptsFolder, Map asms) { + + for (String key : asms.keySet()) { + String fileName = Path.combine(scriptsFolder, key) + ".as"; + if (new File(fileName).exists()) { + ASMSource src = asms.get(key); + String as = Helper.readTextFile(fileName); + + com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser par = new com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser(src.getSwf().version); + try { + src.setActions(par.actionsFromString(as)); + } 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); + } 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); + } catch (IOException ex) { + logger.log(Level.SEVERE, "error during script import, file: %file%".replace("%file%", fileName), ex); + } + + src.setModified(); + } + } + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TextImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TextImporter.java index bc888a41f..2e57ea0c1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TextImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TextImporter.java @@ -18,7 +18,7 @@ package com.jpexs.decompiler.flash.importers; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.configuration.Configuration; -import com.jpexs.decompiler.flash.exporters.TextExporter; +import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler; import com.jpexs.decompiler.flash.tags.base.TextImportErrorHandler; @@ -111,7 +111,7 @@ public class TextImporter { } public void importTextsMultipleFiles(String folder, SWF swf) { - File textsFolder = new File(Path.combine(folder, TextExporter.TEXT_EXPORT_FOLDER)); + File textsFolder = new File(Path.combine(folder, TextExportSettings.EXPORT_FOLDER_NAME)); String[] files = textsFolder.list(new FilenameFilter() { private final Pattern pat = Pattern.compile("\\d+\\.txt", Pattern.CASE_INSENSITIVE); diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 2613a2314..7aa7e193f 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -1041,7 +1041,7 @@ public class CommandLineArgumentParser { if (singleTextFile == null) { singleTextFile = Configuration.textExportSingleFile.get(); } - new TextExporter().exportTexts(handler, outDir + (multipleExportTypes ? File.separator + "texts" : ""), extags, new TextExportSettings(enumFromStr(formats.get("text"), TextExportMode.class), singleTextFile, zoom), evl); + new TextExporter().exportTexts(handler, outDir + (multipleExportTypes ? File.separator + TextExportSettings.EXPORT_FOLDER_NAME : ""), extags, new TextExportSettings(enumFromStr(formats.get("text"), TextExportMode.class), singleTextFile, zoom), evl); } if (exportAll || exportFormats.contains("frame")) { @@ -1056,7 +1056,7 @@ public class CommandLineArgumentParser { } boolean parallel = Configuration.parallelSpeedUp.get(); - String scriptsFolder = Path.combine(outDir, "scripts"); + String scriptsFolder = Path.combine(outDir, ScriptExportSettings.EXPORT_FOLDER_NAME); Path.createDirectorySafe(new File(scriptsFolder)); Boolean singleScriptFile = parseBooleanConfigValue(formats.get("singlescript")); if (singleScriptFile == null) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 888d29dec..da952343b 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -162,6 +162,10 @@ public abstract class MainFrameMenu { mainFrame.getPanel().importText(swf); } + protected void importScript() { + mainFrame.getPanel().importScript(swf); + } + protected void importSymbolClass() { mainFrame.getPanel().importSymbolClass(swf); } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index ae601f3ce..cf96079f3 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -139,6 +139,8 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener private static final String ACTION_IMPORT_TEXT = "IMPORTTEXT"; + private static final String ACTION_IMPORT_SCRIPT = "IMPORTSCRIPT"; + private static final String ACTION_IMPORT_SYMBOL_CLASS = "IMPORTSYMBOLCLASS"; private static final String ACTION_CHECK_UPDATES = "CHECKUPDATES"; @@ -199,6 +201,8 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener private JCommandButton importTextCommandButton; + private JCommandButton importScriptCommandButton; + private JCommandButton importSymbolClassCommandButton; private JCommandButton importXmlCommandButton; @@ -448,6 +452,10 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener importTextCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.import.text")), View.getResizableIcon("importtext32")); assignListener(importTextCommandButton, ACTION_IMPORT_TEXT); + // todo: icon + importScriptCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.import.script")), View.getResizableIcon("importtext32")); + assignListener(importScriptCommandButton, ACTION_IMPORT_SCRIPT); + importSymbolClassCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.import.symbolClass")), View.getResizableIcon("importsymbolclass32")); assignListener(importSymbolClassCommandButton, ACTION_IMPORT_SYMBOL_CLASS); @@ -456,6 +464,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener importBand.addCommandButton(importXmlCommandButton, RibbonElementPriority.TOP); importBand.addCommandButton(importTextCommandButton, RibbonElementPriority.MEDIUM); + importBand.addCommandButton(importScriptCommandButton, RibbonElementPriority.MEDIUM); importBand.addCommandButton(importSymbolClassCommandButton, RibbonElementPriority.MEDIUM); JRibbonBand viewBand = new JRibbonBand(translate("menu.view"), null); @@ -782,6 +791,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener exportXmlCommandButton.setEnabled(swfLoaded); exportSelectionCommandButton.setEnabled(swfLoaded); importTextCommandButton.setEnabled(swfLoaded); + importScriptCommandButton.setEnabled(swfLoaded); importSymbolClassCommandButton.setEnabled(swfLoaded); importXmlCommandButton.setEnabled(swfLoaded); reloadCommandButton.setEnabled(swfLoaded); @@ -994,6 +1004,9 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener case ACTION_IMPORT_TEXT: importText(); break; + case ACTION_IMPORT_SCRIPT: + importScript(); + break; case ACTION_IMPORT_SYMBOL_CLASS: importSymbolClass(); break; diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 9c2e9a1cb..d549db92c 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -80,6 +80,7 @@ import com.jpexs.decompiler.flash.helpers.FileTextWriter; import com.jpexs.decompiler.flash.helpers.Freed; import com.jpexs.decompiler.flash.importers.BinaryDataImporter; import com.jpexs.decompiler.flash.importers.ImageImporter; +import com.jpexs.decompiler.flash.importers.ScriptImporter; import com.jpexs.decompiler.flash.importers.ShapeImporter; import com.jpexs.decompiler.flash.importers.SwfXmlImporter; import com.jpexs.decompiler.flash.importers.SymbolClassImporter; @@ -1090,7 +1091,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec new ShapeExportSettings(export.getValue(ShapeExportMode.class), export.getZoom()), evl)); ret.addAll(new MorphShapeExporter().exportMorphShapes(handler, selFile + File.separator + "morphshapes", morphshapes, new MorphShapeExportSettings(export.getValue(MorphShapeExportMode.class), export.getZoom()), evl)); - ret.addAll(new TextExporter().exportTexts(handler, selFile + File.separator + "texts", texts, + ret.addAll(new TextExporter().exportTexts(handler, selFile + File.separator + TextExportSettings.EXPORT_FOLDER_NAME, texts, new TextExportSettings(export.getValue(TextExportMode.class), Configuration.textExportSingleFile.get(), export.getZoom()), evl)); ret.addAll(new MovieExporter().exportMovies(handler, selFile + File.separator + "movies", movies, new MovieExportSettings(export.getValue(MovieExportMode.class)), evl)); @@ -1120,7 +1121,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } boolean parallel = Configuration.parallelSpeedUp.get(); - String scriptsFolder = Path.combine(selFile, "scripts"); + String scriptsFolder = Path.combine(selFile, ScriptExportSettings.EXPORT_FOLDER_NAME); Path.createDirectorySafe(new File(scriptsFolder)); ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), !parallel && Configuration.scriptExportSingleFile.get()); String singleFileName = Path.combine(scriptsFolder, swf.getShortFileName() + scriptExportSettings.getFileExtension()); @@ -1152,7 +1153,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec new ShapeExportSettings(export.getValue(ShapeExportMode.class), export.getZoom()), evl); new MorphShapeExporter().exportMorphShapes(handler, selFile + File.separator + "morphshapes", swf.tags, new MorphShapeExportSettings(export.getValue(MorphShapeExportMode.class), export.getZoom()), evl); - new TextExporter().exportTexts(handler, selFile + File.separator + "texts", swf.tags, + new TextExporter().exportTexts(handler, selFile + File.separator + TextExportSettings.EXPORT_FOLDER_NAME, swf.tags, new TextExportSettings(export.getValue(TextExportMode.class), Configuration.textExportSingleFile.get(), export.getZoom()), evl); new MovieExporter().exportMovies(handler, selFile + File.separator + "movies", swf.tags, new MovieExportSettings(export.getValue(MovieExportMode.class)), evl); @@ -1174,7 +1175,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } boolean parallel = Configuration.parallelSpeedUp.get(); - String scriptsFolder = Path.combine(selFile, "scripts"); + String scriptsFolder = Path.combine(selFile, ScriptExportSettings.EXPORT_FOLDER_NAME); Path.createDirectorySafe(new File(scriptsFolder)); ScriptExportSettings scriptExportSettings = new ScriptExportSettings(export.getValue(ScriptExportMode.class), !parallel && Configuration.scriptExportSingleFile.get()); String singleFileName = Path.combine(scriptsFolder, swf.getShortFileName() + scriptExportSettings.getFileExtension()); @@ -1629,7 +1630,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String selFile = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath(); - File textsFile = new File(Path.combine(selFile, TextExporter.TEXT_EXPORT_FOLDER, TextExporter.TEXT_EXPORT_FILENAME_FORMATTED)); + File textsFile = new File(Path.combine(selFile, TextExportSettings.EXPORT_FOLDER_NAME, TextExporter.TEXT_EXPORT_FILENAME_FORMATTED)); TextImporter textImporter = new TextImporter(getMissingCharacterHandler(), new TextImportErrorHandler() { // "configuration items" for the current replace only @@ -1665,7 +1666,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (textsFile.exists()) { textImporter.importTextsSingleFileFormatted(textsFile, swf); } else { - textsFile = new File(Path.combine(selFile, TextExporter.TEXT_EXPORT_FOLDER, TextExporter.TEXT_EXPORT_FILENAME_PLAIN)); + textsFile = new File(Path.combine(selFile, TextExportSettings.EXPORT_FOLDER_NAME, TextExporter.TEXT_EXPORT_FILENAME_PLAIN)); // try to import plain texts if (textsFile.exists()) { textImporter.importTextsSingleFile(textsFile, swf); @@ -1679,6 +1680,22 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } + public void importScript(final SWF swf) { + JFileChooser chooser = new JFileChooser(); + chooser.setCurrentDirectory(new File(Configuration.lastExportDir.get())); + chooser.setDialogTitle(translate("import.select.directory")); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setAcceptAllFileFilterUsed(false); + if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { + String selFile = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath(); + String scriptsFolder = Path.combine(selFile, ScriptExportSettings.EXPORT_FOLDER_NAME); + + new ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true)); + + reload(true); + } + } + public void importSymbolClass(final SWF swf) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(Configuration.lastExportDir.get())); diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index cca6578b3..0d4fb8849 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -580,3 +580,4 @@ text.toggleCase = Toggle case #after version 5.0.2 preview.loop = Loop +menu.file.import.script = Import script diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties index 79bcadaec..e105c1e43 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties @@ -579,3 +579,4 @@ text.toggleCase = Kis- nagybet\u0171 v\u00e1ltoztat\u00e1s #after version 5.0.2 preview.loop = Ism\u00e9tl\u00e9s +menu.file.import.script = Szkript import\u00e1l\u00e1sa