From 93a09b4c59ebb9dd81ee0f2c1d40d02a3baf796b Mon Sep 17 00:00:00 2001 From: Dofera Date: Thu, 15 Sep 2022 10:05:37 +0200 Subject: [PATCH] Add Symbol-Class export support for commandline --- .../flash/exporters/SymbolClassExporter.java | 31 ++++++++++------- .../settings/SymbolClassExportSettings.java | 34 +++++++++++++++++++ .../console/CommandLineArgumentParser.java | 10 ++++++ .../jpexs/decompiler/flash/gui/MainPanel.java | 10 ++++-- 4 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/SymbolClassExportSettings.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SymbolClassExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SymbolClassExporter.java index 130fa8384..96fc2da3c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SymbolClassExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SymbolClassExporter.java @@ -15,8 +15,11 @@ * License along with this library. */ package com.jpexs.decompiler.flash.exporters; +import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler; import com.jpexs.decompiler.flash.EventListener; import com.jpexs.decompiler.flash.ReadOnlyTagList; +import com.jpexs.decompiler.flash.RetryTask; +import com.jpexs.decompiler.flash.exporters.settings.SymbolClassExportSettings; import com.jpexs.decompiler.flash.tags.ExportAssetsTag; import com.jpexs.decompiler.flash.tags.SymbolClassTag; import com.jpexs.decompiler.flash.tags.Tag; @@ -39,7 +42,7 @@ public class SymbolClassExporter { public static final String SYMBOL_CLASS_EXPORT_FILENAME = "symbols.csv"; - public List exportNames(final String outdir, ReadOnlyTagList tags, EventListener evl) throws IOException { + public List exportNames(AbortRetryIgnoreHandler handler, final String outdir, ReadOnlyTagList tags, SymbolClassExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); int count = 0; for (Tag t : tags) { @@ -56,21 +59,23 @@ public class SymbolClassExporter { Path.createDirectorySafe(foutdir); final File file = new File(outdir + File.separator + SYMBOL_CLASS_EXPORT_FILENAME); - try (Writer writer = new BufferedWriter(new Utf8OutputStreamWriter(new FileOutputStream(file)))) { - for (Tag t : tags) { - if (t instanceof ExportAssetsTag) { - ExportAssetsTag eat = (ExportAssetsTag) t; - for (int i = 0; i < eat.tags.size(); i++) { - writer.append(eat.tags.get(i) + ";" + eat.names.get(i) + Helper.newLine); - } - } else if (t instanceof SymbolClassTag) { - SymbolClassTag sct = (SymbolClassTag) t; - for (int i = 0; i < sct.tags.size(); i++) { - writer.append(sct.tags.get(i) + ";" + sct.names.get(i) + Helper.newLine); + new RetryTask(() -> { + try (Writer writer = new BufferedWriter(new Utf8OutputStreamWriter(new FileOutputStream(file)))) { + for (Tag t : tags) { + if (t instanceof ExportAssetsTag) { + ExportAssetsTag eat = (ExportAssetsTag) t; + for (int i = 0; i < eat.tags.size(); i++) { + writer.append(eat.tags.get(i) + ";" + eat.names.get(i) + Helper.newLine); + } + } else if (t instanceof SymbolClassTag) { + SymbolClassTag sct = (SymbolClassTag) t; + for (int i = 0; i < sct.tags.size(); i++) { + writer.append(sct.tags.get(i) + ";" + sct.names.get(i) + Helper.newLine); + } } } } - } + }, handler).run(); ret.add(file); return ret; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/SymbolClassExportSettings.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/SymbolClassExportSettings.java new file mode 100644 index 000000000..3f2bbe7c3 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/SymbolClassExportSettings.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010-2022 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.settings; + +import com.jpexs.decompiler.flash.exporters.modes.SymbolClassExportMode; + +/** + * + * @author Dofera + */ +public class SymbolClassExportSettings { + + public static final String EXPORT_FOLDER_NAME = "symbolClass"; + + public SymbolClassExportMode mode; + + public SymbolClassExportSettings(SymbolClassExportMode mode) { + this.mode = mode; + } +} diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 4f897d2fd..2b5c79e85 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -60,6 +60,7 @@ import com.jpexs.decompiler.flash.exporters.MorphShapeExporter; import com.jpexs.decompiler.flash.exporters.MovieExporter; import com.jpexs.decompiler.flash.exporters.ShapeExporter; import com.jpexs.decompiler.flash.exporters.SoundExporter; +import com.jpexs.decompiler.flash.exporters.SymbolClassExporter; import com.jpexs.decompiler.flash.exporters.TextExporter; import com.jpexs.decompiler.flash.exporters.amf.amf3.Amf3Exporter; import com.jpexs.decompiler.flash.exporters.commonshape.Matrix; @@ -74,6 +75,7 @@ import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.exporters.modes.ShapeExportMode; import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode; import com.jpexs.decompiler.flash.exporters.modes.SpriteExportMode; +import com.jpexs.decompiler.flash.exporters.modes.SymbolClassExportMode; import com.jpexs.decompiler.flash.exporters.modes.TextExportMode; import com.jpexs.decompiler.flash.exporters.script.LinkReportExporter; import com.jpexs.decompiler.flash.exporters.settings.BinaryDataExportSettings; @@ -87,6 +89,7 @@ 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.SpriteExportSettings; +import com.jpexs.decompiler.flash.exporters.settings.SymbolClassExportSettings; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.exporters.swf.SwfToSwcExporter; import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter; @@ -339,6 +342,7 @@ public class CommandLineArgumentParser { out.println(" button - Buttons (Default format: PNG)"); out.println(" sound - Sounds (Default format: MP3/WAV/FLV only sound)"); out.println(" binaryData - Binary data (Default format: Raw data)"); + out.println(" symbolClass - Symbol-Class mapping (Default format: CSV)"); out.println(" text - Texts (Default format: Plain text)"); out.println(" all - Every resource (but not FLA and XFL)"); out.println(" fla - Everything to FLA compressed format"); @@ -2109,6 +2113,7 @@ public class CommandLineArgumentParser { "button", "sound", "binarydata", + "symbolclass", "text", "all", "fla", @@ -2288,6 +2293,11 @@ public class CommandLineArgumentParser { new BinaryDataExporter().exportBinaryData(handler, outDir + (multipleExportTypes ? File.separator + BinaryDataExportSettings.EXPORT_FOLDER_NAME : ""), new ReadOnlyTagList(extags), new BinaryDataExportSettings(enumFromStr(formats.get("binarydata"), BinaryDataExportMode.class)), evl); } + if (exportAll || exportFormats.contains("symbolclass")) { + System.out.println("Exporting symbolClass..."); + new SymbolClassExporter().exportNames(handler, outDir + (multipleExportTypes ? File.separator + SymbolClassExportSettings.EXPORT_FOLDER_NAME : ""), new ReadOnlyTagList(extags), new SymbolClassExportSettings(enumFromStr(formats.get("symbolclass"), SymbolClassExportMode.class)), evl); + } + if (exportAll || exportFormats.contains("text")) { System.out.println("Exporting texts..."); Boolean singleTextFile = parseBooleanConfigValue(formats.get("singletext")); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index ae006a66f..833727841 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -73,6 +73,7 @@ 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.SpriteExportSettings; +import com.jpexs.decompiler.flash.exporters.settings.SymbolClassExportSettings; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.exporters.swf.SwfJavaExporter; import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter; @@ -1383,7 +1384,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } if (export.isOptionEnabled(SymbolClassExportMode.class)) { - ret.addAll(new SymbolClassExporter().exportNames(selFile2, new ReadOnlyTagList(symbolNames), evl)); + ret.addAll(new SymbolClassExporter().exportNames(handler, selFile2 + File.separator + SymbolClassExportSettings.EXPORT_FOLDER_NAME, new ReadOnlyTagList(symbolNames), + new SymbolClassExportSettings(export.getValue(SymbolClassExportMode.class)), evl)); } FrameExporter frameExporter = new FrameExporter(); @@ -1495,7 +1497,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } if (export.isOptionEnabled(SymbolClassExportMode.class)) { - new SymbolClassExporter().exportNames(selFile, swf.getTags(), evl); + new SymbolClassExporter().exportNames(handler, Path.combine(selFile, SymbolClassExportSettings.EXPORT_FOLDER_NAME), swf.getTags(), + new SymbolClassExportSettings(export.getValue(SymbolClassExportMode.class)), evl); } FrameExporter frameExporter = new FrameExporter(); @@ -1603,7 +1606,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (export.isOptionEnabled(SymbolClassExportMode.class)) { for (SymbolClassExportMode exportMode : SymbolClassExportMode.values()) { - new SymbolClassExporter().exportNames(selFile, swf.getTags(), evl); + new SymbolClassExporter().exportNames(handler, Path.combine(selFile, SymbolClassExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf.getTags(), + new SymbolClassExportSettings(exportMode), evl); } }