Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. local raw_loadfile = ...
  2. _G._OSVERSION = "OpenOS 1.6.1"
  3. local title = "OpenOS Loading"
  4. local component = component
  5. local computer = computer
  6. local unicode = unicode
  7. local function centrize(wi, screenWidth)
  8. return math.floor(screenWidth / 2 - wi / 2)
  9. end
  10. local runlevel, shutdown = "S", computer.shutdown
  11. computer.runlevel = function() return runlevel end
  12. computer.shutdown = function(reboot)
  13. runlevel = reboot and 6 or 0
  14. if os.sleep then
  15. computer.pushSignal("shutdown")
  16. os.sleep(0.1)
  17. end
  18. shutdown(reboot)
  19. end
  20. local screen = component.list('screen', true)()
  21. for address in component.list('screen', true) do
  22. if #component.invoke(address, 'getKeyboards') > 0 then
  23. screen = address
  24. break
  25. end
  26. end
  27. _G.boot_screen = screen
  28. local gpu = component.list("gpu", true)()
  29. local w, h = 160, 50
  30. if gpu and screen then
  31. component.invoke(gpu, "bind", screen)
  32. w, h = component.invoke(gpu, "maxResolution")
  33. component.invoke(gpu, "setResolution", w, h)
  34. component.invoke(gpu, "setBackground", 0xd4d4d4)
  35. component.invoke(gpu, "setForeground", 0x2D2D2D)
  36. component.invoke(gpu, "fill", 1, 1, w, h, " ")
  37. component.invoke(gpu, "set", centrize(#title, w), h/2, title)
  38. component.invoke(gpu, "setForeground", 0xC3C3C3)
  39. component.invoke(gpu, "set", w/2-25,h/2+2,string.rep("─", 50))
  40. end
  41. local y = 1
  42. local function status(msg)
  43. if gpu and screen then
  44. component.invoke(gpu, "setForeground", 0x878787)
  45. if y < 20 then
  46. loa = string.rep("─", y*2.5)
  47. else
  48. loa = string.rep("─", 50)
  49. end
  50. component.invoke(gpu, "set", w/2-25,h/2+2,loa)
  51. component.invoke(gpu, "fill",1,h,w,h," ")
  52. component.invoke(gpu, "set",1,h,"Status: "..msg)
  53. y = y + 1
  54. end
  55. end
  56. status("Booting " .. _OSVERSION .. "...")
  57. local loadfile = function(file)
  58. status("> " .. file)
  59. return raw_loadfile(file)
  60. end
  61.  
  62. local function dofile(file)
  63. local program, reason = loadfile(file)
  64. if program then
  65. local result = table.pack(pcall(program))
  66. if result[1] then
  67. return table.unpack(result, 2, result.n)
  68. else
  69. error(result[2])
  70. end
  71. else
  72. error(reason)
  73. end
  74. end
  75. status("Initializing package management...")
  76. local package = dofile("/lib/package.lua")
  77. do
  78. _G.component = nil
  79. _G.computer = nil
  80. _G.process = nil
  81. _G.unicode = nil
  82. _G.package = package
  83. package.loaded.component = component
  84. package.loaded.computer = computer
  85. package.loaded.unicode = unicode
  86. package.preload["buffer"] = loadfile("/lib/buffer.lua")
  87. package.preload["filesystem"] = loadfile("/lib/filesystem.lua")
  88. _G.io = loadfile("/lib/io.lua")()
  89. package.delayed["text"] = true
  90. package.delayed["sh"] = true
  91. package.delayed["transforms"] = true
  92. package.delayed["term"] = true
  93. end
  94. status("Initializing file system...")
  95. require("filesystem").mount(computer.getBootAddress(), "/")
  96. package.preload={}
  97. status("Running boot scripts...")
  98. local function rom_invoke(method, ...)
  99. return component.invoke(computer.getBootAddress(), method, ...)
  100. end
  101. local scripts = {}
  102. for _, file in ipairs(rom_invoke("list", "boot")) do
  103. local path = "boot/" .. file
  104. if not rom_invoke("isDirectory", path) then
  105. table.insert(scripts, path)
  106. end
  107. end
  108. table.sort(scripts)
  109. for i = 1, #scripts do
  110. dofile(scripts[i])
  111. end
  112. status("Initializing components...")
  113. for c, t in component.list() do
  114. computer.pushSignal("component_added", c, t)
  115. end
  116. status("Initializing system...")
  117. computer.pushSignal("init") -- so libs know components are initialized.
  118. require("event").pull(1, "init") -- Allow init processing.
  119. _G.runlevel = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement