修复无法识别部分旧版本 Forge 模组的问题 (#4658)
This commit is contained in:
@@ -19,6 +19,8 @@ package org.jackhuang.hmcl.mod.modinfo;
|
|||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
import org.jackhuang.hmcl.mod.LocalModFile;
|
import org.jackhuang.hmcl.mod.LocalModFile;
|
||||||
import org.jackhuang.hmcl.mod.ModLoaderType;
|
import org.jackhuang.hmcl.mod.ModLoaderType;
|
||||||
import org.jackhuang.hmcl.mod.ModManager;
|
import org.jackhuang.hmcl.mod.ModManager;
|
||||||
@@ -125,9 +127,27 @@ public final class ForgeOldModMetadata {
|
|||||||
Path mcmod = fs.getPath("mcmod.info");
|
Path mcmod = fs.getPath("mcmod.info");
|
||||||
if (Files.notExists(mcmod))
|
if (Files.notExists(mcmod))
|
||||||
throw new IOException("File " + modFile + " is not a Forge mod.");
|
throw new IOException("File " + modFile + " is not a Forge mod.");
|
||||||
List<ForgeOldModMetadata> modList = JsonUtils.fromJsonFile(mcmod, listTypeOf(ForgeOldModMetadata.class));
|
|
||||||
|
List<ForgeOldModMetadata> modList;
|
||||||
|
|
||||||
|
try (var reader = Files.newBufferedReader(mcmod);
|
||||||
|
var jsonReader = new JsonReader(reader)) {
|
||||||
|
JsonToken firstToken = jsonReader.peek();
|
||||||
|
|
||||||
|
if (firstToken == JsonToken.BEGIN_ARRAY)
|
||||||
|
modList = JsonUtils.GSON.fromJson(jsonReader, listTypeOf(ForgeOldModMetadata.class));
|
||||||
|
else if (firstToken == JsonToken.BEGIN_OBJECT) {
|
||||||
|
ForgeOldModMetadataLst list = JsonUtils.GSON.fromJson(jsonReader, ForgeOldModMetadataLst.class);
|
||||||
|
if (list == null)
|
||||||
|
throw new IOException("Mod " + modFile + " `mcmod.info` is malformed");
|
||||||
|
modList = list.modList();
|
||||||
|
} else {
|
||||||
|
throw new JsonParseException("Unexpected first token: " + firstToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (modList == null || modList.isEmpty())
|
if (modList == null || modList.isEmpty())
|
||||||
throw new IOException("Mod " + modFile + " `mcmod.info` is malformed..");
|
throw new IOException("Mod " + modFile + " `mcmod.info` is malformed");
|
||||||
ForgeOldModMetadata metadata = modList.get(0);
|
ForgeOldModMetadata metadata = modList.get(0);
|
||||||
String authors = metadata.getAuthor();
|
String authors = metadata.getAuthor();
|
||||||
if (StringUtils.isBlank(authors) && metadata.getAuthors().length > 0)
|
if (StringUtils.isBlank(authors) && metadata.getAuthors().length > 0)
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher
|
||||||
|
* Copyright (C) 2025 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.modinfo;
|
||||||
|
|
||||||
|
import org.jackhuang.hmcl.util.gson.JsonSerializable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// @author Glavo
|
||||||
|
@JsonSerializable
|
||||||
|
public record ForgeOldModMetadataLst(
|
||||||
|
int modListVersion,
|
||||||
|
List<ForgeOldModMetadata> modList) {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user