From 5af83d6f8430023c4f6d5d5b48feb5bed149f4a1 Mon Sep 17 00:00:00 2001 From: jn_xyp Date: Thu, 7 Oct 2021 00:09:25 +0800 Subject: [PATCH] Fixed problem reading mod version with dict values --- .idea/misc.xml | 2 +- config.exe4j | 19 +++++++++++++++++++ .../jnxyp/fossic/crashreporter/Config.java | 4 +++- src/net/jnxyp/fossic/crashreporter/Main.java | 1 - .../collectors/ModInfoCollector.java | 12 ++++++++++-- .../collectors/SystemInfoCollector.java | 10 ++++------ 6 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 config.exe4j diff --git a/.idea/misc.xml b/.idea/misc.xml index 5182650..0548357 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/config.exe4j b/config.exe4j new file mode 100644 index 0000000..35a602e --- /dev/null +++ b/config.exe4j @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/net/jnxyp/fossic/crashreporter/Config.java b/src/net/jnxyp/fossic/crashreporter/Config.java index 95465e6..ee63cf3 100644 --- a/src/net/jnxyp/fossic/crashreporter/Config.java +++ b/src/net/jnxyp/fossic/crashreporter/Config.java @@ -8,7 +8,7 @@ public final class Config { public static final String PROGRAM_NAME = "远行星号 报错信息收集工具"; - public static final String PROGRAM_VERSION = "1.0.4"; + public static final String PROGRAM_VERSION = "1.0.5"; public static final Pattern JSON_COMMENTS_PATTERN = Pattern.compile("#.*$", Pattern.MULTILINE); @@ -35,6 +35,8 @@ public final class Config { public static final Charset MOD_INFO_CHARSET = StandardCharsets.UTF_8; public static final Charset ENABLED_MOD_LIST_CHARSET = StandardCharsets.UTF_8; +// public static final int UI_FONT_SIZE = 18; + private Config() { } diff --git a/src/net/jnxyp/fossic/crashreporter/Main.java b/src/net/jnxyp/fossic/crashreporter/Main.java index becccba..330c524 100644 --- a/src/net/jnxyp/fossic/crashreporter/Main.java +++ b/src/net/jnxyp/fossic/crashreporter/Main.java @@ -1,5 +1,4 @@ package net.jnxyp.fossic.crashreporter; - import java.nio.file.Paths; public class Main { diff --git a/src/net/jnxyp/fossic/crashreporter/collectors/ModInfoCollector.java b/src/net/jnxyp/fossic/crashreporter/collectors/ModInfoCollector.java index dafceaa..ee774b1 100644 --- a/src/net/jnxyp/fossic/crashreporter/collectors/ModInfoCollector.java +++ b/src/net/jnxyp/fossic/crashreporter/collectors/ModInfoCollector.java @@ -56,7 +56,7 @@ public boolean accept(File pathname) { enabledModIds.add(array.getString(i)); } } catch (IOException e) { - throw new InfoCollectionPartialFailureException(this, String.format("在读取已启用Mod列表文件 %s 时发生错误", enabledModListFile.toPath().toString()), e); + throw new InfoCollectionPartialFailureException(this, String.format("在读取已启用Mod列表文件 %s 时发生错误", enabledModListFile.toPath()), e); } for (ModInfo info : mods) { @@ -95,10 +95,18 @@ public ModInfo(String id, String name, String version, String gameVersion, boole public static ModInfo fromModInfoFile(File modInfoFile) throws IOException { String modInfoString = Util.readFile(modInfoFile, Config.MOD_INFO_CHARSET); JSONObject dict = Util.parseJson(modInfoString); + Object versionObj = dict.get("version"); + String version = ""; + if (versionObj instanceof String) { + version = (String) versionObj; + } else if (versionObj instanceof JSONObject) { + JSONObject v = (JSONObject) versionObj; + version = String.format("%d.%d.%d", v.getInt("major"), v.getInt("minor"), v.getInt("patch")); + } return new ModInfo( dict.getString("id"), dict.getString("name"), - dict.getString("version"), + version, dict.getString("gameVersion"), false); } diff --git a/src/net/jnxyp/fossic/crashreporter/collectors/SystemInfoCollector.java b/src/net/jnxyp/fossic/crashreporter/collectors/SystemInfoCollector.java index 23288da..ebd9146 100644 --- a/src/net/jnxyp/fossic/crashreporter/collectors/SystemInfoCollector.java +++ b/src/net/jnxyp/fossic/crashreporter/collectors/SystemInfoCollector.java @@ -19,13 +19,11 @@ public String getName() { public String getRawInfo() throws InfoCollectionPartialFailureException { String javaVersion = System.getProperty("java.version"); String javaPath = System.getProperty("java.home"); - StringBuilder builder = new StringBuilder(); - builder.append(getWarning(javaVersion, javaPath)) - .append(String.format("Java版本:\t`%s`\n\n", javaVersion)) - .append(String.format("Java路径:\t%s\n\n", javaPath)) - .append(String.format("虚拟机参数:\t%s", getVmparams())); - return builder.toString(); + return getWarning(javaVersion, javaPath) + + String.format("Java版本:\t`%s`\n\n", javaVersion) + + String.format("Java路径:\t%s\n\n", javaPath) + + String.format("虚拟机参数:\t%s", getVmparams()); } protected String getVmparams() throws InfoCollectionPartialFailureException {