修复启动游戏补全文件时,任务没有正确归类的问题 (#5430)
Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
@@ -249,11 +249,11 @@ public final class LauncherHelper {
|
||||
i18n("message.doing"),
|
||||
() -> launchingLatch.getCount() == 0, 6.95
|
||||
).withStage("launch.state.waiting_launching"))
|
||||
.withStagesHint(Lang.immutableListOf(
|
||||
"launch.state.java",
|
||||
"launch.state.dependencies",
|
||||
"launch.state.logging_in",
|
||||
"launch.state.waiting_launching"))
|
||||
.withStagesHints(
|
||||
new Task.StagesHint("launch.state.java"),
|
||||
new Task.StagesHint("launch.state.dependencies", List.of("hmcl.install.assets", "hmcl.install.libraries", "hmcl.modpack.download")),
|
||||
new Task.StagesHint("launch.state.logging_in"),
|
||||
new Task.StagesHint("launch.state.waiting_launching"))
|
||||
.executor();
|
||||
launchingStepsPane.setExecutor(executor, false);
|
||||
executor.addTaskListener(new TaskListener() {
|
||||
|
||||
@@ -167,7 +167,7 @@ public final class ModpackHelper {
|
||||
|
||||
return new ServerModpackRemoteInstallTask(profile.getDependency(), manifest, name)
|
||||
.whenComplete(Schedulers.defaultScheduler(), success, failure)
|
||||
.withStagesHint(Arrays.asList("hmcl.modpack", "hmcl.modpack.download"));
|
||||
.withStagesHints("hmcl.modpack", "hmcl.modpack.download");
|
||||
}
|
||||
|
||||
public static boolean isExternalGameNameConflicts(String name) {
|
||||
@@ -211,16 +211,16 @@ public final class ModpackHelper {
|
||||
return modpack.getInstallTask(profile.getDependency(), zipFile, name, iconUrl)
|
||||
.whenComplete(Schedulers.defaultScheduler(), success, failure)
|
||||
.thenComposeAsync(createMultiMCPostInstallTask(profile, (MultiMCInstanceConfiguration) modpack.getManifest(), name))
|
||||
.withStagesHint(List.of("hmcl.modpack", "hmcl.modpack.download"));
|
||||
.withStagesHints("hmcl.modpack", "hmcl.modpack.download");
|
||||
else if (modpack.getManifest() instanceof McbbsModpackManifest)
|
||||
return modpack.getInstallTask(profile.getDependency(), zipFile, name, iconUrl)
|
||||
.whenComplete(Schedulers.defaultScheduler(), success, failure)
|
||||
.thenComposeAsync(createMcbbsPostInstallTask(profile, (McbbsModpackManifest) modpack.getManifest(), name))
|
||||
.withStagesHint(List.of("hmcl.modpack", "hmcl.modpack.download"));
|
||||
.withStagesHints("hmcl.modpack", "hmcl.modpack.download");
|
||||
else
|
||||
return modpack.getInstallTask(profile.getDependency(), zipFile, name, iconUrl)
|
||||
.whenComplete(Schedulers.javafx(), success, failure)
|
||||
.withStagesHint(List.of("hmcl.modpack", "hmcl.modpack.download"));
|
||||
.withStagesHints("hmcl.modpack", "hmcl.modpack.download");
|
||||
}
|
||||
|
||||
public static Task<Void> getUpdateTask(Profile profile, ServerModpackManifest manifest, Charset charset, String name, ModpackConfiguration<?> configuration) throws UnsupportedModpackException {
|
||||
@@ -228,7 +228,7 @@ public final class ModpackHelper {
|
||||
case ServerModpackRemoteInstallTask.MODPACK_TYPE:
|
||||
return new ModpackUpdateTask(profile.getRepository(), name, new ServerModpackRemoteInstallTask(profile.getDependency(), manifest, name))
|
||||
.thenComposeAsync(profile.getRepository().refreshVersionsAsync())
|
||||
.withStagesHint(Arrays.asList("hmcl.modpack", "hmcl.modpack.download"));
|
||||
.withStagesHints("hmcl.modpack", "hmcl.modpack.download");
|
||||
default:
|
||||
throw new UnsupportedModpackException();
|
||||
}
|
||||
|
||||
@@ -106,13 +106,18 @@ public final class TaskListPane extends StackPane {
|
||||
}
|
||||
|
||||
@FXThread
|
||||
private void addStages(@NotNull Collection<String> stages) {
|
||||
for (String stage : stages) {
|
||||
stageNodes.computeIfAbsent(stage, s -> {
|
||||
StageNode node = new StageNode(stage);
|
||||
private void addStagesHints(@NotNull Collection<Task.StagesHint> hints) {
|
||||
for (Task.StagesHint hint : hints) {
|
||||
StageNode node = stageNodes.get(hint.stage());
|
||||
|
||||
if (node == null) {
|
||||
node = new StageNode(hint.stage());
|
||||
stageNodes.put(hint.stage(), node);
|
||||
listView.getItems().add(node);
|
||||
return node;
|
||||
});
|
||||
}
|
||||
for (String stage : hint.aliases()) {
|
||||
stageNodes.put(stage, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +134,7 @@ public final class TaskListPane extends StackPane {
|
||||
Platform.runLater(() -> {
|
||||
stageNodes.clear();
|
||||
listView.getItems().clear();
|
||||
addStages(executor.getStages());
|
||||
addStagesHints(executor.getHints());
|
||||
updateProgressNodePadding();
|
||||
});
|
||||
}
|
||||
@@ -138,7 +143,7 @@ public final class TaskListPane extends StackPane {
|
||||
public void onReady(Task<?> task) {
|
||||
if (task instanceof Task.StagesHintTask) {
|
||||
Platform.runLater(() -> {
|
||||
addStages(((Task<?>.StagesHintTask) task).getStages());
|
||||
addStagesHints(((Task<?>.StagesHintTask) task).getHints());
|
||||
updateProgressNodePadding();
|
||||
});
|
||||
}
|
||||
@@ -394,6 +399,8 @@ public final class TaskListPane extends StackPane {
|
||||
}
|
||||
|
||||
private static final class StageNode extends Node {
|
||||
private int runningTasksCount = 0;
|
||||
|
||||
private enum Status {
|
||||
WAITING(SVG.MORE_HORIZ),
|
||||
RUNNING(SVG.ARROW_FORWARD),
|
||||
@@ -454,17 +461,23 @@ public final class TaskListPane extends StackPane {
|
||||
}
|
||||
|
||||
private void begin() {
|
||||
if (status.get() == Status.WAITING) {
|
||||
runningTasksCount++;
|
||||
if (status.get() == Status.WAITING || status.get() == Status.SUCCESS) {
|
||||
status.set(Status.RUNNING);
|
||||
}
|
||||
}
|
||||
|
||||
public void fail() {
|
||||
status.set(Status.FAILED);
|
||||
public void succeed() {
|
||||
runningTasksCount = Math.max(0, runningTasksCount - 1);
|
||||
|
||||
if (runningTasksCount == 0) {
|
||||
status.set(Status.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
public void succeed() {
|
||||
status.set(Status.SUCCESS);
|
||||
public void fail() {
|
||||
runningTasksCount = Math.max(0, runningTasksCount - 1);
|
||||
status.set(Status.FAILED);
|
||||
}
|
||||
|
||||
public void count() {
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
@@ -78,21 +77,21 @@ public final class UpdateInstallerWizardProvider implements WizardProvider {
|
||||
// We remove library but not save it,
|
||||
// so if installation failed will not break down current version.
|
||||
Task<Version> ret = Task.supplyAsync(() -> version);
|
||||
List<String> stages = new ArrayList<>();
|
||||
var hints = new ArrayList<Task.StagesHint>();
|
||||
for (Object value : settings.asStringMap().values()) {
|
||||
if (value instanceof RemoteVersion remoteVersion) {
|
||||
ret = ret.thenComposeAsync(version -> dependencyManager.installLibraryAsync(version, remoteVersion));
|
||||
stages.add(String.format("hmcl.install.%s:%s", remoteVersion.getLibraryId(), remoteVersion.getSelfVersion()));
|
||||
hints.add(new Task.StagesHint(String.format("hmcl.install.%s:%s", remoteVersion.getLibraryId(), remoteVersion.getSelfVersion())));
|
||||
if ("game".equals(remoteVersion.getLibraryId())) {
|
||||
stages.add("hmcl.install.libraries");
|
||||
stages.add("hmcl.install.assets");
|
||||
hints.add(new Task.StagesHint("hmcl.install.libraries"));
|
||||
hints.add(new Task.StagesHint("hmcl.install.assets"));
|
||||
}
|
||||
} else if (value instanceof RemoveVersionAction removeVersionAction) {
|
||||
ret = ret.thenComposeAsync(version -> dependencyManager.removeLibraryAsync(version, removeVersionAction.libraryId));
|
||||
}
|
||||
}
|
||||
|
||||
return ret.thenComposeAsync(profile.getRepository()::saveAsync).thenComposeAsync(profile.getRepository().refreshVersionsAsync()).withStagesHint(stages);
|
||||
return ret.thenComposeAsync(profile.getRepository()::saveAsync).thenComposeAsync(profile.getRepository().refreshVersionsAsync()).withStagesHints(hints);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -252,7 +252,7 @@ public final class ModListPage extends ListPageBase<ModListPageSkin.ModInfoObjec
|
||||
Controllers.navigateForward(new ModUpdatesPage(modManager, result));
|
||||
}
|
||||
})
|
||||
.withStagesHint(Collections.singletonList("update.checking")),
|
||||
.withStagesHints("update.checking"),
|
||||
i18n("mods.check_updates"), TaskCancellationAction.NORMAL);
|
||||
|
||||
if (profile.getRepository().isModpack(instanceId)) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.util.function.ExceptionalFunction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -43,28 +42,28 @@ public class DefaultGameBuilder extends GameBuilder {
|
||||
|
||||
@Override
|
||||
public Task<?> buildAsync() {
|
||||
List<String> stages = new ArrayList<>();
|
||||
var hints = new ArrayList<Task.StagesHint>();
|
||||
|
||||
Task<Version> libraryTask = Task.supplyAsync(() -> new Version(name));
|
||||
libraryTask = libraryTask.thenComposeAsync(libraryTaskHelper(gameVersion, "game", gameVersion));
|
||||
stages.add("hmcl.install.game:" + gameVersion);
|
||||
stages.add("hmcl.install.libraries");
|
||||
stages.add("hmcl.install.assets");
|
||||
hints.add(new Task.StagesHint("hmcl.install.game:" + gameVersion));
|
||||
hints.add(new Task.StagesHint("hmcl.install.libraries"));
|
||||
hints.add(new Task.StagesHint("hmcl.install.assets"));
|
||||
|
||||
for (Map.Entry<String, String> entry : toolVersions.entrySet()) {
|
||||
libraryTask = libraryTask.thenComposeAsync(libraryTaskHelper(gameVersion, entry.getKey(), entry.getValue()));
|
||||
stages.add(String.format("hmcl.install.%s:%s", entry.getKey(), entry.getValue()));
|
||||
hints.add(new Task.StagesHint(String.format("hmcl.install.%s:%s", entry.getKey(), entry.getValue())));
|
||||
}
|
||||
|
||||
for (RemoteVersion remoteVersion : remoteVersions) {
|
||||
libraryTask = libraryTask.thenComposeAsync(version -> dependencyManager.installLibraryAsync(version, remoteVersion));
|
||||
stages.add(String.format("hmcl.install.%s:%s", remoteVersion.getLibraryId(), remoteVersion.getSelfVersion()));
|
||||
hints.add(new Task.StagesHint(String.format("hmcl.install.%s:%s", remoteVersion.getLibraryId(), remoteVersion.getSelfVersion())));
|
||||
}
|
||||
|
||||
return libraryTask.thenComposeAsync(dependencyManager.getGameRepository()::saveAsync).whenComplete(exception -> {
|
||||
if (exception != null)
|
||||
dependencyManager.getGameRepository().removeVersionFromDisk(name);
|
||||
}).withStagesHint(stages);
|
||||
}).withStagesHints(hints);
|
||||
}
|
||||
|
||||
private ExceptionalFunction<Version, Task<Version>, ?> libraryTaskHelper(String gameVersion, String libraryId, String libraryVersion) {
|
||||
|
||||
@@ -871,15 +871,29 @@ public abstract class Task<T> {
|
||||
return new FakeProgressTask(done, k).setExecutor(Schedulers.defaultScheduler()).setName(name).setSignificance(TaskSignificance.MAJOR);
|
||||
}
|
||||
|
||||
public Task<T> withStagesHint(List<String> stages) {
|
||||
return new StagesHintTask(stages);
|
||||
public record StagesHint(String stage, List<String> aliases) {
|
||||
public StagesHint(String stage) {
|
||||
this(stage, List.of());
|
||||
}
|
||||
}
|
||||
|
||||
public Task<T> withStagesHints(String... hints) {
|
||||
return withStagesHints(Arrays.stream(hints).map(StagesHint::new).toList());
|
||||
}
|
||||
|
||||
public Task<T> withStagesHints(StagesHint... hints) {
|
||||
return new StagesHintTask(List.of(hints));
|
||||
}
|
||||
|
||||
public Task<T> withStagesHints(List<StagesHint> hints) {
|
||||
return new StagesHintTask(hints);
|
||||
}
|
||||
|
||||
public class StagesHintTask extends Task<T> {
|
||||
private final List<String> stages;
|
||||
private final List<StagesHint> hints;
|
||||
|
||||
public StagesHintTask(List<String> stages) {
|
||||
this.stages = stages;
|
||||
public StagesHintTask(List<StagesHint> hints) {
|
||||
this.hints = hints;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -892,8 +906,8 @@ public abstract class Task<T> {
|
||||
setResult(Task.this.getResult());
|
||||
}
|
||||
|
||||
public List<String> getStages() {
|
||||
return stages;
|
||||
public List<StagesHint> getHints() {
|
||||
return hints;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,13 @@ public abstract class TaskExecutor {
|
||||
protected final List<TaskListener> taskListeners = new ArrayList<>(0);
|
||||
protected volatile boolean cancelled = false;
|
||||
protected Exception exception;
|
||||
private final List<String> stages;
|
||||
private final List<Task.StagesHint> hints;
|
||||
|
||||
public TaskExecutor(Task<?> task) {
|
||||
this.firstTask = task;
|
||||
this.stages = task instanceof Task<?>.StagesHintTask hintTask ? hintTask.getStages() : Collections.emptyList();
|
||||
this.hints = task instanceof Task<?>.StagesHintTask hintTask
|
||||
? hintTask.getHints()
|
||||
: List.of();
|
||||
}
|
||||
|
||||
public void addTaskListener(TaskListener taskListener) {
|
||||
@@ -59,7 +61,7 @@ public abstract class TaskExecutor {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public List<String> getStages() {
|
||||
return stages;
|
||||
public List<Task.StagesHint> getHints() {
|
||||
return hints;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user