mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
[FEATURE] LauncherGuardInterface
This commit is contained in:
parent
ec0948594d
commit
642038576a
8 changed files with 135 additions and 9 deletions
|
@ -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");
|
||||
|
|
|
@ -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<String> args, ClientProfile profile, Params params) {
|
||||
PlayerProfile pp = params.pp;
|
||||
|
||||
|
@ -392,15 +401,7 @@ public static Process launch(
|
|||
List<String> 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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue