Skip to content

Commit

Permalink
Final zip file is now created.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Watling committed Jan 3, 2016
1 parent 8ad9b87 commit 5423b4d
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.danwatling.apkdecompiler.steps;

import com.danwatling.apkdecompiler.Logger;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.model.ZipParameters;

import java.io.File;

/**
Expand All @@ -15,6 +19,36 @@ public GenerateFinalZip(File workFolder) {
public boolean run() {
boolean result = true;

generateZipFile();
removeWorkFolder();

return result;
}

private void generateZipFile() {
try {
File outputFile = new File(this.workFolder.getName() + ".zip");
if (outputFile.exists()) {
Logger.info(outputFile.getAbsolutePath() + " already exists. Deleting.");
outputFile.delete();
}
ZipFile output = new net.lingala.zip4j.core.ZipFile(outputFile);
Logger.info("Generating " + output.getFile().getAbsolutePath());

ZipParameters params = new ZipParameters();
params.setIncludeRootFolder(false);
params.setRootFolderInZip("");
output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "apktool", params);
params.setRootFolderInZip("classes");
output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "classes", params);
} catch (Throwable t) {
Logger.error("Unable to generate final zip file.", t);
}
}

private void removeWorkFolder() {
if (!workFolder.delete()) {
Logger.info("Unable to remove " + workFolder.getAbsolutePath());
}
}
}

0 comments on commit 5423b4d

Please sign in to comment.