Advertisement
Guest User

Untitled

a guest
May 23rd, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1. --Variables (For random stuff)
  2. local yPos = 3
  3. local xPos = 1
  4. local currentVersion = 1.0
  5. --Functions
  6. function setColors(backColor, textColor)
  7. term.setBackgroundColor(backColor)
  8. term.setTextColor(textColor)
  9. end
  10. function printY(text, yLoc2)
  11. term.setCursorPos(1, yLoc2)
  12. print(text)
  13. if yLoc2 == yPos+1 then
  14.   yPos = yPos+1
  15. end
  16. end
  17. function centerPrint(text, yPos)
  18.   yPos = yPos or select(2, term.getCursorPos())+1
  19.   w, h = term.getSize()
  20.   term.setCursorPos(math.floor(w-text:len())/2, yPos)
  21.   term.clearLine()
  22.   print(text)
  23. end
  24. function centerPrintError(text, yPos)
  25.   yPos = yPos or select(2, term.getCursorPos())+1
  26.   w, h = term.getSize()
  27.   term.setCursorPos(math.floor(w-text:len())/2, yPos)
  28.   term.clearLine()
  29.   printError(text)
  30.   error()
  31. end
  32. local function downloadFiles(url, path)
  33. for i = 1, 3 do
  34.   local response = http.get(url)
  35.   if response then
  36.    local data = response.readAll()
  37.    if path then
  38.         local dir = path:sub(1, #path-#fs.getName(path))
  39.         fs.makeDir(dir)
  40.         local f = fs.open(path, "w")
  41.         f.write(data)
  42.         f.close()
  43.         sleep(2)
  44.         installing = "false"
  45.         centerPrint("Download success!")
  46.    end
  47.    return true
  48.   end
  49. end
  50. centerPrintError("download: Download Failed")
  51. return false
  52. end
  53. function writeY(text, yLoc)
  54. term.setCursorPos(1, yLoc)
  55. write(text)
  56. if yLoc == yPos+1 then
  57.   yPos = yPos+1
  58. end
  59. end
  60. --Main Code
  61. w, h = term.getSize()
  62. setColors(colors.white, colors.cyan)
  63. term.clear()
  64. centerPrint("Checking for updates...", 1)
  65. paintutils.drawLine(1, 2, w, 2, colors.blue)
  66. downloadFiles("https://raw.github.com/redstonefreak589/redos/master/version", ".redos/os/version")
  67. h = fs.open(".redos/os/version", "r")
  68. versionNumber = h.readAll()
  69. h.close()
  70. if versionNumber ~= currentVersion then
  71. term.setCursorPos(1,1)
  72. term.clearLine()
  73. centerPrint("New update available! Update now?", 1)
  74. event, key = os.pullEvent("key")
  75. if key == 21 then
  76.   fs.delete(".redos/os/version")
  77.   shell.run("/installer")
  78. elseif key == 49 then
  79.   term.setCursorPos(1,1)
  80.   term.clearLine()
  81.   fs.delete(".redos/os/version")
  82. end
  83. else
  84. term.setCursorPos(1,1)
  85. term.clearLine()
  86. centerPrint("No updates avaible", 1)
  87. term.setCursorPos(1,1)
  88. term.clearLine()
  89. end
  90. centerPrint("Welcome To RedOS Login!", 1)
  91. setColors(colors.white, colors.cyan)
  92. centerPrint("RedOS Login System", 8)
  93. sleep(2)
  94. term.setCursorPos(1,3)
  95. printY("RedOS Login", 2)
  96. printY("Username", 3)
  97. writeY("> ", yPos+1)
  98. input = read()
  99. if fs.exists(".redos/login/user") then
  100. h = fs.open(".redos/login/user", "r")
  101. userName = h.readAll()
  102. h.close()
  103. if input == userName then
  104.   term.setCursorPos(1,3)
  105.   print("Password")
  106.   yPos = yPos-1
  107.   term.setCursorPos(1,4)
  108.   term.clearLine()
  109.   writeY("> ", yPos+1)
  110.   input2 = read("*")
  111.   if fs.exists(".redos/login/pass") then
  112.    h = fs.open(".redos/login/pass", "r")
  113.    password = h.readAll()
  114.    h.close()
  115.    if input2 == password then
  116.         printY("Login Confirmed! Loading desktop...", yPos+1)
  117.         sleep(2)
  118.         if fs.exists(".redos/os/desktop") then
  119.          shell.run(".redos/os/desktop")
  120.         else
  121.          term.setBackgroundColor(colors.black)
  122.          term.clear()
  123.          term.setCursorPos(1,1)
  124.          error("desktop: OS corrupt; destop file not present")
  125.         end
  126.    else
  127.         printY("Password incorrect!", yPos+1)
  128.    end
  129.   end
  130. else
  131.   printY("Username incorrect!", yPos+1)
  132. end
  133. else
  134. if not fs.exists(".redos/login") then
  135.   fs.makeDir(".redos")
  136.   fs.makeDir(".redos/login")
  137. end
  138. h = fs.open(".redos/login/user", "w")
  139. printY("Creating new user file", yPos+1)
  140. h.write(input)
  141. h.close()
  142. printY("Type in your new password", yPos+1)
  143. writeY("> ", yPos+1)
  144. newP = read("*")
  145. h = fs.open(".redos/login/pass", "w")
  146. h.write(newP)
  147. h.close()
  148. term.setCursorPos(1,8)
  149. term.clearLine()
  150. printY("Password File generated!", yPos+1)
  151. printY("OS rebooting...", yPos+1)
  152. sleep(2)
  153. os.reboot()
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement