|
20 | 20 | import com.google.gson.JsonParseException; |
21 | 21 | import com.google.gson.annotations.SerializedName; |
22 | 22 | import com.google.gson.reflect.TypeToken; |
| 23 | +import com.google.gson.stream.JsonReader; |
| 24 | +import com.google.gson.stream.JsonToken; |
23 | 25 | import com.tungsten.fclcore.mod.LocalModFile; |
24 | 26 | import com.tungsten.fclcore.mod.ModLoaderType; |
25 | 27 | import com.tungsten.fclcore.mod.ModManager; |
@@ -119,11 +121,26 @@ public static LocalModFile fromFile(ModManager modManager, Path modFile, FileSys |
119 | 121 | Path mcmod = fs.getPath("mcmod.info"); |
120 | 122 | if (Files.notExists(mcmod)) |
121 | 123 | throw new IOException("File " + modFile + " is not a Forge mod."); |
122 | | - List<ForgeOldModMetadata> modList = JsonUtils.GSON.fromJson(FileUtils.readText(mcmod), |
123 | | - new TypeToken<List<ForgeOldModMetadata>>() { |
| 124 | + List<ForgeOldModMetadata> modList; |
| 125 | + |
| 126 | + try (var reader = Files.newBufferedReader(mcmod); |
| 127 | + var jsonReader = new JsonReader(reader)) { |
| 128 | + JsonToken firstToken = jsonReader.peek(); |
| 129 | + |
| 130 | + if (firstToken == JsonToken.BEGIN_ARRAY) |
| 131 | + modList = JsonUtils.GSON.fromJson(jsonReader, new TypeToken<List<ForgeOldModMetadata>>() { |
124 | 132 | }.getType()); |
| 133 | + else if (firstToken == JsonToken.BEGIN_OBJECT) { |
| 134 | + ForgeOldModMetadataLst list = JsonUtils.GSON.fromJson(jsonReader, ForgeOldModMetadataLst.class); |
| 135 | + if (list == null) |
| 136 | + throw new IOException("Mod " + modFile + " `mcmod.info` is malformed"); |
| 137 | + modList = list.getModList(); |
| 138 | + } else { |
| 139 | + throw new JsonParseException("Unexpected first token: " + firstToken); |
| 140 | + } |
| 141 | + } |
125 | 142 | if (modList == null || modList.isEmpty()) |
126 | | - throw new IOException("Mod " + modFile + " `mcmod.info` is malformed.."); |
| 143 | + throw new IOException("Mod " + modFile + " `mcmod.info` is malformed"); |
127 | 144 | ForgeOldModMetadata metadata = modList.get(0); |
128 | 145 | String authors = metadata.getAuthor(); |
129 | 146 | if (StringUtils.isBlank(authors) && metadata.getAuthors().length > 0) |
|
0 commit comments