From d8a397a76fe494dd908a78211f5e5064537f695c Mon Sep 17 00:00:00 2001 From: Glavo Date: Fri, 20 Feb 2026 21:08:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20MultipleSourceVersionL?= =?UTF-8?q?ist=20=E4=B8=8D=E4=BC=9A=E4=BD=BF=E7=94=A8=E5=A4=87=E7=94=A8?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=BA=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../download/MultipleSourceVersionList.java | 58 +++++++++++++++---- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MultipleSourceVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MultipleSourceVersionList.java index 4a77cc5136..c4b0fbb4a3 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MultipleSourceVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MultipleSourceVersionList.java @@ -20,6 +20,8 @@ import org.jackhuang.hmcl.task.Task; import java.util.Arrays; +import java.util.Collection; +import java.util.List; import static org.jackhuang.hmcl.util.logging.Logger.LOG; @@ -47,25 +49,57 @@ public Task refreshAsync() { private Task refreshAsync(String gameVersion, int sourceIndex) { VersionList versionList = backends[sourceIndex]; - return versionList.refreshAsync(gameVersion) - .thenComposeAsync(() -> { + Task refreshTask = versionList.refreshAsync(gameVersion); + + return new Task() { + private Task nextTask = null; + + { + setSignificance(TaskSignificance.MODERATE); + setName("MultipleSourceVersionList.refreshAsync(" + sourceIndex + ")"); + } + + @Override + public Collection> getDependents() { + return List.of(refreshTask); + } + + @Override + public Collection> getDependencies() { + return nextTask != null ? List.of(nextTask) : List.of(); + } + + @Override + public boolean isRelyingOnDependents() { + return false; + } + + @Override + public void execute() throws Exception { + if (isDependentsSucceeded()) { lock.writeLock().lock(); try { versions.putAll(gameVersion, versionList.getVersions(gameVersion)); - } catch (Exception e) { - if (sourceIndex == backends.length - 1) { - LOG.warning("Failed to fetch versions list from all sources", e); - throw e; - } else { - LOG.warning("Failed to fetch versions list and try to fetch from other source", e); - return refreshAsync(gameVersion, sourceIndex + 1); - } } finally { lock.writeLock().unlock(); } - return null; - }); + setResult(refreshTask.getResult()); + } else { + Exception exception = refreshTask.getException(); + assert exception != null; + + if (sourceIndex == backends.length - 1) { + LOG.warning("Failed to fetch versions list from all sources", exception); + setSignificance(TaskSignificance.MINOR); + throw exception; + } else { + LOG.warning("Failed to fetch versions list and try to fetch from other source", exception); + nextTask = refreshAsync(gameVersion, sourceIndex + 1); + } + } + } + }; } @Override From 285adda171b9403d2228158aa391adb277a0b5c1 Mon Sep 17 00:00:00 2001 From: Glavo Date: Fri, 20 Feb 2026 21:43:16 +0800 Subject: [PATCH 2/2] update --- .../org/jackhuang/hmcl/download/MultipleSourceVersionList.java | 1 + 1 file changed, 1 insertion(+) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MultipleSourceVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MultipleSourceVersionList.java index c4b0fbb4a3..4f2676c502 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MultipleSourceVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MultipleSourceVersionList.java @@ -96,6 +96,7 @@ public void execute() throws Exception { } else { LOG.warning("Failed to fetch versions list and try to fetch from other source", exception); nextTask = refreshAsync(gameVersion, sourceIndex + 1); + nextTask.storeTo(this::setResult); } } }