Guest User

installer

a guest
Jul 17th, 2014
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.14 KB | None | 0 0
  1. --Setting the colors
  2. term.setBackgroundColor(colors.white)
  3. term.setTextColor(colors.cyan)
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. loading = "yes"
  7. installing = "true"
  8. --Functions
  9. local function centerPrint(text)
  10.   local x, y = term.getSize()
  11.   local x2, y2 = term.getCursorPos()
  12.   term.setCursorPos(math.ceil((x/2) -(text:len()/2)), y2)
  13.   write(text)
  14.   term.setCursorPos(1,1)
  15. end
  16. local function downloadFiles(url, path)
  17. for i = 1, 3 do
  18.   local response = http.get(url)
  19.   if response then
  20.    local data = response.readAll()
  21.    if path then
  22.     local f = io.open(path, "w")
  23.     f:write(data)
  24.     f:close()
  25.     sleep(2)
  26.     installing = "false"
  27.    end
  28.    return true
  29.   end
  30. end
  31. centerPrint(error("download: Download Failed"))
  32. return false
  33. end
  34.  
  35.  
  36. local function load(yLoc)
  37.   w, h = term.getSize()
  38.   local x2, y2 = term.getCursorPos()
  39.   loc = math.ceil(w/2)
  40.   loc2 = yLoc
  41.   while loading == "yes" do
  42.   term.setCursorPos(loc-3, loc2)
  43.   print("|O---|")
  44.   term.setCursorPos(loc-3, loc2)
  45.   sleep(0.5)
  46.   print("|-O--|")
  47.   term.setCursorPos(loc-3, loc2)
  48.   sleep(0.5)
  49.   print("|--O-|")
  50.   term.setCursorPos(loc-3, loc2)
  51.   sleep(0.5)
  52.   print("|---O|")
  53.   term.setCursorPos(loc-3, loc2)
  54.   sleep(0.5)
  55.   print("|--O-|")
  56.   term.setCursorPos(loc-3, loc2)
  57.   sleep(0.5)
  58.   print("|-O--|")
  59.   term.setCursorPos(loc-3, loc2)
  60.   sleep(0.5)
  61.  end
  62. end
  63. --Main Code
  64. w, h = term.getSize()
  65. centerPrint("RedOS Installer")
  66. paintutils.drawLine(1, 2, w, 2, colors.blue)
  67. term.setTextColor(colors.cyan)
  68. term.setBackgroundColor(colors.white)
  69. term.setCursorPos(1, 4)
  70. centerPrint("Installing Files....")
  71. if not fs.exists(".redos") then
  72.     fs.makeDir(".redos")
  73.     if not fs.exists(".redos/os") then
  74.         fs.makeDir(".redos/os")
  75.     end
  76.     if not fs.exists(".redos/programs") then
  77.         fs.makeDir(".redos/programs")
  78.     end
  79. end
  80. parallel.waitForAny(function() downloadFiles("https://raw.github.com/redstonefreak589/redos/master/RedOS", ".redos/os/RedOS") end, function() load(9) end)
  81. parallel.waitForAny(function() downloadFiles("https://raw.github.com/redstonefreak589/redos/master/Browser", ".redos/programs/browser") end, function() load(9) end)
  82. parallel.waitForAny(function() downloadFiles("https://raw.github.com/redstonefreak589/redos/master/desktop", ".redos/os/desktop") end, function() load(9) end)
  83. parallel.waitForAny(function() downloadFiles("https://raw.github.com/redstonefreak589/redos/master/hashing", ".redos/os/hashing") end, function() load(9) end)
  84. centerPrint("Download Success!", 9)
  85. sleep(2)
  86. term.setCursorPos(1,4)
  87. term.clearLine()
  88. centerPrint("Do you want to run RedOS on startup? Y | N")
  89. event, key = os.pullEvent("key")
  90. if key == 21 then
  91.     if fs.exists("/startup.old") then
  92.         fs.delete("/startup.old")
  93.     end
  94.     if fs.exists("/startup") then
  95.         fs.move("/startup", "/startup.old")
  96.     end
  97.     downloadFiles("https://raw.github.com/redstonefreak589/redos/master/startup", "startup")
  98.     term.setBackgroundColor(colors.black)
  99.     term.setTextColor(colors.white)
  100.     os.reboot()
  101. elseif key == 49 then
  102.     downloadFiles("https://raw.github.com/redstonefreak589/redos/master/redos-start", "redos-start")
  103.     term.setBackgroundColor(colors.black)
  104.     term.setTextColor(colors.white)
  105.     os.reboot()
  106. end
Advertisement
Add Comment
Please, Sign In to add comment