Add id to directory entries

This commit is contained in:
Jordan Goulder 2025-01-20 11:16:51 -05:00
parent 18c5554211
commit 9ff9642f65

View File

@ -41,6 +41,7 @@ export interface IAttributes {
export interface IStandardDirEntry { export interface IStandardDirEntry {
type: 'standard-entry' type: 'standard-entry'
id: string
name: string name: string
basename: string basename: string
extension: string extension: string
@ -53,14 +54,17 @@ export interface IStandardDirEntry {
export interface ILongFileNameDirEntry { export interface ILongFileNameDirEntry {
type: 'long-filename-entry' type: 'long-filename-entry'
id: string
} }
export interface IFinalDirEntry { export interface IFinalDirEntry {
type: 'final-entry' type: 'final-entry'
id: string
} }
export interface IUnusedDirEntry { export interface IUnusedDirEntry {
type: 'unused-entry' type: 'unused-entry'
id: string
} }
export type TDirEntry = IStandardDirEntry | ILongFileNameDirEntry | IFinalDirEntry | IUnusedDirEntry export type TDirEntry = IStandardDirEntry | ILongFileNameDirEntry | IFinalDirEntry | IUnusedDirEntry
@ -304,13 +308,14 @@ function decodeDirectoryEntry(data: DataView, fd: FloppyDisk): TDirEntry | null
const firstByte = data.getUint8(0) const firstByte = data.getUint8(0)
const attributeByte = data.getUint8(11) const attributeByte = data.getUint8(11)
const id = crypto.randomUUID()
if (firstByte === 0) { if (firstByte === 0) {
return { type: 'final-entry' } return { type: 'final-entry', id }
} else if (firstByte === 0xe5) { } else if (firstByte === 0xe5) {
return { type: 'unused-entry' } return { type: 'unused-entry', id }
} else if (attributeByte === 0x0f) { } else if (attributeByte === 0x0f) {
return { type: 'long-filename-entry' } return { type: 'long-filename-entry', id }
} else { } else {
const asciiDecoder = new TextDecoder('ascii') const asciiDecoder = new TextDecoder('ascii')
const basename = asciiDecoder const basename = asciiDecoder
@ -338,6 +343,7 @@ function decodeDirectoryEntry(data: DataView, fd: FloppyDisk): TDirEntry | null
const entry: IStandardDirEntry = { const entry: IStandardDirEntry = {
type: 'standard-entry', type: 'standard-entry',
id,
name, name,
basename, basename,
extension, extension,