mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-11 12:56:53 -04:00
Reconstruct the codes && fix wrong file separator when switch to anther os from Windows.
This commit is contained in:
parent
244b646225
commit
0be056ac04
@ -16,18 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.launcher.launch;
|
package org.jackhuang.hellominecraft.launcher.launch;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
|
||||||
import org.jackhuang.hellominecraft.utils.functions.TrueFunction;
|
import org.jackhuang.hellominecraft.utils.functions.TrueFunction;
|
||||||
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
|
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
|
||||||
import org.jackhuang.hellominecraft.utils.CollectionUtils;
|
|
||||||
import org.jackhuang.hellominecraft.utils.Event;
|
import org.jackhuang.hellominecraft.utils.Event;
|
||||||
import org.jackhuang.hellominecraft.utils.system.JavaProcess;
|
import org.jackhuang.hellominecraft.utils.system.JavaProcessMonitor;
|
||||||
import org.jackhuang.hellominecraft.utils.system.MessageBox;
|
|
||||||
import org.jackhuang.hellominecraft.utils.system.ProcessThread;
|
|
||||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
|
||||||
import org.jackhuang.hellominecraft.views.LogWindow;
|
import org.jackhuang.hellominecraft.views.LogWindow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,58 +30,28 @@ import org.jackhuang.hellominecraft.views.LogWindow;
|
|||||||
*/
|
*/
|
||||||
public class LaunchFinisher implements Event<List<String>> {
|
public class LaunchFinisher implements Event<List<String>> {
|
||||||
|
|
||||||
private final HashSet<Thread> al = new HashSet<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean call(Object sender, List<String> str) {
|
public boolean call(Object sender, List<String> str) {
|
||||||
final GameLauncher obj = (GameLauncher) sender;
|
final GameLauncher obj = (GameLauncher) sender;
|
||||||
obj.launchEvent.register((sender1, p) -> {
|
obj.launchEvent.register((sender1, p) -> {
|
||||||
if (obj.getProfile().getLauncherVisibility() == 0 && !LogWindow.instance.isVisible())
|
if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.CLOSE && !LogWindow.instance.isVisible())
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
else if (obj.getProfile().getLauncherVisibility() == 2)
|
else if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.KEEP)
|
||||||
MainFrame.instance.closeMessage();
|
MainFrame.instance.closeMessage();
|
||||||
else {
|
else {
|
||||||
if (LogWindow.instance.isVisible())
|
if (LogWindow.instance.isVisible())
|
||||||
LogWindow.instance.setExit(TrueFunction.instance);
|
LogWindow.instance.setExit(TrueFunction.instance);
|
||||||
MainFrame.instance.dispose();
|
MainFrame.instance.dispose();
|
||||||
}
|
}
|
||||||
Event<JavaProcess> event = (sender2, t) -> {
|
JavaProcessMonitor jpm = new JavaProcessMonitor(p);
|
||||||
processThreadStopped((ProcessThread) sender2, obj, t, false);
|
jpm.stoppedEvent.register((sender3, t) -> {
|
||||||
return true;
|
if (obj.getProfile().getLauncherVisibility() != LauncherVisibility.KEEP && !LogWindow.instance.isVisible())
|
||||||
};
|
System.exit(0);
|
||||||
ProcessThread a = new ProcessThread(p, true, true);
|
|
||||||
a.stopEvent.register((sender3, p1) -> {
|
|
||||||
if (p1.getExitCode() != 0 && p1.getStdErrLines().size() > 0 && StrUtils.containsOne(p1.getStdErrLines(), Arrays.asList("Could not create the Java Virtual Machine.",
|
|
||||||
"Error occurred during initialization of VM",
|
|
||||||
"A fatal exception has occurred. Program will exit."))) MessageBox.Show(C.i18n("launch.cannot_create_jvm"));
|
|
||||||
processThreadStopped((ProcessThread) sender3, obj, p1, false);
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
a.start();
|
|
||||||
al.add(a);
|
|
||||||
a = new ProcessThread(p, false, true);
|
|
||||||
a.stopEvent.register(event);
|
|
||||||
a.start();
|
|
||||||
al.add(a);
|
|
||||||
a = new ProcessThread(p, false, false);
|
|
||||||
a.stopEvent.register(event);
|
|
||||||
a.start();
|
|
||||||
al.add(a);
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
obj.launch(str);
|
obj.launch(str);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void processThreadStopped(ProcessThread t, GameLauncher obj, JavaProcess p, boolean forceTermintate) {
|
|
||||||
al.remove(t);
|
|
||||||
al.removeAll(CollectionUtils.sortOut(al, t1 -> !t1.isAlive()));
|
|
||||||
if (al.isEmpty() || forceTermintate) {
|
|
||||||
for (Thread a : al) a.interrupt();
|
|
||||||
al.clear();
|
|
||||||
GameLauncher.PROCESS_MANAGER.onProcessStopped(p);
|
|
||||||
if (obj.getProfile().getLauncherVisibility() != 2 && !LogWindow.instance.isVisible())
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* 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 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hellominecraft.launcher.settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author huangyuhui
|
||||||
|
*/
|
||||||
|
public enum LauncherVisibility {
|
||||||
|
CLOSE,
|
||||||
|
HIDE,
|
||||||
|
KEEP
|
||||||
|
}
|
@ -25,6 +25,7 @@ import org.jackhuang.hellominecraft.utils.StrUtils;
|
|||||||
import org.jackhuang.hellominecraft.utils.Utils;
|
import org.jackhuang.hellominecraft.utils.Utils;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager;
|
||||||
|
import org.jackhuang.hellominecraft.utils.system.OS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -235,12 +236,12 @@ public final class Profile {
|
|||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLauncherVisibility() {
|
public LauncherVisibility getLauncherVisibility() {
|
||||||
return launcherVisibility;
|
return LauncherVisibility.values()[launcherVisibility];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLauncherVisibility(int launcherVisibility) {
|
public void setLauncherVisibility(LauncherVisibility launcherVisibility) {
|
||||||
this.launcherVisibility = launcherVisibility;
|
this.launcherVisibility = launcherVisibility.ordinal();
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,4 +307,7 @@ public final class Profile {
|
|||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkFormat() {
|
||||||
|
gameDir = gameDir.replace('/', OS.os().fileSeparator).replace('\\', OS.os().fileSeparator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ import org.jackhuang.hellominecraft.utils.VersionNumber;
|
|||||||
*/
|
*/
|
||||||
public final class Settings {
|
public final class Settings {
|
||||||
|
|
||||||
|
public static final String DEFAULT_PROFILE = "Default";
|
||||||
|
|
||||||
public static final File settingsFile = new File(IOUtils.currentDir(), "hmcl.json");
|
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();
|
||||||
|
|
||||||
@ -56,8 +58,12 @@ public final class Settings {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
settings = initSettings();
|
settings = initSettings();
|
||||||
if (!getVersions().containsKey("Default"))
|
if (!getVersions().containsKey(DEFAULT_PROFILE))
|
||||||
getVersions().put("Default", new Profile());
|
getVersions().put(DEFAULT_PROFILE, new Profile());
|
||||||
|
|
||||||
|
for(Profile e : getVersions().values()) {
|
||||||
|
e.checkFormat();
|
||||||
|
}
|
||||||
|
|
||||||
UPDATE_CHECKER = new UpdateChecker(new VersionNumber(Main.firstVer, Main.secondVer, Main.thirdVer),
|
UPDATE_CHECKER = new UpdateChecker(new VersionNumber(Main.firstVer, Main.secondVer, Main.thirdVer),
|
||||||
"hmcl", settings.isCheckUpdate(), () -> Main.invokeUpdate());
|
"hmcl", settings.isCheckUpdate(), () -> Main.invokeUpdate());
|
||||||
@ -126,11 +132,15 @@ public final class Settings {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void delVersion(Profile ver) {
|
public static boolean delVersion(Profile ver) {
|
||||||
delVersion(ver.getName());
|
return delVersion(ver.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void delVersion(String ver) {
|
public static boolean delVersion(String ver) {
|
||||||
getVersions().remove(ver);
|
if (DEFAULT_PROFILE.equals(ver)) {
|
||||||
|
MessageBox.Show(C.i18n("settings.cannot_remove_default_config"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return getVersions().remove(ver) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import javax.swing.SwingUtilities;
|
|||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
|
||||||
@ -912,18 +913,15 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
|
|
||||||
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
|
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
|
||||||
if (profile == null) return;
|
if (profile == null) return;
|
||||||
if ("Default".equals(profile.getName())) {
|
|
||||||
MessageBox.Show(C.i18n("settings.cannot_remove_default_config"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show(C.i18n("ui.message.sure_remove", profile.getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION) return;
|
if (MessageBox.Show(C.i18n("ui.message.sure_remove", profile.getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION) return;
|
||||||
|
if(Settings.delVersion(profile)) {
|
||||||
cboProfiles.removeItem(profile.getName());
|
cboProfiles.removeItem(profile.getName());
|
||||||
Settings.delVersion(profile);
|
|
||||||
profile = Settings.getOneProfile();
|
profile = Settings.getOneProfile();
|
||||||
if (profile != null) {
|
if (profile != null) {
|
||||||
prepare(profile);
|
prepare(profile);
|
||||||
loadVersions();
|
loadVersions();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}//GEN-LAST:event_btnRemoveProfileActionPerformed
|
}//GEN-LAST:event_btnRemoveProfileActionPerformed
|
||||||
|
|
||||||
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
|
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
|
||||||
@ -1094,7 +1092,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
|
|
||||||
private void cboLauncherVisibilityFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboLauncherVisibilityFocusLost
|
private void cboLauncherVisibilityFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboLauncherVisibilityFocusLost
|
||||||
if (cboLauncherVisibility.getSelectedIndex() >= 0)
|
if (cboLauncherVisibility.getSelectedIndex() >= 0)
|
||||||
profile.setLauncherVisibility(cboLauncherVisibility.getSelectedIndex());
|
profile.setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]);
|
||||||
}//GEN-LAST:event_cboLauncherVisibilityFocusLost
|
}//GEN-LAST:event_cboLauncherVisibilityFocusLost
|
||||||
|
|
||||||
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
|
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
|
||||||
@ -1197,7 +1195,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
chkNoJVMArgs.setSelected(profile.isNoJVMArgs());
|
chkNoJVMArgs.setSelected(profile.isNoJVMArgs());
|
||||||
chkFullscreen.setSelected(profile.isFullscreen());
|
chkFullscreen.setSelected(profile.isFullscreen());
|
||||||
chkCancelWrapper.setSelected(profile.isCanceledWrapper());
|
chkCancelWrapper.setSelected(profile.isCanceledWrapper());
|
||||||
cboLauncherVisibility.setSelectedIndex(profile.getLauncherVisibility());
|
cboLauncherVisibility.setSelectedIndex(profile.getLauncherVisibility().ordinal());
|
||||||
cboGameDirType.setSelectedIndex(profile.getGameDirType().ordinal());
|
cboGameDirType.setSelectedIndex(profile.getGameDirType().ordinal());
|
||||||
|
|
||||||
loadVersions();
|
loadVersions();
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* 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 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hellominecraft.utils.system;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import org.jackhuang.hellominecraft.C;
|
||||||
|
import org.jackhuang.hellominecraft.utils.CollectionUtils;
|
||||||
|
import org.jackhuang.hellominecraft.utils.Event;
|
||||||
|
import org.jackhuang.hellominecraft.utils.EventHandler;
|
||||||
|
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author huangyuhui
|
||||||
|
*/
|
||||||
|
public class JavaProcessMonitor {
|
||||||
|
|
||||||
|
private final HashSet<Thread> al = new HashSet<>();
|
||||||
|
public final EventHandler<JavaProcess> stoppedEvent = new EventHandler<>(this);
|
||||||
|
private final JavaProcess p;
|
||||||
|
|
||||||
|
public JavaProcessMonitor(JavaProcess p) {
|
||||||
|
this.p = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
Event<JavaProcess> event = (sender2, t) -> {
|
||||||
|
processThreadStopped((ProcessThread) sender2, false);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
ProcessThread a = new ProcessThread(p, true, true);
|
||||||
|
a.stopEvent.register((sender3, p1) -> {
|
||||||
|
if (p1.getExitCode() != 0 && p1.getStdErrLines().size() > 0 && StrUtils.containsOne(p1.getStdErrLines(), Arrays.asList("Could not create the Java Virtual Machine.",
|
||||||
|
"Error occurred during initialization of VM",
|
||||||
|
"A fatal exception has occurred. Program will exit."))) MessageBox.Show(C.i18n("launch.cannot_create_jvm"));
|
||||||
|
processThreadStopped((ProcessThread) sender3, false);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
a.start();
|
||||||
|
al.add(a);
|
||||||
|
a = new ProcessThread(p, false, true);
|
||||||
|
a.stopEvent.register(event);
|
||||||
|
a.start();
|
||||||
|
al.add(a);
|
||||||
|
a = new ProcessThread(p, false, false);
|
||||||
|
a.stopEvent.register(event);
|
||||||
|
a.start();
|
||||||
|
al.add(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void processThreadStopped(ProcessThread t, boolean forceTermintate) {
|
||||||
|
al.remove(t);
|
||||||
|
al.removeAll(CollectionUtils.sortOut(al, t1 -> !t1.isAlive()));
|
||||||
|
if (al.isEmpty() || forceTermintate) {
|
||||||
|
for (Thread a : al) a.interrupt();
|
||||||
|
al.clear();
|
||||||
|
stoppedEvent.execute(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,10 +25,16 @@ import org.jackhuang.hellominecraft.HMCLog;
|
|||||||
*/
|
*/
|
||||||
public enum OS {
|
public enum OS {
|
||||||
|
|
||||||
LINUX,
|
LINUX('/'),
|
||||||
WINDOWS,
|
WINDOWS('\\'),
|
||||||
OSX,
|
OSX('/'),
|
||||||
UNKOWN;
|
UNKOWN('/');
|
||||||
|
|
||||||
|
public final char fileSeparator;
|
||||||
|
|
||||||
|
private OS(char fileSeparator) {
|
||||||
|
this.fileSeparator = fileSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
public static OS os() {
|
public static OS os() {
|
||||||
String str;
|
String str;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user