Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- logo = {
- " -------- ",
- "| iGP OS |",
- " -------- "
- }
- function drawKeyboardHelp(keylist)
- w, h, x, y, bgColor, txtColor = term.getSize(), term.getCursorPos(), term.getBackgroundColor(), term.getTextColor()
- term.setCursorPos(1,h)
- term.clearLine()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.lightGray)
- if type(keyList) == "table" then
- for a, b in pairs(keyList) do
- write(b.key .. " = " .. b.action .. " ")
- end
- end
- term.setBackgroundColor(bgColor and bgColor or colors.gray)
- term.setTextColor(txtColor and txtColor or colors.white)
- term.setCursorPos(x,y)
- end
- function menu(title, list, forceSelect, keyHelp, ...)
- local x, y = term.getSize()
- local align, selected = 0, (not forceSelect == nil and forceSelect or 1)
- local titleAlign = 0
- local titleHeight = 0
- local extra = {...}
- if type(title) == "table" then
- for _, txt in pairs(title) do
- if #txt > titleAlign then
- titleAlign = #title
- titleHeight = titleHeight + 1
- end
- end
- else
- titleAlign = title:len()
- titleHeight = 0
- end
- local function redraw()
- term.setBackgroundColor(term.isColor() and (extra[1] or colors.white) or colors.white)
- term.clear()
- term.setTextColor(term.isColor() and (extra[2] or colors.gray) or colors.gray)
- term.setCursorPos((x/2)-(#title/2), (y/2)-0-(#list/2)-(titleHeight/2)-1)
- if type(title) == "table" then
- for num, txt in pairs(title) do
- term.setCursorPos((x/2)-(#title/2), (y/2)-(#list/2)-(num-1)-1)
- term.write(txt)
- end
- else
- term.write(title)
- end
- for i, item in pairs(list) do
- local txt = item.text
- term.setCursorPos((x/2)-(align/2), (y/2)-(#list/2)-(titleHeight/2)+i)
- term.write(txt)
- end
- local helpBar = {
- {key = "Arrow Keys", action = "Select"},
- {key = "Enter", action = "Choose"}
- }
- if not keyHelp == nil then
- for a, b in pairs(keyHelp) do
- table.insert(helpBar, b)
- end
- end
- drawKeyboardHelp(helpBar)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.lightGray)
- drawLogo(2,2)
- term.setTextColor(colors.gray)
- end
- for _, item in pairs(list) do
- if #item.text > align then
- align = #item.text
- end
- end
- redraw()
- while true do
- term.setCursorPos((x/2)-(align/2)-2, (y/2)-(#list/2)-(titleHeight/2)+selected)
- term.setTextColor(term.isColor() and (extra[2] or colors.gray) or colors.gray)
- term.write(string.char(16))
- local event, key = os.pullEvent()
- if event == "mouse_scroll" then
- key = key == 1 and keys.down or keys.up
- elseif event == 'key_up' then
- key = nil -- only process key events
- end
- if key == keys.enter or key == keys.right then
- return selected
- elseif key == keys.down then
- if selected == #list then
- selected = 0
- end
- selected = selected + 1
- elseif key == keys.up then
- if selected == 1 then
- selected = #list + 1
- end
- selected = selected - 1
- elseif event == 'char' then
- key = tonumber(key) or 0
- if list[key] then
- return key
- end
- end
- local cx, cy = term.getCursorPos()
- term.setCursorPos(cx-1, cy)
- term.write(" ")
- end
- end
- function drawLogo(x, y)
- term.setCursorPos(x,y)
- for a, b in pairs(logo) do
- term.setCursorPos(x,(y - 1) + a)
- write(b)
- end
- end
- function cwrite(txt, y)
- local wide, high = term.getSize()
- local x = (wide / 2) - (txt:len() / 2)
- term.setCursorPos(x, y)
- write(txt)
- end
- function recieveStartupKey(delay)
- local id = os.startTimer(delay)
- while true do
- local event, arg = os.pullEventRaw()
- if event=='timer' then
- os.cancelTimer(id)
- return nil
- elseif event == "key" or event == "char" then
- os.cancelTimer(id)
- return arg
- end
- end
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- term.clear()
- function drawBootScreen(mode, ...)
- local args = {...}
- if mode == 1 then
- term.setBackgroundColor(args[3] or colors.white)
- term.setTextColor(args[4] or colors.gray)
- if args[2] == true then
- term.clear()
- end
- wide, high = term.getSize()
- drawLogo((wide / 2) - (10 / 2), (high / 2) - (3 / 2))
- textPosY = (wide / 2) - (high / 2) + (3 / 2) + 2
- term.setCursorPos(1, textPosY)
- term.clearLine()
- term.setTextColor(args[5] or colors.lightGray)
- cwrite(args[1], textPosY)
- elseif mode == 2 then
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- 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.")
- print()
- print(args[1])
- print("ERROR CODE: " .. (not args[3] == nil and args[3] or "INSTALL_FATAL_ERROR"))
- print()
- print(args[2])
- end
- end
- function doWait(txt, func, mode)
- parallel.waitForAny(function()
- local num = (mode and mode or 1)
- while true do
- drawBootScreen(num, txt .. "...")
- sleep(0.1)
- drawBootScreen(num, txt .. " ..")
- sleep(0.1)
- drawBootScreen(num, txt .. " .")
- sleep(0.1)
- drawBootScreen(num, txt .. " ")
- sleep(0.5)
- drawBootScreen(num, txt .. ". ")
- sleep(0.1)
- drawBootScreen(num, txt .. ".. ")
- sleep(0.1)
- end
- end, func)
- end
- --< INSTALL MAIN >--
- function iprint(txt, startTxt)
- print("[" .. os.date() .. "] " .. (not startTxt == nil and "[" .. startTxt .. "] " or "") .. txt )
- end
- function promptText(txt)
- drawBootScreen(1, txt)
- local x, y = term.getCursorPos()
- term.setCursorPos(1, y+2)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.clearLine()
- local output = read()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- term.clearLine()
- return output
- end
- function drawInstallScreen(mode, ...)
- local args = {...}
- if mode == 1 then
- if args[1] == 2 or args[1] == "endLoad" then
- drawBootScreen(1, "Welcome to iGP OS" .. (string.char(127)):rep(3))
- sleep(0.01)
- drawBootScreen(1, "Welcome to iGP OS ")
- sleep(0.1)
- drawBootScreen(1, "Welcome to iGP OS ")
- sleep(0.1)
- drawBootScreen(1, "Welcome to iGP OS ")
- sleep(0.1)
- end
- drawBootScreen(1, "Welcome to iGP OS")
- if args[1] == 1 or args[1] == "startLoad" then
- sleep(0.1)
- drawBootScreen(1, "Welcome to iGP OS ")
- sleep(0.1)
- drawBootScreen(1, "Welcome to iGP OS ")
- sleep(0.1)
- drawBootScreen(1, "Welcome to iGP OS ")
- sleep(0.1)
- drawBootScreen(1, "Welocme to iGP OS. ")
- sleep(0.1)
- drawBootScreen(1, "Welcome to iGP OS.. ")
- sleep(0.1)
- drawBootScreen(1, "Welcome to iGP OS...")
- sleep(0.1)
- end
- end
- end
- function init()
- drawInstallScreen(1)
- sleep(1)
- drawBootScreen(1, "startLoad")
- doWait("Welcome to iGP OS", function()
- sleep(math.random(0.5, 2.25))
- end)
- drawBootScreen(1, "endLoad")
- local installURL = "https://gitlab.com/xenussoft-computercraft-organization/igp-os/-/raw/"
- local branch = "master/"
- local choice = nil
- choice = menu({" Install iGP OS", "", "Choose a version"}, { {text = "Beta Version"}, {text = "Normal Version (No release yet)"} })
- local version = nil
- if choice == 1 then branch = "beta" elseif choice == 2 then branch = "master" end
- choice = menu({" Install iGP OS", "", "Install Third-Party Apps?"}, { {text = "Yes"}, {text = "No"} })
- local installTPA = nil
- if choice == 1 then installTPA = true elseif choice == 2 then installTPA = false end
- drawBootScreen(1, "Please wait...", true)
- doWait("Please wait", function() sleep(math.random(0.5, 2.25)) end)
- local installText = "Starting Installation"
- parallel.waitForAny(function()
- function showLoadText(points)
- local clockt = 0.1
- repeat clockt = clockt - 0.01
- drawBootScreen(1, installText .. points)
- until not clockt > -0.01
- end
- while true do
- showLoadText("...")
- showLoadText(" ..")
- showLoadText(" .")
- showLoadText(" ")
- showLoadText(" ")
- showLoadText(" ")
- showLoadText(" ")
- showLoadText(" ")
- showLoadText(". ")
- showLoadText(".. ")
- end
- end, function()
- -- Install files and do text drawing at the same time.
- local installDIR = http.get(installURL .. branch .. "/installer/dir.lua")
- for a, b in installDIR do
- installText = "Installing " .. b .. " to computer"
- local f = fs.open(b, "w")
- f:write(http.get(installURL .. branch .. "/" ..b))
- f:close()
- end
- installText = "Finalizing"
- sleep(math.random(#installDIR / 20, #installDIR / 20 + 0.1))
- end)
- doWait("Rebooting now...", function() sleep(1) end)
- os.reboot()
- end
- local ok, err = pcall(init)
- if not ok then
- drawBootScreen(2, err, "If this problem repeats, contact XenusSoft. Meanwhile, press enter to exit.")
- while true do
- local ev, p1 = os.pullEventRaw()
- if ev == "key" then
- if p1 == keys.enter then
- drawBootScreen(2, err, "Release the enter key.")
- else
- drawBootScreen(2, err, "If this problem repeats, contact XenusSoft. Press the ENTER key, silly!")
- end
- elseif ev == "key_up" then
- if p1 == keys.enter then
- drawBootScreen(2, err, "Now exiting installer.")
- sleep(2)
- break
- end
- end
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.yellow)
- term.clear()
- term.setCursorPos(1, 1)
- print(os.version())
- print("To retry installing, run the last command you entered by pressing the up arrow once, then hitting the enter key.")
- term.setTextColor(colors.white)
- end
Add Comment
Please, Sign In to add comment