diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftLoader.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftLoader.java index 3411fd149..15f0ff2a8 100644 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftLoader.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/launch/IMinecraftLoader.java @@ -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); diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/settings/Settings.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/settings/Settings.java index 2f3a0cda9..5dc2e8748 100644 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/settings/Settings.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/settings/Settings.java @@ -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); } diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/JdkVersion.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/JdkVersion.java index ab2b52015..5f34aa93d 100644 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/JdkVersion.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/JdkVersion.java @@ -31,18 +31,30 @@ 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; - - public String location; + private int platform; + + private String location; @Override public boolean equals(Object obj) { - if(!(obj instanceof JdkVersion)) return false; - JdkVersion b = (JdkVersion)obj; + if (!(obj instanceof JdkVersion)) return false; + JdkVersion b = (JdkVersion) obj; return new File(b.location).equals(new File(location)); } @@ -53,14 +65,14 @@ public final class JdkVersion { public JdkVersion(String 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(); } public JdkVersion(String location, String ver, Platform platform) { this(location); this.ver = ver; - this.platform = platform; + this.platform = platform.ordinal(); } /** @@ -94,18 +106,17 @@ 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; - } } /** @@ -125,7 +136,8 @@ public final class JdkVersion { * * * rn a code comparable to the JAVA_XX codes in this class - * @return + * + * @return * @see #JAVA_13 * @see #JAVA_14 * @see #JAVA_15 @@ -193,19 +205,17 @@ 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"); }