From ac71352c24a19c01648cc725f24087d836f8da95 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 18 Dec 2020 14:28:49 +0100 Subject: [PATCH] ClipboardWatcher: Catchall profiles --- GUIs.ClipboardWatcher/ProfileFilter.vb | 50 +++++++++++++++++++++++--- GUIs.ClipboardWatcher/ProfileMatch.vb | 11 ++++-- Modules.ZooFlow/Params/ProfileData.vb | 2 ++ 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/GUIs.ClipboardWatcher/ProfileFilter.vb b/GUIs.ClipboardWatcher/ProfileFilter.vb index 10769e3e..5a7ea143 100644 --- a/GUIs.ClipboardWatcher/ProfileFilter.vb +++ b/GUIs.ClipboardWatcher/ProfileFilter.vb @@ -124,15 +124,17 @@ Public Class ProfileFilter End If Dim oIsMatch = oProcess.ProcessName.ToLower = ProcessName.ToLower + Dim oIsCatchAll As Boolean = False ' Catch-all processname If oProcess.ProcessName.ToLower = PROCESS_NAME_CATCHALL.ToLower Then oIsMatch = True + oIsCatchAll = True End If Dim oParent = _ProfileMatch.FindNodeByTag(_TreeView.Nodes, oProfile.Name & "-REGEX") If oParent IsNot Nothing Then - Dim oNode = _ProfileMatch.NewProcessNode(oProfile, oProcess, oIsMatch) + Dim oNode = _ProfileMatch.NewProcessNode(oProfile, oProcess, oIsMatch, oIsCatchAll) oParent.Nodes.Add(oNode) End If @@ -143,8 +145,12 @@ Public Class ProfileFilter oFilteredProfiles.Add(oProfile) _Logger.Info("FilterProfilesByProcess: Profile {0} matched!", oProfile.Name) + ' Set Process matched oProcess.IsMatched = True oProcesses.Add(oProcess) + + ' Set Profile matched + oProfile.IsCatchAll = True oProfile.IsMatched = True oProfile.MatchedProcessID = oProcess.Guid @@ -231,13 +237,23 @@ Public Class ProfileFilter _Logger.Info("FilterWindowsByWindowTitleRegex: Profile {0} matched!", oProfile.Name) End If + + If oProfile.IsCatchAll Then + oProfile.IsMatched = True + oProfiles.Add(oProfile) + + _Logger.Info("FilterWindowsByWindowTitleRegex: Profile {0} is marked catchall!", oProfile.Name) + End If Next + ' Add catch-all profiles to the list + oProfiles = AddCatchAllProfiles(Profiles, oProfiles) + Return oProfiles End Function Public Function FilterProfilesByFocusedControl(Profiles As List(Of ProfileData), ClipboardContents As String, WindowHandle As IntPtr) As List(Of ProfileData) - Dim oFilteredProfiles As New List(Of ProfileData) + Dim oProfiles As New List(Of ProfileData) Dim oWindow As New Window(_LogConfig) Dim oFocusedWindow As Window.WindowInfo @@ -264,7 +280,7 @@ Public Class ProfileFilter ' If Profile has no controls at all, it automatically matches If oFilteredControls.Count = 0 Then _Logger.Debug("Profile has no Controls assigned, automatic MATCH") - oFilteredProfiles.Add(oProfile) + oProfiles.Add(oProfile) Continue For End If @@ -335,13 +351,16 @@ Public Class ProfileFilter If oMatchingControls.Count > 0 Then _Logger.Debug("Profile has {0} MATCHING Controls", oMatchingControls.Count) oProfile.Controls = oMatchingControls - oFilteredProfiles.Add(oProfile) + oProfiles.Add(oProfile) _Logger.Info("FilterProfilesByFocusedControl: Profile {0} matched!", oProfile.Name) End If Next - Return oFilteredProfiles + ' Add catch-all profiles to the list + oProfiles = AddCatchAllProfiles(Profiles, oProfiles) + + Return oProfiles End Function Public Function FilterProfilesBySearchResults(Profiles As List(Of ProfileData), Database As MSSQLServer, User As UserState, ClipboardContents As String) As List(Of ProfileData) @@ -444,6 +463,9 @@ Public Class ProfileFilter End If Next + ' Add catch-all profiles to the list + oProfiles = AddCatchAllProfiles(Profiles, oProfiles) + Return oProfiles End Function @@ -490,6 +512,9 @@ Public Class ProfileFilter End If Next + ' Add catch-all profiles to the list + oProfiles = AddCatchAllProfiles(Profiles, oProfiles) + Return oProfiles End Function @@ -510,6 +535,21 @@ Public Class ProfileFilter ToList() End Function + Private Function AddCatchAllProfiles(AllProfiles As List(Of ProfileData), FilteredProfiles As List(Of ProfileData)) As List(Of ProfileData) + Dim oCatchAllProfiles As New List(Of ProfileData) + + For Each oProfile As ProfileData In AllProfiles + If oProfile.IsCatchAll And FilteredProfiles.Contains(oProfile) = False Then + oProfile.IsMatched = True + oCatchAllProfiles.Add(oProfile) + End If + Next + + Return FilteredProfiles. + Concat(oCatchAllProfiles). + ToList() + End Function + Private Function TransformProfiles() As List(Of ProfileData) Try Dim oList As New List(Of ProfileData) diff --git a/GUIs.ClipboardWatcher/ProfileMatch.vb b/GUIs.ClipboardWatcher/ProfileMatch.vb index b1886e5b..3a290b80 100644 --- a/GUIs.ClipboardWatcher/ProfileMatch.vb +++ b/GUIs.ClipboardWatcher/ProfileMatch.vb @@ -49,11 +49,16 @@ Public Class ProfileMatch Return oNode End Function - Public Function NewProcessNode(Profile As ProfileData, Process As ProcessData, IsMatch As Boolean) As TreeNode + Public Function NewProcessNode(Profile As ProfileData, Process As ProcessData, IsMatch As Boolean, IsCatchAll As Boolean) As TreeNode _Logger.Debug("New Process Node for Profile {0} and ProcessName {1}", Profile.Name, Process.ProcessName) - Dim oMatchText = IIf(IsMatch, "MATCH", "NO MATCH") - Dim oText = $"{GetMatchText(IsMatch)} on ProcessName {Process.ProcessName}" + Dim oText As String + If IsCatchAll Then + oText = $"{GetMatchText(IsMatch)} on Catch-All Process" + Else + oText = $"{GetMatchText(IsMatch)} on ProcessName {Process.ProcessName}" + End If + Dim oNode As New TreeNode() With { .Text = oText, .ImageIndex = ProfileFilter.ImageIndex.Process, diff --git a/Modules.ZooFlow/Params/ProfileData.vb b/Modules.ZooFlow/Params/ProfileData.vb index 1af3e68f..574a04e9 100644 --- a/Modules.ZooFlow/Params/ProfileData.vb +++ b/Modules.ZooFlow/Params/ProfileData.vb @@ -14,6 +14,8 @@ Public CountData As Integer = 0 Public IsMatched As Boolean = False + Public IsCatchAll As Boolean = False + Public MatchedProcessID As Integer = 0 Public MatchedWindowID As Integer = 0 Public MatchedControlID As Integer = 0