Remove proxy from AccountHelper

This commit is contained in:
yushijinhun 2018-07-18 16:32:11 +08:00
parent 06806bd383
commit fe87a899c8
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
2 changed files with 12 additions and 29 deletions

View File

@ -24,7 +24,6 @@ import org.jackhuang.hmcl.auth.Account;
import org.jackhuang.hmcl.auth.yggdrasil.GameProfile; import org.jackhuang.hmcl.auth.yggdrasil.GameProfile;
import org.jackhuang.hmcl.auth.yggdrasil.Texture; import org.jackhuang.hmcl.auth.yggdrasil.Texture;
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount; import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
import org.jackhuang.hmcl.setting.ProxyManager;
import org.jackhuang.hmcl.setting.Settings; import org.jackhuang.hmcl.setting.Settings;
import org.jackhuang.hmcl.task.FileDownloadTask; import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.task.Scheduler; import org.jackhuang.hmcl.task.Scheduler;
@ -34,7 +33,6 @@ import org.jackhuang.hmcl.ui.DialogController;
import org.jackhuang.hmcl.util.NetworkUtils; import org.jackhuang.hmcl.util.NetworkUtils;
import java.io.File; import java.io.File;
import java.net.Proxy;
import java.util.*; import java.util.*;
public final class AccountHelper { public final class AccountHelper {
@ -44,31 +42,19 @@ public final class AccountHelper {
public static final File SKIN_DIR = new File(Launcher.HMCL_DIRECTORY, "skins"); public static final File SKIN_DIR = new File(Launcher.HMCL_DIRECTORY, "skins");
public static void loadSkins() { public static void loadSkins() {
loadSkins(Proxy.NO_PROXY);
}
public static void loadSkins(Proxy proxy) {
for (Account account : Settings.INSTANCE.getAccounts()) { for (Account account : Settings.INSTANCE.getAccounts()) {
if (account instanceof YggdrasilAccount) { if (account instanceof YggdrasilAccount) {
new SkinLoadTask((YggdrasilAccount) account, proxy, false).start(); new SkinLoadTask((YggdrasilAccount) account, false).start();
} }
} }
} }
public static Task loadSkinAsync(YggdrasilAccount account) { public static Task loadSkinAsync(YggdrasilAccount account) {
return loadSkinAsync(account, ProxyManager.getProxy()); return new SkinLoadTask(account, false);
}
public static Task loadSkinAsync(YggdrasilAccount account, Proxy proxy) {
return new SkinLoadTask(account, proxy, false);
} }
public static Task refreshSkinAsync(YggdrasilAccount account) { public static Task refreshSkinAsync(YggdrasilAccount account) {
return refreshSkinAsync(account, ProxyManager.getProxy()); return new SkinLoadTask(account, true);
}
public static Task refreshSkinAsync(YggdrasilAccount account, Proxy proxy) {
return new SkinLoadTask(account, proxy, true);
} }
private static File getSkinFile(UUID uuid) { private static File getSkinFile(UUID uuid) {
@ -95,9 +81,9 @@ public final class AccountHelper {
return getDefaultSkin(uuid, scaleRatio); return getDefaultSkin(uuid, scaleRatio);
} }
public static Image getSkinImmediately(YggdrasilAccount account, GameProfile profile, double scaleRatio, Proxy proxy) throws Exception { public static Image getSkinImmediately(YggdrasilAccount account, GameProfile profile, double scaleRatio) throws Exception {
File file = getSkinFile(profile.getId()); File file = getSkinFile(profile.getId());
downloadSkin(account, profile, true, proxy); downloadSkin(account, profile, true);
if (!file.exists()) if (!file.exists())
return getDefaultSkin(profile.getId(), scaleRatio); return getDefaultSkin(profile.getId(), scaleRatio);
@ -112,17 +98,15 @@ public final class AccountHelper {
private static class SkinLoadTask extends Task { private static class SkinLoadTask extends Task {
private final YggdrasilAccount account; private final YggdrasilAccount account;
private final Proxy proxy;
private final boolean refresh; private final boolean refresh;
private final List<Task> dependencies = new LinkedList<>(); private final List<Task> dependencies = new LinkedList<>();
public SkinLoadTask(YggdrasilAccount account, Proxy proxy) { public SkinLoadTask(YggdrasilAccount account) {
this(account, proxy, false); this(account, false);
} }
public SkinLoadTask(YggdrasilAccount account, Proxy proxy, boolean refresh) { public SkinLoadTask(YggdrasilAccount account, boolean refresh) {
this.account = account; this.account = account;
this.proxy = proxy;
this.refresh = refresh; this.refresh = refresh;
} }
@ -141,11 +125,11 @@ public final class AccountHelper {
if (!account.isLoggedIn() && (account.getCharacter() == null || refresh)) if (!account.isLoggedIn() && (account.getCharacter() == null || refresh))
DialogController.logIn(account); DialogController.logIn(account);
downloadSkin(account, refresh, proxy); downloadSkin(account, refresh);
} }
} }
private static void downloadSkin(YggdrasilAccount account, GameProfile profile, boolean refresh, Proxy proxy) throws Exception { private static void downloadSkin(YggdrasilAccount account, GameProfile profile, boolean refresh) throws Exception {
account.clearCache(); account.clearCache();
Optional<Texture> texture = account.getSkin(profile); Optional<Texture> texture = account.getSkin(profile);
@ -157,7 +141,7 @@ public final class AccountHelper {
new FileDownloadTask(NetworkUtils.toURL(url), file).run(); new FileDownloadTask(NetworkUtils.toURL(url), file).run();
} }
private static void downloadSkin(YggdrasilAccount account, boolean refresh, Proxy proxy) throws Exception { private static void downloadSkin(YggdrasilAccount account, boolean refresh) throws Exception {
account.clearCache(); account.clearCache();
if (account.getCharacter() == null) return; if (account.getCharacter() == null) return;

View File

@ -41,7 +41,6 @@ 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.ProxyManager;
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;
@ -212,7 +211,7 @@ public class AddAccountPane extends StackPane {
for (GameProfile profile : names) { for (GameProfile profile : names) {
Image image; Image image;
try { try {
image = AccountHelper.getSkinImmediately(yggdrasilAccount, profile, 4, ProxyManager.getProxy()); image = AccountHelper.getSkinImmediately(yggdrasilAccount, profile, 4);
} catch (Exception e) { } catch (Exception e) {
Logging.LOG.log(Level.WARNING, "Failed to get skin for " + profile.getName(), e); Logging.LOG.log(Level.WARNING, "Failed to get skin for " + profile.getName(), e);
image = null; image = null;