Dont know update what?
This commit is contained in:
@@ -84,6 +84,7 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
|
|||||||
res.add("-XX:+CMSIncrementalMode");
|
res.add("-XX:+CMSIncrementalMode");
|
||||||
res.add("-XX:-UseAdaptiveSizePolicy");
|
res.add("-XX:-UseAdaptiveSizePolicy");
|
||||||
res.add("-XX:-OmitStackTraceInFastThrow");
|
res.add("-XX:-OmitStackTraceInFastThrow");
|
||||||
|
res.add("-Xincgc");
|
||||||
|
|
||||||
res.add("-Xmn128m");
|
res.add("-Xmn128m");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,21 +86,9 @@ public final class ModpackManager {
|
|||||||
@Override
|
@Override
|
||||||
public void executeTask() throws Throwable {
|
public void executeTask() throws Throwable {
|
||||||
String id = idFUCK;
|
String id = idFUCK;
|
||||||
File versions = new File(service.baseDirectory(), "versions");
|
|
||||||
File oldFile = new File(versions, "minecraft"), newFile = null;
|
|
||||||
if (oldFile.exists()) {
|
|
||||||
newFile = new File(versions, "minecraft-" + System.currentTimeMillis());
|
|
||||||
if (newFile.isDirectory())
|
|
||||||
FileUtils.deleteDirectory(newFile);
|
|
||||||
else if (newFile.isFile())
|
|
||||||
if (!newFile.delete())
|
|
||||||
HMCLog.warn("Failed to delete file " + newFile);
|
|
||||||
if (!oldFile.renameTo(newFile))
|
|
||||||
HMCLog.warn("Failed to rename " + oldFile + " to " + newFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
String description = C.i18n("modpack.install.will_install");
|
String description = C.i18n("modpack.install.will_install");
|
||||||
|
|
||||||
|
// Read modpack name and description from `modpack.json`
|
||||||
try (ZipFile zip = new ZipFile(input)) {
|
try (ZipFile zip = new ZipFile(input)) {
|
||||||
HashMap map = C.GSON.fromJson(new InputStreamReader(zip.getInputStream(zip.getEntry("modpack.json")), "UTF-8"), HashMap.class);
|
HashMap map = C.GSON.fromJson(new InputStreamReader(zip.getInputStream(zip.getEntry("modpack.json")), "UTF-8"), HashMap.class);
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
@@ -116,6 +104,7 @@ public final class ModpackManager {
|
|||||||
throw new IllegalStateException("Illegal modpack id!");
|
throw new IllegalStateException("Illegal modpack id!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show a window to let the user know that what and how the modpack is.
|
||||||
Object msgs[] = new Object[2];
|
Object msgs[] = new Object[2];
|
||||||
msgs[0] = C.i18n("modpack.install.task");
|
msgs[0] = C.i18n("modpack.install.task");
|
||||||
msgs[1] = new WebPage(description);
|
msgs[1] = new WebPage(description);
|
||||||
@@ -124,6 +113,25 @@ public final class ModpackManager {
|
|||||||
if (result == JOptionPane.NO_OPTION)
|
if (result == JOptionPane.NO_OPTION)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
File versions = new File(service.baseDirectory(), "versions");
|
||||||
|
|
||||||
|
// `minecraft` folder is the existent root folder of the modpack
|
||||||
|
// Then we will decompress the modpack and there would be a folder named `minecraft`
|
||||||
|
// So if `minecraft` folder does exist, backup it and then restore it.
|
||||||
|
File oldFile = new File(versions, "minecraft"), newFile = null;
|
||||||
|
if (oldFile.exists()) {
|
||||||
|
newFile = new File(versions, "minecraft-" + System.currentTimeMillis());
|
||||||
|
if (newFile.isDirectory())
|
||||||
|
FileUtils.deleteDirectory(newFile);
|
||||||
|
else if (newFile.isFile())
|
||||||
|
if (!newFile.delete())
|
||||||
|
HMCLog.warn("Failed to delete file " + newFile);
|
||||||
|
if (!oldFile.renameTo(newFile))
|
||||||
|
HMCLog.warn("Failed to rename " + oldFile + " to " + newFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the user install the modpack into an existent version, maybe it wants to update the modpack
|
||||||
|
// So backup the game, copy the saved games.
|
||||||
File preVersion = new File(versions, id), preVersionRenamed = null;
|
File preVersion = new File(versions, id), preVersionRenamed = null;
|
||||||
if (preVersion.exists()) {
|
if (preVersion.exists()) {
|
||||||
HMCLog.log("Backing up the game");
|
HMCLog.log("Backing up the game");
|
||||||
@@ -132,6 +140,7 @@ public final class ModpackManager {
|
|||||||
HMCLog.warn("Failed to rename pre-version folder " + preVersion + " to a temp folder " + preVersionRenamed);
|
HMCLog.warn("Failed to rename pre-version folder " + preVersion + " to a temp folder " + preVersionRenamed);
|
||||||
if (!new File(preVersionRenamed, id + ".json").renameTo(new File(preVersionRenamed, preId + ".json")))
|
if (!new File(preVersionRenamed, id + ".json").renameTo(new File(preVersionRenamed, preId + ".json")))
|
||||||
HMCLog.warn("Failed to rename pre json to new json");
|
HMCLog.warn("Failed to rename pre json to new json");
|
||||||
|
|
||||||
if (!new File(preVersionRenamed, id + ".jar").renameTo(new File(preVersionRenamed, preId + ".jar")))
|
if (!new File(preVersionRenamed, id + ".jar").renameTo(new File(preVersionRenamed, preId + ".jar")))
|
||||||
HMCLog.warn("Failed to rename pre jar to new jar");
|
HMCLog.warn("Failed to rename pre jar to new jar");
|
||||||
}
|
}
|
||||||
@@ -144,6 +153,8 @@ public final class ModpackManager {
|
|||||||
b.incrementAndGet();
|
b.incrementAndGet();
|
||||||
return true;
|
return true;
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
// No pack.json here, illegal modpack.
|
||||||
if (b.get() < 1)
|
if (b.get() < 1)
|
||||||
throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_json"));
|
throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_json"));
|
||||||
File nowFile = new File(versions, id);
|
File nowFile = new File(versions, id);
|
||||||
@@ -161,6 +172,7 @@ public final class ModpackManager {
|
|||||||
if (!json.renameTo(new File(nowFile, id + ".json")))
|
if (!json.renameTo(new File(nowFile, id + ".json")))
|
||||||
HMCLog.warn("Failed to rename pack.json to new id");
|
HMCLog.warn("Failed to rename pack.json to new id");
|
||||||
|
|
||||||
|
// Restore the saved game from the old version.
|
||||||
if (preVersionRenamed != null) {
|
if (preVersionRenamed != null) {
|
||||||
HMCLog.log("Restoring saves");
|
HMCLog.log("Restoring saves");
|
||||||
File presaves = new File(preVersionRenamed, "saves");
|
File presaves = new File(preVersionRenamed, "saves");
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
mcVersion = C.GSON.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
mcVersion = C.GSON.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
||||||
if (mcVersion == null)
|
if (mcVersion == null)
|
||||||
throw new GameException("Wrong json format, got null.");
|
throw new GameException("Wrong json format, got null.");
|
||||||
} catch (IOException | GameException ex) {
|
} catch (IOException | GameException | JsonSyntaxException ex) {
|
||||||
HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", ex);
|
HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", ex);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
for (MinecraftVersion s : getVersions()) {
|
for (MinecraftVersion s : getVersions()) {
|
||||||
FileUtils.deleteDirectoryQuietly(new File(versionRoot(s.id), s.id + "-natives"));
|
FileUtils.deleteDirectoryQuietly(new File(versionRoot(s.id), s.id + "-natives"));
|
||||||
File f = getRunDirectory(s.id);
|
File f = getRunDirectory(s.id);
|
||||||
String[] dir = { "asm", "NVIDIA", "server-resource-packs", "natives", "native" };
|
String[] dir = { "natives", "native", "$native", "AMD", "crash-reports", "logs", "asm", "NVIDIA", "server-resource-packs", "natives", "native" };
|
||||||
for (String str : dir)
|
for (String str : dir)
|
||||||
FileUtils.deleteDirectoryQuietly(new File(f, str));
|
FileUtils.deleteDirectoryQuietly(new File(f, str));
|
||||||
String[] files = { "output-client.log", "usercache.json", "usernamecache.json", "hmclmc.log" };
|
String[] files = { "output-client.log", "usercache.json", "usernamecache.json", "hmclmc.log" };
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class LaunchingUIDaemon {
|
|||||||
WebFrame f = new WebFrame(jpm.getJavaProcess().getStdOutLines().toArray(new String[0]));
|
WebFrame f = new WebFrame(jpm.getJavaProcess().getStdOutLines().toArray(new String[0]));
|
||||||
f.setTitle("Game output");
|
f.setTitle("Game output");
|
||||||
f.setVisible(true);
|
f.setVisible(true);
|
||||||
|
checkExit((LauncherVisibility) obj.getTag());
|
||||||
});
|
});
|
||||||
jpm.jvmLaunchFailedEvent.register(t -> {
|
jpm.jvmLaunchFailedEvent.register(t -> {
|
||||||
HMCLog.err("Cannot create jvm, exit code: " + t);
|
HMCLog.err("Cannot create jvm, exit code: " + t);
|
||||||
@@ -83,13 +84,9 @@ public class LaunchingUIDaemon {
|
|||||||
WebFrame f = new WebFrame(jpm.getJavaProcess().getStdOutLines().toArray(new String[0]));
|
WebFrame f = new WebFrame(jpm.getJavaProcess().getStdOutLines().toArray(new String[0]));
|
||||||
f.setTitle("Game output");
|
f.setTitle("Game output");
|
||||||
f.setVisible(true);
|
f.setVisible(true);
|
||||||
|
checkExit((LauncherVisibility) obj.getTag());
|
||||||
});
|
});
|
||||||
jpm.stoppedEvent.register(() -> {
|
jpm.stoppedEvent.register(() -> checkExit((LauncherVisibility) obj.getTag()));
|
||||||
if ((LauncherVisibility) obj.getTag() == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible()) {
|
|
||||||
HMCLog.log("With the option of closing the launcher anyway, the launcher will exit and will NOT catch game logs.");
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
jpm.start();
|
jpm.start();
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
@@ -101,6 +98,11 @@ public class LaunchingUIDaemon {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static void checkExit(LauncherVisibility v) {
|
||||||
|
if (v != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible())
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
private static final Event<List<String>> LAUNCH_SCRIPT_FINISHER = (sender, str) -> {
|
private static final Event<List<String>> LAUNCH_SCRIPT_FINISHER = (sender, str) -> {
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import org.jackhuang.hellominecraft.util.Pair;
|
|||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
import org.jackhuang.hellominecraft.util.Utils;
|
import org.jackhuang.hellominecraft.util.Utils;
|
||||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||||
|
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.util.system.ZipEngine;
|
import org.jackhuang.hellominecraft.util.system.ZipEngine;
|
||||||
import org.jackhuang.hellominecraft.util.ui.WebPage;
|
import org.jackhuang.hellominecraft.util.ui.WebPage;
|
||||||
import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeNode;
|
import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeNode;
|
||||||
@@ -111,7 +112,8 @@ public class ModpackWizard extends WizardBranchController {
|
|||||||
boolean flag = true;
|
boolean flag = true;
|
||||||
ZipEngine engine = new ZipEngine(loc);
|
ZipEngine engine = new ZipEngine(loc);
|
||||||
Config s = new Config();
|
Config s = new Config();
|
||||||
//s.setBgpath(Settings.getInstance().getBgpath());
|
if (!IOUtils.isAbsolutePath(Settings.getInstance().getBgpath()))
|
||||||
|
s.setBgpath(Settings.getInstance().getBgpath());
|
||||||
s.setDownloadType(Settings.getInstance().getDownloadType());
|
s.setDownloadType(Settings.getInstance().getDownloadType());
|
||||||
engine.putTextFile(C.GSON.toJson(s), "hmcl.json");
|
engine.putTextFile(C.GSON.toJson(s), "hmcl.json");
|
||||||
engine.putFile(modpack, "modpack.zip");
|
engine.putFile(modpack, "modpack.zip");
|
||||||
|
|||||||
@@ -124,6 +124,10 @@ public class IOUtils {
|
|||||||
return realPath;
|
return realPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isAbsolutePath(String path) {
|
||||||
|
return path.startsWith("/") || path.indexOf(":") > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static File currentDir() {
|
public static File currentDir() {
|
||||||
return new File(".");
|
return new File(".");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||||
</SyntheticProperties>
|
</SyntheticProperties>
|
||||||
<Events>
|
<Events>
|
||||||
<EventHandler event="windowClosed" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosed"/>
|
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
|
||||||
</Events>
|
</Events>
|
||||||
<AuxValues>
|
<AuxValues>
|
||||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ public class LogWindow extends javax.swing.JFrame {
|
|||||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
setTitle(C.i18n("logwindow.title")); // NOI18N
|
setTitle(C.i18n("logwindow.title")); // NOI18N
|
||||||
addWindowListener(new java.awt.event.WindowAdapter() {
|
addWindowListener(new java.awt.event.WindowAdapter() {
|
||||||
public void windowClosed(java.awt.event.WindowEvent evt) {
|
public void windowClosing(java.awt.event.WindowEvent evt) {
|
||||||
formWindowClosed(evt);
|
formWindowClosing(evt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -172,14 +172,14 @@ public class LogWindow extends javax.swing.JFrame {
|
|||||||
.addComponent(btnClear)
|
.addComponent(btnClear)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(btnClose))
|
.addComponent(btnClose))
|
||||||
.addComponent(lblCrash, javax.swing.GroupLayout.Alignment.LEADING))
|
.addComponent(lblCrash, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||||
.addContainerGap())
|
.addContainerGap())
|
||||||
);
|
);
|
||||||
layout.setVerticalGroup(
|
layout.setVerticalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(lblCrash, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(lblCrash)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
|
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
@@ -199,33 +199,15 @@ public class LogWindow extends javax.swing.JFrame {
|
|||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
|
private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
|
||||||
boolean flag = false;
|
if (listener != null && listener.apply() && terminateGameListener != null)
|
||||||
for (Frame f : Frame.getFrames()) {
|
terminateGameListener.run();
|
||||||
if (f == this)
|
SwingUtils.exitIfNoWindow(this, true);
|
||||||
continue;
|
|
||||||
if (f.isVisible())
|
|
||||||
flag = true;
|
|
||||||
}
|
|
||||||
if (flag)
|
|
||||||
this.dispose();
|
|
||||||
else
|
|
||||||
try {
|
|
||||||
Utils.shutdownForcely(0);
|
|
||||||
} catch (Exception e) {
|
|
||||||
MessageBox.Show(C.i18n("launcher.exit_failed"));
|
|
||||||
HMCLog.err("Failed to shutdown forcely", e);
|
|
||||||
}
|
|
||||||
}//GEN-LAST:event_btnCloseActionPerformed
|
}//GEN-LAST:event_btnCloseActionPerformed
|
||||||
|
|
||||||
private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed
|
private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed
|
||||||
this.txtLog.setText("");
|
this.txtLog.setText("");
|
||||||
}//GEN-LAST:event_btnClearActionPerformed
|
}//GEN-LAST:event_btnClearActionPerformed
|
||||||
|
|
||||||
private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
|
|
||||||
if (listener != null && listener.apply() && terminateGameListener != null)
|
|
||||||
terminateGameListener.run();
|
|
||||||
}//GEN-LAST:event_formWindowClosed
|
|
||||||
|
|
||||||
private void btnCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCopyActionPerformed
|
private void btnCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCopyActionPerformed
|
||||||
Utils.setClipborad(this.txtLog.getText());
|
Utils.setClipborad(this.txtLog.getText());
|
||||||
}//GEN-LAST:event_btnCopyActionPerformed
|
}//GEN-LAST:event_btnCopyActionPerformed
|
||||||
@@ -251,6 +233,12 @@ public class LogWindow extends javax.swing.JFrame {
|
|||||||
SwingUtils.openLink(C.URL_GITHUB);
|
SwingUtils.openLink(C.URL_GITHUB);
|
||||||
}//GEN-LAST:event_btnGitHubActionPerformed
|
}//GEN-LAST:event_btnGitHubActionPerformed
|
||||||
|
|
||||||
|
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
|
||||||
|
if (listener != null && listener.apply() && terminateGameListener != null)
|
||||||
|
terminateGameListener.run();
|
||||||
|
SwingUtils.exitIfNoWindow(this);
|
||||||
|
}//GEN-LAST:event_formWindowClosing
|
||||||
|
|
||||||
public void log(String status) {
|
public void log(String status) {
|
||||||
log(status, Level.INFO);
|
log(status, Level.INFO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package org.jackhuang.hellominecraft.util.ui;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Frame;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@@ -41,6 +42,7 @@ import org.jackhuang.hellominecraft.util.C;
|
|||||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
|
import org.jackhuang.hellominecraft.util.Utils;
|
||||||
import org.jackhuang.hellominecraft.util.func.NonFunction;
|
import org.jackhuang.hellominecraft.util.func.NonFunction;
|
||||||
import org.jackhuang.hellominecraft.util.system.OS;
|
import org.jackhuang.hellominecraft.util.system.OS;
|
||||||
|
|
||||||
@@ -276,4 +278,27 @@ public class SwingUtils {
|
|||||||
}
|
}
|
||||||
component.setEnabled(t);
|
component.setEnabled(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void exitIfNoWindow(Frame thisFrame) {
|
||||||
|
exitIfNoWindow(thisFrame, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void exitIfNoWindow(Frame thisFrame, boolean neededDispose) {
|
||||||
|
boolean flag = false;
|
||||||
|
for (Frame f : Frame.getFrames()) {
|
||||||
|
if (f == thisFrame)
|
||||||
|
continue;
|
||||||
|
if (f.isVisible())
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
if (!flag)
|
||||||
|
try {
|
||||||
|
Utils.shutdownForcely(0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
MessageBox.Show(C.i18n("launcher.exit_failed"));
|
||||||
|
HMCLog.err("Failed to shutdown forcely", e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
thisFrame.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,15 +45,7 @@ public class WebFrame extends JFrame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
boolean flag = false;
|
SwingUtils.exitIfNoWindow(WebFrame.this);
|
||||||
for (Frame f : Frame.getFrames()) {
|
|
||||||
if (f == WebFrame.this)
|
|
||||||
continue;
|
|
||||||
if (f.isVisible())
|
|
||||||
flag = true;
|
|
||||||
}
|
|
||||||
if (!flag)
|
|
||||||
System.exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user