Skip to content

Commit 6ad4391

Browse files
committed
Enhance metadata handling, error reporting, and file I/O
- Add FileIO module for robust, centralized file operations with error handling - Improve image preview: safer file reads, better error messages, always dispose dialogs - FloppyDB: support multiple entries per MD5, new fields (serial, int, fixed), improved XML parsing, and new helper methods for displaying lists - Summary panel: show all matching names/publishers/years, wrap language field - Localize and clarify error messages for preview/format detection - Refactor and simplify save logic in MainForm - Fix MD5 bug in image preview and typo in AddTitle - Remove unused temp file image functions - General code cleanup and style improvements
1 parent b8af1f7 commit 6ad4391

19 files changed

+562
-246
lines changed

DiskImageTool/DiskImageTool.vbproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
<SubType>Form</SubType>
199199
</Compile>
200200
<Compile Include="Modules\Dialogs.vb" />
201+
<Compile Include="Modules\FileIO.vb" />
201202
<Compile Include="Scanners\FilterScanner.vb" />
202203
<Compile Include="Filters\Enums.vb" />
203204
<Compile Include="Filters\FilterCounts.vb" />

DiskImageTool/Extensions/ListViewExtensions.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Module ListViewExtensions
7575
Else
7676
CalcWidth = listViewControl.Columns.Item(1).Width - 6
7777
End If
78-
If TextRenderer.MeasureText(Value, listViewControl.Font).Width > CalcWidth Then
78+
If TextRenderer.MeasureText(Value, listViewControl.Font).Width > CalcWidth OrElse Value.Contains(vbNewLine) Then
7979
StringList = Value.WordWrap(CalcWidth, listViewControl.Font)
8080
AddTags = True
8181
End If

DiskImageTool/Extensions/StringExtensions.vb

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,45 @@
33
Module StringExtensions
44
<Extension()>
55
Public Function WordWrap(Text As String, Width As Integer, Font As Font) As List(Of String)
6-
Dim StringList As New List(Of String)
7-
Dim Size = TextRenderer.MeasureText(Text, Font)
6+
Dim Result As New List(Of String)
87

9-
If String.IsNullOrEmpty(Text) OrElse Width = 0 OrElse Width >= Size.Width Then
10-
StringList.Add(Text)
11-
Return StringList
8+
If String.IsNullOrEmpty(Text) OrElse Width <= 0 Then
9+
Result.Add(Text)
10+
Return Result
1211
End If
1312

14-
Dim Words = Text.Split(" ")
15-
Dim Line As String = ""
16-
For Each Word In Words
17-
Dim NewLine = Line
18-
If NewLine <> "" Then
19-
NewLine &= " "
13+
' Normalize newlines and split into logical lines
14+
Dim Lines = Text.Replace(vbCrLf, vbLf).Replace(vbCr, vbLf).Split(vbLf)
15+
16+
For Each LogicalLine In Lines
17+
' Preserve blank lines
18+
If LogicalLine = "" Then
19+
Result.Add("")
20+
Continue For
2021
End If
21-
NewLine &= Word
22-
Size = TextRenderer.MeasureText(NewLine, Font)
23-
24-
If Size.Width <= Width Then
25-
Line = NewLine
26-
Else
27-
StringList.Add(Line)
28-
Line = Word
22+
23+
Dim Words = LogicalLine.Split(" ")
24+
Dim Line As String = ""
25+
26+
For Each Word In Words
27+
Dim NewLine = If(Line = "", Word, Line & " " & Word)
28+
Dim Size = TextRenderer.MeasureText(NewLine, Font)
29+
30+
If Size.Width <= Width Then
31+
Line = NewLine
32+
Else
33+
If Line <> "" Then
34+
Result.Add(Line)
35+
End If
36+
Line = Word
37+
End If
38+
Next
39+
40+
If Line <> "" Then
41+
Result.Add(Line)
2942
End If
3043
Next
31-
If Line <> "" Then
32-
StringList.Add(Line)
33-
End If
3444

35-
Return StringList
45+
Return Result
3646
End Function
3747
End Module

DiskImageTool/Filters/ImageFilters.vb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,22 +206,23 @@ Namespace Filters
206206

