mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-11 04:46:18 -04:00
优化代理设置 (#3876)
This commit is contained in:
parent
b69602b735
commit
9c0f823705
@ -30,7 +30,6 @@ import org.jackhuang.hmcl.mod.Modpack;
|
|||||||
import org.jackhuang.hmcl.mod.ModpackConfiguration;
|
import org.jackhuang.hmcl.mod.ModpackConfiguration;
|
||||||
import org.jackhuang.hmcl.mod.ModpackProvider;
|
import org.jackhuang.hmcl.mod.ModpackProvider;
|
||||||
import org.jackhuang.hmcl.setting.Profile;
|
import org.jackhuang.hmcl.setting.Profile;
|
||||||
import org.jackhuang.hmcl.setting.ProxyManager;
|
|
||||||
import org.jackhuang.hmcl.setting.VersionIconType;
|
import org.jackhuang.hmcl.setting.VersionIconType;
|
||||||
import org.jackhuang.hmcl.setting.VersionSetting;
|
import org.jackhuang.hmcl.setting.VersionSetting;
|
||||||
import org.jackhuang.hmcl.ui.FXUtils;
|
import org.jackhuang.hmcl.ui.FXUtils;
|
||||||
@ -204,6 +203,7 @@ public class HMCLGameRepository extends DefaultGameRepository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new version setting if version id has no version setting.
|
* Create new version setting if version id has no version setting.
|
||||||
|
*
|
||||||
* @param id the version id.
|
* @param id the version id.
|
||||||
* @return new version setting, null if given version does not exist.
|
* @return new version setting, null if given version does not exist.
|
||||||
*/
|
*/
|
||||||
@ -226,7 +226,6 @@ public class HMCLGameRepository extends DefaultGameRepository {
|
|||||||
* Get the version setting for version id.
|
* Get the version setting for version id.
|
||||||
*
|
*
|
||||||
* @param id version id
|
* @param id version id
|
||||||
*
|
|
||||||
* @return corresponding version setting, null if the version has no its own version setting.
|
* @return corresponding version setting, null if the version has no its own version setting.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -350,6 +349,7 @@ public class HMCLGameRepository extends DefaultGameRepository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Make version use self version settings instead of the global one.
|
* Make version use self version settings instead of the global one.
|
||||||
|
*
|
||||||
* @param id the version id.
|
* @param id the version id.
|
||||||
* @return specialized version setting, null if given version does not exist.
|
* @return specialized version setting, null if given version does not exist.
|
||||||
*/
|
*/
|
||||||
@ -416,8 +416,12 @@ public class HMCLGameRepository extends DefaultGameRepository {
|
|||||||
.setDaemon(!makeLaunchScript && vs.getLauncherVisibility().isDaemon())
|
.setDaemon(!makeLaunchScript && vs.getLauncherVisibility().isDaemon())
|
||||||
.setJavaAgents(javaAgents)
|
.setJavaAgents(javaAgents)
|
||||||
.setJavaArguments(javaArguments);
|
.setJavaArguments(javaArguments);
|
||||||
|
|
||||||
if (config().hasProxy()) {
|
if (config().hasProxy()) {
|
||||||
builder.setProxy(ProxyManager.getProxy());
|
builder.setProxyType(config().getProxyType());
|
||||||
|
builder.setProxyHost(config().getProxyHost());
|
||||||
|
builder.setProxyPort(config().getProxyPort());
|
||||||
|
|
||||||
if (config().hasProxyAuth()) {
|
if (config().hasProxyAuth()) {
|
||||||
builder.setProxyUser(config().getProxyUser());
|
builder.setProxyUser(config().getProxyUser());
|
||||||
builder.setProxyPass(config().getProxyPass());
|
builder.setProxyPass(config().getProxyPass());
|
||||||
|
@ -17,100 +17,118 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.setting;
|
package org.jackhuang.hmcl.setting;
|
||||||
|
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.InvalidationListener;
|
||||||
import javafx.beans.binding.ObjectBinding;
|
import org.jackhuang.hmcl.util.Lang;
|
||||||
import javafx.beans.value.ObservableObjectValue;
|
|
||||||
import org.jackhuang.hmcl.util.StringUtils;
|
import org.jackhuang.hmcl.util.StringUtils;
|
||||||
|
|
||||||
import java.net.Authenticator;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.*;
|
||||||
import java.net.PasswordAuthentication;
|
import java.util.Collections;
|
||||||
import java.net.Proxy;
|
import java.util.List;
|
||||||
import java.net.Proxy.Type;
|
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
||||||
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
||||||
|
|
||||||
public final class ProxyManager {
|
public final class ProxyManager {
|
||||||
private ProxyManager() {
|
|
||||||
|
private static final ProxySelector NO_PROXY = new SimpleProxySelector(Proxy.NO_PROXY);
|
||||||
|
private static final ProxySelector SYSTEM_DEFAULT = Lang.requireNonNullElse(ProxySelector.getDefault(), NO_PROXY);
|
||||||
|
|
||||||
|
private static ProxySelector getProxySelector() {
|
||||||
|
if (config().hasProxy()) {
|
||||||
|
Proxy.Type proxyType = config().getProxyType();
|
||||||
|
String host = config().getProxyHost();
|
||||||
|
int port = config().getProxyPort();
|
||||||
|
|
||||||
|
if (proxyType == Proxy.Type.DIRECT || StringUtils.isBlank(host)) {
|
||||||
|
return NO_PROXY;
|
||||||
|
} else if (port < 0 || port > 0xFFFF) {
|
||||||
|
LOG.warning("Illegal proxy port: " + port);
|
||||||
|
return NO_PROXY;
|
||||||
|
} else {
|
||||||
|
return new SimpleProxySelector(new Proxy(proxyType, new InetSocketAddress(host, port)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ProxyManager.SYSTEM_DEFAULT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ObjectBinding<Proxy> proxyProperty;
|
private static Authenticator getAuthenticator() {
|
||||||
|
if (config().hasProxy() && config().hasProxyAuth()) {
|
||||||
|
String username = config().getProxyUser();
|
||||||
|
String password = config().getProxyPass();
|
||||||
|
|
||||||
public static Proxy getProxy() {
|
if (username != null || password != null)
|
||||||
return proxyProperty.get();
|
return new SimpleAuthenticator(username, password.toCharArray());
|
||||||
}
|
else
|
||||||
|
return null;
|
||||||
public static ObservableObjectValue<Proxy> proxyProperty() {
|
} else
|
||||||
return proxyProperty;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
proxyProperty = Bindings.createObjectBinding(
|
ProxySelector.setDefault(getProxySelector());
|
||||||
() -> {
|
InvalidationListener updateProxySelector = observable -> ProxySelector.setDefault(getProxySelector());
|
||||||
String host = config().getProxyHost();
|
config().proxyTypeProperty().addListener(updateProxySelector);
|
||||||
int port = config().getProxyPort();
|
config().proxyHostProperty().addListener(updateProxySelector);
|
||||||
if (!config().hasProxy() || StringUtils.isBlank(host) || config().getProxyType() == Proxy.Type.DIRECT) {
|
config().proxyPortProperty().addListener(updateProxySelector);
|
||||||
return Proxy.NO_PROXY;
|
config().hasProxyProperty().addListener(updateProxySelector);
|
||||||
} else {
|
|
||||||
if (port < 0 || port > 0xFFFF) {
|
|
||||||
LOG.warning("Illegal proxy port: " + port);
|
|
||||||
return Proxy.NO_PROXY;
|
|
||||||
}
|
|
||||||
return new Proxy(config().getProxyType(), new InetSocketAddress(host, port));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
config().proxyTypeProperty(),
|
|
||||||
config().proxyHostProperty(),
|
|
||||||
config().proxyPortProperty(),
|
|
||||||
config().hasProxyProperty());
|
|
||||||
|
|
||||||
proxyProperty.addListener(any -> updateSystemProxy());
|
Authenticator.setDefault(getAuthenticator());
|
||||||
updateSystemProxy();
|
InvalidationListener updateAuthenticator = observable -> Authenticator.setDefault(getAuthenticator());
|
||||||
|
config().hasProxyProperty().addListener(updateAuthenticator);
|
||||||
|
config().hasProxyAuthProperty().addListener(updateAuthenticator);
|
||||||
|
config().proxyUserProperty().addListener(updateAuthenticator);
|
||||||
|
config().proxyPassProperty().addListener(updateAuthenticator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class SimpleProxySelector extends ProxySelector {
|
||||||
|
private final List<Proxy> proxies;
|
||||||
|
|
||||||
|
SimpleProxySelector(Proxy proxy) {
|
||||||
|
this(Collections.singletonList(proxy));
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleProxySelector(List<Proxy> proxies) {
|
||||||
|
this.proxies = proxies;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Proxy> select(URI uri) {
|
||||||
|
if (uri == null)
|
||||||
|
throw new IllegalArgumentException("URI can't be null.");
|
||||||
|
|
||||||
|
return proxies;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
|
||||||
|
if (uri == null || sa == null || ioe == null) {
|
||||||
|
throw new IllegalArgumentException("Arguments can't be null.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "SimpleProxySelector" + proxies;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class SimpleAuthenticator extends Authenticator {
|
||||||
|
private final String username;
|
||||||
|
private final char[] password;
|
||||||
|
|
||||||
|
private SimpleAuthenticator(String username, char[] password) {
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
Authenticator.setDefault(new Authenticator() {
|
|
||||||
@Override
|
@Override
|
||||||
protected PasswordAuthentication getPasswordAuthentication() {
|
protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
if (config().hasProxyAuth()) {
|
return getRequestorType() == RequestorType.PROXY ? new PasswordAuthentication(username, password) : null;
|
||||||
String username = config().getProxyUser();
|
|
||||||
String password = config().getProxyPass();
|
|
||||||
if (username != null && password != null) {
|
|
||||||
return new PasswordAuthentication(username, password.toCharArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void updateSystemProxy() {
|
private ProxyManager() {
|
||||||
Proxy proxy = proxyProperty.get();
|
|
||||||
if (proxy.type() == Proxy.Type.DIRECT) {
|
|
||||||
System.clearProperty("http.proxyHost");
|
|
||||||
System.clearProperty("http.proxyPort");
|
|
||||||
System.clearProperty("https.proxyHost");
|
|
||||||
System.clearProperty("https.proxyPort");
|
|
||||||
System.clearProperty("socksProxyHost");
|
|
||||||
System.clearProperty("socksProxyPort");
|
|
||||||
} else {
|
|
||||||
InetSocketAddress address = (InetSocketAddress) proxy.address();
|
|
||||||
String host = address.getHostString();
|
|
||||||
String port = String.valueOf(address.getPort());
|
|
||||||
if (proxy.type() == Type.HTTP) {
|
|
||||||
System.clearProperty("socksProxyHost");
|
|
||||||
System.clearProperty("socksProxyPort");
|
|
||||||
System.setProperty("http.proxyHost", host);
|
|
||||||
System.setProperty("http.proxyPort", port);
|
|
||||||
System.setProperty("https.proxyHost", host);
|
|
||||||
System.setProperty("https.proxyPort", port);
|
|
||||||
} else if (proxy.type() == Type.SOCKS) {
|
|
||||||
System.clearProperty("http.proxyHost");
|
|
||||||
System.clearProperty("http.proxyPort");
|
|
||||||
System.clearProperty("https.proxyHost");
|
|
||||||
System.clearProperty("https.proxyPort");
|
|
||||||
System.setProperty("socksProxyHost", host);
|
|
||||||
System.setProperty("socksProxyPort", port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package org.jackhuang.hmcl.ui.main;
|
package org.jackhuang.hmcl.ui.main;
|
||||||
|
|
||||||
import com.jfoenix.controls.*;
|
import com.jfoenix.controls.*;
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
@ -28,6 +29,7 @@ import javafx.scene.layout.*;
|
|||||||
import org.jackhuang.hmcl.setting.DownloadProviders;
|
import org.jackhuang.hmcl.setting.DownloadProviders;
|
||||||
import org.jackhuang.hmcl.task.FetchTask;
|
import org.jackhuang.hmcl.task.FetchTask;
|
||||||
import org.jackhuang.hmcl.ui.FXUtils;
|
import org.jackhuang.hmcl.ui.FXUtils;
|
||||||
|
import org.jackhuang.hmcl.ui.WeakListenerHolder;
|
||||||
import org.jackhuang.hmcl.ui.construct.*;
|
import org.jackhuang.hmcl.ui.construct.*;
|
||||||
import org.jackhuang.hmcl.util.javafx.SafeStringConverter;
|
import org.jackhuang.hmcl.util.javafx.SafeStringConverter;
|
||||||
|
|
||||||
@ -37,11 +39,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
||||||
import static org.jackhuang.hmcl.ui.FXUtils.stringConverter;
|
import static org.jackhuang.hmcl.ui.FXUtils.stringConverter;
|
||||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||||
import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.reversedSelectedPropertyFor;
|
|
||||||
import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.selectedItemPropertyFor;
|
import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.selectedItemPropertyFor;
|
||||||
|
|
||||||
public class DownloadSettingsPage extends StackPane {
|
public class DownloadSettingsPage extends StackPane {
|
||||||
|
|
||||||
|
private final WeakListenerHolder holder = new WeakListenerHolder();
|
||||||
|
|
||||||
public DownloadSettingsPage() {
|
public DownloadSettingsPage() {
|
||||||
VBox content = new VBox(10);
|
VBox content = new VBox(10);
|
||||||
content.setPadding(new Insets(10));
|
content.setPadding(new Insets(10));
|
||||||
@ -164,38 +167,76 @@ public class DownloadSettingsPage extends StackPane {
|
|||||||
VBox proxyList = new VBox(10);
|
VBox proxyList = new VBox(10);
|
||||||
proxyList.getStyleClass().add("card-non-transparent");
|
proxyList.getStyleClass().add("card-non-transparent");
|
||||||
|
|
||||||
VBox proxyPane = new VBox();
|
HBox proxyTypePane = new HBox();
|
||||||
{
|
{
|
||||||
JFXCheckBox chkDisableProxy = new JFXCheckBox(i18n("settings.launcher.proxy.disable"));
|
proxyTypePane.setPadding(new Insets(10, 0, 0, 0));
|
||||||
VBox.setMargin(chkDisableProxy, new Insets(8, 0, 0, 0));
|
|
||||||
proxyList.getChildren().add(chkDisableProxy);
|
ToggleGroup proxyConfigurationGroup = new ToggleGroup();
|
||||||
reversedSelectedPropertyFor(chkDisableProxy).bindBidirectional(config().hasProxyProperty());
|
|
||||||
proxyPane.disableProperty().bind(chkDisableProxy.selectedProperty());
|
JFXRadioButton chkProxyDefault = new JFXRadioButton(i18n("settings.launcher.proxy.default"));
|
||||||
|
chkProxyDefault.setUserData(null);
|
||||||
|
chkProxyDefault.setToggleGroup(proxyConfigurationGroup);
|
||||||
|
|
||||||
|
JFXRadioButton chkProxyNone = new JFXRadioButton(i18n("settings.launcher.proxy.none"));
|
||||||
|
chkProxyNone.setUserData(Proxy.Type.DIRECT);
|
||||||
|
chkProxyNone.setToggleGroup(proxyConfigurationGroup);
|
||||||
|
|
||||||
|
JFXRadioButton chkProxyHttp = new JFXRadioButton(i18n("settings.launcher.proxy.http"));
|
||||||
|
chkProxyHttp.setUserData(Proxy.Type.HTTP);
|
||||||
|
chkProxyHttp.setToggleGroup(proxyConfigurationGroup);
|
||||||
|
|
||||||
|
|
||||||
|
JFXRadioButton chkProxySocks = new JFXRadioButton(i18n("settings.launcher.proxy.socks"));
|
||||||
|
chkProxySocks.setUserData(Proxy.Type.SOCKS);
|
||||||
|
chkProxySocks.setToggleGroup(proxyConfigurationGroup);
|
||||||
|
|
||||||
|
if (config().hasProxy()) {
|
||||||
|
Proxy.Type proxyType = config().getProxyType();
|
||||||
|
if (proxyType == Proxy.Type.DIRECT) {
|
||||||
|
chkProxyNone.setSelected(true);
|
||||||
|
} else if (proxyType == Proxy.Type.HTTP) {
|
||||||
|
chkProxyHttp.setSelected(true);
|
||||||
|
} else if (proxyType == Proxy.Type.SOCKS) {
|
||||||
|
chkProxySocks.setSelected(true);
|
||||||
|
} else {
|
||||||
|
chkProxyNone.setSelected(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
chkProxyDefault.setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
holder.add(FXUtils.onWeakChange(proxyConfigurationGroup.selectedToggleProperty(), toggle -> {
|
||||||
|
Proxy.Type proxyType = toggle != null ? (Proxy.Type) toggle.getUserData() : null;
|
||||||
|
|
||||||
|
if (proxyType == null) {
|
||||||
|
config().setHasProxy(false);
|
||||||
|
config().setProxyType(null);
|
||||||
|
} else {
|
||||||
|
config().setHasProxy(true);
|
||||||
|
config().setProxyType(proxyType);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
proxyTypePane.getChildren().setAll(chkProxyDefault, chkProxyNone, chkProxyHttp, chkProxySocks);
|
||||||
|
proxyList.getChildren().add(proxyTypePane);
|
||||||
|
}
|
||||||
|
|
||||||
|
VBox proxyPane = new VBox();
|
||||||
{
|
{
|
||||||
proxyPane.setPadding(new Insets(0, 0, 0, 30));
|
proxyPane.disableProperty().bind(
|
||||||
|
Bindings.createBooleanBinding(() ->
|
||||||
|
!config().hasProxy() || config().getProxyType() == null || config().getProxyType() == Proxy.Type.DIRECT,
|
||||||
|
config().hasProxyProperty(),
|
||||||
|
config().proxyTypeProperty()));
|
||||||
|
|
||||||
ColumnConstraints colHgrow = new ColumnConstraints();
|
ColumnConstraints colHgrow = new ColumnConstraints();
|
||||||
colHgrow.setHgrow(Priority.ALWAYS);
|
colHgrow.setHgrow(Priority.ALWAYS);
|
||||||
|
|
||||||
JFXRadioButton chkProxyNone;
|
|
||||||
JFXRadioButton chkProxyHttp;
|
|
||||||
JFXRadioButton chkProxySocks;
|
|
||||||
{
|
|
||||||
HBox hBox = new HBox();
|
|
||||||
chkProxyNone = new JFXRadioButton(i18n("settings.launcher.proxy.none"));
|
|
||||||
chkProxyHttp = new JFXRadioButton(i18n("settings.launcher.proxy.http"));
|
|
||||||
chkProxySocks = new JFXRadioButton(i18n("settings.launcher.proxy.socks"));
|
|
||||||
hBox.getChildren().setAll(chkProxyNone, chkProxyHttp, chkProxySocks);
|
|
||||||
proxyPane.getChildren().add(hBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
GridPane gridPane = new GridPane();
|
GridPane gridPane = new GridPane();
|
||||||
|
gridPane.setPadding(new Insets(0, 0, 0, 30));
|
||||||
gridPane.setHgap(20);
|
gridPane.setHgap(20);
|
||||||
gridPane.setVgap(10);
|
gridPane.setVgap(10);
|
||||||
gridPane.setStyle("-fx-padding: 0 0 0 15;");
|
|
||||||
gridPane.getColumnConstraints().setAll(new ColumnConstraints(), colHgrow);
|
gridPane.getColumnConstraints().setAll(new ColumnConstraints(), colHgrow);
|
||||||
gridPane.getRowConstraints().setAll(new RowConstraints(), new RowConstraints());
|
gridPane.getRowConstraints().setAll(new RowConstraints(), new RowConstraints());
|
||||||
|
|
||||||
@ -223,6 +264,8 @@ public class DownloadSettingsPage extends StackPane {
|
|||||||
|
|
||||||
{
|
{
|
||||||
JFXTextField txtProxyPort = new JFXTextField();
|
JFXTextField txtProxyPort = new JFXTextField();
|
||||||
|
GridPane.setFillWidth(txtProxyPort, false);
|
||||||
|
txtProxyPort.setMaxWidth(200);
|
||||||
GridPane.setRowIndex(txtProxyPort, 2);
|
GridPane.setRowIndex(txtProxyPort, 2);
|
||||||
GridPane.setColumnIndex(txtProxyPort, 1);
|
GridPane.setColumnIndex(txtProxyPort, 1);
|
||||||
FXUtils.setValidateWhileTextChanged(txtProxyPort, true);
|
FXUtils.setValidateWhileTextChanged(txtProxyPort, true);
|
||||||
@ -236,25 +279,25 @@ public class DownloadSettingsPage extends StackPane {
|
|||||||
proxyPane.getChildren().add(gridPane);
|
proxyPane.getChildren().add(gridPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
GridPane authPane = new GridPane();
|
VBox chkProxyAuthenticationPane = new VBox();
|
||||||
{
|
{
|
||||||
VBox vBox = new VBox();
|
chkProxyAuthenticationPane.setPadding(new Insets(20, 0, 20, 5));
|
||||||
vBox.setStyle("-fx-padding: 20 0 20 5;");
|
|
||||||
|
|
||||||
JFXCheckBox chkProxyAuthentication = new JFXCheckBox(i18n("settings.launcher.proxy.authentication"));
|
JFXCheckBox chkProxyAuthentication = new JFXCheckBox(i18n("settings.launcher.proxy.authentication"));
|
||||||
vBox.getChildren().setAll(chkProxyAuthentication);
|
chkProxyAuthenticationPane.getChildren().add(chkProxyAuthentication);
|
||||||
authPane.disableProperty().bind(chkProxyAuthentication.selectedProperty().not());
|
|
||||||
chkProxyAuthentication.selectedProperty().bindBidirectional(config().hasProxyAuthProperty());
|
chkProxyAuthentication.selectedProperty().bindBidirectional(config().hasProxyAuthProperty());
|
||||||
|
|
||||||
proxyPane.getChildren().add(vBox);
|
proxyPane.getChildren().add(chkProxyAuthenticationPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GridPane authPane = new GridPane();
|
||||||
{
|
{
|
||||||
|
authPane.setPadding(new Insets(0, 0, 0, 30));
|
||||||
authPane.setHgap(20);
|
authPane.setHgap(20);
|
||||||
authPane.setVgap(10);
|
authPane.setVgap(10);
|
||||||
authPane.setStyle("-fx-padding: 0 0 0 15;");
|
|
||||||
authPane.getColumnConstraints().setAll(new ColumnConstraints(), colHgrow);
|
authPane.getColumnConstraints().setAll(new ColumnConstraints(), colHgrow);
|
||||||
authPane.getRowConstraints().setAll(new RowConstraints(), new RowConstraints());
|
authPane.getRowConstraints().setAll(new RowConstraints(), new RowConstraints());
|
||||||
|
authPane.disableProperty().bind(config().hasProxyAuthProperty().not());
|
||||||
|
|
||||||
{
|
{
|
||||||
Label username = new Label(i18n("settings.launcher.proxy.username"));
|
Label username = new Label(i18n("settings.launcher.proxy.username"));
|
||||||
@ -286,19 +329,10 @@ public class DownloadSettingsPage extends StackPane {
|
|||||||
txtProxyPassword.textProperty().bindBidirectional(config().proxyPassProperty());
|
txtProxyPassword.textProperty().bindBidirectional(config().proxyPassProperty());
|
||||||
}
|
}
|
||||||
|
|
||||||
ToggleGroup proxyConfigurationGroup = new ToggleGroup();
|
|
||||||
chkProxyNone.setUserData(Proxy.Type.DIRECT);
|
|
||||||
chkProxyNone.setToggleGroup(proxyConfigurationGroup);
|
|
||||||
chkProxyHttp.setUserData(Proxy.Type.HTTP);
|
|
||||||
chkProxyHttp.setToggleGroup(proxyConfigurationGroup);
|
|
||||||
chkProxySocks.setUserData(Proxy.Type.SOCKS);
|
|
||||||
chkProxySocks.setToggleGroup(proxyConfigurationGroup);
|
|
||||||
selectedItemPropertyFor(proxyConfigurationGroup, Proxy.Type.class).bindBidirectional(config().proxyTypeProperty());
|
|
||||||
|
|
||||||
proxyPane.getChildren().add(authPane);
|
proxyPane.getChildren().add(authPane);
|
||||||
}
|
|
||||||
proxyList.getChildren().add(proxyPane);
|
proxyList.getChildren().add(proxyPane);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
content.getChildren().addAll(ComponentList.createComponentListTitle(i18n("settings.launcher.proxy")), proxyList);
|
content.getChildren().addAll(ComponentList.createComponentListTitle(i18n("settings.launcher.proxy")), proxyList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1274,7 +1274,7 @@ settings.launcher.log=Logging
|
|||||||
settings.launcher.log.font=Font
|
settings.launcher.log.font=Font
|
||||||
settings.launcher.proxy=Proxy
|
settings.launcher.proxy=Proxy
|
||||||
settings.launcher.proxy.authentication=Requires Authentication
|
settings.launcher.proxy.authentication=Requires Authentication
|
||||||
settings.launcher.proxy.disable=Use System Proxy
|
settings.launcher.proxy.default=Use System Proxy
|
||||||
settings.launcher.proxy.host=Host
|
settings.launcher.proxy.host=Host
|
||||||
settings.launcher.proxy.http=HTTP
|
settings.launcher.proxy.http=HTTP
|
||||||
settings.launcher.proxy.none=No Proxy
|
settings.launcher.proxy.none=No Proxy
|
||||||
|
@ -1278,7 +1278,7 @@ settings.launcher.log=Registro
|
|||||||
settings.launcher.log.font=Fuente
|
settings.launcher.log.font=Fuente
|
||||||
settings.launcher.proxy=Proxy
|
settings.launcher.proxy=Proxy
|
||||||
settings.launcher.proxy.authentication=Requiere autenticación
|
settings.launcher.proxy.authentication=Requiere autenticación
|
||||||
settings.launcher.proxy.disable=Usar proxy del sistema
|
settings.launcher.proxy.default=Usar proxy del sistema
|
||||||
settings.launcher.proxy.host=Host
|
settings.launcher.proxy.host=Host
|
||||||
settings.launcher.proxy.http=HTTP
|
settings.launcher.proxy.http=HTTP
|
||||||
settings.launcher.proxy.none=Sin proxy
|
settings.launcher.proxy.none=Sin proxy
|
||||||
|
@ -853,7 +853,7 @@ settings.launcher.log=ログ
|
|||||||
settings.launcher.log.font=ログフォント
|
settings.launcher.log.font=ログフォント
|
||||||
settings.launcher.proxy=プロキシ
|
settings.launcher.proxy=プロキシ
|
||||||
settings.launcher.proxy.authentication=プロキシ認証
|
settings.launcher.proxy.authentication=プロキシ認証
|
||||||
settings.launcher.proxy.disable=システムプロキシを使用する
|
settings.launcher.proxy.default=システムプロキシを使用する
|
||||||
settings.launcher.proxy.host=Host
|
settings.launcher.proxy.host=Host
|
||||||
settings.launcher.proxy.http=HTTP
|
settings.launcher.proxy.http=HTTP
|
||||||
settings.launcher.proxy.none=プロキシなし
|
settings.launcher.proxy.none=プロキシなし
|
||||||
|
@ -1278,7 +1278,7 @@ settings.launcher.log=Запись логов
|
|||||||
settings.launcher.log.font=Шрифт
|
settings.launcher.log.font=Шрифт
|
||||||
settings.launcher.proxy=Прокси
|
settings.launcher.proxy=Прокси
|
||||||
settings.launcher.proxy.authentication=Требуется авторизация
|
settings.launcher.proxy.authentication=Требуется авторизация
|
||||||
settings.launcher.proxy.disable=Использовать прокси системы
|
settings.launcher.proxy.default=Использовать прокси системы
|
||||||
settings.launcher.proxy.host=Хост
|
settings.launcher.proxy.host=Хост
|
||||||
settings.launcher.proxy.http=HTTP
|
settings.launcher.proxy.http=HTTP
|
||||||
settings.launcher.proxy.none=Без прокси
|
settings.launcher.proxy.none=Без прокси
|
||||||
|
@ -1070,7 +1070,7 @@ settings.launcher.log=日誌
|
|||||||
settings.launcher.log.font=日誌字體
|
settings.launcher.log.font=日誌字體
|
||||||
settings.launcher.proxy=代理
|
settings.launcher.proxy=代理
|
||||||
settings.launcher.proxy.authentication=身份驗證
|
settings.launcher.proxy.authentication=身份驗證
|
||||||
settings.launcher.proxy.disable=使用系統代理
|
settings.launcher.proxy.default=使用系統代理
|
||||||
settings.launcher.proxy.host=IP 位址
|
settings.launcher.proxy.host=IP 位址
|
||||||
settings.launcher.proxy.http=HTTP
|
settings.launcher.proxy.http=HTTP
|
||||||
settings.launcher.proxy.none=不使用代理
|
settings.launcher.proxy.none=不使用代理
|
||||||
|
@ -1080,7 +1080,7 @@ settings.launcher.log=日志
|
|||||||
settings.launcher.log.font=日志字体
|
settings.launcher.log.font=日志字体
|
||||||
settings.launcher.proxy=代理
|
settings.launcher.proxy=代理
|
||||||
settings.launcher.proxy.authentication=身份验证
|
settings.launcher.proxy.authentication=身份验证
|
||||||
settings.launcher.proxy.disable=使用系统代理
|
settings.launcher.proxy.default=使用系统代理
|
||||||
settings.launcher.proxy.host=主机
|
settings.launcher.proxy.host=主机
|
||||||
settings.launcher.proxy.http=HTTP
|
settings.launcher.proxy.http=HTTP
|
||||||
settings.launcher.proxy.none=不使用代理
|
settings.launcher.proxy.none=不使用代理
|
||||||
|
@ -49,7 +49,9 @@ public class LaunchOptions implements Serializable {
|
|||||||
private boolean fullscreen;
|
private boolean fullscreen;
|
||||||
private String serverIp;
|
private String serverIp;
|
||||||
private String wrapper;
|
private String wrapper;
|
||||||
private Proxy proxy;
|
private Proxy.Type proxyType;
|
||||||
|
private String proxyHost;
|
||||||
|
private int proxyPort;
|
||||||
private String proxyUser;
|
private String proxyUser;
|
||||||
private String proxyPass;
|
private String proxyPass;
|
||||||
private boolean noGeneratedJVMArgs;
|
private boolean noGeneratedJVMArgs;
|
||||||
@ -191,11 +193,16 @@ public class LaunchOptions implements Serializable {
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Proxy.Type getProxyType() {
|
||||||
* Proxy settings
|
return proxyType;
|
||||||
*/
|
}
|
||||||
public Proxy getProxy() {
|
|
||||||
return proxy;
|
public String getProxyHost() {
|
||||||
|
return proxyHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProxyPort() {
|
||||||
|
return proxyPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -402,8 +409,18 @@ public class LaunchOptions implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setProxy(Proxy proxy) {
|
public Builder setProxyType(Proxy.Type proxyType) {
|
||||||
options.proxy = proxy;
|
options.proxyType = proxyType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setProxyHost(String proxyHost) {
|
||||||
|
options.proxyHost = proxyHost;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setProxyPort(int proxyPort) {
|
||||||
|
options.proxyPort = proxyPort;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ import org.jackhuang.hmcl.util.platform.*;
|
|||||||
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
|
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -111,24 +110,6 @@ public class DefaultLauncher extends Launcher {
|
|||||||
|
|
||||||
res.addAllWithoutParsing(options.getOverrideJavaArguments());
|
res.addAllWithoutParsing(options.getOverrideJavaArguments());
|
||||||
|
|
||||||
Proxy proxy = options.getProxy();
|
|
||||||
if (proxy != null && StringUtils.isBlank(options.getProxyUser()) && StringUtils.isBlank(options.getProxyPass())) {
|
|
||||||
InetSocketAddress address = (InetSocketAddress) options.getProxy().address();
|
|
||||||
if (address != null) {
|
|
||||||
String host = address.getHostString();
|
|
||||||
int port = address.getPort();
|
|
||||||
if (proxy.type() == Proxy.Type.HTTP) {
|
|
||||||
res.addDefault("-Dhttp.proxyHost=", host);
|
|
||||||
res.addDefault("-Dhttp.proxyPort=", String.valueOf(port));
|
|
||||||
res.addDefault("-Dhttps.proxyHost=", host);
|
|
||||||
res.addDefault("-Dhttps.proxyPort=", String.valueOf(port));
|
|
||||||
} else if (proxy.type() == Proxy.Type.SOCKS) {
|
|
||||||
res.addDefault("-DsocksProxyHost=", host);
|
|
||||||
res.addDefault("-DsocksProxyPort=", String.valueOf(port));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.getMaxMemory() != null && options.getMaxMemory() > 0)
|
if (options.getMaxMemory() != null && options.getMaxMemory() > 0)
|
||||||
res.addDefault("-Xmx", options.getMaxMemory() + "m");
|
res.addDefault("-Xmx", options.getMaxMemory() + "m");
|
||||||
|
|
||||||
@ -189,6 +170,26 @@ public class DefaultLauncher extends Launcher {
|
|||||||
if (OperatingSystem.CURRENT_OS != OperatingSystem.WINDOWS)
|
if (OperatingSystem.CURRENT_OS != OperatingSystem.WINDOWS)
|
||||||
res.addDefault("-Duser.home=", options.getGameDir().getParent());
|
res.addDefault("-Duser.home=", options.getGameDir().getParent());
|
||||||
|
|
||||||
|
Proxy.Type proxyType = options.getProxyType();
|
||||||
|
if (proxyType == null) {
|
||||||
|
res.addDefault("-Djava.net.useSystemProxies", "true");
|
||||||
|
} else {
|
||||||
|
String proxyHost = options.getProxyHost();
|
||||||
|
int proxyPort = options.getProxyPort();
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(proxyHost) && proxyPort >= 0 && proxyPort <= 0xFFFF) {
|
||||||
|
if (proxyType == Proxy.Type.HTTP) {
|
||||||
|
res.addDefault("-Dhttp.proxyHost=", proxyHost);
|
||||||
|
res.addDefault("-Dhttp.proxyPort=", String.valueOf(proxyPort));
|
||||||
|
res.addDefault("-Dhttps.proxyHost=", proxyHost);
|
||||||
|
res.addDefault("-Dhttps.proxyPort=", String.valueOf(proxyPort));
|
||||||
|
} else if (proxyType == Proxy.Type.SOCKS) {
|
||||||
|
res.addDefault("-DsocksProxyHost=", proxyHost);
|
||||||
|
res.addDefault("-DsocksProxyPort=", String.valueOf(proxyPort));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final int javaVersion = options.getJava().getParsedVersion();
|
final int javaVersion = options.getJava().getParsedVersion();
|
||||||
final boolean is64bit = options.getJava().getBits() == Bits.BIT_64;
|
final boolean is64bit = options.getJava().getBits() == Bits.BIT_64;
|
||||||
|
|
||||||
@ -309,13 +310,15 @@ public class DefaultLauncher extends Launcher {
|
|||||||
if (options.isFullscreen())
|
if (options.isFullscreen())
|
||||||
res.add("--fullscreen");
|
res.add("--fullscreen");
|
||||||
|
|
||||||
if (options.getProxy() != null && options.getProxy().type() == Proxy.Type.SOCKS) {
|
if (options.getProxyType() == Proxy.Type.SOCKS) {
|
||||||
InetSocketAddress address = (InetSocketAddress) options.getProxy().address();
|
String proxyHost = options.getProxyHost();
|
||||||
if (address != null) {
|
int proxyPort = options.getProxyPort();
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(proxyHost) && proxyPort >= 0 && proxyPort <= 0xFFFF) {
|
||||||
res.add("--proxyHost");
|
res.add("--proxyHost");
|
||||||
res.add(address.getHostString());
|
res.add(proxyHost);
|
||||||
res.add("--proxyPort");
|
res.add("--proxyPort");
|
||||||
res.add(String.valueOf(address.getPort()));
|
res.add(String.valueOf(proxyPort));
|
||||||
if (StringUtils.isNotBlank(options.getProxyUser()) && StringUtils.isNotBlank(options.getProxyPass())) {
|
if (StringUtils.isNotBlank(options.getProxyUser()) && StringUtils.isNotBlank(options.getProxyPass())) {
|
||||||
res.add("--proxyUser");
|
res.add("--proxyUser");
|
||||||
res.add(options.getProxyUser());
|
res.add(options.getProxyUser());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user