diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java index fe8091db..7b83ea97 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java @@ -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; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java index 88d60a66..650a2fee 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -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); } } diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg index fa9dba4d..954f8d01 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg @@ -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"; diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java index 62f0c45c..ca00a3a7 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java @@ -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; + } + } }