diff --git a/GBM/Classes/clsGame.vb b/GBM/Classes/clsGame.vb index a01573b..a7ad9b9 100644 --- a/GBM/Classes/clsGame.vb +++ b/GBM/Classes/clsGame.vb @@ -258,6 +258,26 @@ End Set End Property + ReadOnly Property IncludeArray As String() + Get + If FileType = String.Empty Then + Return New String() {} + Else + Return FileType.Split(":") + End If + End Get + End Property + + ReadOnly Property ExcludeArray As String() + Get + If ExcludeList = String.Empty Then + Return New String() {} + Else + Return ExcludeList.Split(":") + End If + End Get + End Property + Public Function SyncEquals(obj As Object, eSyncFields As eOptionalSyncFields) As Boolean Dim oGame As clsGame = TryCast(obj, clsGame) If oGame Is Nothing Then diff --git a/GBM/Managers/mgrBackup.vb b/GBM/Managers/mgrBackup.vb index 486b92a..4119bea 100644 --- a/GBM/Managers/mgrBackup.vb +++ b/GBM/Managers/mgrBackup.vb @@ -88,7 +88,7 @@ Public Class mgrBackup Public Function CheckBackupPrereq(ByVal oGame As clsGame) As Boolean Dim sBackupFile As String = oSettings.BackupFolder Dim lAvailableSpace As Long = mgrCommon.GetAvailableDiskSpace(sBackupFile) - Dim lFolderSize As Long = mgrCommon.GetFolderSize(oGame.Path) + Dim lFolderSize As Long = mgrCommon.GetFolderSize(oGame.Path, oGame.IncludeArray, oGame.ExcludeArray) If oSettings.CreateSubFolder Then sBackupFile = sBackupFile & Path.DirectorySeparatorChar & oGame.Name sBackupFile = sBackupFile & Path.DirectorySeparatorChar & oGame.Name & ".7z" diff --git a/GBM/Managers/mgrCommon.vb b/GBM/Managers/mgrCommon.vb index b7b65e2..49d2025 100644 --- a/GBM/Managers/mgrCommon.vb +++ b/GBM/Managers/mgrCommon.vb @@ -2,6 +2,7 @@ Imports System.Net Imports System.IO Imports System.Security.Principal +Imports System.Text.RegularExpressions Public Class mgrCommon @@ -235,23 +236,62 @@ Public Class mgrCommon Return dFileSize End Function + Public Shared Function WildcardToRegex(ByVal sPattern As String) As String + Dim sRegEx As String + sRegEx = sPattern.Replace("*", ".*") + sRegEx = sRegEx.Replace("?", ".") + Return sRegEx + End Function + + Public Shared Function CompareValueToArrayRegEx(ByVal sValue As String, ByVal sValues As String()) As Boolean + For Each se As String In sValues + If Regex.IsMatch(sValue, WildcardToRegex(se)) Then + Return True + End If + Next + Return False + End Function + 'Calculate the current size of a folder - Public Shared Function GetFolderSize(ByVal sPath As String) + Public Shared Function GetFolderSize(ByVal sPath As String, ByVal sInclude As String(), ByVal sExclude As String()) Dim oFolder As DirectoryInfo + Dim bInclude As Boolean + Dim bExclude As Boolean Dim lSize As Long = 0 Try oFolder = New DirectoryInfo(sPath) 'Files - For Each fi As FileInfo In oFolder.GetFiles - lSize += fi.Length + For Each fi As FileInfo In oFolder.EnumerateFiles() + If sInclude.Length > 0 Then + bInclude = CompareValueToArrayRegEx(fi.Name, sInclude) Or CompareValueToArrayRegEx(Path.GetDirectoryName(sPath), sInclude) + Else + bInclude = True + End If + + If sExclude.Length > 0 Then + bExclude = CompareValueToArrayRegEx(fi.Name, sExclude) Or CompareValueToArrayRegEx(Path.GetDirectoryName(sPath), sExclude) + Else + bExclude = False + End If + + If bInclude And Not bExclude Then + lSize += fi.Length + End If Next 'Sub Folders - For Each di As DirectoryInfo In oFolder.GetDirectories + For Each di As DirectoryInfo In oFolder.EnumerateDirectories() If Not ((di.Attributes And FileAttributes.ReparsePoint) = FileAttributes.ReparsePoint) Then - lSize += GetFolderSize(di.FullName) + If sExclude.Length > 0 Then + bExclude = CompareValueToArrayRegEx(di.Name, sExclude) + Else + bExclude = False + End If + If Not bExclude Then + lSize += GetFolderSize(di.FullName, sInclude, sExclude) + End If End If Next Catch