207207
If _TitleDB.TitleCount > 0 Then
208208
TitleFindResult = _TitleDB.TitleFind(Disk)
209-
If TitleFindResult.TitleData IsNot Nothing Then
209+
Dim TitleData = TitleFindResult.Primary
210+
If TitleData IsNot Nothing Then
210211
Image_NotInDatabase = False
211212
Image_InDatabase = True
212-
If TitleFindResult.TitleData.GetStatus = FloppyDB.FloppyDBStatus.Verified Then
213+
If TitleData.GetStatus = FloppyDB.FloppyDBStatus.Verified Then
213214
Image_Verified = True
214215
Else
215216
Image_Unverified = True
216217
End If
217218
If App.Globals.AppSettings.Debug Then
218-
If TitleFindResult.TitleData.GetIsTDC Then
219+
If TitleData.GetIsTDC Then
219220
Image_InTDC = True
220221
Else
221222
Image_NotInTDC = True
222223
End If
223224
FileData = New FloppyDB.FileNameData(ImageData.FileName)
224-
If TitleFindResult.TitleData.GetStatus <> FileData.Status Then
225+
If TitleData.GetStatus <> FileData.Status Then
225226
Database_MismatchedStatus = True
226227
End If
227228
End If
@@ -272,7 +273,7 @@ Namespace Filters
272273
FileData = New FloppyDB.FileNameData(ImageData.FileName)
273274
End If
274275
Dim Media = FloppyDiskFormatGetName(Disk.BPB, True)
275-
_TitleDB.AddTile(FileData, Media, TitleFindResult.MD5)
276+
_TitleDB.AddTitle(FileData, Media, TitleFindResult.MD5)
276277
End If
277278
End If
278279
End If

DiskImageTool/Flux/Forms/ConvertImageForm.vb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,17 +1104,15 @@ Namespace Flux
11041104
Exit Sub
11051105
End If
11061106

1107+
Dim Caption As String = TextBoxFileName.Text
1108+
11071109
Dim HasSelectedOutputFile As Boolean = _OutputImages.Images.ContainsKey(_SelectedDevice.Device)
11081110

11091111
If HasSelectedOutputFile Then
11101112
Dim ImageInfo = _OutputImages.Images(_SelectedDevice.Device)
11111113
Dim ImageData = New ImageData(ImageInfo.FilePath)
11121114

1113-
Dim Caption As String = TextBoxFileName.Text
1114-
1115-
If Not ImagePreview.Display(ImageData, Caption, Me) Then
1116-
MsgBox(My.Resources.Dialog_ImagePreviewFail, MsgBoxStyle.Exclamation)
1117-
End If
1115+
ImagePreview.Display(ImageData, Caption, Me)
11181116
Else
11191117
If Not _SelectedDevice.SupportsPreview Then
11201118
Exit Sub
@@ -1130,12 +1128,8 @@ Namespace Flux
11301128

11311129
If Not Response.Result Then
11321130
MsgBox(My.Resources.Dialog_ImagePreviewFail, MsgBoxStyle.Exclamation)
1133-
End If
1134-
1135-
Dim Caption As String = TextBoxFileName.Text
1136-
1137-
If Not ImagePreview.Display(Response.Filename, DiskParams.Value, Caption, Me) Then
1138-
MsgBox(My.Resources.Dialog_ImagePreviewFail, MsgBoxStyle.Exclamation)
1131+
Else
1132+
ImagePreview.Display(Response.Filename, DiskParams.Value, Caption, Me)
11391133
End If
11401134

11411135
DeleteTempFileIfExists(Response.Filename)

DiskImageTool/Flux/Greaseweazle/Forms/ReadDiskForm.vb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -771,17 +771,15 @@ Namespace Flux.Greaseweazle
771771
End Sub
772772

773773
Private Sub PreviewImage()
774+
Dim Caption As String = TextBoxFileName.Text
775+
774776
Dim HasOutputfile As Boolean = Not String.IsNullOrEmpty(_OutputFilePath)
775777
Dim IsFluxOutput = CheckIsFluxOutput()
776778

777779
If HasOutputfile AndAlso Not IsFluxOutput Then
778780
Dim ImageData = New ImageData(_OutputFilePath)
779781

