Add path to entry
This commit is contained in:
parent
c79655a467
commit
6ab6f3ee42
@ -48,6 +48,7 @@ export interface IStandardDirEntry {
|
||||
attributes: IAttributes
|
||||
size: number
|
||||
firstCluster: number
|
||||
path: string[]
|
||||
subDirEntries: TDirEntry[]
|
||||
}
|
||||
|
||||
@ -96,6 +97,7 @@ export class FloppyDisk {
|
||||
if (this.buffer.byteLength >= end) {
|
||||
this._rootDirEntries = decodeDirectoryEntries(
|
||||
new DataView(this.buffer, this.rootDirOffset, this.rootDirSize),
|
||||
[''],
|
||||
this,
|
||||
)
|
||||
}
|
||||
@ -200,7 +202,7 @@ export class FloppyDisk {
|
||||
return chain
|
||||
}
|
||||
|
||||
addDirectoryListing(listing: string, path: string[], entries: TDirEntry[]) {
|
||||
addDirectoryListing(listing: string, entries: TDirEntry[]) {
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const entry = entries[i]
|
||||
if (
|
||||
@ -212,11 +214,11 @@ export class FloppyDisk {
|
||||
continue
|
||||
}
|
||||
|
||||
listing += `${path.join('\\') + '\\'}${entry.name}`
|
||||
listing += `${entry.path.join('\\') + '\\'}${entry.name}`
|
||||
|
||||
if (entry.attributes.directory) {
|
||||
listing += '\\<br/>'
|
||||
listing = this.addDirectoryListing(listing, [...path, entry.name], entry.subDirEntries)
|
||||
listing = this.addDirectoryListing(listing, entry.subDirEntries)
|
||||
} else {
|
||||
listing += '<br/>'
|
||||
}
|
||||
@ -227,12 +229,12 @@ export class FloppyDisk {
|
||||
|
||||
buildFileListing(): string {
|
||||
let listing = '<p>\\<br/>'
|
||||
listing += this.addDirectoryListing('', [''], this.rootDirEntries ?? [])
|
||||
listing += this.addDirectoryListing('', this.rootDirEntries ?? [])
|
||||
listing += '</p>'
|
||||
return listing
|
||||
}
|
||||
|
||||
addDirectory(list: IFile[], path: string[], entries: TDirEntry[]) {
|
||||
addDirectory(list: IFile[], entries: TDirEntry[]) {
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const entry = entries[i]
|
||||
if (
|
||||
@ -247,16 +249,16 @@ export class FloppyDisk {
|
||||
if (entry.attributes.directory) {
|
||||
list.push({
|
||||
name: entry.name,
|
||||
path,
|
||||
path: entry.path,
|
||||
isDirectory: true,
|
||||
firstCuster: entry.firstCluster,
|
||||
size: 0,
|
||||
})
|
||||
this.addDirectory(list, [...path, entry.name], entry.subDirEntries)
|
||||
this.addDirectory(list, entry.subDirEntries)
|
||||
} else {
|
||||
list.push({
|
||||
name: entry.name,
|
||||
path,
|
||||
path: entry.path,
|
||||
isDirectory: false,
|
||||
firstCuster: entry.firstCluster,
|
||||
size: entry.size,
|
||||
@ -268,7 +270,7 @@ export class FloppyDisk {
|
||||
getFileList(): IFile[] {
|
||||
const list: IFile[] = []
|
||||
|
||||
this.addDirectory(list, [''], this.rootDirEntries ?? [])
|
||||
this.addDirectory(list, this.rootDirEntries ?? [])
|
||||
return list
|
||||
}
|
||||
|
||||
@ -369,7 +371,7 @@ function decodeBootSector(data: DataView): IBootSectorInfo | null {
|
||||
}
|
||||
}
|
||||
|
||||
function decodeDirectoryEntry(data: DataView, fd: FloppyDisk): TDirEntry | null {
|
||||
function decodeDirectoryEntry(data: DataView, path: string[], fd: FloppyDisk): TDirEntry | null {
|
||||
if (data.byteLength < 32) {
|
||||
return null
|
||||
}
|
||||
@ -418,6 +420,7 @@ function decodeDirectoryEntry(data: DataView, fd: FloppyDisk): TDirEntry | null
|
||||
attributes,
|
||||
firstCluster,
|
||||
size,
|
||||
path,
|
||||
subDirEntries: [],
|
||||
}
|
||||
|
||||
@ -436,7 +439,11 @@ function decodeDirectoryEntry(data: DataView, fd: FloppyDisk): TDirEntry | null
|
||||
|
||||
const resizedData = entryData.slice(0, entry.size > 0 ? entry.size : entryData.byteLength)
|
||||
|
||||
entry.subDirEntries = decodeDirectoryEntries(new DataView(resizedData.buffer), fd)
|
||||
entry.subDirEntries = decodeDirectoryEntries(
|
||||
new DataView(resizedData.buffer),
|
||||
[...path, entry.name],
|
||||
fd,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,7 +451,7 @@ function decodeDirectoryEntry(data: DataView, fd: FloppyDisk): TDirEntry | null
|
||||
}
|
||||
}
|
||||
|
||||
function decodeDirectoryEntries(data: DataView, fd: FloppyDisk): TDirEntry[] {
|
||||
function decodeDirectoryEntries(data: DataView, path: string[], fd: FloppyDisk): TDirEntry[] {
|
||||
const entries: TDirEntry[] = []
|
||||
|
||||
let offset = 0
|
||||
@ -452,7 +459,7 @@ function decodeDirectoryEntries(data: DataView, fd: FloppyDisk): TDirEntry[] {
|
||||
const dirData = new DataView(data.buffer, data.byteOffset + offset, 32)
|
||||
offset += 32
|
||||
|
||||
const entry = decodeDirectoryEntry(dirData, fd)
|
||||
const entry = decodeDirectoryEntry(dirData, path, fd)
|
||||
if (entry === null) {
|
||||
break
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user