Skip to content

Commit 86391d0

Browse files
committed
Code cleanups and refactoring
Merged Import Image Forms for Greaseweazle and Kryoflux Replaced old VB6 style IIFs with IFs Improved the command line Parser Continued work on implementing Read to raw support
1 parent 47e625b commit 86391d0

32 files changed

+1807
-1624
lines changed

DiskImageTool/DiskImage/EpandedDate.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
Public Overloads Function ToString(IncludeTime As Boolean, IncludeSeconds As Boolean, IncludeMilliseconds As Boolean, Use24Hour As Boolean) As String
8080
Dim Response As String = Format(_Year, "0000") & "-" & Format(_Month, "00") & "-" & Format(_Day, "00")
8181
If IncludeTime Then
82-
Response &= " " & Format(IIf(Use24Hour, _Hour, _Hour12), "00") _
82+
Response &= " " & Format(If(Use24Hour, _Hour, _Hour12), "00") _
8383
& ":" & Format(_Minute, "00")
8484

8585
If IncludeSeconds Then
@@ -91,7 +91,7 @@
9191
End If
9292

9393
If Not Use24Hour Then
94-
Response &= IIf(_IsPM, " PM", " AM")
94+
Response &= If(_IsPM, " PM", " AM")
9595
End If
9696
End If
9797

DiskImageTool/DiskImageTool.vbproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@
173173
<Compile Include="Filters\ImageFiltersBase.vb" />
174174
<Compile Include="DiskImageLib.vb" />
175175
<Compile Include="Flux\Greaseweazle\TrackStatus.vb" />
176+
<Compile Include="Flux\ImportImageFormBase.vb">
177+
<SubType>Form</SubType>
178+
</Compile>
176179
<Compile Include="Flux\Kryoflux\CommandLineBuilder.vb" />
177180
<Compile Include="Flux\Kryoflux\ConsoleParser.vb" />
178181
<Compile Include="Flux\Kryoflux\Forms\ConfigurationForm.Designer.vb">

DiskImageTool/FilePanel/FilePanel.vb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Public Class FilePanel
160160
Public Function AddGroup(Directory As IDirectory, Path As String, GroupIndex As Integer) As ListViewGroup
161161
Dim FileCount As UInteger = Directory.Data.FileCount
162162

163-
Dim GroupName As String = IIf(Path = "", InParens(My.Resources.Label_Root), Path) & " ("
163+
Dim GroupName As String = If(Path = "", InParens(My.Resources.Label_Root), Path) & " ("
164164

165165
If FileCount = 1 Then
166166
GroupName &= String.Format(My.Resources.Label_Entry, FileCount)
@@ -327,12 +327,12 @@ Public Class FilePanel
327327
Dim HasInvalidFileSize As Boolean = FileData.DirectoryEntry.HasInvalidFileSize
328328
Dim IsBlank As Boolean = FileData.DirectoryEntry.IsBlank
329329

330-
Dim Attrib As String = IIf(FileData.DirectoryEntry.IsArchive, "A ", "- ") _
331-
& IIf(FileData.DirectoryEntry.IsReadOnly, "R ", "- ") _
332-
& IIf(FileData.DirectoryEntry.IsSystem, "S ", "- ") _
333-
& IIf(FileData.DirectoryEntry.IsHidden, "H ", "- ") _
334-
& IIf(FileData.DirectoryEntry.IsDirectory, "D ", "- ") _
335-
& IIf(FileData.DirectoryEntry.IsVolumeName, "V ", "- ")
330+
Dim Attrib As String = If(FileData.DirectoryEntry.IsArchive, "A ", "- ") _
331+
& If(FileData.DirectoryEntry.IsReadOnly, "R ", "- ") _
332+
& If(FileData.DirectoryEntry.IsSystem, "S ", "- ") _
333+
& If(FileData.DirectoryEntry.IsHidden, "H ", "- ") _
334+
& If(FileData.DirectoryEntry.IsDirectory, "D ", "- ") _
335+
& If(FileData.DirectoryEntry.IsVolumeName, "V ", "- ")
336336

