Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables (For random stuff)
- local yPos = 3
- local xPos = 1
- local currentVersion = 1.0
- --Functions
- function setColors(backColor, textColor)
- term.setBackgroundColor(backColor)
- term.setTextColor(textColor)
- end
- function printY(text, yLoc2)
- term.setCursorPos(1, yLoc2)
- print(text)
- if yLoc2 == yPos+1 then
- yPos = yPos+1
- end
- end
- function centerPrint(text, yPos)
- yPos = yPos or select(2, term.getCursorPos())+1
- w, h = term.getSize()
- term.setCursorPos(math.floor(w-text:len())/2, yPos)
- term.clearLine()
- print(text)
- end
- function centerPrintError(text, yPos)
- yPos = yPos or select(2, term.getCursorPos())+1
- w, h = term.getSize()
- term.setCursorPos(math.floor(w-text:len())/2, yPos)
- term.clearLine()
- printError(text)
- error()
- end
- local function downloadFiles(url, path)
- for i = 1, 3 do
- local response = http.get(url)
- if response then
- local data = response.readAll()
- if path then
- local dir = path:sub(1, #path-#fs.getName(path))
- fs.makeDir(dir)
- local f = fs.open(path, "w")
- f.write(data)
- f.close()
- sleep(2)
- installing = "false"
- centerPrint("Download success!")
- end
- return true
- end
- end
- centerPrintError("download: Download Failed")
- return false
- end
- function writeY(text, yLoc)
- term.setCursorPos(1, yLoc)
- write(text)
- if yLoc == yPos+1 then
- yPos = yPos+1
- end
- end
- --Main Code
- w, h = term.getSize()
- setColors(colors.white, colors.cyan)
- term.clear()
- centerPrint("Checking for updates...", 1)
- paintutils.drawLine(1, 2, w, 2, colors.blue)
- downloadFiles("https://raw.github.com/redstonefreak589/redos/master/version", ".redos/os/version")
- h = fs.open(".redos/os/version", "r")
- versionNumber = h.readAll()
- h.close()
- if versionNumber ~= currentVersion then
- term.setCursorPos(1,1)
- term.clearLine()
- centerPrint("New update available! Update now?", 1)
- event, key = os.pullEvent("key")
- if key == 21 then
- fs.delete(".redos/os/version")
- shell.run("/installer")
- elseif key == 49 then
- term.setCursorPos(1,1)
- term.clearLine()
- fs.delete(".redos/os/version")
- end
- else
- term.setCursorPos(1,1)
- term.clearLine()
- centerPrint("No updates avaible", 1)
- term.setCursorPos(1,1)
- term.clearLine()
- end
- centerPrint("Welcome To RedOS Login!", 1)
- setColors(colors.white, colors.cyan)
- centerPrint("RedOS Login System", 8)
- sleep(2)
- term.setCursorPos(1,3)
- printY("RedOS Login", 2)
- printY("Username", 3)
- writeY("> ", yPos+1)
- input = read()
- if fs.exists(".redos/login/user") then
- h = fs.open(".redos/login/user", "r")
- userName = h.readAll()
- h.close()
- if input == userName then
- term.setCursorPos(1,3)
- print("Password")
- yPos = yPos-1
- term.setCursorPos(1,4)
- term.clearLine()
- writeY("> ", yPos+1)
- input2 = read("*")
- if fs.exists(".redos/login/pass") then
- h = fs.open(".redos/login/pass", "r")
- password = h.readAll()
- h.close()
- if input2 == password then
- printY("Login Confirmed! Loading desktop...", yPos+1)
- sleep(2)
- if fs.exists(".redos/os/desktop") then
- shell.run(".redos/os/desktop")
- else
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- error("desktop: OS corrupt; destop file not present")
- end
- else
- printY("Password incorrect!", yPos+1)
- end
- end
- else
- printY("Username incorrect!", yPos+1)
- end
- else
- if not fs.exists(".redos/login") then
- fs.makeDir(".redos")
- fs.makeDir(".redos/login")
- end
- h = fs.open(".redos/login/user", "w")
- printY("Creating new user file", yPos+1)
- h.write(input)
- h.close()
- printY("Type in your new password", yPos+1)
- writeY("> ", yPos+1)
- newP = read("*")
- h = fs.open(".redos/login/pass", "w")
- h.write(newP)
- h.close()
- term.setCursorPos(1,8)
- term.clearLine()
- printY("Password File generated!", yPos+1)
- printY("OS rebooting...", yPos+1)
- sleep(2)
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement