mirror of
https://github.com/SuspiciousActivity/ByteEdit.git
synced 2026-08-13 17:56:17 +00:00
Added class delete and better class creation
This commit is contained in:
1 parent
89ea031bcc
commit
a7576ea4dc
1 file changed
+60
-23
@@ -234,7 +234,7 @@ public class Main extends JFrame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
if (e.getKeyCode() == 116 && jarFile != null) {
|
if (e.getKeyCode() == 116 && jarFile != null) { // F5
|
||||||
try {
|
try {
|
||||||
isChangingFile = true;
|
isChangingFile = true;
|
||||||
try {
|
try {
|
||||||
@@ -247,6 +247,30 @@ public class Main extends JFrame {
|
|||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
showError(t);
|
showError(t);
|
||||||
}
|
}
|
||||||
|
} else if (e.getKeyCode() == 127) { // del
|
||||||
|
if (tree.getSelectionPath() == null)
|
||||||
|
return;
|
||||||
|
String s = "";
|
||||||
|
boolean b = false;
|
||||||
|
for (Object o : tree.getSelectionPath().getPath()) {
|
||||||
|
DefaultMutableTreeNode path = (DefaultMutableTreeNode) o;
|
||||||
|
if (!b) {
|
||||||
|
b = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
s += (s.isEmpty() || s.replace("/", "").isEmpty() ? "" : "/")
|
||||||
|
+ (path.toString().isEmpty() ? "/" : path.toString());
|
||||||
|
}
|
||||||
|
if (s.isEmpty() || s.endsWith("/"))
|
||||||
|
return;
|
||||||
|
if (JOptionPane.showConfirmDialog(INSTANCE, "Do you want to delete\n\"" + s + "\"?", "Delete",
|
||||||
|
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||||
|
classNodes.remove(s);
|
||||||
|
ArchiveTreeModel model = (ArchiveTreeModel) tree.getModel();
|
||||||
|
model.paths.remove(s);
|
||||||
|
model.refresh();
|
||||||
|
model.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -382,8 +406,8 @@ public class Main extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
globalSearchBox.setVisible(true);
|
globalSearchBox.setVisible(true);
|
||||||
// globalSearchBox.txtFind.requestFocusInWindow();
|
globalSearchBox.txtString.requestFocusInWindow();
|
||||||
// globalSearchBox.txtFind.select(0, searchBox.txtFind.getText().length());
|
globalSearchBox.txtString.select(0, globalSearchBox.txtString.getText().length());
|
||||||
}
|
}
|
||||||
}, ctrlG, JComponent.WHEN_IN_FOCUSED_WINDOW);
|
}, ctrlG, JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||||
txtByteEditView.registerKeyboardAction(new ActionListener() {
|
txtByteEditView.registerKeyboardAction(new ActionListener() {
|
||||||
@@ -612,6 +636,15 @@ public class Main extends JFrame {
|
|||||||
}
|
}
|
||||||
if (classNodes.replace(node.name + ".class", node) == null) {
|
if (classNodes.replace(node.name + ".class", node) == null) {
|
||||||
classNodes.put(node.name + ".class", node);
|
classNodes.put(node.name + ".class", node);
|
||||||
|
ArchiveTreeModel model;
|
||||||
|
if (tree.getModel().getClass().equals(DefaultTreeModel.class)) {
|
||||||
|
tree.setModel(model = new ArchiveTreeModel());
|
||||||
|
} else {
|
||||||
|
model = (ArchiveTreeModel) tree.getModel();
|
||||||
|
}
|
||||||
|
model.paths.add(node.name + ".class");
|
||||||
|
model.refresh();
|
||||||
|
model.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -684,9 +717,8 @@ public class Main extends JFrame {
|
|||||||
public void save(File jar, Collection<ClassNode> classes) {
|
public void save(File jar, Collection<ClassNode> classes) {
|
||||||
try {
|
try {
|
||||||
final JarOutputStream output = new JarOutputStream(new FileOutputStream(jar));
|
final JarOutputStream output = new JarOutputStream(new FileOutputStream(jar));
|
||||||
boolean refreshTree = false;
|
if (tree.getModel().getClass().equals(DefaultTreeModel.class)
|
||||||
if (tree.getModel().getClass().equals(DefaultTreeModel.class)) {
|
|| ((ArchiveTreeModel) tree.getModel()).newCreated) {
|
||||||
refreshTree = true;
|
|
||||||
int acc = ClassUtil.ACC_PUBLIC | ClassUtil.ACC_STATIC;
|
int acc = ClassUtil.ACC_PUBLIC | ClassUtil.ACC_STATIC;
|
||||||
String name = "";
|
String name = "";
|
||||||
for (ClassNode e : classes) {
|
for (ClassNode e : classes) {
|
||||||
@@ -705,6 +737,8 @@ public class Main extends JFrame {
|
|||||||
+ "\n\n";
|
+ "\n\n";
|
||||||
OTHER_FILES.put("META-INF/MANIFEST.MF", val.getBytes());
|
OTHER_FILES.put("META-INF/MANIFEST.MF", val.getBytes());
|
||||||
}
|
}
|
||||||
|
if (tree.getModel() instanceof ArchiveTreeModel)
|
||||||
|
((ArchiveTreeModel) tree.getModel()).newCreated = false;
|
||||||
}
|
}
|
||||||
for (Entry<String, byte[]> entry : OTHER_FILES.entrySet()) {
|
for (Entry<String, byte[]> entry : OTHER_FILES.entrySet()) {
|
||||||
JarEntry ent = new JarEntry(entry.getKey());
|
JarEntry ent = new JarEntry(entry.getKey());
|
||||||
@@ -728,16 +762,6 @@ public class Main extends JFrame {
|
|||||||
}
|
}
|
||||||
output.finish();
|
output.finish();
|
||||||
output.close();
|
output.close();
|
||||||
if (refreshTree) {
|
|
||||||
isChangingFile = true;
|
|
||||||
jarFile = jar;
|
|
||||||
try {
|
|
||||||
tree.setModel(new ArchiveTreeModel(new JarFile(jarFile)));
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
isChangingFile = false;
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
showError(e);
|
showError(e);
|
||||||
@@ -752,6 +776,7 @@ public class Main extends JFrame {
|
|||||||
break;
|
break;
|
||||||
s += "\tat " + ste + "\n";
|
s += "\tat " + ste + "\n";
|
||||||
}
|
}
|
||||||
|
JOptionPane.showMessageDialog(INSTANCE, s, "Error!", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showError(String s) {
|
public static void showError(String s) {
|
||||||
@@ -760,12 +785,19 @@ public class Main extends JFrame {
|
|||||||
|
|
||||||
class ArchiveTreeModel extends DefaultTreeModel {
|
class ArchiveTreeModel extends DefaultTreeModel {
|
||||||
|
|
||||||
|
public ArrayList<String> paths = new ArrayList<>();
|
||||||
|
public boolean newCreated = false;
|
||||||
|
|
||||||
|
public ArchiveTreeModel() {
|
||||||
|
super(new DefaultMutableTreeNode("New"));
|
||||||
|
newCreated = true;
|
||||||
|
}
|
||||||
|
|
||||||
public ArchiveTreeModel(JarFile jar) {
|
public ArchiveTreeModel(JarFile jar) {
|
||||||
super(new DefaultMutableTreeNode(jar.getName().split(File.separator.equals("\\") ? "\\\\"
|
super(new DefaultMutableTreeNode(jar.getName().split(File.separator.equals("\\") ? "\\\\"
|
||||||
: File.separator)[jar.getName().split(File.separator.equals("\\") ? "\\\\" : File.separator).length
|
: File.separator)[jar.getName().split(File.separator.equals("\\") ? "\\\\" : File.separator).length
|
||||||
- 1]));
|
- 1]));
|
||||||
try {
|
try {
|
||||||
ArrayList<String> paths = new ArrayList<>();
|
|
||||||
classNodes.clear();
|
classNodes.clear();
|
||||||
OTHER_FILES.clear();
|
OTHER_FILES.clear();
|
||||||
Enumeration<JarEntry> enumeration = jar.entries();
|
Enumeration<JarEntry> enumeration = jar.entries();
|
||||||
@@ -798,6 +830,17 @@ public class Main extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
jar.close();
|
jar.close();
|
||||||
|
refresh();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
classNodes.clear();
|
||||||
|
OTHER_FILES.clear();
|
||||||
|
e.printStackTrace();
|
||||||
|
showError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
setRoot(new DefaultMutableTreeNode(((DefaultMutableTreeNode) getRoot()).toString()));
|
||||||
Collections.sort(paths);
|
Collections.sort(paths);
|
||||||
for (String s : paths) {
|
for (String s : paths) {
|
||||||
String[] elements = s.split("/");
|
String[] elements = s.split("/");
|
||||||
@@ -812,12 +855,6 @@ public class Main extends JFrame {
|
|||||||
currentNode = nextNode;
|
currentNode = nextNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
|
||||||
classNodes.clear();
|
|
||||||
OTHER_FILES.clear();
|
|
||||||
e.printStackTrace();
|
|
||||||
showError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultMutableTreeNode findNode(DefaultMutableTreeNode parent, String name) {
|
private DefaultMutableTreeNode findNode(DefaultMutableTreeNode parent, String name) {
|
||||||
|
|||||||
Reference in new issue
Block a user