more chdir wip

This commit is contained in:
minjaesong
2020-11-07 17:33:54 +09:00
parent 954307a7f9
commit f01345fb6f
4 changed files with 26 additions and 1 deletions

View File

@@ -69,6 +69,16 @@ filesystem.readAll = function(driveLetter) {
}
return com.pullMessage(port[0]);
};
filesystem.isDirectory = function(driveLetter) {
let port = filesystem._toPorts(driveLetter);
com.sendMessage(port[0], "LISTFILES");
let response = com.getStatusCode(port[0]);
if (135 == response) {
throw Error("File not opened");
}
return (response === 0);
}
Object.freeze(filesystem);
///////////////////////////////////////////////////////////////////////////////

View File

@@ -138,9 +138,22 @@ shell.coreutils = {
return
}
// replace slashes into revslashes
let pathstr = args[1].replaceAll('/','\\\\');
// split them into an array while filtering empty elements except for the root 'head'
let newPwd = [""].concat(pathstr.split("\\").filter(function(it) { return (it.length > 0); }));
// construct new pathstr from pwd arr so it will be sanitised
pathstr = newPwd.join('\\').substring(1);
if (DEBUG_PRINT) serial.println("command.js > pathstr = "+pathstr);
// check if path is valid
let dirOpened = filesystem.open(CURRENT_DRIVE, pathstr, 'R');
if (!dirOpened) { printerrln("CHDIR failed for '"+pathstr+"'"); return; }
// check if path is directory
let isDir = filesystem.isDirectory(CURRENT_DRIVE);
if (!isDir) { printerrln("CHDIR failed for '"+pathstr+"'"); return; }
shell_pwd = newPwd;
},

View File

@@ -365,6 +365,8 @@ class TestDiskDrive(private val driveNum: Int, theRootPath: File? = null) : Bloc
// applies a "cap" if the path attemps to access parent directory of the root
private fun filterSuperRoot(path: String): String {
if (path.isEmpty()) return path
var parentCount = 0
val paths = path.split('/')
val newPaths = ArrayList<String>()

View File

@@ -29,7 +29,7 @@ class V2kRunTest(val appConfig: LwjglApplicationConfiguration) : ApplicationAdap
override fun create() {
super.create()
gpu = GraphicsAdapter(vm, lcdMode = false)
gpu = GraphicsAdapter(vm, theme = GraphicsAdapter.THEME_COLORCRT)
vm.peripheralTable[1] = PeripheralEntry(
VM.PERITYPE_GPU_AND_TERM,