From 2d6b399a077d471b66dd5c10472d24aa621a73ac Mon Sep 17 00:00:00 2001 From: huiyadanli Date: Thu, 8 Feb 2024 19:56:10 +0800 Subject: [PATCH] more user-friendly parsing of error messages --- .../GameTask/AutoPick/AutoPickTrigger.cs | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs b/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs index a5a87c80..fd282284 100644 --- a/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs +++ b/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Text.Json; +using System.Windows.Forms; using BetterGenshinImpact.Helpers; using WindowsInput; @@ -45,16 +46,32 @@ public class AutoPickTrigger : ITaskTrigger public void Init() { IsEnabled = TaskContext.Instance().Config.AutoPickConfig.Enabled; - var blackListJson = Global.ReadAllTextIfExist("User\\pick_black_lists.json"); - if (!string.IsNullOrEmpty(blackListJson)) + try { - _blackList = JsonSerializer.Deserialize>(blackListJson) ?? new List(); + var blackListJson = Global.ReadAllTextIfExist("User\\pick_black_lists.json"); + if (!string.IsNullOrEmpty(blackListJson)) + { + _blackList = JsonSerializer.Deserialize>(blackListJson) ?? new List(); + } + } + catch (Exception e) + { + _logger.LogError(e, "读取拾取黑名单失败"); + MessageBox.Show("读取拾取黑名单失败,请确认修改后的拾取黑名单内容格式是否正确!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } - var whiteListJson = Global.ReadAllTextIfExist("User\\pick_white_lists.json"); - if (!string.IsNullOrEmpty(whiteListJson)) + try { - _whiteList = JsonSerializer.Deserialize>(whiteListJson) ?? new List(); + var whiteListJson = Global.ReadAllTextIfExist("User\\pick_white_lists.json"); + if (!string.IsNullOrEmpty(whiteListJson)) + { + _whiteList = JsonSerializer.Deserialize>(whiteListJson) ?? new List(); + } + } + catch (Exception e) + { + _logger.LogError(e, "读取拾取白名单失败"); + MessageBox.Show("读取拾取白名单失败,请确认修改后的拾取白名单内容格式是否正确!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -72,7 +89,7 @@ public class AutoPickTrigger : ITaskTrigger public void OnCapture(CaptureContent content) { - var speedTimer = new SpeedTimer(); + var speedTimer = new SpeedTimer(); content.CaptureRectArea.Find(_autoPickAssets.FRo, foundRectArea => { speedTimer.Record("识别到 F 拾取键"); @@ -136,6 +153,7 @@ public class AutoPickTrigger : ITaskTrigger { return; } + // 单个字符不拾取 if (text.Length <= 1) { @@ -148,6 +166,7 @@ public class AutoPickTrigger : ITaskTrigger Simulation.SendInput.Keyboard.KeyPress(VirtualKeyCode.VK_F); return; } + speedTimer.Record("白名单判断"); if (isExcludeIcon) @@ -160,6 +179,7 @@ public class AutoPickTrigger : ITaskTrigger { return; } + speedTimer.Record("黑名单判断"); LogPick(content, text);