QuickMuffin8782-Alt

iGP OS Install

Oct 22nd, 2020 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.23 KB | None | 0 0
  1. logo = {
  2. " -------- ",
  3. "| iGP OS |",
  4. " -------- "
  5. }
  6.  
  7. function drawKeyboardHelp(keylist)
  8. w, h, x, y, bgColor, txtColor = term.getSize(), term.getCursorPos(), term.getBackgroundColor(), term.getTextColor()
  9. term.setCursorPos(1,h)
  10. term.clearLine()
  11. term.setBackgroundColor(colors.gray)
  12. term.setTextColor(colors.lightGray)
  13. if type(keyList) == "table" then
  14. for a, b in pairs(keyList) do
  15. write(b.key .. " = " .. b.action .. " ")
  16. end
  17. end
  18. term.setBackgroundColor(bgColor and bgColor or colors.gray)
  19. term.setTextColor(txtColor and txtColor or colors.white)
  20. term.setCursorPos(x,y)
  21. end
  22.  
  23. function menu(title, list, forceSelect, keyHelp, ...)
  24. local x, y = term.getSize()
  25. local align, selected = 0, (not forceSelect == nil and forceSelect or 1)
  26. local titleAlign = 0
  27. local titleHeight = 0
  28. local extra = {...}
  29.  
  30. if type(title) == "table" then
  31. for _, txt in pairs(title) do
  32. if #txt > titleAlign then
  33. titleAlign = #title
  34. titleHeight = titleHeight + 1
  35. end
  36. end
  37. else
  38. titleAlign = title:len()
  39. titleHeight = 0
  40. end
  41.  
  42. local function redraw()
  43. term.setBackgroundColor(term.isColor() and (extra[1] or colors.white) or colors.white)
  44. term.clear()
  45. term.setTextColor(term.isColor() and (extra[2] or colors.gray) or colors.gray)
  46. term.setCursorPos((x/2)-(#title/2), (y/2)-0-(#list/2)-(titleHeight/2)-1)
  47. if type(title) == "table" then
  48. for num, txt in pairs(title) do
  49. term.setCursorPos((x/2)-(#title/2), (y/2)-(#list/2)-(num-1)-1)
  50. term.write(txt)
  51. end
  52. else
  53. term.write(title)
  54. end
  55. for i, item in pairs(list) do
  56. local txt = item.text
  57. term.setCursorPos((x/2)-(align/2), (y/2)-(#list/2)-(titleHeight/2)+i)
  58. term.write(txt)
  59. end
  60. local helpBar = {
  61. {key = "Arrow Keys", action = "Select"},
  62. {key = "Enter", action = "Choose"}
  63. }
  64. if not keyHelp == nil then
  65. for a, b in pairs(keyHelp) do
  66. table.insert(helpBar, b)
  67. end
  68. end
  69. drawKeyboardHelp(helpBar)
  70. term.setBackgroundColor(colors.white)
  71. term.setTextColor(colors.lightGray)
  72. drawLogo(2,2)
  73. term.setTextColor(colors.gray)
  74. end
  75.  
  76. for _, item in pairs(list) do
  77. if #item.text > align then
  78. align = #item.text
  79. end
  80. end
  81.  
  82. redraw()
  83. while true do
  84. term.setCursorPos((x/2)-(align/2)-2, (y/2)-(#list/2)-(titleHeight/2)+selected)
  85. term.setTextColor(term.isColor() and (extra[2] or colors.gray) or colors.gray)
  86.  
  87. term.write(string.char(16))
  88. local event, key = os.pullEvent()
  89. if event == "mouse_scroll" then
  90. key = key == 1 and keys.down or keys.up
  91. elseif event == 'key_up' then
  92. key = nil -- only process key events
  93. end
  94.  
  95. if key == keys.enter or key == keys.right then
  96. return selected
  97. elseif key == keys.down then
  98. if selected == #list then
  99. selected = 0
  100. end
  101. selected = selected + 1
  102. elseif key == keys.up then
  103. if selected == 1 then
  104. selected = #list + 1
  105. end
  106. selected = selected - 1
  107. elseif event == 'char' then
  108. key = tonumber(key) or 0
  109. if list[key] then
  110. return key
  111. end
  112. end
  113.  
  114. local cx, cy = term.getCursorPos()
  115. term.setCursorPos(cx-1, cy)
  116. term.write(" ")
  117. end
  118. end
  119.  
  120. function drawLogo(x, y)
  121. term.setCursorPos(x,y)
  122. for a, b in pairs(logo) do
  123. term.setCursorPos(x,(y - 1) + a)
  124. write(b)
  125. end
  126. end
  127.  
  128. function cwrite(txt, y)
  129. local wide, high = term.getSize()
  130. local x = (wide / 2) - (txt:len() / 2)
  131. term.setCursorPos(x, y)
  132. write(txt)
  133. end
  134.  
  135. function recieveStartupKey(delay)
  136. local id = os.startTimer(delay)
  137. while true do
  138. local event, arg = os.pullEventRaw()
  139. if event=='timer' then
  140. os.cancelTimer(id)
  141. return nil
  142. elseif event == "key" or event == "char" then
  143. os.cancelTimer(id)
  144. return arg
  145. end
  146.  
  147. end
  148. end
  149.  
  150. term.setBackgroundColor(colors.white)
  151. term.setTextColor(colors.gray)
  152. term.clear()
  153. function drawBootScreen(mode, ...)
  154. local args = {...}
  155. if mode == 1 then
  156. term.setBackgroundColor(args[3] or colors.white)
  157. term.setTextColor(args[4] or colors.gray)
  158. if args[2] == true then
  159. term.clear()
  160. end
  161. wide, high = term.getSize()
  162. drawLogo((wide / 2) - (10 / 2), (high / 2) - (3 / 2))
  163. textPosY = (wide / 2) - (high / 2) + (3 / 2) + 2
  164. term.setCursorPos(1, textPosY)
  165. term.clearLine()
  166. term.setTextColor(args[5] or colors.lightGray)
  167. cwrite(args[1], textPosY)
  168. elseif mode == 2 then
  169. term.setBackgroundColor(colors.blue)
  170. term.setTextColor(colors.white)
  171. term.clear()
  172. term.setCursorPos(1,1)
  173. print("A problem has occurred on the installer, and we had to stop all the process. It is due to a error or something else.")
  174. print()
  175. print(args[1])
  176. print("ERROR CODE: " .. (not args[3] == nil and args[3] or "INSTALL_FATAL_ERROR"))
  177. print()
  178. print(args[2])
  179. end
  180. end
  181.  
  182. function doWait(txt, func, mode)
  183. parallel.waitForAny(function()
  184. local num = (mode and mode or 1)
  185. while true do
  186. drawBootScreen(num, txt .. "...")
  187. sleep(0.1)
  188. drawBootScreen(num, txt .. " ..")
  189. sleep(0.1)
  190. drawBootScreen(num, txt .. " .")
  191. sleep(0.1)
  192. drawBootScreen(num, txt .. " ")
  193. sleep(0.5)
  194. drawBootScreen(num, txt .. ". ")
  195. sleep(0.1)
  196. drawBootScreen(num, txt .. ".. ")
  197. sleep(0.1)
  198. end
  199. end, func)
  200. end
  201.  
  202. --< INSTALL MAIN >--
  203.  
  204. function iprint(txt, startTxt)
  205. print("[" .. os.date() .. "] " .. (not startTxt == nil and "[" .. startTxt .. "] " or "") .. txt )
  206. end
  207.  
  208. function promptText(txt)
  209. drawBootScreen(1, txt)
  210. local x, y = term.getCursorPos()
  211. term.setCursorPos(1, y+2)
  212. term.setBackgroundColor(colors.gray)
  213. term.setTextColor(colors.white)
  214. term.clearLine()
  215. local output = read()
  216. term.setBackgroundColor(colors.white)
  217. term.setTextColor(colors.gray)
  218. term.clearLine()
  219. return output
  220. end
  221.  
  222. function drawInstallScreen(mode, ...)
  223. local args = {...}
  224. if mode == 1 then
  225. if args[1] == 2 or args[1] == "endLoad" then
  226. drawBootScreen(1, "Welcome to iGP OS" .. (string.char(127)):rep(3))
  227. sleep(0.01)
  228. drawBootScreen(1, "Welcome to iGP OS ")
  229. sleep(0.1)
  230. drawBootScreen(1, "Welcome to iGP OS ")
  231. sleep(0.1)
  232. drawBootScreen(1, "Welcome to iGP OS ")
  233. sleep(0.1)
  234. end
  235. drawBootScreen(1, "Welcome to iGP OS")
  236. if args[1] == 1 or args[1] == "startLoad" then
  237. sleep(0.1)
  238. drawBootScreen(1, "Welcome to iGP OS ")
  239. sleep(0.1)
  240. drawBootScreen(1, "Welcome to iGP OS ")
  241. sleep(0.1)
  242. drawBootScreen(1, "Welcome to iGP OS ")
  243. sleep(0.1)
  244. drawBootScreen(1, "Welocme to iGP OS. ")
  245. sleep(0.1)
  246. drawBootScreen(1, "Welcome to iGP OS.. ")
  247. sleep(0.1)
  248. drawBootScreen(1, "Welcome to iGP OS...")
  249. sleep(0.1)
  250. end
  251. end
  252. end
  253.  
  254. function init()
  255. drawInstallScreen(1)
  256. sleep(1)
  257. drawBootScreen(1, "startLoad")
  258. doWait("Welcome to iGP OS", function()
  259. sleep(math.random(0.5, 2.25))
  260. end)
  261. drawBootScreen(1, "endLoad")
  262. local installURL = "https://gitlab.com/xenussoft-computercraft-organization/igp-os/-/raw/"
  263. local branch = "master/"
  264. local choice = nil
  265. choice = menu({" Install iGP OS", "", "Choose a version"}, { {text = "Beta Version"}, {text = "Normal Version (No release yet)"} })
  266. local version = nil
  267. if choice == 1 then branch = "beta" elseif choice == 2 then branch = "master" end
  268. choice = menu({" Install iGP OS", "", "Install Third-Party Apps?"}, { {text = "Yes"}, {text = "No"} })
  269. local installTPA = nil
  270. if choice == 1 then installTPA = true elseif choice == 2 then installTPA = false end
  271. drawBootScreen(1, "Please wait...", true)
  272. doWait("Please wait", function() sleep(math.random(0.5, 2.25)) end)
  273. local installText = "Starting Installation"
  274. parallel.waitForAny(function()
  275. function showLoadText(points)
  276. local clockt = 0.1
  277. repeat clockt = clockt - 0.01
  278. drawBootScreen(1, installText .. points)
  279. until not clockt > -0.01
  280. end
  281. while true do
  282. showLoadText("...")
  283. showLoadText(" ..")
  284. showLoadText(" .")
  285. showLoadText(" ")
  286. showLoadText(" ")
  287. showLoadText(" ")
  288. showLoadText(" ")
  289. showLoadText(" ")
  290. showLoadText(". ")
  291. showLoadText(".. ")
  292. end
  293. end, function()
  294. -- Install files and do text drawing at the same time.
  295. local installDIR = http.get(installURL .. branch .. "/installer/dir.lua")
  296. for a, b in installDIR do
  297. installText = "Installing " .. b .. " to computer"
  298. local f = fs.open(b, "w")
  299. f:write(http.get(installURL .. branch .. "/" ..b))
  300. f:close()
  301. end
  302. installText = "Finalizing"
  303. sleep(math.random(#installDIR / 20, #installDIR / 20 + 0.1))
  304. end)
  305. doWait("Rebooting now...", function() sleep(1) end)
  306. os.reboot()
  307. end
  308.  
  309. local ok, err = pcall(init)
  310.  
  311. if not ok then
  312. drawBootScreen(2, err, "If this problem repeats, contact XenusSoft. Meanwhile, press enter to exit.")
  313. while true do
  314. local ev, p1 = os.pullEventRaw()
  315. if ev == "key" then
  316. if p1 == keys.enter then
  317. drawBootScreen(2, err, "Release the enter key.")
  318. else
  319. drawBootScreen(2, err, "If this problem repeats, contact XenusSoft. Press the ENTER key, silly!")
  320. end
  321. elseif ev == "key_up" then
  322. if p1 == keys.enter then
  323. drawBootScreen(2, err, "Now exiting installer.")
  324. sleep(2)
  325. break
  326. end
  327. end
  328. end
  329. term.setBackgroundColor(colors.black)
  330. term.setTextColor(colors.yellow)
  331. term.clear()
  332. term.setCursorPos(1, 1)
  333. print(os.version())
  334. print("To retry installing, run the last command you entered by pressing the up arrow once, then hitting the enter key.")
  335. term.setTextColor(colors.white)
  336. end
  337.  
Add Comment
Please, Sign In to add comment