mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 10:20:52 +00:00
allow to save data range in dumpview to file (e.g. for exporting ABC data)
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.gui.dumpview;
|
||||
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.dumpview.DumpInfo;
|
||||
import com.jpexs.decompiler.flash.dumpview.DumpInfoSwfNode;
|
||||
import com.jpexs.decompiler.flash.gui.Main;
|
||||
@@ -29,7 +30,15 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JTree;
|
||||
@@ -48,6 +57,7 @@ public class DumpTree extends JTree implements ActionListener {
|
||||
|
||||
private static final String ACTION_CLOSE_SWF = "CLOSESWF";
|
||||
private static final String ACTION_EXPAND_RECURSIVE = "EXPANDRECURSIVE";
|
||||
private static final String ACTION_SAVE_TO_FILE = "SAVETOFILE";
|
||||
|
||||
private final MainPanel mainPanel;
|
||||
|
||||
@@ -100,6 +110,11 @@ public class DumpTree extends JTree implements ActionListener {
|
||||
expandRecursiveMenuItem.setActionCommand(ACTION_EXPAND_RECURSIVE);
|
||||
contextPopupMenu.add(expandRecursiveMenuItem);
|
||||
|
||||
final JMenuItem saveToFileMenuItem = new JMenuItem(mainPanel.translate("contextmenu.saveToFile"));
|
||||
saveToFileMenuItem.addActionListener(this);
|
||||
saveToFileMenuItem.setActionCommand(ACTION_SAVE_TO_FILE);
|
||||
contextPopupMenu.add(saveToFileMenuItem);
|
||||
|
||||
final JMenuItem closeSelectionMenuItem = new JMenuItem(mainPanel.translate("contextmenu.closeSwf"));
|
||||
closeSelectionMenuItem.setActionCommand(ACTION_CLOSE_SWF);
|
||||
closeSelectionMenuItem.addActionListener(this);
|
||||
@@ -122,6 +137,7 @@ public class DumpTree extends JTree implements ActionListener {
|
||||
}
|
||||
closeSelectionMenuItem.setVisible(false);
|
||||
expandRecursiveMenuItem.setVisible(false);
|
||||
saveToFileMenuItem.setVisible(false);
|
||||
|
||||
if (paths.length == 1) {
|
||||
DumpInfo treeNode = (DumpInfo) paths[0].getLastPathComponent();
|
||||
@@ -129,6 +145,10 @@ public class DumpTree extends JTree implements ActionListener {
|
||||
if (treeNode instanceof DumpInfoSwfNode) {
|
||||
closeSelectionMenuItem.setVisible(true);
|
||||
}
|
||||
|
||||
if (treeNode.getEndByte() - treeNode.startByte > 3) {
|
||||
saveToFileMenuItem.setVisible(true);
|
||||
}
|
||||
|
||||
TreeModel model = getModel();
|
||||
expandRecursiveMenuItem.setVisible(model.getChildCount(treeNode) > 0);
|
||||
@@ -151,6 +171,28 @@ public class DumpTree extends JTree implements ActionListener {
|
||||
View.expandTreeNodesRecursive(this, path, true);
|
||||
}
|
||||
break;
|
||||
case ACTION_SAVE_TO_FILE: {
|
||||
TreePath[] paths = getSelectionPaths();
|
||||
DumpInfo dumpInfo = (DumpInfo) paths[0].getLastPathComponent();
|
||||
JFileChooser fc = new JFileChooser();
|
||||
String selDir = Configuration.lastOpenDir.get();
|
||||
fc.setCurrentDirectory(new File(selDir));
|
||||
if (!selDir.endsWith(File.separator)) {
|
||||
selDir += File.separator;
|
||||
}
|
||||
JFrame f = new JFrame();
|
||||
View.setWindowIcon(f);
|
||||
if (fc.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) {
|
||||
File sf = Helper.fixDialogFile(fc.getSelectedFile());
|
||||
try (FileOutputStream fos = new FileOutputStream(sf)) {
|
||||
byte[] data = DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf().uncompressedData;
|
||||
fos.write(data, (int) dumpInfo.startByte, (int) (dumpInfo.getEndByte() - dumpInfo.startByte + 1));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(DumpTree.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ACTION_CLOSE_SWF: {
|
||||
Main.closeFile(mainPanel.getCurrentSwfList());
|
||||
}
|
||||
|
||||
@@ -46,20 +46,6 @@ public class DumpViewPanel extends JPanel {
|
||||
add(new JScrollPane(dumpViewHexTable), BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private int getEndIndex(DumpInfo dumpInfo) {
|
||||
int end = (int) dumpInfo.startByte;
|
||||
if (dumpInfo.lengthBytes != 0) {
|
||||
end += dumpInfo.lengthBytes;
|
||||
} else {
|
||||
int bits = dumpInfo.startBit + dumpInfo.lengthBits;
|
||||
end += bits / 8;
|
||||
if (bits % 8 != 0) {
|
||||
end++;
|
||||
}
|
||||
}
|
||||
return end - 1;
|
||||
}
|
||||
|
||||
public void setData(byte[] data, DumpInfo dumpInfo) {
|
||||
List<DumpInfo> dumpInfos = new ArrayList<>();
|
||||
DumpInfo di = dumpInfo;
|
||||
@@ -72,13 +58,13 @@ public class DumpViewPanel extends JPanel {
|
||||
for (int i = 0; i < dumpInfos.size(); i++) {
|
||||
DumpInfo di2 = dumpInfos.get(highlightStarts.length - i - 1);
|
||||
highlightStarts[i] = di2.startByte;
|
||||
highlightEnds[i] = getEndIndex(di2);
|
||||
highlightEnds[i] = di2.getEndByte();
|
||||
}
|
||||
dumpViewHexTable.setData(data, highlightStarts, highlightEnds);
|
||||
|
||||
if (dumpInfo.lengthBytes != 0 || dumpInfo.lengthBits != 0) {
|
||||
int selectionStart = (int) dumpInfo.startByte;
|
||||
int selectionEnd = getEndIndex(dumpInfo);
|
||||
int selectionEnd = (int) dumpInfo.getEndByte();
|
||||
|
||||
dumpViewHexTable.scrollToByte(highlightStarts, highlightEnds);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user