From ff7887a006475d030aee6fa73440a98c066e5805 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Wed, 26 Dec 2018 16:17:47 +0300 Subject: [PATCH] Some fixes. --- .../main/java/ru/gravit/launchserver/LaunchServer.java | 8 +++++++- .../java/ru/gravit/launchserver/binary/BuildContext.java | 4 ++-- .../ru/gravit/launchserver/binary/JARLauncherBinary.java | 6 +++--- .../ru/gravit/launchserver/{ => binary}/ProguardConf.java | 6 +++--- .../launchserver/command/basic/ProguardCleanCommand.java | 6 +++++- 5 files changed, 20 insertions(+), 10 deletions(-) rename LaunchServer/src/main/java/ru/gravit/launchserver/{ => binary}/ProguardConf.java (95%) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index a1efd0bf..e165406e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -53,6 +53,7 @@ import ru.gravit.launchserver.binary.EXELauncherBinary; import ru.gravit.launchserver.binary.JARLauncherBinary; import ru.gravit.launchserver.binary.LauncherBinary; +import ru.gravit.launchserver.binary.ProguardConf; import ru.gravit.launchserver.command.handler.CommandHandler; import ru.gravit.launchserver.command.handler.JLineCommandHandler; import ru.gravit.launchserver.command.handler.StdCommandHandler; @@ -457,7 +458,12 @@ public static void initGson() } private LauncherBinary binary() { - if (config.launch4j.enabled) return new EXEL4JLauncherBinary(this); + try { + Class.forName("net.sf.launch4j.Builder"); + if (config.launch4j.enabled) return new EXEL4JLauncherBinary(this); + } catch (ClassNotFoundException ignored) { + LogHelper.warning("Launch4J isn't in classpath."); + } return new EXELauncherBinary(this); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java index 8c507ae1..fb982873 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java @@ -38,7 +38,7 @@ public void pushJarFile(ZipInputStream input) throws IOException { e = input.getNextEntry(); continue; } - output.putNextEntry(e); + output.putNextEntry(IOHelper.newZipEntry(e)); IOHelper.transfer(input, output); fileList.add(e.getName()); e = input.getNextEntry(); @@ -52,7 +52,7 @@ public void pushJarFile(ZipInputStream input, Set blacklist) throws IOEx e = input.getNextEntry(); continue; } - output.putNextEntry(e); + output.putNextEntry(IOHelper.newZipEntry(e)); IOHelper.transfer(input, output); fileList.add(e.getName()); e = input.getNextEntry(); 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 cf427556..f785a798 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -126,7 +126,7 @@ public JARLauncherBinary(LaunchServer server) throws IOException { runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR); guardDir = server.dir.resolve(Launcher.GUARD_DIR); initScriptFile = runtimeDir.resolve(Launcher.INIT_SCRIPT_FILE); - obfJar = server.dir.resolve(server.config.binaryName + "-obfed.jar"); + obfJar = server.dir.resolve(server.config.binaryName + "-obfPre.jar"); obfOutJar = server.config.buildPostTransform.enabled ? server.dir.resolve(server.config.binaryName + "-obf.jar") : syncBinaryFile; cleanJar = server.dir.resolve(server.config.binaryName + "-clean.jar"); @@ -162,7 +162,7 @@ public void build() throws IOException { ZipEntry e = input.getNextEntry(); while (e != null) { String filename = e.getName(); - output.putNextEntry(IOHelper.newZipEntry(e.getName())); + output.putNextEntry(IOHelper.newZipEntry(e)); if (filename.endsWith(".class")) { String classname = filename.replace('/', '.').substring(0, filename.length() - ".class".length()); byte[] bytes; @@ -226,7 +226,7 @@ private void stdBuild() throws IOException { continue; } try { - output.putNextEntry(IOHelper.newZipEntry(e.getName())); + output.putNextEntry(IOHelper.newZipEntry(e)); } catch (ZipException ex) { LogHelper.error(ex); e = input.getNextEntry(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java similarity index 95% rename from LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java index 29e38b60..f92464aa 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java @@ -1,4 +1,4 @@ -package ru.gravit.launchserver; +package ru.gravit.launchserver.binary; import java.io.IOException; import java.io.InputStream; @@ -10,6 +10,7 @@ import java.security.SecureRandom; import java.util.ArrayList; +import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; @@ -41,7 +42,7 @@ public ProguardConf(LaunchServer srv) { if (srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'"); confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add("-injar \'" + srv.dir.toAbsolutePath() + IOHelper.PLATFORM_SEPARATOR + srv.config.binaryName + "-nonObf.jar\'"); - confStrs.add("-outjar \'" + srv.dir.toAbsolutePath() + IOHelper.PLATFORM_SEPARATOR + srv.config.binaryName + "-obfed.jar\'"); + confStrs.add("-outjar \'" + srv.dir.toAbsolutePath() + IOHelper.PLATFORM_SEPARATOR + srv.config.binaryName + "-obfPre.jar\'"); confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add(readConf()); @@ -59,7 +60,6 @@ private void genConfig(boolean force) throws IOException { public void genWords(boolean force) throws IOException { if (IOHelper.exists(words) && !force) return; Files.deleteIfExists(words); - words.toFile().createNewFile(); SecureRandom rand = SecurityHelper.newRandom(); rand.setSeed(SecureRandom.getSeed(32)); try (PrintWriter out = new PrintWriter(new OutputStreamWriter(IOHelper.newOutput(words), IOHelper.UNICODE_CHARSET))) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ProguardCleanCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ProguardCleanCommand.java index 704f1c6d..b2dd5014 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ProguardCleanCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ProguardCleanCommand.java @@ -1,5 +1,8 @@ package ru.gravit.launchserver.command.basic; +import java.io.IOException; +import java.nio.file.Files; + import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; @@ -19,7 +22,8 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) { + public void invoke(String... args) throws IOException { server.proguardConf.prepare(true); + Files.deleteIfExists(server.proguardConf.mappings); } }