From f204f6ccc675e0ff5b1304b050c8fdbcf0ae08ab Mon Sep 17 00:00:00 2001 From: "Michael J. Seiferling" Date: Wed, 17 Oct 2018 10:32:52 -0600 Subject: [PATCH] Some fixes for backup size calculations --- GBM/Managers/mgrBackup.vb | 16 ++++++++++++++-- GBM/Managers/mgrCommon.vb | 8 +++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/GBM/Managers/mgrBackup.vb b/GBM/Managers/mgrBackup.vb index f4eb557..6576c45 100644 --- a/GBM/Managers/mgrBackup.vb +++ b/GBM/Managers/mgrBackup.vb @@ -118,7 +118,8 @@ Public Class mgrBackup Dim sSavePath As String Dim sOverwriteMessage As String Dim lAvailableSpace As Long - Dim lFolderSize As Long + Dim lFolderSize As Long = 0 + Dim sDeepFolder As String If oSettings.CreateSubFolder Then sBackupFile = sBackupFile & Path.DirectorySeparatorChar & GetFileName(oGame) sBackupFile = sBackupFile & Path.DirectorySeparatorChar & GetFileName(oGame) & ".7z" @@ -128,7 +129,18 @@ Public Class mgrBackup 'Calculate space lAvailableSpace = mgrCommon.GetAvailableDiskSpace(oSettings.BackupFolder) - lFolderSize = mgrCommon.GetFolderSize(sSavePath, oGame.IncludeArray, oGame.ExcludeArray, oGame.RecurseSubFolders) + 'If any includes are using a deep path and we aren't using recursion, we need to go directly to folders to do file size calculations or they will be missed. + If Not oGame.RecurseSubFolders Then + For Each s As String In oGame.IncludeArray + If s.Contains(Path.DirectorySeparatorChar) Then + sDeepFolder = Path.GetDirectoryName(sSavePath & Path.DirectorySeparatorChar & s) + If Directory.Exists(sDeepFolder) Then + lFolderSize += mgrCommon.GetFolderSize(sDeepFolder, oGame.IncludeArray, oGame.ExcludeArray, oGame.RecurseSubFolders) + End If + End If + Next + End If + lFolderSize += mgrCommon.GetFolderSize(sSavePath, oGame.IncludeArray, oGame.ExcludeArray, oGame.RecurseSubFolders) 'Show Available Space RaiseEvent UpdateLog(mgrCommon.FormatString(mgrCommon_AvailableDiskSpace, mgrCommon.FormatDiskSpace(lAvailableSpace)), False, ToolTipIcon.Info, True) diff --git a/GBM/Managers/mgrCommon.vb b/GBM/Managers/mgrCommon.vb index 0bedf94..a620add 100644 --- a/GBM/Managers/mgrCommon.vb +++ b/GBM/Managers/mgrCommon.vb @@ -293,14 +293,15 @@ Public Class mgrCommon Public Shared Function WildcardToRegex(ByVal sPattern As String) As String Dim sRegEx As String - sRegEx = sPattern.Replace("*", ".*") - sRegEx = sRegEx.Replace("?", ".") + sPattern = Regex.Escape(sPattern) + 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, Regex.Escape(WildcardToRegex(se))) Then + If Regex.IsMatch(sValue, WildcardToRegex(se)) Then Return True End If Next @@ -331,6 +332,7 @@ Public Class mgrCommon 'Files For Each fi As FileInfo In oFolder.EnumerateFiles() + If sInclude.Length > 0 Then bInclude = CompareValueToArrayRegEx(fi.FullName, sInclude) Else