mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FIX] Ошибка в паттернах ServerWrapper; баги получения RAM. (#232)
* [FIX] Убраны лишние классы из libLauncher. * [FIX] Получение RAM. * [FIX] Ещё фиксы такового с RAM. * [REFACTOR] Удалён лишний код. * [FEATURE] Теперь прикрутить sentry можно просто добавив библиотеку в libraries и дописав 3 строчки в runtime. * [FIX] Ошибка в паттернах ServerWrapper, порождает java.util.IllegalFormatConversionException
This commit is contained in:
parent
175df1796c
commit
c4cd9812e0
14 changed files with 27 additions and 252 deletions
|
@ -42,7 +42,7 @@ var settingsOverlay = {
|
|||
settingsOverlay.updateRAMLabel();
|
||||
|
||||
var ramSlider = holder.lookup("#ramSlider");
|
||||
ramSlider.setMax(JVMHelper.RAM);
|
||||
ramSlider.setMax(FunctionalBridge.getJVMTotalMemory());
|
||||
ramSlider.setSnapToTicks(true);
|
||||
ramSlider.setShowTickMarks(true);
|
||||
ramSlider.setShowTickLabels(true);
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import ru.gravit.utils.NativeJVMHalt;
|
||||
|
||||
import ru.gravit.launcher.utils.NativeJVMHalt;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import ru.gravit.launcher.managers.ClientGsonManager;
|
||||
import ru.gravit.launcher.managers.ConsoleManager;
|
||||
import ru.gravit.launcher.request.Request;
|
||||
import ru.gravit.launcher.request.websockets.ClientWebSocketService;
|
||||
import ru.gravit.launcher.request.websockets.StandartClientWebSocketService;
|
||||
import ru.gravit.utils.helper.CommonHelper;
|
||||
import ru.gravit.utils.helper.EnvHelper;
|
||||
|
@ -25,7 +24,7 @@ public static void main(String... args) throws Throwable {
|
|||
JVMHelper.checkStackTrace(LauncherEngine.class);
|
||||
JVMHelper.verifySystemProperties(Launcher.class, true);
|
||||
EnvHelper.checkDangerousParams();
|
||||
//if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set");
|
||||
if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set");
|
||||
LogHelper.printVersion("Launcher");
|
||||
LogHelper.printLicense("Launcher");
|
||||
// Start Launcher
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
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;
|
||||
import ru.gravit.launcher.hasher.HashedDir;
|
||||
import ru.gravit.launcher.hasher.HashedEntry;
|
||||
import ru.gravit.launcher.managers.ClientGsonManager;
|
||||
import ru.gravit.launcher.profiles.ClientProfile;
|
||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||
|
@ -15,12 +13,12 @@
|
|||
import ru.gravit.launcher.serialize.HInput;
|
||||
import ru.gravit.launcher.serialize.HOutput;
|
||||
import ru.gravit.launcher.serialize.stream.StreamObject;
|
||||
import ru.gravit.launcher.utils.DirWatcher;
|
||||
import ru.gravit.utils.PublicURLClassLoader;
|
||||
import ru.gravit.utils.helper.*;
|
||||
import ru.gravit.utils.helper.JVMHelper.OS;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
@ -36,10 +34,8 @@
|
|||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public final class ClientLauncher {
|
||||
|
||||
private static final class ClassPathFileVisitor extends SimpleFileVisitor<Path> {
|
||||
private final Collection<Path> result;
|
||||
|
||||
|
@ -331,7 +327,7 @@ public static Process launch(
|
|||
context.playerProfile = params.pp;
|
||||
context.args.add(javaBin.toString());
|
||||
context.args.add(MAGICAL_INTEL_OPTION);
|
||||
if (params.ram > 0 && params.ram <= JVMHelper.RAM) {
|
||||
if (params.ram > 0 && params.ram <= FunctionalBridge.getJVMTotalMemory()) {
|
||||
context.args.add("-Xms" + params.ram + 'M');
|
||||
context.args.add("-Xmx" + params.ram + 'M');
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
import ru.gravit.launcher.managers.HasherManager;
|
||||
import ru.gravit.launcher.managers.HasherStore;
|
||||
import ru.gravit.launcher.request.Request;
|
||||
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
|
@ -30,6 +29,8 @@ public class FunctionalBridge {
|
|||
public static AtomicReference<HWID> hwid = new AtomicReference<>();
|
||||
@LauncherAPI
|
||||
public static Thread getHWID = null;
|
||||
|
||||
private static long cachedMemorySize = -1;
|
||||
|
||||
@LauncherAPI
|
||||
public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder<HashedDir> hdir, FileNameMatcher matcher, boolean digest) {
|
||||
|
@ -42,11 +43,6 @@ public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, S
|
|||
};
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void makeJsonRequest(RequestInterface request, Runnable callback) {
|
||||
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void startTask(Runnable task) {
|
||||
threadPool.execute(task);
|
||||
|
@ -61,7 +57,8 @@ public static HWID getHWID() {
|
|||
|
||||
@LauncherAPI
|
||||
public static long getTotalMemory() {
|
||||
return hwidProvider.getTotalMemory() >> 20;
|
||||
if (cachedMemorySize > 0) return cachedMemorySize;
|
||||
return cachedMemorySize = hwidProvider.getTotalMemory() >> 20;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -106,6 +103,7 @@ public static void setAuthParams(AuthRequestEvent event) {
|
|||
public interface HashedDirRunnable {
|
||||
SignedObjectHolder<HashedDir> run() throws Exception;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void evalCommand(String cmd)
|
||||
{
|
||||
|
|
|
@ -83,7 +83,7 @@ public String getMacAddr() {
|
|||
}
|
||||
|
||||
public long getTotalMemory() {
|
||||
if (noHWID) return -1;
|
||||
if (noHWID) return 1024<<20;
|
||||
if (hardware == null) hardware = systemInfo.getHardware();
|
||||
return hardware.getMemory().getTotal();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package ru.gravit.launcher.hasher;
|
||||
package ru.gravit.launcher.utils;
|
||||
|
||||
import ru.gravit.launcher.LauncherAPI;
|
||||
import ru.gravit.launcher.hasher.FileNameMatcher;
|
||||
import ru.gravit.launcher.hasher.HashedDir;
|
||||
import ru.gravit.launcher.hasher.HashedEntry;
|
||||
import ru.gravit.launcher.hasher.HashedFile;
|
||||
import ru.gravit.launcher.hasher.HashedEntry.Type;
|
||||
import ru.gravit.utils.NativeJVMHalt;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.JVMHelper;
|
||||
import ru.gravit.utils.helper.JVMHelper.OS;
|
|
@ -1,4 +1,4 @@
|
|||
package ru.gravit.utils;
|
||||
package ru.gravit.launcher.utils;
|
||||
|
||||
import cpw.mods.fml.SafeExitJVMLegacy;
|
||||
import net.minecraftforge.fml.SafeExitJVM;
|
|
@ -1,4 +1,4 @@
|
|||
package ru.gravit.launcher.server;
|
||||
package ru.gravit.launcher.server;
|
||||
|
||||
import ru.gravit.launcher.ClientPermissions;
|
||||
import ru.gravit.launcher.Launcher;
|
||||
|
|
|
@ -1,213 +0,0 @@
|
|||
package ru.gravit.utils.downloader;
|
||||
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class Downloader implements Runnable {
|
||||
@FunctionalInterface
|
||||
public interface Handler {
|
||||
void check(Certificate[] certs) throws IOException;
|
||||
}
|
||||
|
||||
public static final Map<String, String> requestClient = Collections.singletonMap("User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
|
||||
public static final int INTERVAL = 300;
|
||||
|
||||
private final File file;
|
||||
private final URL url;
|
||||
private final String method;
|
||||
public final Map<String, String> requestProps;
|
||||
public AtomicInteger writed = new AtomicInteger(0);
|
||||
public final AtomicBoolean interrupt = new AtomicBoolean(false);
|
||||
public final AtomicBoolean interrupted = new AtomicBoolean(false);
|
||||
public AtomicReference<Throwable> ex = new AtomicReference<>(null);
|
||||
private final int skip;
|
||||
private final Handler handler;
|
||||
|
||||
private HttpURLConnection connect = null;
|
||||
|
||||
public Downloader(URL url, File file) {
|
||||
this.requestProps = new HashMap<>(requestClient);
|
||||
this.file = file;
|
||||
this.url = url;
|
||||
this.skip = 0;
|
||||
this.handler = null;
|
||||
this.method = null;
|
||||
}
|
||||
|
||||
public Downloader(URL url, File file, int skip) {
|
||||
this.requestProps = new HashMap<>(requestClient);
|
||||
this.file = file;
|
||||
this.url = url;
|
||||
this.skip = skip;
|
||||
this.handler = null;
|
||||
this.method = null;
|
||||
}
|
||||
|
||||
public Downloader(URL url, File file, Handler handler) {
|
||||
this.requestProps = new HashMap<>(requestClient);
|
||||
this.file = file;
|
||||
this.url = url;
|
||||
this.skip = 0;
|
||||
this.handler = handler;
|
||||
this.method = null;
|
||||
}
|
||||
|
||||
public Downloader(URL url, File file, int skip, Handler handler) {
|
||||
this.requestProps = new HashMap<>(requestClient);
|
||||
this.file = file;
|
||||
this.url = url;
|
||||
this.skip = skip;
|
||||
this.handler = handler;
|
||||
this.method = null;
|
||||
}
|
||||
|
||||
public Downloader(URL url, File file, int skip, Handler handler, Map<String, String> requestProps) {
|
||||
this.requestProps = new HashMap<>(requestProps);
|
||||
this.file = file;
|
||||
this.url = url;
|
||||
this.skip = skip;
|
||||
this.handler = handler;
|
||||
this.method = null;
|
||||
}
|
||||
|
||||
public Downloader(URL url, File file, int skip, Handler handler, Map<String, String> requestProps, String method) {
|
||||
this.requestProps = new HashMap<>(requestProps);
|
||||
this.file = file;
|
||||
this.url = url;
|
||||
this.skip = skip;
|
||||
this.handler = handler;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public Downloader(URL url, File file, int skip, Handler handler, String method) {
|
||||
this.requestProps = new HashMap<>(requestClient);
|
||||
this.file = file;
|
||||
this.url = url;
|
||||
this.skip = skip;
|
||||
this.handler = handler;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public Map<String, String> getProps() {
|
||||
return requestProps;
|
||||
}
|
||||
|
||||
public void addProp(String key, String value) {
|
||||
requestProps.put(key, value);
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public Handler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void downloadFile() throws IOException {
|
||||
if (!(url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https")))
|
||||
throw new IOException("Invalid protocol.");
|
||||
interrupted.set(false);
|
||||
if (url.getProtocol().equalsIgnoreCase("http")) {
|
||||
HttpURLConnection connect = (HttpURLConnection) (url).openConnection();
|
||||
this.connect = connect;
|
||||
if (method != null) connect.setRequestMethod(method);
|
||||
for (Map.Entry<String, String> ent : requestProps.entrySet()) {
|
||||
connect.setRequestProperty(ent.getKey(), ent.getValue());
|
||||
}
|
||||
connect.setInstanceFollowRedirects(true);
|
||||
if (!(connect.getResponseCode() >= 200 && connect.getResponseCode() < 300))
|
||||
throw new IOException(String.format("Invalid response of http server %d.", connect.getResponseCode()));
|
||||
try (BufferedInputStream in = new BufferedInputStream(connect.getInputStream(), IOHelper.BUFFER_SIZE);
|
||||
FileOutputStream fout = new FileOutputStream(file, skip != 0)) {
|
||||
byte data[] = new byte[IOHelper.BUFFER_SIZE];
|
||||
int count = -1;
|
||||
long timestamp = System.currentTimeMillis();
|
||||
int writed_local = 0;
|
||||
in.skip(skip);
|
||||
while ((count = in.read(data)) != -1) {
|
||||
fout.write(data, 0, count);
|
||||
writed_local += count;
|
||||
if (System.currentTimeMillis() - timestamp > INTERVAL) {
|
||||
writed.set(writed_local);
|
||||
LogHelper.debug("Downloaded %d", writed_local);
|
||||
if (interrupt.get()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
LogHelper.debug("Downloaded %d", writed_local);
|
||||
writed.set(writed_local);
|
||||
}
|
||||
} else {
|
||||
HttpsURLConnection connect = (HttpsURLConnection) (url).openConnection();
|
||||
this.connect = connect;
|
||||
if (method != null) connect.setRequestMethod(method);
|
||||
for (Map.Entry<String, String> ent : requestProps.entrySet()) {
|
||||
connect.setRequestProperty(ent.getKey(), ent.getValue());
|
||||
}
|
||||
connect.setInstanceFollowRedirects(true);
|
||||
if (handler != null)
|
||||
handler.check(connect.getServerCertificates());
|
||||
if (!(connect.getResponseCode() >= 200 && connect.getResponseCode() < 300))
|
||||
throw new IOException(String.format("Invalid response of http server %d.", connect.getResponseCode()));
|
||||
try (BufferedInputStream in = new BufferedInputStream(connect.getInputStream(), IOHelper.BUFFER_SIZE);
|
||||
FileOutputStream fout = new FileOutputStream(file, skip != 0)) {
|
||||
byte data[] = new byte[IOHelper.BUFFER_SIZE];
|
||||
int count = -1;
|
||||
long timestamp = System.currentTimeMillis();
|
||||
int writed_local = 0;
|
||||
in.skip(skip);
|
||||
while ((count = in.read(data)) != -1) {
|
||||
fout.write(data, 0, count);
|
||||
writed_local += count;
|
||||
if (System.currentTimeMillis() - timestamp > INTERVAL) {
|
||||
writed.set(writed_local);
|
||||
LogHelper.debug("Downloaded %d", writed_local);
|
||||
if (interrupt.get()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
LogHelper.debug("Downloaded %d", writed_local);
|
||||
writed.set(writed_local);
|
||||
}
|
||||
}
|
||||
interrupted.set(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
downloadFile();
|
||||
} catch (Throwable ex) {
|
||||
this.ex.set(ex);
|
||||
LogHelper.error(ex);
|
||||
}
|
||||
if (connect != null)
|
||||
try {
|
||||
connect.disconnect();
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,8 +7,6 @@
|
|||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
|
@ -52,8 +50,6 @@ public static OS byName(String name) {
|
|||
public static final int OS_BITS = getCorrectOSArch();
|
||||
@LauncherAPI
|
||||
public static final int JVM_BITS = Integer.parseInt(System.getProperty("sun.arch.data.model"));
|
||||
@LauncherAPI
|
||||
public static final int RAM = getRAMAmount();
|
||||
|
||||
@LauncherAPI
|
||||
public static final SecurityManager SECURITY_MANAGER = System.getSecurityManager();
|
||||
|
@ -137,19 +133,6 @@ public static String getEnvPropertyCaseSensitive(String name) {
|
|||
return System.getenv().get(name);
|
||||
}
|
||||
|
||||
private static int getRAMAmount() {
|
||||
int physicalRam = 1024;
|
||||
try {
|
||||
final Method getTotalPhysicalMemorySize = OPERATING_SYSTEM_MXBEAN.getClass().getDeclaredMethod("getTotalPhysicalMemorySize");
|
||||
getTotalPhysicalMemorySize.setAccessible(true);
|
||||
physicalRam = (int) ((long)getTotalPhysicalMemorySize.invoke(OPERATING_SYSTEM_MXBEAN) >> 20);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
|
||||
| SecurityException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
return Math.min(physicalRam, OS_BITS == 32 ? 1536 : 32768); // Limit 32-bit OS to 1536 MiB, and 64-bit OS to 32768 MiB (because it's enough)
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static boolean isJVMMatchesSystemArch() {
|
||||
return JVM_BITS == OS_BITS;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class LogHelper {
|
||||
|
@ -50,6 +51,7 @@ public enum OutputTypes {
|
|||
}
|
||||
|
||||
private static final Set<OutputEnity> OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
|
||||
private static final Set<Consumer<Throwable>> EXCEPTIONS_CALLBACKS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
|
||||
private static final OutputEnity STD_OUTPUT;
|
||||
|
||||
private LogHelper() {
|
||||
|
@ -60,6 +62,11 @@ public static void addOutput(OutputEnity output) {
|
|||
OUTPUTS.add(Objects.requireNonNull(output, "output"));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void addExcCallback(Consumer<Throwable> output) {
|
||||
EXCEPTIONS_CALLBACKS.add(Objects.requireNonNull(output, "output"));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void addOutput(Output output, OutputTypes type) {
|
||||
OUTPUTS.add(new OutputEnity(Objects.requireNonNull(output, "output"), type));
|
||||
|
@ -105,6 +112,7 @@ public static void dev(String format, Object... args) {
|
|||
|
||||
@LauncherAPI
|
||||
public static void error(Throwable exc) {
|
||||
EXCEPTIONS_CALLBACKS.forEach(e -> e.accept(exc));
|
||||
error(isStacktraceEnabled() ? toString(exc) : exc.toString());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue