mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2024-12-15 06:50:12 +08:00
fix(auto-installing): catch logs of forge-installer. Closes #1420.
This commit is contained in:
parent
fd098a65c5
commit
1aa3860706
@ -23,7 +23,6 @@ import javafx.application.Platform;
|
||||
import org.jackhuang.hmcl.Metadata;
|
||||
import org.jackhuang.hmcl.event.Event;
|
||||
import org.jackhuang.hmcl.event.EventManager;
|
||||
import org.jackhuang.hmcl.launch.StreamPump;
|
||||
import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.ui.FXUtils;
|
||||
@ -358,8 +357,8 @@ public final class MultiplayerManager {
|
||||
|
||||
this.type = type;
|
||||
addRelatedThread(Lang.thread(this::waitFor, "CatoExitWaiter", true));
|
||||
addRelatedThread(Lang.thread(new StreamPump(process.getInputStream(), this::checkCatoLog), "CatoInputStreamPump", true));
|
||||
addRelatedThread(Lang.thread(new StreamPump(process.getErrorStream(), this::checkCatoLog), "CatoErrorStreamPump", true));
|
||||
pumpInputStream(this::checkCatoLog);
|
||||
pumpErrorStream(this::checkCatoLog);
|
||||
|
||||
writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
@ -17,8 +17,13 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.util.platform;
|
||||
|
||||
import org.jackhuang.hmcl.launch.StreamPump;
|
||||
import org.jackhuang.hmcl.util.Lang;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* The managed process.
|
||||
@ -36,6 +41,12 @@ public class ManagedProcess {
|
||||
private final Queue<String> lines = new ConcurrentLinkedQueue<>();
|
||||
private final List<Thread> relatedThreads = new ArrayList<>();
|
||||
|
||||
public ManagedProcess(ProcessBuilder processBuilder) throws IOException {
|
||||
this.process = processBuilder.start();
|
||||
this.commands = processBuilder.command();
|
||||
this.classpath = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -119,6 +130,14 @@ public class ManagedProcess {
|
||||
relatedThreads.add(thread);
|
||||
}
|
||||
|
||||
public synchronized void pumpInputStream(Consumer<String> onLogLine) {
|
||||
addRelatedThread(Lang.thread(new StreamPump(process.getInputStream(), onLogLine), "ProcessInputStreamPump", true));
|
||||
}
|
||||
|
||||
public synchronized void pumpErrorStream(Consumer<String> onLogLine) {
|
||||
addRelatedThread(Lang.thread(new StreamPump(process.getErrorStream(), onLogLine), "ProcessErrorStreamPump", true));
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the managed process is running.
|
||||
*/
|
||||
|
@ -18,10 +18,11 @@
|
||||
package org.jackhuang.hmcl.util.platform;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||
|
||||
public final class SystemUtils {
|
||||
private SystemUtils() {}
|
||||
|
||||
@ -30,10 +31,14 @@ public final class SystemUtils {
|
||||
}
|
||||
|
||||
public static int callExternalProcess(List<String> command) throws IOException, InterruptedException {
|
||||
Process process = new ProcessBuilder(command)
|
||||
.redirectOutput(Redirect.INHERIT)
|
||||
.redirectError(Redirect.INHERIT)
|
||||
.start();
|
||||
return process.waitFor();
|
||||
ManagedProcess managedProcess = new ManagedProcess(new ProcessBuilder(command));
|
||||
managedProcess.pumpInputStream(SystemUtils::onLogLine);
|
||||
managedProcess.pumpErrorStream(SystemUtils::onLogLine);
|
||||
return managedProcess.getProcess().waitFor();
|
||||
}
|
||||
|
||||
private static void onLogLine(String log) {
|
||||
LOG.info(log);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user