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;
|
package org.jackhuang.hmcl.ui.versions;
|
||||||
|
|
||||||
import org.jackhuang.hmcl.mod.LocalModFile;
|
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 org.jackhuang.hmcl.task.Task;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ModCheckUpdatesTask extends Task<List<LocalModFile.ModUpdate>> {
|
public class ModCheckUpdatesTask extends Task<List<LocalModFile.ModUpdate>> {
|
||||||
|
|
||||||
private final String gameVersion;
|
private final String gameVersion;
|
||||||
private final Collection<LocalModFile> mods;
|
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) {
|
public ModCheckUpdatesTask(String gameVersion, Collection<LocalModFile> mods) {
|
||||||
this.gameVersion = gameVersion;
|
this.gameVersion = gameVersion;
|
||||||
this.mods = mods;
|
this.mods = mods;
|
||||||
|
|
||||||
dependents = mods.stream()
|
dependents = mods.stream()
|
||||||
.map(mod -> Task.supplyAsync(() -> {
|
.map(mod ->
|
||||||
return mod.checkUpdates(gameVersion, CurseForgeRemoteModRepository.MODS);
|
Arrays.stream(RemoteMod.Type.values())
|
||||||
}).setSignificance(TaskSignificance.MAJOR).setName(mod.getFileName()).withCounter("mods.check_updates"))
|
.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());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
setStage("mods.check_updates");
|
setStage("mods.check_updates");
|
||||||
@@ -57,7 +61,7 @@ public class ModCheckUpdatesTask extends Task<List<LocalModFile.ModUpdate>> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends Task<?>> getDependents() {
|
public Collection<? extends Task<?>> getDependents() {
|
||||||
return dependents;
|
return dependents.stream().flatMap(Collection::stream).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -68,8 +72,14 @@ public class ModCheckUpdatesTask extends Task<List<LocalModFile.ModUpdate>> {
|
|||||||
@Override
|
@Override
|
||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
setResult(dependents.stream()
|
setResult(dependents.stream()
|
||||||
.filter(task -> task.getResult() != null)
|
.map(tasks -> tasks.stream()
|
||||||
.map(Task::getResult)
|
.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()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.mod;
|
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 org.jackhuang.hmcl.task.FileDownloadTask;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -87,8 +89,18 @@ public class RemoteMod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
CURSEFORGE,
|
CURSEFORGE(CurseForgeRemoteModRepository.MODS),
|
||||||
MODRINTH
|
MODRINTH(ModrinthRemoteModRepository.MODS);
|
||||||
|
|
||||||
|
private final RemoteModRepository remoteModRepository;
|
||||||
|
|
||||||
|
public RemoteModRepository getRemoteModRepository() {
|
||||||
|
return this.remoteModRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type(RemoteModRepository remoteModRepository) {
|
||||||
|
this.remoteModRepository = remoteModRepository;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IMod {
|
public interface IMod {
|
||||||
@@ -201,7 +213,7 @@ public class RemoteMod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return encodeLocation (url);
|
return encodeLocation(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFilename() {
|
public String getFilename() {
|
||||||
|
|||||||
Reference in New Issue
Block a user