Improve Emulator management layout
This commit is contained in:
1 parent
8520c599b4
commit
5e6afd32d4
3 files changed
+234
-67
No files matched your search
+7
-3
@@ -51,7 +51,7 @@ internal static class EmulatorCli
|
||||
using var process = Process.Start(info) ?? throw new InvalidOperationException("无法启动 Emulator。");
|
||||
process.StandardInput.Close();
|
||||
var capture = args[0] is "-list" or "-imageList";
|
||||
var stdout = ReadAsync(process.StandardOutput, log, capture, cancellation);
|
||||
var stdout = ReadAsync(process.StandardOutput, capture ? null : log, capture, cancellation);
|
||||
var stderr = ReadAsync(process.StandardError, log, false, cancellation);
|
||||
try
|
||||
{
|
||||
@@ -66,17 +66,21 @@ internal static class EmulatorCli
|
||||
}
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
if (capture)
|
||||
log(await stdout);
|
||||
throw new InvalidOperationException($"Emulator 退出码 {process.ExitCode}。请查看命令输出。");
|
||||
}
|
||||
return await stdout;
|
||||
}
|
||||
|
||||
private static async Task<string> ReadAsync(
|
||||
StreamReader reader, Action<string> log, bool capture, CancellationToken cancellation)
|
||||
StreamReader reader, Action<string>? log, bool capture, CancellationToken cancellation)
|
||||
{
|
||||
var output = new System.Text.StringBuilder();
|
||||
while (await reader.ReadLineAsync(cancellation) is { } line)
|
||||
{
|
||||
log(line);
|
||||
log?.Invoke(line);
|
||||
if (capture)
|
||||
output.AppendLine(line);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user