diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseCompletionTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseCompletionTask.java index d80075bb7..988e04d32 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseCompletionTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseCompletionTask.java @@ -54,6 +54,10 @@ public final class CurseCompletionTask extends Task { private CurseManifest manifest; private final List> dependencies = new LinkedList<>(); + private final AtomicBoolean allNameKnown = new AtomicBoolean(true); + private final AtomicInteger finished = new AtomicInteger(0); + private final AtomicBoolean notFound = new AtomicBoolean(false); + /** * Constructor. * @@ -93,6 +97,11 @@ public final class CurseCompletionTask extends Task { return dependencies; } + @Override + public boolean isRelyingOnDependencies() { + return false; + } + @Override public void execute() throws Exception { if (manifest == null) @@ -100,10 +109,6 @@ public final class CurseCompletionTask extends Task { File root = repository.getVersionRoot(version); - AtomicBoolean flag = new AtomicBoolean(true); - AtomicInteger finished = new AtomicInteger(0); - AtomicBoolean notFound = new AtomicBoolean(false); - // Because in China, Curse is too difficult to visit, // if failed, ignore it and retry next time. CurseManifest newManifest = manifest.setFiles( @@ -132,7 +137,7 @@ public final class CurseCompletionTask extends Task { } catch (IOException ioe) { Logging.LOG.log(Level.WARNING, "Unable to fetch the file name of URL: " + file.getUrl(), ioe); - flag.set(false); + allNameKnown.set(false); return file; } } else @@ -149,16 +154,20 @@ public final class CurseCompletionTask extends Task { .setCaching(true)); } } - - // Let this task fail if the curse manifest has not been completed. - // But continue other downloads. - if (!flag.get() || notFound.get()) - dependencies.add(Task.runAsync(() -> { - if (notFound.get()) - throw new CurseCompletionException(new FileNotFoundException()); - else - throw new CurseCompletionException(); - })); } + @Override + public boolean doPostExecute() { + return true; + } + + @Override + public void postExecute() throws Exception { + // Let this task fail if the curse manifest has not been completed. + // But continue other downloads. + if (notFound.get()) + throw new CurseCompletionException(new FileNotFoundException()); + if (!allNameKnown.get() || !isDependenciesSucceeded()) + throw new CurseCompletionException(); + } }