Replace usage of IFile with IStandardDirEntry
This commit is contained in:
parent
6ab6f3ee42
commit
766dc9ec5b
@ -29,42 +29,20 @@ const currentFileName = ref<string>('')
|
|||||||
const dataView = ref('hex-dump')
|
const dataView = ref('hex-dump')
|
||||||
|
|
||||||
const directories = computed(() => {
|
const directories = computed(() => {
|
||||||
const fileList = floppyDisk?.getFileList()
|
const fileList = floppyDisk?.getFileEntryList()
|
||||||
|
|
||||||
let directories = fileList
|
return fileList
|
||||||
?.filter((file) => {
|
?.filter((file) => {
|
||||||
return file.isDirectory && arraysEqual(currentPath.value, file.path)
|
return file.attributes.directory && arraysEqual(currentPath.value, file.path)
|
||||||
})
|
})
|
||||||
.sort()
|
.sort()
|
||||||
|
|
||||||
if (directories) {
|
|
||||||
directories = [
|
|
||||||
{
|
|
||||||
name: '.',
|
|
||||||
isDirectory: true,
|
|
||||||
path: [],
|
|
||||||
firstCuster: -1,
|
|
||||||
size: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '..',
|
|
||||||
isDirectory: true,
|
|
||||||
path: [],
|
|
||||||
firstCuster: -1,
|
|
||||||
size: 0,
|
|
||||||
},
|
|
||||||
...directories,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
return directories
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const files = computed(() => {
|
const files = computed(() => {
|
||||||
const fileList = floppyDisk?.getFileList()
|
const fileList = floppyDisk?.getFileEntryList()
|
||||||
return fileList
|
return fileList
|
||||||
?.filter((file) => {
|
?.filter((file) => {
|
||||||
return !file.isDirectory && arraysEqual(currentPath.value, file.path)
|
return !file.attributes.directory && arraysEqual(currentPath.value, file.path)
|
||||||
})
|
})
|
||||||
.sort()
|
.sort()
|
||||||
})
|
})
|
||||||
@ -114,7 +92,7 @@ function loadFile(name: string, firstCluster: number, size: number) {
|
|||||||
<a
|
<a
|
||||||
:class="{ current: file.name === currentFileName }"
|
:class="{ current: file.name === currentFileName }"
|
||||||
href=""
|
href=""
|
||||||
@click.prevent="loadFile(file.name, file.firstCuster, file.size)"
|
@click.prevent="loadFile(file.name, file.firstCluster, file.size)"
|
||||||
>{{ file.name }}</a
|
>{{ file.name }}</a
|
||||||
>
|
>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue'
|
|
||||||
import { FloppyDisk } from '@/floppy/disk.ts'
|
import { FloppyDisk } from '@/floppy/disk.ts'
|
||||||
|
|
||||||
const { floppyDisk = null } = defineProps<{ floppyDisk: FloppyDisk | null }>()
|
const { floppyDisk = null } = defineProps<{ floppyDisk: FloppyDisk | null }>()
|
||||||
|
|
||||||
const fileListing = computed(() => {
|
|
||||||
return floppyDisk?.buildFileListing()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<section v-if="floppyDisk">
|
<section v-if="floppyDisk">
|
||||||
<h3>File Listing</h3>
|
<h3>File Listing</h3>
|
||||||
<div v-memo="fileListing" v-html="fileListing"></div>
|
<ul>
|
||||||
|
<li v-for="file in floppyDisk?.getFileNameList()" :key="file">{{ file }}</li>
|
||||||
|
</ul>
|
||||||
<h3>Boot Sector</h3>
|
<h3>Boot Sector</h3>
|
||||||
<pre>{{ floppyDisk.bootSectorInfo }}</pre>
|
<pre>{{ floppyDisk.bootSectorInfo }}</pre>
|
||||||
<h3>Directory Entries</h3>
|
<h3>Directory Entries</h3>
|
||||||
|
|||||||
@ -69,14 +69,6 @@ export interface IUnusedDirEntry {
|
|||||||
|
|
||||||
export type TDirEntry = IStandardDirEntry | ILongFileNameDirEntry | IFinalDirEntry | IUnusedDirEntry
|
export type TDirEntry = IStandardDirEntry | ILongFileNameDirEntry | IFinalDirEntry | IUnusedDirEntry
|
||||||
|
|
||||||
export interface IFile {
|
|
||||||
name: string
|
|
||||||
path: string[]
|
|
||||||
isDirectory: boolean
|
|
||||||
firstCuster: number
|
|
||||||
size: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export class FloppyDisk {
|
export class FloppyDisk {
|
||||||
buffer = new ArrayBuffer(0)
|
buffer = new ArrayBuffer(0)
|
||||||
private _bootSector: IBootSectorInfo | null = null
|
private _bootSector: IBootSectorInfo | null = null
|
||||||
@ -202,7 +194,7 @@ export class FloppyDisk {
|
|||||||
return chain
|
return chain
|
||||||
}
|
}
|
||||||
|
|
||||||
addDirectoryListing(listing: string, entries: TDirEntry[]) {
|
addFileNamesFromDirectories(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 (
|
||||||
@ -214,63 +206,39 @@ export class FloppyDisk {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
listing += `${entry.path.join('\\') + '\\'}${entry.name}`
|
listing.push(`${entry.path.join('\\') + '\\'}${entry.name}`)
|
||||||
|
|
||||||
if (entry.attributes.directory) {
|
if (entry.attributes.directory) {
|
||||||
listing += '\\<br/>'
|
this.addFileNamesFromDirectories(listing, entry.subDirEntries)
|
||||||
listing = this.addDirectoryListing(listing, entry.subDirEntries)
|
|
||||||
} else {
|
|
||||||
listing += '<br/>'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return listing
|
return listing
|
||||||
}
|
}
|
||||||
|
|
||||||
buildFileListing(): string {
|
getFileNameList(): string[] {
|
||||||
let listing = '<p>\\<br/>'
|
const listing = ['\\']
|
||||||
listing += this.addDirectoryListing('', this.rootDirEntries ?? [])
|
this.addFileNamesFromDirectories(listing, this.rootDirEntries ?? [])
|
||||||
listing += '</p>'
|
|
||||||
return listing
|
return listing
|
||||||
}
|
}
|
||||||
|
|
||||||
addDirectory(list: IFile[], entries: TDirEntry[]) {
|
addFileEntriesFromDirectory(list: IStandardDirEntry[], 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 (entry.type !== 'standard-entry' || entry.attributes.volumeId || entry.name === '.') {
|
||||||
entry.type !== 'standard-entry' ||
|
|
||||||
entry.attributes.volumeId ||
|
|
||||||
entry.name === '..' ||
|
|
||||||
entry.name === '.'
|
|
||||||
) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.attributes.directory) {
|
list.push(entry)
|
||||||
list.push({
|
if (entry.attributes.directory && entry.name !== '..') {
|
||||||
name: entry.name,
|
this.addFileEntriesFromDirectory(list, entry.subDirEntries)
|
||||||
path: entry.path,
|
|
||||||
isDirectory: true,
|
|
||||||
firstCuster: entry.firstCluster,
|
|
||||||
size: 0,
|
|
||||||
})
|
|
||||||
this.addDirectory(list, entry.subDirEntries)
|
|
||||||
} else {
|
|
||||||
list.push({
|
|
||||||
name: entry.name,
|
|
||||||
path: entry.path,
|
|
||||||
isDirectory: false,
|
|
||||||
firstCuster: entry.firstCluster,
|
|
||||||
size: entry.size,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileList(): IFile[] {
|
getFileEntryList(): IStandardDirEntry[] {
|
||||||
const list: IFile[] = []
|
const list: IStandardDirEntry[] = []
|
||||||
|
this.addFileEntriesFromDirectory(list, this.rootDirEntries ?? [])
|
||||||
this.addDirectory(list, this.rootDirEntries ?? [])
|
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user