InstallerPanel: show loading in the table instead of showing a task window
This commit is contained in:
@@ -61,7 +61,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
if (!areDependTasksSucceeded)
|
||||
throw new IllegalStateException("Failed to get asset index");
|
||||
String result = FileUtils.read(f);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) {
|
||||
if (areDependTasksSucceeded) {
|
||||
if (renamedFinal != null && !renamedFinal.delete())
|
||||
HMCLog.warn("Failed to delete " + renamedFinal + ", maybe you should do it.");
|
||||
|
||||
@@ -75,7 +75,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
File vpath = new File(service.baseDirectory(), "versions/" + id);
|
||||
if (!areDependTasksSucceeded) {
|
||||
FileUtils.deleteDirectory(vpath);
|
||||
@@ -131,7 +131,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
||||
public Task downloadMinecraftVersionJson(String id) {
|
||||
return new TaskInfo("Download Minecraft Json") {
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
List<MinecraftRemoteVersion> versions = MinecraftRemoteVersions.getRemoteVersions(service.getDownloadType()).justDo();
|
||||
MinecraftRemoteVersion currentVersion = null;
|
||||
for (MinecraftRemoteVersion v : versions)
|
||||
|
||||
@@ -61,7 +61,7 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
if (!areDependTasksSucceeded)
|
||||
return;
|
||||
String s = task.getResult();
|
||||
|
||||
@@ -61,7 +61,7 @@ public class LiteLoaderVersionList extends InstallerVersionList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
if (!areDependTasksSucceeded)
|
||||
return;
|
||||
String s = task.getResult();
|
||||
|
||||
@@ -65,7 +65,7 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
String s = task.getResult();
|
||||
|
||||
versionMap = new HashMap<>();
|
||||
|
||||
@@ -73,7 +73,7 @@ public class OptiFineVersionList extends InstallerVersionList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
if (!areDependTasksSucceeded)
|
||||
return;
|
||||
String content = task.getResult();
|
||||
|
||||
@@ -86,7 +86,7 @@ public final class ModpackManager {
|
||||
Collection<Task> c = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
String id = idFUCK;
|
||||
String description = C.i18n("modpack.task.install.will");
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.util.task;
|
||||
|
||||
import java.util.Collection;
|
||||
import org.jackhuang.hmcl.util.AbstractSwingWorker;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -27,7 +28,7 @@ public abstract class Task {
|
||||
|
||||
/**
|
||||
* Run in a new thread(packed in TaskList).
|
||||
*
|
||||
*
|
||||
* @param areDependTasksSucceeded Would be true if all of tasks which this task depends on have succeed.
|
||||
* @throws java.lang.Throwable If a task throws an exception, this task will be marked as `failed`.
|
||||
*/
|
||||
@@ -49,9 +50,9 @@ public abstract class Task {
|
||||
public boolean isAborted() {
|
||||
return aborted;
|
||||
}
|
||||
|
||||
|
||||
protected boolean hidden = false;
|
||||
|
||||
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
@@ -63,9 +64,10 @@ public abstract class Task {
|
||||
|
||||
/**
|
||||
* This method can be only invoked by TaskList.
|
||||
*
|
||||
* @param s what the `executeTask` throws.
|
||||
*/
|
||||
protected void setFailReason(Throwable s) {
|
||||
protected void setFailReason(Exception s) {
|
||||
failReason = s;
|
||||
}
|
||||
|
||||
@@ -73,12 +75,13 @@ public abstract class Task {
|
||||
|
||||
/**
|
||||
* For FileDownloadTask: info replacement.
|
||||
* @return
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
public Task setTag(String tag) {
|
||||
this.tag = tag;
|
||||
return this;
|
||||
@@ -105,7 +108,7 @@ public abstract class Task {
|
||||
return new DoubleTask(this, t);
|
||||
}
|
||||
|
||||
public void runWithException() throws Throwable {
|
||||
public void runWithException() throws Exception {
|
||||
Collection<Task> c = getDependTasks();
|
||||
if (c != null)
|
||||
for (Task t : c)
|
||||
@@ -116,4 +119,13 @@ public abstract class Task {
|
||||
for (Task t : c)
|
||||
t.runWithException();
|
||||
}
|
||||
|
||||
public void runAsync() {
|
||||
new AbstractSwingWorker<Void>() {
|
||||
@Override
|
||||
protected void work() throws Exception {
|
||||
runWithException();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class TaskList extends Thread {
|
||||
boolean flag = true;
|
||||
try {
|
||||
t.executeTask(areDependTasksSucceeded);
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
t.setFailReason(e);
|
||||
flag = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* 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 {http://www.gnu.org/licenses/}.
|
||||
*/
|
||||
package org.jackhuang.hmcl.util.task;
|
||||
|
||||
import java.util.List;
|
||||
import org.jackhuang.hmcl.api.func.Consumer;
|
||||
import org.jackhuang.hmcl.util.AbstractSwingWorker;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huang
|
||||
*/
|
||||
public abstract class TaskWorker<T> extends Task {
|
||||
|
||||
protected final AbstractSwingWorker<T> worker;
|
||||
|
||||
public TaskWorker() {
|
||||
worker = new AbstractSwingWorker<T>() {
|
||||
@Override
|
||||
protected void work() throws Exception {
|
||||
runWithException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public TaskWorker<T> reg(Consumer<T> c) {
|
||||
worker.reg(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskWorker<T> regDone(Runnable c) {
|
||||
worker.regDone(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void send(T... result) {
|
||||
worker.send(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return "TaskWorker";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsync() {
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
public List<T> justDo() throws Exception {
|
||||
return worker.justDo();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user