fix(download): we can check hash of fabric-api jar.
This commit is contained in:
@@ -20,13 +20,11 @@ package org.jackhuang.hmcl.download.fabric;
|
||||
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||
import org.jackhuang.hmcl.task.GetTask;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -37,7 +35,6 @@ import java.util.List;
|
||||
*/
|
||||
public final class FabricAPIInstallTask extends Task<Version> {
|
||||
|
||||
private GetTask dependent;
|
||||
private final DefaultDependencyManager dependencyManager;
|
||||
private final Version version;
|
||||
private final FabricAPIRemoteVersion remote;
|
||||
@@ -47,22 +44,6 @@ public final class FabricAPIInstallTask extends Task<Version> {
|
||||
this.dependencyManager = dependencyManager;
|
||||
this.version = version;
|
||||
this.remote = remoteVersion;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPreExecute() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preExecute() throws Exception {
|
||||
this.dependent = new GetTask(new URL(remote.getUrls().get(0) + ".sha1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Task<?>> getDependents() {
|
||||
return Collections.singleton(dependent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,9 +59,9 @@ public final class FabricAPIInstallTask extends Task<Version> {
|
||||
@Override
|
||||
public void execute() throws IOException {
|
||||
dependencies.add(new FileDownloadTask(
|
||||
new URL(remote.getUrls().get(0)),
|
||||
dependencyManager.getGameRepository().getRunDirectory(version.getId()).toPath().resolve("mods").resolve("fabric-api-" + remote.getFullVersion() + ".jar").toFile(),
|
||||
new FileDownloadTask.IntegrityCheck("SHA-1", dependent.getResult().trim()))
|
||||
new URL(remote.getVersion().getFile().getUrl()),
|
||||
dependencyManager.getGameRepository().getRunDirectory(version.getId()).toPath().resolve("mods").resolve("fabric-api-" + remote.getVersion().getVersion() + ".jar").toFile(),
|
||||
remote.getVersion().getFile().getIntegrityCheck())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jackhuang.hmcl.download.fabric;
|
||||
|
||||
import org.jackhuang.hmcl.download.*;
|
||||
import org.jackhuang.hmcl.game.Version;
|
||||
import org.jackhuang.hmcl.mod.RemoteMod;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
|
||||
import java.time.Instant;
|
||||
@@ -26,6 +27,7 @@ import java.util.List;
|
||||
|
||||
public class FabricAPIRemoteVersion extends RemoteVersion {
|
||||
private final String fullVersion;
|
||||
private final RemoteMod.Version version;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -34,10 +36,11 @@ public class FabricAPIRemoteVersion extends RemoteVersion {
|
||||
* @param selfVersion the version string of the remote version.
|
||||
* @param urls the installer or universal jar original URL.
|
||||
*/
|
||||
FabricAPIRemoteVersion(String gameVersion, String selfVersion, String fullVersion, Instant datePublished, List<String> urls) {
|
||||
FabricAPIRemoteVersion(String gameVersion, String selfVersion, String fullVersion, Instant datePublished, RemoteMod.Version version, List<String> urls) {
|
||||
super(LibraryAnalyzer.LibraryType.FABRIC_API.getPatchId(), gameVersion, selfVersion, datePublished, urls);
|
||||
|
||||
this.fullVersion = fullVersion;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,6 +48,10 @@ public class FabricAPIRemoteVersion extends RemoteVersion {
|
||||
return fullVersion;
|
||||
}
|
||||
|
||||
public RemoteMod.Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task<Version> getInstallTask(DefaultDependencyManager dependencyManager, Version baseVersion) {
|
||||
return new FabricAPIInstallTask(dependencyManager, baseVersion, this);
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.jackhuang.hmcl.download.fabric;
|
||||
import org.jackhuang.hmcl.download.DownloadProvider;
|
||||
import org.jackhuang.hmcl.download.VersionList;
|
||||
import org.jackhuang.hmcl.mod.RemoteMod;
|
||||
import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository;
|
||||
import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository;
|
||||
import org.jackhuang.hmcl.util.Lang;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -47,9 +47,9 @@ public class FabricAPIVersionList extends VersionList<FabricAPIRemoteVersion> {
|
||||
@Override
|
||||
public CompletableFuture<?> refreshAsync() {
|
||||
return CompletableFuture.runAsync(wrap(() -> {
|
||||
for (RemoteMod.Version modVersion : Lang.toIterable(CurseForgeRemoteModRepository.MODS.getRemoteVersionsById("306612"))) {
|
||||
for (RemoteMod.Version modVersion : Lang.toIterable(ModrinthRemoteModRepository.INSTANCE.getRemoteVersionsById("P7dR8mSH"))) {
|
||||
for (String gameVersion : modVersion.getGameVersions()) {
|
||||
versions.put(gameVersion, new FabricAPIRemoteVersion(gameVersion, modVersion.getName(), modVersion.getName(), modVersion.getDatePublished(),
|
||||
versions.put(gameVersion, new FabricAPIRemoteVersion(gameVersion, modVersion.getVersion(), modVersion.getName(), modVersion.getDatePublished(), modVersion,
|
||||
Collections.singletonList(modVersion.getFile().getUrl())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.mod;
|
||||
|
||||
import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
@@ -184,6 +186,18 @@ public class RemoteMod {
|
||||
return hashes;
|
||||
}
|
||||
|
||||
public FileDownloadTask.IntegrityCheck getIntegrityCheck() {
|
||||
if (hashes.containsKey("md5")) {
|
||||
return new FileDownloadTask.IntegrityCheck("MD5", hashes.get("sha1"));
|
||||
} else if (hashes.containsKey("sha1")) {
|
||||
return new FileDownloadTask.IntegrityCheck("SHA-1", hashes.get("sha1"));
|
||||
} else if (hashes.containsKey("sha512")) {
|
||||
return new FileDownloadTask.IntegrityCheck("SHA-256", hashes.get("sha1"));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user