mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-01 22:14:01 +03:00
Merge branch 'master' into relauncher
This commit is contained in:
commit
dc3643089e
9 changed files with 84 additions and 73 deletions
|
@ -263,6 +263,7 @@ private SignConf(BlockConfigEntry block, Path coredir) {
|
|||
}
|
||||
|
||||
public static void main(String... args) throws Throwable {
|
||||
JVMHelper.checkStackTrace(LaunchServer.class);
|
||||
JVMHelper.verifySystemProperties(LaunchServer.class, true);
|
||||
LogHelper.addOutput(IOHelper.WORKING_DIR.resolve("LaunchServer.log"));
|
||||
LogHelper.printVersion("LaunchServer");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
String realMainClassName = "ru.gravit.launcher.LauncherEngine"
|
||||
|
||||
String realMainClassName = "ru.gravit.launcher.ClientLauncherWrapper"
|
||||
String mainAgentName = "ru.gravit.launcher.LauncherAgent"
|
||||
|
||||
String mainClassName = "ru.gravit.launcher.relauncher.VerRelauncher"
|
||||
|
|
|
@ -10,6 +10,9 @@ var LauncherApp = Java.extend(JSApplication, {
|
|||
}, start: function(primaryStage) {
|
||||
stage = primaryStage;
|
||||
stage.setTitle(config.title);
|
||||
|
||||
// Disable resizable button
|
||||
stage.setResizable(false);
|
||||
|
||||
// Set icons
|
||||
for each (var icon in config.icons) {
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package ru.gravit.launcher;
|
||||
|
||||
import ru.gravit.launcher.client.ClientLauncher;
|
||||
import ru.gravit.utils.helper.EnvHelper;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.JVMHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ClientLauncherWrapper {
|
||||
@LauncherAPI
|
||||
public static void main(String[] arguments) throws IOException, InterruptedException {
|
||||
LogHelper.printVersion("Launcher");
|
||||
JVMHelper.checkStackTrace(ClientLauncherWrapper.class);
|
||||
JVMHelper.verifySystemProperties(Launcher.class, true);
|
||||
EnvHelper.checkDangerousParametrs();
|
||||
LogHelper.debug("Restart Launcher");
|
||||
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||
processBuilder.inheritIO();
|
||||
Path javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
||||
List<String> args = new LinkedList<>();
|
||||
args.add(javaBin.toString());
|
||||
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
|
||||
Collections.addAll(args, "-javaagent:".concat(pathLauncher));
|
||||
Collections.addAll(args, LauncherEngine.class.getName());
|
||||
args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled())));
|
||||
EnvHelper.addEnv(processBuilder);
|
||||
processBuilder.command(args);
|
||||
Process process = processBuilder.start();
|
||||
if(!LogHelper.isDebugEnabled()) {
|
||||
Thread.sleep(3000);
|
||||
if (!process.isAlive()) {
|
||||
LogHelper.error("Process error code: %d", process.exitValue());
|
||||
} else {
|
||||
LogHelper.debug("Process started success");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
process.waitFor();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,10 +4,10 @@
|
|||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.script.Bindings;
|
||||
|
@ -148,8 +148,10 @@ public static void addLauncherClassBindings(Map<String, Object> bindings) {
|
|||
}
|
||||
|
||||
public static void main(String... args) throws Throwable {
|
||||
JVMHelper.checkStackTrace(LauncherEngine.class);
|
||||
JVMHelper.verifySystemProperties(Launcher.class, true);
|
||||
EnvHelper.checkDangerousParametrs();
|
||||
if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set");
|
||||
LogHelper.printVersion("Launcher");
|
||||
// Start Launcher
|
||||
Instant start = Instant.now();
|
||||
|
|
|
@ -416,6 +416,7 @@ public static void main(String... args) throws Throwable {
|
|||
checkJVMBitsAndVersion();
|
||||
JVMHelper.verifySystemProperties(ClientLauncher.class, true);
|
||||
EnvHelper.checkDangerousParametrs();
|
||||
JVMHelper.checkStackTrace(ClientLauncher.class);
|
||||
LogHelper.printVersion("Client Launcher");
|
||||
// Read and delete params file
|
||||
LogHelper.debug("Reading ClientLauncher params");
|
||||
|
|
|
@ -50,4 +50,8 @@ public static void premain(String agentArgument, Instrumentation instrumentation
|
|||
}
|
||||
}
|
||||
}
|
||||
public static boolean isStarted()
|
||||
{
|
||||
return isAgentStarted;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,68 +7,27 @@
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
public class EnvHelper {
|
||||
private static final boolean TST;
|
||||
private static final boolean HASXW;
|
||||
public static final String[] toTest;
|
||||
public static final Pattern[] test;
|
||||
|
||||
static {
|
||||
toTest = new String[] { "_JAVA_OPTIONS", "_JAVA_OPTS", "JAVA_OPTS", "JAVA_OPTIONS" };
|
||||
test = new Pattern[] { Pattern.compile("-xm.*\\d+[KMG]") };
|
||||
TST = check0();
|
||||
HASXW = check1();
|
||||
}
|
||||
|
||||
public static void addEnv(ProcessBuilder builder) {
|
||||
if (hasOptsEnv()) {
|
||||
Map<String, String> repl = new HashMap<>();
|
||||
for (String str : toTest) {
|
||||
repl.put(str, "");
|
||||
repl.put(str.toLowerCase(Locale.US), "");
|
||||
}
|
||||
JVMHelper.appendVars(builder, repl);
|
||||
Map<String, String> repl = builder.environment();
|
||||
for (String str : toTest) {
|
||||
repl.put(str, "");
|
||||
repl.put(str.toLowerCase(Locale.US), "");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean check0() {
|
||||
for (String test : toTest)
|
||||
if (System.getProperty(test) != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Вынужденное решение ибо тест на наличие -Xm* этакой нужен.
|
||||
*/
|
||||
private static boolean check1() {
|
||||
if (hasOptsEnv())
|
||||
for (String testStr : toTest)
|
||||
if (System.getenv(testStr) != null) {
|
||||
String str = System.getenv(testStr).toLowerCase(Locale.US);
|
||||
StringTokenizer st = new StringTokenizer(str);
|
||||
while (st.hasMoreTokens())
|
||||
if (CommonHelper.multiMatches(test, st.nextToken()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void checkDangerousParametrs() {
|
||||
if (hasOptsEnv())
|
||||
for (String t : toTest)
|
||||
if (System.getenv(t) != null) {
|
||||
String env = System.getenv(t).toLowerCase(Locale.US);
|
||||
if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent")
|
||||
|| env.contains("-agentpath") || env.contains("-agentlib"))
|
||||
throw new SecurityException("JavaAgent in global optings not allow");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasOptsEnv() {
|
||||
return TST;
|
||||
}
|
||||
|
||||
public static boolean hasWarnPreDef() {
|
||||
return HASXW;
|
||||
for (String t : toTest)
|
||||
if (System.getenv(t) != null) {
|
||||
String env = System.getenv(t).toLowerCase(Locale.US);
|
||||
if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent")
|
||||
|| env.contains("-agentpath") || env.contains("-agentlib"))
|
||||
throw new SecurityException("JavaAgent in global optings not allow");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,18 +71,6 @@ public static OS byName(String name) {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
||||
public static void addClassPath(URL url) {
|
||||
throw new IllegalArgumentException("Method Deprecated");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
||||
public static void addNativePath(Path path) {
|
||||
throw new IllegalArgumentException("Method Deprecated");
|
||||
}
|
||||
|
||||
|
||||
public static void appendVars(ProcessBuilder builder, Map<String, String> vars) {
|
||||
builder.environment().putAll(vars);
|
||||
|
@ -106,12 +94,6 @@ public static void fullGC() {
|
|||
LogHelper.debug("Used heap: %d MiB", RUNTIME.totalMemory() - RUNTIME.freeMemory() >> 20);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
||||
public static Certificate[] getCertificates(String resource) {
|
||||
throw new IllegalArgumentException("Method Deprecated");
|
||||
}
|
||||
|
||||
|
||||
public static String[] getClassPath() {
|
||||
return System.getProperty("java.class.path").split(File.pathSeparator);
|
||||
|
@ -134,6 +116,15 @@ public static URL[] getClassPathURL() {
|
|||
}
|
||||
return list;
|
||||
}
|
||||
public static void checkStackTrace(Class mainClass)
|
||||
{
|
||||
Exception e = new Exception("Testing stacktrace");
|
||||
StackTraceElement[] list = e.getStackTrace();
|
||||
if(!list[list.length - 1].getClassName().equals(mainClass.getName()))
|
||||
{
|
||||
throw new SecurityException(String.format("Invalid StackTraceElement: %s",list[list.length - 1].getClassName()));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("CallToSystemGetenv")
|
||||
private static int getCorrectOSArch() {
|
||||
|
|
Loading…
Reference in a new issue