mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-02-05 16:44:47 +08:00
Added a console log to warn the user when "always close the launcher" option turned on
This commit is contained in:
parent
9835aa4110
commit
f32ce42af3
@ -21,7 +21,7 @@ package org.jackhuang.hellominecraft.launcher.launch;
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class GameException extends RuntimeException {
|
||||
public class GameException extends Exception {
|
||||
|
||||
public GameException(String message) {
|
||||
super(message);
|
||||
|
@ -74,7 +74,7 @@ public class GameLauncher {
|
||||
else
|
||||
result = login.loginBySettings();
|
||||
if (result == null)
|
||||
throw new IllegalStateException("Result can not be null.");
|
||||
throw new GameException("Result can not be null.");
|
||||
PluginManager.NOW_PLUGIN.onProcessingLoginResult(result);
|
||||
} catch (Throwable e) {
|
||||
String error = C.i18n("login.failed") + e.getMessage();
|
||||
@ -150,6 +150,7 @@ public class GameLauncher {
|
||||
builder.directory(provider.getRunDirectory(provider.getSelectedVersion().id))
|
||||
.environment().put("APPDATA", get.getCanonicalGameDir());
|
||||
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
|
||||
HMCLog.log("The game process have been started");
|
||||
launchEvent.execute(jp);
|
||||
} catch (Exception e) {
|
||||
failEvent.execute(C.i18n("launch.failed_creating_process") + "\n" + e.getMessage());
|
||||
|
@ -77,7 +77,7 @@ public abstract class IMinecraftProvider {
|
||||
*
|
||||
* @return libraries of resolved minecraft version v.
|
||||
*/
|
||||
public abstract GameLauncher.DecompressLibraryJob getDecompressLibraries(MinecraftVersion v);
|
||||
public abstract GameLauncher.DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) throws GameException;
|
||||
|
||||
public abstract File getDecompressNativesToLocation(MinecraftVersion v);
|
||||
|
||||
@ -99,9 +99,9 @@ public abstract class IMinecraftProvider {
|
||||
*
|
||||
* @return what you want
|
||||
*
|
||||
* @throws IllegalStateException circular denpendency versions
|
||||
* @throws GameException circular denpendency versions
|
||||
*/
|
||||
public abstract IMinecraftLoader provideMinecraftLoader(UserProfileProvider p) throws IllegalStateException;
|
||||
public abstract IMinecraftLoader provideMinecraftLoader(UserProfileProvider p) throws GameException;
|
||||
|
||||
/**
|
||||
* Rename version
|
||||
|
@ -289,6 +289,8 @@ public final class Profile {
|
||||
}
|
||||
|
||||
public GameDirType getGameDirType() {
|
||||
if (gameDirType < 0 || gameDirType > 1)
|
||||
setGameDirType(GameDirType.ROOT_FOLDER);
|
||||
return GameDirType.values()[gameDirType];
|
||||
}
|
||||
|
||||
|
@ -72,11 +72,11 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
|
||||
return new MinecraftVersion(minecraftArguments, mainClass, time, id, type, processArguments, releaseTime, assets, jar, inheritsFrom, minimumLauncherVersion, libraries, hidden);
|
||||
}
|
||||
|
||||
public MinecraftVersion resolve(IMinecraftProvider manager) {
|
||||
public MinecraftVersion resolve(IMinecraftProvider manager) throws GameException {
|
||||
return resolve(manager, new HashSet<>());
|
||||
}
|
||||
|
||||
protected MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar) {
|
||||
protected MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar) throws GameException {
|
||||
if (inheritsFrom == null)
|
||||
return this;
|
||||
if (!resolvedSoFar.add(id))
|
||||
|
@ -208,7 +208,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameLauncher.DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) {
|
||||
public GameLauncher.DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) throws GameException {
|
||||
if (v.libraries == null)
|
||||
throw new GameException("Wrong format: minecraft.json");
|
||||
ArrayList<File> unzippings = new ArrayList<>();
|
||||
|
@ -559,9 +559,10 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
public boolean call(Object sender, List<String> str) {
|
||||
final GameLauncher obj = (GameLauncher) sender;
|
||||
obj.launchEvent.register((sender1, p) -> {
|
||||
if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible())
|
||||
if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible()) {
|
||||
HMCLog.log("Without the option of keeping the launcher visible, this application will exit and will NOT catch game logs, but you can turn on \"Debug Mode\".");
|
||||
System.exit(0);
|
||||
else if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.KEEP)
|
||||
} else if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.KEEP)
|
||||
MainFrame.INSTANCE.closeMessage();
|
||||
else {
|
||||
if (LogWindow.INSTANCE.isVisible())
|
||||
@ -570,16 +571,20 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
}
|
||||
JavaProcessMonitor jpm = new JavaProcessMonitor(p);
|
||||
jpm.applicationExitedAbnormallyEvent.register((sender2, t) -> {
|
||||
HMCLog.err("The game exited abnormally, exit code: " + t);
|
||||
MessageBox.Show(C.i18n("launch.exited_abnormally") + ", exit code: " + t);
|
||||
return true;
|
||||
});
|
||||
jpm.jvmLaunchFailedEvent.register((sender2, t) -> {
|
||||
HMCLog.err("Cannot create jvm, exit code: " + t);
|
||||
MessageBox.Show(C.i18n("launch.cannot_create_jvm") + ", exit code: " + t);
|
||||
return true;
|
||||
});
|
||||
jpm.stoppedEvent.register((sender2, t) -> {
|
||||
if (obj.getProfile().getLauncherVisibility() != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible())
|
||||
if (obj.getProfile().getLauncherVisibility() != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible()) {
|
||||
HMCLog.log("Without the option of keeping the launcher visible, this application will exit and will NOT catch game logs, but you can turn on \"Debug Mode\".");
|
||||
System.exit(0);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
jpm.start();
|
||||
|
@ -72,10 +72,10 @@ public class Hex {
|
||||
return new String(encodeHex(data));
|
||||
}
|
||||
|
||||
protected static int toDigit(char ch, int index) throws Exception {
|
||||
protected static int toDigit(char ch, int index) {
|
||||
int digit = Character.digit(ch, 16);
|
||||
if (digit == -1)
|
||||
throw new Exception("Illegal hexadecimal character " + ch + " at index " + index);
|
||||
throw new IllegalArgumentException("Illegal hexadecimal character " + ch + " at index " + index);
|
||||
return digit;
|
||||
}
|
||||
|
||||
|
@ -74,8 +74,6 @@ public class FileUtils {
|
||||
public static void cleanDirectory(File directory)
|
||||
throws IOException {
|
||||
if (!directory.exists()) {
|
||||
//String message = directory + " does not exist";
|
||||
//throw new IllegalArgumentException(message);
|
||||
directory.mkdirs();
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user