From 254b13a32689ce814343ff4a1db02305a37ac237 Mon Sep 17 00:00:00 2001 From: honfika Date: Tue, 5 Aug 2014 21:38:48 +0200 Subject: [PATCH] better export filename generation --- .../flash/exporters/FontExporter.java | 2 +- .../flash/exporters/ImageExporter.java | 6 +- .../flash/exporters/MovieExporter.java | 3 +- .../flash/exporters/TextExporter.java | 4 +- .../jpexs/decompiler/flash/gui/MainPanel.java | 2 +- .../flash/tags/base/CharacterIdTag.java | 155 +++++++++--------- .../flash/tags/base/CharacterTag.java | 23 +-- 7 files changed, 93 insertions(+), 102 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/exporters/FontExporter.java b/src/com/jpexs/decompiler/flash/exporters/FontExporter.java index 3801d411a..3a8064700 100644 --- a/src/com/jpexs/decompiler/flash/exporters/FontExporter.java +++ b/src/com/jpexs/decompiler/flash/exporters/FontExporter.java @@ -72,7 +72,7 @@ public class FontExporter { if (settings.mode == FontExportMode.WOFF) { ext = ".woff"; } - final File file = new File(outdir + File.separator + st.getCharacterExportFileName() + ext); + final File file = new File(outdir + File.separator + Helper.makeFileName(st.getCharacterExportFileName() + ext)); newfile = file; new RetryTask(new RunnableIOEx() { @Override diff --git a/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java b/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java index 1be54206e..c1fa43564 100644 --- a/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java +++ b/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.exporters.modes.ImageExportMode; import com.jpexs.decompiler.flash.exporters.settings.ImageExportSettings; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ImageTag; +import com.jpexs.helpers.Helper; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -60,14 +61,15 @@ public class ImageExporter { fileFormat = "jpg"; } - final File file = new File(outdir + File.separator + ((ImageTag) t).getExportFileName2() + "." + fileFormat); + final ImageTag imageTag = (ImageTag) t; + final File file = new File(outdir + File.separator + Helper.makeFileName(imageTag.getCharacterExportFileName() + "." + fileFormat)); final List ttags = tags; final String ffileFormat = fileFormat; new RetryTask(new RunnableIOEx() { @Override public void run() throws IOException { - ImageIO.write(((ImageTag) t).getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), file); + ImageIO.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), file); } }, handler).run(); ret.add(file); diff --git a/src/com/jpexs/decompiler/flash/exporters/MovieExporter.java b/src/com/jpexs/decompiler/flash/exporters/MovieExporter.java index 7f94935da..6c24a99cc 100644 --- a/src/com/jpexs/decompiler/flash/exporters/MovieExporter.java +++ b/src/com/jpexs/decompiler/flash/exporters/MovieExporter.java @@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.flv.VIDEODATA; import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.VideoFrameTag; +import com.jpexs.helpers.Helper; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -61,7 +62,7 @@ public class MovieExporter { for (Tag t : tags) { if (t instanceof DefineVideoStreamTag) { final DefineVideoStreamTag videoStream = (DefineVideoStreamTag) t; - final File file = new File(outdir + File.separator + ((DefineVideoStreamTag) t).getCharacterExportFileName() + ".flv"); + final File file = new File(outdir + File.separator + Helper.makeFileName(videoStream.getCharacterExportFileName() + ".flv")); new RetryTask(new RunnableIOEx() { @Override public void run() throws IOException { diff --git a/src/com/jpexs/decompiler/flash/exporters/TextExporter.java b/src/com/jpexs/decompiler/flash/exporters/TextExporter.java index 8da892159..225518c83 100644 --- a/src/com/jpexs/decompiler/flash/exporters/TextExporter.java +++ b/src/com/jpexs/decompiler/flash/exporters/TextExporter.java @@ -65,7 +65,7 @@ public class TextExporter { for (Tag t : tags) { if (t instanceof TextTag) { final TextTag textTag = (TextTag) t; - final File file = new File(outdir + File.separator + textTag.getExportFileName2()+ ".svg"); + final File file = new File(outdir + File.separator + Helper.makeFileName(textTag.getCharacterExportFileName()+ ".svg")); new RetryTask(new RunnableIOEx() { @Override public void run() throws IOException { @@ -110,7 +110,7 @@ public class TextExporter { for (Tag t : tags) { if (t instanceof TextTag) { final TextTag textTag = (TextTag) t; - final File file = new File(outdir + File.separator + textTag.getCharacterId() + ".txt"); + final File file = new File(outdir + File.separator + Helper.makeFileName(textTag.getCharacterExportFileName() + ".txt")); new RetryTask(new RunnableIOEx() { @Override public void run() throws IOException { diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 801d73292..ef2e1cebb 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1134,7 +1134,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (dumpInfo == null) { return null; } - + return DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf(); } diff --git a/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java b/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java index 219ab1b2d..7e12b4f61 100644 --- a/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java +++ b/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java @@ -1,76 +1,79 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.tags.base; - -import com.jpexs.decompiler.flash.SWF; -import com.jpexs.decompiler.flash.tags.ExportAssetsTag; -import com.jpexs.decompiler.flash.tags.Tag; -import com.jpexs.decompiler.flash.types.annotations.Internal; -import com.jpexs.helpers.ByteArrayRange; -import java.util.ArrayList; -import java.util.List; - -/** - * - * @author JPEXS - */ -public abstract class CharacterIdTag extends Tag { - - public CharacterIdTag(SWF swf, int id, String name, ByteArrayRange data) { - super(swf, id, name, data); - } - - public abstract int getCharacterId(); - /** - * List of ExportAssetsTag used for converting to String - */ - @Internal - public List exportAssetsTags = new ArrayList<>(); - protected String exportName; - - public void setExportName(String exportName) { - this.exportName = exportName; - } - - @Override - public String getName() { - String nameAppend = ""; - if (exportName != null) { - nameAppend = ": " + exportName; - } - if (getCharacterId() != -1) { - return super.getName() + " (" + getCharacterId() + nameAppend + ")"; - } - if (!nameAppend.isEmpty()) { - return super.getName() + " (" + nameAppend + ")"; - } - return super.getName(); - } - - @Override - public String getExportFileName() { - return super.getName() + "_" + getCharacterId() + (((exportName != null) && (!exportName.isEmpty())) ? "_" + exportName : ""); - } - - public String getCharacterExportFileName() { - return getCharacterId() + (((exportName != null) && (!exportName.isEmpty())) ? "_" + exportName : ""); - } - - public String getExportName() { - return exportName; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.tags.base; + +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.tags.ExportAssetsTag; +import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.helpers.ByteArrayRange; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author JPEXS + */ +public abstract class CharacterIdTag extends Tag { + + public CharacterIdTag(SWF swf, int id, String name, ByteArrayRange data) { + super(swf, id, name, data); + } + + public abstract int getCharacterId(); + /** + * List of ExportAssetsTag used for converting to String + */ + @Internal + public List exportAssetsTags = new ArrayList<>(); + protected String exportName; + + public void setExportName(String exportName) { + if ("".equals(exportName)) { + exportName = null; + } + this.exportName = exportName; + } + + @Override + public String getName() { + String nameAppend = ""; + if (exportName != null) { + nameAppend = ": " + exportName; + } + if (getCharacterId() != -1) { + return super.getName() + " (" + getCharacterId() + nameAppend + ")"; + } + if (!nameAppend.isEmpty()) { + return super.getName() + " (" + nameAppend + ")"; + } + return super.getName(); + } + + @Override + public String getExportFileName() { + return super.getName() + "_" + getCharacterId() + (exportName != null ? "_" + exportName : ""); + } + + public String getCharacterExportFileName() { + return getCharacterId() + (exportName != null ? "_" + exportName : ""); + } + + public String getExportName() { + return exportName; + } +} diff --git a/src/com/jpexs/decompiler/flash/tags/base/CharacterTag.java b/src/com/jpexs/decompiler/flash/tags/base/CharacterTag.java index 9f53bdd50..e443766ff 100644 --- a/src/com/jpexs/decompiler/flash/tags/base/CharacterTag.java +++ b/src/com/jpexs/decompiler/flash/tags/base/CharacterTag.java @@ -56,24 +56,9 @@ public abstract class CharacterTag extends CharacterIdTag { } return tagName; } - /* - export with classname/export namme - */ - public String getExportFileName2() { - String nameAppend = ""; - if (exportName != null) { - nameAppend = ": " + exportName; - return exportName; - } - if (className != null) { - nameAppend = ": " + className; - return className; - } - if (getCharacterId() != -1) { - return getCharacterId()+""; - // return tagName + " (" + getCharacterId() + nameAppend + ")"; - } - - return tagName; + + @Override + public String getCharacterExportFileName() { + return getCharacterId() + (exportName != null ? "_" + exportName : "") + (className != null ? "_" + className : ""); } }