add: friendly prompt of corrupt forge installer

This commit is contained in:
huanghongxun
2020-02-03 12:09:06 +08:00
parent 9849b5659b
commit 25e4fa3834
8 changed files with 38 additions and 5 deletions

View File

@@ -0,0 +1,14 @@
package org.jackhuang.hmcl.download;
import java.io.IOException;
public class ArtifactMalformedException extends IOException {
public ArtifactMalformedException(String message) {
super(message);
}
public ArtifactMalformedException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -17,6 +17,7 @@
*/
package org.jackhuang.hmcl.download.forge;
import org.jackhuang.hmcl.download.ArtifactMalformedException;
import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.download.LibraryAnalyzer;
import org.jackhuang.hmcl.download.game.GameLibrariesTask;
@@ -54,7 +55,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.zip.ZipException;
import static org.jackhuang.hmcl.util.DigestUtils.digest;
import static org.jackhuang.hmcl.util.Hex.encodeHex;
@@ -176,7 +177,7 @@ public class ForgeNewInstallTask extends Task<Version> {
value = parseLiteral(value, data, ExceptionalFunction.identity());
if (key == null || value == null) {
throw new Exception("Invalid forge installation configuration");
throw new ArtifactMalformedException("Invalid forge installation configuration");
}
outputs.put(key, value);
@@ -235,7 +236,7 @@ public class ForgeNewInstallTask extends Task<Version> {
for (String arg : processor.getArgs()) {
String parsed = parseLiteral(arg, data, ExceptionalFunction.identity());
if (parsed == null)
throw new IOException("Invalid forge installation configuration");
throw new ArtifactMalformedException("Invalid forge installation configuration");
args.add(parsed);
}
@@ -264,6 +265,8 @@ public class ForgeNewInstallTask extends Task<Version> {
updateProgress(++finished, processors.size());
}
} catch (ZipException ex) {
throw new ArtifactMalformedException("Malformed forge installer file", ex);
}
setResult(forgeVersion

View File

@@ -17,6 +17,7 @@
*/
package org.jackhuang.hmcl.download.forge;
import org.jackhuang.hmcl.download.ArtifactMalformedException;
import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.download.LibraryAnalyzer;
import org.jackhuang.hmcl.game.Library;
@@ -35,6 +36,7 @@ import java.nio.file.Path;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
public class ForgeOldInstallTask extends Task<Version> {
@@ -69,7 +71,7 @@ public class ForgeOldInstallTask extends Task<Version> {
try (ZipFile zipFile = new ZipFile(installer.toFile())) {
InputStream stream = zipFile.getInputStream(zipFile.getEntry("install_profile.json"));
if (stream == null)
throw new IOException("Malformed forge installer file, install_profile.json does not exist.");
throw new ArtifactMalformedException("Malformed forge installer file, install_profile.json does not exist.");
String json = IOUtils.readFullyAsString(stream);
ForgeInstallProfile installProfile = JsonUtils.fromNonNullJson(json, ForgeInstallProfile.class);
@@ -89,6 +91,8 @@ public class ForgeOldInstallTask extends Task<Version> {
.setId(LibraryAnalyzer.LibraryType.FORGE.getPatchId())
.setVersion(selfVersion));
dependencies.add(dependencyManager.checkLibraryCompletionAsync(installProfile.getVersionInfo()));
} catch (ZipException ex) {
throw new ArtifactMalformedException("Malformed forge installer file", ex);
}
}
}

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hmcl.download.game;
import org.jackhuang.hmcl.download.AbstractDependencyManager;
import org.jackhuang.hmcl.download.ArtifactMalformedException;
import org.jackhuang.hmcl.download.DefaultCacheRepository;
import org.jackhuang.hmcl.game.Library;
import org.jackhuang.hmcl.task.DownloadException;
@@ -220,7 +221,12 @@ public class LibraryDownloadTask extends Task<Void> {
if (!dest.delete())
throw new IOException("Unable to delete file " + dest);
byte[] decompressed = IOUtils.readFullyAsByteArray(new XZInputStream(new ByteArrayInputStream(src)));
byte[] decompressed;
try {
decompressed = IOUtils.readFullyAsByteArray(new XZInputStream(new ByteArrayInputStream(src)));
} catch (IOException e) {
throw new ArtifactMalformedException("Library " + dest + " is malformed");
}
String end = new String(decompressed, decompressed.length - 4, 4);
if (!end.equals("SIGN"))