Remove simple properties in Settings

This commit is contained in:
yushijinhun
2018-07-17 17:12:25 +08:00
parent fac62a8d24
commit 6d83fd9903
5 changed files with 30 additions and 103 deletions

View File

@@ -17,8 +17,8 @@
*/ */
package org.jackhuang.hmcl.game; package org.jackhuang.hmcl.game;
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.task.FileDownloadTask; import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.task.FileDownloadTask.IntegrityCheck; import org.jackhuang.hmcl.task.FileDownloadTask.IntegrityCheck;
import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.Task;
@@ -58,7 +58,7 @@ public class HMCLGameDownloadTask extends Task {
public void execute() { public void execute() {
File jar = profile.getRepository().getVersionJar(version); File jar = profile.getRepository().getVersionJar(version);
File cache = new File(Settings.INSTANCE.getCommonPath(), "jars/" + gameVersion + ".jar"); File cache = new File(ConfigHolder.CONFIG.commonDirectory.get(), "jars/" + gameVersion + ".jar");
if (cache.exists()) if (cache.exists())
try { try {
FileUtils.copyFile(cache, jar); FileUtils.copyFile(cache, jar);

View File

@@ -22,9 +22,9 @@ import com.google.gson.GsonBuilder;
import org.jackhuang.hmcl.event.EventBus; import org.jackhuang.hmcl.event.EventBus;
import org.jackhuang.hmcl.event.RefreshedVersionsEvent; import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
import org.jackhuang.hmcl.event.RefreshingVersionsEvent; import org.jackhuang.hmcl.event.RefreshingVersionsEvent;
import org.jackhuang.hmcl.setting.ConfigHolder;
import org.jackhuang.hmcl.setting.EnumGameDirectory; import org.jackhuang.hmcl.setting.EnumGameDirectory;
import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.setting.Settings;
import org.jackhuang.hmcl.setting.VersionSetting; import org.jackhuang.hmcl.setting.VersionSetting;
import org.jackhuang.hmcl.util.FileUtils; import org.jackhuang.hmcl.util.FileUtils;
import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.Logging;
@@ -60,7 +60,7 @@ public class HMCLGameRepository extends DefaultGameRepository {
if (useSelf(version, assetId)) if (useSelf(version, assetId))
return super.getAssetDirectory(version, assetId); return super.getAssetDirectory(version, assetId);
else else
return new File(Settings.INSTANCE.getCommonPath(), "assets"); return new File(ConfigHolder.CONFIG.commonDirectory.get(), "assets");
} }
@Override @Override
@@ -85,7 +85,7 @@ public class HMCLGameRepository extends DefaultGameRepository {
if (self.exists() || vs.isNoCommon()) if (self.exists() || vs.isNoCommon())
return self; return self;
else else
return new File(Settings.INSTANCE.getCommonPath(), "libraries/" + lib.getPath()); return new File(ConfigHolder.CONFIG.commonDirectory.get(), "libraries/" + lib.getPath());
} }

View File

@@ -19,7 +19,6 @@ package org.jackhuang.hmcl.setting;
import javafx.beans.InvalidationListener; import javafx.beans.InvalidationListener;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.scene.text.Font; import javafx.scene.text.Font;
@@ -121,27 +120,6 @@ public class Settings {
return firstLaunch; return firstLaunch;
} }
private final StringProperty commonPath = new ImmediateStringProperty(this, "commonPath", ConfigHolder.CONFIG.commonDirectory.get()) {
@Override
public void invalidated() {
super.invalidated();
ConfigHolder.CONFIG.commonDirectory.set(get());
}
};
public String getCommonPath() {
return commonPath.get();
}
public StringProperty commonPathProperty() {
return commonPath;
}
public void setCommonPath(String commonPath) {
this.commonPath.set(commonPath);
}
private Locales.SupportedLocale locale = Locales.getLocaleByName(ConfigHolder.CONFIG.localization.get()); private Locales.SupportedLocale locale = Locales.getLocaleByName(ConfigHolder.CONFIG.localization.get());
public Locales.SupportedLocale getLocale() { public Locales.SupportedLocale getLocale() {
@@ -171,67 +149,19 @@ public class Settings {
loadProxy(); loadProxy();
} }
public String getProxyHost() {
return ConfigHolder.CONFIG.proxyHost.get();
}
public void setProxyHost(String proxyHost) {
ConfigHolder.CONFIG.proxyHost.set(proxyHost);
}
public String getProxyPort() {
return ConfigHolder.CONFIG.proxyPort.get();
}
public void setProxyPort(String proxyPort) {
ConfigHolder.CONFIG.proxyPort.set(proxyPort);
}
public String getProxyUser() {
return ConfigHolder.CONFIG.proxyUser.get();
}
public void setProxyUser(String proxyUser) {
ConfigHolder.CONFIG.proxyUser.set(proxyUser);
}
public String getProxyPass() {
return ConfigHolder.CONFIG.proxyPass.get();
}
public void setProxyPass(String proxyPass) {
ConfigHolder.CONFIG.proxyPass.set(proxyPass);
}
public boolean hasProxy() {
return ConfigHolder.CONFIG.hasProxy.get();
}
public void setHasProxy(boolean hasProxy) {
ConfigHolder.CONFIG.hasProxy.set(hasProxy);
}
public boolean hasProxyAuth() {
return ConfigHolder.CONFIG.hasProxyAuth.get();
}
public void setHasProxyAuth(boolean hasProxyAuth) {
ConfigHolder.CONFIG.hasProxyAuth.set(hasProxyAuth);
}
private void loadProxy() { private void loadProxy() {
String host = getProxyHost(); String host = ConfigHolder.CONFIG.proxyHost.get();
Integer port = Lang.toIntOrNull(getProxyPort()); Integer port = Lang.toIntOrNull(ConfigHolder.CONFIG.proxyPort.get());
if (!hasProxy() || StringUtils.isBlank(host) || port == null || getProxyType() == Proxy.Type.DIRECT) if (!ConfigHolder.CONFIG.hasProxy.get() || StringUtils.isBlank(host) || port == null || getProxyType() == Proxy.Type.DIRECT)
proxy = Proxy.NO_PROXY; proxy = Proxy.NO_PROXY;
else { else {
System.setProperty("http.proxyHost", getProxyHost()); System.setProperty("http.proxyHost", ConfigHolder.CONFIG.proxyHost.get());
System.setProperty("http.proxyPort", getProxyPort()); System.setProperty("http.proxyPort", ConfigHolder.CONFIG.proxyPort.get());
proxy = new Proxy(proxyType, new InetSocketAddress(host, port)); proxy = new Proxy(proxyType, new InetSocketAddress(host, port));
String user = getProxyUser(); String user = ConfigHolder.CONFIG.proxyUser.get();
String pass = getProxyPass(); String pass = ConfigHolder.CONFIG.proxyPass.get();
if (hasProxyAuth() && StringUtils.isNotBlank(user) && StringUtils.isNotBlank(pass)) { if (ConfigHolder.CONFIG.hasProxyAuth.get() && StringUtils.isNotBlank(user) && StringUtils.isNotBlank(pass)) {
System.setProperty("http.proxyUser", user); System.setProperty("http.proxyUser", user);
System.setProperty("http.proxyPassword", pass); System.setProperty("http.proxyPassword", pass);

View File

@@ -517,10 +517,10 @@ public final class VersionSetting {
.setFullscreen(isFullscreen()) .setFullscreen(isFullscreen())
.setServerIp(getServerIp()) .setServerIp(getServerIp())
.setWrapper(getWrapper()) .setWrapper(getWrapper())
.setProxyHost(Settings.INSTANCE.getProxyHost()) .setProxyHost(ConfigHolder.CONFIG.proxyHost.get())
.setProxyPort(Settings.INSTANCE.getProxyPort()) .setProxyPort(ConfigHolder.CONFIG.proxyPort.get())
.setProxyUser(Settings.INSTANCE.getProxyUser()) .setProxyUser(ConfigHolder.CONFIG.proxyUser.get())
.setProxyPass(Settings.INSTANCE.getProxyPass()) .setProxyPass(ConfigHolder.CONFIG.proxyPass.get())
.setPrecalledCommand(getPreLaunchCommand()) .setPrecalledCommand(getPreLaunchCommand())
.setNoGeneratedJVMArgs(isNoJVMArgs()) .setNoGeneratedJVMArgs(isNoJVMArgs())
.create(); .create();

View File

@@ -20,7 +20,6 @@ package org.jackhuang.hmcl.ui;
import com.jfoenix.controls.*; import com.jfoenix.controls.*;
import com.jfoenix.effects.JFXDepthManager; import com.jfoenix.effects.JFXDepthManager;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
@@ -48,9 +47,7 @@ import org.jackhuang.hmcl.util.i18n.Locales;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import java.net.Proxy; import java.net.Proxy;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.stream.Collectors;
public final class SettingsPage extends StackPane implements DecoratorPage { public final class SettingsPage extends StackPane implements DecoratorPage {
private final StringProperty title = new SimpleStringProperty(this, "title", i18n("settings.launcher")); private final StringProperty title = new SimpleStringProperty(this, "title", i18n("settings.launcher"));
@@ -107,17 +104,17 @@ public final class SettingsPage extends StackPane implements DecoratorPage {
FXUtils.smoothScrolling(scroll); FXUtils.smoothScrolling(scroll);
txtProxyHost.setText(Settings.INSTANCE.getProxyHost()); txtProxyHost.setText(ConfigHolder.CONFIG.proxyHost.get());
txtProxyHost.textProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setProxyHost(newValue)); txtProxyHost.textProperty().addListener((a, b, newValue) -> ConfigHolder.CONFIG.proxyHost.set(newValue));
txtProxyPort.setText(Settings.INSTANCE.getProxyPort()); txtProxyPort.setText(ConfigHolder.CONFIG.proxyPort.get());
txtProxyPort.textProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setProxyPort(newValue)); txtProxyPort.textProperty().addListener((a, b, newValue) -> ConfigHolder.CONFIG.proxyPort.set(newValue));
txtProxyUsername.setText(Settings.INSTANCE.getProxyUser()); txtProxyUsername.setText(ConfigHolder.CONFIG.proxyUser.get());
txtProxyUsername.textProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setProxyUser(newValue)); txtProxyUsername.textProperty().addListener((a, b, newValue) -> ConfigHolder.CONFIG.proxyUser.set(newValue));
txtProxyPassword.setText(Settings.INSTANCE.getProxyPass()); txtProxyPassword.setText(ConfigHolder.CONFIG.proxyPass.get());
txtProxyPassword.textProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setProxyPass(newValue)); txtProxyPassword.textProperty().addListener((a, b, newValue) -> ConfigHolder.CONFIG.proxyPass.set(newValue));
cboDownloadSource.getSelectionModel().select(DownloadProviders.DOWNLOAD_PROVIDERS.indexOf(Settings.INSTANCE.getDownloadProvider())); cboDownloadSource.getSelectionModel().select(DownloadProviders.DOWNLOAD_PROVIDERS.indexOf(Settings.INSTANCE.getDownloadProvider()));
cboDownloadSource.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setDownloadProvider(DownloadProviders.getDownloadProvider(newValue.intValue()))); cboDownloadSource.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setDownloadProvider(DownloadProviders.getDownloadProvider(newValue.intValue())));
@@ -163,23 +160,23 @@ public final class SettingsPage extends StackPane implements DecoratorPage {
ToggleGroup hasProxyGroup = new ToggleGroup(); ToggleGroup hasProxyGroup = new ToggleGroup();
chkNoProxy.setToggleGroup(hasProxyGroup); chkNoProxy.setToggleGroup(hasProxyGroup);
chkManualProxy.setToggleGroup(hasProxyGroup); chkManualProxy.setToggleGroup(hasProxyGroup);
if (!Settings.INSTANCE.hasProxy()) if (!ConfigHolder.CONFIG.hasProxy.get())
chkNoProxy.setSelected(true); chkNoProxy.setSelected(true);
else else
chkManualProxy.setSelected(true); chkManualProxy.setSelected(true);
proxyPane.disableProperty().bind(chkNoProxy.selectedProperty()); proxyPane.disableProperty().bind(chkNoProxy.selectedProperty());
hasProxyGroup.selectedToggleProperty().addListener((a, b, newValue) -> hasProxyGroup.selectedToggleProperty().addListener((a, b, newValue) ->
Settings.INSTANCE.setHasProxy(newValue != chkNoProxy)); ConfigHolder.CONFIG.hasProxy.set(newValue != chkNoProxy));
proxyConfigurationGroup.selectedToggleProperty().addListener((a, b, newValue) -> proxyConfigurationGroup.selectedToggleProperty().addListener((a, b, newValue) ->
Settings.INSTANCE.setProxyType((Proxy.Type) newValue.getUserData())); Settings.INSTANCE.setProxyType((Proxy.Type) newValue.getUserData()));
chkProxyAuthentication.setSelected(Settings.INSTANCE.hasProxyAuth()); chkProxyAuthentication.setSelected(ConfigHolder.CONFIG.hasProxyAuth.get());
chkProxyAuthentication.selectedProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setHasProxyAuth(newValue)); chkProxyAuthentication.selectedProperty().addListener((a, b, newValue) -> ConfigHolder.CONFIG.hasProxyAuth.set(newValue));
authPane.disableProperty().bind(chkProxyAuthentication.selectedProperty().not()); authPane.disableProperty().bind(chkProxyAuthentication.selectedProperty().not());
fileCommonLocation.pathProperty().bindBidirectional(Settings.INSTANCE.commonPathProperty()); fileCommonLocation.pathProperty().bindBidirectional(ConfigHolder.CONFIG.commonDirectory);
FXUtils.installTooltip(btnUpdate, i18n("update.tooltip")); FXUtils.installTooltip(btnUpdate, i18n("update.tooltip"));
checkUpdate(); checkUpdate();