[FEATURE] LauncherGuardInterface

This commit is contained in:
Gravit 2019-01-21 15:52:08 +07:00
parent ec0948594d
commit 642038576a
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
8 changed files with 135 additions and 9 deletions

View file

@ -5,6 +5,7 @@
import ru.gravit.launcher.client.DirBridge; import ru.gravit.launcher.client.DirBridge;
import ru.gravit.launcher.client.FunctionalBridge; import ru.gravit.launcher.client.FunctionalBridge;
import ru.gravit.launcher.client.LauncherSettings; import ru.gravit.launcher.client.LauncherSettings;
import ru.gravit.launcher.guard.LauncherGuardManager;
import ru.gravit.launcher.gui.JSRuntimeProvider; import ru.gravit.launcher.gui.JSRuntimeProvider;
import ru.gravit.launcher.gui.RuntimeProvider; import ru.gravit.launcher.gui.RuntimeProvider;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
@ -61,6 +62,7 @@ public void start(String... args) throws Throwable {
Launcher.modulesManager = new ClientModuleManager(this); Launcher.modulesManager = new ClientModuleManager(this);
LauncherConfig.getAutogenConfig().initModules(); LauncherConfig.getAutogenConfig().initModules();
Launcher.modulesManager.preInitModules(); Launcher.modulesManager.preInitModules();
LauncherGuardManager.initGuard(false);
if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider(); if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider();
runtimeProvider.init(false); runtimeProvider.init(false);
Objects.requireNonNull(args, "args"); Objects.requireNonNull(args, "args");

View file

@ -3,6 +3,7 @@
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import ru.gravit.launcher.*; import ru.gravit.launcher.*;
import ru.gravit.launcher.guard.LauncherGuardManager;
import ru.gravit.launcher.gui.JSRuntimeProvider; import ru.gravit.launcher.gui.JSRuntimeProvider;
import ru.gravit.launcher.hasher.DirWatcher; import ru.gravit.launcher.hasher.DirWatcher;
import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.FileNameMatcher;
@ -231,6 +232,14 @@ public static class ClientUserProperties {
String[] cloakDigest; String[] cloakDigest;
} }
public static boolean isDownloadJava() {
return isDownloadJava;
}
public static Path getJavaBinPath() {
return JavaBinPath;
}
private static void addClientArgs(Collection<String> args, ClientProfile profile, Params params) { private static void addClientArgs(Collection<String> args, ClientProfile profile, Params params) {
PlayerProfile pp = params.pp; PlayerProfile pp = params.pp;
@ -392,15 +401,7 @@ public static Process launch(
List<String> args = new LinkedList<>(); List<String> args = new LinkedList<>();
boolean wrapper = isUsingWrapper(); boolean wrapper = isUsingWrapper();
LogHelper.debug("Resolving JVM binary"); LogHelper.debug("Resolving JVM binary");
Path javaBin = null; Path javaBin = LauncherGuardManager.getGuardJavaBinPath();
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")));
args.add(javaBin.toString()); args.add(javaBin.toString());
args.add(MAGICAL_INTEL_OPTION); args.add(MAGICAL_INTEL_OPTION);
if (params.ram > 0 && params.ram <= JVMHelper.RAM) { if (params.ram > 0 && params.ram <= JVMHelper.RAM) {
@ -468,6 +469,7 @@ public static void main(String... args) throws Throwable {
LauncherConfig.getAutogenConfig().initModules(); //INIT LauncherConfig.getAutogenConfig().initModules(); //INIT
initGson(); initGson();
Launcher.modulesManager.preInitModules(); Launcher.modulesManager.preInitModules();
LauncherGuardManager.initGuard(true);
checkJVMBitsAndVersion(); checkJVMBitsAndVersion();
JVMHelper.verifySystemProperties(ClientLauncher.class, true); JVMHelper.verifySystemProperties(ClientLauncher.class, true);
EnvHelper.checkDangerousParams(); EnvHelper.checkDangerousParams();

View file

@ -59,6 +59,11 @@ public static Path getAppDataDir() throws IOException {
public static Path getLauncherDir(String projectname) throws IOException { public static Path getLauncherDir(String projectname) throws IOException {
return getAppDataDir().resolve(projectname); return getAppDataDir().resolve(projectname);
} }
@LauncherAPI
public static Path getGuardDir()
{
return dir.resolve("guard");
}
@LauncherAPI @LauncherAPI
public static Path getLegacyLauncherDir(String projectname) { public static Path getLegacyLauncherDir(String projectname) {

View file

@ -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);
}

View file

@ -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();
}
}

View file

@ -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) {
}
}

View file

@ -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");
}
}

View file

@ -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) {
}
}