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

@ -18,6 +18,7 @@
package org.jackhuang.hmcl.ui.download;
import javafx.scene.Node;
import org.jackhuang.hmcl.download.ArtifactMalformedException;
import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.download.RemoteVersion;
@ -121,6 +122,8 @@ public final class InstallerWizardProvider implements WizardProvider {
Controllers.dialog(i18n("install.failed.optifine_conflict"), i18n("install.failed"), MessageType.ERROR, next);
} else if (exception instanceof DefaultDependencyManager.UnsupportedLibraryInstallerException) {
Controllers.dialog(i18n("install.failed.install_online"), i18n("install.failed"), MessageType.ERROR, next);
} else if (exception instanceof ArtifactMalformedException) {
Controllers.dialog(i18n("install.failed.malformed"), i18n("install.failed"), MessageType.ERROR, next);
} else if (exception instanceof VersionMismatchException) {
VersionMismatchException e = ((VersionMismatchException) exception);
Controllers.dialog(i18n("install.failed.version_mismatch", e.getExpect(), e.getActual()), i18n("install.failed"), MessageType.ERROR, next);

View File

@ -134,6 +134,7 @@ install.failed.downloading=Failed to install due to some files not downloaded su
install.failed.downloading.detail=Failed to download file: %s
install.failed.downloading.timeout=Timed out while downloading the file: %s
install.failed.install_online=Unable to recognize the provided installer file
install.failed.malformed=The files just downloaded a moment ago is malformed. You may switch to other download provider to resolve this problem.
install.failed.optifine_conflict=Fabric, OptiFine and Forge are installed simultaneously on Minecraft 1.13
install.failed.version_mismatch=The library requires the game version %s, but the actual version is %s.
install.installer.choose=Choose a %s version

View File

@ -133,6 +133,7 @@ install.failed.downloading=安裝失敗,部分文件未能完成下載
install.failed.downloading.detail=未能下載檔案:%s
install.failed.downloading.timeout=下載超時:%s
install.failed.install_online=無法識別要安裝的軟體
install.failed.malformed=剛才下載的檔案格式損壞。您可以切換到其他下載源來解決此問題。
install.failed.optifine_conflict=暫不支持 OptiFine 與 Forge 同時安裝在 Minecraft 1.13 上
install.failed.version_mismatch=該軟體需要的遊戲版本為 %s但實際的遊戲版本為 %s。
install.installer.choose=選擇 %s 版本

View File

@ -133,6 +133,7 @@ install.failed.downloading=安装失败,部分文件未能完成下载
install.failed.downloading.detail=未能下载文件:%s
install.failed.downloading.timeout=下载超时:%s
install.failed.install_online=无法识别要安装的软件
install.failed.malformed=刚才下载的文件格式损坏。您可以切换到其他下载源来解决此问题。
install.failed.optifine_conflict=暂不支持 OptiFine, Fabric 与 Forge 同时安装在 Minecraft 1.13 及以上版本
install.failed.version_mismatch=该软件需要的游戏版本为 %s但实际的游戏版本为 %s。
install.installer.choose=选择 %s 版本

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"))