Fixed wrong action in mod management.

This commit is contained in:
huanghongxun
2015-09-04 19:24:26 +08:00
parent e727ca331f
commit 6e003a7364
16 changed files with 73 additions and 51 deletions

View File

@@ -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;
}
}

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -22,5 +22,5 @@ package org.jackhuang.hellominecraft.utils.functions;
*/
public interface NonFunction<T> {
T onDone();
T apply();
}

View File

@@ -27,7 +27,7 @@ public class TrueFunction implements NonFunction<Boolean> {
private TrueFunction(){}
@Override
public Boolean onDone() {
public Boolean apply() {
return Boolean.TRUE;
}

View File

@@ -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;
};

View File

@@ -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() {
}
}

View File

@@ -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