diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 4b1bca74..db5a797a 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -5,6 +5,7 @@ import ru.gravit.launcher.client.DirBridge; import ru.gravit.launcher.client.FunctionalBridge; import ru.gravit.launcher.client.LauncherSettings; +import ru.gravit.launcher.guard.LauncherGuardManager; import ru.gravit.launcher.gui.JSRuntimeProvider; import ru.gravit.launcher.gui.RuntimeProvider; import ru.gravit.utils.helper.CommonHelper; @@ -61,6 +62,7 @@ public void start(String... args) throws Throwable { Launcher.modulesManager = new ClientModuleManager(this); LauncherConfig.getAutogenConfig().initModules(); Launcher.modulesManager.preInitModules(); + LauncherGuardManager.initGuard(false); if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider(); runtimeProvider.init(false); Objects.requireNonNull(args, "args"); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index 251cc728..932ddf80 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -3,6 +3,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import ru.gravit.launcher.*; +import ru.gravit.launcher.guard.LauncherGuardManager; import ru.gravit.launcher.gui.JSRuntimeProvider; import ru.gravit.launcher.hasher.DirWatcher; import ru.gravit.launcher.hasher.FileNameMatcher; @@ -231,6 +232,14 @@ public static class ClientUserProperties { String[] cloakDigest; } + public static boolean isDownloadJava() { + return isDownloadJava; + } + + public static Path getJavaBinPath() { + return JavaBinPath; + } + private static void addClientArgs(Collection args, ClientProfile profile, Params params) { PlayerProfile pp = params.pp; @@ -392,15 +401,7 @@ public static Process launch( List args = new LinkedList<>(); boolean wrapper = isUsingWrapper(); LogHelper.debug("Resolving JVM binary"); - Path javaBin = null; - if (isDownloadJava) { - //Linux и Mac не должны скачивать свою JVM - if (JVMHelper.OS_TYPE == OS.MUSTDIE) - javaBin = IOHelper.resolveJavaBin(JavaBinPath); - else - javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); - } else - javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); + Path javaBin = LauncherGuardManager.getGuardJavaBinPath(); args.add(javaBin.toString()); args.add(MAGICAL_INTEL_OPTION); if (params.ram > 0 && params.ram <= JVMHelper.RAM) { @@ -468,6 +469,7 @@ public static void main(String... args) throws Throwable { LauncherConfig.getAutogenConfig().initModules(); //INIT initGson(); Launcher.modulesManager.preInitModules(); + LauncherGuardManager.initGuard(true); checkJVMBitsAndVersion(); JVMHelper.verifySystemProperties(ClientLauncher.class, true); EnvHelper.checkDangerousParams(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java index 4d7b346d..c24b966a 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java @@ -59,6 +59,11 @@ public static Path getAppDataDir() throws IOException { public static Path getLauncherDir(String projectname) throws IOException { return getAppDataDir().resolve(projectname); } + @LauncherAPI + public static Path getGuardDir() + { + return dir.resolve("guard"); + } @LauncherAPI public static Path getLegacyLauncherDir(String projectname) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardInterface.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardInterface.java new file mode 100644 index 00000000..429cd0ca --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardInterface.java @@ -0,0 +1,9 @@ +package ru.gravit.launcher.guard; + +import java.nio.file.Path; + +public interface LauncherGuardInterface { + String getName(); + Path getJavaBinPath(); + void init(boolean clientInstance); +} diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardManager.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardManager.java new file mode 100644 index 00000000..804bbb3d --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardManager.java @@ -0,0 +1,27 @@ +package ru.gravit.launcher.guard; + +import ru.gravit.launcher.client.ClientLauncher; +import ru.gravit.utils.helper.LogHelper; + +import java.nio.file.Path; + +public class LauncherGuardManager { + public static LauncherGuardInterface guard; + public static void initGuard(boolean clientInstance) + { + if(ClientLauncher.isUsingWrapper()) + { + guard = new LauncherWrapperGuard(); + } + else if(ClientLauncher.isDownloadJava()) + { + guard = new LauncherJavaGuard(); + } + else guard = new LauncherNoGuard(); + guard.init(clientInstance); + } + public static Path getGuardJavaBinPath() + { + return guard.getJavaBinPath(); + } +} diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherJavaGuard.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherJavaGuard.java new file mode 100644 index 00000000..06659f42 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherJavaGuard.java @@ -0,0 +1,28 @@ +package ru.gravit.launcher.guard; + +import ru.gravit.launcher.client.ClientLauncher; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.JVMHelper; + +import java.nio.file.Path; +import java.nio.file.Paths; + +public class LauncherJavaGuard implements LauncherGuardInterface { + @Override + public String getName() { + return "java"; + } + + @Override + public Path getJavaBinPath() { + if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) + return ClientLauncher.getJavaBinPath(); + else + return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); + } + + @Override + public void init(boolean clientInstance) { + + } +} diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherNoGuard.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherNoGuard.java new file mode 100644 index 00000000..c49799ac --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherNoGuard.java @@ -0,0 +1,25 @@ +package ru.gravit.launcher.guard; + +import ru.gravit.launcher.client.DirBridge; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + +import java.nio.file.Path; +import java.nio.file.Paths; + +public class LauncherNoGuard implements LauncherGuardInterface { + @Override + public String getName() { + return "noGuard"; + } + + @Override + public Path getJavaBinPath() { + return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); + } + + @Override + public void init(boolean clientInstance) { + LogHelper.warning("Using noGuard interface"); + } +} diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherWrapperGuard.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherWrapperGuard.java new file mode 100644 index 00000000..59d8f74c --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherWrapperGuard.java @@ -0,0 +1,28 @@ +package ru.gravit.launcher.guard; + +import ru.gravit.launcher.client.DirBridge; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.JVMHelper; + +import java.nio.file.Path; +import java.nio.file.Paths; + +public class LauncherWrapperGuard implements LauncherGuardInterface { + @Override + public String getName() { + return "wrapper"; + } + + @Override + public Path getJavaBinPath() { + if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) + return DirBridge.getGuardDir().resolve(JVMHelper.JVM_BITS == 64 ? "wrapper64.exe" : "wrapper32.exe"); + else + return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); + } + + @Override + public void init(boolean clientInstance) { + + } +}