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