Change type from ExceptionalSupplier to AuthlibInjectorDownloader

This commit is contained in:
yushijinhun 2018-11-23 17:46:59 +08:00
parent 875b0c27ef
commit a4e4782f2f
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
4 changed files with 15 additions and 13 deletions

View File

@ -62,7 +62,7 @@ public final class Accounts {
public static final OfflineAccountFactory FACTORY_OFFLINE = OfflineAccountFactory.INSTANCE;
public static final YggdrasilAccountFactory FACTORY_YGGDRASIL = new YggdrasilAccountFactory(MojangYggdrasilProvider.INSTANCE);
public static final AuthlibInjectorAccountFactory FACTORY_AUTHLIB_INJECTOR = new AuthlibInjectorAccountFactory(
new AuthlibInjectorDownloader(Metadata.HMCL_DIRECTORY, DownloadProviders::getDownloadProvider)::getArtifactInfo,
new AuthlibInjectorDownloader(Metadata.HMCL_DIRECTORY, DownloadProviders::getDownloadProvider),
Accounts::getOrCreateAuthlibInjectorServer);
// ==== login type / account factory mapping ====

View File

@ -33,16 +33,17 @@ import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import static org.jackhuang.hmcl.util.io.IOUtils.readFullyWithoutClosing;
public class AuthlibInjectorAccount extends YggdrasilAccount {
private AuthlibInjectorServer server;
private ExceptionalSupplier<AuthlibInjectorArtifactInfo, ? extends IOException> authlibInjectorDownloader;
private AuthlibInjectorDownloader downloader;
protected AuthlibInjectorAccount(YggdrasilService service, AuthlibInjectorServer server, ExceptionalSupplier<AuthlibInjectorArtifactInfo, ? extends IOException> authlibInjectorDownloader, String username, UUID characterUUID, YggdrasilSession session) {
protected AuthlibInjectorAccount(YggdrasilService service, AuthlibInjectorServer server, AuthlibInjectorDownloader downloader, String username, UUID characterUUID, YggdrasilSession session) {
super(service, username, characterUUID, session);
this.authlibInjectorDownloader = authlibInjectorDownloader;
this.downloader = downloader;
this.server = server;
}
@ -67,7 +68,7 @@ public class AuthlibInjectorAccount extends YggdrasilAccount {
CompletableFuture<AuthlibInjectorArtifactInfo> artifactTask = CompletableFuture.supplyAsync(() -> {
try {
return authlibInjectorDownloader.get();
return downloader.getArtifactInfo();
} catch (IOException e) {
throw new CompletionException(new AuthlibInjectorDownloadException(e));
}

View File

@ -22,9 +22,6 @@ import org.jackhuang.hmcl.auth.AuthenticationException;
import org.jackhuang.hmcl.auth.CharacterSelector;
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilService;
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilSession;
import org.jackhuang.hmcl.util.function.ExceptionalSupplier;
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
@ -32,14 +29,14 @@ import java.util.function.Function;
import static org.jackhuang.hmcl.util.Lang.tryCast;
public class AuthlibInjectorAccountFactory extends AccountFactory<AuthlibInjectorAccount> {
private ExceptionalSupplier<AuthlibInjectorArtifactInfo, ? extends IOException> authlibInjectorDownloader;
private AuthlibInjectorDownloader downloader;
private Function<String, AuthlibInjectorServer> serverLookup;
/**
* @param serverLookup a function that looks up {@link AuthlibInjectorServer} by url
*/
public AuthlibInjectorAccountFactory(ExceptionalSupplier<AuthlibInjectorArtifactInfo, ? extends IOException> authlibInjectorDownloader, Function<String, AuthlibInjectorServer> serverLookup) {
this.authlibInjectorDownloader = authlibInjectorDownloader;
public AuthlibInjectorAccountFactory(AuthlibInjectorDownloader downloader, Function<String, AuthlibInjectorServer> serverLookup) {
this.downloader = downloader;
this.serverLookup = serverLookup;
}
@ -52,7 +49,7 @@ public class AuthlibInjectorAccountFactory extends AccountFactory<AuthlibInjecto
AuthlibInjectorServer server = (AuthlibInjectorServer) additionalData;
AuthlibInjectorAccount account = new AuthlibInjectorAccount(new YggdrasilService(new AuthlibInjectorProvider(server.getUrl())),
server, authlibInjectorDownloader, username, null, null);
server, downloader, username, null, null);
account.logInWithPassword(password, selector);
return account;
}
@ -71,6 +68,6 @@ public class AuthlibInjectorAccountFactory extends AccountFactory<AuthlibInjecto
AuthlibInjectorServer server = serverLookup.apply(apiRoot);
return new AuthlibInjectorAccount(new YggdrasilService(new AuthlibInjectorProvider(server.getUrl())),
server, authlibInjectorDownloader, username, session.getSelectedProfile().getId(), session);
server, downloader, username, session.getSelectedProfile().getId(), session);
}
}

View File

@ -79,6 +79,10 @@ public class AuthlibInjectorDownloader {
}
}
public Optional<AuthlibInjectorArtifactInfo> getArtifactInfoImmediately() {
return getLocalArtifact();
}
private void update(Optional<AuthlibInjectorArtifactInfo> local) throws IOException {
LOG.info("Checking update of authlib-injector");
AuthlibInjectorVersionInfo latest = getLatestArtifactInfo();