refactor(mod): ModInfo -> LocalMod

This commit is contained in:
huanghongxun
2021-10-04 16:48:50 +08:00
parent bb6bd86e71
commit 31327d685b
21 changed files with 343 additions and 285 deletions

View File

@@ -202,10 +202,10 @@ public class Datapack {
private Path file;
private final BooleanProperty active;
private final String id;
private final ModInfo.Description description;
private final LocalMod.Description description;
private final Datapack datapack;
public Pack(Path file, String id, ModInfo.Description description, Datapack datapack) {
public Pack(Path file, String id, LocalMod.Description description, Datapack datapack) {
this.file = file;
this.id = id;
this.description = description;
@@ -235,7 +235,7 @@ public class Datapack {
return id;
}
public ModInfo.Description getDescription() {
public LocalMod.Description getDescription() {
return description;
}

View File

@@ -64,14 +64,14 @@ public final class FabricModMetadata {
this.contact = contact;
}
public static ModInfo fromFile(File modFile) throws IOException, JsonParseException {
public static LocalMod fromFile(File modFile) throws IOException, JsonParseException {
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(modFile.toPath())) {
Path mcmod = fs.getPath("fabric.mod.json");
if (Files.notExists(mcmod))
throw new IOException("File " + modFile + " is not a Fabric mod.");
FabricModMetadata metadata = JsonUtils.fromNonNullJson(FileUtils.readText(mcmod), FabricModMetadata.class);
String authors = metadata.authors == null ? "" : metadata.authors.stream().map(author -> author.name).collect(Collectors.joining(", "));
return new ModInfo(modFile, metadata.id, metadata.name, new ModInfo.Description(metadata.description),
return new LocalMod(modFile, ModLoaderType.FABRIC, metadata.id, metadata.name, new LocalMod.Description(metadata.description),
authors, metadata.version, "", metadata.contact != null ? metadata.contact.getOrDefault("homepage", "") : "", metadata.icon);
}
}

View File

@@ -116,7 +116,7 @@ public final class ForgeNewModMetadata {
}
}
public static ModInfo fromFile(File modFile) throws IOException, JsonParseException {
public static LocalMod fromFile(File modFile) throws IOException, JsonParseException {
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(modFile.toPath())) {
Path modstoml = fs.getPath("META-INF/mods.toml");
if (Files.notExists(modstoml))
@@ -135,7 +135,7 @@ public final class ForgeNewModMetadata {
LOG.log(Level.WARNING, "Failed to parse MANIFEST.MF in file " + modFile.getPath());
}
}
return new ModInfo(modFile, mod.getModId(), mod.getDisplayName(), new ModInfo.Description(mod.getDescription()),
return new LocalMod(modFile, ModLoaderType.FORGE, mod.getModId(), mod.getDisplayName(), new LocalMod.Description(mod.getDescription()),
mod.getAuthors(), mod.getVersion().replace("${file.jarVersion}", jarVersion), "",
mod.getDisplayURL(),
metadata.getLogoFile());

View File

@@ -120,7 +120,7 @@ public final class ForgeOldModMetadata {
return authors;
}
public static ModInfo fromFile(File modFile) throws IOException, JsonParseException {
public static LocalMod fromFile(File modFile) throws IOException, JsonParseException {
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(modFile.toPath())) {
Path mcmod = fs.getPath("mcmod.info");
if (Files.notExists(mcmod))
@@ -138,7 +138,7 @@ public final class ForgeOldModMetadata {
authors = String.join(", ", metadata.getAuthorList());
if (StringUtils.isBlank(authors))
authors = metadata.getCredits();
return new ModInfo(modFile, metadata.getModId(), metadata.getName(), new ModInfo.Description(metadata.getDescription()),
return new LocalMod(modFile, ModLoaderType.FORGE, metadata.getModId(), metadata.getName(), new LocalMod.Description(metadata.getDescription()),
authors, metadata.getVersion(), metadata.getGameVersion(),
StringUtils.isBlank(metadata.getUrl()) ? metadata.getUpdateUrl() : metadata.url,
metadata.getLogoFile());

View File

@@ -108,7 +108,7 @@ public final class LiteModMetadata {
return updateURI;
}
public static ModInfo fromFile(File modFile) throws IOException, JsonParseException {
public static LocalMod fromFile(File modFile) throws IOException, JsonParseException {
try (ZipFile zipFile = new ZipFile(modFile)) {
ZipEntry entry = zipFile.getEntry("litemod.json");
if (entry == null)
@@ -116,7 +116,7 @@ public final class LiteModMetadata {
LiteModMetadata metadata = JsonUtils.GSON.fromJson(IOUtils.readFullyAsString(zipFile.getInputStream(entry)), LiteModMetadata.class);
if (metadata == null)
throw new IOException("Mod " + modFile + " `litemod.json` is malformed.");
return new ModInfo(modFile, null, metadata.getName(), new ModInfo.Description(metadata.getDescription()), metadata.getAuthor(),
return new LocalMod(modFile, ModLoaderType.FORGE, null, metadata.getName(), new LocalMod.Description(metadata.getDescription()), metadata.getAuthor(),
metadata.getVersion(), metadata.getGameVersion(), metadata.getUpdateURI(), "");
}
}

View File

@@ -35,9 +35,10 @@ import java.util.logging.Level;
*
* @author huangyuhui
*/
public final class ModInfo implements Comparable<ModInfo> {
public final class LocalMod implements Comparable<LocalMod> {
private Path file;
private final ModLoaderType modLoaderType;
private final String id;
private final String name;
private final Description description;
@@ -49,12 +50,13 @@ public final class ModInfo implements Comparable<ModInfo> {
private final String logoPath;
private final BooleanProperty activeProperty;
public ModInfo(File file, String id, String name, Description description) {
this(file, id, name, description, "", "", "", "", "");
public LocalMod(File file, ModLoaderType modLoaderType, String id, String name, Description description) {
this(file, modLoaderType, id, name, description, "", "", "", "", "");
}
public ModInfo(File file, String id, String name, Description description, String authors, String version, String gameVersion, String url, String logoPath) {
public LocalMod(File file, ModLoaderType modLoaderType, String id, String name, Description description, String authors, String version, String gameVersion, String url, String logoPath) {
this.file = file.toPath();
this.modLoaderType = modLoaderType;
this.id = id;
this.name = name;
this.description = description;
@@ -67,13 +69,13 @@ public final class ModInfo implements Comparable<ModInfo> {
activeProperty = new SimpleBooleanProperty(this, "active", !ModManager.isDisabled(file)) {
@Override
protected void invalidated() {
Path path = ModInfo.this.file.toAbsolutePath();
Path path = LocalMod.this.file.toAbsolutePath();
try {
if (get())
ModInfo.this.file = ModManager.enableMod(path);
LocalMod.this.file = ModManager.enableMod(path);
else
ModInfo.this.file = ModManager.disableMod(path);
LocalMod.this.file = ModManager.disableMod(path);
} catch (IOException e) {
Logging.LOG.log(Level.SEVERE, "Unable to invert state of mod file " + path, e);
}
@@ -87,6 +89,10 @@ public final class ModInfo implements Comparable<ModInfo> {
return file;
}
public ModLoaderType getModLoaderType() {
return modLoaderType;
}
public String getId() {
return id;
}
@@ -136,13 +142,13 @@ public final class ModInfo implements Comparable<ModInfo> {
}
@Override
public int compareTo(ModInfo o) {
public int compareTo(LocalMod o) {
return getFileName().compareTo(o.getFileName());
}
@Override
public boolean equals(Object obj) {
return obj instanceof ModInfo && Objects.equals(getFileName(), ((ModInfo) obj).getFileName());
return obj instanceof LocalMod && Objects.equals(getFileName(), ((LocalMod) obj).getFileName());
}
@Override

View File

@@ -0,0 +1,26 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.mod;
public enum ModLoaderType {
UNKNOWN,
FORGE,
FABRIC,
LITE_LOADER,
PACK
}

View File

@@ -32,7 +32,7 @@ import java.util.TreeSet;
public final class ModManager {
private final GameRepository repository;
private final String id;
private final TreeSet<ModInfo> modInfos = new TreeSet<>();
private final TreeSet<LocalMod> localMods = new TreeSet<>();
private boolean loaded = false;
@@ -55,12 +55,12 @@ public final class ModManager {
private void addModInfo(File file) {
try {
modInfos.add(getModInfo(file));
localMods.add(getModInfo(file));
} catch (IllegalArgumentException ignore) {
}
}
public static ModInfo getModInfo(File modFile) {
public static LocalMod getModInfo(File modFile) {
File file = isDisabled(modFile) ? new File(modFile.getAbsoluteFile().getParentFile(), FileUtils.getNameWithoutExtension(modFile)) : modFile;
String description, extension = FileUtils.getExtension(file);
switch (extension) {
@@ -98,11 +98,11 @@ public final class ModManager {
default:
throw new IllegalArgumentException("File " + modFile + " is not a mod file.");
}
return new ModInfo(modFile, null, FileUtils.getNameWithoutExtension(modFile), new ModInfo.Description(description));
return new LocalMod(modFile, ModLoaderType.UNKNOWN, null, FileUtils.getNameWithoutExtension(modFile), new LocalMod.Description(description));
}
public void refreshMods() throws IOException {
modInfos.clear();
localMods.clear();
if (Files.isDirectory(getModsDirectory())) {
try (DirectoryStream<Path> modsDirectoryStream = Files.newDirectoryStream(getModsDirectory())) {
for (Path subitem : modsDirectoryStream) {
@@ -122,10 +122,10 @@ public final class ModManager {
loaded = true;
}
public Collection<ModInfo> getMods() throws IOException {
public Collection<LocalMod> getMods() throws IOException {
if (!loaded)
refreshMods();
return modInfos;
return localMods;
}
public void addMod(File file) throws IOException {
@@ -145,9 +145,9 @@ public final class ModManager {
addModInfo(newFile);
}
public void removeMods(ModInfo... modInfos) throws IOException {
for (ModInfo modInfo : modInfos) {
Files.deleteIfExists(modInfo.getFile());
public void removeMods(LocalMod... localMods) throws IOException {
for (LocalMod localMod : localMods) {
Files.deleteIfExists(localMod.getFile());
}
}

View File

@@ -66,13 +66,13 @@ public class PackMcMeta implements Validation {
private final int packFormat;
@SerializedName("description")
private final ModInfo.Description description;
private final LocalMod.Description description;
public PackInfo() {
this(0, new ModInfo.Description(Collections.emptyList()));
this(0, new LocalMod.Description(Collections.emptyList()));
}
public PackInfo(int packFormat, ModInfo.Description description) {
public PackInfo(int packFormat, LocalMod.Description description) {
this.packFormat = packFormat;
this.description = description;
}
@@ -81,7 +81,7 @@ public class PackMcMeta implements Validation {
return packFormat;
}
public ModInfo.Description getDescription() {
public LocalMod.Description getDescription() {
return description;
}
}
@@ -112,13 +112,13 @@ public class PackMcMeta implements Validation {
}
}
public ModInfo.Description.Part deserialize(JsonElement json, JsonDeserializationContext context) throws JsonParseException {
public LocalMod.Description.Part deserialize(JsonElement json, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonPrimitive()) {
return new ModInfo.Description.Part(parseText(json));
return new LocalMod.Description.Part(parseText(json));
} else if (json.isJsonObject()) {
JsonObject obj = json.getAsJsonObject();
String text = parseText(obj.get("text"));
return new ModInfo.Description.Part(text);
return new LocalMod.Description.Part(text);
} else {
throw new JsonParseException("pack.mcmeta Raw JSON text should be string or an object");
}
@@ -126,31 +126,31 @@ public class PackMcMeta implements Validation {
@Override
public PackInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
List<ModInfo.Description.Part> parts = new ArrayList<>();
List<LocalMod.Description.Part> parts = new ArrayList<>();
JsonObject packInfo = json.getAsJsonObject();
int packFormat = packInfo.get("pack_format").getAsInt();
JsonElement description = packInfo.get("description");
if (description.isJsonPrimitive()) {
parts.add(new ModInfo.Description.Part(parseText(description)));
parts.add(new LocalMod.Description.Part(parseText(description)));
} else if (description.isJsonArray()) {
for (JsonElement element : description.getAsJsonArray()) {
JsonObject descriptionPart = element.getAsJsonObject();
parts.add(new ModInfo.Description.Part(descriptionPart.get("text").getAsString(), descriptionPart.get("color").getAsString()));
parts.add(new LocalMod.Description.Part(descriptionPart.get("text").getAsString(), descriptionPart.get("color").getAsString()));
}
} else {
throw new JsonParseException("pack.mcmeta::pack::description should be String or array of text objects with text and color fields");
}
return new PackInfo(packFormat, new ModInfo.Description(parts));
return new PackInfo(packFormat, new LocalMod.Description(parts));
}
}
public static ModInfo fromFile(File modFile) throws IOException, JsonParseException {
public static LocalMod fromFile(File modFile) throws IOException, JsonParseException {
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(modFile.toPath())) {
Path mcmod = fs.getPath("pack.mcmeta");
if (Files.notExists(mcmod))
throw new IOException("File " + modFile + " is not a resource pack.");
PackMcMeta metadata = JsonUtils.fromNonNullJson(FileUtils.readText(mcmod), PackMcMeta.class);
return new ModInfo(modFile, null, FileUtils.getNameWithoutExtension(modFile), metadata.pack.description, "", "", "", "", "");
return new LocalMod(modFile, ModLoaderType.PACK, null, FileUtils.getNameWithoutExtension(modFile), metadata.pack.description, "", "", "", "", "");
}
}
}

View File

@@ -0,0 +1,180 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2021 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.mod;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
public class RemoteMod {
private final String slug;
private final String author;
private final String title;
private final String description;
private final List<String> categories;
private final String pageUrl;
private final String iconUrl;
private final IMod data;
public RemoteMod(String slug, String author, String title, String description, List<String> categories, String pageUrl, String iconUrl, IMod data) {
this.slug = slug;
this.author = author;
this.title = title;
this.description = description;
this.categories = categories;
this.pageUrl = pageUrl;
this.iconUrl = iconUrl;
this.data = data;
}
public String getSlug() {
return slug;
}
public String getAuthor() {
return author;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public List<String> getCategories() {
return categories;
}
public String getPageUrl() {
return pageUrl;
}
public String getIconUrl() {
return iconUrl;
}
public IMod getData() {
return data;
}
public enum VersionType {
Release,
Beta,
Alpha
}
public interface IMod {
List<RemoteMod> loadDependencies() throws IOException;
Stream<Version> loadVersions() throws IOException;
}
public static class Version {
private final Object self;
private final String name;
private final String version;
private final String changelog;
private final Instant datePublished;
private final VersionType versionType;
private final File file;
private final List<String> dependencies;
private final List<String> gameVersions;
private final List<String> loaders;
public Version(Object self, String name, String version, String changelog, Instant datePublished, VersionType versionType, File file, List<String> dependencies, List<String> gameVersions, List<String> loaders) {
this.self = self;
this.name = name;
this.version = version;
this.changelog = changelog;
this.datePublished = datePublished;
this.versionType = versionType;
this.file = file;
this.dependencies = dependencies;
this.gameVersions = gameVersions;
this.loaders = loaders;
}
public Object getSelf() {
return self;
}
public String getName() {
return name;
}
public String getVersion() {
return version;
}
public String getChangelog() {
return changelog;
}
public Instant getDatePublished() {
return datePublished;
}
public VersionType getVersionType() {
return versionType;
}
public File getFile() {
return file;
}
public List<String> getDependencies() {
return dependencies;
}
public List<String> getGameVersions() {
return gameVersions;
}
public List<String> getLoaders() {
return loaders;
}
}
public static class File {
private final Map<String, String> hashes;
private final String url;
private final String filename;
public File(Map<String, String> hashes, String url, String filename) {
this.hashes = hashes;
this.url = url;
this.filename = filename;
}
public Map<String, String> getHashes() {
return hashes;
}
public String getUrl() {
return url;
}
public String getFilename() {
return filename;
}
}
}

View File

@@ -19,27 +19,19 @@ package org.jackhuang.hmcl.mod;
import java.io.IOException;
import java.nio.file.Path;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
public interface RemoteModRepository {
Stream<Mod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, int sort)
Stream<RemoteMod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, int sort)
throws IOException;
Optional<Version> getRemoteVersionByLocalFile(Path file) throws IOException;
Optional<RemoteMod.Version> getRemoteVersionByLocalFile(Path file) throws IOException;
Stream<Category> getCategories() throws IOException;
interface IMod {
List<Mod> loadDependencies() throws IOException;
Stream<Version> loadVersions() throws IOException;
}
class Category {
private final Object self;
private final String id;
@@ -64,156 +56,6 @@ public interface RemoteModRepository {
}
}
class Mod {
private final String slug;
private final String author;
private final String title;
private final String description;
private final List<String> categories;
private final String pageUrl;
private final String iconUrl;
private final IMod data;
public Mod(String slug, String author, String title, String description, List<String> categories, String pageUrl, String iconUrl, IMod data) {
this.slug = slug;
this.author = author;
this.title = title;
this.description = description;
this.categories = categories;
this.pageUrl = pageUrl;
this.iconUrl = iconUrl;
this.data = data;
}
public String getSlug() {
return slug;
}
public String getAuthor() {
return author;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public List<String> getCategories() {
return categories;
}
public String getPageUrl() {
return pageUrl;
}
public String getIconUrl() {
return iconUrl;
}
public IMod getData() {
return data;
}
}
enum VersionType {
Release,
Beta,
Alpha
}
class Version {
private final Object self;
private final String name;
private final String version;
private final String changelog;
private final Instant datePublished;
private final VersionType versionType;
private final File file;
private final List<String> dependencies;
private final List<String> gameVersions;
private final List<String> loaders;
public Version(Object self, String name, String version, String changelog, Instant datePublished, VersionType versionType, File file, List<String> dependencies, List<String> gameVersions, List<String> loaders) {
this.self = self;
this.name = name;
this.version = version;
this.changelog = changelog;
this.datePublished = datePublished;
this.versionType = versionType;
this.file = file;
this.dependencies = dependencies;
this.gameVersions = gameVersions;
this.loaders = loaders;
}
public Object getSelf() {
return self;
}
public String getName() {
return name;
}
public String getVersion() {
return version;
}
public String getChangelog() {
return changelog;
}
public Instant getDatePublished() {
return datePublished;
}
public VersionType getVersionType() {
return versionType;
}
public File getFile() {
return file;
}
public List<String> getDependencies() {
return dependencies;
}
public List<String> getGameVersions() {
return gameVersions;
}
public List<String> getLoaders() {
return loaders;
}
}
class File {
private final Map<String, String> hashes;
private final String url;
private final String filename;
public File(Map<String, String> hashes, String url, String filename) {
this.hashes = hashes;
this.url = url;
this.filename = filename;
}
public Map<String, String> getHashes() {
return hashes;
}
public String getUrl() {
return url;
}
public String getFilename() {
return filename;
}
}
String[] DEFAULT_GAME_VERSIONS = new String[]{
"1.17.1", "1.17",
"1.16.5", "1.16.4", "1.16.3", "1.16.2", "1.16.1", "1.16",

View File

@@ -17,7 +17,7 @@
*/
package org.jackhuang.hmcl.mod.curse;
import org.jackhuang.hmcl.mod.RemoteModRepository;
import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.util.Immutable;
import java.io.IOException;
@@ -30,7 +30,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
@Immutable
public class CurseAddon implements RemoteModRepository.IMod {
public class CurseAddon implements RemoteMod.IMod {
private final int id;
private final String name;
private final List<Author> authors;
@@ -168,13 +168,13 @@ public class CurseAddon implements RemoteModRepository.IMod {
}
@Override
public List<RemoteModRepository.Mod> loadDependencies() throws IOException {
public List<RemoteMod> loadDependencies() throws IOException {
Set<Integer> dependencies = latestFiles.stream()
.flatMap(latestFile -> latestFile.getDependencies().stream())
.filter(dep -> dep.getType() == 3)
.map(Dependency::getAddonId)
.collect(Collectors.toSet());
List<RemoteModRepository.Mod> mods = new ArrayList<>();
List<RemoteMod> mods = new ArrayList<>();
for (int dependencyId : dependencies) {
mods.add(CurseForgeRemoteModRepository.MODS.getAddon(dependencyId).toMod());
}
@@ -182,12 +182,12 @@ public class CurseAddon implements RemoteModRepository.IMod {
}
@Override
public Stream<RemoteModRepository.Version> loadVersions() throws IOException {
public Stream<RemoteMod.Version> loadVersions() throws IOException {
return CurseForgeRemoteModRepository.MODS.getFiles(this).stream()
.map(CurseAddon.LatestFile::toVersion);
}
public RemoteModRepository.Mod toMod() {
public RemoteMod toMod() {
String iconUrl = null;
for (CurseAddon.Attachment attachment : attachments) {
if (attachment.isDefault()) {
@@ -195,7 +195,7 @@ public class CurseAddon implements RemoteModRepository.IMod {
}
}
return new RemoteModRepository.Mod(
return new RemoteMod(
slug,
"",
name,
@@ -481,31 +481,31 @@ public class CurseAddon implements RemoteModRepository.IMod {
return fileDataInstant;
}
public RemoteModRepository.Version toVersion() {
RemoteModRepository.VersionType versionType;
public RemoteMod.Version toVersion() {
RemoteMod.VersionType versionType;
switch (getReleaseType()) {
case 1:
versionType = RemoteModRepository.VersionType.Release;
versionType = RemoteMod.VersionType.Release;
break;
case 2:
versionType = RemoteModRepository.VersionType.Beta;
versionType = RemoteMod.VersionType.Beta;
break;
case 3:
versionType = RemoteModRepository.VersionType.Alpha;
versionType = RemoteMod.VersionType.Alpha;
break;
default:
versionType = RemoteModRepository.VersionType.Release;
versionType = RemoteMod.VersionType.Release;
break;
}
return new RemoteModRepository.Version(
return new RemoteMod.Version(
this,
getDisplayName(),
null,
null,
getParsedFileDate(),
versionType,
new RemoteModRepository.File(Collections.emptyMap(), getDownloadUrl(), getFileName()),
new RemoteMod.File(Collections.emptyMap(), getDownloadUrl(), getFileName()),
Collections.emptyList(),
gameVersion.stream().filter(ver -> ver.startsWith("1.") || ver.contains("w")).collect(Collectors.toList()),
Collections.emptyList()

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hmcl.mod.curse;
import com.google.gson.reflect.TypeToken;
import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.mod.RemoteModRepository;
import org.jackhuang.hmcl.util.MurmurHash;
import org.jackhuang.hmcl.util.gson.JsonUtils;
@@ -64,7 +65,7 @@ public final class CurseForgeRemoteModRepository implements RemoteModRepository
}
@Override
public Stream<RemoteModRepository.Mod> search(String gameVersion, RemoteModRepository.Category category, int pageOffset, int pageSize, String searchFilter, int sort) throws IOException {
public Stream<RemoteMod> search(String gameVersion, RemoteModRepository.Category category, int pageOffset, int pageSize, String searchFilter, int sort) throws IOException {
int categoryId = 0;
if (category != null) categoryId = ((Category) category.getSelf()).getId();
return searchPaginated(gameVersion, categoryId, pageOffset, pageSize, searchFilter, sort).stream()
@@ -72,7 +73,7 @@ public final class CurseForgeRemoteModRepository implements RemoteModRepository
}
@Override
public Optional<RemoteModRepository.Version> getRemoteVersionByLocalFile(Path file) throws IOException {
public Optional<RemoteMod.Version> getRemoteVersionByLocalFile(Path file) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(file)))) {
int b;

View File

@@ -19,6 +19,7 @@ package org.jackhuang.hmcl.mod.modrinth;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.mod.RemoteModRepository;
import org.jackhuang.hmcl.util.DigestUtils;
import org.jackhuang.hmcl.util.Hex;
@@ -64,13 +65,13 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
}
@Override
public Stream<RemoteModRepository.Mod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, int sort) throws IOException {
public Stream<RemoteMod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, int sort) throws IOException {
return searchPaginated(gameVersion, pageOffset, pageSize, searchFilter).stream()
.map(ModResult::toMod);
}
@Override
public Optional<RemoteModRepository.Version> getRemoteVersionByLocalFile(Path file) throws IOException {
public Optional<RemoteMod.Version> getRemoteVersionByLocalFile(Path file) throws IOException {
String sha1 = Hex.encodeHex(DigestUtils.digest("SHA-1", file));
try {
@@ -288,23 +289,23 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
return loaders;
}
public Optional<RemoteModRepository.Version> toVersion() {
RemoteModRepository.VersionType type;
public Optional<RemoteMod.Version> toVersion() {
RemoteMod.VersionType type;
if ("release".equals(versionType)) {
type = RemoteModRepository.VersionType.Release;
type = RemoteMod.VersionType.Release;
} else if ("beta".equals(versionType)) {
type = RemoteModRepository.VersionType.Beta;
type = RemoteMod.VersionType.Beta;
} else if ("alpha".equals(versionType)) {
type = RemoteModRepository.VersionType.Alpha;
type = RemoteMod.VersionType.Alpha;
} else {
type = RemoteModRepository.VersionType.Release;
type = RemoteMod.VersionType.Release;
}
if (files.size() == 0) {
return Optional.empty();
}
return Optional.of(new RemoteModRepository.Version(
return Optional.of(new RemoteMod.Version(
this,
name,
versionNumber,
@@ -342,12 +343,12 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
return filename;
}
public RemoteModRepository.File toFile() {
return new RemoteModRepository.File(hashes, url, filename);
public RemoteMod.File toFile() {
return new RemoteMod.File(hashes, url, filename);
}
}
public static class ModResult implements RemoteModRepository.IMod {
public static class ModResult implements RemoteMod.IMod {
@SerializedName("mod_id")
private final String modId;
@@ -457,19 +458,19 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
}
@Override
public List<RemoteModRepository.Mod> loadDependencies() throws IOException {
public List<RemoteMod> loadDependencies() throws IOException {
return Collections.emptyList();
}
@Override
public Stream<RemoteModRepository.Version> loadVersions() throws IOException {
public Stream<RemoteMod.Version> loadVersions() throws IOException {
return ModrinthRemoteModRepository.INSTANCE.getFiles(this).stream()
.map(ModVersion::toVersion)
.flatMap(Lang::toStream);
}
public RemoteModRepository.Mod toMod() {
return new RemoteModRepository.Mod(
public RemoteMod toMod() {
return new RemoteMod(
slug,
author,
title,