Skip to content

Commit

Permalink
Add support for DBPF compression when using command line. `pack input…
Browse files Browse the repository at this point in the history
…Folder outputFile -compress 0`, with 0 being the file size threshold to compress.
  • Loading branch information
emd4600 committed Jan 6, 2024
1 parent 749eefd commit e6b1e86
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/sporemodder/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,12 @@ public static class PackCommand implements Callable<Integer> {

@Parameters(index = "0", description = "The input folder to pack.")
private File input;

@Parameters(index = "1", description = "The output DBPF file to generate.")
private File output;

@Option(names = {"--compress"}, description = "[Experimental] Compress files bigger than N bytes")
private int compressThreshold = -1;

@Override
public Integer call() throws Exception {
Expand All @@ -375,6 +378,7 @@ public Integer call() throws Exception {

startTime = System.currentTimeMillis();
final DBPFPackingTask task = new DBPFPackingTask(input, output);
task.setCompressThreshold(compressThreshold);
task.setNoJavaFX();
task.setNoJavaFXProgressListener(PROGRESS_BAR_LISTENER);

Expand Down
18 changes: 18 additions & 0 deletions src/sporemodder/file/dbpf/DBPFPackingTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class DBPFPackingTask extends Task<Void> {

private boolean noJavaFX = false;
private Consumer<Double> noJavaFXProgressListener;
private int compressThreshold = -1;

public DBPFPackingTask(Project project, boolean storeDebugInformation) {
this.inputFolder = project.getFolder();
Expand Down Expand Up @@ -298,6 +299,7 @@ public Void call() throws Exception {
}

this.packer = packer;
packer.setCompressThreshold(compressThreshold);

pack();
}
Expand Down Expand Up @@ -379,4 +381,20 @@ private void writePackageSignature(boolean alreadyHasPackageSignature) throws IO
}
}

/**
* If a file size is bigger than this threshold, the file data will be compressed.
* @param compressThreshold
*/
public void setCompressThreshold(int compressThreshold) {
this.compressThreshold = compressThreshold;
}

/**
* If a file size is bigger than this threshold, the file data will be compressed.
* @return
*/
public int getCompressThreshold() {
return compressThreshold;
}

}

0 comments on commit e6b1e86

Please sign in to comment.