780-
Dim Caption As String = TextBoxFileName.Text
781-
782-
If Not ImagePreview.Display(ImageData, Caption, Me) Then
783-
MsgBox(My.Resources.Dialog_ImagePreviewFail, MsgBoxStyle.Exclamation)
784-
End If
782+
ImagePreview.Display(ImageData, Caption, Me)
785783
Else
786784
Dim DiskParams = SelectedDiskParams()
787785
Dim Opt As DriveOption = _SelectedOption
@@ -794,12 +792,8 @@ Namespace Flux.Greaseweazle
794792

795793
If Not Response.Result Then
796794
MsgBox(My.Resources.Dialog_ImagePreviewFail, MsgBoxStyle.Exclamation)
797-
End If
798-
799-
Dim Caption As String = TextBoxFileName.Text
800-
801-
If Not ImagePreview.Display(Response.FileName, DiskParams.Value, Caption, Me) Then
802-
MsgBox(My.Resources.Dialog_ImagePreviewFail, MsgBoxStyle.Exclamation)
795+
Else
796+
ImagePreview.Display(Response.FileName, DiskParams.Value, Caption, Me)
803797
End If
804798

805799
DeleteTempFileIfExists(Response.FileName)

DiskImageTool/Flux/Greaseweazle/GreaseweazleLib.vb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ Namespace Flux.Greaseweazle
194194
End If
195195

196196
Dim Builder As New CommandLineBuilder(CommandLineBuilder.CommandAction.convert) With {
197-
.InFile = FilePath,
198-
.OutFile = FileName,
199-
.Format = Format,
200-
.Heads = If(BothSides, TrackHeads.both, TrackHeads.head0)
201-
}
197+
.InFile = FilePath,
198+
.OutFile = FileName,
199+
.Format = Format,
200+
.Heads = If(BothSides, TrackHeads.both, TrackHeads.head0)
201+
}
202202
Builder.AddCylinder(0)
203203

204204
ConsoleProcessRunner.RunProcess(Settings.AppPath, Builder.Arguments)
@@ -330,12 +330,12 @@ Namespace Flux.Greaseweazle
330330
End If
331331

332332
Dim Builder As New CommandLineBuilder(CommandLineBuilder.CommandAction.read) With {
333-
.Device = Settings.ComPort,
334-
.Drive = DriveId,
335-
.File = FileName,
336-
.Format = Format,
337-
.Heads = If(BothSides, TrackHeads.both, TrackHeads.head0)
338-
}
333+
.Device = Settings.ComPort,
334+
.Drive = DriveId,
335+
.File = FileName,
336+
.Format = Format,
337+
.Heads = If(BothSides, TrackHeads.both, TrackHeads.head0)
338+
}
339339
Builder.AddCylinder(0)
340340

341341
Dim Result = ConsoleProcessRunner.RunProcess(Settings.AppPath, Builder.Arguments)

DiskImageTool/Flux/SharedLib.vb

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,25 @@ Namespace Flux
150150
Dim Length As Integer = 513
151151
Dim DetectedFormat As FloppyDiskFormat
152152

153-
Using fs As New IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
154-
Using br As New IO.BinaryReader(fs, System.Text.Encoding.ASCII, leaveOpen:=False)
155-
Buffer = br.ReadBytes(Length)
156-
DetectedFormat = FloppyDiskFormatGet(Buffer)
157-
If DetectedFormat = FloppyDiskFormat.FloppyXDFMicro Then
158-
If fs.Length >= SecondOffset + Length Then
159-
fs.Seek(SecondOffset, IO.SeekOrigin.Begin)
160-
Buffer = br.ReadBytes(513)
161-
DetectedFormat = FloppyDiskFormatGet(Buffer)
153+
Try
154+
Using fs As New IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
155+
Using br As New IO.BinaryReader(fs, System.Text.Encoding.ASCII, leaveOpen:=False)
156+
Buffer = br.ReadBytes(Length)
157+
DetectedFormat = FloppyDiskFormatGet(Buffer)
158+
If DetectedFormat = FloppyDiskFormat.FloppyXDFMicro Then
159+
If fs.Length >= SecondOffset + Length Then
160+
fs.Seek(SecondOffset, IO.SeekOrigin.Begin)
161+
Buffer = br.ReadBytes(513)
162+
DetectedFormat = FloppyDiskFormatGet(Buffer)
163+
End If
162164
End If
163-
End If
165+
End Using
164166
End Using
165-
End Using
167+
Catch ex As Exception
168+
Dim Msg = My.Resources.Dialog_DetectFormatError & vbNewLine & vbNewLine & ex.Message
169+
MsgBox(Msg, MsgBoxStyle.Critical)
170+
DetectedFormat = FloppyDiskFormat.FloppyUnknown
171+
End Try
166172

