Added drive selector to search

This commit is contained in:
Michael J. Seiferling
2016-03-24 15:46:33 -06:00
parent b458b89b46
commit b149a19a8b
4 changed files with 108 additions and 33 deletions
+20 -8
View File
@@ -28,20 +28,21 @@ Partial Class frmFileFolderSearch
Me.lstResults = New System.Windows.Forms.ListBox() Me.lstResults = New System.Windows.Forms.ListBox()
Me.btnOk = New System.Windows.Forms.Button() Me.btnOk = New System.Windows.Forms.Button()
Me.lblResults = New System.Windows.Forms.Label() Me.lblResults = New System.Windows.Forms.Label()
Me.cboDrive = New System.Windows.Forms.ComboBox()
Me.SuspendLayout() Me.SuspendLayout()
' '
'txtCurrentLocation '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.Name = "txtCurrentLocation"
Me.txtCurrentLocation.ReadOnly = True 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.TabIndex = 0
Me.txtCurrentLocation.TabStop = False Me.txtCurrentLocation.TabStop = False
' '
'btnCancel '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.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(75, 23) Me.btnCancel.Size = New System.Drawing.Size(75, 23)
Me.btnCancel.TabIndex = 4 Me.btnCancel.TabIndex = 4
@@ -55,14 +56,14 @@ Partial Class frmFileFolderSearch
'lstResults 'lstResults
' '
Me.lstResults.FormattingEnabled = True 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.Name = "lstResults"
Me.lstResults.Size = New System.Drawing.Size(460, 56) Me.lstResults.Size = New System.Drawing.Size(460, 82)
Me.lstResults.TabIndex = 2 Me.lstResults.TabIndex = 2
' '
'btnOk '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.Name = "btnOk"
Me.btnOk.Size = New System.Drawing.Size(75, 23) Me.btnOk.Size = New System.Drawing.Size(75, 23)
Me.btnOk.TabIndex = 3 Me.btnOk.TabIndex = 3
@@ -71,18 +72,28 @@ Partial Class frmFileFolderSearch
' '
'lblResults '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.Name = "lblResults"
Me.lblResults.Size = New System.Drawing.Size(463, 13) Me.lblResults.Size = New System.Drawing.Size(463, 13)
Me.lblResults.TabIndex = 1 Me.lblResults.TabIndex = 1
Me.lblResults.Text = "Search Results" Me.lblResults.Text = "Search Results"
Me.lblResults.TextAlign = System.Drawing.ContentAlignment.MiddleCenter 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 'frmFileFolderSearch
' '
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font 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.lblResults)
Me.Controls.Add(Me.btnOk) Me.Controls.Add(Me.btnOk)
Me.Controls.Add(Me.lstResults) Me.Controls.Add(Me.lstResults)
@@ -105,4 +116,5 @@ Partial Class frmFileFolderSearch
Friend WithEvents lstResults As System.Windows.Forms.ListBox Friend WithEvents lstResults As System.Windows.Forms.ListBox
Friend WithEvents btnOk As System.Windows.Forms.Button Friend WithEvents btnOk As System.Windows.Forms.Button
Friend WithEvents lblResults As System.Windows.Forms.Label Friend WithEvents lblResults As System.Windows.Forms.Label
Friend WithEvents cboDrive As System.Windows.Forms.ComboBox
End Class End Class
+70 -19
View File
@@ -4,13 +4,22 @@ Imports System.IO
Public Class frmFileFolderSearch Public Class frmFileFolderSearch
Private sSearchItem As String Private sSearchItem As String
Private sGameName As String = String.Empty Private sGameName As String = String.Empty
Private bIsLoading As Boolean
Private bIsFolder As Boolean Private bIsFolder As Boolean
Private sFoundItem As String Private sFoundItem As String
Private oDrives As List(Of DriveInfo) Private oDrives As List(Of DriveInfo)
Private iCurrentDrive As Integer
Private oSearchDrive As DirectoryInfo Private oSearchDrive As DirectoryInfo
Dim bShutdown As Boolean = False 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 UpdateInfoCallBack(ByVal sCurrentFolder As String)
Delegate Sub UpdateResultsCallBack(ByVal sItem As String) Delegate Sub UpdateResultsCallBack(ByVal sItem As String)
@@ -151,43 +160,58 @@ Public Class frmFileFolderSearch
End Function End Function
Private Sub GetDrives() 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) oDrives = New List(Of DriveInfo)
For Each oDrive As DriveInfo In My.Computer.FileSystem.Drives For Each oDrive As DriveInfo In My.Computer.FileSystem.Drives
If oDrive.DriveType = IO.DriveType.Fixed Then If oDrive.DriveType = IO.DriveType.Fixed Then
oDrives.Add(oDrive) oDrives.Add(oDrive)
oComboItems.Add(New KeyValuePair(Of Integer, String)(iCount, oDrive.RootDirectory.ToString))
iCount += 1
End If End If
Next Next
cboDrive.DataSource = oComboItems
End Sub End Sub
Private Sub Search(ByVal oDrive As DriveInfo) Private Sub Search(ByVal oDrive As DriveInfo)
iStopStatus = eStopStatus.FinishedDrive
oSearchDrive = oDrive.RootDirectory oSearchDrive = oDrive.RootDirectory
bwSearch.RunWorkerAsync() bwSearch.RunWorkerAsync()
iCurrentDrive += 1
End Sub End Sub
Private Sub EndSearch() Private Sub EndSearch()
Dim oResult As MsgBoxResult
If Not bShutdown Then
If FoundItem = "Cancel" Then FoundItem = String.Empty If FoundItem = "Cancel" Then FoundItem = String.Empty
If oDrives.Count > iCurrentDrive And FoundItem = String.Empty Then Select Case iStopStatus
oResult = mgrCommon.ShowMessage(frmFileFolderSearch_SwitchDrives, New String() {oDrives(iCurrentDrive).RootDirectory.ToString}, MsgBoxStyle.YesNo) Case eStopStatus.Cancel
If oResult = MsgBoxResult.Yes Then SearchComplete(frmFileFolderSearch_SearchCancel)
Search(oDrives(iCurrentDrive)) 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 End If
Else Else
SearchComplete() SearchComplete(frmFileFolderSearch_SearchComplete)
End If End If
End If Case eStopStatus.FoundResult
End Sub
Private Sub SearchComplete()
If lstResults.Items.Count = 0 Then
bShutdown = True bShutdown = True
Me.Close() Me.Close()
Else End Select
txtCurrentLocation.Text = frmFileFolderSearch_SearchComplete End Sub
Private Sub SearchComplete(ByVal sStopMessage As String)
txtCurrentLocation.Text = sStopMessage
If lstResults.Items.Count > 0 Then
lstResults.SelectedIndex = 0 lstResults.SelectedIndex = 0
End If End If
End Sub End Sub
@@ -203,9 +227,11 @@ Public Class frmFileFolderSearch
End Sub End Sub
Private Sub frmFileFolderSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub frmFileFolderSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load
bIsLoading = True
SetForm() SetForm()
GetDrives() GetDrives()
Search(oDrives(iCurrentDrive)) bIsLoading = False
Search(oDrives(0))
End Sub End Sub
Private Sub bwSearch_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bwSearch.DoWork 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 Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
If bwSearch.IsBusy Then If bwSearch.IsBusy Then
iStopStatus = eStopStatus.Cancel
bwSearch.CancelAsync() bwSearch.CancelAsync()
Else Else
bShutdown = True bShutdown = True
@@ -230,7 +257,6 @@ Public Class frmFileFolderSearch
End Sub End Sub
Private Sub frmFileFolderSearch_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing Private Sub frmFileFolderSearch_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
bwSearch.CancelAsync()
If Not bShutdown Then e.Cancel = True If Not bShutdown Then e.Cancel = True
End Sub End Sub
@@ -241,9 +267,34 @@ Public Class frmFileFolderSearch
sItem = lstResults.SelectedItem.ToString sItem = lstResults.SelectedItem.ToString
If mgrCommon.ShowMessage(mgrPath_ConfirmPathCorrect, New String() {GameName, sItem}, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then If mgrCommon.ShowMessage(mgrPath_ConfirmPathCorrect, New String() {GameName, sItem}, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
FoundItem = sItem FoundItem = sItem
If bwSearch.IsBusy Then
iStopStatus = eStopStatus.FoundResult
bwSearch.CancelAsync()
Else
bShutdown = True bShutdown = True
Me.Close() Me.Close()
End If End If
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 End Sub
End Class End Class
+9
View File
@@ -861,6 +861,15 @@ Namespace My.Resources
End Get End Get
End Property End Property
'''<summary>
''' Looks up a localized string similar to Search Aborted!.
'''</summary>
Friend ReadOnly Property frmFileFolderSearch_SearchCancel() As String
Get
Return ResourceManager.GetString("frmFileFolderSearch_SearchCancel", resourceCulture)
End Get
End Property
'''<summary> '''<summary>
''' Looks up a localized string similar to Search Complete!. ''' Looks up a localized string similar to Search Complete!.
'''</summary> '''</summary>
+3
View File
@@ -1594,4 +1594,7 @@
<data name="frmFileFolderSearch_SearchComplete" xml:space="preserve"> <data name="frmFileFolderSearch_SearchComplete" xml:space="preserve">
<value>Search Complete!</value> <value>Search Complete!</value>
</data> </data>
<data name="frmFileFolderSearch_SearchCancel" xml:space="preserve">
<value>Search Aborted!</value>
</data>
</root> </root>