337337
If IsDeleted Then
338338
ForeColor = Color.Gray
@@ -342,7 +342,7 @@ Public Class FilePanel
342342
ForeColor = Color.Blue
343343
End If
344344

345-
Dim ModifiedString As String = IIf(FileData.DirectoryEntry.IsModified, "#", "")
345+
Dim ModifiedString As String = If(FileData.DirectoryEntry.IsModified, "#", "")
346346

347347
Dim Item As New ListViewItem(ModifiedString, Group) With {
348348
.UseItemStyleForSubItems = False,
@@ -842,7 +842,7 @@ Public Class FilePanel
842842
' Else
843843
' Offset = 0
844844
'End If
845-
Dim State = IIf(_CheckAll, VisualStyles.CheckBoxState.CheckedNormal, VisualStyles.CheckBoxState.UncheckedNormal)
845+
Dim State = If(_CheckAll, VisualStyles.CheckBoxState.CheckedNormal, VisualStyles.CheckBoxState.UncheckedNormal)
846846
Dim Size = CheckBoxRenderer.GetGlyphSize(e.Graphics, State)
847847
CheckBoxRenderer.DrawCheckBox(e.Graphics, New Point(4, (e.Bounds.Height - Size.Height) \ 2), State)
848848
'e.Graphics.DrawString(e.Header.Text, e.Font, New SolidBrush(Color.Black), New Point(20 + Offset, (e.Bounds.Height - Size.Height) \ 2 + Offset))

DiskImageTool/Filters/ImageFiltersBase.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
ItemTag.Visible = Visible
166166

167167
With _ContextMenuFilters.Items.Item("FilterSeparator")
168-
.Tag = .Tag + IIf(Visible, 1, -1)
168+
.Tag = .Tag + If(Visible, 1, -1)
169169
.Visible = (.Tag > 0)
170170
End With
171171
End If

DiskImageTool/Flux/Greaseweazle/ConsoleParser.vb

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Namespace Flux.Greaseweazle
77
Public Const REGEX_TRACK_CONVERTING As String = "^\s*Converting\s+c=(?<cs>\d+)(?:-(?<ce>\d+))?\s*:\s*h=(?<hs>\d+)(?:-(?<he>\d+))?\s*->\s*c=(?<ds>\d+)(?:-(?<de>\d+))?\s*:\s*h=(?<dhs>\d+)(?:-(?<dhe>\d+))?\s*$"
88
Public Const REGEX_TRACK_READ_DETAILS As String = "^(?<system>\w+) (?<encoding>\w+)( \((?<sectorsFound>\d+)\/(?<sectorsTotal>\d+) sectors\))?(?: from (?<srcFormat>[^()]+))? \((?<fluxCount>\d+) flux in (?<fluxTimeMS>\d+(?:\.?\d+)?)ms\)( \(Retry #(?<seek>\d+)\.(?<retry>\d+)\))?"
99
Public Const REGEX_TRACK_READ_FAILED As String = "^Giving up: (?<sectors>\d+) sectors missing"
10+
Public Const REGEX_TRACK_READ_OUTOFRANGE As String = "^WARNING: Out of range for format '(?<format>(\w|\.)+)': No format conversion applied: Raw Flux \((?<fluxCount>\d+) flux in (?<fluxTimeMS>\d+(?:\.?\d+)?)ms\)"
1011
Public Const REGEX_TRACK_READ_SUMMARY As String = "^T(?<destTrack>\d+)\.(?<destSide>\d+)( <- (?<srcType>\w+) (?<srcTrack>\d+)\.(?<srcSide>\d+))?: (?<details>.+)"
1112
Public Const REGEX_TRACK_UNEXPECTED As String = "^T(?<track>\d+)\.(?<side>\d+): Ignoring unexpected sector C:(?<cylinder>\d+) H:(?<head>\d+) R:(?<sectorId>\d+) N:(?<sizeId>\d+)"
1213
Public Const REGEX_TRACK_WRITE As String = "^T(?<srcTrack>\d+)\.(?<srcSide>\d+)( -> Drive (?<destTrack>\d+).(?<destHead>\d+))?: (?<action>Writing|Erasing) Track\b( \((?<details>.+)\))?"
@@ -17,6 +18,7 @@ Namespace Flux.Greaseweazle
1718
Private ReadOnly RegExTrackConverting As New Regex(REGEX_TRACK_CONVERTING, RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant Or RegexOptions.Compiled)
1819
Private ReadOnly RegExTrackReadDetails As New Regex(REGEX_TRACK_READ_DETAILS, RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant Or RegexOptions.Compiled)
1920
Private ReadOnly RegExTrackReadFailed As New Regex(REGEX_TRACK_READ_FAILED, RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant Or RegexOptions.Compiled)
21+
Private ReadOnly RegExTrackReadOutOfRange As New Regex(REGEX_TRACK_READ_OUTOFRANGE, RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant Or RegexOptions.Compiled)
2022
Private ReadOnly RegExTrackReadSummary As New Regex(REGEX_TRACK_READ_SUMMARY, RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant Or RegexOptions.Compiled)
2123
Private ReadOnly RegExTrackUnexpected As New Regex(REGEX_TRACK_UNEXPECTED, RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant Or RegexOptions.Compiled)
2224
Private ReadOnly RegExTrackWrite As New Regex(REGEX_TRACK_WRITE, RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant Or RegexOptions.Compiled)
@@ -34,12 +36,12 @@ Namespace Flux.Greaseweazle
3436
End If
3537

3638
Dim info As New TrackRange With {
37-
.Action = Match.Groups("action").Value,
38-
.TrackStart = GetInt(Match, "trkStart"),
39-
.TrackEnd = GetIntOrDefault(Match, "trkEnd", .TrackStart),
40-
.HeadStart = GetInt(Match, "headStart"),
41-
.HeadEnd = GetIntOrDefault(Match, "headEnd", .HeadStart)
42-
}
39+
.Action = Match.Groups("action").Value,
40+
.TrackStart = GetInt(Match, "trkStart"),
41+
.TrackEnd = GetIntOrDefault(Match, "trkEnd", .TrackStart),
42+
.HeadStart = GetInt(Match, "headStart"),
43+
.HeadEnd = GetIntOrDefault(Match, "headEnd", .HeadStart)
44+
}
4345

