Enable HMCL to update mod from Modrinth (#2236)
* Enable HMCL to update mod from Modrinth * Fix UI * Fix: HMCL won't select the latest version when there is newer version in several remote mod repository.
This commit is contained in:
@@ -18,27 +18,31 @@
|
||||
package org.jackhuang.hmcl.ui.versions;
|
||||
|
||||
import org.jackhuang.hmcl.mod.LocalModFile;
|
||||
import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository;
|
||||
import org.jackhuang.hmcl.mod.RemoteMod;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModCheckUpdatesTask extends Task<List<LocalModFile.ModUpdate>> {
|
||||
|
||||
private final String gameVersion;
|
||||
private final Collection<LocalModFile> mods;
|
||||
private final Collection<Task<LocalModFile.ModUpdate>> dependents;
|
||||
private final Collection<Collection<Task<LocalModFile.ModUpdate>>> dependents;
|
||||
|
||||
public ModCheckUpdatesTask(String gameVersion, Collection<LocalModFile> mods) {
|
||||
this.gameVersion = gameVersion;
|
||||
this.mods = mods;
|
||||
|
||||
dependents = mods.stream()
|
||||
.map(mod -> Task.supplyAsync(() -> {
|
||||
return mod.checkUpdates(gameVersion, CurseForgeRemoteModRepository.MODS);
|
||||
}).setSignificance(TaskSignificance.MAJOR).setName(mod.getFileName()).withCounter("mods.check_updates"))
|
||||
.map(mod ->
|
||||
Arrays.stream(RemoteMod.Type.values())
|
||||
.map(type ->
|
||||
Task.supplyAsync(() -> mod.checkUpdates(gameVersion, type.getRemoteModRepository()))
|
||||
.setSignificance(TaskSignificance.MAJOR)
|
||||
.setName(String.format("%s (%s)", mod.getFileName(), type.name())).withCounter("mods.check_updates")
|
||||
)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
setStage("mods.check_updates");
|
||||
@@ -57,7 +61,7 @@ public class ModCheckUpdatesTask extends Task<List<LocalModFile.ModUpdate>> {
|
||||
|
||||
@Override
|
||||
public Collection<? extends Task<?>> getDependents() {
|
||||
return dependents;
|
||||
return dependents.stream().flatMap(Collection::stream).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,8 +72,14 @@ public class ModCheckUpdatesTask extends Task<List<LocalModFile.ModUpdate>> {
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
setResult(dependents.stream()
|
||||
.filter(task -> task.getResult() != null)
|
||||
.map(Task::getResult)
|
||||
.map(tasks -> tasks.stream()
|
||||
.filter(task -> task.getResult() != null)
|
||||
.map(Task::getResult)
|
||||
.filter(modUpdate -> !modUpdate.getCandidates().isEmpty())
|
||||
.max(Comparator.comparing((LocalModFile.ModUpdate modUpdate) -> modUpdate.getCandidates().get(0).getDatePublished()))
|
||||
.orElse(null)
|
||||
)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.mod;
|
||||
|
||||
import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository;
|
||||
import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository;
|
||||
import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -87,8 +89,18 @@ public class RemoteMod {
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
CURSEFORGE,
|
||||
MODRINTH
|
||||
CURSEFORGE(CurseForgeRemoteModRepository.MODS),
|
||||
MODRINTH(ModrinthRemoteModRepository.MODS);
|
||||
|
||||
private final RemoteModRepository remoteModRepository;
|
||||
|
||||
public RemoteModRepository getRemoteModRepository() {
|
||||
return this.remoteModRepository;
|
||||
}
|
||||
|
||||
Type(RemoteModRepository remoteModRepository) {
|
||||
this.remoteModRepository = remoteModRepository;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMod {
|
||||
@@ -201,7 +213,7 @@ public class RemoteMod {
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return encodeLocation (url);
|
||||
return encodeLocation(url);
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
|
||||
Reference in New Issue
Block a user