From 1c1aa37fd7679e47aec47e551f455b450bbb3cae Mon Sep 17 00:00:00 2001 From: noberumotto Date: Mon, 28 Nov 2022 17:30:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BF=BD=E7=95=A5=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=8A=9F=E8=83=BD=E5=A2=9E=E5=8A=A0=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Core.csproj | 1 + Core/Librarys/RegexHelper.cs | 31 ++++++++++++++++++++++++ Core/Models/Config/BehaviorModel.cs | 2 +- Core/Servicers/Instances/Main.cs | 3 +-- UI/Controls/SettingPanel/SettingPanel.cs | 8 ++++++ UI/Models/DetailPageModel.cs | 5 ++++ UI/ViewModels/DetailPageVM.cs | 13 ++++++++++ UI/Views/DetailPage.xaml | 28 ++++++++++++++------- 8 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 Core/Librarys/RegexHelper.cs diff --git a/Core/Core.csproj b/Core/Core.csproj index 5ed8a9c..31ac218 100644 --- a/Core/Core.csproj +++ b/Core/Core.csproj @@ -144,6 +144,7 @@ + diff --git a/Core/Librarys/RegexHelper.cs b/Core/Librarys/RegexHelper.cs new file mode 100644 index 0000000..2a5ab09 --- /dev/null +++ b/Core/Librarys/RegexHelper.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Core.Librarys +{ + public static class RegexHelper + { + /// + /// 是否正则匹配成功 + /// + /// + /// + /// + public static bool IsMatch(string input, string pattern) + { + try + { + return Regex.IsMatch(input, pattern); + } + catch (Exception ex) + { + Logger.Error("正则表达式错误。" + ex.ToString()); + return false; + } + } + } +} diff --git a/Core/Models/Config/BehaviorModel.cs b/Core/Models/Config/BehaviorModel.cs index 266ad9c..7108f14 100644 --- a/Core/Models/Config/BehaviorModel.cs +++ b/Core/Models/Config/BehaviorModel.cs @@ -11,7 +11,7 @@ namespace Core.Models.Config /// public class BehaviorModel { - [Config(IsCanImportExport = true, Name = "忽略应用", Description = "忽略的应用将不进行时长统计", Group = "忽略应用", Placeholder = "应用进程名称,不需要输入.exe。支持正则表达式")] + [Config(IsCanImportExport = true, Name = "忽略应用", Description = "可以通过进程名称或者正则表达式进行匹配。当使用正则表达式时可以匹配程序路径", Group = "忽略应用", Placeholder = "进程名称,不需要输入.exe。支持正则表达式")] /// /// 忽略的进程列表 /// diff --git a/Core/Servicers/Instances/Main.cs b/Core/Servicers/Instances/Main.cs index 2c72f91..333fbe4 100644 --- a/Core/Servicers/Instances/Main.cs +++ b/Core/Servicers/Instances/Main.cs @@ -254,10 +254,9 @@ private bool IsCheckApp(string processName, string description, string file) // 正则表达式 foreach (string reg in ConfigIgnoreProcessRegxList) { - if (Regex.IsMatch(processName, reg)) + if (RegexHelper.IsMatch(processName, reg) || RegexHelper.IsMatch(file, reg)) { IgnoreProcessCacheList.Add(processName); - return false; } } diff --git a/UI/Controls/SettingPanel/SettingPanel.cs b/UI/Controls/SettingPanel/SettingPanel.cs index d3c2e71..e06a24a 100644 --- a/UI/Controls/SettingPanel/SettingPanel.cs +++ b/UI/Controls/SettingPanel/SettingPanel.cs @@ -484,6 +484,14 @@ private UIElement RenderListStringConfigControl(ConfigAttribute configAttribute, { listControl.Items.Remove(listControl.SelectedItem); }; + var contextMenuItemCopy = new MenuItem(); + contextMenuItemCopy.Header = "复制内容"; + contextMenuItemCopy.Click += (e, c) => + { + Clipboard.SetText(listControl.SelectedItem); + }; + contextMenu.Items.Add(contextMenuItemCopy); + contextMenu.Items.Add(new Separator()); contextMenu.Items.Add(contextMenuItemDel); listControl.ContextMenu = contextMenu; diff --git a/UI/Models/DetailPageModel.cs b/UI/Models/DetailPageModel.cs index eb20092..57353aa 100644 --- a/UI/Models/DetailPageModel.cs +++ b/UI/Models/DetailPageModel.cs @@ -161,5 +161,10 @@ public int TabbarSelectedIndex /// 关联的应用 /// public List LinkApps { get { return LinkApps_; } set { LinkApps_ = value; OnPropertyChanged(); } } + private bool IsRegexIgnore_; + /// + /// 是否已被正则忽略 + /// + public bool IsRegexIgnore { get { return IsRegexIgnore_; } set { IsRegexIgnore_ = value; OnPropertyChanged(); } } } } diff --git a/UI/ViewModels/DetailPageVM.cs b/UI/ViewModels/DetailPageVM.cs index 4d9e345..ec8ebce 100644 --- a/UI/ViewModels/DetailPageVM.cs +++ b/UI/ViewModels/DetailPageVM.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using UI.Controls; @@ -98,8 +99,20 @@ private async void Init() LoadDayData(); inputServicer.OnKeyUpInput += InputServicer_OnKeyUpInput; + + // 判断正则忽略 + var regexList = config.Behavior.IgnoreProcessList.Where(m => Regex.IsMatch(m, @"[\.|\*|\?|\{|\\|\[|\^|\|]")); + foreach (string reg in regexList) + { + if (RegexHelper.IsMatch(App.Name, reg) || RegexHelper.IsMatch(App.File, reg)) + { + IsRegexIgnore = true; + break; + } + } } + private async void InputServicer_OnKeyUpInput(object sender, System.Windows.Forms.Keys key) { if (key == System.Windows.Forms.Keys.F5) diff --git a/UI/Views/DetailPage.xaml b/UI/Views/DetailPage.xaml index 058ae06..4a2173d 100644 --- a/UI/Views/DetailPage.xaml +++ b/UI/Views/DetailPage.xaml @@ -56,13 +56,22 @@ --> - - - - - - - + + + + + + + + + + + + + + + + @@ -85,12 +94,13 @@ - + + 忽略此应用 取消忽略 - +