mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-17 08:16:06 +09:00
zfm: faster dir listing
This commit is contained in:
@@ -73,12 +73,46 @@ function refreshFilePanelCache(side) {
|
|||||||
let pathStr = path[side].concat(['']).join("\\").replaceAll('\\\\', '\\')
|
let pathStr = path[side].concat(['']).join("\\").replaceAll('\\\\', '\\')
|
||||||
const showDrives = (pathStr.length == 0)
|
const showDrives = (pathStr.length == 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
filePanelCache[side] = []
|
filePanelCache[side] = []
|
||||||
|
|
||||||
let fileList = []
|
let ds = []
|
||||||
|
let fs = []
|
||||||
|
|
||||||
|
//serial.println(`pathStr=${pathStr}`)
|
||||||
if (!showDrives) {
|
if (!showDrives) {
|
||||||
// serial.println(`pathStr=${pathStr}`)
|
let letter = pathStr[0]
|
||||||
fileList = files.open(pathStr).list()
|
let serialPath = pathStr.substring(3)
|
||||||
|
// remove trailing slashes
|
||||||
|
while (serialPath.endsWith("\\")) {
|
||||||
|
serialPath = serialPath.substring(0, serialPath.length - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
let port = _TVDOS.DRV.FS.SERIAL._toPorts(letter)
|
||||||
|
com.sendMessage(port[0], "DEVRST\x17")
|
||||||
|
com.sendMessage(port[0], "OPENR"+'"'+serialPath+'",'+port[1])
|
||||||
|
//serial.println("OPENR"+'"'+serialPath+'",'+port[1])
|
||||||
|
com.sendMessage(port[0], "LISTFILES")
|
||||||
|
let response = com.getStatusCode(port[0])
|
||||||
|
let rawStr = com.pullMessage(port[0]) // {\x11 | \x12} <name> [ \x1E {\x11 | \x12} <name> ] \x17
|
||||||
|
|
||||||
|
//serial.println(`rawStr=${rawStr}`)
|
||||||
|
|
||||||
|
|
||||||
|
rawStr.substring(0, rawStr.length).split('\x1E').forEach((s) => {
|
||||||
|
let fname = undefined
|
||||||
|
if (s[0] == '\x11') {
|
||||||
|
fname = s.substr(1)
|
||||||
|
//serial.println(`fname=(dir)${fname}`)
|
||||||
|
ds.push(files.open(`${pathStr}${fname}`))
|
||||||
|
}
|
||||||
|
else if (s[0] == '\x12') {
|
||||||
|
fname = s.substr(1)
|
||||||
|
//serial.println(`fname=(file)${fname}`)
|
||||||
|
fs.push(files.open(`${pathStr}${fname}`))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Object.entries(_TVDOS.DRIVES).map(it=>{
|
Object.entries(_TVDOS.DRIVES).map(it=>{
|
||||||
@@ -87,20 +121,12 @@ function refreshFilePanelCache(side) {
|
|||||||
|
|
||||||
if (dinfo.type == "STOR") {
|
if (dinfo.type == "STOR") {
|
||||||
let file = files.open(`${letter}:\\`)
|
let file = files.open(`${letter}:\\`)
|
||||||
fileList.push(file)
|
ds.push(file)
|
||||||
// serial.println(`fileList ${file.fullPath}`)
|
//serial.println(`fileList ${file.fullPath}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let ds = []
|
|
||||||
let fs = []
|
|
||||||
fileList.forEach((file)=>{
|
|
||||||
if (file.isDirectory)
|
|
||||||
ds.push(file)
|
|
||||||
else
|
|
||||||
fs.push(file)
|
|
||||||
})
|
|
||||||
ds.sort((a,b) => (a.name > b.name) ? 1 : (a.name < b.name) ? -1 : 0)
|
ds.sort((a,b) => (a.name > b.name) ? 1 : (a.name < b.name) ? -1 : 0)
|
||||||
fs.sort((a,b) => (a.name > b.name) ? 1 : (a.name < b.name) ? -1 : 0)
|
fs.sort((a,b) => (a.name > b.name) ? 1 : (a.name < b.name) ? -1 : 0)
|
||||||
dirFileList[side] = ds.concat(fs)
|
dirFileList[side] = ds.concat(fs)
|
||||||
@@ -112,7 +138,7 @@ function refreshFilePanelCache(side) {
|
|||||||
let file = dirFileList[side][i]
|
let file = dirFileList[side][i]
|
||||||
let sizestr;
|
let sizestr;
|
||||||
if (!showDrives) {
|
if (!showDrives) {
|
||||||
sizestr = (file) ? bytesToReadable(file.size) : ''
|
sizestr = (file) ? bytesToReadable(file.size) : '' // FIXME file.size creates disk access
|
||||||
}
|
}
|
||||||
else if (file) {
|
else if (file) {
|
||||||
let port = _TVDOS.DRIVES[file.driveLetter]
|
let port = _TVDOS.DRIVES[file.driveLetter]
|
||||||
@@ -151,7 +177,7 @@ let filesPanelDraw = (wo) => {
|
|||||||
let freeBytes = undefined
|
let freeBytes = undefined
|
||||||
let pathStr = path[windowMode].concat(['']).join("\\").replaceAll('\\\\', '\\')
|
let pathStr = path[windowMode].concat(['']).join("\\").replaceAll('\\\\', '\\')
|
||||||
|
|
||||||
// serial.println(`pathStr=${pathStr}`)
|
//serial.println(`pathStr=${pathStr}`)
|
||||||
|
|
||||||
let port = _TVDOS.DRIVES[pathStr[0]]
|
let port = _TVDOS.DRIVES[pathStr[0]]
|
||||||
|
|
||||||
@@ -401,7 +427,7 @@ let filenavOninput = (window, event) => {
|
|||||||
let selectedFileCache = filePanelCache[windowMode][cursor[windowMode]]
|
let selectedFileCache = filePanelCache[windowMode][cursor[windowMode]]
|
||||||
let selectedFile = selectedFileCache.file
|
let selectedFile = selectedFileCache.file
|
||||||
|
|
||||||
// serial.println(`selectedFile = ${selectedFile.fullPath}`)
|
//serial.println(`selectedFile = ${selectedFile.fullPath}`)
|
||||||
|
|
||||||
if (selectedFile.fullPath[1] == ":" && selectedFile.fullPath[2] == "\\" && selectedFile.fullPath.length == 3) {
|
if (selectedFile.fullPath[1] == ":" && selectedFile.fullPath[2] == "\\" && selectedFile.fullPath.length == 3) {
|
||||||
path[windowMode].push(selectedFile.fullPath)
|
path[windowMode].push(selectedFile.fullPath)
|
||||||
@@ -410,7 +436,7 @@ let filenavOninput = (window, event) => {
|
|||||||
drawFilePanel()
|
drawFilePanel()
|
||||||
}
|
}
|
||||||
else if (selectedFileCache.isDirectory) {
|
else if (selectedFileCache.isDirectory) {
|
||||||
// serial.println(`selectedFile.name = ${selectedFile.name}`)
|
//serial.println(`selectedFile.name = ${selectedFile.name}`)
|
||||||
path[windowMode].push(selectedFileCache.filename)
|
path[windowMode].push(selectedFileCache.filename)
|
||||||
cursor[windowMode] = 0; scroll[windowMode] = 0
|
cursor[windowMode] = 0; scroll[windowMode] = 0
|
||||||
refreshFilePanelCache(windowMode)
|
refreshFilePanelCache(windowMode)
|
||||||
@@ -423,15 +449,15 @@ let filenavOninput = (window, event) => {
|
|||||||
|
|
||||||
con.curs_set(1);clearScr();con.move(1,1)
|
con.curs_set(1);clearScr();con.move(1,1)
|
||||||
try {
|
try {
|
||||||
// // serial.println(selectedFile.fullPath)
|
//serial.println(selectedFile.fullPath)
|
||||||
errorlevel = execfun(selectedFile.fullPath)
|
errorlevel = execfun(selectedFile.fullPath)
|
||||||
// // serial.println("1 errorlevel = " + errorlevel)
|
//serial.println("1 errorlevel = " + errorlevel)
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// TODO popup error
|
// TODO popup error
|
||||||
println(e)
|
println(e)
|
||||||
errorlevel = 1
|
errorlevel = 1
|
||||||
// // serial.println("2 errorlevel = " + errorlevel)
|
//serial.println("2 errorlevel = " + errorlevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorlevel) {
|
if (errorlevel) {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
|||||||
blockSize.setRelease(bytesReceived)
|
blockSize.setRelease(bytesReceived)
|
||||||
writeoutImpl(inputData)
|
writeoutImpl(inputData)
|
||||||
|
|
||||||
println("Contents: ${inputData.toString(VM.CHARSET)}")
|
// println("Contents: ${inputData.toString(VM.CHARSET)}")
|
||||||
applyBaudRateDelay(bytesReceived)
|
applyBaudRateDelay(bytesReceived)
|
||||||
|
|
||||||
busy.setRelease(false)
|
busy.setRelease(false)
|
||||||
@@ -127,7 +127,7 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
|||||||
val sleepTimeMS = (delayAkku / 1000000).toLong()
|
val sleepTimeMS = (delayAkku / 1000000).toLong()
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTimeMS)
|
Thread.sleep(sleepTimeMS)
|
||||||
println("Sleep $sleepTimeMS ms for $byteCount bytes")
|
// println("Sleep $sleepTimeMS ms for $byteCount bytes")
|
||||||
delayAkku -= sleepTimeMS * 1000000.0
|
delayAkku -= sleepTimeMS * 1000000.0
|
||||||
}
|
}
|
||||||
catch (e: InterruptedException) {
|
catch (e: InterruptedException) {
|
||||||
@@ -135,7 +135,7 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
println("Sleep skip for $byteCount bytes")
|
// println("Sleep skip for $byteCount bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update last transmission time
|
// Update last transmission time
|
||||||
|
|||||||
@@ -289,6 +289,7 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
|
|||||||
statusCode.set(STATE_CODE_NO_FILE_OPENED)
|
statusCode.set(STATE_CODE_NO_FILE_OPENED)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// println("[TestDiskDrive] file opened: ${file.path}")
|
||||||
try {
|
try {
|
||||||
if (file.isDirectory) {
|
if (file.isDirectory) {
|
||||||
file.listFiles()!!.forEachIndexed { index, lsfile ->
|
file.listFiles()!!.forEachIndexed { index, lsfile ->
|
||||||
|
|||||||
Reference in New Issue
Block a user