diff --git a/Launcher/runtime/dialog/dialog.js b/Launcher/runtime/dialog/dialog.js index 47cf8eeb..b9b37cf1 100644 --- a/Launcher/runtime/dialog/dialog.js +++ b/Launcher/runtime/dialog/dialog.js @@ -20,7 +20,7 @@ function initDialog() { // Init overlays debug.initOverlay(); processing.initOverlay(); - settings.initOverlay(); + settingsOverlay.initOverlay(); update.initOverlay(); // Verify launcher & make request @@ -135,7 +135,7 @@ function goSettings(event) { } // Show settings overlay - overlay.show(settings.overlay, null); + overlay.show(settingsOverlay.overlay, null); } /* ======== Processing functions ======== */ diff --git a/Launcher/runtime/dialog/overlay/settings/settings.js b/Launcher/runtime/dialog/overlay/settings/settings.js index 0817ebea..1ea60f64 100644 --- a/Launcher/runtime/dialog/overlay/settings/settings.js +++ b/Launcher/runtime/dialog/overlay/settings/settings.js @@ -22,7 +22,7 @@ var settingsClass = Java.extend(LauncherSettingsClass.static, { setPassword: function(password) { var encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password)); - settings.password = encrypted; + //settings.password = encrypted; return encrypted; } @@ -34,26 +34,26 @@ var settingsOverlay = { deleteDirPressedAgain: false, initOverlay: function() { - settings.overlay = loadFXML("dialog/overlay/settings/settings.fxml"); + settingsOverlay.overlay = loadFXML("dialog/overlay/settings/settings.fxml"); // Lookup autoEnter checkbox - var autoEnterBox = settings.overlay.lookup("#autoEnter"); + var autoEnterBox = settingsOverlay.overlay.lookup("#autoEnter"); autoEnterBox.setSelected(settings.autoEnter); autoEnterBox.selectedProperty()["addListener(javafx.beans.value.ChangeListener)"]( function(o, ov, nv) settings.autoEnter = nv); // Lookup fullScreen checkbox - var fullScreenBox = settings.overlay.lookup("#fullScreen"); + var fullScreenBox = settingsOverlay.overlay.lookup("#fullScreen"); fullScreenBox.setSelected(settings.fullScreen); fullScreenBox.selectedProperty()["addListener(javafx.beans.value.ChangeListener)"]( function(o, ov, nv) settings.fullScreen = nv); // Lookup RAM label - settings.ramLabel = settings.overlay.lookup("#ramLabel"); - settings.updateRAMLabel(); + settingsOverlay.ramLabel = settingsOverlay.overlay.lookup("#ramLabel"); + settingsOverlay.updateRAMLabel(); // Lookup RAM slider options - var ramSlider = settings.overlay.lookup("#ramSlider"); + var ramSlider = settingsOverlay.overlay.lookup("#ramSlider"); ramSlider.setMin(0); ramSlider.setMax(JVMHelper.RAM); ramSlider.setSnapToTicks(true); @@ -65,17 +65,17 @@ var settingsOverlay = { ramSlider.setValue(settings.ram); ramSlider.valueProperty()["addListener(javafx.beans.value.ChangeListener)"](function(o, ov, nv) { settings.setRAM(nv); - settings.updateRAMLabel(); + settingsOverlay.updateRAMLabel(); }); // Lookup dir label - settings.dirLabel = settings.overlay.lookup("#dirLabel"); - settings.dirLabel.setOnAction(function(event) + settingsOverlay.dirLabel = settingsOverlay.overlay.lookup("#dirLabel"); + settingsOverlay.dirLabel.setOnAction(function(event) app.getHostServices().showDocument(settings.updatesDir.toUri())); - settings.updateDirLabel(); + settingsOverlay.updateDirLabel(); // Lookup change dir button - settings.overlay.lookup("#changeDir").setOnAction(function(event) { + settingsOverlay.overlay.lookup("#changeDir").setOnAction(function(event) { var chooser = new javafx.stage.DirectoryChooser(); chooser.setTitle("Сменить директорию загрузок"); chooser.setInitialDirectory(dir.toFile()); @@ -89,53 +89,54 @@ var settingsOverlay = { }); // Lookup delete dir button - var deleteDirButton = settings.overlay.lookup("#deleteDir"); + var deleteDirButton = settingsOverlay.overlay.lookup("#deleteDir"); deleteDirButton.setOnAction(function(event) { - if (!settings.deleteDirPressedAgain) { - settings.deleteDirPressedAgain = true; + if (!settingsOverlay.deleteDirPressedAgain) { + settingsOverlay.deleteDirPressedAgain = true; deleteDirButton.setText("Подтвердить вменяемость"); return; } // Delete dir! - settings.deleteUpdatesDir(); - settings.deleteDirPressedAgain = false; + settingsOverlay.deleteUpdatesDir(); + settingsOverlay.deleteDirPressedAgain = false; deleteDirButton.setText("Ещё раз попробовать"); }); // Lookup debug checkbox - var debugBox = settings.overlay.lookup("#debug"); + var debugBox = settingsOverlay.overlay.lookup("#debug"); debugBox.setSelected(LogHelper.isDebugEnabled()); debugBox.selectedProperty()["addListener(javafx.beans.value.ChangeListener)"]( function(o, ov, nv) LogHelper.setDebugEnabled(nv)); // Lookup apply settings button - settings.overlay.lookup("#apply").setOnAction(function(event) overlay.hide(0, null)); + settingsOverlay.overlay.lookup("#apply").setOnAction(function(event) overlay.hide(0, null)); }, updateRAMLabel: function() { - settings.ramLabel.setText(settings.ram <= 0 ? "Автоматически" : settings.ram + " MiB"); + settingsOverlay.ramLabel.setText(settings.ram <= 0 ? "Автоматически" : settings.ram + " MiB"); }, deleteUpdatesDir: function() { processing.description.setText("Удаление директории загрузок"); overlay.swap(0, processing.overlay, function(event) { var task = newTask(function() IOHelper.deleteDir(settings.updatesDir, false)); - task.setOnSucceeded(function(event) overlay.swap(0, settings.overlay, null)); + task.setOnSucceeded(function(event) overlay.swap(0, settingsOverlay.overlay, null)); task.setOnFailed(function(event) { processing.setError(task.getException()); - overlay.swap(2500, settings.overlay, null); + overlay.swap(2500, settingsOverlay.overlay, null); }); startTask(task); }); }, updateDirLabel: function() { - settings.dirLabel.setText(IOHelper.toString(settings.updatesDir)); + settingsOverlay.dirLabel.setText(IOHelper.toString(settings.updatesDir)); } }; +var settings = new settingsClass; /* ====================== CLI PARAMS ===================== */ -var cliParamsClass = Java.extend(CliParamsInterface.static, { +var cliParams = { login: null, password: null, profile: -1, autoLogin: false, // Auth updatesDir: null, autoEnter: null, fullScreen: null, ram: -1, // Client offline: false, // Offline @@ -192,7 +193,7 @@ var cliParamsClass = Java.extend(CliParamsInterface.static, { // Apply client params if (cliParams.updatesDir !== null) { - settings.updatesDir = cliParams.updatesDir; + //settings.updatesDir = cliParams.updatesDir; } if (cliParams.autoEnter !== null) { settings.autoLogin = cliParams.autoEnter; @@ -209,7 +210,4 @@ var cliParamsClass = Java.extend(CliParamsInterface.static, { settings.offline = cliParams.offline; } } -}); -var cliParams = new cliParamsClass; -var settings = new settingsClass; -settings.cliParams = cliParams; \ No newline at end of file +}; \ No newline at end of file diff --git a/Launcher/runtime/init.js b/Launcher/runtime/init.js index 0f7a6137..f27431e2 100644 --- a/Launcher/runtime/init.js +++ b/Launcher/runtime/init.js @@ -6,6 +6,7 @@ var LauncherApp = Java.extend(JSApplication, { app = JSApplication.getInstance(); cliParams.init(app.getParameters()); settings.load(); + cliParams.applySettings(); }, start: function(primaryStage) { stage = primaryStage; stage.setTitle(config.title); diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 5a1003a3..7b882b73 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -135,7 +135,6 @@ public static void addLauncherClassBindings(Map bindings) { 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 deleted file mode 100644 index 408b72f7..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/client/CliParamsInterface.java +++ /dev/null @@ -1,10 +0,0 @@ -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 752690a6..643c4b01 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java @@ -9,16 +9,19 @@ import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.utils.helper.*; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; import java.io.IOException; import java.nio.file.Path; import java.security.SignatureException; import java.security.interfaces.RSAPublicKey; import java.util.HashMap; import java.util.LinkedList; +import java.util.List; import java.util.Map; public class LauncherSettings { - public static int settingsMagic; + public static int settingsMagic = 0xc0de5; @LauncherAPI public Path file = DirBridge.dir.resolve("settings.bin"); @LauncherAPI @@ -37,23 +40,33 @@ public class LauncherSettings { public boolean offline; @LauncherAPI public int ram; - @LauncherAPI - public CliParamsInterface cliParams; @LauncherAPI public byte[] lastSign; @LauncherAPI - public LinkedList> lastProfiles; + public List> lastProfiles = new LinkedList<>(); @LauncherAPI - public HashMap> lastHDirs; + public Map> lastHDirs = new HashMap<>(16); @LauncherAPI - public void load() - { + 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() throws SignatureException { + LogHelper.debug("Save settings file"); + try { + try(HOutput output = new HOutput(IOHelper.newOutput(file))) + { + write(output); } } catch(IOException e) { LogHelper.error(e); @@ -100,7 +113,6 @@ 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(); } @LauncherAPI public void write(HOutput output) throws IOException { @@ -166,8 +178,10 @@ public void setDefault() lastSign = null; lastProfiles.clear(); lastHDirs.clear(); - - // Apply CLI params - cliParams.applySettings(); + } + @LauncherAPI + public byte[] setPassword(String password) throws BadPaddingException, IllegalBlockSizeException { + byte[] encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password)); + return encrypted; } }