mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
[FEATURE] Удаление лишнего кода
This commit is contained in:
parent
94c19c9c56
commit
fd54f4739f
5 changed files with 11 additions and 148 deletions
|
@ -166,8 +166,6 @@ public void start(String... args) throws Throwable {
|
||||||
LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this));
|
LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this));
|
||||||
runtimeProvider.preLoad();
|
runtimeProvider.preLoad();
|
||||||
LauncherGuardManager.initGuard(false);
|
LauncherGuardManager.initGuard(false);
|
||||||
FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID);
|
|
||||||
FunctionalBridge.getHWID.start();
|
|
||||||
LogHelper.debug("Dir: %s", DirBridge.dir);
|
LogHelper.debug("Dir: %s", DirBridge.dir);
|
||||||
runtimeProvider.run(args);
|
runtimeProvider.run(args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
import pro.gravit.launcher.hasher.FileNameMatcher;
|
import pro.gravit.launcher.hasher.FileNameMatcher;
|
||||||
import pro.gravit.launcher.hasher.HashedDir;
|
import pro.gravit.launcher.hasher.HashedDir;
|
||||||
import pro.gravit.launcher.hwid.HWIDProvider;
|
import pro.gravit.launcher.hwid.HWIDProvider;
|
||||||
|
import pro.gravit.launcher.hwid.OshiHWIDProvider;
|
||||||
import pro.gravit.launcher.managers.ClientGsonManager;
|
import pro.gravit.launcher.managers.ClientGsonManager;
|
||||||
import pro.gravit.launcher.managers.ClientHookManager;
|
import pro.gravit.launcher.managers.ClientHookManager;
|
||||||
import pro.gravit.launcher.modules.events.PreConfigPhase;
|
import pro.gravit.launcher.modules.events.PreConfigPhase;
|
||||||
|
@ -48,6 +49,12 @@
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public final class ClientLauncher {
|
public final class ClientLauncher {
|
||||||
|
|
||||||
|
@LauncherAPI
|
||||||
|
public static int getClientJVMBits() {
|
||||||
|
return LauncherGuardManager.guard.getClientJVMBits();
|
||||||
|
}
|
||||||
|
|
||||||
private static final class ClassPathFileVisitor extends SimpleFileVisitor<Path> {
|
private static final class ClassPathFileVisitor extends SimpleFileVisitor<Path> {
|
||||||
private final Stream.Builder<Path> result;
|
private final Stream.Builder<Path> result;
|
||||||
|
|
||||||
|
@ -327,7 +334,7 @@ public static Process launch(
|
||||||
context.playerProfile = params.pp;
|
context.playerProfile = params.pp;
|
||||||
context.args.add(javaBin.toString());
|
context.args.add(javaBin.toString());
|
||||||
context.args.add(MAGICAL_INTEL_OPTION);
|
context.args.add(MAGICAL_INTEL_OPTION);
|
||||||
if (params.ram > 0 && params.ram <= FunctionalBridge.getJVMTotalMemory()) {
|
if (params.ram > 0) {
|
||||||
context.args.add("-Xms" + params.ram + 'M');
|
context.args.add("-Xms" + params.ram + 'M');
|
||||||
context.args.add("-Xmx" + params.ram + 'M');
|
context.args.add("-Xmx" + params.ram + 'M');
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ public ClientLauncherContext build() throws IOException {
|
||||||
context.args.add(MAGICAL_INTEL_OPTION);
|
context.args.add(MAGICAL_INTEL_OPTION);
|
||||||
context.params = params;
|
context.params = params;
|
||||||
if(paramsWriter != null) paramsWriter.write(context);
|
if(paramsWriter != null) paramsWriter.write(context);
|
||||||
if (params.ram > 0 && params.ram <= FunctionalBridge.getJVMTotalMemory()) {
|
if (params.ram > 0) {
|
||||||
context.args.add("-Xms" + params.ram + 'M');
|
context.args.add("-Xms" + params.ram + 'M');
|
||||||
context.args.add("-Xmx" + params.ram + 'M');
|
context.args.add("-Xmx" + params.ram + 'M');
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,8 @@ public static void setUseLegacyDir(boolean b) {
|
||||||
try {
|
try {
|
||||||
DirBridge.dir = getLauncherDir(projectName);
|
DirBridge.dir = getLauncherDir(projectName);
|
||||||
if (!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir);
|
if (!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir);
|
||||||
|
DirBridge.defaultUpdatesDir = DirBridge.dir.resolve("updates");
|
||||||
|
if (!IOHelper.exists(DirBridge.defaultUpdatesDir)) Files.createDirectories(DirBridge.defaultUpdatesDir);
|
||||||
DirBridge.dirStore = getStoreDir(projectName);
|
DirBridge.dirStore = getStoreDir(projectName);
|
||||||
if (!IOHelper.exists(DirBridge.dirStore)) Files.createDirectories(DirBridge.dirStore);
|
if (!IOHelper.exists(DirBridge.dirStore)) Files.createDirectories(DirBridge.dirStore);
|
||||||
DirBridge.dirProjectStore = getProjectStoreDir(projectName);
|
DirBridge.dirProjectStore = getProjectStoreDir(projectName);
|
||||||
|
|
|
@ -1,144 +0,0 @@
|
||||||
package pro.gravit.launcher.client;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
|
||||||
import pro.gravit.launcher.LauncherAPI;
|
|
||||||
import pro.gravit.launcher.api.AuthService;
|
|
||||||
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
|
||||||
import pro.gravit.launcher.guard.LauncherGuardManager;
|
|
||||||
import pro.gravit.launcher.hasher.FileNameMatcher;
|
|
||||||
import pro.gravit.launcher.hasher.HashedDir;
|
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
|
||||||
import pro.gravit.launcher.hwid.OshiHWIDProvider;
|
|
||||||
import pro.gravit.launcher.managers.ConsoleManager;
|
|
||||||
import pro.gravit.launcher.managers.HasherManager;
|
|
||||||
import pro.gravit.launcher.managers.HasherStore;
|
|
||||||
import pro.gravit.launcher.request.Request;
|
|
||||||
import pro.gravit.utils.Version;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
public class FunctionalBridge {
|
|
||||||
@LauncherAPI
|
|
||||||
public static final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0);
|
|
||||||
@LauncherAPI
|
|
||||||
public static OshiHWIDProvider hwidProvider;
|
|
||||||
@LauncherAPI
|
|
||||||
public static final 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, HashedDir hdir, FileNameMatcher matcher, boolean digest) {
|
|
||||||
return () -> {
|
|
||||||
if (hdir == null) {
|
|
||||||
Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName));
|
|
||||||
}
|
|
||||||
ClientLauncher.verifyHDir(dir, hdir, matcher, digest);
|
|
||||||
return hdir;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static void startTask(Runnable task) {
|
|
||||||
threadPool.execute(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static HWID getHWID() {
|
|
||||||
HWID hhwid = hwid.get();
|
|
||||||
if (hhwid == null) {
|
|
||||||
if (hwidProvider == null) hwidProvider = new OshiHWIDProvider();
|
|
||||||
hwid.set(hwidProvider.getHWID());
|
|
||||||
}
|
|
||||||
return hhwid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static long getTotalMemory() {
|
|
||||||
if (cachedMemorySize > 0) return cachedMemorySize;
|
|
||||||
if (hwidProvider == null) hwidProvider = new OshiHWIDProvider();
|
|
||||||
return (cachedMemorySize = hwidProvider.getTotalMemory() >> 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static int getClientJVMBits() {
|
|
||||||
return LauncherGuardManager.guard.getClientJVMBits();
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static long getJVMTotalMemory() {
|
|
||||||
if (getClientJVMBits() == 32) {
|
|
||||||
return Math.min(getTotalMemory(), 1536);
|
|
||||||
} else {
|
|
||||||
return getTotalMemory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static HasherStore getDefaultHasherStore() {
|
|
||||||
return HasherManager.getDefaultStore();
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static void registerUserSettings(String typename, Class<? extends UserSettings> clazz) {
|
|
||||||
UserSettings.providers.register(typename, clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static void close() throws Exception {
|
|
||||||
threadPool.awaitTermination(2, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static void setAuthParams(AuthRequestEvent event) {
|
|
||||||
if (event.session != 0) {
|
|
||||||
Request.setSession(event.session);
|
|
||||||
}
|
|
||||||
LauncherGuardManager.guard.setProtectToken(event.protectToken);
|
|
||||||
AuthService.permissions = event.permissions;
|
|
||||||
if (event.playerProfile != null) {
|
|
||||||
AuthService.username = event.playerProfile.username;
|
|
||||||
AuthService.uuid = event.playerProfile.uuid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface HashedDirRunnable {
|
|
||||||
HashedDir run() throws Exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static void evalCommand(String cmd) {
|
|
||||||
ConsoleManager.handler.eval(cmd, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static void addPlainOutput(LogHelper.Output output) {
|
|
||||||
LogHelper.addOutput(output, LogHelper.OutputTypes.PLAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static String getLauncherVersion() {
|
|
||||||
return String.format("GravitLauncher v%d.%d.%d build %d",
|
|
||||||
Version.MAJOR,
|
|
||||||
Version.MINOR,
|
|
||||||
Version.PATCH,
|
|
||||||
Version.BUILD
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@LauncherAPI
|
|
||||||
public static byte[] encryptPassword(String string) throws Exception {
|
|
||||||
byte[] encode = IOHelper.encode(string);
|
|
||||||
return SecurityHelper.encrypt(Launcher.getConfig().passwordEncryptKey, encode);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue