Skip to content

Commit a9c8006

Browse files
committed
Refactor device capability handling and extensibility
Refactored `FluxDeviceInfo` to use a new `FlucDeviceFeatures` structure, replacing `AllowSCP` and `AllowHFE` with extensible lists for valid input and output types. Introduced `FluxDeviceGetFeatures` to centralize device feature definitions. Updated capability checks across the codebase to use the new `Features` property, improving consistency and reducing redundancy. Enhanced file extension handling to dynamically determine valid extensions based on output types.
1 parent 2d35ca1 commit a9c8006

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

DiskImageTool/Flux/Enums.vb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
head1
3232
both
3333
End Enum
34+
3435
Public Function ImageImportOutputTypeDescription(Value As ImageImportOutputTypes) As String
3536
Select Case Value
3637
Case ImageImportOutputTypes.HFE

DiskImageTool/Flux/Forms/ConvertImageForm.vb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ Namespace Flux
105105

106106
Private Function CanAcceptDrop(paths As IEnumerable(Of String)) As Boolean
107107
Dim SelectedDevice As FluxDeviceInfo = CType(ComboDevices.SelectedItem, FluxDeviceInfo)
108+
Dim AllowSCP As Boolean = SelectedDevice.Features.ImportValidInputTypes.Contains(InputFileTypeEnum.scp)
108109

109110
For Each path In paths
110-
If IsValidFluxImport(path, SelectedDevice.AllowSCP).Result Then
111+
If IsValidFluxImport(path, AllowSCP).Result Then
111112
Return True
112113
End If
113114

@@ -418,8 +419,9 @@ Namespace Flux
418419

419420
Private Function OpenFluxImage(Filename As String) As Boolean
420421
Dim SelectedDevice As FluxDeviceInfo = CType(ComboDevices.SelectedItem, FluxDeviceInfo)
422+
Dim AllowSCP As Boolean = SelectedDevice.Features.ImportValidInputTypes.Contains(InputFileTypeEnum.scp)
421423

422-
Dim response = AnalyzeFluxImage(Filename, SelectedDevice.AllowSCP)
424+
Dim response = AnalyzeFluxImage(Filename, AllowSCP)
423425
If response.Result Then
424426
_TrackCount = response.TrackCount
425427
_SideCount = response.SideCount
@@ -433,7 +435,9 @@ Namespace Flux
433435

434436
Private Function OpenFluxImage() As Boolean
435437
Dim SelectedDevice As FluxDeviceInfo = CType(ComboDevices.SelectedItem, FluxDeviceInfo)
436-
Dim FileName As String = SharedLib.OpenFluxImage(Me, SelectedDevice.AllowSCP)
438+
Dim AllowSCP As Boolean = SelectedDevice.Features.ImportValidInputTypes.Contains(InputFileTypeEnum.scp)
439+
440+
Dim FileName As String = SharedLib.OpenFluxImage(Me, AllowSCP)
437441

438442
If FileName <> "" Then
439443
Return OpenFluxImage(FileName)
@@ -479,11 +483,12 @@ Namespace Flux
479483
_ComboExtensionsNoEvent = True
480484

481485
Dim OutputType As ImageImportOutputTypes = ComboOutputType.SelectedValue
482-
Dim hfeOnly = OutputType = ImageImportOutputTypes.HFE AndAlso _SelectedDevice.AllowHFE
483486

484-
If hfeOnly Then
487+
If OutputType <> ImageImportOutputTypes.IMA Then
488+
Dim Extension = ImageImportOutputTypeFileExt(OutputType)
489+
485490
Dim items As New List(Of FileExtensionItem) From {
486-
New FileExtensionItem(".hfe", Nothing)
491+
New FileExtensionItem(Extension, Nothing)
487492
}
488493

489494
With ComboExtensions
@@ -515,11 +520,7 @@ Namespace Flux
515520
Dim UseSectorImage As Boolean = AllowSectorImage()
516521

517522
For Each OutputType As ImageImportOutputTypes In [Enum].GetValues(GetType(ImageImportOutputTypes))
518-
If OutputType = ImageImportOutputTypes.IMA AndAlso Not UseSectorImage AndAlso _SelectedDevice.AllowHFE Then
519-
Continue For
520-
End If
521-
522-
If OutputType = ImageImportOutputTypes.HFE AndAlso Not _SelectedDevice.AllowHFE Then
523+
If Not _SelectedDevice.Features.ImportValidOutputTypes.Contains(OutputType) Then
523524
Continue For
524525
End If
525526

@@ -783,7 +784,9 @@ Namespace Flux
783784

