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