diff --git a/Launcher/runtime/dialog/overlay/settings/settings.js b/Launcher/runtime/dialog/overlay/settings/settings.js index a3bf4da7..0817ebea 100644 --- a/Launcher/runtime/dialog/overlay/settings/settings.js +++ b/Launcher/runtime/dialog/overlay/settings/settings.js @@ -1,117 +1,4 @@ -var settings = { - file: DirBridge.dir.resolve("settings.bin"), // Settings file - login: null, rsaPassword: null, profile: 0, // Auth - updatesDir: null, autoEnter: false, fullScreen: false, ram: 0, // Client - - // Offline cache - offline: false, - lastSign: null, - lastProfiles: new java.util.LinkedList(), - lastHDirs: new java.util.HashMap(16), - - /* Settings and overlay functions */ - load: function() { - LogHelper.debug("Loading settings file"); - try { - tryWithResources(new HInput(IOHelper.newInput(settings.file)), settings.read); - } catch(e) { - LogHelper.error(e); - settings.setDefault(); - } - }, - - save: function() { - LogHelper.debug("Saving settings file"); - try { - tryWithResources(new HOutput(IOHelper.newOutput(settings.file)), settings.write); - } catch(e) { - LogHelper.error(e); - } - }, - - // Internal functions - read: function(input) { - var magic = input.readInt(); - if (magic != config.settingsMagic) { - throw new java.io.IOException("Settings magic mismatch: " + java.lang.Integer.toString(magic, 16)); - } - - // Launcher settings - var debug = input.readBoolean(); - if (!LogHelper.isDebugEnabled() && debug) { - LogHelper.setDebugEnabled(true); - } - - // Auth settings - settings.login = input.readBoolean() ? input.readString(255) : null; - settings.rsaPassword = input.readBoolean() ? input.readByteArray(IOHelper.BUFFER_SIZE) : null; - settings.profile = input.readLength(0); - - // Client settings - settings.updatesDir = IOHelper.toPath(input.readString(0)); - settings.autoEnter = input.readBoolean(); - settings.fullScreen = input.readBoolean(); - settings.setRAM(input.readLength(JVMHelper.RAM)); - - // Offline cache - var publicKey = Launcher.getConfig().publicKey; - settings.lastSign = input.readBoolean() ? input.readByteArray(-SecurityHelper.RSA_KEY_LENGTH) : null; - settings.lastProfiles.clear(); - var lastProfilesCount = input.readLength(0); - for (var i = 0; i < lastProfilesCount; i++) { - settings.lastProfiles.add(new SignedObjectHolder(input, publicKey, ClientProfile.RO_ADAPTER)); - } - settings.lastHDirs.clear(); - var lastHDirsCount = input.readLength(0); - for (var i = 0; i < lastHDirsCount; i++) { - var name = IOHelper.verifyFileName(input.readString(255)); - VerifyHelper.putIfAbsent(settings.lastHDirs, name, new SignedObjectHolder(input, publicKey, function(i) new HashedDir(i)), - java.lang.String.format("Duplicate offline hashed dir: '%s'", name)); - } - - // Apply CLI params - cliParams.applySettings(); - }, - - write: function(output) { - output.writeInt(config.settingsMagic); - - // Launcher settings - output.writeBoolean(LogHelper.isDebugEnabled()); - - // Auth settings - output.writeBoolean(settings.login !== null); - if (settings.login !== null) { - output.writeString(settings.login, 255); - } - output.writeBoolean(settings.rsaPassword !== null); - if (settings.rsaPassword !== null) { - output.writeByteArray(settings.rsaPassword, IOHelper.BUFFER_SIZE); - } - output.writeLength(settings.profile, 0); - - // Client settings - output.writeString(IOHelper.toString(settings.updatesDir), 0); - output.writeBoolean(settings.autoEnter); - output.writeBoolean(settings.fullScreen); - output.writeLength(settings.ram, JVMHelper.RAM); - - // Offline cache - output.writeBoolean(settings.lastSign !== null); - if (settings.lastSign !== null) { - output.writeByteArray(settings.lastSign, -SecurityHelper.RSA_KEY_LENGTH); - } - output.writeLength(settings.lastProfiles.size(), 0); - for each (var profile in settings.lastProfiles) { - profile.write(output); - } - output.writeLength(settings.lastHDirs.size(), 0); - for each (var entry in settings.lastHDirs.entrySet()) { - output.writeString(entry.getKey(), 0); - entry.getValue().write(output); - } - }, - +var settingsClass = Java.extend(LauncherSettingsClass.static, { setDefault: function() { // Auth settings settings.login = null; @@ -137,13 +24,12 @@ var settings = { var encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password)); settings.password = encrypted; return encrypted; - }, + } - setRAM: function(ram) { - settings.ram = java.lang.Math["min(int,int)"](((ram / 256) | 0) * 256, JVMHelper.RAM); - }, - /* ===================== OVERLAY ===================== */ +}); +var settingsOverlay = { +/* ===================== OVERLAY ===================== */ overlay: null, ramLabel: null, dirLabel: null, deleteDirPressedAgain: false, @@ -248,9 +134,8 @@ var settings = { settings.dirLabel.setText(IOHelper.toString(settings.updatesDir)); } }; - /* ====================== CLI PARAMS ===================== */ -var cliParams = { +var cliParamsClass = Java.extend(CliParamsInterface.static, { login: null, password: null, profile: -1, autoLogin: false, // Auth updatesDir: null, autoEnter: null, fullScreen: null, ram: -1, // Client offline: false, // Offline @@ -324,4 +209,7 @@ var cliParams = { settings.offline = cliParams.offline; } } -}; +}); +var cliParams = new cliParamsClass; +var settings = new settingsClass; +settings.cliParams = cliParams; \ No newline at end of file diff --git a/Launcher/runtime/engine/api.js b/Launcher/runtime/engine/api.js index 0cdbf766..f334a90c 100644 --- a/Launcher/runtime/engine/api.js +++ b/Launcher/runtime/engine/api.js @@ -67,6 +67,7 @@ var DigestAlgorithm = DigestAlgorithmClass.static; var VerifyHelper = VerifyHelperClass.static; var RingProgressIndicator = RingProgressIndicatorClass.static var RingProgressIndicatorSkin = RingProgressIndicatorSkinClass.static +var LauncherSettings = LauncherSettingsClass.static // Helper JS class API imports var JSApplication = null; diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 82cf25be..5a1003a3 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -134,6 +134,8 @@ public static void addLauncherClassBindings(Map bindings) { bindings.put("VerifyHelperClass", VerifyHelper.class); bindings.put("DirBridgeClass", DirBridge.class); bindings.put("FunctionalBridgeClass",FunctionalBridge.class); + bindings.put("LauncherSettingsClass",LauncherSettings.class); + bindings.put("CliParamsInterface",CliParamsInterface.class); // Load JS API if available bindings.put("RingProgressIndicatorClass", RingProgressIndicator.class); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/CliParamsInterface.java b/Launcher/src/main/java/ru/gravit/launcher/client/CliParamsInterface.java new file mode 100644 index 00000000..408b72f7 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/client/CliParamsInterface.java @@ -0,0 +1,10 @@ +package ru.gravit.launcher.client; + +import ru.gravit.launcher.LauncherAPI; + +public interface CliParamsInterface { + @LauncherAPI + void applySettings(); + @LauncherAPI + void init(javafx.application.Application.Parameters params); +} diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java index 2e256eed..752690a6 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java @@ -1,13 +1,12 @@ package ru.gravit.launcher.client; import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherConfig; +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.launcher.serialize.signed.SignedObjectHolder; -import ru.gravit.utils.event.EventManager; import ru.gravit.utils.helper.*; import java.io.IOException; @@ -20,18 +19,34 @@ public class LauncherSettings { public static int settingsMagic; - Path file = DirBridge.dir.resolve("settings.bin"); - String login; - byte[] rsaPassword; - int profile; - Path updatesDir; - boolean autoEnter; - boolean fullScreen; - int ram; + @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 CliParamsInterface cliParams; - byte[] lastSign; - LinkedList> lastProfiles; - HashMap> lastHDirs; + @LauncherAPI + public byte[] lastSign; + @LauncherAPI + public LinkedList> lastProfiles; + @LauncherAPI + public HashMap> lastHDirs; + @LauncherAPI public void load() { LogHelper.debug("Loading settings file"); @@ -45,6 +60,7 @@ public void load() setDefault(); } } + @LauncherAPI public void read(HInput input) throws IOException, SignatureException { int magic = input.readInt(); @@ -84,8 +100,9 @@ public void read(HInput input) throws IOException, SignatureException VerifyHelper.putIfAbsent(lastHDirs, name, new SignedObjectHolder<>(input, publicKey, HashedDir::new), java.lang.String.format("Duplicate offline hashed dir: '%s'", name)); } - //cliParams.applySettings(); + cliParams.applySettings(); } + @LauncherAPI public void write(HOutput output) throws IOException { output.writeInt(settingsMagic); @@ -115,19 +132,21 @@ public void write(HOutput output) throws IOException { output.writeByteArray(lastSign, -SecurityHelper.RSA_KEY_LENGTH); } output.writeLength(lastProfiles.size(), 0); - for(SignedObjectHolder profile : lastProfiles) { - profile.write(output); - } + for (SignedObjectHolder profile : lastProfiles) { + profile.write(output); + } output.writeLength(lastHDirs.size(), 0); - for(Map.Entry> entry : lastHDirs.entrySet()) { - output.writeString(entry.getKey(), 0); - entry.getValue().write(output); - } + for (Map.Entry> entry : lastHDirs.entrySet()) { + output.writeString(entry.getKey(), 0); + entry.getValue().write(output); + } } + @LauncherAPI public void setRAM(int ram) { ram = java.lang.Math.min(((ram / 256)) * 256, JVMHelper.RAM); } + @LauncherAPI public void setDefault() { // Auth settings @@ -149,6 +168,6 @@ public void setDefault() lastHDirs.clear(); // Apply CLI params - //cliParams.applySettings(); + cliParams.applySettings(); } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index d3507562..80ce866f 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -63,9 +63,9 @@ static int readBuildNumber() { private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); public static int MAJOR = 4; public static int MINOR = 0; - public static int PATCH = 3; + public static int PATCH = 4; public static int BUILD = readBuildNumber(); - public static Version.Type RELEASE = Version.Type.BETA; + public static Version.Type RELEASE = Version.Type.DEV; @LauncherAPI public static LauncherConfig getConfig() {