Skip to content

Commit

Permalink
fix jbytemod changing empty file names and removing empty directories
Browse files Browse the repository at this point in the history
(#62)
  • Loading branch information
GraxCode committed Aug 29, 2018
1 parent 64e9628 commit c404204
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private String escape(String absolutePath) {

private File createTempJar(byte[] b) {
File temp = new File(tempDir, b.hashCode() + ".jar");
JarUtils.saveAsJar(Collections.singletonMap(cn.name, b), temp.getAbsolutePath());
JarUtils.saveAsJar(Collections.singletonMap(cn.name + ".class", b), temp.getAbsolutePath());
return temp;
}

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/me/grax/jbytemod/utils/task/LoadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private void readJar(JarFile jar, JarEntry en, Map<String, ClassNode> classes, M
publish((int) (((float) loaded++ / (float) jarSize) * 100f));
String name = en.getName();
try (InputStream jis = jar.getInputStream(en)) {
System.out.println(name + " " + en.isDirectory());
if (name.endsWith(".class")) {
byte[] bytes = IOUtils.toByteArray(jis);
String cafebabe = String.format("%02X%02X%02X%02X", bytes[0], bytes[1], bytes[2], bytes[3]);
Expand All @@ -104,9 +105,13 @@ private void readJar(JarFile jar, JarEntry en, Map<String, ClassNode> classes, M
JByteMod.LOGGER.err("Failed loading class file " + name);
}
}
} else if (!en.isDirectory()) {
byte[] bytes = IOUtils.toByteArray(jis);
otherFiles.put(name, bytes);
} else {
if (!en.isDirectory()) {
byte[] bytes = IOUtils.toByteArray(jis);
otherFiles.put(name, bytes);
} else {
otherFiles.put(name, new byte[0]);
}
}
if (memoryWarning) {
long timeDif = System.currentTimeMillis() - ms;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/grax/jbytemod/utils/task/SaveTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected Void doInBackground() throws Exception {
ClassNode node = classes.get(s);
ClassWriter writer = new ClassWriter(flags);
node.accept(writer);
outputBytes.put(s, writer.toByteArray());
outputBytes.put(s + ".class", writer.toByteArray());
publish((int) ((i++ / size) * 50d));
}
publish(50);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/lpk/util/JarUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public static void saveAsJar(Map<String, byte[]> outBytes, String fileName) {
try {
JarOutputStream out = new JarOutputStream(new java.io.FileOutputStream(fileName));
for (String entry : outBytes.keySet()) {
String ext = entry.contains(".") ? "" : ".class";
out.putNextEntry(new ZipEntry(entry + ext));
out.write(outBytes.get(entry));
out.putNextEntry(new ZipEntry(entry));
if (!entry.endsWith("/"))
out.write(outBytes.get(entry));
out.closeEntry();
}
out.close();
Expand Down

1 comment on commit c404204

@MadTooth
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Spasibo you very nice very good fix, I'll make a new video for your cool program on YouTube channel -> Cheezoed

Please sign in to comment.