提交记录修改Core/Models/Config/BehaviorModel.cs+1 −1看文件
修改Core/Servicers/Instances/Main.cs+74 −24看文件
| @@ -11,7 +11,7 @@ namespace Core.Models.Config | ||
| 11 | 11 | /// </summary> |
| 12 | 12 | public class BehaviorModel |
| 13 | 13 | { |
| 14 | 删除: [Config(IsCanImportExport = true, Name = "忽略进程", Description = "忽略的进程将不进行时长统计", Group = "忽略进程", Placeholder = "进程名,不需要输入.exe")] | |
| 14 | 新增: [Config(IsCanImportExport = true, Name = "忽略应用", Description = "忽略的应用将不进行时长统计", Group = "忽略应用", Placeholder = "应用进程名称,不需要输入.exe。支持正则表达式")] | |
| 15 | 15 | /// <summary> |
| 16 | 16 | /// 忽略的进程列表 |
| 17 | 17 | /// </summary> |
| @@ -11,6 +11,7 @@ using System.Data.Entity; | ||
| 11 | 11 | using System.Diagnostics; |
| 12 | 12 | using System.Linq; |
| 13 | 13 | using System.Text; |
| 14 | 新增:using System.Text.RegularExpressions; | |
| 14 | 15 | using System.Threading.Tasks; |
| 15 | 16 | using System.Timers; |
| 16 | 17 | using System.Windows.Threading; |
| @@ -27,7 +28,7 @@ namespace Core.Servicers.Instances | ||
| 27 | 28 | private readonly IAppData appData; |
| 28 | 29 | private readonly ICategorys categories; |
| 29 | 30 | // 忽略的进程 |
| 30 | 删除: private readonly string[] IgnoreProcess = new string[] { | |
| 31 | 新增: private readonly string[] DefaultIgnoreProcess = new string[] { | |
| 31 | 32 | "Tai", |
| 32 | 33 | "SearchHost", |
| 33 | 34 | "Taskmgr", |
| @@ -61,6 +62,19 @@ namespace Core.Servicers.Instances | ||
| 61 | 62 | |
| 62 | 63 | public event EventHandler OnUpdateTime; |
| 63 | 64 | |
| 65 | 新增: /// <summary> | |
| 66 | 新增: /// 忽略进程缓存列表 | |
| 67 | 新增: /// </summary> | |
| 68 | 新增: private List<string> IgnoreProcessCacheList; | |
| 69 | 新增: | |
| 70 | 新增: /// <summary> | |
| 71 | 新增: /// 配置正则忽略进程列表 | |
| 72 | 新增: /// </summary> | |
| 73 | 新增: private List<string> ConfigIgnoreProcessRegxList; | |
| 74 | 新增: /// <summary> | |
| 75 | 新增: /// 配置忽略进程名称列表 | |
| 76 | 新增: /// </summary> | |
| 77 | 新增: private List<string> ConfigIgnoreProcessList; | |
| 64 | 78 | public Main( |
| 65 | 79 | IObserver observer, |
| 66 | 80 | IData data, |
| @@ -77,6 +91,10 @@ namespace Core.Servicers.Instances | ||
| 77 | 91 | this.appData = appData; |
| 78 | 92 | this.categories = categories; |
| 79 | 93 | |
| 94 | 新增: IgnoreProcessCacheList = new List<string>(); | |
| 95 | 新增: ConfigIgnoreProcessRegxList = new List<string>(); | |
| 96 | 新增: ConfigIgnoreProcessList = new List<string>(); | |
| 97 | 新增: | |
| 80 | 98 | observer.OnAppActive += Observer_OnAppActive; |
| 81 | 99 | sleepdiscover.SleepStatusChanged += Sleepdiscover_SleepStatusChanged; |
| 82 | 100 | appConfig.ConfigChanged += AppConfig_ConfigChanged; |
| @@ -97,6 +115,9 @@ namespace Core.Servicers.Instances | ||
| 97 | 115 | { |
| 98 | 116 | // 处理开机自启 |
| 99 | 117 | Shortcut.SetStartup(newConfig.General.IsStartatboot); |
| 118 | 新增: | |
| 119 | 新增: // 更新忽略规则 | |
| 120 | 新增: UpdateConfigIgnoreProcess(); | |
| 100 | 121 | } |
| 101 | 122 | } |
| 102 | 123 | |
| @@ -126,6 +147,7 @@ namespace Core.Servicers.Instances | ||
| 126 | 147 | // 加载应用配置(确保配置文件最先加载 |
| 127 | 148 | appConfig.Load(); |
| 128 | 149 | config = appConfig.GetConfig(); |
| 150 | 新增: UpdateConfigIgnoreProcess(); | |
| 129 | 151 | |
| 130 | 152 | // 日期变化观察 |
| 131 | 153 | dateTimeObserver.Start(); |
| @@ -146,6 +168,21 @@ namespace Core.Servicers.Instances | ||
| 146 | 168 | } |
| 147 | 169 | |
| 148 | 170 | |
| 171 | 新增: private void UpdateConfigIgnoreProcess() | |
| 172 | 新增: { | |
| 173 | 新增: ConfigIgnoreProcessList.Clear(); | |
| 174 | 新增: ConfigIgnoreProcessRegxList.Clear(); | |
| 175 | 新增: IgnoreProcessCacheList.Clear(); | |
| 176 | 新增: | |
| 177 | 新增: ConfigIgnoreProcessList = config.Behavior.IgnoreProcessList.Where(m => !IsRegex(m)).ToList(); | |
| 178 | 新增: ConfigIgnoreProcessRegxList = config.Behavior.IgnoreProcessList.Where(m => IsRegex(m)).ToList(); | |
| 179 | 新增: } | |
| 180 | 新增: | |
| 181 | 新增: private bool IsRegex(string str) | |
| 182 | 新增: { | |
| 183 | 新增: return Regex.IsMatch(str, @"[\.|\*|\?|\{|\\|\[|\^|\|]"); | |
| 184 | 新增: } | |
| 185 | 新增: | |
| 149 | 186 | private void Sleepdiscover_SleepStatusChanged(Enums.SleepStatus sleepStatus) |
| 150 | 187 | { |
| 151 | 188 | this.sleepStatus = sleepStatus; |
| @@ -173,53 +210,66 @@ namespace Core.Servicers.Instances | ||
| 173 | 210 | |
| 174 | 211 | |
| 175 | 212 | /// <summary> |
| 176 | 删除: /// 检查焦点app是否已经在库 | |
| 213 | 新增: /// 检查应用是否需要记录数据 | |
| 177 | 214 | /// </summary> |
| 178 | 215 | /// <param name="processName"></param> |
| 179 | 216 | /// <param name="description"></param> |
| 180 | 217 | /// <param name="file"></param> |
| 181 | 删除: private void CheckApp(string processName, string description, string file) | |
| 218 | 新增: private bool IsCheckApp(string processName, string description, string file) | |
| 182 | 219 | { |
| 183 | 删除: if (string.IsNullOrEmpty(file) || string.IsNullOrEmpty(processName)) | |
| 220 | 新增: if (string.IsNullOrEmpty(file) || string.IsNullOrEmpty(processName) || DefaultIgnoreProcess.Contains(processName) || IgnoreProcessCacheList.Contains(processName)) | |
| 184 | 221 | { |
| 185 | 删除: return; | |
| 222 | 新增: return false; | |
| 186 | 223 | } |
| 187 | 224 | |
| 225 | 新增: // 从名称判断 | |
| 226 | 新增: if (ConfigIgnoreProcessList.Contains(processName)) | |
| 227 | 新增: { | |
| 228 | 新增: return false; | |
| 229 | 新增: } | |
| 188 | 230 | |
| 189 | 删除: if (!config.Behavior.IgnoreProcessList.Contains(processName) | |
| 190 | 删除: && !IgnoreProcess.Contains(processName)) | |
| 231 | 新增: // 正则表达式 | |
| 232 | 新增: foreach (string reg in ConfigIgnoreProcessRegxList) | |
| 191 | 233 | { |
| 192 | 删除: AppModel app = appData.GetApp(processName); | |
| 193 | 删除: if (app == null) | |
| 234 | 新增: if (Regex.IsMatch(processName, reg)) | |
| 194 | 235 | { |
| 195 | 删除: // 提取icon | |
| 196 | 删除: string iconFile = Iconer.ExtractFromFile(file, processName, description); | |
| 236 | 新增: IgnoreProcessCacheList.Add(processName); | |
| 197 | 237 | |
| 198 | 删除: appData.AddApp(new AppModel() | |
| 199 | 删除: { | |
| 200 | 删除: Name = processName, | |
| 201 | 删除: Description = description, | |
| 202 | 删除: File = file, | |
| 203 | 删除: CategoryID = 0, | |
| 204 | 删除: IconFile = iconFile, | |
| 205 | 删除: }); | |
| 238 | 新增: return false; | |
| 206 | 239 | } |
| 207 | 240 | } |
| 241 | 新增: | |
| 242 | 新增: AppModel app = appData.GetApp(processName); | |
| 243 | 新增: if (app == null) | |
| 244 | 新增: { | |
| 245 | 新增: // 记录应用信息 | |
| 246 | 新增: | |
| 247 | 新增: // 提取icon | |
| 248 | 新增: string iconFile = Iconer.ExtractFromFile(file, processName, description); | |
| 249 | 新增: | |
| 250 | 新增: appData.AddApp(new AppModel() | |
| 251 | 新增: { | |
| 252 | 新增: Name = processName, | |
| 253 | 新增: Description = description, | |
| 254 | 新增: File = file, | |
| 255 | 新增: CategoryID = 0, | |
| 256 | 新增: IconFile = iconFile, | |
| 257 | 新增: }); | |
| 258 | 新增: } | |
| 259 | 新增: | |
| 260 | 新增: return true; | |
| 208 | 261 | } |
| 209 | 262 | |
| 210 | 263 | private void Observer_OnAppActive(string processName, string description, string file) |
| 211 | 264 | { |
| 212 | 删除: CheckApp(processName, description, file); | |
| 265 | 新增: bool isCheck = IsCheckApp(processName, description, file); | |
| 213 | 266 | |
| 214 | 267 | if (activeProcess != processName && activeProcessFile != file) |
| 215 | 268 | { |
| 216 | 269 | UpdateTime(); |
| 217 | 270 | } |
| 218 | 271 | |
| 219 | 删除: if (!config.Behavior.IgnoreProcessList.Contains(processName) | |
| 220 | 删除: && file != string.Empty | |
| 221 | 删除: && sleepStatus != SleepStatus.Sleep | |
| 222 | 删除: && !IgnoreProcess.Contains(processName)) | |
| 272 | 新增: if (isCheck && sleepStatus != SleepStatus.Sleep) | |
| 223 | 273 | { |
| 224 | 274 | activeProcess = processName; |
| 225 | 275 | activeProcessDescription = description; |

