Some improvements of jar building.

This commit is contained in:
zaxar163 2018-12-03 16:07:49 +03:00
parent a55e22f6b2
commit 5d19f48951
No known key found for this signature in database
GPG key ID: E3B309DD3852DE06
4 changed files with 54 additions and 52 deletions

View file

@ -32,8 +32,7 @@ public void clear() {
// URL constants
private static final String DOWNLOAD_URL = "http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html"; // Oracle
// JRE
// 8
// JRE 8
// File constants
private final Path faviconFile;

View file

@ -130,14 +130,12 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
reader = new ClassMetadataReader();
UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), cleanJar);
reader.getCp().add(new JarFile(cleanJar.toFile()));
tryUnpackRuntime();
tryUnpackGuard();
tryUnpack();
}
@Override
public void build() throws IOException {
tryUnpackRuntime();
tryUnpackGuard();
tryUnpack();
// Build launcher binary
LogHelper.info("Building launcher binary file");
@ -287,44 +285,9 @@ private void stdBuild() throws IOException {
}
}
public void tryUnpackRuntime() throws IOException {
// Verify is guard dir unpacked
if (IOHelper.isDir(runtimeDir))
return; // Already unpacked
// Unpack launcher guard files
Files.createDirectory(runtimeDir);
LogHelper.info("Unpacking launcher runtime files");
if (Launcher.class.getResource("/runtime.zip") == null) return;
try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL("runtime.zip"))) {
for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
if (entry.isDirectory())
continue; // Skip dirs
// Unpack guard file
IOHelper.transfer(input, runtimeDir.resolve(IOHelper.toPath(entry.getName())));
}
}
}
public void tryUnpackGuard() throws IOException {
// Verify is guard dir unpacked
if (IOHelper.isDir(guardDir))
return; // Already unpacked
// Unpack launcher guard files
Files.createDirectory(guardDir);
LogHelper.info("Unpacking launcher native guard files");
if (Launcher.class.getResource("/guard.zip") == null) return;
try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL("guard.zip"))) {
for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
if (entry.isDirectory())
continue; // Skip dirs
// Unpack guard file
IOHelper.transfer(input, guardDir.resolve(IOHelper.toPath(entry.getName())));
}
}
public void tryUnpack() throws IOException {
LogHelper.info("Unpacking launcher native guard files and runtime");
UnpackHelper.unpackZipNoCheck("guard.zip", guardDir);
UnpackHelper.unpackZipNoCheck("runtime.zip", runtimeDir);
}
}

View file

@ -55,12 +55,12 @@ binaryName: "Launcher";
launch4J: {
enabled: true;
productName: "sashok724's Launcher v3 mod by Gravit";
productVer: "1.0.0.0";
productVer: "4.1.0.0";
fileDesc: "sashok724's Launcher v3 mod by Gravit";
fileVer: "1.0.0.0";
fileVer: "1.1.0.0";
internalName: "Launcher";
copyright: "© sashok724 LLC";
trademarks: "This product is licensed under MIT License";
trademarks: "This product is licensed under GNU GPL v3.0 License";
# version and build number
txtFileVersion: "%s, build %d";
txtProductVersion: "%s, build %d";

View file

@ -3,18 +3,22 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class UnpackHelper {
public static boolean unpack(URL resource, Path target) throws IOException {
if (IOHelper.exists(target)) {
if (IOHelper.isFile(target)) {
if (matches(target, resource)) return false;
}
if (!IOHelper.exists(target))
target.toFile().createNewFile();
Files.deleteIfExists(target);
Files.createFile(target);
try (InputStream in = IOHelper.newInput(resource)) {
IOHelper.transfer(in, target, false);
IOHelper.transfer(in, target);
}
return true;
}
@ -27,4 +31,40 @@ private static boolean matches(Path target, URL in) {
return false;
}
}
public static boolean unpackZipNoCheck(URL resource, Path target) throws IOException {
if (Files.isDirectory(target))
return false;
Files.deleteIfExists(target);
Files.createDirectory(target);
try (ZipInputStream input = IOHelper.newZipInput(resource)) {
for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
if (entry.isDirectory())
continue; // Skip dirs
// Unpack file
IOHelper.transfer(input, target.resolve(IOHelper.toPath(entry.getName())));
}
}
return true;
}
public static boolean unpackZipNoCheck(String resource, Path target) throws IOException {
try {
if (Files.isDirectory(target))
return false;
Files.deleteIfExists(target);
Files.createDirectory(target);
try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL(resource))) {
for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
if (entry.isDirectory())
continue; // Skip dirs
// Unpack file
IOHelper.transfer(input, target.resolve(IOHelper.toPath(entry.getName())));
}
}
return true;
} catch (NoSuchFileException e) {
return true;
}
}
}