mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
[FEATURE] Включена фитча customDir
This commit is contained in:
parent
f157e9c01f
commit
88be2a623b
5 changed files with 26 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
package ru.gravit.launcher;
|
package ru.gravit.launcher;
|
||||||
|
|
||||||
import ru.gravit.launcher.client.ClientLauncher;
|
import ru.gravit.launcher.client.ClientLauncher;
|
||||||
|
import ru.gravit.launcher.client.DirBridge;
|
||||||
import ru.gravit.utils.helper.EnvHelper;
|
import ru.gravit.utils.helper.EnvHelper;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.JVMHelper;
|
import ru.gravit.utils.helper.JVMHelper;
|
||||||
|
@ -19,18 +20,22 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
|
||||||
LogHelper.printLicense("Launcher");
|
LogHelper.printLicense("Launcher");
|
||||||
LogHelper.info("Restart Launcher with JavaAgent...");
|
LogHelper.info("Restart Launcher with JavaAgent...");
|
||||||
LogHelper.info("If need debug output use -Dlauncher.debug=true");
|
LogHelper.info("If need debug output use -Dlauncher.debug=true");
|
||||||
|
LogHelper.info("If need stacktrace output use -Dlauncher.stacktrace=true");
|
||||||
JVMHelper.checkStackTrace(ClientLauncherWrapper.class);
|
JVMHelper.checkStackTrace(ClientLauncherWrapper.class);
|
||||||
JVMHelper.verifySystemProperties(Launcher.class, true);
|
JVMHelper.verifySystemProperties(Launcher.class, true);
|
||||||
EnvHelper.checkDangerousParams();
|
EnvHelper.checkDangerousParams();
|
||||||
LogHelper.debug("Restart Launcher");
|
LogHelper.debug("Restart Launcher");
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder();
|
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||||
processBuilder.inheritIO();
|
if (LogHelper.isDebugEnabled()) processBuilder.inheritIO();
|
||||||
Path javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
Path javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
||||||
List<String> args = new LinkedList<>();
|
List<String> args = new LinkedList<>();
|
||||||
args.add(javaBin.toString());
|
args.add(javaBin.toString());
|
||||||
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
|
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
|
||||||
args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled())));
|
args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled())));
|
||||||
args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled())));
|
args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled())));
|
||||||
|
JVMHelper.addSystemPropertyToArgs(args, DirBridge.CUSTOMDIR_PROPERTY);
|
||||||
|
JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_CUSTOMDIR_PROPERTY);
|
||||||
|
JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_OPTDIR_PROPERTY);
|
||||||
Collections.addAll(args, "-javaagent:".concat(pathLauncher));
|
Collections.addAll(args, "-javaagent:".concat(pathLauncher));
|
||||||
Collections.addAll(args, "-cp");
|
Collections.addAll(args, "-cp");
|
||||||
Collections.addAll(args, pathLauncher);
|
Collections.addAll(args, pathLauncher);
|
||||||
|
|
|
@ -58,7 +58,6 @@ private LauncherEngine() {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public void start(String... args) throws Throwable {
|
public void start(String... args) throws Throwable {
|
||||||
LogHelper.debug("%d", LauncherSettings.settingsMagic);
|
|
||||||
Launcher.modulesManager = new ClientModuleManager(this);
|
Launcher.modulesManager = new ClientModuleManager(this);
|
||||||
LauncherConfig.getAutogenConfig().initModules();
|
LauncherConfig.getAutogenConfig().initModules();
|
||||||
Launcher.modulesManager.preInitModules();
|
Launcher.modulesManager.preInitModules();
|
||||||
|
|
|
@ -347,6 +347,9 @@ public static Process launch(
|
||||||
context.args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled())));
|
context.args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled())));
|
||||||
context.args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled())));
|
context.args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled())));
|
||||||
context.args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled())));
|
context.args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled())));
|
||||||
|
JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.CUSTOMDIR_PROPERTY);
|
||||||
|
JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_CUSTOMDIR_PROPERTY);
|
||||||
|
JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_OPTDIR_PROPERTY);
|
||||||
if (LauncherConfig.ADDRESS_OVERRIDE != null)
|
if (LauncherConfig.ADDRESS_OVERRIDE != null)
|
||||||
context.args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE));
|
context.args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE));
|
||||||
if (JVMHelper.OS_TYPE == OS.MUSTDIE) {
|
if (JVMHelper.OS_TYPE == OS.MUSTDIE) {
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class DirBridge {
|
public class DirBridge {
|
||||||
|
|
||||||
|
public static final String USE_CUSTOMDIR_PROPERTY = "launcher.usecustomdir";
|
||||||
|
public static final String CUSTOMDIR_PROPERTY = "launcher.customdir";
|
||||||
|
public static final String USE_OPTDIR_PROPERTY = "launcher.useoptdir";
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static Path dir;
|
public static Path dir;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -27,12 +32,12 @@ public static void move(Path newDir) throws IOException {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static Path getAppDataDir() throws IOException {
|
public static Path getAppDataDir() throws IOException {
|
||||||
Boolean isCustomDir = Boolean.getBoolean(System.getProperty("launcher.usecustomdir", "false"));
|
boolean isCustomDir = Boolean.getBoolean(System.getProperty(USE_CUSTOMDIR_PROPERTY, "false"));
|
||||||
if (isCustomDir) {
|
if (isCustomDir) {
|
||||||
return Paths.get(System.getProperty("launcher.customdir"));
|
return Paths.get(System.getProperty(CUSTOMDIR_PROPERTY));
|
||||||
}
|
}
|
||||||
if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) {
|
if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) {
|
||||||
Boolean isOpt = Boolean.getBoolean(System.getProperty("launcher.useoptdir", "false"));
|
boolean isOpt = Boolean.getBoolean(System.getProperty(USE_OPTDIR_PROPERTY, "false"));
|
||||||
if (isOpt) {
|
if (isOpt) {
|
||||||
Path opt = Paths.get("/").resolve("opt");
|
Path opt = Paths.get("/").resolve("opt");
|
||||||
if (!IOHelper.isDir(opt)) Files.createDirectories(opt);
|
if (!IOHelper.isDir(opt)) Files.createDirectories(opt);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -155,6 +156,14 @@ public static String systemToJvmProperty(String name) {
|
||||||
return String.format("-D%s=%s", name, System.getProperties().getProperty(name));
|
return String.format("-D%s=%s", name, System.getProperties().getProperty(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@LauncherAPI
|
||||||
|
public static void addSystemPropertyToArgs(Collection<String> args, String name)
|
||||||
|
{
|
||||||
|
String property = System.getProperty(name);
|
||||||
|
if(property != null)
|
||||||
|
args.add(String.format("-D%s=%s", name, property));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void verifySystemProperties(Class<?> mainClass, boolean requireSystem) {
|
public static void verifySystemProperties(Class<?> mainClass, boolean requireSystem) {
|
||||||
Locale.setDefault(Locale.US);
|
Locale.setDefault(Locale.US);
|
||||||
|
|
Loading…
Reference in a new issue