Fixed detecting duplicate games with regex for issue #98

This commit is contained in:
Michael J. Seiferling
2018-02-13 20:22:03 -06:00
parent b3d9510edd
commit 1ab0e77918
3 changed files with 29 additions and 26 deletions
+18 -1
View File
@@ -258,6 +258,24 @@ Public Class mgrCommon
Return dFileSize Return dFileSize
End Function End Function
Public Shared Function IsMatch(ByRef oGame As clsGame, ByRef sProcessCheck As String) As Boolean
If oGame.IsRegEx Then
Try
If Regex.IsMatch(sProcessCheck, oGame.ProcessName) Then
Return True
End If
Catch
'Ignore malformed regular expressions that may have passed validation
End Try
Else
If oGame.ProcessName = sProcessCheck Then
Return True
End If
End If
Return False
End Function
Public Shared Function WildcardToRegex(ByVal sPattern As String) As String Public Shared Function WildcardToRegex(ByVal sPattern As String) As String
Dim sRegEx As String Dim sRegEx As String
sRegEx = sPattern.Replace("*", ".*") sRegEx = sPattern.Replace("*", ".*")
@@ -488,7 +506,6 @@ Public Class mgrCommon
Return sString Return sString
End Function End Function
'Handles single parameter stings 'Handles single parameter stings
Public Shared Function FormatString(ByVal sString As String, ByVal sParam As String) As String Public Shared Function FormatString(ByVal sString As String, ByVal sParam As String) As String
sString = sString.Replace("[BR]", vbCrLf) sString = sString.Replace("[BR]", vbCrLf)
+6 -2
View File
@@ -74,6 +74,7 @@ Public Class mgrMonitorList
Dim hshList As New Hashtable Dim hshList As New Hashtable
Dim hshDupeList As New Hashtable Dim hshDupeList As New Hashtable
Dim oGame As clsGame Dim oGame As clsGame
Dim oCompareGame As clsGame
sSQL = "Select * from monitorlist ORDER BY Name Asc" sSQL = "Select * from monitorlist ORDER BY Name Asc"
oData = oDatabase.ReadParamData(sSQL, New Hashtable) oData = oDatabase.ReadParamData(sSQL, New Hashtable)
@@ -85,11 +86,14 @@ Public Class mgrMonitorList
'Don't wrap this, if it fails there's a problem with the database 'Don't wrap this, if it fails there's a problem with the database
hshList.Add(oGame.ProcessName & ":" & oGame.Name, oGame) hshList.Add(oGame.ProcessName & ":" & oGame.Name, oGame)
Case eListTypes.ScanList Case eListTypes.ScanList
If hshList.Contains(oGame.ProcessName) Then For Each de As DictionaryEntry In hshList
DirectCast(hshList.Item(oGame.ProcessName), clsGame).Duplicate = True oCompareGame = DirectCast(de.Value, clsGame)
If mgrCommon.IsMatch(oCompareGame, oGame.ProcessName) Then
DirectCast(hshList.Item(oCompareGame.ProcessName), clsGame).Duplicate = True
oGame.ProcessName = oGame.ProcessName & ":" & oGame.Name oGame.ProcessName = oGame.ProcessName & ":" & oGame.Name
oGame.Duplicate = True oGame.Duplicate = True
End If End If
Next
If oGame.Enabled Then hshList.Add(oGame.ProcessName, oGame) If oGame.Enabled Then hshList.Add(oGame.ProcessName, oGame)
End Select End Select
Next Next
+2 -20
View File
@@ -90,7 +90,7 @@ Public Class mgrProcesses
For Each o As clsGame In hshScanList.Values For Each o As clsGame In hshScanList.Values
sProcess = o.ProcessName.Split(":")(0) sProcess = o.ProcessName.Split(":")(0)
If o.Duplicate = True And sProcess = oGame.TrueProcess Then If o.Duplicate = True And (sProcess = oGame.TrueProcess Or Regex.IsMatch(sProcess, oGame.TrueProcess)) Then
If o.Parameter <> String.Empty And FullCommand.Contains(o.Parameter) Then If o.Parameter <> String.Empty And FullCommand.Contains(o.Parameter) Then
oGame = o.ShallowCopy oGame = o.ShallowCopy
Return True Return True
@@ -163,24 +163,6 @@ Public Class mgrProcesses
End Try End Try
End Function End Function
Private Function IsMatch(ByRef oGame As clsGame, ByRef sProcessCheck As String) As Boolean
If oGame.IsRegEx Then
Try
If Regex.IsMatch(sProcessCheck, oGame.ProcessName) Then
Return True
End If
Catch
'Ignore malformed regular expressions that may have passed validation
End Try
Else
If oGame.ProcessName = sProcessCheck Then
Return True
End If
End If
Return False
End Function
Public Function SearchRunningProcesses(ByVal hshScanList As Hashtable, ByRef bNeedsPath As Boolean, ByRef iErrorCode As Integer, ByVal bDebugMode As Boolean) As Boolean Public Function SearchRunningProcesses(ByVal hshScanList As Hashtable, ByRef bNeedsPath As Boolean, ByRef iErrorCode As Integer, ByVal bDebugMode As Boolean) As Boolean
Dim prsList() As Process = Process.GetProcesses Dim prsList() As Process = Process.GetProcesses
Dim sProcessCheck As String = String.Empty Dim sProcessCheck As String = String.Empty
@@ -218,7 +200,7 @@ Public Class mgrProcesses
'Detection Pass 1 'Detection Pass 1
For Each oCurrentGame As clsGame In hshScanList.Values For Each oCurrentGame As clsGame In hshScanList.Values
If IsMatch(oCurrentGame, sProcessCheck) Then If mgrCommon.IsMatch(oCurrentGame, sProcessCheck) Then
prsFoundProcess = prsCurrent prsFoundProcess = prsCurrent
oGame = oCurrentGame.ShallowCopy oGame = oCurrentGame.ShallowCopy
bPass = True bPass = True