4446
Return info
4547
End Function
@@ -128,6 +130,24 @@ Namespace Flux.Greaseweazle
128130
Return info
129131
End Function
130132

133+
Public Function ParseTrackReadOutOfRange(line As String) As TrackReadOutOfRange
134+
If String.IsNullOrWhiteSpace(line) Then
135+
Return Nothing
136+
End If
137+
138+
Dim Match = RegExTrackReadOutOfRange.Match(line)
139+
If Not Match.Success Then
140+
Return Nothing
141+
End If
142+
143+
Dim info As New TrackReadOutOfRange With {
144+
.Format = Match.Groups("format").Value,
145+
.FluxCount = GetInt(Match, "fluxCount"),
146+
.FluxTimeMs = GetDouble(Match, "fluxTimeMS")
147+
}
148+
Return info
149+
End Function
150+
131151
Public Function ParseTrackUnexpected(line As String) As UnexpectedSector
132152
If String.IsNullOrWhiteSpace(line) Then
133153
Return Nothing
@@ -227,6 +247,13 @@ Namespace Flux.Greaseweazle
227247
Public Property TrackStart As Integer = 0
228248
End Class
229249

250+
Public Class TrackReadOutOfRange
251+
Public Property FluxCount As Integer
252+
Public Property FluxTimeMs As Double
253+
Public Property Format As String
254+
255+
End Class
256+
230257
Public Class TrackReadDetails
231258
Public ReadOnly Property BadSectors As Integer
232259
Get

