mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2024-11-27 06:10:08 +08:00
Fixed #26
This commit is contained in:
parent
48f14e193a
commit
dd0cdb5c83
@ -31,6 +31,7 @@ import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.util.MinecraftCrashAdvicer;
|
||||
import org.jackhuang.hellominecraft.util.DoubleOutputStream;
|
||||
import org.jackhuang.hellominecraft.util.LauncherPrintStream;
|
||||
import org.jackhuang.hellominecraft.util.Utils;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -106,6 +107,7 @@ public final class Launcher {
|
||||
|
||||
LOGGER.info("*** Launching Game ***");
|
||||
|
||||
int flag = 0;
|
||||
try {
|
||||
minecraftMain.invoke(null, new Object[] { (String[]) cmdList.toArray(new String[cmdList.size()]) });
|
||||
} catch (Throwable throwable) {
|
||||
@ -113,8 +115,15 @@ public final class Launcher {
|
||||
System.err.println(C.i18n("crash.minecraft"));
|
||||
System.err.println(MinecraftCrashAdvicer.getAdvice(trace));
|
||||
System.err.println(trace);
|
||||
flag = 1;
|
||||
}
|
||||
|
||||
LOGGER.info("*** Game exited ***");
|
||||
LOGGER.info("*** Game Exited ***");
|
||||
|
||||
try {
|
||||
Utils.shutdownForcely(flag);
|
||||
} catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Failed to shut down this process...", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public final class Main implements Runnable {
|
||||
return;
|
||||
|
||||
System.setProperty("sun.java2d.noddraw", "true");
|
||||
System.setProperty("sun.java2d.apiaware", "false");
|
||||
System.setProperty("sun.java2d.dpiaware", "false");
|
||||
Thread.setDefaultUncaughtExceptionHandler(new CrashReporter(true));
|
||||
|
||||
try {
|
||||
|
@ -82,23 +82,31 @@ public class HeaderTab extends JLabel
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (!isEnabled())
|
||||
return;
|
||||
this.model.setPressed(true);
|
||||
this.model.setArmed(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (!isEnabled())
|
||||
return;
|
||||
this.model.setPressed(false);
|
||||
this.model.setArmed(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
if (!isEnabled())
|
||||
return;
|
||||
this.model.setRollover(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
if (!isEnabled())
|
||||
return;
|
||||
this.model.setRollover(false);
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ import org.jackhuang.hellominecraft.lookandfeel.comp.ConstomButton;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
|
||||
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||
import org.jackhuang.hellominecraft.util.ui.wizard.api.WizardDisplayer;
|
||||
|
||||
/**
|
||||
@ -501,6 +502,8 @@ public class MainPagePanel extends AnimatedPanel {
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
final Consumer<Boolean> launchingStateChanged = t -> SwingUtils.setEnabled(MainFrame.INSTANCE.getRootPane(), !t);
|
||||
|
||||
final Consumer<String> versionChanged = this::versionChanged;
|
||||
|
||||
void versionChanged(String selectedVersion) {
|
||||
@ -513,6 +516,7 @@ public class MainPagePanel extends AnimatedPanel {
|
||||
final Consumer<Profile> onSelectedProfilesChanged = t -> {
|
||||
t.service().version().onRefreshedVersions.register(onRefreshedVersions);
|
||||
t.selectedVersionChangedEvent.register(versionChanged);
|
||||
t.launcher().launchingStateChanged.register(launchingStateChanged);
|
||||
|
||||
((DefaultComboBoxModel) cboProfiles.getModel()).setSelectedItem(t.getName());
|
||||
};
|
||||
|
@ -206,7 +206,7 @@ public class ModpackInitializationPanel extends javax.swing.JPanel {
|
||||
wizardData.put(KEY_INCLUDING_LAUNCHER, chkIncludeLauncher.isSelected());
|
||||
}//GEN-LAST:event_chkIncludeLauncherItemStateChanged
|
||||
|
||||
static final Pattern PATTERN = Pattern.compile("[-a-zA-Z0-9_\\.\u4E00-\u9FA5]+$");
|
||||
static final Pattern PATTERN = Pattern.compile("[-a-zA-Z0-9_\\.\\(\\)\\[\\]\\{\\}\\<\\>\"\'\u4E00-\u9FA5]+$");
|
||||
|
||||
void checkProblem() {
|
||||
controller.setProblem(null);
|
||||
|
@ -37,7 +37,6 @@ import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.Pair;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.Utils;
|
||||
import org.jackhuang.hellominecraft.util.func.CallbackIO;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.system.ZipEngine;
|
||||
import org.jackhuang.hellominecraft.util.ui.WebPage;
|
||||
|
@ -131,7 +131,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
if (THROWABLE_SET.contains(stacktrace))
|
||||
return;
|
||||
THROWABLE_SET.add(stacktrace);
|
||||
new Thread(() -> {
|
||||
Thread t = new Thread(() -> {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("CrashReport", text);
|
||||
try {
|
||||
@ -139,7 +139,9 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
} catch (IOException ex) {
|
||||
LOGGER.log(Level.SEVERE, "Failed to post HMCL server.", ex);
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
|
||||
import org.jackhuang.hellominecraft.launcher.setting.Profile;
|
||||
import org.jackhuang.hellominecraft.launcher.setting.Settings;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.EventHandler;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
|
||||
@ -41,31 +42,39 @@ public class HMCLGameLauncher {
|
||||
Profile profile;
|
||||
boolean isLaunching = false;
|
||||
|
||||
public final EventHandler<Boolean> launchingStateChanged = new EventHandler<>(this);
|
||||
|
||||
public HMCLGameLauncher(Profile p) {
|
||||
this.profile = p;
|
||||
}
|
||||
|
||||
void setLaunching(boolean isLaunching) {
|
||||
if (isLaunching != this.isLaunching)
|
||||
launchingStateChanged.execute(isLaunching);
|
||||
this.isLaunching = isLaunching;
|
||||
}
|
||||
|
||||
public void genLaunchCode(final Consumer<GameLauncher> listener, final Consumer<String> failed, String passwordIfNeeded) {
|
||||
if (isLaunching || profile == null)
|
||||
return;
|
||||
isLaunching = true;
|
||||
setLaunching(true);
|
||||
HMCLog.log("Start generating launching command...");
|
||||
File file = profile.getCanonicalGameDirFile();
|
||||
if (!file.exists()) {
|
||||
failed.accept(C.i18n("minecraft.wrong_path"));
|
||||
isLaunching = false;
|
||||
setLaunching(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile.getSelectedVersion() == null) {
|
||||
failed.accept(C.i18n("minecraft.no_selected_version"));
|
||||
isLaunching = false;
|
||||
setLaunching(false);
|
||||
return;
|
||||
}
|
||||
|
||||
final IAuthenticator l = IAuthenticator.LOGINS.get(Settings.getInstance().getLoginType());
|
||||
final LoginInfo li = new LoginInfo(l.getUserName(), l.isLoggedIn() || !l.hasPassword() ? null : passwordIfNeeded);
|
||||
new Thread() {
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Game Launcher");
|
||||
@ -74,18 +83,20 @@ public class HMCLGameLauncher {
|
||||
PluginManager.plugin().onProcessingLaunchOptions(options);
|
||||
DefaultGameLauncher gl = new DefaultGameLauncher(options, profile.service(), li, l);
|
||||
gl.setTag(profile.getSelectedVersionSetting().getLauncherVisibility());
|
||||
gl.successEvent.register(() -> isLaunching = false);
|
||||
gl.successEvent.register(() -> setLaunching(false));
|
||||
listener.accept(gl);
|
||||
gl.makeLaunchCommand();
|
||||
} catch (GameException e) {
|
||||
failed.accept(C.i18n("launch.failed") + ", " + e.getMessage());
|
||||
isLaunching = false;
|
||||
setLaunching(false);
|
||||
} catch (AuthenticationException e) {
|
||||
failed.accept(C.i18n("login.failed") + ", " + e.getMessage());
|
||||
isLaunching = false;
|
||||
setLaunching(false);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
};
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.util.ui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.FontMetrics;
|
||||
import java.io.File;
|
||||
@ -27,6 +28,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JOptionPane;
|
||||
@ -265,4 +267,13 @@ public class SwingUtils {
|
||||
return -1;
|
||||
return ((JComboBox) msgs[1]).getSelectedIndex();
|
||||
}
|
||||
|
||||
public static void setEnabled(JComponent component, boolean t) {
|
||||
synchronized (component.getTreeLock()) {
|
||||
for (Component c : component.getComponents())
|
||||
if (c instanceof JComponent)
|
||||
setEnabled((JComponent) c, t);
|
||||
}
|
||||
component.setEnabled(t);
|
||||
}
|
||||
}
|
||||
|
@ -460,6 +460,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
}
|
||||
};
|
||||
Thread runner = new Thread(run, "Wizard Background Result Thread " + r);
|
||||
runner.setDaemon(true);
|
||||
runner.start();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user