From a65bbfbf53f52e3f0fbdd9210c6fa8a954112480 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Sat, 30 Aug 2025 22:29:31 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20Copilot=20?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/UI/CopilotViewModel.cs | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs index e87e7ae788..0dde92469e 100644 --- a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs @@ -1422,25 +1422,25 @@ namespace MaaWpfGui.ViewModels.UI private async Task VerifyCopilotListTask() { - var list = CopilotItemViewModels.Where(i => i.IsChecked); - if (list.Any(i => string.IsNullOrEmpty(i.Name.Trim()))) + var copilotItemViewModels = CopilotItemViewModels.Where(i => i.IsChecked).ToArray(); + + if (copilotItemViewModels.Any(i => string.IsNullOrEmpty(i.Name.Trim()))) { AddLog(LocalizationHelper.GetString("CopilotTasksWithEmptyName"), UiLogColor.Error, showTime: false); return false; } - if (!list.Any()) + switch (copilotItemViewModels.Length) { - AddLog(LocalizationHelper.GetString("Copilot.StartWithEmptyList"), UiLogColor.Error, showTime: false); - return false; - } - else if (list.Count() == 1) - { - AddLog(LocalizationHelper.GetString("CopilotSingleTaskWarning"), UiLogColor.Error, showTime: false); - return false; + case 0: + AddLog(LocalizationHelper.GetString("Copilot.StartWithEmptyList"), UiLogColor.Error, showTime: false); + return false; + case 1: + AddLog(LocalizationHelper.GetString("CopilotSingleTaskWarning"), UiLogColor.Error, showTime: false); + return false; } - var stageNames = list.Select(i => i.FilePath).ToHashSet().Select(async path => + var stageNames = copilotItemViewModels.Select(i => i.FilePath).ToHashSet().Select(async path => { if (!File.Exists(path)) { @@ -1455,20 +1455,22 @@ namespace MaaWpfGui.ViewModels.UI } catch (Exception ex) { - _logger.Error("could not read & parse copilot file: " + path, ex); + _logger.Error(ex, "could not read & parse copilot file: {Path}", path); return null; } }); foreach (var stageName in stageNames) { var name = await stageName; - if (string.IsNullOrEmpty(name) || DataHelper.FindMap(name) is null) + if (!string.IsNullOrEmpty(name) && DataHelper.FindMap(name) is not null) { - AddLog(LocalizationHelper.GetString("UnsupportedStages") + $" {name}", UiLogColor.Error, showTime: false); - _ = Task.Run(ResourceUpdater.ResourceUpdateAndReloadAsync); - AchievementTrackerHelper.Instance.Unlock(AchievementIds.MapOutdated); - return false; + continue; } + + AddLog(LocalizationHelper.GetString("UnsupportedStages") + $" {name}", UiLogColor.Error, showTime: false); + _ = Task.Run(ResourceUpdater.ResourceUpdateAndReloadAsync); + AchievementTrackerHelper.Instance.Unlock(AchievementIds.MapOutdated); + return false; } return true;