From a0d552e573fdc65b8cd24c29371fd8e424e3abdc Mon Sep 17 00:00:00 2001 From: Szperak Date: Mon, 31 Aug 2015 16:35:39 +0200 Subject: [PATCH] Class files are now added to the list file contents --- .../club/bytecodeviewer/JarUtils.java | 36 ++++++++++--------- .../gui/FileNavigationPane.java | 30 ---------------- 2 files changed, 19 insertions(+), 47 deletions(-) diff --git a/src/the/bytecode/club/bytecodeviewer/JarUtils.java b/src/the/bytecode/club/bytecodeviewer/JarUtils.java index 8e148d00..98240b66 100644 --- a/src/the/bytecode/club/bytecodeviewer/JarUtils.java +++ b/src/the/bytecode/club/bytecodeviewer/JarUtils.java @@ -63,26 +63,28 @@ public class JarUtils { try { final String name = entry.getName(); final byte[] bytes = getBytes(jis); - if (!name.endsWith(".class")) { - if(!entry.isDirectory()) - files.put(name, bytes); - } else { - String cafebabe = String.format("%02X", bytes[0]) - + String.format("%02X", bytes[1]) - + String.format("%02X", bytes[2]) - + String.format("%02X", bytes[3]); - if(cafebabe.toLowerCase().equals("cafebabe")) { - try { - final ClassNode cn = getNode(bytes); - container.classes.add(cn); - } catch(Exception e) { - e.printStackTrace(); - } + if(!files.containsKey(name)){ + if (!name.endsWith(".class")) { + if(!entry.isDirectory()) + files.put(name, bytes); } else { - System.out.println(jarFile+">"+name+": Header does not start with CAFEBABE, ignoring."); + String cafebabe = String.format("%02X", bytes[0]) + + String.format("%02X", bytes[1]) + + String.format("%02X", bytes[2]) + + String.format("%02X", bytes[3]); + if(cafebabe.toLowerCase().equals("cafebabe")) { + try { + final ClassNode cn = getNode(bytes); + container.classes.add(cn); + } catch(Exception e) { + e.printStackTrace(); + } + } else { + System.out.println(jarFile+">"+name+": Header does not start with CAFEBABE, ignoring."); + } + files.put(name, bytes); } } - } catch(Exception e) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); } finally { diff --git a/src/the/bytecode/club/bytecodeviewer/gui/FileNavigationPane.java b/src/the/bytecode/club/bytecodeviewer/gui/FileNavigationPane.java index 70a37c1c..149a121b 100644 --- a/src/the/bytecode/club/bytecodeviewer/gui/FileNavigationPane.java +++ b/src/the/bytecode/club/bytecodeviewer/gui/FileNavigationPane.java @@ -311,36 +311,6 @@ public class FileNavigationPane extends VisibleComponent implements ImageRenderer renderer = new ImageRenderer(); tree.setCellRenderer(renderer); - if(!container.classes.isEmpty()) { - for(ClassNode c : container.classes) { - String name = c.name; - final String[] spl = name.split("/"); - if (spl.length < 2) { - root.add(new MyTreeNode(name+".class")); - } else { - MyTreeNode parent = root; - for (int i1 = 0; i1 < spl.length; i1++) { - String s = spl[i1]; - MyTreeNode child = null; - for (int i = 0; i < parent.getChildCount(); i++) { - if (((MyTreeNode) parent.getChildAt(i)).getUserObject() - .equals(s)) { - child = (MyTreeNode) parent.getChildAt(i); - break; - } - } - if (child == null) { - if(i1 == spl.length-1) - child = new MyTreeNode(s+".class"); - else - child = new MyTreeNode(s); - parent.add(child); - } - parent = child; - } - } - } - } if(!container.files.isEmpty()) { for (final Entry entry : container.files.entrySet()) {