Improvements

This commit is contained in:
SuspiciousActivity authored and GitHub committed 2020-11-23 19:52:23 +01:00
1 parent c91d8ccada
commit a70bc89deb
1 file changed
+64 -25
+64 -25
View File
@@ -98,7 +98,7 @@ public class Main extends JFrame {
public static Main INSTANCE;
private JPanel contentPane;
private boolean isChangingFile;
private volatile boolean isChangingFile;
public static File jarFile;
public static HashMap<String, byte[]> OTHER_FILES = new HashMap<>();
public static HashMap<String, ClassNode> classNodes = new HashMap<>();
@@ -118,6 +118,8 @@ public class Main extends JFrame {
public static HashSet<String> fakedFolders = new HashSet<>();
public static final Object treeLock = new Object();
/**
* Launch the application.
*/
@@ -255,18 +257,36 @@ public class Main extends JFrame {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == 116 && jarFile != null) { // F5
synchronized (treeLock) {
if (isChangingFile) {
return;
}
try {
isChangingFile = true;
Main.this.setTitle("ByteEdit - Reloading...");
new Thread(new Runnable() {
public void run() {
try {
tree.setModel(new ArchiveTreeModel(new JarFile(jarFile)));
} catch (IOException e1) {
e1.printStackTrace();
}
ArchiveTreeModel model = new ArchiveTreeModel(new JarFile(jarFile));
EventQueue.invokeLater(new Runnable() {
public void run() {
synchronized (treeLock) {
tree.setModel(model);
isChangingFile = false;
Main.this.setTitle("ByteEdit");
}
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
} catch (Throwable t) {
t.printStackTrace();
showError(t);
}
}
} else if (e.getKeyCode() == 127) { // del
if (tree.getSelectionPath() == null)
return;
@@ -310,15 +330,22 @@ public class Main extends JFrame {
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
synchronized (treeLock) {
if (!isChangingFile) {
selectFile(((ByteEditTreeNode) e.getPath().getLastPathComponent()).path);
}
}
}
});
new DropTarget(tree, new DropTargetListener() {
@Override
public void drop(DropTargetDropEvent dtde) {
synchronized (treeLock) {
if (isChangingFile) {
dtde.rejectDrop();
return;
}
try {
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
@@ -332,10 +359,18 @@ public class Main extends JFrame {
saveFolder = file.getParentFile();
isChangingFile = true;
try {
tree.setModel(new ArchiveTreeModel(new JarFile(jarFile)));
} catch (IOException e1) {
e1.printStackTrace();
Main.this.setTitle("ByteEdit - Loading '" + jarFile.getCanonicalPath() + "'");
} catch (IOException ex) {
Main.this.setTitle("ByteEdit - Loading '" + jarFile.getAbsolutePath() + "'");
}
new Thread(new Runnable() {
public void run() {
try {
ArchiveTreeModel model = new ArchiveTreeModel(new JarFile(jarFile));
EventQueue.invokeLater(new Runnable() {
public void run() {
synchronized (treeLock) {
tree.setModel(model);
txtByteEditView.setText("");
currentNodeName = null;
globalSearchBox.setVisible(false);
@@ -346,8 +381,18 @@ public class Main extends JFrame {
renameBox.setVisible(false);
compilationBox.setVisible(false);
isChangingFile = false;
Main.this.setTitle("ByteEdit");
}
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
dtde.dropComplete(true);
break;
}
}
return;
@@ -355,6 +400,7 @@ public class Main extends JFrame {
t.printStackTrace();
showError(t);
}
}
dtde.rejectDrop();
}
@@ -543,14 +589,10 @@ public class Main extends JFrame {
if (line.startsWith("invoke")) {
String[] split = line.split(" ");
String desc = UnicodeUtils.unescape(split[1]);
String className = UnicodeUtils.unescape(split[2]);
String[] nameSplit = className.split("/");
String methodName = nameSplit[nameSplit.length - 1];
className = className.substring(0, className.length() - methodName.length() - 1);
while (className.endsWith("/")) {
methodName = "/" + methodName;
className = className.substring(0, className.length() - 1);
}
String target = split[2];
int index = target.lastIndexOf("/");
String className = UnicodeUtils.unescape(target.substring(0, index));
String methodName = UnicodeUtils.unescape(target.substring(index + 1));
ClassNode classNode = classNodes.get(getFullName(className));
if (classNode == null) {
return;
@@ -579,14 +621,10 @@ public class Main extends JFrame {
|| line.startsWith("putfield ")) {
String[] split = line.split(" ");
String desc = UnicodeUtils.unescape(split[1]);
String className = UnicodeUtils.unescape(split[2]);
String[] nameSplit = className.split("/");
String fieldName = nameSplit[nameSplit.length - 1];
className = className.substring(0, className.length() - fieldName.length() - 1);
while (className.endsWith("/")) {
fieldName = "/" + fieldName;
className = className.substring(0, className.length() - 1);
}
String target = split[2];
int index = target.lastIndexOf("/");
String className = UnicodeUtils.unescape(target.substring(0, index));
String fieldName = UnicodeUtils.unescape(target.substring(index + 1));
ClassNode classNode = classNodes.get(getFullName(className));
if (classNode == null) {
return;
@@ -909,9 +947,10 @@ public class Main extends JFrame {
}
});
// Windows-like sorting (like file explorer)
List<String> tmp = new ArrayList<>(paths);
List<String> folders = tmp.stream().map(s -> {
List<String> folders = tmp.stream().filter(s -> s.contains("/")).map(s -> {
int idx = s.lastIndexOf('/');
if (idx == s.length() - 1)
idx = s.lastIndexOf('/', idx - 1);