feat: Mod dependencies & Mod downloads should be classified.
This commit is contained in:
@@ -28,6 +28,7 @@ public final class DownloadManager {
|
||||
}
|
||||
|
||||
public interface IMod {
|
||||
List<Mod> loadDependencies() throws IOException;
|
||||
Stream<Version> loadVersions() throws IOException;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,10 @@ import org.jackhuang.hmcl.util.Immutable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -159,6 +161,19 @@ public class CurseAddon implements DownloadManager.IMod {
|
||||
return isExperimental;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DownloadManager.Mod> loadDependencies() throws IOException {
|
||||
Set<Integer> dependencies = latestFiles.stream()
|
||||
.flatMap(latestFile -> latestFile.getDependencies().stream())
|
||||
.map(Dependency::getAddonId)
|
||||
.collect(Collectors.toSet());
|
||||
List<DownloadManager.Mod> mods = new ArrayList<>();
|
||||
for (int dependencyId : dependencies) {
|
||||
mods.add(CurseModManager.getAddon(dependencyId).toMod());
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<DownloadManager.Version> loadVersions() throws IOException {
|
||||
return CurseModManager.getFiles(this).stream()
|
||||
@@ -485,7 +500,7 @@ public class CurseAddon implements DownloadManager.IMod {
|
||||
versionType,
|
||||
new DownloadManager.File(Collections.emptyMap(), getDownloadUrl(), getFileName()),
|
||||
Collections.emptyList(),
|
||||
gameVersion,
|
||||
gameVersion.stream().filter(ver -> ver.startsWith("1.") || ver.contains("w")).collect(Collectors.toList()),
|
||||
Collections.emptyList()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,11 @@ public final class CurseModManager {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public static CurseAddon getAddon(int id) throws IOException {
|
||||
String response = NetworkUtils.doGet(NetworkUtils.toURL("https://addons-ecs.forgesvc.net/api/v2/addon/" + id));
|
||||
return JsonUtils.fromNonNullJson(response, CurseAddon.class);
|
||||
}
|
||||
|
||||
public static List<CurseAddon.LatestFile> getFiles(CurseAddon addon) throws IOException {
|
||||
String response = NetworkUtils.doGet(NetworkUtils.toURL("https://addons-ecs.forgesvc.net/api/v2/addon/" + addon.getId() + "/files"));
|
||||
return JsonUtils.fromNonNullJson(response, new TypeToken<List<CurseAddon.LatestFile>>() {
|
||||
|
||||
@@ -418,6 +418,11 @@ public final class Modrinth {
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DownloadManager.Mod> loadDependencies() throws IOException {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<DownloadManager.Version> loadVersions() throws IOException {
|
||||
return Modrinth.getFiles(this).stream()
|
||||
|
||||
@@ -865,7 +865,7 @@ public abstract class Task<T> {
|
||||
* @param tasks the Tasks
|
||||
* @return a new Task that is completed when all of the given Tasks complete
|
||||
*/
|
||||
public static Task<Void> allOf(Task<?>... tasks) {
|
||||
public static Task<List<Object>> allOf(Task<?>... tasks) {
|
||||
return allOf(Arrays.asList(tasks));
|
||||
}
|
||||
|
||||
@@ -880,14 +880,15 @@ public abstract class Task<T> {
|
||||
* @param tasks the Tasks
|
||||
* @return a new Task that is completed when all of the given Tasks complete
|
||||
*/
|
||||
public static Task<Void> allOf(Collection<Task<?>> tasks) {
|
||||
return new Task<Void>() {
|
||||
public static Task<List<Object>> allOf(Collection<Task<?>> tasks) {
|
||||
return new Task<List<Object>>() {
|
||||
{
|
||||
setSignificance(TaskSignificance.MINOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
setResult(tasks.stream().map(Task::getResult).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user