Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.63 KB | None | 0 0
  1. local function parseArgs(params)
  2. local args = {}
  3. local options = {}
  4. for key,data in ipairs(params) do
  5. if type(data) == "string" then
  6.   if data:find("--") == 1 then
  7.     data = data:sub(3,-1)
  8.     local head,body = data:match("([^=]+)=([^=]+)")
  9.     if body ~= nil then
  10.       options[head] = body
  11.     else
  12.       options[data] = true
  13.     end
  14.  elseif data:find("-") == 1 then
  15.     data = data:sub(2,-1)
  16.     for i=1,#data do
  17.       options[data:sub(i,i)] = true
  18.     end
  19.   else
  20.     table.insert(args,data)
  21.   end
  22. end
  23. end
  24. return args,options
  25. end
  26.  
  27. local argst,ops = parseArgs({...})
  28.  
  29. if ops.biosPath == nil then
  30.     printError("Missed Argument --biosPath=Path")
  31.     return
  32. end
  33. if ops.romPath == nil then
  34.     printError("Missed Argument --romPath=Path")
  35.     return
  36. end
  37. if ops.rootPath == nil then
  38.     printError("Missed Argument --rootPath=Path")
  39.     return
  40. end
  41.  
  42. local sBiosPath = fs.combine(ops.biosPath,"")
  43. local sRomPath = fs.combine(ops.romPath,"")
  44. local sRootPath = fs.combine(ops.rootPath,"")
  45. local bReeboot = false
  46. local nVirtualID = math.random(1,1000)
  47.  
  48. if not fs.exists(sBiosPath) then
  49.     printError("Bios not found")
  50.     return
  51. end
  52.  
  53. if not fs.isDir(sRomPath) then
  54.     printError("Rom not found")
  55.     return
  56. end
  57.  
  58. if not fs.isDir(sRootPath) then
  59.     printError("Rootfolder not found")
  60.     return
  61. end
  62.  
  63. local tFs = {}
  64. for k,v in pairs(fs) do
  65.     tFs[k] = v
  66. end
  67. local function getRealPath(sPath)
  68.     if sPath:find("rom") == 1 or sPath:find("/rom") == 1 or sPath:find("\\rom") == 1 then
  69.         local sPath = fs.combine(sPath,"")
  70.         sPath = sPath:sub(4)
  71.         sPath = fs.combine(sRomPath,sPath)
  72.         return sPath
  73.     end
  74.     local sNewPath = fs.combine(sRootPath,sPath)
  75.     return sNewPath
  76. end
  77.  
  78. function tFs.list(sPath)
  79.     local sPath = getRealPath(sPath)
  80.     local tList = fs.list(sPath)
  81.     if sPath == sRootPath then
  82.         table.insert(tList,"rom")
  83.     end
  84.     table.sort(tList)
  85.     return tList
  86. end
  87.  
  88. function tFs.open(sPath,sMode)
  89.     local sPath = getRealPath(sPath)
  90.     return fs.open(sPath,sMode)
  91. end
  92.  
  93. function tFs.exists(sPath)
  94.     local sPath = getRealPath(sPath)
  95.     return fs.exists(sPath)
  96. end
  97.  
  98. function tFs.isDir(sPath)
  99.     local sPath = getRealPath(sPath)
  100.     return fs.isDir(sPath)
  101. end
  102.  
  103. function tFs.delete(sPath)
  104.     local sPath = getRealPath(sPath)
  105.     return fs.delete(sPath)
  106. end
  107.  
  108. function tFs.move(sPath,sTo)
  109.     local sPath = getRealPath(sPath)
  110.     local sTo = getRealPath(sTo)
  111.     return fs.move(sPath,sTo)
  112. end
  113.  
  114. function tFs.copy(sPath,sTo)
  115.     local sPath = getRealPath(sPath)
  116.     local sTo = getRealPath(sTo)
  117.     return fs.copy(sPath,sTo)
  118. end
  119.  
  120. function tFs.find(sPath)
  121.     local sPath = getRealPath(sPath)
  122.     local tResult = fs.find(sPath)
  123.     for k,v in ipairs(tResult) do
  124.         tResult[k] = v:sub(#sRootPath+2)
  125.     end
  126.     return tResult
  127. end
  128.  
  129. function tFs.getSize(sPath)
  130.     local sPath = getRealPath(sPath)
  131.     return fs.getSize(sPath)
  132. end
  133.  
  134. --For Pre 1.8 User
  135. local tPalette = {
  136.     [1] = {240, 240, 240},
  137.     [2] = {242, 178, 51},
  138.     [4] = {229, 127, 216},
  139.     [8] = {153, 178, 242},
  140.     [16] = {222, 222, 108},
  141.     [32] = {127, 204, 25},
  142.     [64] = {242, 178, 204},
  143.     [128] = {76, 76, 76},
  144.     [256] = {153, 153, 153},
  145.     [512] = {76, 153, 178},
  146.     [1024] = {178, 102, 229},
  147.     [2048] = {51, 102, 204},
  148.     [4096] = {127, 102, 76},
  149.     [8192] = {87, 166, 78},
  150.     [16384] = {204, 76, 76},
  151.     [32768] = {25, 25, 25},
  152. }
  153. local tTerm = {}
  154. for k,v in pairs(term.current()) do
  155.     tTerm[k] = v
  156. end
  157. tTerm.setPaletteColor = tTerm.setPaletteColor or function(col,a,b,c) tPalette[col][1] = a*255 tPalette[col][2] = b*255 tPalette[col][3] = c*255 end
  158. tTerm.setPaletteColour = tTerm.setPaletteColour or function(col,a,b,c) tPalette[col][1] = a*255 tPalette[col][2] = b*255 tPalette[col][3] = c*255 end
  159. tTerm.getPaletteColor = tTerm.getPaletteColor or function(color) return tPalette[color][1]/255,tPalette[color][3]/255,tPalette[color][3]/255 end
  160. tTerm.getPaletteColour = tTerm.getPaletteColour or function(color) return tPalette[color][1]/255,tPalette[color][3]/255,tPalette[color][3]/255 end
  161. if ops.oldnative then
  162.     tTerm.native = tTerm
  163. else
  164.     tTerm.native = function() return tTerm end
  165. end
  166.  
  167. local nStarttime = os.clock()
  168. local tOs = {}
  169. local sLabel = ops.label
  170. local tTimer
  171. tOs.startTimer = os.startTimer
  172. tOs.shutdown = function() os.queueEvent("VirtualOS_shutdown:"..nVirtualID) end
  173. tOs.reboot = function() bReeboot = true os.queueEvent("VirtualOS_shutdown:"..nVirtualID) end
  174. tOs.clock = function() return os.clock()-nStarttime end
  175. tOs.getComputerID = function() return tonumber(ops.id) or 0 end
  176. tOs.getComputerLabel = function() return sLabel end
  177. tOs.setComputerLabel = function(label) sLabel = label end
  178. tOs.queueEvent = os.queueEvent
  179. tOs.cancelTimer = os.cancelTimer
  180. function tOs.time(source)
  181.     if ops.notime then
  182.         return 7
  183.     else
  184.         return os.time(source)
  185.     end
  186. end
  187. function tOs.day(source)
  188.     if ops.noday then
  189.         return 1
  190.     else
  191.         return os.day(source)
  192.     end
  193. end
  194. tOs.epoch = os.epoch or function() return tOs.day() * 86400000 + (tOs.time() * 3600000) end
  195.  
  196. local tEnv = {}
  197. tEnv.ipairs = ipairs
  198. tEnv.type = type
  199. tEnv.rawget = rawget
  200. tEnv.rawequal = rawequal
  201. tEnv.setmetatable = setmetatable
  202. tEnv.getmetatable = getmetatable
  203. tEnv.loadstring = loadstring
  204. tEnv.setfenv = setfenv
  205. tEnv.pairs = pairs
  206. tEnv.rawset = rawset
  207. tEnv.getfenv = getfenv
  208. tEnv.pcall = pcall
  209. tEnv.xpcall = xpcall
  210. tEnv.tostring = tostring
  211. tEnv.tonumber = tonumber
  212. tEnv.unpack = unpack
  213. tEnv.load = load
  214. tEnv.select = select
  215. tEnv.next = next
  216. tEnv.error = error
  217. tEnv.peripheral = peripheral
  218. tEnv.table = table
  219. tEnv.math = math
  220. tEnv.bit = bit
  221. tEnv.rs = rs
  222. tEnv.redstone = redstone
  223. tEnv.fs = tFs
  224. tEnv.term = tTerm
  225. tEnv.os = tOs
  226. tEnv.coroutine = coroutine
  227. tEnv.string = string
  228. tEnv.turtle = turtle
  229. tEnv.pocket = pocket
  230. if not ops.nohttp then
  231.     tEnv.http = http
  232. end
  233. tEnv._HOST = ops.host or "VirtualOS 2.0"
  234. tEnv._CC_VERSION = ops.ccversion
  235. tEnv._MC_VERSION = ops.mcversion
  236. tEnv._VERSION = _VERSION
  237. tEnv._G = tEnv
  238.  
  239. local fn,err = loadfile(sBiosPath)
  240. setfenv(fn,tEnv)
  241.  
  242. local function shutdownLoop()
  243.     os.pullEvent("VirtualOS_shutdown:"..nVirtualID)
  244. end
  245.  
  246. if multishell then
  247.     multishell.setTitle(multishell.getCurrent(),ops.title or "CraftOS")
  248. end
  249.  
  250. term.setTextColor(colors.white)
  251. term.setBackgroundColor(colors.black)
  252. term.clear()
  253. term.setCursorPos(1,1)
  254.  
  255. while true do    
  256.     parallel.waitForAny(fn,shutdownLoop)
  257.     if bReeboot == true then
  258.         bReeboot = false
  259.         term.setTextColor(colors.white)
  260.         term.setBackgroundColor(color.black)
  261.         term.clear()
  262.         term.setCursorPos(1,1)
  263.     else
  264.         break
  265.     end
  266. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement