Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
040dceb9ed |
+18
@@ -25,6 +25,7 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
||||
|
||||
@@ -37,6 +38,8 @@ public final class MojangJavaDownloadTask extends Task<MojangJavaDownloadTask.Re
|
||||
private final Path tempDir;
|
||||
private final Task<MojangJavaRemoteFiles> javaDownloadsTask;
|
||||
private final List<Task<?>> dependencies = new ArrayList<>();
|
||||
private final AtomicInteger completedFiles = new AtomicInteger();
|
||||
private volatile int totalFiles;
|
||||
|
||||
private volatile MojangJavaDownloads.JavaDownload download;
|
||||
|
||||
@@ -147,6 +150,21 @@ public final class MojangJavaDownloadTask extends Task<MojangJavaDownloadTask.Re
|
||||
Files.createSymbolicLink(dest, Paths.get(link.getTarget()));
|
||||
}
|
||||
}
|
||||
|
||||
// Report per-file progress so the bar advances through the download, LZMA decompress and
|
||||
// cache-copy phases; otherwise it stays indeterminate while files appear on disk and players
|
||||
// assume the install is frozen. The callbacks run after each file completes and never touch
|
||||
// the download/decompress logic above.
|
||||
totalFiles = dependencies.size();
|
||||
if (totalFiles > 0) {
|
||||
List<Task<?>> tracked = new ArrayList<>(totalFiles);
|
||||
for (Task<?> dependency : dependencies) {
|
||||
tracked.add(dependency.thenRunAsync(() -> updateProgress(completedFiles.incrementAndGet(), totalFiles)));
|
||||
}
|
||||
dependencies.clear();
|
||||
dependencies.addAll(tracked);
|
||||
updateProgress(0, totalFiles);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user