Store compiled regular expressions for #170

This commit is contained in:
Michael J. Seiferling
2018-11-12 11:59:07 -06:00
parent 54b624a1cb
commit 7dc61e76ab
3 changed files with 19 additions and 5 deletions
+13 -1
View File
@@ -1,4 +1,6 @@
<Serializable()> Imports System.Text.RegularExpressions
<Serializable()>
Public Class clsGame Public Class clsGame
Private sGameID As String = Guid.NewGuid.ToString Private sGameID As String = Guid.NewGuid.ToString
Private sGameName As String = String.Empty Private sGameName As String = String.Empty
@@ -24,6 +26,7 @@ Public Class clsGame
Private bRecurseSubFolders As Boolean = True Private bRecurseSubFolders As Boolean = True
Private oImportTags As New List(Of Tag) Private oImportTags As New List(Of Tag)
Private bImportUpdate As Boolean = False Private bImportUpdate As Boolean = False
Private oCompiledRegEx As Regex
<Flags()> Public Enum eOptionalSyncFields <Flags()> Public Enum eOptionalSyncFields
None = 0 None = 0
@@ -278,6 +281,15 @@ Public Class clsGame
End Set End Set
End Property End Property
Property CompiledRegEx As Regex
Get
Return oCompiledRegEx
End Get
Set(value As Regex)
oCompiledRegEx = value
End Set
End Property
ReadOnly Property IncludeArray As String() ReadOnly Property IncludeArray As String()
Get Get
If FileType = String.Empty Then If FileType = String.Empty Then
+5
View File
@@ -38,6 +38,11 @@ Public Class mgrMonitorList
oGame.IsRegEx = CBool(dr("IsRegEx")) oGame.IsRegEx = CBool(dr("IsRegEx"))
oGame.RecurseSubFolders = CBool(dr("RecurseSubFolders")) oGame.RecurseSubFolders = CBool(dr("RecurseSubFolders"))
'Compile RegEx
If oGame.IsRegEx Then
oGame.CompiledRegEx = New Regex(oGame.ProcessName, RegexOptions.Compiled)
End If
Return oGame Return oGame
End Function End Function
+1 -4
View File
@@ -1,6 +1,5 @@
Imports System.IO Imports System.IO
Imports System.Management Imports System.Management
Imports System.Text.RegularExpressions
Public Class mgrProcessDetection Public Class mgrProcessDetection
@@ -12,7 +11,6 @@ Public Class mgrProcessDetection
Private oDuplicateGames As New ArrayList Private oDuplicateGames As New ArrayList
Private bDuplicates As Boolean Private bDuplicates As Boolean
Private bVerified As Boolean = False Private bVerified As Boolean = False
Private oRegEx As Regex
Property FoundProcess As Process Property FoundProcess As Process
Get Get
@@ -144,8 +142,7 @@ Public Class mgrProcessDetection
Private Function IsMatch(ByRef oGame As clsGame, ByRef sProcessCheck As String) As Boolean Private Function IsMatch(ByRef oGame As clsGame, ByRef sProcessCheck As String) As Boolean
If oGame.IsRegEx Then If oGame.IsRegEx Then
Try Try
oRegEx = New Regex(oGame.ProcessName) If oGame.CompiledRegEx.IsMatch(sProcessCheck) Then
If oRegEx.IsMatch(sProcessCheck) Then
Return True Return True
End If End If
Catch Catch