Fix JSON Exception.
This commit is contained in:
@@ -88,12 +88,12 @@ public abstract class IMinecraftLoader {
|
||||
res.add("-Xmn128m");
|
||||
}
|
||||
|
||||
if (jv != null && jv.platform == Platform.BIT_32 && Platform.getPlatform() == Platform.BIT_64)
|
||||
if (jv != null && jv.getPlatform() == Platform.BIT_32 && Platform.getPlatform() == Platform.BIT_64)
|
||||
MessageBox.Show(C.i18n("advice.os64butjdk32"));
|
||||
|
||||
if (!StrUtils.isBlank(v.getMaxMemory())) {
|
||||
int mem = MathUtils.parseMemory(v.getMaxMemory(), 2147483647);
|
||||
if (jv != null && jv.platform == Platform.BIT_32 && mem > 1024)
|
||||
if (jv != null && jv.getPlatform() == Platform.BIT_32 && mem > 1024)
|
||||
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_64bit"));
|
||||
else {
|
||||
long a = OS.getTotalPhysicalMemory() / 1024 / 1024;
|
||||
@@ -107,7 +107,7 @@ public abstract class IMinecraftLoader {
|
||||
}
|
||||
|
||||
if (!StrUtils.isBlank(v.getPermSize()) && !v.isNoJVMArgs())
|
||||
if (jv != null && jv.ver != null && (jv.ver.startsWith("1.8") || jv.ver.startsWith("1.9")));
|
||||
if (jv != null && jv.getVersion() != null && (jv.getVersion().startsWith("1.8") || jv.getVersion().startsWith("1.9")));
|
||||
else res.add("-XX:MaxPermSize=" + v.getPermSize() + "m");
|
||||
|
||||
if (!v.isNoJVMArgs()) appendJVMArgs(res);
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.launcher.utils.settings;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -27,12 +25,10 @@ import java.util.Objects;
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.Main;
|
||||
import org.jackhuang.hellominecraft.utils.EnumAdapter;
|
||||
import org.jackhuang.hellominecraft.utils.tinystream.CollectionUtils;
|
||||
import org.jackhuang.hellominecraft.utils.FileUtils;
|
||||
import org.jackhuang.hellominecraft.utils.IOUtils;
|
||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||
import org.jackhuang.hellominecraft.utils.Platform;
|
||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
import org.jackhuang.hellominecraft.utils.UpdateChecker;
|
||||
import org.jackhuang.hellominecraft.utils.VersionNumber;
|
||||
@@ -44,7 +40,7 @@ import org.jackhuang.hellominecraft.utils.VersionNumber;
|
||||
public final class Settings {
|
||||
|
||||
public static final File settingsFile = new File(IOUtils.currentDir(), "hmcl.json");
|
||||
public static final Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Platform.class, new EnumAdapter<>(Platform.values())).create();
|
||||
//public static final Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Platform.class, new EnumAdapter<>(Platform.values())).create();
|
||||
|
||||
private static boolean isFirstLoad;
|
||||
private static final Config settings;
|
||||
@@ -75,7 +71,7 @@ public final class Settings {
|
||||
if (str == null || str.trim().equals(""))
|
||||
HMCLog.log("Settings file is empty, use the default settings.");
|
||||
else {
|
||||
Config d = gson.fromJson(str, Config.class);
|
||||
Config d = C.gsonPrettyPrinting.fromJson(str, Config.class);
|
||||
if (d != null) c = d;
|
||||
}
|
||||
HMCLog.log("Initialized settings.");
|
||||
@@ -96,7 +92,7 @@ public final class Settings {
|
||||
|
||||
public static void save() {
|
||||
try {
|
||||
FileUtils.write(settingsFile, gson.toJson(settings));
|
||||
FileUtils.write(settingsFile, C.gsonPrettyPrinting.toJson(settings));
|
||||
} catch (IOException ex) {
|
||||
HMCLog.err("Failed to save config", ex);
|
||||
}
|
||||
|
||||
@@ -31,13 +31,25 @@ import org.jackhuang.hellominecraft.HMCLog;
|
||||
*/
|
||||
public final class JdkVersion {
|
||||
|
||||
public String ver;
|
||||
private String ver;
|
||||
|
||||
public String getVersion() {
|
||||
return ver;
|
||||
}
|
||||
|
||||
public Platform getPlatform() {
|
||||
return Platform.values()[platform];
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
/**
|
||||
* -1 - unkown 0 - 32Bit 1 - 64Bit
|
||||
*/
|
||||
public Platform platform;
|
||||
private int platform;
|
||||
|
||||
public String location;
|
||||
private String location;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@@ -60,7 +72,7 @@ public final class JdkVersion {
|
||||
public JdkVersion(String location, String ver, Platform platform) {
|
||||
this(location);
|
||||
this.ver = ver;
|
||||
this.platform = platform;
|
||||
this.platform = platform.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,19 +106,18 @@ public final class JdkVersion {
|
||||
static {
|
||||
javaVersion = System.getProperty("java.version");
|
||||
// version String should look like "1.4.2_10"
|
||||
if (javaVersion.contains("1.9.")) {
|
||||
if (javaVersion.contains("1.9."))
|
||||
majorJavaVersion = JAVA_18;
|
||||
} else if (javaVersion.contains("1.8.")) {
|
||||
else if (javaVersion.contains("1.8."))
|
||||
majorJavaVersion = JAVA_18;
|
||||
} else if (javaVersion.contains("1.7.")) {
|
||||
else if (javaVersion.contains("1.7."))
|
||||
majorJavaVersion = JAVA_17;
|
||||
} else if (javaVersion.contains("1.6.")) {
|
||||
else if (javaVersion.contains("1.6."))
|
||||
majorJavaVersion = JAVA_16;
|
||||
} else {
|
||||
else
|
||||
// else leave 1.5 as default (it's either 1.5 or unknown)
|
||||
majorJavaVersion = JAVA_15;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the full Java version string, as returned by
|
||||
@@ -125,6 +136,7 @@ public final class JdkVersion {
|
||||
*
|
||||
*
|
||||
* rn a code comparable to the JAVA_XX codes in this class
|
||||
*
|
||||
* @return
|
||||
* @see #JAVA_13
|
||||
* @see #JAVA_14
|
||||
@@ -193,18 +205,16 @@ public final class JdkVersion {
|
||||
} catch (InterruptedException | IOException e) {
|
||||
HMCLog.warn("Failed to get java version", e);
|
||||
} finally {
|
||||
if (br != null) {
|
||||
if (br != null)
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
return new JdkVersion(file, ver, platform);
|
||||
}
|
||||
|
||||
public void write(File f) throws IOException {
|
||||
if (ver != null && platform != Platform.UNKNOWN) {
|
||||
if (ver != null && getPlatform() != Platform.UNKNOWN)
|
||||
FileUtils.write(f, ver + "\n" + platform);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEarlyAccess() {
|
||||
return ver != null && ver.endsWith("-ea");
|
||||
|
||||
Reference in New Issue
Block a user