Skip to content

Commit

Permalink
更新忽略应用功能增加程序路径匹配
Browse files Browse the repository at this point in the history
  • Loading branch information
noberumotto committed Nov 28, 2022
1 parent 9450c4d commit 1c1aa37
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 12 deletions.
1 change: 1 addition & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<Compile Include="Event\EventHandler.cs" />
<Compile Include="Event\ObserverEventHandler.cs" />
<Compile Include="Librarys\ProcessHelper.cs" />
<Compile Include="Librarys\RegexHelper.cs" />
<Compile Include="Librarys\Shortcut.cs" />
<Compile Include="Librarys\Iconer.cs" />
<Compile Include="Librarys\SQLite\SQLiteBuilder.cs" />
Expand Down
31 changes: 31 additions & 0 deletions Core/Librarys/RegexHelper.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 是否正则匹配成功
/// </summary>
/// <param name="input"></param>
/// <param name="pattern"></param>
/// <returns></returns>
public static bool IsMatch(string input, string pattern)
{
try
{
return Regex.IsMatch(input, pattern);
}
catch (Exception ex)
{
Logger.Error("正则表达式错误。" + ex.ToString());
return false;
}
}
}
}
2 changes: 1 addition & 1 deletion Core/Models/Config/BehaviorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Core.Models.Config
/// </summary>
public class BehaviorModel
{
[Config(IsCanImportExport = true, Name = "忽略应用", Description = "忽略的应用将不进行时长统计", Group = "忽略应用", Placeholder = "应用进程名称,不需要输入.exe。支持正则表达式")]
[Config(IsCanImportExport = true, Name = "忽略应用", Description = "可以通过进程名称或者正则表达式进行匹配。当使用正则表达式时可以匹配程序路径", Group = "忽略应用", Placeholder = "进程名称,不需要输入.exe。支持正则表达式")]
/// <summary>
/// 忽略的进程列表
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions Core/Servicers/Instances/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
8 changes: 8 additions & 0 deletions UI/Controls/SettingPanel/SettingPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions UI/Models/DetailPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,10 @@ public int TabbarSelectedIndex
/// 关联的应用
/// </summary>
public List<AppModel> LinkApps { get { return LinkApps_; } set { LinkApps_ = value; OnPropertyChanged(); } }
private bool IsRegexIgnore_;
/// <summary>
/// 是否已被正则忽略
/// </summary>
public bool IsRegexIgnore { get { return IsRegexIgnore_; } set { IsRegexIgnore_ = value; OnPropertyChanged(); } }
}
}
13 changes: 13 additions & 0 deletions UI/ViewModels/DetailPageVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 19 additions & 9 deletions UI/Views/DetailPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,22 @@
<TextBlock ToolTip="进程名" Text="{Binding ProcessName}" FontSize="12" Foreground="Gray" VerticalAlignment="Center" Margin="10,0,0,0"/>
</StackPanel>-->
<Border Background="#f51837" Padding="10,5" CornerRadius="4" Margin="0,0,0,5" VerticalAlignment="Center" HorizontalAlignment="Left" Visibility="{Binding CancelBlockBtnVisibility}" ToolTip="该应用将不再统计使用时长">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<base:Icon IconType="StatusCircleBlock" FontSize="12" VerticalAlignment="Center" Foreground="White"/>
<TextBlock Text="已被忽略" Foreground="White" VerticalAlignment="Center" Margin="5,0,0,0"/>
</StackPanel>
</Border>

<base:View Condition="=false" Value="{Binding IsRegexIgnore}">
<Border Background="#f51837" Padding="10,5" CornerRadius="4" Margin="0,0,0,5" VerticalAlignment="Center" HorizontalAlignment="Left" Visibility="{Binding CancelBlockBtnVisibility}" ToolTip="该应用将不再统计使用时长">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<base:Icon IconType="StatusCircleBlock" FontSize="12" VerticalAlignment="Center" Foreground="White"/>
<TextBlock Text="已被忽略" Foreground="White" VerticalAlignment="Center" Margin="5,0,0,0"/>
</StackPanel>
</Border>
</base:View>
<base:View Value="{Binding IsRegexIgnore}">
<Border Background="#f51837" Padding="10,5" CornerRadius="4" Margin="0,0,0,5" VerticalAlignment="Center" HorizontalAlignment="Left" ToolTip="该应用将不再统计使用时长">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<base:Icon IconType="StatusCircleBlock" FontSize="12" VerticalAlignment="Center" Foreground="White"/>
<TextBlock Text="已被正则忽略匹配" Foreground="White" VerticalAlignment="Center" Margin="5,0,0,0"/>
</StackPanel>
</Border>
</base:View>
<TextBlock ToolTip="应用描述" Grid.Column="1" Text="{Binding App.Description}" FontSize="18" VerticalAlignment="Center" TextWrapping="WrapWithOverflow"/>

<TextBlock ToolTip="应用进程名称" Text="{Binding App.Name}" FontSize="12" Foreground="Gray" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,5,0,0"/>
Expand All @@ -85,12 +94,13 @@

</StackPanel>
<Grid Grid.Column="2">
<StackPanel Grid.Column="2" HorizontalAlignment="Right" Margin="0,0,20,0">
<base:View Grid.Column="2" Condition="=false" Value="{Binding IsRegexIgnore}">
<StackPanel HorizontalAlignment="Right" Margin="0,0,20,0">
<btn:Button Command="{Binding BlockActionCommand}" CommandParameter="block" Width="120" Visibility="{Binding BlockBtnVisibility}" Icon="StatusCircleBlock">忽略此应用</btn:Button>
<btn:Button Command="{Binding BlockActionCommand}" CommandParameter="unblock" Width="120" Visibility="{Binding CancelBlockBtnVisibility}" Icon="Remove">取消忽略</btn:Button>

</StackPanel>

</base:View>
<ItemsControl Margin="0,20,10,0" VerticalAlignment="Bottom" ItemsSource="{Binding LinkApps}" HorizontalAlignment="Right">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
Expand Down

0 comments on commit 1c1aa37

Please sign in to comment.