This commit is contained in:
huanghongxun
2015-08-14 21:23:50 +08:00
parent a5388e790f
commit a77275cfc0
14 changed files with 100 additions and 66 deletions

View File

@@ -54,7 +54,7 @@ import org.jackhuang.hellominecraft.utils.system.OS;
public final class Main implements NonConsumer {
public static String launcherName = "Hello Minecraft! Launcher";
public static byte firstVer = 2, secondVer = 3, thirdVer = 4;
public static byte firstVer = 2, secondVer = 3, thirdVer = 4, forthVer = 10;
public static int minimumLauncherVersion = 16;
/**

View File

@@ -26,7 +26,6 @@ import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.tasks.ParallelTask;
import org.jackhuang.hellominecraft.tasks.TaskWindow;
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.system.Compressor;
import org.jackhuang.hellominecraft.utils.system.MessageBox;
@@ -46,10 +45,9 @@ public class DefaultGameLauncher extends GameLauncher {
downloadLibrariesEvent.register((sender, t) -> {
final TaskWindow dw = TaskWindow.getInstance();
ParallelTask parallelTask = new ParallelTask();
for (DownloadLibraryJob s : t) {
for (DownloadLibraryJob s : t)
//parallelTask.addDependsTask(new FileDownloadTask(s.url, s.path).setTag(s.name));
parallelTask.addDependsTask(new LibraryDownloadTask(s));
}
dw.addTask(parallelTask);
boolean flag = true;
if (t.size() > 0) flag = dw.start();
@@ -58,6 +56,7 @@ public class DefaultGameLauncher extends GameLauncher {
return flag;
});
decompressNativesEvent.register((sender, value) -> {
if (value == null) return false;
for (int i = 0; i < value.decompressFiles.length; i++)
try {
Compressor.unzip(value.decompressFiles[i], value.decompressTo, value.extractRules[i]);

View File

@@ -62,10 +62,10 @@ public final class Settings {
static {
settings = initSettings();
if (!getVersions().containsKey(DEFAULT_PROFILE))
getVersions().put(DEFAULT_PROFILE, new Profile());
if (!getProfiles().containsKey(DEFAULT_PROFILE))
getProfiles().put(DEFAULT_PROFILE, new Profile());
for (Profile e : getVersions().values())
for (Profile e : getProfiles().values())
e.checkFormat();
UPDATE_CHECKER = new UpdateChecker(new VersionNumber(Main.firstVer, Main.secondVer, Main.thirdVer),
@@ -116,42 +116,42 @@ public final class Settings {
}
}
public static Profile getVersion(String name) {
return getVersions().get(name);
public static Profile getProfile(String name) {
return getProfiles().get(name);
}
public static Map<String, Profile> getVersions() {
public static Map<String, Profile> getProfiles() {
return settings.getConfigurations();
}
public static void setVersion(Profile ver) {
getVersions().put(ver.getName(), ver);
public static void setProfile(Profile ver) {
getProfiles().put(ver.getName(), ver);
}
public static Collection<Profile> getProfiles() {
return CollectionUtils.sortOut(getVersions().values(), (t) -> t != null && t.getName() != null);
public static Collection<Profile> getProfilesFiltered() {
return CollectionUtils.sortOut(getProfiles().values(), (t) -> t != null && t.getName() != null);
}
public static Profile getOneProfile() {
return settings.getConfigurations().firstEntry().getValue();
}
public static boolean trySetVersion(Profile ver) {
if (ver == null || ver.getName() == null || getVersions().containsKey(ver.getName()))
public static boolean trySetProfile(Profile ver) {
if (ver == null || ver.getName() == null || getProfiles().containsKey(ver.getName()))
return false;
getVersions().put(ver.getName(), ver);
getProfiles().put(ver.getName(), ver);
return true;
}
public static boolean delVersion(Profile ver) {
return delVersion(ver.getName());
public static boolean delProfile(Profile ver) {
return delProfile(ver.getName());
}
public static boolean delVersion(String ver) {
public static boolean delProfile(String ver) {
if (DEFAULT_PROFILE.equals(ver)) {
MessageBox.Show(C.i18n("settings.cannot_remove_default_config"));
return false;
}
return getVersions().remove(ver) != null;
return getProfiles().remove(ver) != null;
}
}

View File

@@ -16,14 +16,14 @@
*/
package org.jackhuang.hellominecraft.launcher.utils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.launch.MinecraftCrashAdvicer;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.UpdateChecker;
import org.jackhuang.hellominecraft.utils.system.MessageBox;
@@ -42,17 +42,38 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
this.enableLogger = enableLogger;
}
public boolean checkThrowable(Throwable e) {
String s = StrUtils.getStackTrace(e);
if(s.contains("sun.awt.shell.Win32ShellFolder2") || s.contains("UnsatisfiedLinkError")) {
System.out.println(C.i18n("crash.user_fault"));
try {
MessageBox.Show(C.i18n("crash.user_fault"));
} catch(Throwable t) {
t.printStackTrace();
}
return false;
} else if(s.contains("java.awt.HeadlessException")) {
System.out.println(C.i18n("crash.headless"));
try {
MessageBox.Show(C.i18n("crash.headless"));
} catch(Throwable t) {
}
}
return true;
}
@Override
public void uncaughtException(Thread t, Throwable e) {
if (!checkThrowable(e)) return;
String s = StrUtils.getStackTrace(e);
if (!s.contains("org.jackhuang.hellominecraft")) return;
try {
String text = "\n---- Hello Minecraft! Crash Report ----\n";
text += " Version: " + Main.makeVersion() + "\n";
text += " Time: " + DateFormat.getDateInstance().format(new Date()) + "\n";
text += " Version: " + Main.makeVersion() + "." + Main.forthVer + "\n";
text += " Time: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "\n";
text += " Thread: " + t.toString() + "\n";
text += "\n Advice: \n ";
text += MinecraftCrashAdvicer.getAdvice(StrUtils.getStackTrace(e), true);
text += "\n Content: \n ";
text += StrUtils.getStackTrace(e) + "\n\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 += " Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + "\n";
@@ -61,7 +82,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
else System.out.println(text);
SwingUtilities.invokeLater(() -> LogWindow.instance.showAsCrashWindow(UpdateChecker.OUT_DATED));
if (!UpdateChecker.OUT_DATED)
reportToServer(text, e);
reportToServer(text, s);
} catch (Throwable ex) {
try {
MessageBox.Show(e.getMessage() + "\n" + ex.getMessage(), "ERROR", MessageBox.ERROR_MESSAGE);
@@ -74,10 +95,9 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
private static final HashSet<String> throwableSet = new HashSet<>();
void reportToServer(String text, Throwable t) {
String s = StrUtils.getStackTrace(t);
if (throwableSet.contains(s)) return;
throwableSet.add(s);
void reportToServer(String text, String stacktrace) {
if (throwableSet.contains(stacktrace)) return;
throwableSet.add(stacktrace);
new Thread(() -> {
HashMap<String, String> map = new HashMap<>();
map.put("CrashReport", text);

View File

@@ -18,6 +18,7 @@ package org.jackhuang.hellominecraft.launcher.utils;
import java.io.File;
import javax.swing.filechooser.FileFilter;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
/**
*
@@ -33,7 +34,7 @@ public class FileNameFilter extends FileFilter {
@Override
public boolean accept(File f) {
return f.isDirectory() || f.getName().equals(acceptedName);
return f.isDirectory() || f.getName().equals(acceptedName) && !FileUtils.getExtension(f.getName()).equals("lnk");
}
@Override

View File

@@ -21,7 +21,6 @@ import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -283,6 +282,7 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
@Override
public GameLauncher.DecompressLibraryJob getDecompressLibraries() {
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this, Settings.getInstance().getDownloadSource());
if (v.libraries == null) return null;
ArrayList<File> unzippings = new ArrayList<>();
ArrayList<String[]> extractRules = new ArrayList<>();
for (IMinecraftLibrary l : v.libraries) {

View File

@@ -1102,7 +1102,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
if (profile == null) return;
if (MessageBox.Show(C.i18n("ui.message.sure_remove", profile.getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION) return;
if (Settings.delVersion(profile)) {
if (Settings.delProfile(profile)) {
cboProfiles.removeItem(profile.getName());
profile = Settings.getOneProfile();
if (profile != null) {
@@ -1218,7 +1218,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
MessageBox.Show(C.i18n("setupwindow.no_empty_name"));
return;
}
Settings.trySetVersion(new Profile(name).setGameDir(newGameDir.getAbsolutePath()));
Settings.trySetProfile(new Profile(name).setGameDir(newGameDir.getAbsolutePath()));
MessageBox.Show(C.i18n("setupwindow.find_in_configurations"));
loadProfiles();
}
@@ -1438,7 +1438,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
cboProfiles.removeAllItems();
Profile firstProfile = null, selectedProfile = null;
int index = 0, i = 0;
for (Profile s : Settings.getProfiles()) {
for (Profile s : Settings.getProfilesFiltered()) {
if (firstProfile == null) firstProfile = s;
cboProfiles.addItem(s.getName());
if (Settings.getInstance().getLast() != null && Settings.getInstance().getLast().equals(s.getName())) {
@@ -1461,7 +1461,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
final Profile getProfile() {
if (cboProfiles.getSelectedIndex() >= 0)
return Settings.getVersion(cboProfiles.getSelectedItem().toString());
return Settings.getProfile(cboProfiles.getSelectedItem().toString());
else return null;
}

View File

@@ -451,7 +451,7 @@ public class MainPagePanel extends javax.swing.JPanel {
}
void loadFromSettings() {
for (Profile s : Settings.getProfiles()) cboProfiles.addItem(s.getName());
for (Profile s : Settings.getProfilesFiltered()) cboProfiles.addItem(s.getName());
}
boolean showedNoVersion = false;
@@ -460,6 +460,7 @@ public class MainPagePanel extends javax.swing.JPanel {
isLoading = true;
cboVersions.removeAllItems();
int index = 0, i = 0;
if (getCurrentProfile() != null) {
getCurrentProfile().getMinecraftProvider().refreshVersions();
MinecraftVersion selVersion = getCurrentProfile().getSelectedMinecraftVersion();
String selectedMC = selVersion == null ? null : selVersion.id;
@@ -478,6 +479,7 @@ public class MainPagePanel extends javax.swing.JPanel {
}
if (index < cboVersions.getItemCount()) cboVersions.setSelectedIndex(index);
}
}
isLoading = false;
}
@@ -533,7 +535,7 @@ public class MainPagePanel extends javax.swing.JPanel {
}
public Profile getCurrentProfile() {
return Settings.getVersion((String) cboProfiles.getSelectedItem());
return Settings.getProfile((String) cboProfiles.getSelectedItem());
}
public void onSelected() {

View File

@@ -32,7 +32,7 @@ public final class NewProfileWindow extends javax.swing.JDialog {
setLocationRelativeTo(null);
for (Profile s : Settings.getProfiles())
for (Profile s : Settings.getProfilesFiltered())
cboProfiles.addItem(s.getName());
}
@@ -126,9 +126,9 @@ public final class NewProfileWindow extends javax.swing.JDialog {
private void txtNewProfileNameKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNewProfileNameKeyTyped
switch (evt.getKeyCode()) {
case 13:
Profile newProfile = new Profile(Settings.getVersion(cboProfiles.getSelectedItem().toString()));
Profile newProfile = new Profile(Settings.getProfile(cboProfiles.getSelectedItem().toString()));
newProfile.setName(txtNewProfileName.getText());
Settings.trySetVersion(newProfile);
Settings.trySetProfile(newProfile);
case 27:
this.dispose();
}
@@ -136,9 +136,9 @@ public final class NewProfileWindow extends javax.swing.JDialog {
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
if (!StrUtils.isBlank(txtNewProfileName.getText())) {
Profile newProfile = new Profile(Settings.getVersion(cboProfiles.getSelectedItem().toString()));
Profile newProfile = new Profile(Settings.getProfile(cboProfiles.getSelectedItem().toString()));
newProfile.setName(txtNewProfileName.getText());
Settings.trySetVersion(newProfile);
Settings.trySetProfile(newProfile);
}
this.dispose();
}//GEN-LAST:event_btnOKActionPerformed

View File

@@ -19,6 +19,7 @@ package org.jackhuang.hellominecraft.utils;
import java.awt.FontMetrics;
import java.net.URI;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollBar;
@@ -169,5 +170,4 @@ public class SwingUtils {
}
return builder.toString();
}
}

View File

@@ -114,6 +114,9 @@ crash.advice.no_lwjgl=\u53ef\u80fd\u662f\u6e38\u620f\u4f9d\u8d56\u5e93\u4e0d\u5b
crash.advice.no=\u65e0\u5efa\u8bae\u3002
crash.user_fault=\u60a8\u7684\u7cfb\u7edf\u6216Java\u73af\u5883\u53ef\u80fd\u5b89\u88c5\u4e0d\u5f53\u5bfc\u81f4\u672c\u8f6f\u4ef6\u5d29\u6e83\uff0c\u8bf7\u68c0\u67e5\u60a8\u7684Java\u73af\u5883\u6216\u60a8\u7684\u7535\u8111\uff01\u53ef\u4ee5\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5Java\u3002
crash.headless=\u5982\u679c\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\u662fLinux\uff0c\u8bf7\u6ce8\u610f\u4e0d\u8981\u4f7f\u7528OpenJDK\uff0c\u52a1\u5fc5\u4f7f\u7528Oracle JDK\uff0c\u6216\u5c1d\u8bd5\u6dfb\u52a0-Djava.awt.headless=false\u53c2\u6570\uff0c\u6216\u68c0\u67e5\u60a8\u7684Xserver\u662f\u5426\u6b63\u5e38
crash.error=\u60a8\u7684Minecraft\u5d29\u6e83\u4e86\u3002
crash.main_class_not_found=\u627e\u4e0d\u5230\u4e3b\u7c7b\uff0c\u53ef\u80fd\u662f\u60a8\u7684JSON\u6587\u4ef6\u586b\u5199\u9519\u8bef\u3002\u65e0\u6cd5\u542f\u52a8\u6e38\u620f\u3002\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
crash.class_path_wrong=\u89e3\u6790Class Path\u65f6\u51fa\u73b0\u9519\u8bef\uff0c\u6b64\u9519\u8bef\u672c\u4e0d\u5e94\u8be5\u53d1\u751f\u3002\u53ef\u80fd\u662f\u542f\u52a8\u811a\u672c\u9519\u8bef\uff0c\u8bf7\u4ed4\u7ec6\u68c0\u67e5\u542f\u52a8\u811a\u672c\u3002

View File

@@ -114,6 +114,9 @@ crash.advice.no_lwjgl=Maybe drivers caused problems.
crash.advice.no=No advice.
crash.user_fault=Your OS or Java environment may not be properly installed resulting in crashing of this software, please check your Java Environment or your computer!
crash.headless=If your OS is Linux, please use Oracle JDK instead of OpenJDK, or add "-Djava.awt.headless=false" JVM argument, or check if your Xserver works normally.
crash.error=Minecraft has crashed.
crash.main_class_not_found=Main Class is not found, may be your mc has been broken.
crash.class_path_wrong=Maybe the launch script is malformed.

View File

@@ -114,6 +114,9 @@ crash.advice.no_lwjgl=\u53ef\u80fd\u662f\u6e38\u620f\u4f9d\u8d56\u5e93\u4e0d\u5b
crash.advice.no=\u65e0\u5efa\u8bae\u3002
crash.user_fault=\u60a8\u7684\u7cfb\u7edf\u6216Java\u73af\u5883\u53ef\u80fd\u5b89\u88c5\u4e0d\u5f53\u5bfc\u81f4\u672c\u8f6f\u4ef6\u5d29\u6e83\uff0c\u8bf7\u68c0\u67e5\u60a8\u7684Java\u73af\u5883\u6216\u60a8\u7684\u7535\u8111\uff01\u53ef\u4ee5\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5Java\u3002
crash.headless=\u5982\u679c\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\u662fLinux\uff0c\u8bf7\u6ce8\u610f\u4e0d\u8981\u4f7f\u7528OpenJDK\uff0c\u52a1\u5fc5\u4f7f\u7528Oracle JDK\uff0c\u6216\u5c1d\u8bd5\u6dfb\u52a0-Djava.awt.headless=false\u53c2\u6570\uff0c\u6216\u68c0\u67e5\u60a8\u7684Xserver\u662f\u5426\u6b63\u5e38
crash.error=\u60a8\u7684Minecraft\u5d29\u6e83\u4e86\u3002
crash.main_class_not_found=\u627e\u4e0d\u5230\u4e3b\u7c7b\uff0c\u53ef\u80fd\u662f\u60a8\u7684JSON\u6587\u4ef6\u586b\u5199\u9519\u8bef\u3002\u65e0\u6cd5\u542f\u52a8\u6e38\u620f\u3002\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
crash.class_path_wrong=\u89e3\u6790Class Path\u65f6\u51fa\u73b0\u9519\u8bef\uff0c\u6b64\u9519\u8bef\u672c\u4e0d\u5e94\u8be5\u53d1\u751f\u3002\u53ef\u80fd\u662f\u542f\u52a8\u811a\u672c\u9519\u8bef\uff0c\u8bf7\u4ed4\u7ec6\u68c0\u67e5\u542f\u52a8\u811a\u672c\u3002

View File

@@ -114,6 +114,9 @@ crash.advice.no_lwjgl=\u53ef\u80fd\u662f\u904a\u6232\u4f9d\u8cf4\u5eab\u4e0d\u5b
crash.advice.no=\u7121\u5efa\u8b70\u3002
crash.user_fault=\u60a8\u7684\u7cfb\u7d71\u6216Java\u74b0\u5883\u53ef\u80fd\u5b89\u88dd\u4e0d\u7576\u5c0e\u81f4\u672c\u8edf\u4ef6\u5d29\u6f70\uff0c\u8acb\u6aa2\u67e5\u60a8\u7684Java\u74b0\u5883\u6216\u60a8\u7684\u96fb\u8166\uff01\u53ef\u4ee5\u5617\u8a66\u91cd\u65b0\u5b89\u88ddJava\u3002
crash.headless=\u5982\u679c\u60a8\u7684\u64cd\u4f5c\u7cfb\u7d71\u662fLinux\uff0c\u8acb\u6ce8\u610f\u4e0d\u8981\u4f7f\u7528OpenJDK\uff0c\u52d9\u5fc5\u4f7f\u7528Oracle JDK\uff0c\u6216\u5617\u8a66\u6dfb\u52a0-Djava.awt.headless=false\u53c3\u6578\uff0c\u6216\u6aa2\u67e5\u60a8\u7684Xserver\u662f\u5426\u6b63\u5e38
crash.error=\u60a8\u7684Minecraft\u5d29\u6f70\u4e86\u3002
crash.main_class_not_found=\u627e\u4e0d\u5230\u4e3b\u985e\uff0c\u53ef\u80fd\u662f\u60a8\u7684JSON\u6587\u4ef6\u586b\u5beb\u932f\u8aa4\u3002\u7121\u6cd5\u555f\u52d5\u904a\u6232\u3002\u53ef\u4ee5\u901a\u904e\u4e0b\u8f09\u6574\u5408\u5305\u89e3\u6c7a\u554f\u984c\u3002
crash.class_path_wrong=\u89e3\u6790Class Path\u6642\u51fa\u73fe\u932f\u8aa4\uff0c\u6b64\u932f\u8aa4\u672c\u4e0d\u61c9\u8a72\u767c\u751f\u3002\u53ef\u80fd\u662f\u555f\u52d5\u8173\u672c\u932f\u8aa4\uff0c\u8acb\u4ed4\u7d30\u6aa2\u67e5\u555f\u52d5\u8173\u672c\u3002