Fix for issue #78 & #84

This commit is contained in:
MikeMaximus
2017-06-26 10:23:57 -06:00
parent 41d11cca8e
commit d4210053ad
3 changed files with 66 additions and 6 deletions
+20
View File
@@ -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
+1 -1
View File
@@ -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"
+45 -5
View File
@@ -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