ClipboardWatcher: Catchall profiles

This commit is contained in:
Jonathan Jenne 2020-12-18 14:28:49 +01:00
parent 8907f64bf9
commit ac71352c24
3 changed files with 55 additions and 8 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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