Move config load/save code to ConfigHolder(WIP)
This commit is contained in:
@@ -71,7 +71,7 @@ public final class Accounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static AuthlibInjectorServer getOrCreateAuthlibInjectorServer(String url) {
|
private static AuthlibInjectorServer getOrCreateAuthlibInjectorServer(String url) {
|
||||||
return Settings.SETTINGS.authlibInjectorServers.stream()
|
return ConfigHolder.CONFIG.authlibInjectorServers.stream()
|
||||||
.filter(server -> url.equals(server.getUrl()))
|
.filter(server -> url.equals(server.getUrl()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseGet(() -> {
|
.orElseGet(() -> {
|
||||||
@@ -85,7 +85,7 @@ public final class Accounts {
|
|||||||
LOG.log(Level.WARNING, "Failed to migrate authlib injector server " + url, e);
|
LOG.log(Level.WARNING, "Failed to migrate authlib injector server " + url, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.SETTINGS.authlibInjectorServers.add(server);
|
ConfigHolder.CONFIG.authlibInjectorServers.add(server);
|
||||||
return server;
|
return server;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2018 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hmcl.setting;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
|
||||||
|
public final class ConfigHolder {
|
||||||
|
|
||||||
|
private ConfigHolder() {}
|
||||||
|
|
||||||
|
public static final String CONFIG_FILENAME = "hmcl.json";
|
||||||
|
public static final Path CONFIG_PATH = Paths.get(CONFIG_FILENAME).toAbsolutePath();
|
||||||
|
public static final Config CONFIG = initSettings();
|
||||||
|
|
||||||
|
private static Config initSettings() {
|
||||||
|
Config config = new Config();
|
||||||
|
if (Files.exists(CONFIG_PATH)) {
|
||||||
|
try {
|
||||||
|
Config deserialized = Config.fromJson(new String(Files.readAllBytes(CONFIG_PATH), UTF_8));
|
||||||
|
if (deserialized == null) {
|
||||||
|
LOG.finer("Settings file is empty, use the default settings.");
|
||||||
|
} else {
|
||||||
|
config = deserialized;
|
||||||
|
}
|
||||||
|
LOG.finest("Initialized settings.");
|
||||||
|
} catch (IOException | JsonParseException e) {
|
||||||
|
LOG.log(Level.WARNING, "Something happened wrongly when load settings.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void saveConfig(Config config) {
|
||||||
|
try {
|
||||||
|
Files.write(CONFIG_PATH, config.toJson().getBytes(UTF_8));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
LOG.log(Level.SEVERE, "Failed to save config", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -33,22 +33,15 @@ import org.jackhuang.hmcl.task.Schedulers;
|
|||||||
import org.jackhuang.hmcl.util.*;
|
import org.jackhuang.hmcl.util.*;
|
||||||
import org.jackhuang.hmcl.util.i18n.Locales;
|
import org.jackhuang.hmcl.util.i18n.Locales;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.Authenticator;
|
import java.net.Authenticator;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.PasswordAuthentication;
|
import java.net.PasswordAuthentication;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating;
|
import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating;
|
||||||
import static org.jackhuang.hmcl.util.Lang.tryCast;
|
import static org.jackhuang.hmcl.util.Lang.tryCast;
|
||||||
@@ -56,11 +49,6 @@ import static org.jackhuang.hmcl.util.Logging.LOG;
|
|||||||
|
|
||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
public static final String SETTINGS_FILE_NAME = "hmcl.json";
|
|
||||||
public static final Path SETTINGS_FILE = Paths.get(SETTINGS_FILE_NAME).toAbsolutePath();
|
|
||||||
|
|
||||||
public static final Config SETTINGS = initSettings();
|
|
||||||
|
|
||||||
public static final Settings INSTANCE = new Settings();
|
public static final Settings INSTANCE = new Settings();
|
||||||
|
|
||||||
private final Map<String, Account> accounts = new ConcurrentHashMap<>();
|
private final Map<String, Account> accounts = new ConcurrentHashMap<>();
|
||||||
@@ -68,11 +56,12 @@ public class Settings {
|
|||||||
private final boolean firstLaunch;
|
private final boolean firstLaunch;
|
||||||
|
|
||||||
private Settings() {
|
private Settings() {
|
||||||
firstLaunch = SETTINGS.firstLaunch.get();
|
firstLaunch = ConfigHolder.CONFIG.firstLaunch.get();
|
||||||
|
ConfigHolder.CONFIG.firstLaunch.set(false);
|
||||||
|
|
||||||
loadProxy();
|
loadProxy();
|
||||||
|
|
||||||
for (Iterator<Map<Object, Object>> iterator = SETTINGS.accounts.iterator(); iterator.hasNext();) {
|
for (Iterator<Map<Object, Object>> iterator = ConfigHolder.CONFIG.accounts.iterator(); iterator.hasNext();) {
|
||||||
Map<Object, Object> settings = iterator.next();
|
Map<Object, Object> settings = iterator.next();
|
||||||
AccountFactory<?> factory = Accounts.ACCOUNT_FACTORY.get(tryCast(settings.get("type"), String.class).orElse(""));
|
AccountFactory<?> factory = Accounts.ACCOUNT_FACTORY.get(tryCast(settings.get("type"), String.class).orElse(""));
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
@@ -93,7 +82,7 @@ public class Settings {
|
|||||||
accounts.put(Accounts.getAccountId(account), account);
|
accounts.put(Accounts.getAccountId(account), account);
|
||||||
}
|
}
|
||||||
|
|
||||||
SETTINGS.authlibInjectorServers.addListener(onInvalidating(this::removeDanglingAuthlibInjectorAccounts));
|
ConfigHolder.CONFIG.authlibInjectorServers.addListener(onInvalidating(this::removeDanglingAuthlibInjectorAccounts));
|
||||||
|
|
||||||
checkProfileMap();
|
checkProfileMap();
|
||||||
|
|
||||||
@@ -108,53 +97,26 @@ public class Settings {
|
|||||||
Lang.ignoringException(() -> Runtime.getRuntime().addShutdownHook(new Thread(this::save)));
|
Lang.ignoringException(() -> Runtime.getRuntime().addShutdownHook(new Thread(this::save)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Config initSettings() {
|
|
||||||
Config config = new Config();
|
|
||||||
if (Files.exists(SETTINGS_FILE)) {
|
|
||||||
try {
|
|
||||||
String str = new String(Files.readAllBytes(SETTINGS_FILE), UTF_8);
|
|
||||||
if (StringUtils.isBlank(str)) {
|
|
||||||
LOG.finer("Settings file is empty, use the default settings.");
|
|
||||||
} else {
|
|
||||||
Config deserialized = Config.fromJson(str);
|
|
||||||
if (deserialized != null) {
|
|
||||||
config = deserialized;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LOG.finest("Initialized settings.");
|
|
||||||
} catch (IOException | JsonParseException e) {
|
|
||||||
LOG.log(Level.WARNING, "Something happened wrongly when load settings.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
try {
|
ConfigHolder.CONFIG.accounts.clear();
|
||||||
SETTINGS.accounts.clear();
|
|
||||||
SETTINGS.firstLaunch.set(false);
|
|
||||||
for (Account account : accounts.values()) {
|
for (Account account : accounts.values()) {
|
||||||
Map<Object, Object> storage = account.toStorage();
|
Map<Object, Object> storage = account.toStorage();
|
||||||
storage.put("type", Accounts.getAccountType(account));
|
storage.put("type", Accounts.getAccountType(account));
|
||||||
SETTINGS.accounts.add(storage);
|
ConfigHolder.CONFIG.accounts.add(storage);
|
||||||
}
|
|
||||||
|
|
||||||
Files.write(SETTINGS_FILE, SETTINGS.toJson().getBytes(UTF_8));
|
|
||||||
} catch (IOException ex) {
|
|
||||||
LOG.log(Level.SEVERE, "Failed to save config", ex);
|
|
||||||
}
|
}
|
||||||
|
ConfigHolder.saveConfig(ConfigHolder.CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFirstLaunch() {
|
public boolean isFirstLaunch() {
|
||||||
return firstLaunch;
|
return firstLaunch;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final StringProperty commonPath = new ImmediateStringProperty(this, "commonPath", SETTINGS.commonDirectory.get()) {
|
private final StringProperty commonPath = new ImmediateStringProperty(this, "commonPath", ConfigHolder.CONFIG.commonDirectory.get()) {
|
||||||
@Override
|
@Override
|
||||||
public void invalidated() {
|
public void invalidated() {
|
||||||
super.invalidated();
|
super.invalidated();
|
||||||
|
|
||||||
SETTINGS.commonDirectory.set(get());
|
ConfigHolder.CONFIG.commonDirectory.set(get());
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -171,7 +133,7 @@ public class Settings {
|
|||||||
this.commonPath.set(commonPath);
|
this.commonPath.set(commonPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Locales.SupportedLocale locale = Locales.getLocaleByName(SETTINGS.localization.get());
|
private Locales.SupportedLocale locale = Locales.getLocaleByName(ConfigHolder.CONFIG.localization.get());
|
||||||
|
|
||||||
public Locales.SupportedLocale getLocale() {
|
public Locales.SupportedLocale getLocale() {
|
||||||
return locale;
|
return locale;
|
||||||
@@ -179,7 +141,7 @@ public class Settings {
|
|||||||
|
|
||||||
public void setLocale(Locales.SupportedLocale locale) {
|
public void setLocale(Locales.SupportedLocale locale) {
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
SETTINGS.localization.set(Locales.getNameByLocale(locale));
|
ConfigHolder.CONFIG.localization.set(Locales.getNameByLocale(locale));
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +151,7 @@ public class Settings {
|
|||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Proxy.Type proxyType = Proxies.getProxyType(SETTINGS.proxyType.get());
|
private Proxy.Type proxyType = Proxies.getProxyType(ConfigHolder.CONFIG.proxyType.get());
|
||||||
|
|
||||||
public Proxy.Type getProxyType() {
|
public Proxy.Type getProxyType() {
|
||||||
return proxyType;
|
return proxyType;
|
||||||
@@ -197,62 +159,62 @@ public class Settings {
|
|||||||
|
|
||||||
public void setProxyType(Proxy.Type proxyType) {
|
public void setProxyType(Proxy.Type proxyType) {
|
||||||
this.proxyType = proxyType;
|
this.proxyType = proxyType;
|
||||||
SETTINGS.proxyType.set(Proxies.PROXIES.indexOf(proxyType));
|
ConfigHolder.CONFIG.proxyType.set(Proxies.PROXIES.indexOf(proxyType));
|
||||||
save();
|
save();
|
||||||
loadProxy();
|
loadProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProxyHost() {
|
public String getProxyHost() {
|
||||||
return SETTINGS.proxyHost.get();
|
return ConfigHolder.CONFIG.proxyHost.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProxyHost(String proxyHost) {
|
public void setProxyHost(String proxyHost) {
|
||||||
SETTINGS.proxyHost.set(proxyHost);
|
ConfigHolder.CONFIG.proxyHost.set(proxyHost);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProxyPort() {
|
public String getProxyPort() {
|
||||||
return SETTINGS.proxyPort.get();
|
return ConfigHolder.CONFIG.proxyPort.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProxyPort(String proxyPort) {
|
public void setProxyPort(String proxyPort) {
|
||||||
SETTINGS.proxyPort.set(proxyPort);
|
ConfigHolder.CONFIG.proxyPort.set(proxyPort);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProxyUser() {
|
public String getProxyUser() {
|
||||||
return SETTINGS.proxyUser.get();
|
return ConfigHolder.CONFIG.proxyUser.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProxyUser(String proxyUser) {
|
public void setProxyUser(String proxyUser) {
|
||||||
SETTINGS.proxyUser.set(proxyUser);
|
ConfigHolder.CONFIG.proxyUser.set(proxyUser);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProxyPass() {
|
public String getProxyPass() {
|
||||||
return SETTINGS.proxyPass.get();
|
return ConfigHolder.CONFIG.proxyPass.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProxyPass(String proxyPass) {
|
public void setProxyPass(String proxyPass) {
|
||||||
SETTINGS.proxyPass.set(proxyPass);
|
ConfigHolder.CONFIG.proxyPass.set(proxyPass);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasProxy() {
|
public boolean hasProxy() {
|
||||||
return SETTINGS.hasProxy.get();
|
return ConfigHolder.CONFIG.hasProxy.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHasProxy(boolean hasProxy) {
|
public void setHasProxy(boolean hasProxy) {
|
||||||
SETTINGS.hasProxy.set(hasProxy);
|
ConfigHolder.CONFIG.hasProxy.set(hasProxy);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasProxyAuth() {
|
public boolean hasProxyAuth() {
|
||||||
return SETTINGS.hasProxyAuth.get();
|
return ConfigHolder.CONFIG.hasProxyAuth.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHasProxyAuth(boolean hasProxyAuth) {
|
public void setHasProxyAuth(boolean hasProxyAuth) {
|
||||||
SETTINGS.hasProxyAuth.set(hasProxyAuth);
|
ConfigHolder.CONFIG.hasProxyAuth.set(hasProxyAuth);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,21 +245,21 @@ public class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Font getFont() {
|
public Font getFont() {
|
||||||
return Font.font(SETTINGS.fontFamily.get(), SETTINGS.fontSize.get());
|
return Font.font(ConfigHolder.CONFIG.fontFamily.get(), ConfigHolder.CONFIG.fontSize.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFont(Font font) {
|
public void setFont(Font font) {
|
||||||
SETTINGS.fontFamily.set(font.getFamily());
|
ConfigHolder.CONFIG.fontFamily.set(font.getFamily());
|
||||||
SETTINGS.fontSize.set(font.getSize());
|
ConfigHolder.CONFIG.fontSize.set(font.getSize());
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLogLines() {
|
public int getLogLines() {
|
||||||
return Math.max(SETTINGS.logLines.get(), 100);
|
return Math.max(ConfigHolder.CONFIG.logLines.get(), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLogLines(int logLines) {
|
public void setLogLines(int logLines) {
|
||||||
SETTINGS.logLines.set(logLines);
|
ConfigHolder.CONFIG.logLines.set(logLines);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +275,7 @@ public class Settings {
|
|||||||
private void removeDanglingAuthlibInjectorAccounts() {
|
private void removeDanglingAuthlibInjectorAccounts() {
|
||||||
accounts.values().stream()
|
accounts.values().stream()
|
||||||
.filter(AuthlibInjectorAccount.class::isInstance)
|
.filter(AuthlibInjectorAccount.class::isInstance)
|
||||||
.filter(it -> !SETTINGS.authlibInjectorServers.contains(((AuthlibInjectorAccount) it).getServer()))
|
.filter(it -> !ConfigHolder.CONFIG.authlibInjectorServers.contains(((AuthlibInjectorAccount) it).getServer()))
|
||||||
.collect(toList())
|
.collect(toList())
|
||||||
.forEach(this::deleteAccount);
|
.forEach(this::deleteAccount);
|
||||||
}
|
}
|
||||||
@@ -323,14 +285,14 @@ public class Settings {
|
|||||||
****************************************/
|
****************************************/
|
||||||
|
|
||||||
public DownloadProvider getDownloadProvider() {
|
public DownloadProvider getDownloadProvider() {
|
||||||
return DownloadProviders.getDownloadProvider(SETTINGS.downloadType.get());
|
return DownloadProviders.getDownloadProvider(ConfigHolder.CONFIG.downloadType.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDownloadProvider(DownloadProvider downloadProvider) {
|
public void setDownloadProvider(DownloadProvider downloadProvider) {
|
||||||
int index = DownloadProviders.DOWNLOAD_PROVIDERS.indexOf(downloadProvider);
|
int index = DownloadProviders.DOWNLOAD_PROVIDERS.indexOf(downloadProvider);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
throw new IllegalArgumentException("Unknown download provider: " + downloadProvider);
|
throw new IllegalArgumentException("Unknown download provider: " + downloadProvider);
|
||||||
SETTINGS.downloadType.set(index);
|
ConfigHolder.CONFIG.downloadType.set(index);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +300,7 @@ public class Settings {
|
|||||||
* ACCOUNTS *
|
* ACCOUNTS *
|
||||||
****************************************/
|
****************************************/
|
||||||
|
|
||||||
private final ImmediateObjectProperty<Account> selectedAccount = new ImmediateObjectProperty<Account>(this, "selectedAccount", accounts.get(SETTINGS.selectedAccount.get())) {
|
private final ImmediateObjectProperty<Account> selectedAccount = new ImmediateObjectProperty<Account>(this, "selectedAccount", accounts.get(ConfigHolder.CONFIG.selectedAccount.get())) {
|
||||||
@Override
|
@Override
|
||||||
public Account get() {
|
public Account get() {
|
||||||
Account a = super.get();
|
Account a = super.get();
|
||||||
@@ -360,7 +322,7 @@ public class Settings {
|
|||||||
public void invalidated() {
|
public void invalidated() {
|
||||||
super.invalidated();
|
super.invalidated();
|
||||||
|
|
||||||
SETTINGS.selectedAccount.set(getValue() == null ? "" : Accounts.getAccountId(getValue()));
|
ConfigHolder.CONFIG.selectedAccount.set(getValue() == null ? "" : Accounts.getAccountId(getValue()));
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -410,12 +372,12 @@ public class Settings {
|
|||||||
* BACKGROUND *
|
* BACKGROUND *
|
||||||
****************************************/
|
****************************************/
|
||||||
|
|
||||||
private final ImmediateStringProperty backgroundImage = new ImmediateStringProperty(this, "backgroundImage", SETTINGS.backgroundImage.get()) {
|
private final ImmediateStringProperty backgroundImage = new ImmediateStringProperty(this, "backgroundImage", ConfigHolder.CONFIG.backgroundImage.get()) {
|
||||||
@Override
|
@Override
|
||||||
public void invalidated() {
|
public void invalidated() {
|
||||||
super.invalidated();
|
super.invalidated();
|
||||||
|
|
||||||
SETTINGS.backgroundImage.set(get());
|
ConfigHolder.CONFIG.backgroundImage.set(get());
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -432,12 +394,12 @@ public class Settings {
|
|||||||
this.backgroundImage.set(backgroundImage);
|
this.backgroundImage.set(backgroundImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ImmediateObjectProperty<EnumBackgroundImage> backgroundImageType = new ImmediateObjectProperty<EnumBackgroundImage>(this, "backgroundImageType", EnumBackgroundImage.indexOf(SETTINGS.backgroundImageType.get())) {
|
private final ImmediateObjectProperty<EnumBackgroundImage> backgroundImageType = new ImmediateObjectProperty<EnumBackgroundImage>(this, "backgroundImageType", EnumBackgroundImage.indexOf(ConfigHolder.CONFIG.backgroundImageType.get())) {
|
||||||
@Override
|
@Override
|
||||||
public void invalidated() {
|
public void invalidated() {
|
||||||
super.invalidated();
|
super.invalidated();
|
||||||
|
|
||||||
SETTINGS.backgroundImageType.set(get().ordinal());
|
ConfigHolder.CONFIG.backgroundImageType.set(get().ordinal());
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -458,12 +420,12 @@ public class Settings {
|
|||||||
* THEME *
|
* THEME *
|
||||||
****************************************/
|
****************************************/
|
||||||
|
|
||||||
private final ImmediateObjectProperty<Theme> theme = new ImmediateObjectProperty<Theme>(this, "theme", Theme.getTheme(SETTINGS.theme.get()).orElse(Theme.BLUE)) {
|
private final ImmediateObjectProperty<Theme> theme = new ImmediateObjectProperty<Theme>(this, "theme", Theme.getTheme(ConfigHolder.CONFIG.theme.get()).orElse(Theme.BLUE)) {
|
||||||
@Override
|
@Override
|
||||||
public void invalidated() {
|
public void invalidated() {
|
||||||
super.invalidated();
|
super.invalidated();
|
||||||
|
|
||||||
SETTINGS.theme.set(get().getName().toLowerCase());
|
ConfigHolder.CONFIG.theme.set(get().getName().toLowerCase());
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -487,19 +449,19 @@ public class Settings {
|
|||||||
public Profile getSelectedProfile() {
|
public Profile getSelectedProfile() {
|
||||||
checkProfileMap();
|
checkProfileMap();
|
||||||
|
|
||||||
if (!hasProfile(SETTINGS.selectedProfile.get())) {
|
if (!hasProfile(ConfigHolder.CONFIG.selectedProfile.get())) {
|
||||||
getProfileMap().keySet().stream().findFirst().ifPresent(selectedProfile -> {
|
getProfileMap().keySet().stream().findFirst().ifPresent(selectedProfile -> {
|
||||||
SETTINGS.selectedProfile.set(selectedProfile);
|
ConfigHolder.CONFIG.selectedProfile.set(selectedProfile);
|
||||||
save();
|
save();
|
||||||
});
|
});
|
||||||
Schedulers.computation().schedule(this::onProfileChanged);
|
Schedulers.computation().schedule(this::onProfileChanged);
|
||||||
}
|
}
|
||||||
return getProfile(SETTINGS.selectedProfile.get());
|
return getProfile(ConfigHolder.CONFIG.selectedProfile.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedProfile(Profile selectedProfile) {
|
public void setSelectedProfile(Profile selectedProfile) {
|
||||||
if (hasProfile(selectedProfile.getName()) && !Objects.equals(selectedProfile.getName(), SETTINGS.selectedProfile.get())) {
|
if (hasProfile(selectedProfile.getName()) && !Objects.equals(selectedProfile.getName(), ConfigHolder.CONFIG.selectedProfile.get())) {
|
||||||
SETTINGS.selectedProfile.set(selectedProfile.getName());
|
ConfigHolder.CONFIG.selectedProfile.set(selectedProfile.getName());
|
||||||
save();
|
save();
|
||||||
Schedulers.computation().schedule(this::onProfileChanged);
|
Schedulers.computation().schedule(this::onProfileChanged);
|
||||||
}
|
}
|
||||||
@@ -517,7 +479,7 @@ public class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Profile> getProfileMap() {
|
public Map<String, Profile> getProfileMap() {
|
||||||
return SETTINGS.configurations;
|
return ConfigHolder.CONFIG.configurations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Profile> getProfiles() {
|
public Collection<Profile> getProfiles() {
|
||||||
@@ -576,6 +538,6 @@ public class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Config getRawConfig() {
|
public Config getRawConfig() {
|
||||||
return SETTINGS.clone();
|
return ConfigHolder.CONFIG.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import org.jackhuang.hmcl.auth.yggdrasil.RemoteAuthenticationException;
|
|||||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
||||||
import org.jackhuang.hmcl.game.AccountHelper;
|
import org.jackhuang.hmcl.game.AccountHelper;
|
||||||
import org.jackhuang.hmcl.setting.Accounts;
|
import org.jackhuang.hmcl.setting.Accounts;
|
||||||
|
import org.jackhuang.hmcl.setting.ConfigHolder;
|
||||||
import org.jackhuang.hmcl.setting.Settings;
|
import org.jackhuang.hmcl.setting.Settings;
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
@@ -80,7 +81,7 @@ public class AddAccountPane extends StackPane {
|
|||||||
|
|
||||||
cboServers.setCellFactory(jfxListCellFactory(server -> new TwoLineListItem(server.getName(), server.getUrl())));
|
cboServers.setCellFactory(jfxListCellFactory(server -> new TwoLineListItem(server.getName(), server.getUrl())));
|
||||||
cboServers.setConverter(stringConverter(AuthlibInjectorServer::getName));
|
cboServers.setConverter(stringConverter(AuthlibInjectorServer::getName));
|
||||||
Bindings.bindContent(cboServers.getItems(), Settings.SETTINGS.authlibInjectorServers);
|
Bindings.bindContent(cboServers.getItems(), ConfigHolder.CONFIG.authlibInjectorServers);
|
||||||
cboServers.getItems().addListener(onInvalidating(this::selectDefaultServer));
|
cboServers.getItems().addListener(onInvalidating(this::selectDefaultServer));
|
||||||
selectDefaultServer();
|
selectDefaultServer();
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
|
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
|
||||||
import org.jackhuang.hmcl.setting.Settings;
|
import org.jackhuang.hmcl.setting.ConfigHolder;
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
||||||
@@ -132,8 +132,8 @@ public class AddAuthlibInjectorServerPane extends StackPane {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onAddFinish() {
|
private void onAddFinish() {
|
||||||
if (!Settings.SETTINGS.authlibInjectorServers.contains(serverBeingAdded)) {
|
if (!ConfigHolder.CONFIG.authlibInjectorServers.contains(serverBeingAdded)) {
|
||||||
Settings.SETTINGS.authlibInjectorServers.add(serverBeingAdded);
|
ConfigHolder.CONFIG.authlibInjectorServers.add(serverBeingAdded);
|
||||||
}
|
}
|
||||||
fireEvent(new DialogCloseEvent());
|
fireEvent(new DialogCloseEvent());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import static org.jackhuang.hmcl.ui.FXUtils.loadFXML;
|
|||||||
import static org.jackhuang.hmcl.ui.FXUtils.smoothScrolling;
|
import static org.jackhuang.hmcl.ui.FXUtils.smoothScrolling;
|
||||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||||
|
|
||||||
import org.jackhuang.hmcl.setting.Settings;
|
import org.jackhuang.hmcl.setting.ConfigHolder;
|
||||||
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
||||||
|
|
||||||
import javafx.beans.InvalidationListener;
|
import javafx.beans.InvalidationListener;
|
||||||
@@ -48,15 +48,15 @@ public class AuthlibInjectorServersPage extends StackPane implements DecoratorPa
|
|||||||
smoothScrolling(scrollPane);
|
smoothScrolling(scrollPane);
|
||||||
|
|
||||||
serversListener = observable -> updateServersList();
|
serversListener = observable -> updateServersList();
|
||||||
Settings.SETTINGS.authlibInjectorServers.addListener(new WeakInvalidationListener(serversListener));
|
ConfigHolder.CONFIG.authlibInjectorServers.addListener(new WeakInvalidationListener(serversListener));
|
||||||
updateServersList();
|
updateServersList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateServersList() {
|
private void updateServersList() {
|
||||||
listPane.getChildren().setAll(
|
listPane.getChildren().setAll(
|
||||||
Settings.SETTINGS.authlibInjectorServers.stream()
|
ConfigHolder.CONFIG.authlibInjectorServers.stream()
|
||||||
.map(server -> new AuthlibInjectorServerItem(server,
|
.map(server -> new AuthlibInjectorServerItem(server,
|
||||||
item -> Settings.SETTINGS.authlibInjectorServers.remove(item.getServer())))
|
item -> ConfigHolder.CONFIG.authlibInjectorServers.remove(item.getServer())))
|
||||||
.collect(toList()));
|
.collect(toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.jackhuang.hmcl.game.HMCLModpackExportTask;
|
|||||||
import org.jackhuang.hmcl.game.HMCLModpackManager;
|
import org.jackhuang.hmcl.game.HMCLModpackManager;
|
||||||
import org.jackhuang.hmcl.mod.Modpack;
|
import org.jackhuang.hmcl.mod.Modpack;
|
||||||
import org.jackhuang.hmcl.setting.Config;
|
import org.jackhuang.hmcl.setting.Config;
|
||||||
|
import org.jackhuang.hmcl.setting.ConfigHolder;
|
||||||
import org.jackhuang.hmcl.setting.Profile;
|
import org.jackhuang.hmcl.setting.Profile;
|
||||||
import org.jackhuang.hmcl.setting.Settings;
|
import org.jackhuang.hmcl.setting.Settings;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
@@ -93,7 +94,7 @@ public final class ExportWizardProvider implements WizardProvider {
|
|||||||
config.logLines.set(100);
|
config.logLines.set(100);
|
||||||
config.configurations.clear();
|
config.configurations.clear();
|
||||||
|
|
||||||
zip.putTextFile(config.toJson(), Settings.SETTINGS_FILE_NAME);
|
zip.putTextFile(config.toJson(), ConfigHolder.CONFIG_FILENAME);
|
||||||
zip.putFile(tempModpack, "modpack.zip");
|
zip.putFile(tempModpack, "modpack.zip");
|
||||||
|
|
||||||
File bg = new File("bg").getAbsoluteFile();
|
File bg = new File("bg").getAbsoluteFile();
|
||||||
|
|||||||
Reference in New Issue
Block a user