diff --git a/src/MaaWpfGui/Helper/WinAdapter.cs b/src/MaaWpfGui/Helper/WinAdapter.cs index 86e45c3702..1733e0e321 100644 --- a/src/MaaWpfGui/Helper/WinAdapter.cs +++ b/src/MaaWpfGui/Helper/WinAdapter.cs @@ -16,6 +16,8 @@ using System.Diagnostics; using System.IO; using System.Linq; using MaaWpfGui.Main; +using MaaWpfGui.ViewModels.UI; +using Serilog; namespace MaaWpfGui.Helper { @@ -24,6 +26,8 @@ namespace MaaWpfGui.Helper /// public class WinAdapter { + private static readonly ILogger _logger = Log.ForContext(); + private static readonly Dictionary _emulatorIdDict = new Dictionary { { "HD-Player", "BlueStacks" }, @@ -129,7 +133,7 @@ namespace MaaWpfGui.Helper process.StartInfo.RedirectStandardOutput = true; process.Start(); var output = process.StandardOutput.ReadToEnd(); - AsstProxy.AsstLog(adbPath + " devices | output:\n" + output); + _logger.Information(adbPath + " devices | output:\n" + output); var outLines = output.Split(new[] { '\r', '\n' }); foreach (var line in outLines) { diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index d14263b751..77c44ceb63 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -614,7 +614,7 @@ namespace MaaWpfGui.ViewModels.UI StartInfo = startInfo, }; - AsstProxy.AsstLog("Try to start emulator: \nfileName: " + fileName + "\narguments: " + arguments); + _logger.Information("Try to start emulator: \nfileName: " + fileName + "\narguments: " + arguments); process.Start(); try @@ -623,7 +623,7 @@ namespace MaaWpfGui.ViewModels.UI process.WaitForInputIdle(); if (MinimizingStartup) { - AsstProxy.AsstLog("Try minimizing the emulator"); + _logger.Information("Try minimizing the emulator"); int i; for (i = 0; !IsIconic(process.MainWindowHandle) && i < 100; ++i) { @@ -637,14 +637,14 @@ namespace MaaWpfGui.ViewModels.UI if (i >= 100) { - AsstProxy.AsstLog("Attempts to exceed the limit"); + _logger.Information("Attempts to exceed the limit"); throw new Exception(); } } } catch (Exception) { - AsstProxy.AsstLog("The emulator was already start"); + _logger.Information("The emulator was already start"); // 如果之前就启动了模拟器,如果开启了最小化启动,就把所有模拟器最小化 // TODO:只最小化需要开启的模拟器 @@ -654,7 +654,7 @@ namespace MaaWpfGui.ViewModels.UI { if (MinimizingStartup) { - AsstProxy.AsstLog("Try minimizing the emulator by processName: " + processName); + _logger.Information("Try minimizing the emulator by processName: " + processName); foreach (Process p in processes) { int i; @@ -666,7 +666,7 @@ namespace MaaWpfGui.ViewModels.UI if (i >= 100) { - AsstProxy.AsstLog("The emulator minimization failure"); + _logger.Warning("The emulator minimization failure"); } } } @@ -675,7 +675,7 @@ namespace MaaWpfGui.ViewModels.UI } catch (Exception) { - AsstProxy.AsstLog("Start emulator error, try to start using the default: \n" + + _logger.Information("Start emulator error, try to start using the default: \n" + "EmulatorPath: " + EmulatorPath + "\n" + "EmulatorAddCommand: " + EmulatorAddCommand); if (EmulatorAddCommand.Length != 0) @@ -697,7 +697,7 @@ namespace MaaWpfGui.ViewModels.UI { if (Instances.TaskQueueViewModel.Stopping) { - AsstProxy.AsstLog("Stop waiting for the emulator to start"); + _logger.Information("Stop waiting for the emulator to start"); return; } @@ -705,7 +705,7 @@ namespace MaaWpfGui.ViewModels.UI { Execute.OnUIThread(() => Instances.TaskQueueViewModel.AddLog( LocalizationHelper.GetString("WaitForEmulator") + ": " + (delay - i) + "s")); - AsstProxy.AsstLog("Waiting for the emulator to start: " + (delay - i) + "s"); + _logger.Information("Waiting for the emulator to start: " + (delay - i) + "s"); } Thread.Sleep(1000); @@ -713,7 +713,7 @@ namespace MaaWpfGui.ViewModels.UI Execute.OnUIThread(() => Instances.TaskQueueViewModel.AddLog( LocalizationHelper.GetString("WaitForEmulatorFinish"))); - AsstProxy.AsstLog("The wait is over"); + _logger.Information("The wait is over"); // 重置按钮状态,不影响后续判断 Instances.TaskQueueViewModel.Idle = idle; diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index 15bbab8ecb..756d557562 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -1111,7 +1111,7 @@ namespace MaaWpfGui.ViewModels.UI } else { - AsstProxy.AsstLog($"Error: `{consolePath}` not found, try to kill eumlator by window."); + _logger.Error($"Error: `{consolePath}` not found, try to kill eumlator by window."); return KillEumlatorbyWindow(); } } @@ -1161,7 +1161,7 @@ namespace MaaWpfGui.ViewModels.UI } else { - AsstProxy.AsstLog($"Error: `{consolePath}` not found, try to kill eumlator by window."); + _logger.Information($"Error: `{consolePath}` not found, try to kill eumlator by window."); return KillEumlatorbyWindow(); } } @@ -1209,7 +1209,7 @@ namespace MaaWpfGui.ViewModels.UI } else { - AsstProxy.AsstLog($"Error: `{consolePath}` not found, try to kill eumlator by window."); + _logger.Information($"Error: `{consolePath}` not found, try to kill eumlator by window."); return KillEumlatorbyWindow(); } } @@ -1250,7 +1250,7 @@ namespace MaaWpfGui.ViewModels.UI } else { - AsstProxy.AsstLog($"Error: `{consolePath}` not found, try to kill eumlator by window."); + _logger.Information($"Error: `{consolePath}` not found, try to kill eumlator by window."); return KillEumlatorbyWindow(); } } @@ -1273,12 +1273,12 @@ namespace MaaWpfGui.ViewModels.UI if (File.Exists(consolePath)) { - AsstProxy.AsstLog($"Info: `{consolePath}` has been found. This may be the BlueStacks China emulator, try to kill the emulator by window."); + _logger.Information($"Info: `{consolePath}` has been found. This may be the BlueStacks China emulator, try to kill the emulator by window."); return KillEumlatorbyWindow(); } else { - AsstProxy.AsstLog($"Info: `{consolePath}` not found. This may be the BlueStacks International emulator, try to kill the emulator by the port."); + _logger.Information($"Info: `{consolePath}` not found. This may be the BlueStacks International emulator, try to kill the emulator by the port."); if (KillEmulator()) { return true; @@ -1287,13 +1287,13 @@ namespace MaaWpfGui.ViewModels.UI { try { - AsstProxy.AsstLog($"Info: Failed to kill emulator by the port, try to kill emulator process with PID."); + _logger.Information($"Info: Failed to kill emulator by the port, try to kill emulator process with PID."); processes[0].Kill(); return processes[0].WaitForExit(20000); } catch (Exception ex) { - AsstProxy.AsstLog($"Error: Failed to kill emulator process with PID {processes[0].Id}. Exception: {ex.Message}"); + _logger.Information($"Error: Failed to kill emulator process with PID {processes[0].Id}. Exception: {ex.Message}"); } } }