From 19cae84a01b23115808f2386df2bb19631eee7f0 Mon Sep 17 00:00:00 2001 From: Glavo Date: Wed, 31 Jan 2024 01:56:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BB=8E=E5=80=99=E9=80=89?= =?UTF-8?q?=E6=BA=90=E8=8E=B7=E5=8F=96=20AuthlibInjectorVersionInfo=20(#27?= =?UTF-8?q?11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 尝试从候选源获取 AuthlibInjectorVersionInfo * update * update * update --- .../AuthlibInjectorDownloader.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorDownloader.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorDownloader.java index 551e0d630..315c82840 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorDownloader.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorDownloader.java @@ -110,11 +110,22 @@ public class AuthlibInjectorDownloader implements AuthlibInjectorArtifactProvide } private AuthlibInjectorVersionInfo getLatestArtifactInfo() throws IOException { - try { - return HttpRequest.GET(downloadProvider.get().injectURL(LATEST_BUILD_URL)).getJson(AuthlibInjectorVersionInfo.class); - } catch (JsonParseException e) { - throw new IOException("Malformed response", e); + IOException exception = null; + for (URL url : downloadProvider.get().injectURLWithCandidates(LATEST_BUILD_URL)) { + try { + return HttpRequest.GET(url.toExternalForm()).getJson(AuthlibInjectorVersionInfo.class); + } catch (IOException | JsonParseException e) { + if (exception == null) { + exception = new IOException("Failed to fetch authlib-injector artifact info"); + } + exception.addSuppressed(e); + } } + + if (exception == null) { + exception = new IOException("No authlib-injector download providers available"); + } + throw exception; } private Optional getLocalArtifact() { @@ -133,7 +144,7 @@ public class AuthlibInjectorDownloader implements AuthlibInjectorArtifactProvide } } - private static class AuthlibInjectorVersionInfo { + private static final class AuthlibInjectorVersionInfo { @SerializedName("build_number") public int buildNumber;