Skip to content

Commit

Permalink
save single file as .class
Browse files Browse the repository at this point in the history
  • Loading branch information
apkreader committed Jul 12, 2024
1 parent 1b15f13 commit d54d7bc
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/main/java/me/grax/jbytemod/utils/task/SaveTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;

public class SaveTask extends SwingWorker<Void, Integer> {

private File output;
private PageEndPanel jpb;
private JarArchive file;
private final File output;
private final PageEndPanel jpb;
private final JarArchive file;

public SaveTask(JByteMod jbm, File output, JarArchive file) {
this.output = output;
Expand All @@ -42,10 +43,10 @@ protected Void doInBackground() throws Exception {
CustomClassWriter writer = new CustomClassWriter(flags);
node.accept(writer);
publish(50);
Main.INSTANCE.getLogger().log("Saving..");
Files.write(this.output.toPath(), writer.toByteArray());
Main.INSTANCE.getLogger().log("Saving..");
Files.write(new File(this.output.toString().replace(".jar", ".class")).toPath(), writer.toByteArray());
publish(100);
Main.INSTANCE.getLogger().log("Saving successful!");
Main.INSTANCE.getLogger().log("Saving successful!");
return null;
}

Expand Down Expand Up @@ -78,17 +79,15 @@ protected Void doInBackground() throws Exception {

public void saveAsJarNew(Map<String, byte[]> outBytes, String fileName) {
try {
ZipOutputStream out = new ZipOutputStream(new java.io.FileOutputStream(fileName));
ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(Paths.get(fileName)));
out.setEncoding("UTF-8");
for (String entry : outBytes.keySet()) {
out.putNextEntry(new ZipEntry(entry));
if (!entry.endsWith("/") || !entry.endsWith("\\"))
out.write(outBytes.get(entry));
out.closeEntry();
}
if (out != null) {
out.close();
}
out.close();

} catch (IOException e) {
e.printStackTrace();
Expand Down

0 comments on commit d54d7bc

Please sign in to comment.