mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-17 07:47:57 -04:00
Fixed #130
This commit is contained in:
parent
4f03ec503f
commit
ebadbb0f18
@ -172,6 +172,8 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
|
|||||||
if (newName != null)
|
if (newName != null)
|
||||||
if (Settings.getLastProfile().service().version().renameVersion(mcVersion, newName))
|
if (Settings.getLastProfile().service().version().renameVersion(mcVersion, newName))
|
||||||
refreshVersions();
|
refreshVersions();
|
||||||
|
else
|
||||||
|
MessageBox.showLocalized("wizard.failed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ppmManage.add(itm);
|
ppmManage.add(itm);
|
||||||
|
@ -69,7 +69,7 @@ public class LaunchingUIDaemon {
|
|||||||
// See events below.
|
// See events below.
|
||||||
ProcessMonitor monitor = new ProcessMonitor(p.getValue());
|
ProcessMonitor monitor = new ProcessMonitor(p.getValue());
|
||||||
monitor.registerPrintlnEvent(PRINTLN);
|
monitor.registerPrintlnEvent(PRINTLN);
|
||||||
monitor.setTag(tag.launcherVisibility);
|
monitor.setTag(obj);
|
||||||
monitor.start();
|
monitor.start();
|
||||||
});
|
});
|
||||||
HMCLApi.EVENT_BUS.channel(LaunchSucceededEvent.class).register(p -> {
|
HMCLApi.EVENT_BUS.channel(LaunchSucceededEvent.class).register(p -> {
|
||||||
@ -79,7 +79,9 @@ public class LaunchingUIDaemon {
|
|||||||
else if (state == 2)
|
else if (state == 2)
|
||||||
LAUNCH_SCRIPT_FINISHER.accept(p);
|
LAUNCH_SCRIPT_FINISHER.accept(p);
|
||||||
});
|
});
|
||||||
HMCLApi.EVENT_BUS.channel(JavaProcessStoppedEvent.class).register(event -> checkExit((LauncherVisibility) ((ProcessMonitor) event.getSource()).getTag()));
|
HMCLApi.EVENT_BUS.channel(JavaProcessStoppedEvent.class).register(event -> {
|
||||||
|
checkExit(unpackProcessMonitor(event.getSource()));
|
||||||
|
});
|
||||||
HMCLApi.EVENT_BUS.channel(JavaProcessExitedAbnormallyEvent.class).register(event -> {
|
HMCLApi.EVENT_BUS.channel(JavaProcessExitedAbnormallyEvent.class).register(event -> {
|
||||||
ProcessMonitor monitor = (ProcessMonitor) event.getSource();
|
ProcessMonitor monitor = (ProcessMonitor) event.getSource();
|
||||||
int exitCode = event.getValue().getExitCode();
|
int exitCode = event.getValue().getExitCode();
|
||||||
@ -109,6 +111,12 @@ public class LaunchingUIDaemon {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static LauncherVisibility unpackProcessMonitor(Object obj) {
|
||||||
|
GameLauncher launcher = ((GameLauncher) ((ProcessMonitor) obj).getTag());
|
||||||
|
HMCLGameLauncher.GameLauncherTag tag = (HMCLGameLauncher.GameLauncherTag) launcher.getTag();
|
||||||
|
return tag.launcherVisibility;
|
||||||
|
}
|
||||||
|
|
||||||
boolean noExitThisTime = false;
|
boolean noExitThisTime = false;
|
||||||
|
|
||||||
void runGame(Profile profile) {
|
void runGame(Profile profile) {
|
||||||
@ -137,12 +145,16 @@ public class LaunchingUIDaemon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final Consumer<PrintlnEvent> PRINTLN = t -> {
|
private static final Consumer<PrintlnEvent> PRINTLN = t -> {
|
||||||
LauncherVisibility l = ((LauncherVisibility) ((ProcessMonitor) t.getSource()).getTag());
|
GameLauncher launcher = ((GameLauncher) ((ProcessMonitor) t.getSource()).getTag());
|
||||||
|
HMCLGameLauncher.GameLauncherTag tag = (HMCLGameLauncher.GameLauncherTag) launcher.getTag();
|
||||||
|
LauncherVisibility l = tag.launcherVisibility;
|
||||||
if (t.getLine().contains("LWJGL Version: ") && l != LauncherVisibility.KEEP)
|
if (t.getLine().contains("LWJGL Version: ") && l != LauncherVisibility.KEEP)
|
||||||
if (l != LauncherVisibility.HIDE_AND_REOPEN)
|
if (l != LauncherVisibility.HIDE_AND_REOPEN)
|
||||||
MainFrame.INSTANCE.dispose();
|
MainFrame.INSTANCE.dispose();
|
||||||
else
|
else { // If current state is 'hide and reopen', closes the main window and reset the state to normal.
|
||||||
MainFrame.INSTANCE.setVisible(false);
|
MainFrame.INSTANCE.setVisible(false);
|
||||||
|
HMCLApi.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(launcher, LaunchingState.Done));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final Consumer<LaunchingStateChangedEvent> LAUNCHING_STATE_CHANGED = t -> {
|
private static final Consumer<LaunchingStateChangedEvent> LAUNCHING_STATE_CHANGED = t -> {
|
||||||
@ -164,6 +176,7 @@ public class LaunchingUIDaemon {
|
|||||||
message = "launch.state.waiting_launching";
|
message = "launch.state.waiting_launching";
|
||||||
break;
|
break;
|
||||||
case Done:
|
case Done:
|
||||||
|
MainFrame.INSTANCE.closeMessage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MainFrame.INSTANCE.showMessage(C.i18n(message));
|
MainFrame.INSTANCE.showMessage(C.i18n(message));
|
||||||
|
@ -169,20 +169,19 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
@Override
|
@Override
|
||||||
public boolean renameVersion(String from, String to) {
|
public boolean renameVersion(String from, String to) {
|
||||||
try {
|
try {
|
||||||
File fromJson = new File(versionRoot(from), from + ".json");
|
|
||||||
MinecraftVersion mcVersion = C.GSON.fromJson(FileUtils.read(fromJson), MinecraftVersion.class);
|
|
||||||
mcVersion.id = to;
|
|
||||||
FileUtils.writeQuietly(fromJson, C.GSON.toJson(mcVersion));
|
|
||||||
File toDir = versionRoot(to);
|
File toDir = versionRoot(to);
|
||||||
if (!versionRoot(from).renameTo(toDir))
|
if (!versionRoot(from).renameTo(toDir))
|
||||||
HMCLog.warn("MinecraftVersionManager.RenameVersion: Failed to rename version root " + from + " to " + to);
|
return false;
|
||||||
File toJson = new File(toDir, to + ".json");
|
File toJson = new File(toDir, to + ".json");
|
||||||
File toJar = new File(toDir, to + ".jar");
|
File toJar = new File(toDir, to + ".jar");
|
||||||
if (new File(toDir, from + ".json").renameTo(toJson))
|
if (!new File(toDir, from + ".json").renameTo(toJson))
|
||||||
HMCLog.warn("MinecraftVersionManager.RenameVersion: Failed to rename json");
|
HMCLog.warn("MinecraftVersionManager.RenameVersion: Failed to rename json");
|
||||||
File newJar = new File(toDir, from + ".jar");
|
MinecraftVersion mcVersion = C.GSON.fromJson(FileUtils.read(toJson), MinecraftVersion.class);
|
||||||
if (newJar.exists() && !newJar.renameTo(toJar))
|
mcVersion.id = to;
|
||||||
HMCLog.warn("Failed to rename pre jar " + newJar + " to new jar " + toJar);
|
FileUtils.writeQuietly(toJson, C.GSON.toJson(mcVersion));
|
||||||
|
File oldJar = new File(toDir, from + ".jar");
|
||||||
|
if (oldJar.exists() && !oldJar.renameTo(toJar))
|
||||||
|
HMCLog.warn("Failed to rename pre jar " + oldJar + " to new jar " + toJar);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException | JsonSyntaxException e) {
|
} catch (IOException | JsonSyntaxException e) {
|
||||||
HMCLog.warn("Failed to rename " + from + " to " + to + ", the json of this Minecraft is malformed.", e);
|
HMCLog.warn("Failed to rename " + from + " to " + to + ", the json of this Minecraft is malformed.", e);
|
||||||
|
@ -267,7 +267,7 @@ public class BEButtonUI extends BasicButtonUI implements Skin {
|
|||||||
state = State.ROLLOVER;
|
state = State.ROLLOVER;
|
||||||
else if (b instanceof JButton
|
else if (b instanceof JButton
|
||||||
&& ((JButton) b).isDefaultButton())
|
&& ((JButton) b).isDefaultButton())
|
||||||
state = State.DEFAULT;
|
state = State.NORMAL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
state = State.NORMAL;
|
state = State.NORMAL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user