mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-04-18 18:40:34 +08: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 (Settings.getLastProfile().service().version().renameVersion(mcVersion, newName))
|
||||
refreshVersions();
|
||||
else
|
||||
MessageBox.showLocalized("wizard.failed");
|
||||
}
|
||||
});
|
||||
ppmManage.add(itm);
|
||||
|
@ -69,7 +69,7 @@ public class LaunchingUIDaemon {
|
||||
// See events below.
|
||||
ProcessMonitor monitor = new ProcessMonitor(p.getValue());
|
||||
monitor.registerPrintlnEvent(PRINTLN);
|
||||
monitor.setTag(tag.launcherVisibility);
|
||||
monitor.setTag(obj);
|
||||
monitor.start();
|
||||
});
|
||||
HMCLApi.EVENT_BUS.channel(LaunchSucceededEvent.class).register(p -> {
|
||||
@ -79,7 +79,9 @@ public class LaunchingUIDaemon {
|
||||
else if (state == 2)
|
||||
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 -> {
|
||||
ProcessMonitor monitor = (ProcessMonitor) event.getSource();
|
||||
int exitCode = event.getValue().getExitCode();
|
||||
@ -108,6 +110,12 @@ public class LaunchingUIDaemon {
|
||||
noExitThisTime = true;
|
||||
});
|
||||
}
|
||||
|
||||
static LauncherVisibility unpackProcessMonitor(Object obj) {
|
||||
GameLauncher launcher = ((GameLauncher) ((ProcessMonitor) obj).getTag());
|
||||
HMCLGameLauncher.GameLauncherTag tag = (HMCLGameLauncher.GameLauncherTag) launcher.getTag();
|
||||
return tag.launcherVisibility;
|
||||
}
|
||||
|
||||
boolean noExitThisTime = false;
|
||||
|
||||
@ -137,12 +145,16 @@ public class LaunchingUIDaemon {
|
||||
}
|
||||
|
||||
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 (l != LauncherVisibility.HIDE_AND_REOPEN)
|
||||
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);
|
||||
HMCLApi.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(launcher, LaunchingState.Done));
|
||||
}
|
||||
};
|
||||
|
||||
private static final Consumer<LaunchingStateChangedEvent> LAUNCHING_STATE_CHANGED = t -> {
|
||||
@ -164,6 +176,7 @@ public class LaunchingUIDaemon {
|
||||
message = "launch.state.waiting_launching";
|
||||
break;
|
||||
case Done:
|
||||
MainFrame.INSTANCE.closeMessage();
|
||||
return;
|
||||
}
|
||||
MainFrame.INSTANCE.showMessage(C.i18n(message));
|
||||
|
@ -169,20 +169,19 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
@Override
|
||||
public boolean renameVersion(String from, String to) {
|
||||
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);
|
||||
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 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");
|
||||
File newJar = new File(toDir, from + ".jar");
|
||||
if (newJar.exists() && !newJar.renameTo(toJar))
|
||||
HMCLog.warn("Failed to rename pre jar " + newJar + " to new jar " + toJar);
|
||||
MinecraftVersion mcVersion = C.GSON.fromJson(FileUtils.read(toJson), MinecraftVersion.class);
|
||||
mcVersion.id = to;
|
||||
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;
|
||||
} catch (IOException | JsonSyntaxException 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;
|
||||
else if (b instanceof JButton
|
||||
&& ((JButton) b).isDefaultButton())
|
||||
state = State.DEFAULT;
|
||||
state = State.NORMAL;
|
||||
break;
|
||||
default:
|
||||
state = State.NORMAL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user