Skip to content

Commit f63f888

Browse files
committed
crash report uploading system & fix crashing when no version here.
1 parent 70f0383 commit f63f888

File tree

8 files changed

+5616
-19
lines changed

8 files changed

+5616
-19
lines changed

HMCL/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if (!hasProperty('mainClass')) {
2828
def buildnumber = System.getenv("BUILD_NUMBER") == null ? "" : "."+System.getenv("BUILD_NUMBER")
2929

3030
String mavenGroupId = 'HMCL'
31-
String mavenVersion = '2.3.3' + buildnumber
31+
String mavenVersion = '2.3.4' + buildnumber
3232
String bundleName = "Hello Minecraft! Launcher"
3333

3434
group = mavenGroupId

HMCL/obfuscate_2.3.4.map

Lines changed: 5565 additions & 0 deletions
Large diffs are not rendered by default.

HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/Main.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.net.URI;
2828
import java.net.URISyntaxException;
2929
import java.text.ParseException;
30+
import java.util.Map;
3031
import javax.swing.ImageIcon;
3132
import javax.swing.UIManager;
3233
import javax.swing.UnsupportedLookAndFeelException;
@@ -44,6 +45,7 @@
4445
import org.jackhuang.hellominecraft.lookandfeel.HelloMinecraftLookAndFeel;
4546
import org.jackhuang.hellominecraft.utils.system.MessageBox;
4647
import org.jackhuang.hellominecraft.utils.StrUtils;
48+
import org.jackhuang.hellominecraft.utils.system.OS;
4749

4850
/**
4951
*
@@ -52,7 +54,7 @@
5254
public final class Main implements NonConsumer {
5355

5456
public static String launcherName = "Hello Minecraft! Launcher";
55-
public static byte firstVer = 2, secondVer = 3, thirdVer = 3;
57+
public static byte firstVer = 2, secondVer = 3, thirdVer = 4;
5658
public static int minimumLauncherVersion = 16;
5759

5860
/**
@@ -126,17 +128,25 @@ public void onDone() {
126128
public static void update() {
127129
if (MessageBox.Show(C.i18n("update.newest_version") + Settings.UPDATE_CHECKER.getNewVersion().firstVer + "." + Settings.UPDATE_CHECKER.getNewVersion().secondVer + "." + Settings.UPDATE_CHECKER.getNewVersion().thirdVer + "\n"
128130
+ C.i18n("update.should_open_link"),
129-
MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
131+
MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
132+
Map<String, String> map = Settings.UPDATE_CHECKER.download_link;
133+
String url = C.URL_PUBLISH;
134+
if (map != null)
135+
if (map.containsKey(OS.os().checked_name))
136+
url = map.get(OS.os().checked_name);
137+
else if (map.containsKey(OS.UNKOWN.checked_name))
138+
url = map.get(OS.UNKOWN.checked_name);
139+
if (url == null) url = C.URL_PUBLISH;
130140
try {
131-
java.awt.Desktop.getDesktop().browse(new URI(C.URL_PUBLISH));
141+
java.awt.Desktop.getDesktop().browse(new URI(url));
132142
} catch (URISyntaxException | IOException e) {
133-
HMCLog.warn("Failed to browse uri: " + C.URL_PUBLISH, e);
143+
HMCLog.warn("Failed to browse uri: " + url, e);
134144

135145
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
136-
cb.setContents(new StringSelection(C.URL_PUBLISH), null);
146+
cb.setContents(new StringSelection(url), null);
137147
MessageBox.Show(C.i18n("update.no_browser"));
138148
}
139-
else
149+
} else
140150
Settings.getInstance().setCheckUpdate(false);
141151
}
142152

HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/CrashReporter.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
import java.text.DateFormat;
2020
import java.util.Date;
21+
import java.util.HashMap;
2122
import javax.swing.SwingUtilities;
2223
import org.jackhuang.hellominecraft.HMCLog;
2324
import org.jackhuang.hellominecraft.launcher.Main;
2425
import org.jackhuang.hellominecraft.launcher.launch.MinecraftCrashAdvicer;
26+
import org.jackhuang.hellominecraft.utils.NetUtils;
2527
import org.jackhuang.hellominecraft.utils.UpdateChecker;
2628
import org.jackhuang.hellominecraft.utils.system.MessageBox;
2729
import org.jackhuang.hellominecraft.utils.StrUtils;
@@ -57,6 +59,8 @@ public void uncaughtException(Thread t, Throwable e) {
5759
if (enableLogger) HMCLog.err(text);
5860
else System.out.println(text);
5961
SwingUtilities.invokeLater(() -> LogWindow.instance.showAsCrashWindow(UpdateChecker.OUT_DATED));
62+
if (!UpdateChecker.OUT_DATED)
63+
reportToServer(text);
6064
} catch (Throwable ex) {
6165
try {
6266
MessageBox.Show(e.getMessage() + "\n" + ex.getMessage(), "ERROR", MessageBox.ERROR_MESSAGE);
@@ -67,4 +71,12 @@ public void uncaughtException(Thread t, Throwable e) {
6771
}
6872
}
6973

74+
void reportToServer(String text) {
75+
new Thread(() -> {
76+
HashMap<String, String> map = new HashMap<>();
77+
map.put("CrashReport", text);
78+
System.out.println(NetUtils.post("http://huangyuhui.duapp.com/crash.php", map));
79+
}).start();
80+
}
81+
7082
}

HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/version/MinecraftVersionManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.File;
2222
import java.io.IOException;
2323
import java.util.ArrayList;
24+
import java.util.Arrays;
2425
import java.util.Collection;
2526
import java.util.Collections;
2627
import java.util.LinkedList;
@@ -222,6 +223,7 @@ public File getRunDirectory(String id) {
222223

223224
@Override
224225
public List<ModInfo> listMods() {
226+
if (profile.getSelectedMinecraftVersion() == null) return Arrays.asList();
225227
File modsFolder = new File(getRunDirectory(profile.getSelectedMinecraftVersion().id), "mods");
226228
ArrayList<ModInfo> mods = new ArrayList<>();
227229
Queue<File> queue = new LinkedList<>();
@@ -235,9 +237,8 @@ public List<ModInfo> listMods() {
235237
ModInfo m = ModInfo.readModInfo(f);
236238
if (m != null)
237239
mods.add(m);
238-
} else if(f.isDirectory()) {
240+
} else if (f.isDirectory())
239241
queue.add(f);
240-
}
241242
}
242243
Collections.sort(mods);
243244
return mods;

HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/NetUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ public static String post(String url, Map<String, String> params) {
123123
}
124124
sb = new StringBuilder(sb.substring(0, sb.length() - 1));
125125
}
126-
System.out.println("send_url:" + url);
127-
System.out.println("send_data:" + sb.toString());
128126
try {
129127
u = new URL(url);
130128
con = (HttpURLConnection) u.openConnection();

HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/UpdateChecker.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.jackhuang.hellominecraft.utils;
1818

19+
import java.util.Map;
1920
import org.jackhuang.hellominecraft.utils.system.MessageBox;
2021
import org.jackhuang.hellominecraft.C;
2122
import org.jackhuang.hellominecraft.utils.functions.NonConsumer;
@@ -32,6 +33,7 @@ public final class UpdateChecker extends Thread {
3233
public String type;
3334
public boolean continueUpdate;
3435
public NonConsumer dl;
36+
public Map<String, String> download_link;
3537

3638
public UpdateChecker(VersionNumber base, String type, boolean continueUpdate, NonConsumer dl) {
3739
super("UpdateChecker");
@@ -46,9 +48,9 @@ public UpdateChecker(VersionNumber base, String type, boolean continueUpdate, No
4648
@Override
4749
public void run() {
4850

49-
String url = "http://huangyuhui.duapp.com/info.php?type=" + type, version;
51+
String version;
5052
try {
51-
version = NetUtils.doGet(url);
53+
version = NetUtils.doGet("http://huangyuhui.duapp.com/info.php?type=" + type);
5254
} catch (Exception e) {
5355
HMCLog.warn("Failed to get update url.", e);
5456
return;
@@ -57,6 +59,14 @@ public void run() {
5759
if (!continueUpdate)
5860
return;
5961
process(false);
62+
if (OUT_DATED) {
63+
try {
64+
download_link = C.gson.fromJson(NetUtils.doGet("http://huangyuhui.duapp.com/update_link.php?type=" + type), Map.class);
65+
} catch (Exception e) {
66+
HMCLog.warn("Failed to get update link.", e);
67+
}
68+
dl.onDone();
69+
}
6070
}
6171

6272
public void process(boolean showMessage) {
@@ -67,7 +77,6 @@ public void process(boolean showMessage) {
6777
} else
6878
if (VersionNumber.isOlder(base, value)) {
6979
OUT_DATED = true;
70-
dl.onDone();
7180
}
7281
}
7382

HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/system/OS.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525
*/
2626
public enum OS {
2727

28-
LINUX('/'),
29-
WINDOWS('\\'),
30-
OSX('/'),
31-
UNKOWN('/');
28+
LINUX('/', "linux"),
29+
WINDOWS('\\', "windows"),
30+
OSX('/', "osx"),
31+
UNKOWN('/', "universal");
3232

3333
public final char fileSeparator;
34+
public final String checked_name;
3435

35-
private OS(char fileSeparator) {
36+
private OS(char fileSeparator, String n) {
3637
this.fileSeparator = fileSeparator;
38+
checked_name = n;
3739
}
3840

3941
public static OS os() {

0 commit comments

Comments
 (0)