diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/CrashReporter.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/CrashReporter.java index 9928153bd..7d9850b07 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/CrashReporter.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/CrashReporter.java @@ -1,7 +1,7 @@ /* * Hello Minecraft! Launcher. * Copyright (C) 2013 huangyuhui - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -30,6 +30,7 @@ import org.jackhuang.hellominecraft.launcher.settings.Settings; import org.jackhuang.hellominecraft.utils.NetUtils; import org.jackhuang.hellominecraft.utils.MessageBox; import org.jackhuang.hellominecraft.utils.StrUtils; +import org.jackhuang.hellominecraft.utils.system.OS; import org.jackhuang.hellominecraft.views.LogWindow; /** @@ -96,7 +97,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler { text += "\n Content: \n "; text += s + "\n\n"; text += "-- System Details --\n"; - text += " Operating System: " + System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ") version " + System.getProperty("os.version") + "\n"; + text += " Operating System: " + OS.getSystemVersion() + "\n"; text += " Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + "\n"; text += " Java VM Version: " + System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor") + "\n"; if (enableLogger) diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/InstallerPanel.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/InstallerPanel.java index 267474728..a2abddf88 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/InstallerPanel.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/InstallerPanel.java @@ -43,7 +43,7 @@ public class InstallerPanel extends AnimatedPanel implements Selectable { /** * Creates new form InstallerPanel * - * @param gsp To get the minecraft version + * @param gsp To get the minecraft version * @param installerType load which installer */ public InstallerPanel(GameSettingsPanel gsp, InstallerType installerType) { @@ -56,10 +56,9 @@ public class InstallerPanel extends AnimatedPanel implements Selectable { } /** - * This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents @@ -125,7 +124,7 @@ public class InstallerPanel extends AnimatedPanel implements Selectable { void refreshVersions() { if (TaskWindow.getInstance().addTask(new TaskRunnableArg1<>(C.i18n("install." + id.id + ".get_list"), list) - .registerPreviousResult(new DefaultPreviousResult<>(new String[] {gsp.getMinecraftVersionFormatted()}))) + .registerPreviousResult(new DefaultPreviousResult<>(new String[]{gsp.getMinecraftVersionFormatted()}))) .start()) loadVersions(); } @@ -152,7 +151,8 @@ public class InstallerPanel extends AnimatedPanel implements Selectable { SwingUtils.clearDefaultTable(lstInstallers); if (versions != null) for (InstallerVersionList.InstallerVersion v : versions) - model.addRow(new Object[] {v.selfVersion == null ? "null" : v.selfVersion, v.mcVersion == null ? "null" : v.mcVersion}); + if (v != null) + model.addRow(new Object[]{v.selfVersion == null ? "null" : v.selfVersion, v.mcVersion == null ? "null" : v.mcVersion}); } }); } diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/StrUtils.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/StrUtils.java index 9129e7178..9a7080440 100755 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/StrUtils.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/StrUtils.java @@ -1,7 +1,7 @@ /* * Hello Minecraft! Launcher. * Copyright (C) 2013 huangyuhui - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -87,6 +87,13 @@ public final class StrUtils { return false; } + public static boolean containsOne(String base, String... match) { + for (String s : match) + if (base.contains(s)) + return true; + return false; + } + public static boolean containsOne(List base, List match) { for (String a : base) for (String b : match) diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/system/OS.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/system/OS.java index b358bbe0a..084fb2b50 100755 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/system/OS.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/system/OS.java @@ -26,6 +26,7 @@ import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.util.StringTokenizer; import org.jackhuang.hellominecraft.HMCLog; +import org.jackhuang.hellominecraft.utils.StrUtils; /** * @author huangyuhui @@ -108,4 +109,18 @@ public enum OS { return result; } + public static String getLinuxReleaseVersion() throws IOException { + return FileUtils.readFileToString(new File("/etc/issue")); + } + + public static String getSystemVersion() { + if (os() == LINUX) + try { + return getLinuxReleaseVersion(); + } catch (IOException e) { + HMCLog.warn("Failed to catch /etc/issue"); + } + return System.getProperty("os.name") + " (" + System.getProperty("os.arch") + "), " + System.getProperty("os.version"); + } + } diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/views/SwingUtils.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/views/SwingUtils.java index 8603a8a18..c85f6aabd 100755 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/views/SwingUtils.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/views/SwingUtils.java @@ -22,6 +22,9 @@ import java.awt.FontMetrics; import java.io.File; import java.io.IOException; import java.net.URI; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import javax.swing.DefaultListModel; import javax.swing.JLabel; import javax.swing.JList; @@ -222,12 +225,19 @@ public class SwingUtils { return builder.toString(); } - private static final ThreadLocal THREAD_LOCAL = new ThreadLocal<>(); + private static final Map INVOKE_AND_WAIT_MAP = Collections.synchronizedMap(new HashMap<>()); + private static int INVOKE_AND_WAIT_ID = 0; + private static final Object INVOKE_AND_WAIT_LOCK = new Object(); public static T invokeAndWait(NonFunction x) { - Runnable r = () -> THREAD_LOCAL.set(x.apply()); + int id; + synchronized (INVOKE_AND_WAIT_LOCK) { + id = ++INVOKE_AND_WAIT_ID; + } + int fuck = id; + Runnable r = () -> INVOKE_AND_WAIT_MAP.put(fuck, x.apply()); invokeAndWait(r); - return (T) THREAD_LOCAL.get(); + return (T) INVOKE_AND_WAIT_MAP.remove(id); } public static void invokeAndWait(Runnable r) { diff --git a/MetroLookAndFeel/src/main/java/org/jackhuang/hellominecraft/lookandfeel/painters/ProgressPainter.java b/MetroLookAndFeel/src/main/java/org/jackhuang/hellominecraft/lookandfeel/painters/ProgressPainter.java index c7eda851f..b6fb06de8 100755 --- a/MetroLookAndFeel/src/main/java/org/jackhuang/hellominecraft/lookandfeel/painters/ProgressPainter.java +++ b/MetroLookAndFeel/src/main/java/org/jackhuang/hellominecraft/lookandfeel/painters/ProgressPainter.java @@ -37,13 +37,13 @@ import java.awt.LinearGradientPaint; */ public class ProgressPainter extends SynthPainter { - private static final float[] NORMAL_BG_PTS = new float[] {0, 1}; - private static final Color[] NORMAL_BG = new Color[] { + private static final float[] NORMAL_BG_PTS = new float[]{0, 1}; + private static final Color[] NORMAL_BG = new Color[]{ GraphicsUtils.getWebColor("c6c6c6"), GraphicsUtils.getWebColor("c6c6c6") }; - private static final float[] BAR_FG_PTS = new float[] {0, 1}; - private static final Color[] BAR_FG = new Color[] { + private static final float[] BAR_FG_PTS = new float[]{0, 1}; + private static final Color[] BAR_FG = new Color[]{ GraphicsUtils.getWebColor("41B1E1"), GraphicsUtils.getWebColor("41B1E1") }; @@ -69,7 +69,7 @@ public class ProgressPainter extends SynthPainter { Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(new LinearGradientPaint(x, y + 2, x, y + h - 2, BAR_FG_PTS, BAR_FG)); if (x + 2 < w - 5 && y + 2 < h - 5) - g2.drawRect(x + 2, y + 2, w - 5, h - 5); + g2.fillRect(x + 2, y + 2, w - 5, h - 5); } /**