Enhancement for issue #78

This commit is contained in:
Michael J. Seiferling
2017-06-13 09:38:06 -06:00
parent e701d67d79
commit 9cd786c303
5 changed files with 198 additions and 45 deletions
+2 -2
View File
@@ -583,7 +583,7 @@ Public Class frmGameManager
sFileName = BackupFolder & CurrentBackupItem.FileName
If File.Exists(sFileName) Then
lblBackupFileData.Text = Path.GetFileName(CurrentBackupItem.FileName) & " (" & mgrCommon.GetFileSize(sFileName) & ")"
lblBackupFileData.Text = Path.GetFileName(CurrentBackupItem.FileName) & " (" & mgrCommon.FormatDiskSpace(mgrCommon.GetFileSize(sFileName)) & ")"
Else
lblBackupFileData.Text = frmGameManager_ErrorNoBackupExists
End If
@@ -625,7 +625,7 @@ Public Class frmGameManager
btnDeleteBackup.Enabled = True
If File.Exists(sFileName) Then
lblBackupFileData.Text = Path.GetFileName(CurrentBackupItem.FileName) & " (" & mgrCommon.GetFileSize(sFileName) & ")"
lblBackupFileData.Text = Path.GetFileName(CurrentBackupItem.FileName) & " (" & mgrCommon.FormatDiskSpace(mgrCommon.GetFileSize(sFileName)) & ")"
Else
lblBackupFileData.Text = frmGameManager_ErrorNoBackupExists
End If
+17 -1
View File
@@ -87,9 +87,25 @@ 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)
If oSettings.CreateSubFolder Then sBackupFile = sBackupFile & Path.DirectorySeparatorChar & oGame.Name
sBackupFile = sBackupFile & Path.DirectorySeparatorChar & oGame.Name & ".7z"
'Show Available Space
RaiseEvent UpdateLog(mgrCommon.FormatString(mgrCommon_AvailableDiskSpace, mgrCommon.FormatDiskSpace(lAvailableSpace)), False, ToolTipIcon.Info, True)
'Show Save Folder Size
RaiseEvent UpdateLog(mgrCommon.FormatString(mgrCommon_SavedGameFolderSize, New String() {oGame.Name, mgrCommon.FormatDiskSpace(lFolderSize)}), False, ToolTipIcon.Info, True)
If lFolderSize >= lAvailableSpace Then
If mgrCommon.ShowMessage(mgrBackup_ConfirmDiskSpace, MsgBoxStyle.YesNo) = MsgBoxResult.No Then
RaiseEvent UpdateLog(mgrBackup_ErrorDiskSpace, False, ToolTipIcon.Error, True)
Return False
End If
End If
If mgrRestore.CheckManifest(oGame.Name) Then
If mgrCommon.ShowMessage(mgrBackup_ConfirmManifestConflict, oGame.Name, MsgBoxStyle.YesNo) = MsgBoxResult.No Then
RaiseEvent UpdateLog(mgrBackup_ErrorManifestConflict, False, ToolTipIcon.Error, True)
@@ -223,7 +239,7 @@ Public Class mgrBackup
prs7z.WaitForExit()
If Not CancelOperation Then
If prs7z.ExitCode = 0 Then
RaiseEvent UpdateLog(mgrCommon.FormatString(mgrBackup_BackupComplete, New String() {oGame.Name, mgrCommon.GetFileSize(sBackupFile)}), False, ToolTipIcon.Info, True)
RaiseEvent UpdateLog(mgrCommon.FormatString(mgrBackup_BackupComplete, New String() {oGame.Name, mgrCommon.FormatDiskSpace(mgrCommon.GetFileSize(sBackupFile))}), False, ToolTipIcon.Info, True)
bBackupCompleted = True
Else
RaiseEvent UpdateLog(mgrCommon.FormatString(mgrBackup_BackupWarnings, oGame.Name), True, ToolTipIcon.Warning, True)
+71 -18
View File
@@ -165,6 +165,77 @@ Public Class mgrCommon
Return eSyncFields And (Not eSyncField)
End Function
'Get a file size
Public Shared Function GetFileSize(ByVal sFile As String) As Long
Dim oFileInfo As FileInfo
Dim dFileSize As Long = 0
Try
oFileInfo = New FileInfo(sFile)
dFileSize = oFileInfo.Length
Catch ex As Exception
'Do Nothing
End Try
Return dFileSize
End Function
'Calculate the current size of a folder
Public Shared Function GetFolderSize(ByVal sPath As String)
Dim oFolder As DirectoryInfo
Dim lSize As Long = 0
Try
oFolder = New DirectoryInfo(sPath)
'Files
For Each fi As FileInfo In oFolder.GetFiles
lSize += fi.Length
Next
'Sub Folders
For Each di As DirectoryInfo In oFolder.GetDirectories
lSize += GetFolderSize(di.FullName)
Next
Catch
'Do Nothing
End Try
Return lSize
End Function
'Format Disk Space Amounts
Public Shared Function FormatDiskSpace(ByVal lSize As Long)
Select Case lSize
Case >= 1125899906842624
Return FormatString(mgrCommon_PB, Math.Round(lSize / 1125899906842624, 2))
Case >= 1099511627776
Return FormatString(mgrCommon_TB, Math.Round(lSize / 1099511627776, 2))
Case >= 1073741824
Return FormatString(mgrCommon_GB, Math.Round(lSize / 1073741824, 2))
Case >= 1048576
Return FormatString(mgrCommon_MB, Math.Round(lSize / 1048576, 2))
Case >= 1024
Return FormatString(mgrCommon_KB, Math.Round(lSize / 1024, 2))
End Select
Return lSize
End Function
'Get available disk space on a drive
Public Shared Function GetAvailableDiskSpace(ByVal sPath As String) As Long
Dim oDrive As DriveInfo
Dim lAvailableSpace As Long = 0
Try
oDrive = New DriveInfo(Path.GetPathRoot(sPath))
lAvailableSpace = oDrive.AvailableFreeSpace
Catch
'Do Nothing
End Try
Return lAvailableSpace
End Function
'Delete file based on OS type
Public Shared Sub DeleteFile(ByVal sPath As String, Optional ByVal bRecycle As Boolean = True)
If File.Exists(sPath) Then
@@ -224,24 +295,6 @@ Public Class mgrCommon
End Try
End Sub
'Get a file size
Public Shared Function GetFileSize(ByVal sFile As String) As String
Dim oFileInfo As FileInfo
Dim dFileSize As Double
Try
oFileInfo = New FileInfo(sFile)
dFileSize = oFileInfo.Length
If dFileSize > 1048576 Then
Return FormatString(App_MB, Math.Round(dFileSize / 1048576, 2).ToString)
Else
Return FormatString(App_KB, Math.Round(dFileSize / 1024, 2).ToString)
End If
Catch ex As Exception
Return String.Empty
End Try
End Function
'Handles no extra parameters
Public Shared Function ShowMessage(ByVal sMsg As String, ByVal oType As MsgBoxStyle) As MsgBoxResult
Dim oResult As MsgBoxResult
+81 -18
View File
@@ -96,24 +96,6 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] KB.
'''</summary>
Friend ReadOnly Property App_KB() As String
Get
Return ResourceManager.GetString("App_KB", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] MB.
'''</summary>
Friend ReadOnly Property App_MB() As String
Get
Return ResourceManager.GetString("App_MB", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Game Backup Monitor.
'''</summary>
@@ -4510,6 +4492,15 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to You may not have enough disk space available to perform a backup.[BR][BR]Do you want to continue anyway?.
'''</summary>
Friend ReadOnly Property mgrBackup_ConfirmDiskSpace() As String
Get
Return ResourceManager.GetString("mgrBackup_ConfirmDiskSpace", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to The manifest shows the backup folder contains a backup for [PARAM] that has not been restored on this computer.[BR][BR]Do you want to overwrite this file anyway?.
'''</summary>
@@ -4528,6 +4519,15 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Backup aborted due to lack of disk space..
'''</summary>
Friend ReadOnly Property mgrBackup_ErrorDiskSpace() As String
Get
Return ResourceManager.GetString("mgrBackup_ErrorDiskSpace", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to An error occured creating a file list: [PARAM].
'''</summary>
@@ -4609,6 +4609,15 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Available Disk Space: [PARAM].
'''</summary>
Friend ReadOnly Property mgrCommon_AvailableDiskSpace() As String
Get
Return ResourceManager.GetString("mgrCommon_AvailableDiskSpace", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to An error has occured writing the text file.[BR][BR][PARAM].
'''</summary>
@@ -4627,6 +4636,33 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] GB.
'''</summary>
Friend ReadOnly Property mgrCommon_GB() As String
Get
Return ResourceManager.GetString("mgrCommon_GB", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] KB.
'''</summary>
Friend ReadOnly Property mgrCommon_KB() As String
Get
Return ResourceManager.GetString("mgrCommon_KB", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] MB.
'''</summary>
Friend ReadOnly Property mgrCommon_MB() As String
Get
Return ResourceManager.GetString("mgrCommon_MB", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to No.
'''</summary>
@@ -4636,6 +4672,33 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] PB.
'''</summary>
Friend ReadOnly Property mgrCommon_PB() As String
Get
Return ResourceManager.GetString("mgrCommon_PB", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] Save Folder Size: [PARAM].
'''</summary>
Friend ReadOnly Property mgrCommon_SavedGameFolderSize() As String
Get
Return ResourceManager.GetString("mgrCommon_SavedGameFolderSize", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] TB.
'''</summary>
Friend ReadOnly Property mgrCommon_TB() As String
Get
Return ResourceManager.GetString("mgrCommon_TB", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Yes.
'''</summary>
+27 -6
View File
@@ -424,12 +424,6 @@
<data name="App_ConfirmDirty" xml:space="preserve">
<value>There are unsaved changes on this form. Do you want to save?</value>
</data>
<data name="App_KB" xml:space="preserve">
<value>[PARAM] KB</value>
</data>
<data name="App_MB" xml:space="preserve">
<value>[PARAM] MB</value>
</data>
<data name="frmGameManager_BackupTimeAndName" xml:space="preserve">
<value>[PARAM] ([PARAM])</value>
</data>
@@ -1762,4 +1756,31 @@
<data name="frmMain_NoCheckSum" xml:space="preserve">
<value>The backup file for [PARAM] has no checksum, it cannot be automatically restored.</value>
</data>
<data name="mgrBackup_ConfirmDiskSpace" xml:space="preserve">
<value>You may not have enough disk space available to perform a backup.[BR][BR]Do you want to continue anyway?</value>
</data>
<data name="mgrBackup_ErrorDiskSpace" xml:space="preserve">
<value>Backup aborted due to lack of disk space.</value>
</data>
<data name="mgrCommon_AvailableDiskSpace" xml:space="preserve">
<value>Available Disk Space: [PARAM]</value>
</data>
<data name="mgrCommon_GB" xml:space="preserve">
<value>[PARAM] GB</value>
</data>
<data name="mgrCommon_KB" xml:space="preserve">
<value>[PARAM] KB</value>
</data>
<data name="mgrCommon_MB" xml:space="preserve">
<value>[PARAM] MB</value>
</data>
<data name="mgrCommon_PB" xml:space="preserve">
<value>[PARAM] PB</value>
</data>
<data name="mgrCommon_SavedGameFolderSize" xml:space="preserve">
<value>[PARAM] Save Folder Size: [PARAM]</value>
</data>
<data name="mgrCommon_TB" xml:space="preserve">
<value>[PARAM] TB</value>
</data>
</root>