diff --git a/GBM/Forms/frmFileFolderSearch.Designer.vb b/GBM/Forms/frmFileFolderSearch.Designer.vb index 4f3ab2e..8d10947 100644 --- a/GBM/Forms/frmFileFolderSearch.Designer.vb +++ b/GBM/Forms/frmFileFolderSearch.Designer.vb @@ -28,20 +28,21 @@ Partial Class frmFileFolderSearch Me.lstResults = New System.Windows.Forms.ListBox() Me.btnOk = New System.Windows.Forms.Button() Me.lblResults = New System.Windows.Forms.Label() + Me.cboDrive = New System.Windows.Forms.ComboBox() Me.SuspendLayout() ' 'txtCurrentLocation ' - Me.txtCurrentLocation.Location = New System.Drawing.Point(12, 12) + Me.txtCurrentLocation.Location = New System.Drawing.Point(102, 13) Me.txtCurrentLocation.Name = "txtCurrentLocation" Me.txtCurrentLocation.ReadOnly = True - Me.txtCurrentLocation.Size = New System.Drawing.Size(460, 20) + Me.txtCurrentLocation.Size = New System.Drawing.Size(370, 20) Me.txtCurrentLocation.TabIndex = 0 Me.txtCurrentLocation.TabStop = False ' 'btnCancel ' - Me.btnCancel.Location = New System.Drawing.Point(397, 114) + Me.btnCancel.Location = New System.Drawing.Point(397, 146) Me.btnCancel.Name = "btnCancel" Me.btnCancel.Size = New System.Drawing.Size(75, 23) Me.btnCancel.TabIndex = 4 @@ -55,14 +56,14 @@ Partial Class frmFileFolderSearch 'lstResults ' Me.lstResults.FormattingEnabled = True - Me.lstResults.Location = New System.Drawing.Point(12, 52) + Me.lstResults.Location = New System.Drawing.Point(12, 58) Me.lstResults.Name = "lstResults" - Me.lstResults.Size = New System.Drawing.Size(460, 56) + Me.lstResults.Size = New System.Drawing.Size(460, 82) Me.lstResults.TabIndex = 2 ' 'btnOk ' - Me.btnOk.Location = New System.Drawing.Point(316, 114) + Me.btnOk.Location = New System.Drawing.Point(316, 146) Me.btnOk.Name = "btnOk" Me.btnOk.Size = New System.Drawing.Size(75, 23) Me.btnOk.TabIndex = 3 @@ -71,18 +72,28 @@ Partial Class frmFileFolderSearch ' 'lblResults ' - Me.lblResults.Location = New System.Drawing.Point(9, 36) + Me.lblResults.Location = New System.Drawing.Point(9, 42) Me.lblResults.Name = "lblResults" Me.lblResults.Size = New System.Drawing.Size(463, 13) Me.lblResults.TabIndex = 1 Me.lblResults.Text = "Search Results" Me.lblResults.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' + 'cboDrive + ' + Me.cboDrive.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList + Me.cboDrive.FormattingEnabled = True + Me.cboDrive.Location = New System.Drawing.Point(12, 12) + Me.cboDrive.Name = "cboDrive" + Me.cboDrive.Size = New System.Drawing.Size(85, 21) + Me.cboDrive.TabIndex = 5 + ' 'frmFileFolderSearch ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(484, 146) + Me.ClientSize = New System.Drawing.Size(484, 181) + Me.Controls.Add(Me.cboDrive) Me.Controls.Add(Me.lblResults) Me.Controls.Add(Me.btnOk) Me.Controls.Add(Me.lstResults) @@ -105,4 +116,5 @@ Partial Class frmFileFolderSearch Friend WithEvents lstResults As System.Windows.Forms.ListBox Friend WithEvents btnOk As System.Windows.Forms.Button Friend WithEvents lblResults As System.Windows.Forms.Label + Friend WithEvents cboDrive As System.Windows.Forms.ComboBox End Class diff --git a/GBM/Forms/frmFileFolderSearch.vb b/GBM/Forms/frmFileFolderSearch.vb index 6bc475d..289754d 100644 --- a/GBM/Forms/frmFileFolderSearch.vb +++ b/GBM/Forms/frmFileFolderSearch.vb @@ -4,13 +4,22 @@ Imports System.IO Public Class frmFileFolderSearch Private sSearchItem As String Private sGameName As String = String.Empty + Private bIsLoading As Boolean Private bIsFolder As Boolean Private sFoundItem As String Private oDrives As List(Of DriveInfo) - Private iCurrentDrive As Integer Private oSearchDrive As DirectoryInfo Dim bShutdown As Boolean = False + Private Enum eStopStatus As Integer + Cancel = 1 + ChangeDrive = 2 + FoundResult = 3 + FinishedDrive = 4 + End Enum + + Private iStopStatus As eStopStatus + Delegate Sub UpdateInfoCallBack(ByVal sCurrentFolder As String) Delegate Sub UpdateResultsCallBack(ByVal sItem As String) @@ -151,43 +160,58 @@ Public Class frmFileFolderSearch End Function Private Sub GetDrives() + Dim oComboItems As New List(Of KeyValuePair(Of Integer, String)) + Dim iCount As Integer = 0 + + 'cboDrive + cboDrive.ValueMember = "Key" + cboDrive.DisplayMember = "Value" + oDrives = New List(Of DriveInfo) For Each oDrive As DriveInfo In My.Computer.FileSystem.Drives If oDrive.DriveType = IO.DriveType.Fixed Then oDrives.Add(oDrive) + oComboItems.Add(New KeyValuePair(Of Integer, String)(iCount, oDrive.RootDirectory.ToString)) + iCount += 1 End If Next + cboDrive.DataSource = oComboItems End Sub Private Sub Search(ByVal oDrive As DriveInfo) + iStopStatus = eStopStatus.FinishedDrive oSearchDrive = oDrive.RootDirectory bwSearch.RunWorkerAsync() - iCurrentDrive += 1 End Sub Private Sub EndSearch() - Dim oResult As MsgBoxResult + If FoundItem = "Cancel" Then FoundItem = String.Empty - If Not bShutdown Then - If FoundItem = "Cancel" Then FoundItem = String.Empty - - If oDrives.Count > iCurrentDrive And FoundItem = String.Empty Then - oResult = mgrCommon.ShowMessage(frmFileFolderSearch_SwitchDrives, New String() {oDrives(iCurrentDrive).RootDirectory.ToString}, MsgBoxStyle.YesNo) - If oResult = MsgBoxResult.Yes Then - Search(oDrives(iCurrentDrive)) + Select Case iStopStatus + Case eStopStatus.Cancel + SearchComplete(frmFileFolderSearch_SearchCancel) + Case eStopStatus.ChangeDrive + Search(oDrives(cboDrive.SelectedValue)) + Case eStopStatus.FinishedDrive + 'Attempt to move onto the next drive it one exists and there's been no results + If oDrives.Count > 1 And lstResults.Items.Count = 0 Then + If cboDrive.SelectedIndex = (cboDrive.Items.Count - 1) Then + cboDrive.SelectedIndex = 0 + Else + cboDrive.SelectedIndex = cboDrive.SelectedIndex + 1 + End If + Else + SearchComplete(frmFileFolderSearch_SearchComplete) End If - Else - SearchComplete() - End If - End If + Case eStopStatus.FoundResult + bShutdown = True + Me.Close() + End Select End Sub - Private Sub SearchComplete() - If lstResults.Items.Count = 0 Then - bShutdown = True - Me.Close() - Else - txtCurrentLocation.Text = frmFileFolderSearch_SearchComplete + Private Sub SearchComplete(ByVal sStopMessage As String) + txtCurrentLocation.Text = sStopMessage + If lstResults.Items.Count > 0 Then lstResults.SelectedIndex = 0 End If End Sub @@ -203,9 +227,11 @@ Public Class frmFileFolderSearch End Sub Private Sub frmFileFolderSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load + bIsLoading = True SetForm() GetDrives() - Search(oDrives(iCurrentDrive)) + bIsLoading = False + Search(oDrives(0)) End Sub Private Sub bwSearch_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bwSearch.DoWork @@ -222,6 +248,7 @@ Public Class frmFileFolderSearch Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click If bwSearch.IsBusy Then + iStopStatus = eStopStatus.Cancel bwSearch.CancelAsync() Else bShutdown = True @@ -229,8 +256,7 @@ Public Class frmFileFolderSearch End If End Sub - Private Sub frmFileFolderSearch_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing - bwSearch.CancelAsync() + Private Sub frmFileFolderSearch_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing If Not bShutdown Then e.Cancel = True End Sub @@ -241,8 +267,33 @@ Public Class frmFileFolderSearch sItem = lstResults.SelectedItem.ToString If mgrCommon.ShowMessage(mgrPath_ConfirmPathCorrect, New String() {GameName, sItem}, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then FoundItem = sItem - bShutdown = True - Me.Close() + If bwSearch.IsBusy Then + iStopStatus = eStopStatus.FoundResult + bwSearch.CancelAsync() + Else + bShutdown = True + Me.Close() + End If + End If + End If + End Sub + + Private Sub cboDrive_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboDrive.SelectedIndexChanged + If Not bIsLoading Then + Dim oResult As MsgBoxResult + + oResult = mgrCommon.ShowMessage(frmFileFolderSearch_SwitchDrives, New String() {oDrives(cboDrive.SelectedValue).RootDirectory.ToString}, MsgBoxStyle.YesNo) + + If oResult = MsgBoxResult.Yes Then + If bwSearch.IsBusy Then + iStopStatus = eStopStatus.ChangeDrive + bwSearch.CancelAsync() + Else + Search(oDrives(cboDrive.SelectedValue)) + End If + Else + iStopStatus = eStopStatus.FinishedDrive + SearchComplete(frmFileFolderSearch_SearchCancel) End If End If End Sub diff --git a/GBM/My Project/Resources.Designer.vb b/GBM/My Project/Resources.Designer.vb index 4c3b60a..6538c3e 100644 --- a/GBM/My Project/Resources.Designer.vb +++ b/GBM/My Project/Resources.Designer.vb @@ -861,6 +861,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to Search Aborted!. + ''' + Friend ReadOnly Property frmFileFolderSearch_SearchCancel() As String + Get + Return ResourceManager.GetString("frmFileFolderSearch_SearchCancel", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to Search Complete!. ''' diff --git a/GBM/My Project/Resources.resx b/GBM/My Project/Resources.resx index c879fe8..83ee2db 100644 --- a/GBM/My Project/Resources.resx +++ b/GBM/My Project/Resources.resx @@ -1594,4 +1594,7 @@ Search Complete! + + Search Aborted! + \ No newline at end of file