Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lDir
- local sboot
- local nuke
- local oFs
- local oldString
- local oldR
- local newG
- function init(dir,boot,nuke)
- --Setup argvars
- lDir = dir
- sboot = boot
- nuke = nuke
- --Clone fs and string to local tables
- oFs = {}
- oldString = {}
- for k,v in pairs(string) do
- oldString[k] = string[k]
- end
- for k,v in pairs(fs) do
- oFs[k] = v
- end
- --overwrite reboot and clone _G to a new table
- newG = {}
- for k,v in pairs(_G) do
- if k ~= _G then
- newG[k] = v
- end
- end
- oldR = _G.os.shutdown
- newG.os.shutdown = function()
- term.clear()
- term.setCursorPos(1,1)
- for k,v in pairs(oFs) do
- fs[k] = oFs[k]
- end
- end
- end
- local pUsage
- local resolve
- local sRes
- function fres()
- --Basic setup
- if not fs.exists(lDir) then
- fs.makeDir(lDir)
- end
- if nuke == "true" then
- for k,v in pairs(fs.list(lDir)) do
- fs.delete(lDir.."/"..v)
- end
- end
- --Path Resolver Stuff
- function resolve(p1,p2)
- local res = oFs.combine(p1,p2)
- if string.find(res,"%.%.") then
- if oldString.sub(res,4, 6) == "rom" then
- return res
- end
- return ""
- else
- if res:sub(0,3) == "rom" then
- return "../"..res
- else
- return res
- end
- end
- end
- function sRes(p1,p2)
- return lDir.."/"..resolve(p1,p2)
- end
- newG.fs.list = function(D)
- return oFs.list(sRes("/",D))
- end
- newG.fs.exists = function(D)
- return oFs.exists(sRes("/",D))
- end
- newG.fs.isDir = function(D)
- return oFs.isDir(sRes("/",D))
- end
- newG.fs.open = function(D,M)
- return oFs.open(sRes("/",D),M)
- end
- newG.fs.isReadOnly = function(D)
- return oFs.isReadOnly(sRes("/",D))
- end
- newG.fs.getName = function(D)
- return oFs.getName(sRes("/",D))
- end
- newG.fs.getDrive = function(D)
- return oFs.getDrive(sRes("/",D))
- end
- newG.fs.getSize = function(D)
- return oFs.getSize(sRes("/",D))
- end
- newG.fs.getFreeSpace = function(D)
- return oFs.getFreeSpace(sRes("/",D))
- end
- newG.fs.makeDir = function(D)
- return oFs.makeDir(sRes("/",D))
- end
- newG.fs.move = function(D1,D2)
- D1 = sRes("/",D1)
- D2 = sRes("/",D2)
- oFs.move(D1,D2)
- end
- newG.fs.copy = function(D1,D2)
- D1 = sRes("/",D1)
- D2 = sRes("/",D2)
- oFs.copy(D1,D2)
- end
- newG.fs.delete = function(D)
- oFs.delete(sRes("/",D))
- end
- newG.getDir = function(D)
- return oFs.getDir(sRes("/",D))
- end
- newG.fs.combine = resolve
- end
- function sBox()
- term.clear()
- term.setCursorPos(1,1)
- local f
- if fs.exists("/rom/programs/shell") then
- f = "/rom/programs/shell"
- else
- f = "/rom/programs/shell.lua"
- end
- local file = fs.open(f,"r")
- local cont = file.readAll()
- file.close()
- if sboot ~= "true" or not fs.exists("/startup") or not fs.exists("/startup.lua") then
- load(cont,"shell","t",newG)()
- else
- if fs.exists("/startup") then
- local file = fs.open("/startup","r")
- local cont = file.readAll()
- file.close()
- elseif fs.exists("/startup.lua") then
- local file = fs.open("startup.lua","r")
- local cont = file.readAll()
- file.close()
- end
- load(cont,"startup","t",newG)()
- end
- end
Add Comment
Please, Sign In to add comment