Sirshark10

sBox

Jul 9th, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local lDir
  2. local sboot
  3. local nuke
  4. local oFs
  5. local oldString
  6. local oldR
  7. local newG
  8.  
  9. function init(dir,boot,nuke)
  10. --Setup argvars
  11.     lDir = dir
  12.     sboot = boot
  13.     nuke = nuke
  14.  
  15.     --Clone fs and string to local tables
  16.     oFs = {}
  17.     oldString = {}
  18.     for k,v in pairs(string) do
  19.         oldString[k] = string[k]
  20.     end
  21.  
  22.     for k,v in pairs(fs) do
  23.         oFs[k] = v
  24.     end
  25.  
  26.     --overwrite reboot and clone _G to a new table
  27.     newG = {}
  28.     for k,v in pairs(_G) do
  29.         if k ~= _G then
  30.             newG[k] = v
  31.         end
  32.     end
  33.    
  34.    
  35.     oldR = _G.os.shutdown
  36.     newG.os.shutdown = function()
  37.         term.clear()
  38.         term.setCursorPos(1,1)
  39.         for k,v in pairs(oFs) do
  40.             fs[k] = oFs[k]
  41.         end
  42.  end
  43. end
  44.  
  45.  
  46. local pUsage
  47. local resolve
  48. local sRes
  49. function fres()
  50.     --Basic setup
  51.    
  52.     if not fs.exists(lDir) then
  53.         fs.makeDir(lDir)
  54.     end
  55.  
  56.     if nuke == "true" then
  57.         for k,v in pairs(fs.list(lDir)) do
  58.             fs.delete(lDir.."/"..v)
  59.         end
  60.     end
  61.  
  62.     --Path Resolver Stuff
  63.     function resolve(p1,p2)
  64.     local res = oFs.combine(p1,p2)
  65.     if string.find(res,"%.%.") then
  66.         if oldString.sub(res,4, 6) == "rom" then
  67.             return res
  68.         end
  69.         return ""
  70.     else
  71.         if res:sub(0,3) == "rom" then
  72.             return "../"..res
  73.         else
  74.             return res
  75.         end
  76.     end
  77. end
  78.  
  79.     function sRes(p1,p2)
  80.         return lDir.."/"..resolve(p1,p2)
  81.     end
  82.  
  83.  
  84.     newG.fs.list = function(D)
  85.       return oFs.list(sRes("/",D))
  86.     end
  87.  
  88.     newG.fs.exists = function(D)
  89.       return oFs.exists(sRes("/",D))
  90.     end
  91.  
  92.     newG.fs.isDir = function(D)
  93.       return oFs.isDir(sRes("/",D))
  94.     end
  95.  
  96.     newG.fs.open = function(D,M)
  97.       return oFs.open(sRes("/",D),M)
  98.     end
  99.  
  100.     newG.fs.isReadOnly = function(D)
  101.        return oFs.isReadOnly(sRes("/",D))
  102.     end
  103.  
  104.     newG.fs.getName = function(D)
  105.        return oFs.getName(sRes("/",D))
  106.     end
  107.  
  108.     newG.fs.getDrive = function(D)
  109.        return oFs.getDrive(sRes("/",D))
  110.     end
  111.  
  112.     newG.fs.getSize = function(D)
  113.        return oFs.getSize(sRes("/",D))
  114.     end
  115.  
  116.     newG.fs.getFreeSpace = function(D)
  117.        return oFs.getFreeSpace(sRes("/",D))
  118.     end
  119.  
  120.     newG.fs.makeDir = function(D)
  121.        return oFs.makeDir(sRes("/",D))
  122.     end
  123.  
  124.     newG.fs.move = function(D1,D2)
  125.        D1 = sRes("/",D1)
  126.        D2 = sRes("/",D2)
  127.        oFs.move(D1,D2)
  128.     end
  129.  
  130.     newG.fs.copy = function(D1,D2)
  131.        D1 = sRes("/",D1)
  132.        D2 = sRes("/",D2)
  133.        oFs.copy(D1,D2)
  134.     end
  135.  
  136.     newG.fs.delete = function(D)
  137.        oFs.delete(sRes("/",D))
  138.     end
  139.  
  140.     newG.getDir = function(D)
  141.        return oFs.getDir(sRes("/",D))
  142.     end
  143.  
  144.     newG.fs.combine = resolve
  145. end
  146.  
  147.  
  148. function sBox()
  149.     term.clear()
  150.     term.setCursorPos(1,1)
  151.     local f
  152.     if fs.exists("/rom/programs/shell") then
  153.         f = "/rom/programs/shell"
  154.     else
  155.         f = "/rom/programs/shell.lua"
  156.     end
  157.     local file = fs.open(f,"r")
  158.     local cont = file.readAll()
  159.     file.close()
  160.     if sboot ~= "true" or not fs.exists("/startup") or not fs.exists("/startup.lua") then
  161.         load(cont,"shell","t",newG)()
  162.     else
  163.         if fs.exists("/startup") then
  164.             local file = fs.open("/startup","r")
  165.             local cont = file.readAll()
  166.             file.close()
  167.         elseif fs.exists("/startup.lua") then
  168.             local file = fs.open("startup.lua","r")
  169.             local cont = file.readAll()
  170.             file.close()
  171.         end
  172.         load(cont,"startup","t",newG)()
  173.     end
  174. end
Add Comment
Please, Sign In to add comment