mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Экспериментальная фитча - натсройки в json
This commit is contained in:
parent
0283110a92
commit
ae0e178d43
8 changed files with 144 additions and 54 deletions
|
@ -180,7 +180,7 @@ function goAuth(event) {
|
||||||
if (!passwordField.isDisable()) {
|
if (!passwordField.isDisable()) {
|
||||||
var password = passwordField.getText();
|
var password = passwordField.getText();
|
||||||
if (password !== null && !password.isEmpty()) {
|
if (password !== null && !password.isEmpty()) {
|
||||||
rsaPassword = settings.setPassword(password);
|
rsaPassword = settingsOverlay.setPassword(password);
|
||||||
} else if (settings.rsaPassword !== null) {
|
} else if (settings.rsaPassword !== null) {
|
||||||
rsaPassword = settings.rsaPassword;
|
rsaPassword = settings.rsaPassword;
|
||||||
} else {
|
} else {
|
||||||
|
@ -443,6 +443,7 @@ var serverHolder = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ======== Scenes scripts ======== */
|
/* ======== Scenes scripts ======== */
|
||||||
|
launcher.loadScript("api/settings.js");
|
||||||
launcher.loadScript("dialog/overlay/debug/debug.js");
|
launcher.loadScript("dialog/overlay/debug/debug.js");
|
||||||
launcher.loadScript("dialog/overlay/processing/processing.js");
|
launcher.loadScript("dialog/overlay/processing/processing.js");
|
||||||
launcher.loadScript("dialog/overlay/settings/settings.js");
|
launcher.loadScript("dialog/overlay/settings/settings.js");
|
||||||
|
|
|
@ -1,35 +1,3 @@
|
||||||
var settingsClass = Java.extend(LauncherSettingsClass.static, {
|
|
||||||
setDefault: function() {
|
|
||||||
settings.login = null;
|
|
||||||
settings.rsaPassword = null;
|
|
||||||
settings.profile = 0;
|
|
||||||
|
|
||||||
settings.updatesDir = DirBridge.defaultUpdatesDir;
|
|
||||||
settings.autoEnter = config.autoEnterDefault;
|
|
||||||
settings.fullScreen = config.fullScreenDefault;
|
|
||||||
settings.setRAM(config.ramDefault);
|
|
||||||
|
|
||||||
settings.lastDigest = null;
|
|
||||||
settings.lastProfiles.clear();
|
|
||||||
settings.lastHDirs.clear();
|
|
||||||
|
|
||||||
cliParams.applySettings();
|
|
||||||
},
|
|
||||||
|
|
||||||
setPassword: function(password) {
|
|
||||||
var encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password));
|
|
||||||
return encrypted;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
setRAM: function(ram) {
|
|
||||||
if (ram>762&&ram<1024){
|
|
||||||
settings.ram = java.lang.Math["min(int,int)"](ram, FunctionalBridge.getJVMTotalMemory());
|
|
||||||
}else{
|
|
||||||
settings.ram = java.lang.Math["min(int,int)"](((ram / 256) | 0) * 256, FunctionalBridge.getJVMTotalMemory());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
var settingsOverlay = {
|
var settingsOverlay = {
|
||||||
/* ===================== OVERLAY ===================== */
|
/* ===================== OVERLAY ===================== */
|
||||||
overlay: null, ramLabel: null, dirLabel: null, transferDialog: null,
|
overlay: null, ramLabel: null, dirLabel: null, transferDialog: null,
|
||||||
|
@ -83,7 +51,7 @@ var settingsOverlay = {
|
||||||
ramSlider.setBlockIncrement(1024);
|
ramSlider.setBlockIncrement(1024);
|
||||||
ramSlider.setValue(settings.ram);
|
ramSlider.setValue(settings.ram);
|
||||||
ramSlider.valueProperty()["addListener(javafx.beans.value.ChangeListener)"](function(o, ov, nv) {
|
ramSlider.valueProperty()["addListener(javafx.beans.value.ChangeListener)"](function(o, ov, nv) {
|
||||||
settings.setRAM(nv);
|
settingsOverlay.setRAM(nv);
|
||||||
settingsOverlay.updateRAMLabel();
|
settingsOverlay.updateRAMLabel();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -153,12 +121,25 @@ var settingsOverlay = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setPassword: function(password) {
|
||||||
|
var encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password));
|
||||||
|
return encrypted;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
setRAM: function(ram) {
|
||||||
|
if (ram>762&&ram<1024){
|
||||||
|
settings.ram = java.lang.Math["min(int,int)"](ram, FunctionalBridge.getJVMTotalMemory());
|
||||||
|
}else{
|
||||||
|
settings.ram = java.lang.Math["min(int,int)"](((ram / 256) | 0) * 256, FunctionalBridge.getJVMTotalMemory());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
updateDirLabel: function() {
|
updateDirLabel: function() {
|
||||||
settingsOverlay.dirLabel.setText(IOHelper.toString(settings.updatesDir));
|
settingsOverlay.dirLabel.setText(IOHelper.toString(settings.updatesDir));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
LogHelper.debug("Dir: %s", DirBridge.dir);
|
LogHelper.debug("Dir: %s", DirBridge.dir);
|
||||||
var settings = new settingsClass;
|
|
||||||
|
|
||||||
/* ====================== CLI PARAMS ===================== */
|
/* ====================== CLI PARAMS ===================== */
|
||||||
var cliParams = {
|
var cliParams = {
|
||||||
|
@ -206,7 +187,7 @@ var cliParams = {
|
||||||
settings.login = cliParams.login;
|
settings.login = cliParams.login;
|
||||||
}
|
}
|
||||||
if (cliParams.password !== null) {
|
if (cliParams.password !== null) {
|
||||||
settings.setPassword(cliParams.password);
|
settingsOverlay.setPassword(cliParams.password);
|
||||||
}
|
}
|
||||||
if (cliParams.profile >= 0) {
|
if (cliParams.profile >= 0) {
|
||||||
settings.profile = cliParams.profile;
|
settings.profile = cliParams.profile;
|
||||||
|
@ -221,7 +202,7 @@ var cliParams = {
|
||||||
settings.fullScreen = cliParams.fullScreen;
|
settings.fullScreen = cliParams.fullScreen;
|
||||||
}
|
}
|
||||||
if (cliParams.ram >= 0) {
|
if (cliParams.ram >= 0) {
|
||||||
settings.setRAM(cliParams.ram);
|
settingsOverlay.setRAM(cliParams.ram);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cliParams.offline !== null) {
|
if (cliParams.offline !== null) {
|
||||||
|
|
|
@ -56,6 +56,8 @@ var SecurityHelper = SecurityHelperClass.static;
|
||||||
var DigestAlgorithm = DigestAlgorithmClass.static;
|
var DigestAlgorithm = DigestAlgorithmClass.static;
|
||||||
var VerifyHelper = VerifyHelperClass.static;
|
var VerifyHelper = VerifyHelperClass.static;
|
||||||
var LauncherSettings = LauncherSettingsClass.static;
|
var LauncherSettings = LauncherSettingsClass.static;
|
||||||
|
var NewLauncherSettings = NewLauncherSettingsClass.static;
|
||||||
|
var SettingsManager = SettingsManagerClass.static;
|
||||||
|
|
||||||
// Helper JS class API imports
|
// Helper JS class API imports
|
||||||
var JSApplication = null;
|
var JSApplication = null;
|
||||||
|
@ -86,4 +88,4 @@ function startTask(task) {
|
||||||
|
|
||||||
function openURL(url) {
|
function openURL(url) {
|
||||||
app.getHostServices().showDocument(url.toURI());
|
app.getHostServices().showDocument(url.toURI());
|
||||||
}
|
}
|
21
Launcher/runtime/engine/settings.js
Normal file
21
Launcher/runtime/engine/settings.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
var settingsManagerClass = Java.extend(SettingsManagerClass.static, {
|
||||||
|
getDefaultConfig: function() {
|
||||||
|
var new_settings = new NewLauncherSettings;
|
||||||
|
new_settings.login = null;
|
||||||
|
new_settings.rsaPassword = null;
|
||||||
|
new_settings.profile = 0;
|
||||||
|
|
||||||
|
new_settings.updatesDir = DirBridge.defaultUpdatesDir;
|
||||||
|
new_settings.autoEnter = config.autoEnterDefault;
|
||||||
|
new_settings.fullScreen = config.fullScreenDefault;
|
||||||
|
new_settings.ram = config.ramDefault;
|
||||||
|
|
||||||
|
new_settings.lastDigest = null;
|
||||||
|
new_settings.lastProfiles.clear();
|
||||||
|
new_settings.lastHDirs.clear();
|
||||||
|
return new_settings;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
var settingsManager = new settingsManager;
|
||||||
|
var settings = SettingsManager.settings;
|
|
@ -0,0 +1,38 @@
|
||||||
|
package ru.gravit.launcher;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.hasher.HashedDir;
|
||||||
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class NewLauncherSettings {
|
||||||
|
@LauncherAPI
|
||||||
|
public String login;
|
||||||
|
@LauncherAPI
|
||||||
|
public byte[] rsaPassword;
|
||||||
|
@LauncherAPI
|
||||||
|
public int profile;
|
||||||
|
@LauncherAPI
|
||||||
|
public transient Path updatesDir;
|
||||||
|
@LauncherAPI
|
||||||
|
public String updatesDirPath;
|
||||||
|
@LauncherAPI
|
||||||
|
public boolean autoEnter;
|
||||||
|
@LauncherAPI
|
||||||
|
public boolean fullScreen;
|
||||||
|
@LauncherAPI
|
||||||
|
public boolean offline;
|
||||||
|
@LauncherAPI
|
||||||
|
public int ram;
|
||||||
|
|
||||||
|
@LauncherAPI
|
||||||
|
public byte[] lastDigest;
|
||||||
|
@LauncherAPI
|
||||||
|
public List<ClientProfile> lastProfiles = new LinkedList<>();
|
||||||
|
@LauncherAPI
|
||||||
|
public Map<String, HashedDir> lastHDirs = new HashMap<>(16);
|
||||||
|
}
|
|
@ -1,14 +1,12 @@
|
||||||
package ru.gravit.launcher.gui;
|
package ru.gravit.launcher.gui;
|
||||||
|
|
||||||
import ru.gravit.launcher.JSApplication;
|
import ru.gravit.launcher.*;
|
||||||
import ru.gravit.launcher.Launcher;
|
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
|
||||||
import ru.gravit.launcher.client.*;
|
import ru.gravit.launcher.client.*;
|
||||||
import ru.gravit.launcher.hasher.FileNameMatcher;
|
import ru.gravit.launcher.hasher.FileNameMatcher;
|
||||||
import ru.gravit.launcher.hasher.HashedDir;
|
import ru.gravit.launcher.hasher.HashedDir;
|
||||||
import ru.gravit.launcher.hasher.HashedEntry;
|
import ru.gravit.launcher.hasher.HashedEntry;
|
||||||
import ru.gravit.launcher.hasher.HashedFile;
|
import ru.gravit.launcher.hasher.HashedFile;
|
||||||
|
import ru.gravit.launcher.managers.SettingsManager;
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launcher.profiles.Texture;
|
import ru.gravit.launcher.profiles.Texture;
|
||||||
|
@ -52,6 +50,8 @@ public static void addLauncherClassBindings(Map<String, Object> bindings) {
|
||||||
bindings.put("LauncherClass", Launcher.class);
|
bindings.put("LauncherClass", Launcher.class);
|
||||||
bindings.put("LauncherConfigClass", LauncherConfig.class);
|
bindings.put("LauncherConfigClass", LauncherConfig.class);
|
||||||
bindings.put("HTTPRequestClass", HTTPRequest.class);
|
bindings.put("HTTPRequestClass", HTTPRequest.class);
|
||||||
|
bindings.put("SettingsManagerClass", SettingsManager.class);
|
||||||
|
bindings.put("NewLauncherSettingsClass", NewLauncherSettings.class);
|
||||||
|
|
||||||
// Set client class bindings
|
// Set client class bindings
|
||||||
bindings.put("PlayerProfileClass", PlayerProfile.class);
|
bindings.put("PlayerProfileClass", PlayerProfile.class);
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package ru.gravit.launcher.managers;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
|
import ru.gravit.launcher.NewLauncherSettings;
|
||||||
|
import ru.gravit.launcher.client.DirBridge;
|
||||||
|
import ru.gravit.utils.config.JsonConfigurable;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
public class SettingsManager extends JsonConfigurable<NewLauncherSettings> {
|
||||||
|
@LauncherAPI
|
||||||
|
public static NewLauncherSettings settings;
|
||||||
|
|
||||||
|
public SettingsManager() {
|
||||||
|
super(NewLauncherSettings.class, DirBridge.dir.resolve("settings.json"));
|
||||||
|
}
|
||||||
|
@LauncherAPI
|
||||||
|
@Override
|
||||||
|
public NewLauncherSettings getConfig() {
|
||||||
|
settings.updatesDirPath = settings.updatesDir.toString();
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
@LauncherAPI
|
||||||
|
@Override
|
||||||
|
public NewLauncherSettings getDefaultConfig() {
|
||||||
|
return new NewLauncherSettings();
|
||||||
|
}
|
||||||
|
@LauncherAPI
|
||||||
|
@Override
|
||||||
|
public void setConfig(NewLauncherSettings config) {
|
||||||
|
settings = config;
|
||||||
|
settings.updatesDir = Paths.get(settings.updatesDirPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setType(Type type) {
|
||||||
|
super.setType(type);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
package ru.gravit.utils.config;
|
package ru.gravit.utils.config;
|
||||||
|
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
|
import ru.gravit.utils.Version;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -12,60 +14,64 @@
|
||||||
public abstract class JsonConfigurable<T> {
|
public abstract class JsonConfigurable<T> {
|
||||||
private Type type;
|
private Type type;
|
||||||
protected Path configPath;
|
protected Path configPath;
|
||||||
|
@LauncherAPI
|
||||||
public void saveConfig() throws IOException {
|
public void saveConfig() throws IOException {
|
||||||
saveConfig(configPath);
|
saveConfig(configPath);
|
||||||
}
|
}
|
||||||
|
@LauncherAPI
|
||||||
public void loadConfig() throws IOException {
|
public void loadConfig() throws IOException {
|
||||||
loadConfig(configPath);
|
loadConfig(configPath);
|
||||||
}
|
}
|
||||||
|
@LauncherAPI
|
||||||
public JsonConfigurable(Type type, Path configPath) {
|
public JsonConfigurable(Type type, Path configPath) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.configPath = configPath;
|
this.configPath = configPath;
|
||||||
}
|
}
|
||||||
|
@LauncherAPI
|
||||||
public void saveConfig(Path configPath) throws IOException {
|
public void saveConfig(Path configPath) throws IOException {
|
||||||
try (BufferedWriter writer = IOHelper.newWriter(configPath)) {
|
try (BufferedWriter writer = IOHelper.newWriter(configPath)) {
|
||||||
Launcher.gson.toJson(getConfig(), type, writer);
|
Launcher.gson.toJson(getConfig(), type, writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@LauncherAPI
|
||||||
public void loadConfig(Path configPath) throws IOException {
|
public void loadConfig(Path configPath) throws IOException {
|
||||||
if (generateConfigIfNotExists(configPath)) return;
|
if (generateConfigIfNotExists(configPath)) return;
|
||||||
try (BufferedReader reader = IOHelper.newReader(configPath)) {
|
try (BufferedReader reader = IOHelper.newReader(configPath)) {
|
||||||
setConfig(Launcher.gson.fromJson(reader, type));
|
setConfig(Launcher.gson.fromJson(reader, type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@LauncherAPI
|
||||||
public void resetConfig() throws IOException {
|
public void resetConfig() throws IOException {
|
||||||
setConfig(getDefaultConfig());
|
setConfig(getDefaultConfig());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
@LauncherAPI
|
||||||
public void resetConfig(Path newPath) throws IOException {
|
public void resetConfig(Path newPath) throws IOException {
|
||||||
setConfig(getDefaultConfig());
|
setConfig(getDefaultConfig());
|
||||||
saveConfig(newPath);
|
saveConfig(newPath);
|
||||||
}
|
}
|
||||||
|
@LauncherAPI
|
||||||
public boolean generateConfigIfNotExists(Path path) throws IOException {
|
public boolean generateConfigIfNotExists(Path path) throws IOException {
|
||||||
if (IOHelper.isFile(path))
|
if (IOHelper.isFile(path))
|
||||||
return false;
|
return false;
|
||||||
resetConfig(path);
|
resetConfig(path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@LauncherAPI
|
||||||
public boolean generateConfigIfNotExists() throws IOException {
|
public boolean generateConfigIfNotExists() throws IOException {
|
||||||
if (IOHelper.isFile(configPath))
|
if (IOHelper.isFile(configPath))
|
||||||
return false;
|
return false;
|
||||||
resetConfig();
|
resetConfig();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
protected void setType(Type type)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
@LauncherAPI
|
||||||
public abstract T getConfig();
|
public abstract T getConfig();
|
||||||
|
@LauncherAPI
|
||||||
public abstract T getDefaultConfig();
|
public abstract T getDefaultConfig();
|
||||||
|
@LauncherAPI
|
||||||
public abstract void setConfig(T config);
|
public abstract void setConfig(T config);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue