add: show stages of game installation

This commit is contained in:
huanghongxun
2020-02-19 16:51:05 +08:00
parent 1ea9170b2e
commit c26579bebd
21 changed files with 218 additions and 50 deletions

View File

@@ -102,7 +102,8 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
VersionList<?> versionList = getVersionList(libraryId);
return versionList.loadAsync(gameVersion)
.thenComposeAsync(() -> installLibraryAsync(baseVersion, versionList.getVersion(gameVersion, libraryVersion)
.orElseThrow(() -> new IOException("Remote library " + libraryId + " has no version " + libraryVersion))));
.orElseThrow(() -> new IOException("Remote library " + libraryId + " has no version " + libraryVersion))))
.withStage("hmcl.install." + libraryId);
}
@Override
@@ -112,11 +113,7 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
return removeLibraryAsync(baseVersion.resolvePreservingPatches(repository), libraryVersion.getLibraryId())
.thenComposeAsync(version -> libraryVersion.getInstallTask(this, version))
.thenApplyAsync(baseVersion::addPatch)
.thenComposeAsync(repository::save);
}
public ExceptionalFunction<Version, Task<Version>, ?> installLibraryAsync(RemoteVersion libraryVersion) {
return version -> installLibraryAsync(version, libraryVersion);
.thenComposeAsync(repository::save).withStage("hmcl.install." + libraryVersion.getLibraryId());
}
public Task<Version> installLibraryAsync(Version oldVersion, Path installer) {

View File

@@ -54,7 +54,7 @@ public class DefaultGameBuilder extends GameBuilder {
libraryTask = libraryTask.thenComposeAsync(libraryTaskHelper(gameVersion, entry.getKey(), entry.getValue()));
for (RemoteVersion remoteVersion : remoteVersions)
libraryTask = libraryTask.thenComposeAsync(dependencyManager.installLibraryAsync(remoteVersion));
libraryTask = libraryTask.thenComposeAsync(version -> dependencyManager.installLibraryAsync(version, remoteVersion));
return libraryTask.whenComplete(exception -> {
if (exception != null)

View File

@@ -73,7 +73,7 @@ public class GameInstallTask extends Task<Version> {
.thenComposeAsync(Task.allOf(
new GameAssetDownloadTask(dependencyManager, version, GameAssetDownloadTask.DOWNLOAD_INDEX_FORCIBLY),
new GameLibrariesTask(dependencyManager, version)
).withComposeAsync(gameRepository.save(version))));
).withStage("hmcl.install.assets").withComposeAsync(gameRepository.save(version))));
}
}

View File

@@ -133,8 +133,8 @@ public final class CurseInstallTask extends Task<Void> {
File root = repository.getVersionRoot(name);
FileUtils.writeText(new File(root, "manifest.json"), JsonUtils.GSON.toJson(manifest));
dependencies.add(new CurseCompletionTask(dependencyManager, name, manifest));
dependencies.add(new MinecraftInstanceTask<>(zipFile, modpack.getEncoding(), manifest.getOverrides(), manifest, MODPACK_TYPE, repository.getModpackConfiguration(name)));
dependencies.add(new CurseCompletionTask(dependencyManager, name, manifest).withStage("hmcl.modpack.download"));
dependencies.add(new MinecraftInstanceTask<>(zipFile, modpack.getEncoding(), manifest.getOverrides(), manifest, MODPACK_TYPE, repository.getModpackConfiguration(name)).withStage("hmcl.modpack.unzip"));
}
public static final String MODPACK_TYPE = "Curse";

View File

@@ -30,6 +30,7 @@ public abstract class TaskExecutor {
protected final AtomicInteger totTask = new AtomicInteger(0);
protected final AtomicBoolean cancelled = new AtomicBoolean(false);
protected Exception exception;
private TaskStages stages = TaskStages.EMPTY;
public TaskExecutor(Task<?> task) {
this.firstTask = task;
@@ -64,4 +65,12 @@ public abstract class TaskExecutor {
public int getRunningTasks() {
return totTask.get();
}
public TaskStages getStages() {
return stages;
}
public void setStages(TaskStages stages) {
this.stages = stages;
}
}

View File

@@ -0,0 +1,43 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.task;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TaskStages {
public static final TaskStages EMPTY = new TaskStages();
private final List<String> stages = new ArrayList<>();
private final Map<String, String> localization = new HashMap<>();
protected void addStage(String stage, String localizedMessage) {
stages.add(stage);
localization.put(stage, localizedMessage);
}
public List<String> getStages() {
return stages;
}
public String localize(String stage) {
return localization.get(stage);
}
}