From 1ab0e77918cbe1359e368efcf0f5b47ed6bfa893 Mon Sep 17 00:00:00 2001 From: "Michael J. Seiferling" Date: Tue, 13 Feb 2018 20:22:03 -0600 Subject: [PATCH] Fixed detecting duplicate games with regex for issue #98 --- GBM/Managers/mgrCommon.vb | 19 ++++++++++++++++++- GBM/Managers/mgrMonitorList.vb | 14 +++++++++----- GBM/Managers/mgrProcesses.vb | 22 ++-------------------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/GBM/Managers/mgrCommon.vb b/GBM/Managers/mgrCommon.vb index 61be07d..4bb6f1b 100644 --- a/GBM/Managers/mgrCommon.vb +++ b/GBM/Managers/mgrCommon.vb @@ -258,6 +258,24 @@ Public Class mgrCommon Return dFileSize 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 Dim sRegEx As String sRegEx = sPattern.Replace("*", ".*") @@ -488,7 +506,6 @@ Public Class mgrCommon Return sString End Function - 'Handles single parameter stings Public Shared Function FormatString(ByVal sString As String, ByVal sParam As String) As String sString = sString.Replace("[BR]", vbCrLf) diff --git a/GBM/Managers/mgrMonitorList.vb b/GBM/Managers/mgrMonitorList.vb index 83da602..f127394 100644 --- a/GBM/Managers/mgrMonitorList.vb +++ b/GBM/Managers/mgrMonitorList.vb @@ -74,6 +74,7 @@ Public Class mgrMonitorList Dim hshList As New Hashtable Dim hshDupeList As New Hashtable Dim oGame As clsGame + Dim oCompareGame As clsGame sSQL = "Select * from monitorlist ORDER BY Name Asc" 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 hshList.Add(oGame.ProcessName & ":" & oGame.Name, oGame) Case eListTypes.ScanList - If hshList.Contains(oGame.ProcessName) Then - DirectCast(hshList.Item(oGame.ProcessName), clsGame).Duplicate = True - oGame.ProcessName = oGame.ProcessName & ":" & oGame.Name - oGame.Duplicate = True - End If + For Each de As DictionaryEntry In hshList + 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.Duplicate = True + End If + Next If oGame.Enabled Then hshList.Add(oGame.ProcessName, oGame) End Select Next diff --git a/GBM/Managers/mgrProcesses.vb b/GBM/Managers/mgrProcesses.vb index 8383e4c..cba3c9e 100644 --- a/GBM/Managers/mgrProcesses.vb +++ b/GBM/Managers/mgrProcesses.vb @@ -90,7 +90,7 @@ Public Class mgrProcesses For Each o As clsGame In hshScanList.Values 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 oGame = o.ShallowCopy Return True @@ -163,24 +163,6 @@ Public Class mgrProcesses End Try 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 Dim prsList() As Process = Process.GetProcesses Dim sProcessCheck As String = String.Empty @@ -218,7 +200,7 @@ Public Class mgrProcesses 'Detection Pass 1 For Each oCurrentGame As clsGame In hshScanList.Values - If IsMatch(oCurrentGame, sProcessCheck) Then + If mgrCommon.IsMatch(oCurrentGame, sProcessCheck) Then prsFoundProcess = prsCurrent oGame = oCurrentGame.ShallowCopy bPass = True