DiskImageTool/Flux/Greaseweazle/Enums.vb

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ Namespace Flux.Greaseweazle
1616
IBM_2880
1717
End Enum
1818

19-
Public Enum GreaseweazleOutputType
19+
Public Enum ImageImportOutputTypes
2020
IMA
2121
HFE
2222
End Enum
2323

24+
Public Enum ReadDiskOutputTypes
25+
IMA
26+
HFE
27+
RAW
28+
End Enum
29+
2430
Public Function GreaseweazleFindCompatibleFloppyType(DiskParams As FloppyDiskParams, AvailableTypes As FloppyMediaType) As FloppyMediaType
2531
Dim Result As FloppyMediaType = FloppyMediaType.MediaUnknown
2632

@@ -148,26 +154,52 @@ Namespace Flux.Greaseweazle
148154
End Select
149155
End Function
150156

151-
Public Function GreaseweazleOutputTypeDescription(Value As GreaseweazleOutputType) As String
157+
Public Function ImageImportOutputTypeFileExt(Value As ImageImportOutputTypes) As String
152158
Select Case Value
153-
Case GreaseweazleOutputType.HFE
154-
Return "HxC HFE Image"
155-
Case GreaseweazleOutputType.IMA
156-
Return "Basic Sector Image"
159+
Case ImageImportOutputTypes.HFE
160+
Return ".hfe"
161+
Case ImageImportOutputTypes.IMA
162+
Return ".ima"
157163
Case Else
158-
Return ""
164+
Return ".ima"
159165
End Select
160166
End Function
161167

162-
Public Function GreaseweazleOutputTypeFileExt(Value As GreaseweazleOutputType) As String
168+
Public Function ReadDisktOutputTypeFileExt(Value As ReadDiskOutputTypes) As String
163169
Select Case Value
164-
Case GreaseweazleOutputType.HFE
170+
Case ImageImportOutputTypes.HFE
165171
Return ".hfe"
166-
Case GreaseweazleOutputType.IMA
172+
Case ImageImportOutputTypes.IMA
167173
Return ".ima"
174+
Case ReadDiskOutputTypes.RAW
175+
Return ".raw"
168176
Case Else
169177
Return ".ima"
170178
End Select
171179
End Function
180+
181+
Public Function ImageImportOutputTypeDescription(Value As ImageImportOutputTypes) As String
182+
Select Case Value
183+
Case ImageImportOutputTypes.HFE
184+
Return "HxC HFE Image"
185+
Case ImageImportOutputTypes.IMA
186+
Return "Basic Sector Image"
187+
Case Else
188+
Return ""
189+
End Select
190+
End Function
191+
192+
Public Function ReadDiskOutputTypeDescription(Value As ReadDiskOutputTypes) As String
193+
Select Case Value
194+
Case ReadDiskOutputTypes.HFE
195+
Return "HxC HFE Image"
196+
Case ReadDiskOutputTypes.IMA
197+
Return "Basic Sector Image"
198+
Case ReadDiskOutputTypes.RAW
199+
Return "Raw Flux Set"
200+
Case Else
201+
Return ""
202+
End Select
203+
End Function
172204
End Module
173205
End Namespace

DiskImageTool/Flux/Greaseweazle/Forms/CleanDiskForm.vb

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Namespace Flux.Greaseweazle
77
Private WithEvents ButtonReset As Button
88
Private WithEvents ComboImageDrives As ComboBox
99
Private ReadOnly _Initialized As Boolean = False
10-
Private _ProcessRunning As Boolean = False
1110
Private NumericCyls As NumericUpDown
1211
Private NumericLinger As NumericUpDown
1312
Private NumericPasses As NumericUpDown
@@ -49,7 +48,6 @@ Namespace Flux.Greaseweazle
4948

5049
Dim Arguments = Builder.Arguments
5150

52-
ToggleProcessRunning(True)
5351
Process.StartAsyncRaw(Settings.AppPath, Arguments)
5452
End Sub
5553

