From d87b768fc0c1f37716c74166e5fbb8332accd7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=97=E5=AE=AB=E4=B8=B4=E9=A3=8E?= Date: Thu, 7 Jul 2016 18:01:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A8=A1=E7=BB=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/core/mod/ModInfo.java | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/mod/ModInfo.java b/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/mod/ModInfo.java index f508b2acc..5de1ab074 100755 --- a/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/mod/ModInfo.java +++ b/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/mod/ModInfo.java @@ -17,13 +17,15 @@ */ package org.jackhuang.hellominecraft.launcher.core.mod; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import java.lang.reflect.Type; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -60,6 +62,8 @@ public class ModInfo implements Comparable { public String credits; @SerializedName("authorList") public String[] authorList; + @SerializedName("authors") + public String[] authors; public boolean isActive() { return !location.getName().endsWith(".disabled"); @@ -87,6 +91,8 @@ public class ModInfo implements Comparable { public String getAuthor() { if (authorList != null && authorList.length > 0) return StrUtils.parseParams("", authorList, ", "); + else if (authors != null && authors.length > 0) + return StrUtils.parseParams("", authors, ", "); else if (StrUtils.isNotBlank(author)) return author; else @@ -123,18 +129,30 @@ public class ModInfo implements Comparable { return name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith("litemod"); } - private static final Type TYPE = new TypeToken>() { - }.getType(); - private static ModInfo getForgeModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException { - ModInfo i = new ModInfo(); - i.location = f; - List m = C.GSON.fromJson(new InputStreamReader(jar.getInputStream(entry), "UTF-8"), TYPE); - if (m != null && m.size() > 0) { - i = m.get(0); - i.location = f; - } - return i; + ModInfo i = new ModInfo(); + i.location = f; + + InputStreamReader streamReader = new InputStreamReader(jar.getInputStream(entry), "UTF-8"); + + JsonParser parser = new JsonParser(); + JsonElement element = parser.parse(streamReader); + List m = null; + if (element.isJsonArray()) { + m = C.GSON.fromJson(element, new TypeToken>(){}.getType()); + } else if (element.isJsonObject()) { + JsonObject modInfo = element.getAsJsonObject(); + if (modInfo.has("modList") && modInfo.get("modList").isJsonArray()) { + m = C.GSON.fromJson(modInfo.get("modList"), new TypeToken>(){}.getType()); + } + } + + if (m != null && m.size() > 0) { + i = m.get(0); + i.location = f; + } + + return i; } private static ModInfo getLiteLoaderModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException {