Skip to content

Commit c628f9b

Browse files
committed
Remove filesToPrcess list and update the logic to process files in a single pass.
1 parent 68aed24 commit c628f9b

1 file changed

Lines changed: 27 additions & 40 deletions

File tree

SharpPocketToolsGUI/frmMain.vb

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Imports System.Text.RegularExpressions
44

55
Public Class frmMain
66

7-
Dim filesToPrcess As List(Of String)
8-
97
''' <summary>
108
''' Execute a process, wait for it to finish and redirect output if needed.
119
''' </summary>
@@ -50,47 +48,35 @@ Public Class frmMain
5048
End Function
5149

5250
''' <summary>
53-
''' Processes the files one by one and calls the required function based by the file extension.
51+
''' Processes the file and calls the required function based by the file extension.
5452
''' </summary>
55-
Sub ProcessFiles()
53+
Sub ProcessFile(file As String)
5654
Dim ret As Integer = 0
5755

58-
For Each file In filesToPrcess
59-
txtLog.Text &= "Processing " & file & vbCrLf & vbCrLf
60-
If file.EndsWith(".bas", StringComparison.OrdinalIgnoreCase) Then
61-
Dim sharpFileName As String
62-
If optUseFilename.Checked = True Then
63-
'Use the specified file name
64-
sharpFileName = txtFileName.Text.ToUpper()
56+
If file.EndsWith(".bas", StringComparison.OrdinalIgnoreCase) Then
57+
Dim sharpFileName As String
58+
If optUseFilename.Checked = True Then
59+
'Use the specified file name
60+
sharpFileName = txtFileName.Text.ToUpper()
61+
Else
62+
If Path.GetFileNameWithoutExtension(file).Length > txtFileName.MaxLength Then
63+
'Truncate the file name if it is longer than 7 characters (or 16 for Sharp 1500)
64+
sharpFileName = Path.GetFileNameWithoutExtension(file).Substring(0, txtFileName.MaxLength).ToUpper()
65+
txtLog.Text &= "Warning! Filename is longer than " & txtFileName.MaxLength & " characters! It will be truncated to " & sharpFileName & vbCrLf
6566
Else
66-
If Path.GetFileNameWithoutExtension(file).Length > txtFileName.MaxLength Then
67-
'Truncate the file name if it is longer than 7 characters (or 16 for Sharp 1500)
68-
sharpFileName = Path.GetFileNameWithoutExtension(file).Substring(0, txtFileName.MaxLength).ToUpper()
69-
txtLog.Text &= "Warning! Filename is longer than " & txtFileName.MaxLength & " characters! It will be truncated to " & sharpFileName & vbCrLf & vbCrLf
70-
Else
71-
sharpFileName = Path.GetFileNameWithoutExtension(file).ToUpper()
72-
End If
67+
sharpFileName = Path.GetFileNameWithoutExtension(file).ToUpper()
7368
End If
74-
ret = ProcessBAS(file, sharpFileName)
75-
ElseIf file.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) Then
76-
ret = ProcessWAV(file, False)
77-
ElseIf file.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) Then
78-
ret = ProcessWAV(file, True)
79-
End If
80-
If ret = -1 Then
81-
Exit For
8269
End If
83-
txtLog.Text &= "---------------------------------------------------------------------" & vbCrLf
84-
Next
70+
ret = ProcessBAS(file, sharpFileName)
71+
ElseIf file.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) Then
72+
ret = ProcessWAV(file, False)
73+
ElseIf file.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) Then
74+
ret = ProcessWAV(file, True)
75+
End If
8576

8677
If ret = -1 Then
87-
txtLog.Text &= vbCrLf & "Please check output above!" & vbCrLf
78+
txtLog.Text &= vbCrLf & "Errors encountered while processing " & file & " Please check output above!" & vbCrLf
8879
End If
89-
txtLog.Text &= "Done." & vbCrLf
90-
91-
'Always scroll the Log to the end.
92-
txtLog.SelectionStart = txtLog.Text.Length
93-
txtLog.ScrollToCaret()
9480
End Sub
9581

9682
''' <summary>
@@ -256,7 +242,6 @@ Public Class frmMain
256242

257243
Private Sub frmMain_DragDrop(sender As Object, e As DragEventArgs) Handles MyBase.DragDrop
258244
Dim files As String() = e.Data.GetData(DataFormats.FileDrop)
259-
filesToPrcess.Clear()
260245
txtLog.Clear()
261246

262247
'Add only the supported files to the process queue
@@ -272,17 +257,20 @@ Public Class frmMain
272257
If file.EndsWith(".bas", StringComparison.OrdinalIgnoreCase) OrElse
273258
file.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) OrElse
274259
file.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) Then
275-
filesToPrcess.Add(file)
276-
txtLog.Text &= "Will process " & file & vbCrLf
260+
txtLog.Text &= "Processing " & file & vbCrLf & vbCrLf
261+
ProcessFile(file)
277262
Else
278263
txtLog.Text &= "Unsupported " & file & vbCrLf
279264
End If
280265
End If
266+
txtLog.Text &= "----------------------------------------------------------------------" & vbCrLf
281267
Next
282268

283-
txtLog.Text &= "====================================================================" & vbCrLf & vbCrLf
269+
txtLog.Text &= "Done." & vbCrLf
284270

285-
ProcessFiles()
271+
'Always scroll the Log to the end.
272+
txtLog.SelectionStart = txtLog.Text.Length
273+
txtLog.ScrollToCaret()
286274
End Sub
287275

288276
Private Sub frmMain_DragEnter(sender As Object, e As DragEventArgs) Handles MyBase.DragEnter
@@ -293,7 +281,6 @@ Public Class frmMain
293281

294282
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
295283
Text = My.Application.Info.Title & " v" & My.Application.Info.Version.Major & "." & My.Application.Info.Version.Minor
296-
filesToPrcess = New List(Of String)
297284

298285
'Load settings
299286
cmbPcModel.Text = My.Settings.pcModel

0 commit comments

Comments
 (0)