167173
If DeleteWhenDone Then
168174
DeleteTempFileIfExists(FileName)

DiskImageTool/Forms/ImagePreview.vb

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
Dim MD5 As String = ""
2323
If FullDisplay Then
24-
MD5 = CurrentImage.Disk.Image.GetMD5Hash
24+
MD5 = _Disk.Image.GetMD5Hash
2525
Else
2626
Me.Width = Me.MinimumSize.Width
2727
End If
@@ -33,12 +33,21 @@
3333

3434
_SummaryPanel.Populate(CurrentImage, App.BootstrapDB, App.TitleDB, MD5, Not FullDisplay)
3535
If FullDisplay Then
36-
HashPanel1.Populate(Disk, MD5)
36+
HashPanel1.Populate(_Disk, MD5)
3737
End If
3838
FilePanelMain.Load(CurrentImage, False, FullDisplay)
3939
End Sub
4040

4141
Public Shared Function Display(FileName As String, ImageParams As DiskImage.FloppyDiskParams, Caption As String, owner As IWin32Window) As Boolean
42+
Dim OpenResponse = FileOpenBinary(FileName)
43+
44+
If Not OpenResponse.Result Then
45+
Dim Msg = My.Resources.Dialog_ImagePreviewFail & vbNewLine & vbNewLine & OpenResponse.ErrorMsg
46+
MsgBox(Msg, MsgBoxStyle.Exclamation)
47+
48+
Return False
49+
End If
50+
4251
Try
4352
Dim Size = ImageParams.BPBParams.SizeInBytes
4453

@@ -48,37 +57,38 @@
4857
Buffer(i) = &HF6
4958
Next
5059

51-
Dim FileBytes = IO.File.ReadAllBytes(FileName)
52-
53-
Dim ToCopy As Integer = Math.Min(FileBytes.Length, Buffer.Length)
54-
Array.Copy(FileBytes, 0, Buffer, 0, ToCopy)
60+
Dim ToCopy As Integer = Math.Min(OpenResponse.Data.Length, Buffer.Length)
61+
Array.Copy(OpenResponse.Data, 0, Buffer, 0, ToCopy)
5562

5663
Dim FloppyImage As New DiskImage.BasicSectorImage(Buffer)
5764
Dim Disk As New DiskImage.Disk(FloppyImage, 0)
5865

5966
Display(Disk, False, Caption, owner)
6067
Catch ex As Exception
68+
MsgBox(My.Resources.Dialog_ImagePreviewFail, MsgBoxStyle.Exclamation)
69+
6170
Return False
6271
End Try
6372

6473
Return True
6574
End Function
6675

6776
Public Shared Function Display(ImageData As ImageData, Caption As String, owner As IWin32Window) As Boolean
68-
Try
69-
Dim Disk = DiskImageLoadFromImageData(ImageData)
77+
Dim Disk = DiskImageLoadFromImageData(ImageData)
7078

71-
Display(Disk, True, Caption, owner)
72-
Catch ex As Exception
79+
If Disk Is Nothing Then
80+
MsgBox(My.Resources.Dialog_ImagePreviewFail, MsgBoxStyle.Exclamation)
7381
Return False
74-
End Try
82+
End If
83+
84+
Display(Disk, True, Caption, owner)
7585

7686
Return True
7787
End Function
7888

7989
Public Shared Sub Display(Disk As DiskImage.Disk, FullDisplay As Boolean, Caption As String, owner As IWin32Window)
80-
With New ImagePreview(Disk, FullDisplay, Caption)
81-
.ShowDialog(owner)
82-
End With
90+
Using Dialog As New ImagePreview(Disk, FullDisplay, Caption)
91+
Dialog.ShowDialog(owner)
92+
End Using
8393
End Sub
8494
End Class

0 commit comments

Comments
 (0)