mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-15 21:48:12 +00:00
exporting selected images
swt library loading UI depends on system
This commit is contained in:
@@ -21,6 +21,8 @@ import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
@@ -128,12 +130,17 @@ public class Configuration {
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
File f = new File(getASDecHome());
|
||||
if (!f.exists()) {
|
||||
f.mkdir();
|
||||
}
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
oos = new ObjectOutputStream(new FileOutputStream(getConfigFile()));
|
||||
oos.writeObject(config);
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (IOException ex) {
|
||||
JOptionPane.showMessageDialog(null, "Cannot save configuration.\nPlease make application directory writable.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
Logger.getLogger(SWFInputStream.class.getName()).severe("Configuration directory is read only.");
|
||||
} finally {
|
||||
if (oos != null) {
|
||||
try {
|
||||
|
||||
@@ -29,7 +29,9 @@ import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.*;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.FileHandler;
|
||||
@@ -77,7 +79,6 @@ public class Main {
|
||||
return commandLineMode;
|
||||
}
|
||||
public static boolean DEBUG_COPY = false;
|
||||
public static boolean FLASH_PLAYER = true;
|
||||
/**
|
||||
* Debug mode = throwing an error when comparing original file and recompiled
|
||||
*/
|
||||
@@ -414,12 +415,94 @@ public class Main {
|
||||
System.out.println("java -jar ASDec.jar -decompress myfiledec.swf myfile.swf");
|
||||
}
|
||||
|
||||
private static void copyFile(String from, String to) throws IOException {
|
||||
FileInputStream fis = new FileInputStream(from);
|
||||
FileOutputStream fos = new FileOutputStream(to);
|
||||
byte buf[] = new byte[4096];
|
||||
int cnt = 0;
|
||||
while ((cnt = fis.read(buf)) > 0) {
|
||||
fos.write(buf, 0, cnt);
|
||||
}
|
||||
fis.close();
|
||||
fos.close();
|
||||
}
|
||||
|
||||
public static void restartApplication2(String[] args) {
|
||||
StringBuilder cmd = new StringBuilder();
|
||||
cmd.append(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java ");
|
||||
for (String jvmArg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
|
||||
cmd.append(jvmArg + " ");
|
||||
}
|
||||
cmd.append("-cp ").append(ManagementFactory.getRuntimeMXBean().getClassPath()).append(" ");
|
||||
cmd.append(Main.class.getName()).append(" ");
|
||||
for (String arg : args) {
|
||||
cmd.append(arg).append(" ");
|
||||
}
|
||||
|
||||
try {
|
||||
Runtime.getRuntime().exec(cmd.toString());
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public static void restartApplication() {
|
||||
try {
|
||||
System.out.println("1");
|
||||
final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
|
||||
final File currentJar = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||
|
||||
System.out.println("currentJar=" + currentJar);
|
||||
/* is it a jar file? */
|
||||
if (!currentJar.getName().endsWith(".jar")) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Build command: java -jar application.jar */
|
||||
final ArrayList<String> command = new ArrayList<String>();
|
||||
command.add(javaBin);
|
||||
command.add("-jar");
|
||||
command.add(currentJar.getPath());
|
||||
|
||||
final ProcessBuilder builder = new ProcessBuilder(command);
|
||||
builder.start();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();;
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public static void checkSWT(String[] args) {
|
||||
if (System.getProperty("os.name").toLowerCase().indexOf("win") == -1) {
|
||||
return;
|
||||
}
|
||||
String lastBits = (String) Configuration.getConfig("bits", "-");
|
||||
if ((!System.getProperty("sun.arch.data.model").equals(lastBits)) || (!(new File("lib/swt.jar")).exists())) {
|
||||
try {
|
||||
if (System.getProperty("sun.arch.data.model").equals("32")) {
|
||||
copyFile("lib/swt32.jar", "lib/swt.jar");
|
||||
} else if (System.getProperty("sun.arch.data.model").equals("64")) {
|
||||
copyFile("lib/swt64.jar", "lib/swt.jar");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
JOptionPane.showMessageDialog(null, "Cannot copy SWT library.\nPlease make application directory writeable.\n(Placing outside of Program files may help)", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
Logger.getLogger(SWFInputStream.class.getName()).severe("Cannot copy SWT library");
|
||||
System.exit(1);
|
||||
}
|
||||
Configuration.setConfig("bits", System.getProperty("sun.arch.data.model"));
|
||||
Configuration.save();
|
||||
restartApplication2(args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) throws IOException {
|
||||
View.setWinLookAndFeel();
|
||||
View.setLookAndFeel();
|
||||
Configuration.load();
|
||||
checkSWT(args);
|
||||
|
||||
int pos = 0;
|
||||
if (args.length > 0) {
|
||||
if (args[0].equals("-debug")) {
|
||||
|
||||
@@ -393,7 +393,7 @@ public class SWF {
|
||||
}
|
||||
}
|
||||
|
||||
private String getImageFormat(byte data[]) {
|
||||
private static String getImageFormat(byte data[]) {
|
||||
if (hasErrorHeader(data)) {
|
||||
return "jpg";
|
||||
}
|
||||
@@ -426,14 +426,7 @@ public class SWF {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void exportImages(String outdir) throws IOException {
|
||||
JPEGTablesTag jtt = null;
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof JPEGTablesTag) {
|
||||
jtt = (JPEGTablesTag) t;
|
||||
}
|
||||
}
|
||||
|
||||
public static void exportImages(String outdir, List<Tag> tags, JPEGTablesTag jtt) throws IOException {
|
||||
for (Tag t : tags) {
|
||||
if ((t instanceof DefineBitsJPEG2Tag) || (t instanceof DefineBitsJPEG3Tag) || (t instanceof DefineBitsJPEG4Tag)) {
|
||||
byte imageData[] = null;
|
||||
@@ -496,4 +489,15 @@ public class SWF {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void exportImages(String outdir) throws IOException {
|
||||
JPEGTablesTag jtt = null;
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof JPEGTablesTag) {
|
||||
jtt = (JPEGTablesTag) t;
|
||||
}
|
||||
}
|
||||
exportImages(outdir, tags, jtt);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.jpexs.asdec.tags.DefineTextTag;
|
||||
import com.jpexs.asdec.tags.DoABCTag;
|
||||
import com.jpexs.asdec.tags.DoInitActionTag;
|
||||
import com.jpexs.asdec.tags.ExportAssetsTag;
|
||||
import com.jpexs.asdec.tags.JPEGTablesTag;
|
||||
import com.jpexs.asdec.tags.ShowFrameTag;
|
||||
import com.jpexs.asdec.tags.Tag;
|
||||
import com.jpexs.asdec.tags.base.ASMSource;
|
||||
@@ -81,6 +82,13 @@ public class MainFrame extends JFrame implements ActionListener {
|
||||
}
|
||||
statusLabel.setText(s);
|
||||
}
|
||||
private TagPanel imagesTagPanel;
|
||||
private TagPanel shapesTagPanel;
|
||||
private TagPanel morphshapesTagPanel;
|
||||
private TagPanel spritesTagPanel;
|
||||
private TagPanel textsTagPanel;
|
||||
private TagPanel buttonsTagPanel;
|
||||
private TagPanel fontsTagPanel;
|
||||
|
||||
public MainFrame(SWF swf) {
|
||||
setSize(1000, 700);
|
||||
@@ -124,8 +132,13 @@ public class MainFrame extends JFrame implements ActionListener {
|
||||
miExportAllPCode.setActionCommand("EXPORTPCODE");
|
||||
miExportAllPCode.addActionListener(this);
|
||||
|
||||
JMenuItem miExportImages = new JMenuItem("Images...");
|
||||
miExportImages.setActionCommand("EXPORTIMAGES");
|
||||
miExportImages.addActionListener(this);
|
||||
|
||||
menuExportAll.add(miExportAllAS);
|
||||
menuExportAll.add(miExportAllPCode);
|
||||
menuExportAll.add(miExportImages);
|
||||
|
||||
|
||||
JMenu menuExportSel = new JMenu("Export selection");
|
||||
@@ -139,8 +152,13 @@ public class MainFrame extends JFrame implements ActionListener {
|
||||
miExportSelPCode.setActionCommand("EXPORTPCODESEL");
|
||||
miExportSelPCode.addActionListener(this);
|
||||
|
||||
JMenuItem miExportSelImages = new JMenuItem("Images...");
|
||||
miExportSelImages.setActionCommand("EXPORTIMAGESSEL");
|
||||
miExportSelImages.addActionListener(this);
|
||||
|
||||
menuExportSel.add(miExportSelAS);
|
||||
menuExportSel.add(miExportSelPCode);
|
||||
menuExportSel.add(miExportSelImages);
|
||||
|
||||
|
||||
menuFile.add(miOpen);
|
||||
@@ -227,25 +245,25 @@ public class MainFrame extends JFrame implements ActionListener {
|
||||
}
|
||||
|
||||
if (!shapes.isEmpty()) {
|
||||
tabPane.addTab("Shapes", new TagPanel(shapes, swf));
|
||||
tabPane.addTab("Shapes", shapesTagPanel = new TagPanel(shapes, swf));
|
||||
}
|
||||
if (!morphShapes.isEmpty()) {
|
||||
tabPane.addTab("MorphShapes", new TagPanel(morphShapes, swf));
|
||||
tabPane.addTab("MorphShapes", morphshapesTagPanel = new TagPanel(morphShapes, swf));
|
||||
}
|
||||
if (!images.isEmpty()) {
|
||||
tabPane.addTab("Images", new TagPanel(images, swf));
|
||||
tabPane.addTab("Images", imagesTagPanel = new TagPanel(images, swf));
|
||||
}
|
||||
if (!sprites.isEmpty()) {
|
||||
tabPane.addTab("Sprites", new TagPanel(sprites, swf));
|
||||
tabPane.addTab("Sprites", spritesTagPanel = new TagPanel(sprites, swf));
|
||||
}
|
||||
if (!fonts.isEmpty()) {
|
||||
tabPane.addTab("Fonts", new TagPanel(fonts, swf));
|
||||
tabPane.addTab("Fonts", fontsTagPanel = new TagPanel(fonts, swf));
|
||||
}
|
||||
if (!texts.isEmpty()) {
|
||||
tabPane.addTab("Texts", new TagPanel(texts, swf));
|
||||
tabPane.addTab("Texts", textsTagPanel = new TagPanel(texts, swf));
|
||||
}
|
||||
if (!buttons.isEmpty()) {
|
||||
tabPane.addTab("Buttons", new TagPanel(buttons, swf));
|
||||
tabPane.addTab("Buttons", buttonsTagPanel = new TagPanel(buttons, swf));
|
||||
}
|
||||
/*tabPane.addTab("Tags", new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tagTree), new JScrollPane(fPanel)));*/
|
||||
|
||||
@@ -585,12 +603,32 @@ public class MainFrame extends JFrame implements ActionListener {
|
||||
Configuration.setConfig("lastExportDir", chooser.getSelectedFile().getParentFile().getAbsolutePath());
|
||||
final boolean isPcode = e.getActionCommand().startsWith("EXPORTPCODE");
|
||||
final boolean onlySel = e.getActionCommand().endsWith("SEL");
|
||||
final boolean images = e.getActionCommand().startsWith("EXPORTIMAGES");
|
||||
(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (onlySel) {
|
||||
if (abcPanel != null) {
|
||||
if (images) {
|
||||
if (imagesTagPanel != null) {
|
||||
List<Tag> list = new ArrayList<Tag>();
|
||||
|
||||
Object lob[] = imagesTagPanel.tagList.getSelectedValues();
|
||||
for (Object o : lob) {
|
||||
if (o instanceof Tag) {
|
||||
list.add((Tag) o);
|
||||
}
|
||||
}
|
||||
JPEGTablesTag jtt = null;
|
||||
for (Tag t : swf.tags) {
|
||||
if (t instanceof JPEGTablesTag) {
|
||||
jtt = (JPEGTablesTag) t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SWF.exportImages(selFile, list, jtt);
|
||||
}
|
||||
} else if (abcPanel != null) {
|
||||
List<TreeLeafScript> tlsList = abcPanel.classTree.getSelectedScripts();
|
||||
if (tlsList.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "No script selected!");
|
||||
@@ -612,7 +650,11 @@ public class MainFrame extends JFrame implements ActionListener {
|
||||
com.jpexs.asdec.action.TagNode.exportNode(allnodes, selFile, isPcode);
|
||||
}
|
||||
} else {
|
||||
Main.swf.exportActionScript(selFile, isPcode);
|
||||
if (images) {
|
||||
Main.swf.exportImages(selFile);
|
||||
} else {
|
||||
Main.swf.exportActionScript(selFile, isPcode);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
JOptionPane.showMessageDialog(null, "Cannot write to the file");
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package com.jpexs.asdec.gui;
|
||||
|
||||
import com.jpexs.asdec.Main;
|
||||
import com.jpexs.asdec.SWF;
|
||||
import com.jpexs.asdec.SWFOutputStream;
|
||||
import com.jpexs.asdec.tags.DefineBitsJPEG2Tag;
|
||||
@@ -51,6 +50,7 @@ import java.awt.Color;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -58,6 +58,7 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
@@ -81,6 +82,14 @@ public class TagPanel extends JPanel implements ListSelectionListener {
|
||||
private JPEGTablesTag jtt;
|
||||
private HashMap<Integer, CharacterTag> characters;
|
||||
|
||||
static {
|
||||
try {
|
||||
File.createTempFile("temp", ".swf").delete(); //First call to this is slow, so make it first
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(TagPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseCharacters(List<Object> list) {
|
||||
for (Object t : list) {
|
||||
if (t instanceof CharacterTag) {
|
||||
@@ -107,12 +116,19 @@ public class TagPanel extends JPanel implements ListSelectionListener {
|
||||
tagList.addListSelectionListener(this);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
if (Main.FLASH_PLAYER) {
|
||||
try {
|
||||
flashPanel = new FlashPanel();
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
displayPanel = new JPanel(new CardLayout());
|
||||
if (Main.FLASH_PLAYER) {
|
||||
if (flashPanel != null) {
|
||||
displayPanel.add(flashPanel, CARDFLASHPANEL);
|
||||
} else {
|
||||
JPanel swtPanel = new JPanel(new BorderLayout());
|
||||
swtPanel.add(new JLabel("<html><center>Preview of this object is not available on this platform. (Windows only)</center></html>", JLabel.CENTER), BorderLayout.CENTER);
|
||||
swtPanel.setBackground(Color.white);
|
||||
displayPanel.add(swtPanel, CARDFLASHPANEL);
|
||||
}
|
||||
imagePanel = new ImagePanel();
|
||||
CardLayout cl = (CardLayout) (displayPanel.getLayout());
|
||||
@@ -263,8 +279,10 @@ public class TagPanel extends JPanel implements ListSelectionListener {
|
||||
sos.write(data);
|
||||
fos.close();
|
||||
showCard(CARDFLASHPANEL);
|
||||
if (Main.FLASH_PLAYER) {
|
||||
flashPanel.displaySWF(tempFile.getAbsolutePath());
|
||||
if (flashPanel != null) {
|
||||
if (flashPanel instanceof FlashPanel) {
|
||||
flashPanel.displaySWF(tempFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -31,11 +31,11 @@ public class View {
|
||||
/**
|
||||
* Sets windows Look and Feel
|
||||
*/
|
||||
public static void setWinLookAndFeel() {
|
||||
public static void setLookAndFeel() {
|
||||
try {
|
||||
|
||||
UIManager.setLookAndFeel(
|
||||
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
||||
UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (UnsupportedLookAndFeelException ignored) {
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
} catch (InstantiationException ignored) {
|
||||
|
||||
Reference in New Issue
Block a user