修正模组信息解析问题
This commit is contained in:
@@ -17,13 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.launcher.core.mod;
|
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.JsonSyntaxException;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
@@ -60,6 +62,8 @@ public class ModInfo implements Comparable<ModInfo> {
|
|||||||
public String credits;
|
public String credits;
|
||||||
@SerializedName("authorList")
|
@SerializedName("authorList")
|
||||||
public String[] authorList;
|
public String[] authorList;
|
||||||
|
@SerializedName("authors")
|
||||||
|
public String[] authors;
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return !location.getName().endsWith(".disabled");
|
return !location.getName().endsWith(".disabled");
|
||||||
@@ -87,6 +91,8 @@ public class ModInfo implements Comparable<ModInfo> {
|
|||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
if (authorList != null && authorList.length > 0)
|
if (authorList != null && authorList.length > 0)
|
||||||
return StrUtils.parseParams("", authorList, ", ");
|
return StrUtils.parseParams("", authorList, ", ");
|
||||||
|
else if (authors != null && authors.length > 0)
|
||||||
|
return StrUtils.parseParams("", authors, ", ");
|
||||||
else if (StrUtils.isNotBlank(author))
|
else if (StrUtils.isNotBlank(author))
|
||||||
return author;
|
return author;
|
||||||
else
|
else
|
||||||
@@ -123,17 +129,29 @@ public class ModInfo implements Comparable<ModInfo> {
|
|||||||
return name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith("litemod");
|
return name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith("litemod");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Type TYPE = new TypeToken<List<ModInfo>>() {
|
|
||||||
}.getType();
|
|
||||||
|
|
||||||
private static ModInfo getForgeModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException {
|
private static ModInfo getForgeModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException {
|
||||||
ModInfo i = new ModInfo();
|
ModInfo i = new ModInfo();
|
||||||
i.location = f;
|
i.location = f;
|
||||||
List<ModInfo> m = C.GSON.fromJson(new InputStreamReader(jar.getInputStream(entry), "UTF-8"), TYPE);
|
|
||||||
|
InputStreamReader streamReader = new InputStreamReader(jar.getInputStream(entry), "UTF-8");
|
||||||
|
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
JsonElement element = parser.parse(streamReader);
|
||||||
|
List<ModInfo> m = null;
|
||||||
|
if (element.isJsonArray()) {
|
||||||
|
m = C.GSON.fromJson(element, new TypeToken<List<ModInfo>>(){}.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<List<ModInfo>>(){}.getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m != null && m.size() > 0) {
|
if (m != null && m.size() > 0) {
|
||||||
i = m.get(0);
|
i = m.get(0);
|
||||||
i.location = f;
|
i.location = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user