@@ -87,7 +87,7 @@ Namespace DiskImage
8787 End Function
8888
8989 Public Function BuildBootSectorFromType(Type As FloppyDiskType) As BootSector
90- Dim Data( 511 ) As Byte
90+ Dim Data(DiskImage.BootSector.BOOT_SECTOR_SIZE - 1 ) As Byte
9191 Dim FileBytes As New ImageByteArray(Data)
9292 Dim BootSector = New BootSector(FileBytes)
9393
@@ -395,27 +395,88 @@ Namespace DiskImage
395395 Return Content
396396 End Function
397397
398- Public Function GetDirectoryEntryCount(FileBytes As ByteArray, OffsetStart As UInteger, OffsetEnd As UInteger, FileCountOnly As Boolean , ExcludeDeleted As Boolean ) As UInteger
399- Dim Count As UInteger = 0
400-
401- Do While FileBytes.GetByte(OffsetStart) > 0
402- If Not ExcludeDeleted OrElse FileBytes.GetByte(OffsetStart) <> &HE5 Then
403- If Not FileCountOnly Then
404- Count += 1
405- ElseIf FileBytes.GetByte(OffsetStart + 11 ) <> &HF Then 'Exclude LFN entries
406- Dim FilePart = FileBytes.ToUInt16(OffsetStart)
407- If FilePart <> &H202E And FilePart <> &H2E2E Then 'Exclude '.' and '..' entries
408- Count += 1
409- End If
398+ Public Function DirectoryEntryHasData(FileBytes As ByteArray, Offset As UInteger) As Boolean
399+ Dim Result As Boolean = False
400+
401+
402+ If FileBytes.GetByte(Offset) = &HE5 Then
403+ For Offset2 As UInteger = Offset + 1 To Offset + DirectoryEntry.DIRECTORY_ENTRY_SIZE - 1
404+ If FileBytes.GetByte(Offset2) <> 0 Then
405+ Result = True
406+ Exit For
407+ End If
408+ Next
409+ ElseIf FileBytes.GetByte(Offset) <> 0 Then
410+ Result = True
411+ Else
412+ Dim HexF6Count As UInteger = 0
413+ For Offset2 As UInteger = Offset + 1 To Offset + DirectoryEntry.DIRECTORY_ENTRY_SIZE - 1
414+ If FileBytes.GetByte(Offset2) = &HF6 Then
415+ HexF6Count += 1
416+ ElseIf FileBytes.GetByte(Offset2) <> 0 Then
417+ Result = True
418+ Exit For
419+ End If
420+ Next
421+ If Not Result Then
422+ If HexF6Count > 0 And HexF6Count < DirectoryEntry.DIRECTORY_ENTRY_SIZE - 2 Then
423+ Result = True
410424 End If
411425 End If
412- OffsetStart += 32
413- If OffsetEnd > 0 And OffsetStart >= OffsetEnd Then
414- Exit Do
415- End If
416- Loop
426+ End If
427+
428+ Return Result
429+ End Function
430+
431+ Public Function GetDirectoryData(Data As DirectoryData, FileBytes As ByteArray, OffsetStart As UInteger, OffsetEnd As UInteger, EndOfDirectory As Boolean , CheckBootSector As Boolean ) As Boolean
432+ Dim EntryCount = (OffsetEnd - OffsetStart) \ DirectoryEntry.DIRECTORY_ENTRY_SIZE
433+
434+ Data.MaxEntries += EntryCount
435+
436+ If EntryCount > 0 Then
437+ For Entry As UInteger = 0 To EntryCount - 1
438+ Dim Offset = OffsetStart + (Entry * DirectoryEntry.DIRECTORY_ENTRY_SIZE)
439+ Dim FirstByte = FileBytes.GetByte(Offset)
440+ If FirstByte = 0 Then
441+ EndOfDirectory = True
442+ End If
443+ If Not Data.HasBootSector And CheckBootSector Then
444+ If BootSector.ValidJumpInstructuon.Contains(FirstByte) Then
445+ If OffsetEnd - Offset >= BootSector.BOOT_SECTOR_SIZE Then
446+ Dim BootSectorData = FileBytes.GetBytes(Offset, DiskImage.BootSector.BOOT_SECTOR_SIZE)
447+ Dim BootSector = New BootSector( New ImageByteArray(BootSectorData))
448+ If BootSector.IsValidImage Then
449+ Data.HasBootSector = True
450+ Data.BootSectorOffset = Offset
451+ EndOfDirectory = True
452+ End If
453+ End If
454+ End If
455+ End If
456+ If EndOfDirectory Then
457+ If Not Data.HasAdditionalData Then
458+ If Not Data.HasBootSector Or Offset < Data.BootSectorOffset Or Offset > Data.BootSectorOffset + DiskImage.BootSector.BOOT_SECTOR_SIZE Then
459+ If DirectoryEntryHasData(FileBytes, Offset) Then
460+ Data.HasAdditionalData = True
461+ End If
462+ End If
463+ End If
464+ Else
465+ Data.EntryCount += 1
466+ If FileBytes.GetByte(Offset + 11 ) <> &HF Then 'Exclude LFN entries
467+ Dim FilePart = FileBytes.ToUInt16(Offset)
468+ If FilePart <> &H202E And FilePart <> &H2E2E Then 'Exclude '.' and '..' entries
469+ Data.FileCount += 1
470+ If FirstByte = DirectoryEntry.CHAR_DELETED Then
471+ Data.DeletedFileCount += 1
472+ End If
473+ End If
474+ End If
475+ End If
476+ Next
477+ End If
417478
418- Return Count
479+ Return EndOfDirectory
419480 End Function
420481
421482 Public Function GetObjectSize(o As Object ) As Integer
0 commit comments