@@ -184,51 +182,38 @@ Namespace Flux.Greaseweazle
184182

185183
Private Sub RefreshButtonState()
186184
Dim Opt As DriveOption = ComboImageDrives.SelectedValue
185+
Dim IsRunning As Boolean = Process.IsRunning
186+
Dim IsIdle As Boolean = Not IsRunning
187187

188-
ComboImageDrives.Enabled = Not _ProcessRunning
189-
NumericPasses.Enabled = Not _ProcessRunning
190-
NumericLinger.Enabled = Not _ProcessRunning
191-
NumericCyls.Enabled = Not _ProcessRunning
192-
193-
If _ProcessRunning Then
194-
ButtonProcess.Text = My.Resources.Label_Abort
195-
Else
196-
ButtonProcess.Text = My.Resources.Label_Clean
197-
End If
198-
199-
ButtonSaveLog.Enabled = Not _ProcessRunning AndAlso TextBoxConsole.Text.Length > 0
188+
ComboImageDrives.Enabled = IsIdle
189+
NumericPasses.Enabled = IsIdle
190+
NumericLinger.Enabled = IsIdle
191+
NumericCyls.Enabled = IsIdle
200192

193+
ButtonProcess.Text = If(IsRunning, My.Resources.Label_Abort, My.Resources.Label_Clean)
201194
ButtonProcess.Enabled = Opt.Id <> ""
202195

203-
ButtonReset.Enabled = Not _ProcessRunning
196+
ButtonSaveLog.Enabled = IsIdle AndAlso TextBoxConsole.Text.Length > 0
197+
198+
ButtonReset.Enabled = IsIdle
204199
End Sub
205200

206201
Private Sub RefreshCylinderCount()
207202
Dim Opt As DriveOption = ComboImageDrives.SelectedValue
208203

209-
Dim MaxTrackCount As UShort
210-
211-
Select Case Opt.Type
212-
Case FloppyMediaType.Media525DoubleDensity
213-
MaxTrackCount = 40
214-
Case Else
215-
MaxTrackCount = 80
216-
End Select
204+
Dim MaxTrackCount As UShort = IIf(Opt.Type = FloppyMediaType.Media525DoubleDensity, 40, 80)
217205

218206
If NumericCyls.Maximum <> MaxTrackCount Then
219207
NumericCyls.Maximum = MaxTrackCount
220208
NumericCyls.Value = MaxTrackCount
221209
End If
222210
End Sub
211+
223212
Private Sub ResetState()
224213
ClearStatusBar()
225214
TextBoxConsole.Clear()
226215
End Sub
227-
Private Sub ToggleProcessRunning(Value As Boolean)
228-
_ProcessRunning = Value
229216

230-
RefreshButtonState()
231-
End Sub
232217
#Region "Events"
233218
Private Sub ButtonProcess_Click(sender As Object, e As EventArgs) Handles ButtonProcess.Click
234219
If CancelProcessIfRunning() Then
@@ -257,16 +242,12 @@ Namespace Flux.Greaseweazle
257242
RefreshCylinderCount()
258243
End Sub
259244

260-
Private Sub Process_ErrorDataReceived(data As String) Handles Process.ErrorDataReceived
245+
Private Sub Process_DataReceived(data As String) Handles Process.ErrorDataReceived, Process.OutputDataReceived
261246
TextBoxConsole.AppendText(data)
262247
End Sub
263248

264-
Private Sub Process_ProcessExited(exitCode As Integer) Handles Process.ProcessExited
265-
ToggleProcessRunning(False)
266-
End Sub
267-
268-
Private Sub Process_ProcessFailed(message As String, ex As Exception) Handles Process.ProcessFailed
269-
ToggleProcessRunning(False)
249+
Private Sub Process_ProcessStateChanged(State As ConsoleProcessRunner.ProcessStateEnum) Handles Process.ProcessStateChanged
250+
RefreshButtonState()
270251
End Sub
271252
#End Region
272253
End Class

0 commit comments

Comments
 (0)