11_G ._OSNAME = " miniOS"
2- _G ._OSVER = " 0.5.9.7 "
2+ _G ._OSVER = " 0.6 "
33_G ._OSVERSION = _OSNAME .. " " .. _OSVER
44
55-- component code
@@ -503,7 +503,18 @@ function fs_code()
503503 letter = letter :upper ()
504504 if not fs .drive ._map [letter ] then error (" Invalid Drive" , 2 ) end
505505 fs .drive ._current = letter
506- end
506+ end
507+ function fs .drive .drivepathSplit (mixed )
508+ local drive = fs .drive ._current
509+ local path
510+ if mixed :sub (2 ,2 ) == " :" then
511+ drive = mixed :sub (1 ,1 ):upper ()
512+ path = mixed :sub (3 )
513+ else
514+ path = mixed
515+ end
516+ return drive , path
517+ end
507518 function fs .drive .getcurrent () return fs .drive ._current end
508519 function fs .invoke (method , ...) return fs .drive ._map [fs .drive ._current ][method ](... ) end
509520 function fs .proxy (filter )
@@ -527,13 +538,31 @@ function fs_code()
527538 end
528539 return component .proxy (address )
529540 end
530- function fs .open (file , mode ) return fs .invoke (" open" , file , mode or " r" ) end
531- function fs .write (handle , data ) return fs .invoke (" write" , handle , data ) end
532- function fs .read (handle , length ) return fs .invoke (" read" , handle , length or math.huge ) end
533- function fs .close (handle ) return fs .invoke (" close" , handle ) end
534- function fs .isDirectory (path ) return fs .invoke (" isDirectory" , path ) end
535- function fs .exists (path ) return fs .invoke (" exists" , path ) end
536- function fs .remove (path ) return fs .invoke (" remove" , path ) end
541+ function fs .open (file , mode )
542+ local drive , handle , proxy
543+ drive , path = fs .drive .drivepathSplit (file )
544+ proxy = fs .drive .letterToProxy (drive )
545+ handle = proxy .open (path , mode or ' r' )
546+ return {_handle = handle , _proxy = proxy }
547+ end
548+ function fs .write (handle , data ) return handle ._proxy .write (handle ._handle , data ) end
549+ function fs .read (handle , length ) return handle ._proxy .read (handle ._handle , length or math.huge ) end
550+ function fs .close (handle ) return handle ._proxy .close (handle ._handle ) end
551+ function fs .isDirectory (path )
552+ local drive
553+ drive , path = fs .drive .drivepathSplit (path )
554+ return fs .drive .letterToProxy (drive ).isDirectory (path )
555+ end
556+ function fs .exists (path )
557+ local drive
558+ drive , path = fs .drive .drivepathSplit (path )
559+ return fs .drive .letterToProxy (drive ).exists (path )
560+ end
561+ function fs .remove (path )
562+ local drive
563+ drive , path = fs .drive .drivepathSplit (path )
564+ return fs .drive .letterToProxy (drive ).remove (path )
565+ end
537566 function fs .copy (fromPath , toPath )
538567 if fs .isDirectory (fromPath ) then
539568 return nil , " cannot copy folders"
@@ -564,11 +593,22 @@ function fs_code()
564593 filesystem .close (output )
565594 return true
566595 end
567- function fs .rename (path1 , path2 ) return fs .invoke (" rename" , path1 , path2 ) end
568- function fs .makeDirectory (path ) return fs .invoke (" makeDirectory" , path ) end
596+ function fs .rename (path1 , path2 )
597+ local drive
598+ drive , path = fs .drive .drivepathSplit (path )
599+ return fs .drive .letterToProxy (drive ).rename (path1 , path2 )
600+ end
601+ function fs .makeDirectory (path )
602+ local drive
603+ drive , path = fs .drive .drivepathSplit (path )
604+ return fs .drive .letterToProxy (drive ).makeDirectory (path )
605+ end
569606 function fs .list (path )
607+ local drive
608+ drive , path = fs .drive .drivepathSplit (path )
609+
570610 local i = 0
571- local t = fs .invoke ( " list" , path )
611+ local t = fs .drive . letterToProxy ( drive ). list ( path )
572612 local n = # t
573613 return function ()
574614 i = i + 1
@@ -1126,7 +1166,8 @@ end
11261166
11271167miniOS = {}
11281168local function interrupt (data )
1129- if data [2 ] == " RUN" then miniOS .runfile (data [3 ], table.unpack (data [4 ])) end
1169+ -- print("INTERRUPT!")
1170+ if data [2 ] == " RUN" then return miniOS .runfile (data [3 ], table.unpack (data [4 ])) end
11301171end
11311172local function runfile (file , ...)
11321173 local program , reason = loadfile (file )
@@ -1135,7 +1176,7 @@ local function runfile(file, ...)
11351176 if result [1 ] then
11361177 return table.unpack (result , 2 , result .n )
11371178 else
1138- if type (result [2 ]) == " table" then if result [2 ][1 ] then if result [2 ][1 ] == " INTERRUPT" then interrupt (result [2 ]) return end end end
1179+ if type (result [2 ]) == " table" then if result [2 ][1 ] then if result [2 ][1 ] == " INTERRUPT" then interrupt (result [2 ]) return true end end end
11391180 error (result [2 ], 3 )
11401181 end
11411182 else
@@ -1147,15 +1188,15 @@ local function kernelError()
11471188 term .readKey ()
11481189end
11491190function miniOS .runfile (...)
1150- local _ , err = pcall (runfile , ... )
1151- if not _ then
1191+ local s , v = pcall (runfile , ... )
1192+ if not s then
11521193 printErr (err )
11531194 -- printErr("\n" .. debug.traceback())
11541195 end
1155- return _
1196+ return v
11561197end
11571198function require (lib )
1158- return _G [lib ] or _G [string.lower (lib )]
1199+ return _G [lib ] or _G [string.lower (lib )] or miniOS . runfile ( lib .. " .lua " )
11591200end
11601201
11611202miniOS .freeMem = computer .freeMemory ()
@@ -1167,5 +1208,5 @@ while true do
11671208 miniOS .freeMem = computer .freeMemory ()
11681209 print ()
11691210 fs .drive .setcurrent (command_drive )
1170- if not miniOS .runfile (" command.lua" , " -c" ) then kernelError () end
1171- end
1211+ if not miniOS .runfile (" command.lua" , " -c" ) then printErr ( " \n\n Error during shell! Will restart command.lua! " ) kernelError () end
1212+ end
0 commit comments