Фитча для модулей - список файлов в jar лаунчера

Упрощает процедуру внедрения своих файлов в JAR
This commit is contained in:
Gravit 2018-12-26 16:34:18 +07:00
parent e915d408a9
commit 0862e3c541
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 12 additions and 0 deletions

View file

@ -4,6 +4,7 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -13,24 +14,33 @@ public class BuildContext {
public final ZipOutputStream output; public final ZipOutputStream output;
public final JAConfigurator config; public final JAConfigurator config;
public final JARLauncherBinary data; public final JARLauncherBinary data;
public final HashSet<String> fileList;
public BuildContext(ZipOutputStream output, JAConfigurator config, JARLauncherBinary data) { public BuildContext(ZipOutputStream output, JAConfigurator config, JARLauncherBinary data) {
this.output = output; this.output = output;
this.config = config; this.config = config;
this.data = data; this.data = data;
fileList = new HashSet<>(1024);
} }
public void pushFile(String filename, InputStream inputStream) throws IOException { public void pushFile(String filename, InputStream inputStream) throws IOException {
ZipEntry zip = IOHelper.newZipEntry(filename); ZipEntry zip = IOHelper.newZipEntry(filename);
output.putNextEntry(zip); output.putNextEntry(zip);
IOHelper.transfer(inputStream, output); IOHelper.transfer(inputStream, output);
fileList.add(filename);
} }
public void pushJarFile(ZipInputStream input) throws IOException { public void pushJarFile(ZipInputStream input) throws IOException {
ZipEntry e = input.getNextEntry(); ZipEntry e = input.getNextEntry();
while (e != null) { while (e != null) {
if (fileList.contains(e.getName())) {
e = input.getNextEntry();
continue;
}
output.putNextEntry(e); output.putNextEntry(e);
IOHelper.transfer(input, output); IOHelper.transfer(input, output);
fileList.add(e.getName());
e = input.getNextEntry(); e = input.getNextEntry();
} }
} }
@ -44,6 +54,7 @@ public void pushJarFile(ZipInputStream input, Set<String> blacklist) throws IOEx
} }
output.putNextEntry(e); output.putNextEntry(e);
IOHelper.transfer(input, output); IOHelper.transfer(input, output);
fileList.add(e.getName());
e = input.getNextEntry(); e = input.getNextEntry();
} }
} }

View file

@ -242,6 +242,7 @@ private void stdBuild() throws IOException {
} }
} else } else
IOHelper.transfer(input, output); IOHelper.transfer(input, output);
context.fileList.add(filename);
e = input.getNextEntry(); e = input.getNextEntry();
} }
} }