From 7062f4b4eac69e5e9b9c3fc5507da9768b7ffe9a Mon Sep 17 00:00:00 2001 From: MikeMaximus Date: Sun, 7 Apr 2019 14:16:47 -0600 Subject: [PATCH] Added "Open Backup Folder" to Game Manager --- GBM/Forms/frmGameManager.Designer.vb | 46 ++++++++++++++---- GBM/Forms/frmGameManager.resx | 3 ++ GBM/Forms/frmGameManager.vb | 72 ++++++++++++---------------- GBM/Managers/mgrCommon.vb | 28 +++++++++++ GBM/My Project/Resources.Designer.vb | 37 ++++++++++++-- GBM/My Project/Resources.resx | 15 ++++-- 6 files changed, 141 insertions(+), 60 deletions(-) diff --git a/GBM/Forms/frmGameManager.Designer.vb b/GBM/Forms/frmGameManager.Designer.vb index f19700e..fa5e066 100644 --- a/GBM/Forms/frmGameManager.Designer.vb +++ b/GBM/Forms/frmGameManager.Designer.vb @@ -81,7 +81,7 @@ Partial Class frmGameManager Me.lblLocalBackupData = New System.Windows.Forms.Label() Me.lblRestorePath = New System.Windows.Forms.Label() Me.btnOpenRestorePath = New System.Windows.Forms.Button() - Me.btnOpenBackupFile = New System.Windows.Forms.Button() + Me.btnOpenBackup = New System.Windows.Forms.Button() Me.btnDeleteBackup = New System.Windows.Forms.Button() Me.lblBackupFile = New System.Windows.Forms.Label() Me.lblRemote = New System.Windows.Forms.Label() @@ -111,6 +111,9 @@ Partial Class frmGameManager Me.cmsDeleteAll = New System.Windows.Forms.ToolStripMenuItem() Me.btnProcesses = New System.Windows.Forms.Button() Me.ttFullPath = New System.Windows.Forms.ToolTip(Me.components) + Me.cmsOpenBackup = New System.Windows.Forms.ContextMenuStrip(Me.components) + Me.cmsOpenBackupFile = New System.Windows.Forms.ToolStripMenuItem() + Me.cmsOpenBackupFolder = New System.Windows.Forms.ToolStripMenuItem() Me.grpConfig.SuspendLayout() CType(Me.nudLimit, System.ComponentModel.ISupportInitialize).BeginInit() Me.grpExtra.SuspendLayout() @@ -120,6 +123,7 @@ Partial Class frmGameManager Me.grpFilter.SuspendLayout() Me.cmsImport.SuspendLayout() Me.cmsDeleteBackup.SuspendLayout() + Me.cmsOpenBackup.SuspendLayout() Me.SuspendLayout() ' 'btnAdd @@ -629,7 +633,7 @@ Partial Class frmGameManager Me.grpStats.Controls.Add(Me.lblLocalBackupData) Me.grpStats.Controls.Add(Me.lblRestorePath) Me.grpStats.Controls.Add(Me.btnOpenRestorePath) - Me.grpStats.Controls.Add(Me.btnOpenBackupFile) + Me.grpStats.Controls.Add(Me.btnOpenBackup) Me.grpStats.Controls.Add(Me.btnDeleteBackup) Me.grpStats.Controls.Add(Me.lblBackupFile) Me.grpStats.Controls.Add(Me.lblRemote) @@ -711,14 +715,14 @@ Partial Class frmGameManager Me.btnOpenRestorePath.Text = "O&pen Restore Path" Me.btnOpenRestorePath.UseVisualStyleBackColor = True ' - 'btnOpenBackupFile + 'btnOpenBackup ' - Me.btnOpenBackupFile.Location = New System.Drawing.Point(249, 125) - Me.btnOpenBackupFile.Name = "btnOpenBackupFile" - Me.btnOpenBackupFile.Size = New System.Drawing.Size(114, 23) - Me.btnOpenBackupFile.TabIndex = 10 - Me.btnOpenBackupFile.Text = "&Open Backup File" - Me.btnOpenBackupFile.UseVisualStyleBackColor = True + Me.btnOpenBackup.Location = New System.Drawing.Point(249, 125) + Me.btnOpenBackup.Name = "btnOpenBackup" + Me.btnOpenBackup.Size = New System.Drawing.Size(114, 23) + Me.btnOpenBackup.TabIndex = 10 + Me.btnOpenBackup.Text = "&Open Backup" + Me.btnOpenBackup.UseVisualStyleBackColor = True ' 'btnDeleteBackup ' @@ -972,6 +976,24 @@ Partial Class frmGameManager Me.ttFullPath.InitialDelay = 300 Me.ttFullPath.ReshowDelay = 60 ' + 'cmsOpenBackup + ' + Me.cmsOpenBackup.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.cmsOpenBackupFile, Me.cmsOpenBackupFolder}) + Me.cmsOpenBackup.Name = "cmsOpenBackup" + Me.cmsOpenBackup.Size = New System.Drawing.Size(108, 48) + ' + 'cmsOpenBackupFile + ' + Me.cmsOpenBackupFile.Name = "cmsOpenBackupFile" + Me.cmsOpenBackupFile.Size = New System.Drawing.Size(107, 22) + Me.cmsOpenBackupFile.Text = "&File" + ' + 'cmsOpenBackupFolder + ' + Me.cmsOpenBackupFolder.Name = "cmsOpenBackupFolder" + Me.cmsOpenBackupFolder.Size = New System.Drawing.Size(107, 22) + Me.cmsOpenBackupFolder.Text = "F&older" + ' 'frmGameManager ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) @@ -1017,6 +1039,7 @@ Partial Class frmGameManager Me.grpFilter.PerformLayout() Me.cmsImport.ResumeLayout(False) Me.cmsDeleteBackup.ResumeLayout(False) + Me.cmsOpenBackup.ResumeLayout(False) Me.ResumeLayout(False) Me.PerformLayout() @@ -1065,7 +1088,7 @@ Partial Class frmGameManager Friend WithEvents btnMarkAsRestored As System.Windows.Forms.Button Friend WithEvents btnRestore As System.Windows.Forms.Button Friend WithEvents btnDeleteBackup As System.Windows.Forms.Button - Friend WithEvents btnOpenBackupFile As System.Windows.Forms.Button + Friend WithEvents btnOpenBackup As System.Windows.Forms.Button Friend WithEvents grpFilter As System.Windows.Forms.GroupBox Friend WithEvents optPendingRestores As System.Windows.Forms.RadioButton Friend WithEvents optAllGames As System.Windows.Forms.RadioButton @@ -1109,4 +1132,7 @@ Partial Class frmGameManager Friend WithEvents lblOS As Label Friend WithEvents cboOS As ComboBox Friend WithEvents btnWineConfig As Button + Friend WithEvents cmsOpenBackup As ContextMenuStrip + Friend WithEvents cmsOpenBackupFile As ToolStripMenuItem + Friend WithEvents cmsOpenBackupFolder As ToolStripMenuItem End Class diff --git a/GBM/Forms/frmGameManager.resx b/GBM/Forms/frmGameManager.resx index 30ad1df..5897b7d 100644 --- a/GBM/Forms/frmGameManager.resx +++ b/GBM/Forms/frmGameManager.resx @@ -126,4 +126,7 @@ 275, 17 + + 378, 17 + \ No newline at end of file diff --git a/GBM/Forms/frmGameManager.vb b/GBM/Forms/frmGameManager.vb index 5e823b3..9840504 100644 --- a/GBM/Forms/frmGameManager.vb +++ b/GBM/Forms/frmGameManager.vb @@ -535,24 +535,15 @@ Public Class frmGameManager End Sub Private Sub OpenBackupFile() - Dim sFileName As String - Dim oProcessStartInfo As ProcessStartInfo + Dim sFileName As String = BackupFolder & CurrentBackupItem.FileName - sFileName = BackupFolder & CurrentBackupItem.FileName + mgrCommon.OpenInOS(sFileName, frmGameManager_ErrorNoBackupFileExists) + End Sub - If File.Exists(sFileName) Then - Try - oProcessStartInfo = New ProcessStartInfo - oProcessStartInfo.FileName = sFileName - oProcessStartInfo.UseShellExecute = True - oProcessStartInfo.Verb = "open" - Process.Start(oProcessStartInfo) - Catch ex As Exception - mgrCommon.ShowMessage(App_ErrorLaunchExternal, ex.Message, MsgBoxStyle.Exclamation) - End Try - Else - mgrCommon.ShowMessage(frmGameManager_ErrorNoBackupExists, MsgBoxStyle.Exclamation) - End If + Private Sub OpenBackupFolder() + Dim sFileName As String = BackupFolder & Path.GetDirectoryName(CurrentBackupItem.FileName) + + mgrCommon.OpenInOS(sFileName, frmGameManager_ErrorNoBackupFolderExists) End Sub Private Sub UpdateBuilderButtonLabel(ByVal sBuilderString As String, ByVal sLabel As String, ByVal btn As Button, ByVal bDirty As Boolean) @@ -642,7 +633,6 @@ Public Class frmGameManager Private Sub OpenRestorePath() Dim sPath As String = String.Empty - Dim oProcessStartInfo As ProcessStartInfo If CurrentBackupItem.AbsolutePath Then sPath = CurrentBackupItem.RestorePath @@ -652,19 +642,7 @@ Public Class frmGameManager End If End If - If Directory.Exists(sPath) Then - Try - oProcessStartInfo = New ProcessStartInfo - oProcessStartInfo.FileName = sPath - oProcessStartInfo.UseShellExecute = True - oProcessStartInfo.Verb = "open" - Process.Start(oProcessStartInfo) - Catch ex As Exception - mgrCommon.ShowMessage(App_ErrorLaunchExternal, ex.Message, MsgBoxStyle.Exclamation) - End Try - Else - mgrCommon.ShowMessage(frmGameManager_ErrorNoRestorePathExists, MsgBoxStyle.Exclamation) - End If + mgrCommon.OpenInOS(sPath, frmGameManager_ErrorNoRestorePathExists) End Sub Private Sub OpenProcesses() @@ -822,7 +800,7 @@ Public Class frmGameManager sFileName = BackupFolder & CurrentBackupItem.FileName - btnOpenBackupFile.Enabled = True + btnOpenBackup.Enabled = True btnOpenRestorePath.Enabled = True btnRestore.Enabled = True btnDeleteBackup.Enabled = True @@ -830,7 +808,7 @@ Public Class frmGameManager If File.Exists(sFileName) Then lblBackupFileData.Text = Path.GetFileName(CurrentBackupItem.FileName) & " (" & mgrCommon.FormatDiskSpace(mgrCommon.GetFileSize(sFileName)) & ")" Else - lblBackupFileData.Text = frmGameManager_ErrorNoBackupExists + lblBackupFileData.Text = frmGameManager_ErrorNoBackupFileExists End If SetBackupRestorePath(oApp) @@ -838,7 +816,7 @@ Public Class frmGameManager oComboItems.Add(New KeyValuePair(Of String, String)(String.Empty, frmGameManager_None)) lblBackupFileData.Text = String.Empty lblRestorePathData.Text = String.Empty - btnOpenBackupFile.Enabled = False + btnOpenBackup.Enabled = False btnOpenRestorePath.Enabled = False btnRestore.Enabled = False btnDeleteBackup.Enabled = False @@ -876,7 +854,7 @@ Public Class frmGameManager If mgrPath.IsSupportedRegistryPath(oApp.TruePath) Then btnImportBackup.Enabled = False - btnOpenBackupFile.Enabled = False + btnOpenBackup.Enabled = False btnOpenRestorePath.Enabled = False End If @@ -893,7 +871,7 @@ Public Class frmGameManager If File.Exists(sFileName) Then lblBackupFileData.Text = Path.GetFileName(CurrentBackupItem.FileName) & " (" & mgrCommon.FormatDiskSpace(mgrCommon.GetFileSize(sFileName)) & ")" Else - lblBackupFileData.Text = frmGameManager_ErrorNoBackupExists + lblBackupFileData.Text = frmGameManager_ErrorNoBackupFileExists End If SetBackupRestorePath(CurrentGame) @@ -1081,7 +1059,7 @@ Public Class frmGameManager btnRestore.Enabled = False btnImportBackup.Enabled = False btnDeleteBackup.Enabled = False - btnOpenBackupFile.Enabled = False + btnOpenBackup.Enabled = False btnOpenRestorePath.Enabled = False chkEnabled.Checked = True chkMonitorOnly.Checked = False @@ -1115,7 +1093,7 @@ Public Class frmGameManager btnRestore.Enabled = False btnImportBackup.Enabled = False btnDeleteBackup.Enabled = False - btnOpenBackupFile.Enabled = False + btnOpenBackup.Enabled = False btnOpenRestorePath.Enabled = False btnTags.Enabled = True btnProcesses.Enabled = True @@ -1818,7 +1796,7 @@ Public Class frmGameManager btnSave.Text = frmGameManager_btnSave lblRestorePath.Text = frmGameManager_lblRestorePath btnOpenRestorePath.Text = frmGameManager_btnOpenRestorePath - btnOpenBackupFile.Text = frmGameManager_btnOpenBackupFile + btnOpenBackup.Text = frmGameManager_btnOpenBackup btnDeleteBackup.Text = frmGameManager_btnDeleteBackup lblBackupFile.Text = frmGameManager_lblBackupFile lblRemote.Text = frmGameManager_lblRemote @@ -1860,6 +1838,8 @@ Public Class frmGameManager btnProcesses.Text = frmGameManager_btnProcesses lblOS.Text = frmGameManager_lblOS btnWineConfig.Text = frmGameManager_btnWineConfig + cmsOpenBackupFile.Text = frmGameManager_cmsOpenBackupFile + cmsOpenBackupFolder.Text = frmGameManager_cmsOpenBackupFolder 'Init Combos Dim oComboItems As New List(Of KeyValuePair(Of Integer, String)) @@ -1902,7 +1882,7 @@ Public Class frmGameManager btnRestore.Visible = False btnMarkAsRestored.Visible = False btnDeleteBackup.Visible = False - btnOpenBackupFile.Visible = False + btnOpenBackup.Visible = False btnOpenRestorePath.Visible = False End If @@ -1984,10 +1964,18 @@ Public Class frmGameManager IconBrowse() End Sub - Private Sub btnOpenBackupFile_Click(sender As Object, e As EventArgs) Handles btnOpenBackupFile.Click + Private Sub btnOpenBackup_Click(sender As Object, e As EventArgs) Handles btnOpenBackup.Click + mgrCommon.OpenButtonSubMenu(cmsOpenBackup, btnOpenBackup) + End Sub + + Private Sub cmsOpenBackupFile_Click(sender As Object, e As EventArgs) Handles cmsOpenBackupFile.Click OpenBackupFile() End Sub + Private Sub cmsOpenBackupFolder_Click(sender As Object, e As EventArgs) Handles cmsOpenBackupFolder.Click + OpenBackupFolder() + End Sub + Private Sub btnOpenRestorePath_Click(sender As Object, e As EventArgs) Handles btnOpenRestorePath.Click OpenRestorePath() End Sub @@ -2006,7 +1994,7 @@ Public Class frmGameManager Private Sub btnDeleteBackup_Click(sender As Object, e As EventArgs) Handles btnDeleteBackup.Click If cboRemoteBackup.Items.Count > 1 Then - cmsDeleteBackup.Show(btnDeleteBackup, New Drawing.Point(btnDeleteBackup.Size.Width - Math.Floor(btnDeleteBackup.Size.Width * 0.1), btnDeleteBackup.Size.Height - Math.Floor(btnDeleteBackup.Size.Height * 0.5)), ToolStripDropDownDirection.AboveRight) + mgrCommon.OpenButtonSubMenu(cmsDeleteBackup, btnDeleteBackup) Else DeleteBackup() End If @@ -2076,7 +2064,7 @@ Public Class frmGameManager End Sub Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click - cmsImport.Show(btnImport, New Drawing.Point(btnImport.Size.Width - Math.Floor(btnImport.Size.Width * 0.1), btnImport.Size.Height - Math.Floor(btnImport.Size.Height * 0.5)), ToolStripDropDownDirection.AboveRight) + mgrCommon.OpenButtonSubMenu(cmsImport, btnImport) End Sub Private Sub cmsOfficialWindows_Click(sender As Object, e As EventArgs) Handles cmsOfficialWindows.Click, cmsOfficial.Click diff --git a/GBM/Managers/mgrCommon.vb b/GBM/Managers/mgrCommon.vb index 5bf0e0a..4dfe00f 100644 --- a/GBM/Managers/mgrCommon.vb +++ b/GBM/Managers/mgrCommon.vb @@ -529,6 +529,29 @@ Public Class mgrCommon End If End Sub + 'Opens a file or folder in default application determined by the OS + Public Shared Function OpenInOS(ByVal sFileName As String, ByVal sNotFoundError As String) As Boolean + Dim oProcessStartInfo As ProcessStartInfo + + If File.Exists(sFileName) Or Directory.Exists(sFileName) Then + Try + oProcessStartInfo = New ProcessStartInfo + oProcessStartInfo.FileName = sFileName + oProcessStartInfo.UseShellExecute = True + oProcessStartInfo.Verb = "open" + Process.Start(oProcessStartInfo) + Catch ex As Exception + mgrCommon.ShowMessage(App_ErrorLaunchExternal, ex.Message, MsgBoxStyle.Exclamation) + Return False + End Try + Else + mgrCommon.ShowMessage(sNotFoundError, MsgBoxStyle.Exclamation) + Return False + End If + + Return True + End Function + 'Delete a sub-folder based on the provided backup information Public Shared Sub DeleteDirectoryByBackup(ByVal sBackupFolder As String, ByVal oBackup As clsBackup) Dim oDir As DirectoryInfo @@ -569,6 +592,11 @@ Public Class mgrCommon End Try End Sub + 'Open a nice button sub-menu + Public Shared Sub OpenButtonSubMenu(ByRef cms As ContextMenuStrip, ByRef btn As Button) + cms.Show(btn, New Drawing.Point(btn.Size.Width - Math.Floor(btn.Size.Width * 0.1), btn.Size.Height - Math.Floor(btn.Size.Height * 0.5)), ToolStripDropDownDirection.AboveRight) + End Sub + 'Configure a fake form to trigger focus for priority messages Private Shared Sub ConfigureFakeForm(ByRef frm As Form) frm.FormBorderStyle = FormBorderStyle.None diff --git a/GBM/My Project/Resources.Designer.vb b/GBM/My Project/Resources.Designer.vb index e62c3c3..3494233 100644 --- a/GBM/My Project/Resources.Designer.vb +++ b/GBM/My Project/Resources.Designer.vb @@ -1654,11 +1654,11 @@ Namespace My.Resources End Property ''' - ''' Looks up a localized string similar to &Open Backup File. + ''' Looks up a localized string similar to &Open Backup. ''' - Friend ReadOnly Property frmGameManager_btnOpenBackupFile() As String + Friend ReadOnly Property frmGameManager_btnOpenBackup() As String Get - Return ResourceManager.GetString("frmGameManager_btnOpenBackupFile", resourceCulture) + Return ResourceManager.GetString("frmGameManager_btnOpenBackup", resourceCulture) End Get End Property @@ -1905,6 +1905,24 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to &File. + ''' + Friend ReadOnly Property frmGameManager_cmsOpenBackupFile() As String + Get + Return ResourceManager.GetString("frmGameManager_cmsOpenBackupFile", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to F&older. + ''' + Friend ReadOnly Property frmGameManager_cmsOpenBackupFolder() As String + Get + Return ResourceManager.GetString("frmGameManager_cmsOpenBackupFolder", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to Are you sure you want to run a backup for [PARAM]? This will close the form.. ''' @@ -2106,9 +2124,18 @@ Namespace My.Resources ''' ''' Looks up a localized string similar to The backup file does not exist.. ''' - Friend ReadOnly Property frmGameManager_ErrorNoBackupExists() As String + Friend ReadOnly Property frmGameManager_ErrorNoBackupFileExists() As String Get - Return ResourceManager.GetString("frmGameManager_ErrorNoBackupExists", resourceCulture) + Return ResourceManager.GetString("frmGameManager_ErrorNoBackupFileExists", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to The backup folder does not exist.. + ''' + Friend ReadOnly Property frmGameManager_ErrorNoBackupFolderExists() As String + Get + Return ResourceManager.GetString("frmGameManager_ErrorNoBackupFolderExists", resourceCulture) End Get End Property diff --git a/GBM/My Project/Resources.resx b/GBM/My Project/Resources.resx index 5cab32a..ce1e1ad 100644 --- a/GBM/My Project/Resources.resx +++ b/GBM/My Project/Resources.resx @@ -460,8 +460,8 @@ &Mark as Restored - - &Open Backup File + + &Open Backup O&pen Restore Path @@ -553,7 +553,7 @@ The selected game(s) have no backup data or can't be restored with their current configuration. - + The backup file does not exist. @@ -2380,4 +2380,13 @@ ..\resources\gbm.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + &File + + + F&older + + + The backup folder does not exist. + \ No newline at end of file