Fixed wrong action in mod management.
This commit is contained in:
@@ -41,7 +41,8 @@ public class LauncherPrintStream extends PrintStream {
|
||||
a1.accept(paramString);
|
||||
}
|
||||
|
||||
public final void addPrintListener(Consumer<String> paraml) {
|
||||
public final LauncherPrintStream addPrintListener(Consumer<String> paraml) {
|
||||
this.printListeners.add(paraml);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,12 +168,12 @@ public final class Utils {
|
||||
/**
|
||||
* In order to fight against the permission manager.
|
||||
*/
|
||||
public static void shutdownForcely() {
|
||||
public static void shutdownForcely(int status) {
|
||||
try {
|
||||
Class z = Class.forName("java.lang.Shutdown");
|
||||
Method exit = z.getDeclaredMethod("exit", int.class);
|
||||
exit.setAccessible(true);
|
||||
exit.invoke(z, 0);
|
||||
exit.invoke(z, status);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
MessageBox.Show(C.i18n("launcher.exit_failed"));
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -23,7 +23,7 @@ package org.jackhuang.hellominecraft.utils.functions;
|
||||
public class FalseFunction implements NonFunction<Boolean> {
|
||||
|
||||
@Override
|
||||
public Boolean onDone() {
|
||||
public Boolean apply() {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,5 +22,5 @@ package org.jackhuang.hellominecraft.utils.functions;
|
||||
*/
|
||||
public interface NonFunction<T> {
|
||||
|
||||
T onDone();
|
||||
T apply();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class TrueFunction implements NonFunction<Boolean> {
|
||||
private TrueFunction(){}
|
||||
|
||||
@Override
|
||||
public Boolean onDone() {
|
||||
public Boolean apply() {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ public class JavaProcessMonitor {
|
||||
|
||||
public void start() {
|
||||
Event<JavaProcess> event = (sender2, t) -> {
|
||||
if(t.getExitCode() != 0) {
|
||||
MessageBox.Show(C.i18n("launch.exited_abnormally"));
|
||||
}
|
||||
processThreadStopped((ProcessThread) sender2, false);
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.system;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -47,23 +46,44 @@ public class ProcessThread extends Thread {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
InputStream in = null;
|
||||
BufferedReader br = null;
|
||||
if (enableReading)
|
||||
in = readError ? p.getRawProcess().getErrorStream() : p.getRawProcess().getInputStream();
|
||||
try {
|
||||
if (enableReading)
|
||||
InputStreamReader br;
|
||||
if (enableReading) {
|
||||
InputStream in = readError ? p.getRawProcess().getErrorStream() : p.getRawProcess().getInputStream();
|
||||
try {
|
||||
br = new BufferedReader(new InputStreamReader(in, System.getProperty("sun.jnu.encoding", "UTF-8")));
|
||||
br = new InputStreamReader(in, System.getProperty("sun.jnu.encoding", "UTF-8"));
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
HMCLog.warn("Unsupported encoding: " + System.getProperty("sun.jnu.encoding", "UTF-8"), ex);
|
||||
br = new BufferedReader(new InputStreamReader(in));
|
||||
br = new InputStreamReader(in);
|
||||
}
|
||||
}
|
||||
else br = null;
|
||||
|
||||
String line;
|
||||
int ch;
|
||||
String line = "";
|
||||
while (p.isRunning())
|
||||
if (enableReading)
|
||||
while ((line = br.readLine()) != null) {
|
||||
if (br != null)
|
||||
while ((ch = br.read()) != -1)
|
||||
if (ch == '\n') {
|
||||
printlnEvent.execute(line);
|
||||
if (readError) {
|
||||
System.err.println(line);
|
||||
p.getStdErrLines().add(line);
|
||||
} else {
|
||||
System.out.println(line);
|
||||
p.getStdOutLines().add(line);
|
||||
}
|
||||
line = "";
|
||||
} else
|
||||
line += (char) ch;
|
||||
else
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (br != null)
|
||||
while ((ch = br.read()) != -1)
|
||||
if (ch == '\n') {
|
||||
printlnEvent.execute(line);
|
||||
if (readError) {
|
||||
System.err.println(line);
|
||||
@@ -72,29 +92,12 @@ public class ProcessThread extends Thread {
|
||||
System.out.println(line);
|
||||
p.getStdOutLines().add(line);
|
||||
}
|
||||
}
|
||||
else
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (enableReading)
|
||||
while ((line = br.readLine()) != null) {
|
||||
printlnEvent.execute(line);
|
||||
if (readError) {
|
||||
System.err.println(line);
|
||||
p.getStdErrLines().add(line);
|
||||
} else {
|
||||
System.out.println(line);
|
||||
p.getStdOutLines().add(line);
|
||||
}
|
||||
}
|
||||
line = "";
|
||||
} else
|
||||
line += (char) ch;
|
||||
stopEvent.execute(p);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void stopped() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,8 @@ public class LogWindow extends javax.swing.JFrame {
|
||||
}//GEN-LAST:event_btnClearActionPerformed
|
||||
|
||||
private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
|
||||
if (listener != null && listener.onDone()) Utils.shutdownForcely();
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user