784785
Private Sub ImageImportForm_DragDrop(sender As Object, e As DragEventArgs) Handles Me.DragDrop
785786
Dim SelectedDevice As FluxDeviceInfo = CType(ComboDevices.SelectedItem, FluxDeviceInfo)
787+
Dim AllowSCP As Boolean = SelectedDevice.Features.ImportValidInputTypes.Contains(InputFileTypeEnum.scp)
786788
Dim HasOutputfile As Boolean = Not String.IsNullOrEmpty(_OutputFilePath)
789+
787790
If Process.IsRunning Or HasOutputfile Then
788791
Return
789792
End If
@@ -799,7 +802,7 @@ Namespace Flux
799802

800803
Dim firstPath = paths(0)
801804

802-
Dim Response = IsValidFluxImport(firstPath, SelectedDevice.AllowSCP)
805+
Dim Response = IsValidFluxImport(firstPath, AllowSCP)
803806
If Response.Result Then
804807
If OpenFluxImage(Response.File) Then
805808
InitializeDevice(True)

DiskImageTool/Flux/SharedLib.vb

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,39 @@ Namespace Flux
149149
Return DetectedFormat
150150
End Function
151151

152+
Private Function FluxDeviceGetFeatures(Device As FluxDevice) As FlucDeviceFeatures
153+
154+
Dim features As New FlucDeviceFeatures With {
155+
.ImportValidInputTypes = New List(Of InputFileTypeEnum),
156+
.ImportValidOutputTypes = New List(Of ImageImportOutputTypes)
157+
}
158+
159+
Select Case Device
160+
Case FluxDevice.Greaseweazle
161+
features.ImportValidInputTypes.Add(InputFileTypeEnum.scp)
162+
features.ImportValidInputTypes.Add(InputFileTypeEnum.raw)
163+
164+
features.ImportValidOutputTypes.Add(ImageImportOutputTypes.IMA)
165+
features.ImportValidOutputTypes.Add(ImageImportOutputTypes.HFE)
166+
167+
Case FluxDevice.Kryoflux
168+
features.ImportValidInputTypes.Add(InputFileTypeEnum.raw)
169+
170+
features.ImportValidOutputTypes.Add(ImageImportOutputTypes.IMA)
171+
End Select
172+
173+
Return features
174+
End Function
175+
152176
Public Function FluxDeviceGetInfo(Device As FluxDevice) As FluxDeviceInfo?
177+
Dim Features = FluxDeviceGetFeatures(Device)
178+
153179
Select Case Device
154180
Case FluxDevice.Greaseweazle
155-
Return New FluxDeviceInfo(Device, "Greaseweazle", True, True, App.Globals.AppSettings.Greaseweazle)
181+
Return New FluxDeviceInfo(Device, "Greaseweazle", Features, App.Globals.AppSettings.Greaseweazle)
182+
156183
Case FluxDevice.Kryoflux
157-
Return New FluxDeviceInfo(Device, "KryoFlux", False, False, App.Globals.AppSettings.Kryoflux)
184+
Return New FluxDeviceInfo(Device, "KryoFlux", Features, App.Globals.AppSettings.Kryoflux)
158185
Case Else
159186
Return Nothing
160187
End Select
@@ -173,7 +200,7 @@ Namespace Flux
173200
' Get FluxDeviceInfo
174201
Dim info = FluxDeviceGetInfo(dev)
175202
If info.HasValue Then
176-
If Not info.Value.AllowSCP And FileType = InputFileTypeEnum.scp Then
203+
If Not info.Value.Features.ImportValidInputTypes.Contains(FileType) Then
177204
Continue For
178205
End If
179206
list.Add(info.Value)
@@ -615,19 +642,22 @@ Namespace Flux
615642
End Function
616643
End Structure
617644

645+
Public Structure FlucDeviceFeatures
646+
Public Property ImportValidInputTypes As List(Of InputFileTypeEnum)
647+
Public Property ImportValidOutputTypes As List(Of ImageImportOutputTypes)
648+
End Structure
649+
618650
Public Structure FluxDeviceInfo
619-
Public Sub New(Device As FluxDevice, Name As String, AllowSCP As Boolean, AllowHFE As Boolean, Settings As ISettings)
651+
Public Sub New(Device As FluxDevice, Name As String, Features As FlucDeviceFeatures, Settings As ISettings)
620652
Me.Device = Device
621653
Me.Name = Name
622-
Me.AllowSCP = AllowSCP
623-
Me.AllowHFE = AllowHFE
654+
Me.Features = Features
624655
Me.Settings = Settings
625656
End Sub
626657

627-
ReadOnly Property AllowHFE As Boolean
628-
ReadOnly Property AllowSCP As Boolean
629658
ReadOnly Property Device As FluxDevice
630659
ReadOnly Property Name As String
660+
ReadOnly Property Features As FlucDeviceFeatures
631661
ReadOnly Property Settings As ISettings
632662
End Structure
633663

0 commit comments

Comments
 (0)