diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java index e7474ca6b..95fb31b97 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java @@ -40,6 +40,12 @@ public final class Config { @SerializedName("commonpath") private String commonDirectory = Main.MINECRAFT_DIRECTORY.getAbsolutePath(); + @SerializedName("hasProxy") + private boolean hasProxy = false; + + @SerializedName("hasProxyAuth") + private boolean hasProxyAuth = false; + @SerializedName("proxyType") private int proxyType = 0; @@ -121,6 +127,24 @@ public final class Config { Settings.INSTANCE.save(); } + public boolean isHasProxy() { + return hasProxy; + } + + public void setHasProxy(boolean hasProxy) { + this.hasProxy = hasProxy; + Settings.INSTANCE.save(); + } + + public boolean isHasProxyAuth() { + return hasProxyAuth; + } + + public void setHasProxyAuth(boolean hasProxyAuth) { + this.hasProxyAuth = hasProxyAuth; + Settings.INSTANCE.save(); + } + public int getProxyType() { return proxyType; } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profiles.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profiles.java new file mode 100644 index 000000000..b41fad711 --- /dev/null +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profiles.java @@ -0,0 +1,36 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2017 huangyuhui + * + * 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 org.jackhuang.hmcl.Main; + +public final class Profiles { + private Profiles() { + } + + public static String getProfileDisplayName(Profile profile) { + switch (profile.getName()) { + case Settings.DEFAULT_PROFILE: + return Main.i18n("profile.default"); + case Settings.HOME_PROFILE: + return Main.i18n("profile.home"); + default: + return profile.getName(); + } + } +} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Settings.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Settings.java index 260faeb1b..43adbe380 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Settings.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Settings.java @@ -124,11 +124,6 @@ public class Settings { } catch (Exception e) { Logging.LOG.log(Level.WARNING, "Something happened wrongly when load settings.", e); } - else { - Logging.LOG.config("No settings file here, may be first loading."); - if (!c.getConfigurations().containsKey(HOME_PROFILE)) - c.getConfigurations().put(HOME_PROFILE, new Profile(HOME_PROFILE, Main.MINECRAFT_DIRECTORY)); - } return c; } @@ -229,22 +224,27 @@ public class Settings { SETTINGS.setProxyPass(proxyPass); } + public boolean hasProxy() { return SETTINGS.isHasProxy(); } + + public void setHasProxy(boolean hasProxy) { SETTINGS.setHasProxy(hasProxy); } + + public boolean hasProxyAuth() { return SETTINGS.isHasProxyAuth(); } + + public void setHasProxyAuth(boolean hasProxyAuth) { SETTINGS.setHasProxyAuth(hasProxyAuth); } + private void loadProxy() { String host = getProxyHost(); Integer port = Lang.toIntOrNull(getProxyPort()); - if (StringUtils.isBlank(host) || port == null) + if (!hasProxy() || StringUtils.isBlank(host) || port == null || getProxyType() == Proxy.Type.DIRECT) proxy = Proxy.NO_PROXY; else { System.setProperty("http.proxyHost", getProxyHost()); System.setProperty("http.proxyPort", getProxyPort()); - if (getProxyType() == Proxy.Type.DIRECT) - proxy = Proxy.NO_PROXY; - else - proxy = new Proxy(proxyType, new InetSocketAddress(host, port)); + proxy = new Proxy(proxyType, new InetSocketAddress(host, port)); String user = getProxyUser(); String pass = getProxyPass(); - if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(pass)) { + if (hasProxyAuth() && StringUtils.isNotBlank(user) && StringUtils.isNotBlank(pass)) { System.setProperty("http.proxyUser", user); System.setProperty("http.proxyPassword", pass); @@ -463,7 +463,7 @@ public class Settings { } public boolean hasProfile(String name) { - return getProfileMap().containsKey(Lang.nonNull(name, DEFAULT_PROFILE)); + return getProfileMap().containsKey(name); } public Map getProfileMap() { @@ -494,8 +494,10 @@ public class Settings { } private void checkProfileMap() { - if (getProfileMap().isEmpty()) + if (getProfileMap().isEmpty()) { getProfileMap().put(DEFAULT_PROFILE, new Profile(DEFAULT_PROFILE)); + getProfileMap().put(HOME_PROFILE, new Profile(HOME_PROFILE, Main.MINECRAFT_DIRECTORY)); + } } private void onProfileChanged() { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountsPage.java index ce98d5e95..561e1322c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountsPage.java @@ -160,20 +160,10 @@ public final class AccountsPage extends StackPane implements DecoratorPage { Settings.INSTANCE.addAccount((Account) account); dialog.close(); loadAccounts(); - } else if (account instanceof InvalidCredentialsException) { - lblCreationWarning.setText(Main.i18n("account.failed.wrong_password")); - } else if (account instanceof NoCharacterException) { - lblCreationWarning.setText(Main.i18n("account.failed.no_charactor")); - } else if (account instanceof ServerDisconnectException) { - lblCreationWarning.setText(Main.i18n("account.failed.connect_authentication_server")); - } else if (account instanceof InvalidTokenException) { - lblCreationWarning.setText(Main.i18n("account.failed.invalid_token")); - } else if (account instanceof InvalidPasswordException) { - lblCreationWarning.setText(Main.i18n("account.failed.invalid_password")); } else if (account instanceof NoSelectedCharacterException) { dialog.close(); } else if (account instanceof Exception) { - lblCreationWarning.setText(account.getClass() + ": " + ((Exception) account).getLocalizedMessage()); + lblCreationWarning.setText(accountException((Exception) account)); } progressBar.setVisible(false); }); @@ -197,6 +187,22 @@ public final class AccountsPage extends StackPane implements DecoratorPage { this.title.set(title); } + public static String accountException(Exception account) { + if (account instanceof InvalidCredentialsException) { + return Main.i18n("account.failed.invalid_credentials"); + } else if (account instanceof NoCharacterException) { + return Main.i18n("account.failed.no_charactor"); + } else if (account instanceof ServerDisconnectException) { + return Main.i18n("account.failed.connect_authentication_server"); + } else if (account instanceof InvalidTokenException) { + return Main.i18n("account.failed.invalid_token"); + } else if (account instanceof InvalidPasswordException) { + return Main.i18n("account.failed.invalid_password"); + } else { + return account.getClass() + ": " + ((Exception) account).getLocalizedMessage(); + } + } + public static String accountType(Account account) { if (account instanceof OfflineAccount) return Main.i18n("account.methods.offline"); else if (account instanceof YggdrasilAccount) return Main.i18n("account.methods.yggdrasil"); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java index ba4d88ad5..745d1e796 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java @@ -39,6 +39,7 @@ import org.jackhuang.hmcl.mod.Modpack; import org.jackhuang.hmcl.mod.UnsupportedModpackException; import org.jackhuang.hmcl.setting.Accounts; import org.jackhuang.hmcl.setting.Profile; +import org.jackhuang.hmcl.setting.Profiles; import org.jackhuang.hmcl.setting.Settings; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; @@ -122,7 +123,7 @@ public final class LeftPaneController { private void onProfilesLoading() { LinkedList list = new LinkedList<>(); for (Profile profile : Settings.INSTANCE.getProfiles()) { - VersionListItem item = new VersionListItem(profile.getName()); + VersionListItem item = new VersionListItem(Profiles.getProfileDisplayName(profile)); RipplerContainer ripplerContainer = new RipplerContainer(item); item.setOnSettingsButtonClicked(() -> Controllers.getDecorator().showPage(new ProfilePage(profile))); ripplerContainer.setOnMouseClicked(e -> Settings.INSTANCE.setSelectedProfile(profile)); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java index 5465c780b..ecffe19de 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java @@ -25,6 +25,7 @@ import javafx.fxml.FXML; import javafx.scene.layout.StackPane; import org.jackhuang.hmcl.Main; import org.jackhuang.hmcl.setting.Profile; +import org.jackhuang.hmcl.setting.Profiles; import org.jackhuang.hmcl.setting.Settings; import org.jackhuang.hmcl.ui.construct.FileItem; import org.jackhuang.hmcl.ui.wizard.DecoratorPage; @@ -58,7 +59,7 @@ public final class ProfilePage extends StackPane implements DecoratorPage { FXUtils.loadFXML(this, "/assets/fxml/profile.fxml"); - txtProfileName.setText(Optional.ofNullable(profile).map(Profile::getName).orElse("")); + txtProfileName.setText(Optional.ofNullable(profile).map(Profiles::getProfileDisplayName).orElse("")); FXUtils.onChangeAndOperate(txtProfileName.textProperty(), it -> { btnSave.setDisable(!txtProfileName.validate() || StringUtils.isBlank(getLocation())); }); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java index 04d614b17..c4b35b831 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java @@ -17,18 +17,16 @@ */ package org.jackhuang.hmcl.ui; -import com.jfoenix.controls.JFXButton; -import com.jfoenix.controls.JFXComboBox; -import com.jfoenix.controls.JFXTextField; +import com.jfoenix.controls.*; import javafx.application.Platform; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; -import javafx.scene.control.Label; -import javafx.scene.control.ScrollPane; -import javafx.scene.control.Tooltip; +import javafx.scene.control.*; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.text.Font; import org.jackhuang.hmcl.Main; @@ -40,6 +38,7 @@ import org.jackhuang.hmcl.ui.construct.Validator; import org.jackhuang.hmcl.ui.wizard.DecoratorPage; import org.jackhuang.hmcl.util.Lang; +import java.net.Proxy; import java.util.Arrays; import java.util.Collections; @@ -57,8 +56,6 @@ public final class SettingsPage extends StackPane implements DecoratorPage { @FXML private JFXTextField txtFontSize; @FXML - private JFXComboBox cboProxyType; - @FXML private JFXComboBox