Skip to content
Merged
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
38 changes: 36 additions & 2 deletions src/main/java/me/itzg/helpers/forge/ForgeInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static me.itzg.helpers.http.Fetch.fetch;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -44,6 +45,8 @@ public class ForgeInstaller {
+ "|The server installed successfully, you should now be able to run the file (?<universalJar>.+)");
public static final String MANIFEST_ID = "forge";

private static final Pattern OLD_FORGE_ID_VERSION = Pattern.compile("Forge(.+)");

@AllArgsConstructor
private static class VersionPair {
String minecraft;
Expand Down Expand Up @@ -148,9 +151,9 @@ else if (
private VersionPair extractVersion(Path forgeInstaller) throws IOException {

// Extract version from installer jar's version.json file
// where top level "id" field looks like "1.12.2-forge-14.23.5.2859"
// where top level "id" field is used

return IoStreams.readFileFromZip(forgeInstaller, "version.json", inputStream -> {
final VersionPair fromVersionJson = IoStreams.readFileFromZip(forgeInstaller, "version.json", inputStream -> {
final ObjectNode parsed = ObjectMappers.defaultMapper()
.readValue(inputStream, ObjectNode.class);

Expand All @@ -163,6 +166,37 @@ private VersionPair extractVersion(Path forgeInstaller) throws IOException {

return new VersionPair(idParts[0], idParts[2]);
});
if (fromVersionJson != null) {
return fromVersionJson;
}

return IoStreams.readFileFromZip(forgeInstaller, "install_profile.json", inputStream -> {
final ObjectNode parsed = ObjectMappers.defaultMapper()
.readValue(inputStream, ObjectNode.class);

final JsonNode idNode = parsed.path("versionInfo").path("id");
if (idNode.isTextual()) {
// such as "1.7.10-Forge10.13.4.1614-1.7.10"
final String[] idParts = idNode.asText().split("-");

if (idParts.length == 3) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the forge versions only have length 2 here. 1.7.10 sure had an annoying extra bit in the filename.
Here's 1.5.2:

  "versionInfo": {
    "id": "1.5.2-Forge7.8.1.738",

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great investigation. As I mentioned over in the issue, it would be awesome if you could PR the fix for this. Just reference the same issue as before.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (idParts.length == 3) {
if (idParts.length == 2 || idParts.length == 3) {

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code suggestions can't be applied after the PR is merged. Can you create a new PR with this?

final Matcher m = OLD_FORGE_ID_VERSION.matcher(idParts[1]);
if (m.matches()) {
return new VersionPair(idParts[0], m.group(1));
}
else {
throw new GenericException("Unexpected format of id from Forge installer's install_profile.json: " + idNode.asText());
}
}
else {
throw new GenericException("Unexpected format of id from Forge installer's install_profile.json: " + idNode.asText());
}
}
else {
throw new GenericException("install_profile.json seems to be missing versionInfo.id");

}
});
}

private ForgeManifest loadManifest(Path outputDir) throws IOException {
Expand Down