From 4d6a456b8fafbbac8daeee0470db8dfe22aa23d0 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 21 Apr 2019 04:50:41 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20Runtime=20=D0=BC=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D1=82=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=B2=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D1=81=D0=B2=D0=BE=D0=B8=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D1=8B=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launcher/NewLauncherSettings.java | 7 +- .../launcher/client/FunctionalBridge.java | 5 + .../launcher/client/LauncherSettings.java | 193 ------------------ .../gravit/launcher/client/UserSettings.java | 7 + .../launcher/gui/JSRuntimeProvider.java | 6 +- .../launcher/managers/ClientGsonManager.java | 4 +- 6 files changed, 21 insertions(+), 201 deletions(-) delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java create mode 100644 Launcher/src/main/java/ru/gravit/launcher/client/UserSettings.java diff --git a/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java index 7fa38e55..fa5ccc40 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java @@ -1,12 +1,11 @@ package ru.gravit.launcher; +import ru.gravit.launcher.client.UserSettings; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.profiles.ClientProfile; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; +import java.util.*; public class NewLauncherSettings { @LauncherAPI @@ -32,6 +31,8 @@ public class NewLauncherSettings { public byte[] lastDigest; @LauncherAPI public List lastProfiles = new LinkedList<>(); + @LauncherAPI + public Map userSettings = new HashMap<>(); public static class HashedStoreEntry { @LauncherAPI diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index 903f61f5..ce940c99 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -79,6 +79,11 @@ public static long getJVMTotalMemory() { public static HasherStore getDefaultHasherStore() { return HasherManager.getDefaultStore(); } + @LauncherAPI + public static void registerUserSettings(String typename, Class clazz) + { + UserSettings.providers.registerProvider(typename, clazz); + } @LauncherAPI public static void setAuthParams(AuthRequestEvent event) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java deleted file mode 100644 index 4263ccdc..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java +++ /dev/null @@ -1,193 +0,0 @@ -package ru.gravit.launcher.client; - -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.hasher.HashedDir; -import ru.gravit.launcher.profiles.ClientProfile; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; - -import javax.crypto.BadPaddingException; -import javax.crypto.IllegalBlockSizeException; -import java.io.IOException; -import java.nio.file.Path; -import java.security.SignatureException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -public class LauncherSettings { - public static int settingsMagic = 0xc0dea; - @LauncherAPI - public Path file = DirBridge.dir.resolve("settings.bin"); - @LauncherAPI - public String login; - @LauncherAPI - public byte[] rsaPassword; - @LauncherAPI - public int profile; - @LauncherAPI - public Path updatesDir; - @LauncherAPI - public boolean autoEnter; - @LauncherAPI - public boolean fullScreen; - @LauncherAPI - public boolean offline; - @LauncherAPI - public int ram; - - @LauncherAPI - public byte[] lastDigest; - @LauncherAPI - public List lastProfiles = new LinkedList<>(); - @LauncherAPI - public Map lastHDirs = new HashMap<>(16); - - @LauncherAPI - public void load() throws SignatureException { - LogHelper.debug("Loading settings file"); - try { - try (HInput input = new HInput(IOHelper.newInput(file))) { - read(input); - } - } catch (IOException e) { - LogHelper.error(e); - setDefault(); - } - } - - @LauncherAPI - public void save() { - LogHelper.debug("Save settings file"); - try { - try (HOutput output = new HOutput(IOHelper.newOutput(file))) { - write(output); - } - } catch (IOException e) { - LogHelper.error(e); - setDefault(); - } - } - - @LauncherAPI - public void read(HInput input) throws IOException, SignatureException { - int magic = input.readInt(); - if (magic != settingsMagic) { - setDefault(); - LogHelper.warning("Settings magic mismatch: " + java.lang.Integer.toString(magic, 16)); - return; - //throw new java.io.IOException(); - } - - // Launcher settings - boolean debug = input.readBoolean(); - if (!LogHelper.isDebugEnabled() && debug) { - LogHelper.setDebugEnabled(true); - } - - // Auth settings - login = input.readBoolean() ? input.readString(255) : null; - rsaPassword = input.readBoolean() ? input.readByteArray(IOHelper.BUFFER_SIZE) : null; - profile = input.readLength(0); - - // Client settings - updatesDir = IOHelper.toPath(input.readString(0)); - DirBridge.dirUpdates = updatesDir; - autoEnter = input.readBoolean(); - fullScreen = input.readBoolean(); - setRAM(input.readLength(JVMHelper.RAM)); - - // Offline cache - lastDigest = input.readBoolean() ? input.readByteArray(0) : null; - lastProfiles.clear(); - int lastProfilesCount = input.readLength(0); - for (int i = 0; i < lastProfilesCount; i++) { - lastProfiles.add(Launcher.gsonManager.gson.fromJson(input.readString(0), ClientProfile.class)); - } - lastHDirs.clear(); - int lastHDirsCount = input.readLength(0); - for (int i = 0; i < lastHDirsCount; i++) { - String name = IOHelper.verifyFileName(input.readString(255)); - HashedDir hdir = new HashedDir(input); - lastHDirs.put(name, hdir); - } - } - - @LauncherAPI - public void write(HOutput output) throws IOException { - output.writeInt(settingsMagic); - - // Launcher settings - output.writeBoolean(LogHelper.isDebugEnabled()); - - // Auth settings - output.writeBoolean(login != null); - if (login != null) { - output.writeString(login, 255); - } - output.writeBoolean(rsaPassword != null); - if (rsaPassword != null) { - output.writeByteArray(rsaPassword, IOHelper.BUFFER_SIZE); - } - output.writeLength(profile, 0); - - // Client settings - output.writeString(IOHelper.toString(updatesDir), 0); - output.writeBoolean(autoEnter); - output.writeBoolean(fullScreen); - output.writeLength(ram, JVMHelper.RAM); - - // Offline cache - output.writeBoolean(lastDigest != null); - if (lastDigest != null) { - output.writeByteArray(lastDigest, 0); - } - output.writeLength(lastProfiles.size(), 0); - for (ClientProfile profile : lastProfiles) { - output.writeString(Launcher.gsonManager.gson.toJson(profile), 0); - } - output.writeLength(lastHDirs.size(), 0); - for (Map.Entry entry : lastHDirs.entrySet()) { - output.writeString(entry.getKey(), 0); - entry.getValue().write(output); - } - } - - @LauncherAPI - public void setRAM(int ram) { - this.ram = java.lang.Math.min(((ram / 256)) * 256, JVMHelper.RAM); - } - - @LauncherAPI - public void setDefault() { - // Auth settings - login = null; - rsaPassword = null; - profile = 0; - - // Client settings - //==DEFAULT== - updatesDir = DirBridge.defaultUpdatesDir; - autoEnter = false; - fullScreen = false; - setRAM(1024); - //========== - - // Offline cache - lastDigest = null; - lastProfiles.clear(); - lastHDirs.clear(); - } - - @LauncherAPI - public byte[] setPassword(String password) throws BadPaddingException, IllegalBlockSizeException { - byte[] encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password)); - return encrypted; - } -} diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/UserSettings.java b/Launcher/src/main/java/ru/gravit/launcher/client/UserSettings.java new file mode 100644 index 00000000..b04c66c4 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/client/UserSettings.java @@ -0,0 +1,7 @@ +package ru.gravit.launcher.client; + +import ru.gravit.utils.ProviderMap; + +public class UserSettings { + public static ProviderMap providers = new ProviderMap<>(); +} diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java index 9e8e9a31..1436d4ea 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java @@ -1,10 +1,7 @@ package ru.gravit.launcher.gui; import ru.gravit.launcher.*; -import ru.gravit.launcher.client.ClientLauncher; -import ru.gravit.launcher.client.DirBridge; -import ru.gravit.launcher.client.FunctionalBridge; -import ru.gravit.launcher.client.ServerPinger; +import ru.gravit.launcher.client.*; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedEntry; @@ -94,6 +91,7 @@ public static void addLauncherClassBindings(Map bindings) { bindings.put("SignedObjectHolderClass", SignedObjectHolder.class); bindings.put("EnumSerializerClass", EnumSerializer.class); bindings.put("OptionalFileClass", OptionalFile.class); + bindings.put("UserSettingsClass", UserSettings.class); // Set helper class bindings bindings.put("CommonHelperClass", CommonHelper.class); diff --git a/Launcher/src/main/java/ru/gravit/launcher/managers/ClientGsonManager.java b/Launcher/src/main/java/ru/gravit/launcher/managers/ClientGsonManager.java index cdd82078..1798d0fe 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/managers/ClientGsonManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/managers/ClientGsonManager.java @@ -1,11 +1,13 @@ package ru.gravit.launcher.managers; import com.google.gson.GsonBuilder; +import ru.gravit.launcher.client.UserSettings; +import ru.gravit.utils.UniversalJsonAdapter; public class ClientGsonManager extends GsonManager { @Override public void registerAdapters(GsonBuilder builder) { super.registerAdapters(builder); - + builder.registerTypeAdapter(UserSettings.class, new UniversalJsonAdapter<>(UserSettings.providers)); } }