Friendly prompt that it cannot download some libraries successfully.

This commit is contained in:
huangyuhui
2018-07-22 18:50:44 +08:00
parent 247f02d423
commit e31120be21
8 changed files with 63 additions and 9 deletions

View File

@@ -0,0 +1,34 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2017 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.download.game;
import org.jackhuang.hmcl.game.Library;
public class LibraryDownloadException extends Exception {
private final Library library;
public LibraryDownloadException(Library library, Throwable cause) {
super("Unable to download library " + library, cause);
this.library = library;
}
public Library getLibrary() {
return library;
}
}

View File

@@ -55,7 +55,7 @@ public final class LibraryDownloadTask extends Task {
@Override
public Collection<? extends Task> getDependents() {
return library.getChecksums() != null ? Collections.singleton(xzTask) : Collections.emptySet();
return library.getChecksums() != null ? Collections.singleton(xzTask) : Collections.singleton(task);
}
@Override
@@ -65,20 +65,23 @@ public final class LibraryDownloadTask extends Task {
@Override
public void execute() throws Exception {
if (isDependentsSucceeded() && library.getChecksums() != null) {
if (!isDependentsSucceeded()) {
// Since FileDownloadTask wraps the actual exception with another IOException.
// We should extract it letting the error message clearer.
Throwable t = library.getChecksums() != null ? xzTask.getLastException() : task.getLastException();
if (t.getCause() != null && t.getCause() != t)
throw new LibraryDownloadException(library, t.getCause());
else
throw new LibraryDownloadException(library, t);
}
if (library.getChecksums() != null) {
unpackLibrary(jar, FileUtils.readBytes(xzFile));
if (!checksumValid(jar, library.getChecksums()))
throw new IOException("Checksum failed for " + library);
downloaded = true;
}
}
@Override
public Collection<? extends Task> getDependencies() {
return downloaded ? Collections.emptySet() : Collections.singleton(task);
}
private static boolean checksumValid(File libPath, List<String> checksums) {
try {
if ((checksums == null) || (checksums.isEmpty())) {

View File

@@ -63,6 +63,16 @@ public abstract class Task {
this.state = state;
}
private Throwable lastException = null;
public Throwable getLastException() {
return lastException;
}
void setLastException(Throwable e) {
lastException = e;
}
/**
* The scheduler that decides how this task runs.
*/

View File

@@ -190,6 +190,7 @@ public final class TaskExecutor {
} catch (SilentException | RejectedExecutionException e) {
// do nothing
} catch (Exception e) {
task.setLastException(e);
lastException = e;
variables.set(LAST_EXCEPTION_ID, e);
if (task.getSignificance().shouldLog()) {