diff --git a/trunk/src/com/jpexs/decompiler/flash/BinarySWFBundle.java b/trunk/src/com/jpexs/decompiler/flash/BinarySWFBundle.java index abd904590..e71ddf489 100644 --- a/trunk/src/com/jpexs/decompiler/flash/BinarySWFBundle.java +++ b/trunk/src/com/jpexs/decompiler/flash/BinarySWFBundle.java @@ -17,7 +17,6 @@ package com.jpexs.decompiler.flash; -import com.jpexs.helpers.ReReadableInputStream; import com.jpexs.helpers.StreamSearch; import com.jpexs.helpers.streams.SeekableInputStream; import java.io.IOException; diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFSearch.java b/trunk/src/com/jpexs/decompiler/flash/SWFSearch.java index b1d94d3a8..00f2e7db0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFSearch.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFSearch.java @@ -22,10 +22,8 @@ import com.jpexs.helpers.ProgressListener; import com.jpexs.helpers.Searchable; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java index e8116ee69..fdac07b91 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java @@ -208,6 +208,7 @@ public class LoadFromMemoryFrame extends AppFrame implements ActionListener { selProcesses = list.getSelectedValuesList(); if (!selProcesses.isEmpty()) { processing = true; + tableRes.setEnabled(false); resTableModel.getDataVector().removeAllElements(); resTableModel.fireTableDataChanged(); foundIs = null; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index e390c368d..0332a9b1a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -241,7 +241,6 @@ public class Main { startWork(AppStrings.translate("work.reading.swf"), p); } }, Configuration.parallelSpeedUp.get()); - swf.file = sourceInfo.getFile(); swf.fileTitle = streamEntry.getKey(); swf.readOnly = true; result.add(swf); @@ -300,17 +299,17 @@ public class Main { } public static void saveFile(SWF swf, String outfile) throws IOException { - saveFile(swf, outfile, ".swf"); + saveFile(swf, outfile, SaveFileMode.SAVE); } - public static void saveFile(SWF swf, String outfile, String extension) throws IOException { - if (extension.equals(".swf")) { + public static void saveFile(SWF swf, String outfile, SaveFileMode mode) throws IOException { + if (mode == SaveFileMode.SAVEAS) { swf.file = outfile; } File outfileF = new File(outfile); File tmpFile = new File(outfile + ".tmp"); FileOutputStream fos = new FileOutputStream(tmpFile); - if (extension.equals(".exe")) { + if (mode == SaveFileMode.EXE) { InputStream exeStream = View.class.getClassLoader().getResourceAsStream("com/jpexs/helpers/resource/Swf2Exe.bin"); byte [] buffer = new byte[4096]; int bytesRead = 0; @@ -507,13 +506,22 @@ public class Main { mainFrame.getPanel().closeAll(); } - public static boolean saveFileDialog(SWF swf) { - return saveFileDialog(swf, ".swf"); - } - - public static boolean saveFileDialog(SWF swf, final String extension) { + public static boolean saveFileDialog(SWF swf, final SaveFileMode mode) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(Configuration.lastSaveDir.get())); + String ext = ".swf"; + switch (mode) { + case SAVE: + case SAVEAS: + if (swf.file != null) { + ext = Helper.getExtension(swf.file); + } + break; + case EXE: + ext = ".exe"; + break; + } + final String extension = ext; FileFilter swfFilter = new FileFilter() { @Override public boolean accept(File f) { @@ -567,7 +575,7 @@ public class Main { } swf.gfx = true; } - Main.saveFile(swf, fileName, extension); + Main.saveFile(swf, fileName, mode); Configuration.lastSaveDir.set(file.getParentFile().getAbsolutePath()); return true; } catch (IOException ex) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java index 262077385..bf806aa5c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java @@ -361,6 +361,14 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener { deobfuscationCommandButton.setEnabled(hasAbc);*/ } + private void saveAs(SWF swf, SaveFileMode mode) { + if (Main.saveFileDialog(swf, mode)) { + swf.fileTitle = null; + mainFrame.setTitle(ApplicationInfo.applicationVerName + (Configuration.displayFileName.get() ? " - " + swf.getFileTitle() : "")); + saveCommandButton.setEnabled(mainFrame.panel.getCurrentSwf() != null); + } + } + @Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { @@ -475,30 +483,30 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener { } break; case ACTION_SAVE: - try { + { SWF swf = mainFrame.panel.getCurrentSwf(); - Main.saveFile(swf, swf.file); - } catch (IOException ex) { - Logger.getLogger(MainFrameClassicMenu.class.getName()).log(Level.SEVERE, null, ex); - View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE); + if (swf.file == null) { + saveAs(swf, SaveFileMode.SAVEAS); + } else { + try { + Main.saveFile(swf, swf.file); + } catch (IOException ex) { + Logger.getLogger(MainFrameClassicMenu.class.getName()).log(Level.SEVERE, null, ex); + View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE); + } + } } break; case ACTION_SAVE_AS: { SWF swf = mainFrame.panel.getCurrentSwf(); - if (Main.saveFileDialog(swf)) { - mainFrame.setTitle(ApplicationInfo.applicationVerName + (Configuration.displayFileName.get() ? " - " + swf.getFileTitle() : "")); - saveCommandButton.setEnabled(mainFrame.panel.getCurrentSwf() != null); - } + saveAs(swf, SaveFileMode.SAVEAS); } break; case ACTION_SAVE_AS_EXE: { SWF swf = mainFrame.panel.getCurrentSwf(); - if (Main.saveFileDialog(swf, ".exe")) { - mainFrame.setTitle(ApplicationInfo.applicationVerName + (Configuration.displayFileName.get() ? " - " + swf.getFileTitle() : "")); - saveCommandButton.setEnabled(mainFrame.panel.getCurrentSwf() != null); - } + saveAs(swf, SaveFileMode.EXE); } break; case ACTION_OPEN: diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index 57a598c54..119a5e34a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -499,6 +499,14 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener { deobfuscationCommandButton.setEnabled(hasAbc); } + private void saveAs(SWF swf, SaveFileMode mode) { + if (Main.saveFileDialog(swf, mode)) { + swf.fileTitle = null; + mainFrame.setTitle(ApplicationInfo.applicationVerName + (Configuration.displayFileName.get() ? " - " + swf.getFileTitle() : "")); + saveCommandButton.setEnabled(mainFrame.panel.getCurrentSwf() != null); + } + } + @Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { @@ -616,30 +624,30 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener { } break; case ACTION_SAVE: - try { + { SWF swf = mainFrame.panel.getCurrentSwf(); - Main.saveFile(swf, swf.file); - } catch (IOException ex) { - Logger.getLogger(MainFrameRibbonMenu.class.getName()).log(Level.SEVERE, null, ex); - View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE); + if (swf.file == null) { + saveAs(swf, SaveFileMode.SAVEAS); + } else { + try { + Main.saveFile(swf, swf.file); + } catch (IOException ex) { + Logger.getLogger(MainFrameRibbonMenu.class.getName()).log(Level.SEVERE, null, ex); + View.showMessageDialog(null, translate("error.file.save"), translate("error"), JOptionPane.ERROR_MESSAGE); + } + } } break; case ACTION_SAVE_AS: { SWF swf = mainFrame.panel.getCurrentSwf(); - if (Main.saveFileDialog(swf)) { - mainFrame.setTitle(ApplicationInfo.applicationVerName + (Configuration.displayFileName.get() ? " - " + swf.getFileTitle() : "")); - saveCommandButton.setEnabled(mainFrame.panel.getCurrentSwf() != null); - } + saveAs(swf, SaveFileMode.SAVEAS); } break; case ACTION_SAVE_AS_EXE: { SWF swf = mainFrame.panel.getCurrentSwf(); - if (Main.saveFileDialog(swf, ".exe")) { - mainFrame.setTitle(ApplicationInfo.applicationVerName + (Configuration.displayFileName.get() ? " - " + swf.getFileTitle() : "")); - saveCommandButton.setEnabled(mainFrame.panel.getCurrentSwf() != null); - } + saveAs(swf, SaveFileMode.EXE); } break; case ACTION_OPEN: diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java index e42ce4103..17b7d8bb9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -944,18 +944,14 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } private void updateUi() { - if (!isWelcomeScreen) { + if (!isWelcomeScreen && swfs.isEmpty()) { CardLayout cl = (CardLayout) (contentPanel.getLayout()); cl.show(contentPanel, WELCOME_PANEL); isWelcomeScreen = true; } - if (swfs.isEmpty()) { - mainMenu.updateComponets(null, null); - } else { - SWFList swfList = swfs.get(0); - updateUi(swfList.get(0)); - } + mainFrame.setTitle(ApplicationInfo.applicationVerName); + mainMenu.updateComponets(null, null); } public void closeAll() { @@ -1462,6 +1458,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec return swfs.get(0).get(0); } + if (treeNode instanceof SWFBundleNode) { + return null; + } + return treeNode.getItem().getSwf(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/SaveFileMode.java b/trunk/src/com/jpexs/decompiler/flash/gui/SaveFileMode.java new file mode 100644 index 000000000..883d20fe0 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/gui/SaveFileMode.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2010-2013 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.gui; + +/** + * + * @author JPEXS + */ +public enum SaveFileMode { + + SAVE, SAVEAS, EXE +} diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 69e768ec7..e75bf99b7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -122,9 +122,8 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi } if (h2 != null) { ignoreCarret = true; - try { + if (h2.startPos <= getDocument().getLength()) { setCaretPosition(h2.startPos); - } catch (IllegalArgumentException iex) { } getCaret().setVisible(true); ignoreCarret = false; @@ -138,9 +137,8 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi Highlighting h2 = Highlighting.search(disassembledHilights, "offset", "" + offset); if (h2 != null) { ignoreCarret = true; - try { + if (h2.startPos <= getDocument().getLength()) { setCaretPosition(h2.startPos); - } catch (IllegalArgumentException iex) { } getCaret().setVisible(true); ignoreCarret = false; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 2363a8d2d..f79d8a441 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -112,10 +112,8 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL for (Highlighting h : allh) { if (h.getPropertyString("subtype").equals(type) && ((long) h.getPropertyLong("index") == index)) { ignoreCarret = true; - try { + if (h.startPos <= getDocument().getLength()) { setCaretPosition(h.startPos); - } catch (IllegalArgumentException ie) { - //ignored } getCaret().setVisible(true); ignoreCarret = false; @@ -134,10 +132,8 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL Highlighting h2 = Highlighting.search(highlights, "offset", "" + offset, h.startPos, h.startPos + h.len); if (h2 != null) { ignoreCarret = true; - try { + if (h2.startPos <= getDocument().getLength()) { setCaretPosition(h2.startPos); - } catch (IllegalArgumentException ie) { - //ignored } getCaret().setVisible(true); ignoreCarret = false; @@ -405,19 +401,18 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL if (tc != null) { Highlighting th = Highlighting.search(traitHighlights, "index", "" + traitId, tc.startPos, tc.startPos + tc.len); if (th != null) { - try { - ignoreCarret = true; - setCaretPosition(th.startPos + th.len - 1); - ignoreCarret = false; - } catch (IllegalArgumentException iae) { + ignoreCarret = true; + int startPos = th.startPos + th.len - 1; + if (startPos <= getDocument().getLength()) { + setCaretPosition(startPos); } + ignoreCarret = false; final int pos = th.startPos; new Timer().schedule(new TimerTask() { @Override public void run() { - try { + if (pos <= getDocument().getLength()) { setCaretPosition(pos); - } catch (IllegalArgumentException iae) { } } }, 100); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index 21c3ec326..b47426811 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -278,27 +278,31 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene }); } - private void setText(HilightedText text, String contentType) { - int pos = editor.getCaretPosition(); - Highlighting lastH = null; - for (Highlighting h : disassembledHilights) { - if (pos < h.startPos) { - break; + private void setText(final HilightedText text, final String contentType) { + View.execInEventDispatch(new Runnable() { + + @Override + public void run() { + int pos = editor.getCaretPosition(); + Highlighting lastH = null; + for (Highlighting h : disassembledHilights) { + if (pos < h.startPos) { + break; + } + lastH = h; + } + String offset = lastH == null ? "0" : lastH.getPropertyString("offset"); + disassembledHilights = text.instructionHilights; + String stripped = text.text; + setEditorText(stripped, contentType); + Highlighting h = Highlighting.search(disassembledHilights, "offset", offset); + if (h != null) { + if (h.startPos <= editor.getDocument().getLength()) { + editor.setCaretPosition(h.startPos); + } + } } - lastH = h; - } - String offset = lastH == null ? "0" : lastH.getPropertyString("offset"); - // getting hilights is fast now - // setEditorText("; " + AppStrings.translate("work.gettinghilights") + "...", "text/flasm"); - disassembledHilights = text.instructionHilights; - String stripped = text.text; - setEditorText(stripped, contentType); - Highlighting h = Highlighting.search(disassembledHilights, "offset", offset); - if (h != null) { - if (h.startPos <= editor.getText().length()) { - editor.setCaretPosition(h.startPos); - } - } + }); } private HilightedText getHilightedText(ExportMode exportMode) { @@ -479,7 +483,6 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene panB.add(panCode, BorderLayout.CENTER); - JPanel buttonsPan = new JPanel(); buttonsPan.setLayout(new FlowLayout()); buttonsPan.add(editButton); @@ -515,7 +518,6 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene cancelButton.setVisible(false); - saveDecompiledButton.addActionListener(this); saveDecompiledButton.setActionCommand(ACTION_SAVE_DECOMPILED); editDecompiledButton.addActionListener(this); @@ -539,10 +541,6 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene //decLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); - - - - setLayout(new BorderLayout()); add(splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panA, panB), BorderLayout.CENTER); splitPane.setResizeWeight(0.5); @@ -578,7 +576,9 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene Highlighting h2 = Highlighting.search(decompiledHilights, "offset", ofs); if (h2 != null) { ignoreCarret = true; - decompiledEditor.setCaretPosition(h2.startPos); + if (h2.startPos <= decompiledEditor.getDocument().getLength()) { + decompiledEditor.setCaretPosition(h2.startPos); + } decompiledEditor.getCaret().setVisible(true); ignoreCarret = false; diff --git a/trunk/src/com/jpexs/helpers/Helper.java b/trunk/src/com/jpexs/helpers/Helper.java index 74e42fb05..4475650e6 100644 --- a/trunk/src/com/jpexs/helpers/Helper.java +++ b/trunk/src/com/jpexs/helpers/Helper.java @@ -752,6 +752,13 @@ public class Helper { } } + /* + * Get the extension of a file. + */ + public static String getExtension(String fileName) { + return getExtension(new File(fileName)); + } + /* * Get the extension of a file. */