Add progress of installing and game downloading
This commit is contained in:
@@ -19,8 +19,12 @@ package org.jackhuang.hmcl.core.download;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import org.jackhuang.hmcl.util.C;
|
||||
import org.jackhuang.hmcl.util.net.HTTPGetTask;
|
||||
import org.jackhuang.hmcl.util.net.NetUtils;
|
||||
import org.jackhuang.hmcl.util.task.Task;
|
||||
import org.jackhuang.hmcl.util.task.TaskWorker;
|
||||
|
||||
/**
|
||||
@@ -57,15 +61,23 @@ public class MinecraftRemoteVersions {
|
||||
|
||||
public static class RemoteVersionsTask extends TaskWorker<MinecraftRemoteVersion> {
|
||||
|
||||
HTTPGetTask task;
|
||||
@Override
|
||||
public Collection<Task> getDependTasks() {
|
||||
return Arrays.asList(task);
|
||||
}
|
||||
|
||||
DownloadType type;
|
||||
|
||||
public RemoteVersionsTask(DownloadType type) {
|
||||
this.type = type;
|
||||
this.task = new HTTPGetTask(type.getProvider().getVersionsListDownloadURL());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean b) throws Exception {
|
||||
MinecraftRemoteVersions r = C.GSON.fromJson(NetUtils.get(type.getProvider().getVersionsListDownloadURL()), MinecraftRemoteVersions.class);
|
||||
if (!b) throw new IllegalStateException("Previous http get task failed");
|
||||
MinecraftRemoteVersions r = C.GSON.fromJson(task.getResult(), MinecraftRemoteVersions.class);
|
||||
if (r != null && r.versions != null) {
|
||||
INSTANCE = r;
|
||||
send(r.versions.toArray(new MinecraftRemoteVersion[r.versions.size()]));
|
||||
|
||||
@@ -55,4 +55,11 @@ public class DoubleTask extends TaskInfo {
|
||||
throw new IllegalStateException("Depend tasks failed.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task setProgressProviderListener(ProgressProviderListener p) {
|
||||
a.setProgressProviderListener(p);
|
||||
b.setProgressProviderListener(p);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Collection;
|
||||
import org.jackhuang.hmcl.util.AbstractSwingWorker;
|
||||
|
||||
/**
|
||||
*
|
||||
* Create a new instance when you use a task anyway.
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public abstract class Task {
|
||||
@@ -111,13 +111,19 @@ public abstract class Task {
|
||||
public void runWithException() throws Exception {
|
||||
Collection<Task> c = getDependTasks();
|
||||
if (c != null)
|
||||
for (Task t : c)
|
||||
for (Task t : c) {
|
||||
if (t.ppl == null)
|
||||
t.setProgressProviderListener(this.ppl);
|
||||
t.runWithException();
|
||||
}
|
||||
executeTask(true);
|
||||
c = getAfterTasks();
|
||||
if (c != null)
|
||||
for (Task t : c)
|
||||
for (Task t : c) {
|
||||
if (t.ppl == null)
|
||||
t.setProgressProviderListener(this.ppl);
|
||||
t.runWithException();
|
||||
}
|
||||
}
|
||||
|
||||
public void runAsync() {
|
||||
|
||||
Reference in New Issue
Block a user