Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,101 +56,20 @@
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

@Immutable
public final class ForgeNewModMetadata {
private final String modLoader;

private final String loaderVersion;

private final String logoFile;

private final String license;

private final List<Mod> mods;

public ForgeNewModMetadata(String modLoader, String loaderVersion, String logoFile, String license, List<Mod> mods) {
this.modLoader = modLoader;
this.loaderVersion = loaderVersion;
this.logoFile = logoFile;
this.license = license;
this.mods = mods;
}

public String getModLoader() {
return modLoader;
}

public String getLoaderVersion() {
return loaderVersion;
}

public String getLogoFile() {
return logoFile;
}

public String getLicense() {
return license;
}

public List<Mod> getMods() {
return mods;
}

public static class Mod {
private final String modId;
private final String version;
private final String displayName;
private final String side;
private final String displayURL;
@JsonAdapter(AuthorDeserializer.class)
private final String authors;
private final String description;
private final String logoFile;

public Mod() {
this("", "", "", "", "", "", "", "");
}

public Mod(String modId, String version, String displayName, String side, String displayURL, String authors, String description, String logoFile) {
this.modId = modId;
this.version = version;
this.displayName = displayName;
this.side = side;
this.displayURL = displayURL;
this.authors = authors;
this.description = description;
this.logoFile = logoFile;
}

public String getModId() {
return modId;
}

public String getVersion() {
return version;
}

public String getDisplayName() {
return displayName;
}

public String getSide() {
return side;
}

public String getDisplayURL() {
return displayURL;
}

public String getAuthors() {
return authors;
}

public String getDescription() {
return description;
}

public String getLogoFile() {
return logoFile;
public record ForgeNewModMetadata(String modLoader, String loaderVersion, String logoFile, String license, List<Mod> mods) {

public record Mod(String modId, String version, String displayName, String side, String displayURL,
@JsonAdapter(AuthorDeserializer.class) String authors, String description, String logoFile) {

public Mod {
if (modId == null) modId = "";
if (version == null) version = "";
if (displayName == null) displayName = "";
if (side == null) side = "";
if (displayURL == null) displayURL = "";
if (authors == null) authors = "";
if (description == null) description = "";
if (logoFile == null) logoFile = "";
}

static final class AuthorDeserializer implements JsonDeserializer<String> {
Expand Down Expand Up @@ -226,9 +145,9 @@ private static LocalModFile fromFile0(
throw ioException;
}
ForgeNewModMetadata metadata = JsonUtils.GSON.fromJson(tomlParseResult.toJson(), ForgeNewModMetadata.class);
if (metadata == null || metadata.getMods().isEmpty())
if (metadata == null || metadata.mods().isEmpty())
throw new IOException("Mod " + modFile + " `%s` is malformed..".formatted(modToml.getName()));
Mod mod = metadata.getMods().get(0);
Mod mod = metadata.mods().get(0);
ZipArchiveEntry manifestMF = tree.getEntry("META-INF/MANIFEST.MF");
String jarVersion = "";
if (manifestMF != null) {
Expand All @@ -240,13 +159,13 @@ private static LocalModFile fromFile0(
}
}

ModLoaderType type = analyzeLoader(tomlParseResult, mod.getModId(), modLoaderType);
ModLoaderType type = analyzeLoader(tomlParseResult, mod.modId(), modLoaderType);

String logoPath = StringUtils.isNotBlank(mod.getLogoFile()) ? mod.getLogoFile() : metadata.getLogoFile();
String logoPath = StringUtils.isNotBlank(mod.logoFile()) ? mod.logoFile() : metadata.logoFile();

return new LocalModFile(modManager, modManager.getLocalMod(mod.getModId(), type), modFile, mod.getDisplayName(), new LocalAddonFile.Description(mod.getDescription()),
mod.getAuthors(), jarVersion == null ? mod.getVersion() : mod.getVersion().replace("${file.jarVersion}", jarVersion), "",
mod.getDisplayURL(),
return new LocalModFile(modManager, modManager.getLocalMod(mod.modId(), type), modFile, mod.displayName(), new LocalAddonFile.Description(mod.description()),
mod.authors(), jarVersion == null ? mod.version() : mod.version().replace("${file.jarVersion}", jarVersion), "",
mod.displayURL(),
logoPath);
}

Expand Down Expand Up @@ -316,7 +235,7 @@ private static ModLoaderType analyzeLoader(TomlParseResult toml, String modID, M
try {
TomlArray tomlArray = toml.getArray("dependencies." + modID);
if (tomlArray != null) {
dependencies = tomlArray.toList().stream().map( o -> ((TomlTable) o).toMap()).toList();
dependencies = tomlArray.toList().stream().map(o -> ((TomlTable) o).toMap()).toList();
}
} catch (ClassCastException ignored) { // https://github.com/HMCL-dev/HMCL/issues/5068
}
Expand All @@ -325,7 +244,7 @@ private static ModLoaderType analyzeLoader(TomlParseResult toml, String modID, M
try {
TomlArray tomlArray = toml.getArray("dependencies"); // ??? I have no idea why some of the Forge mods use [[dependencies]]
if (tomlArray != null) {
dependencies = tomlArray.toList().stream().map( o -> ((TomlTable) o).toMap()).toList();
dependencies = tomlArray.toList().stream().map(o -> ((TomlTable) o).toMap()).toList();
}
} catch (ClassCastException e) {
try {
Expand All @@ -335,7 +254,7 @@ private static ModLoaderType analyzeLoader(TomlParseResult toml, String modID, M

TomlArray tomlArray = table.getArray(modID);
if (tomlArray != null) {
dependencies = tomlArray.toList().stream().map( o -> ((TomlTable) o).toMap()).toList();
dependencies = tomlArray.toList().stream().map(o -> ((TomlTable) o).toMap()).toList();
}
} catch (Throwable ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ public Task<?> refreshAsync(String gameVersion) {
continue;
List<String> urls = new ArrayList<>();
for (ForgeVersion.File file : version.getFiles())
if ("installer".equals(file.getCategory()) && "jar".equals(file.getFormat())) {
if ("installer".equals(file.category()) && "jar".equals(file.format())) {
String branch = toLookupBranch(gameVersion, version.getBranch());

String classifier = lookupVersion + "-" + version.getVersion() + (branch.isEmpty() ? "" : '-' + branch);
String fileName1 = "forge-" + classifier + "-" + file.getCategory() + "." + file.getFormat();
String fileName2 = "forge-" + classifier + "-" + lookupVersion + "-" + file.getCategory() + "." + file.getFormat();
String fileName1 = "forge-" + classifier + "-" + file.category() + "." + file.format();
String fileName2 = "forge-" + classifier + "-" + lookupVersion + "-" + file.category() + "." + file.format();
urls.add("https://files.minecraftforge.net/maven/net/minecraftforge/forge/" + classifier + "/" + fileName1);
urls.add("https://files.minecraftforge.net/maven/net/minecraftforge/forge/" + classifier + "-" + lookupVersion + "/" + fileName2);
urls.add(NetworkUtils.withQuery("https://bmclapi2.bangbang93.com/forge/download", mapOf(
pair("mcversion", version.getGameVersion()),
pair("version", version.getVersion()),
pair("branch", branch),
pair("category", file.getCategory()),
pair("format", file.getFormat())
pair("category", file.category()),
pair("format", file.format())
)));
}

Expand Down Expand Up @@ -202,31 +202,12 @@ public void validate() throws JsonParseException {
}

@Immutable
public static final class File {
private final String format;
private final String category;
private final String hash;
public record File(String format, String category, String hash) {

public File() {
this("", "", "");
}

public File(String format, String category, String hash) {
this.format = format;
this.category = category;
this.hash = hash;
}

public String getFormat() {
return format;
}

public String getCategory() {
return category;
}

public String getHash() {
return hash;
public File {
if (format == null) format = "";
if (category == null) category = "";
if (hash == null) hash = "";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,68 +25,6 @@
* @author huangyuhui
*/
@Immutable
public final class ForgeInstall {

private final String profileName;
private final String target;
private final Artifact path;
private final String version;
private final String filePath;
private final String welcome;
private final String minecraft;
private final String mirrorList;
private final String logo;

public ForgeInstall() {
this(null, null, null, null, null, null, null, null, null);
}

public ForgeInstall(String profileName, String target, Artifact path, String version, String filePath, String welcome, String minecraft, String mirrorList, String logo) {
this.profileName = profileName;
this.target = target;
this.path = path;
this.version = version;
this.filePath = filePath;
this.welcome = welcome;
this.minecraft = minecraft;
this.mirrorList = mirrorList;
this.logo = logo;
}

public String getProfileName() {
return profileName;
}

public String getTarget() {
return target;
}

public Artifact getPath() {
return path;
}

public String getVersion() {
return version;
}

public String getFilePath() {
return filePath;
}

public String getWelcome() {
return welcome;
}

public String getMinecraft() {
return minecraft;
}

public String getMirrorList() {
return mirrorList;
}

public String getLogo() {
return logo;
}

public record ForgeInstall(String profileName, String target, Artifact path, String version, String filePath,
String welcome, String minecraft, String mirrorList, String logo) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,8 @@
* @author huangyuhui
*/
@Immutable
public final class ForgeInstallProfile implements Validation {

@SerializedName("install")
private final ForgeInstall install;

@SerializedName("versionInfo")
private final Version versionInfo;

public ForgeInstallProfile(ForgeInstall install, Version versionInfo) {
this.install = install;
this.versionInfo = versionInfo;
}

public ForgeInstall getInstall() {
return install;
}

public Version getVersionInfo() {
return versionInfo;
}
public record ForgeInstallProfile(@SerializedName("install") ForgeInstall install,
@SerializedName("versionInfo") Version versionInfo) implements Validation {

@Override
public void validate() throws JsonParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public static boolean detectForgeInstallerType(DependencyManager dependencyManag
return true;
} else if (installProfile.containsKey("install") && installProfile.containsKey("versionInfo")) {
ForgeInstallProfile profile = JsonUtils.fromNonNullJson(installProfileText, ForgeInstallProfile.class);
if (!gameVersion.get().equals(profile.getInstall().getMinecraft()))
throw new VersionMismatchException(profile.getInstall().getMinecraft(), gameVersion.get());
if (!gameVersion.get().equals(profile.install().minecraft()))
throw new VersionMismatchException(profile.install().minecraft(), gameVersion.get());
return false;
} else {
throw new IOException();
Expand Down Expand Up @@ -167,9 +167,9 @@ public static Task<Version> install(DefaultDependencyManager dependencyManager,
return new ForgeNewInstallTask(dependencyManager, version, modifyVersion(gameVersion.get(), profile.getVersion()), installer);
} else if (installProfile.containsKey("install") && installProfile.containsKey("versionInfo")) {
ForgeInstallProfile profile = JsonUtils.fromNonNullJson(installProfileText, ForgeInstallProfile.class);
if (!gameVersion.get().equals(profile.getInstall().getMinecraft()))
throw new VersionMismatchException(profile.getInstall().getMinecraft(), gameVersion.get());
return new ForgeOldInstallTask(dependencyManager, version, modifyVersion(gameVersion.get(), profile.getInstall().getPath().getVersion().replaceAll("(?i)forge", "")), installer);
if (!gameVersion.get().equals(profile.install().minecraft()))
throw new VersionMismatchException(profile.install().minecraft(), gameVersion.get());
return new ForgeOldInstallTask(dependencyManager, version, modifyVersion(gameVersion.get(), profile.install().path().getVersion().replaceAll("(?i)forge", "")), installer);
} else {
throw new IOException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Map<String, String> getData() {
if (data == null)
return new HashMap<>();

return data.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getClient()));
return data.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().client()));
}

@Override
Expand Down Expand Up @@ -196,22 +196,12 @@ public void validate() throws JsonParseException, TolerableValidationException {
}
}

public static class Datum {
private final String client;

public Datum(String client) {
this.client = client;
}

/**
* Can be in the following formats:
* [value]: An artifact path.
* 'value': A string literal.
* value: A file in the installer package, to be extracted to a temp folder, and then have the absolute path in replacements.
* @return Value to use for the client install
*/
public String getClient() {
return client;
}
/// @param client Value to use for the client install.
///
/// Can be in the following formats:
/// - \[value]: An artifact path.
/// - 'value': A string literal.
/// - value: A file in the installer package, to be extracted to a temp folder, and then have the absolute path in replacements.
public record Datum(String client) {
}
}
Loading