mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-07 01:34:49 +00:00
exporting text
This commit is contained in:
@@ -76,6 +76,7 @@ import com.jpexs.decompiler.flash.tags.base.ASMSource;
|
||||
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.Container;
|
||||
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextTag;
|
||||
import com.jpexs.decompiler.flash.types.RECT;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
@@ -769,6 +770,40 @@ public class SWF {
|
||||
}
|
||||
}
|
||||
|
||||
public void exportTexts(String outdir, List<Tag> tags, boolean formatted) throws IOException {
|
||||
if (tags.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!(new File(outdir)).exists()) {
|
||||
(new File(outdir)).mkdirs();
|
||||
}
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof TextTag) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(outdir + File.separator + ((TextTag) t).getCharacterID() + ".txt");
|
||||
if (formatted) {
|
||||
fos.write(((TextTag) t).getFormattedText(this.tags).getBytes("UTF-8"));
|
||||
} else {
|
||||
fos.write(((TextTag) t).getText(this.tags).getBytes("UTF-8"));
|
||||
}
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (Exception ex) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void exportTexts(String outdir, boolean formatted) throws IOException {
|
||||
exportTexts(outdir, tags, formatted);
|
||||
}
|
||||
|
||||
public static void exportShapes(String outdir, List<Tag> tags) throws IOException {
|
||||
if (tags.isEmpty()) {
|
||||
return;
|
||||
|
||||
@@ -19,6 +19,7 @@ public class ExportDialog extends JDialog {
|
||||
boolean cancelled = false;
|
||||
String options[][] = {
|
||||
{"SVG"},
|
||||
{"Plain Text", "Formatted text"},
|
||||
{"PNG/JPEG"},
|
||||
{"FLV (No audio)"},
|
||||
{"MP3/FLV", "FLV (Audio only)"},
|
||||
@@ -26,16 +27,18 @@ public class ExportDialog extends JDialog {
|
||||
};
|
||||
String optionNames[] = {
|
||||
"Shapes",
|
||||
"Texts",
|
||||
"Images",
|
||||
"Movies",
|
||||
"Sounds",
|
||||
"ActionScript"
|
||||
};
|
||||
public static final int OPTION_SHAPES = 0;
|
||||
public static final int OPTION_IMAGES = 1;
|
||||
public static final int OPTION_MOVIES = 2;
|
||||
public static final int OPTION_SOUNDS = 3;
|
||||
public static final int OPTION_ACTIONSCRIPT = 4;
|
||||
public static final int OPTION_TEXTS = 1;
|
||||
public static final int OPTION_IMAGES = 2;
|
||||
public static final int OPTION_MOVIES = 3;
|
||||
public static final int OPTION_SOUNDS = 4;
|
||||
public static final int OPTION_ACTIONSCRIPT = 5;
|
||||
private JComboBox combos[];
|
||||
|
||||
public int getOption(int index) {
|
||||
@@ -58,10 +61,10 @@ public class ExportDialog extends JDialog {
|
||||
int top = 10;
|
||||
for (int i = 0; i < optionNames.length; i++) {
|
||||
JLabel lab = new JLabel(optionNames[i]);
|
||||
lab.setBounds(10, top, 60, 25);
|
||||
lab.setBounds(10, top, 75, 25);
|
||||
cnt.add(lab);
|
||||
combos[i] = new JComboBox(options[i]);
|
||||
combos[i].setBounds(75, top, 105, 25);
|
||||
combos[i].setBounds(90, top, 125, 25);
|
||||
cnt.add(combos[i]);
|
||||
top += 25;
|
||||
}
|
||||
@@ -75,7 +78,7 @@ public class ExportDialog extends JDialog {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
okButton.setBounds(25, top, 75, 25);
|
||||
okButton.setBounds(43, top, 75, 25);
|
||||
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
@@ -85,11 +88,15 @@ public class ExportDialog extends JDialog {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
cancelButton.setBounds(100, top, 75, 25);
|
||||
cancelButton.setBounds(118, top, 75, 25);
|
||||
|
||||
top += 25;
|
||||
cnt.add(okButton);
|
||||
cnt.add(cancelButton);
|
||||
setSize(210, top + 70);
|
||||
|
||||
top += 15;
|
||||
pack();
|
||||
setSize(245, top + getInsets().top);
|
||||
View.centerScreen(this);
|
||||
View.setWindowIcon(this);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
|
||||
@@ -1176,6 +1176,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
Configuration.setConfig("lastExportDir", chooser.getSelectedFile().getParentFile().getAbsolutePath());
|
||||
final boolean isPcode = export.getOption(ExportDialog.OPTION_ACTIONSCRIPT) == 1;
|
||||
final boolean isMp3 = export.getOption(ExportDialog.OPTION_SOUNDS) == 0;
|
||||
final boolean isFormatted = export.getOption(ExportDialog.OPTION_TEXTS) == 1;
|
||||
final boolean onlySel = e.getActionCommand().endsWith("SEL");
|
||||
(new Thread() {
|
||||
@Override
|
||||
@@ -1196,6 +1197,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
List<Tag> shapes = new ArrayList<Tag>();
|
||||
List<Tag> movies = new ArrayList<Tag>();
|
||||
List<Tag> sounds = new ArrayList<Tag>();
|
||||
List<Tag> texts = new ArrayList<Tag>();
|
||||
List<TagNode> actionNodes = new ArrayList<TagNode>();
|
||||
List<Tag> binaryData = new ArrayList<Tag>();
|
||||
for (Object d : sel) {
|
||||
@@ -1219,6 +1221,9 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
if ("binaryData".equals(getTagType(n.tag))) {
|
||||
binaryData.add((Tag) n.tag);
|
||||
}
|
||||
if ("text".equals(getTagType(n.tag))) {
|
||||
texts.add((Tag) n.tag);
|
||||
}
|
||||
}
|
||||
if (d instanceof TreeElement) {
|
||||
if (((TreeElement) d).isLeaf()) {
|
||||
@@ -1228,6 +1233,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
}
|
||||
SWF.exportImages(selFile + File.separator + "images", images, jtt);
|
||||
SWF.exportShapes(selFile + File.separator + "shapes", shapes);
|
||||
swf.exportTexts(selFile + File.separator + "texts", texts, isFormatted);
|
||||
swf.exportMovies(selFile + File.separator + "movies", movies);
|
||||
swf.exportSounds(selFile + File.separator + "sounds", sounds, isMp3);
|
||||
swf.exportBinaryData(selFile + File.separator + "binaryData", binaryData);
|
||||
@@ -1250,6 +1256,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
} else {
|
||||
swf.exportImages(selFile + File.separator + "images");
|
||||
swf.exportShapes(selFile + File.separator + "shapes");
|
||||
swf.exportTexts(selFile + File.separator + "texts", isFormatted);
|
||||
swf.exportMovies(selFile + File.separator + "movies");
|
||||
swf.exportSounds(selFile + File.separator + "sounds", isMp3);
|
||||
swf.exportBinaryData(selFile + File.separator + "binaryData");
|
||||
|
||||
@@ -71,17 +71,49 @@ public class DefineEditTextTag extends CharacterTag implements BoundedTag, TextT
|
||||
public String variableName;
|
||||
public String initialText;
|
||||
|
||||
private String stripTags(String inp) {
|
||||
boolean intag = false;
|
||||
String outp = "";
|
||||
for (int i = 0; i < inp.length(); ++i) {
|
||||
if (!intag && inp.charAt(i) == '<') {
|
||||
intag = true;
|
||||
continue;
|
||||
}
|
||||
if (intag && inp.charAt(i) == '>') {
|
||||
intag = false;
|
||||
continue;
|
||||
}
|
||||
if (!intag) {
|
||||
outp = outp + inp.charAt(i);
|
||||
}
|
||||
}
|
||||
return outp;
|
||||
}
|
||||
|
||||
private String entitiesReplace(String s) {
|
||||
s = s.replace("<", "<");
|
||||
s = s.replace(">", ">");
|
||||
s = s.replace("&", "&");
|
||||
s = s.replace(""", "\"");
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(List<Tag> tags) {
|
||||
if (hasText) {
|
||||
return initialText;
|
||||
String ret = getFormattedText(tags);
|
||||
if (html) {
|
||||
ret = stripTags(ret);
|
||||
ret = entitiesReplace(ret);
|
||||
}
|
||||
return "";
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedText(List<Tag> tags) {
|
||||
return getText(tags);
|
||||
if (hasText) {
|
||||
return initialText;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,4 +31,6 @@ public interface TextTag {
|
||||
public String getFormattedText(List<Tag> tags);
|
||||
|
||||
public void setFormattedText(List<Tag> tags, String text) throws ParseException;
|
||||
|
||||
public int getCharacterID();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user