EnterYourName

AutoUpdate

May 12th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.03 KB | None | 0 0
  1. local newfiles = {"Wj6Ftupr"}
  2. local color = colors.red
  3.  
  4. function writeCentered (dy, s, device)
  5.     local w,h = device.getSize()
  6.     local x = math.floor((w - string.len(s)) / 2)
  7.     local y = math.floor(h/2) + dy
  8.     device.setCursorPos(x,y)
  9.     device.clearLine()
  10.     device.write(s)
  11. end
  12.  
  13. function drawLineCentered (dy, width, device)
  14.     local w,h = device.getSize()
  15.     local x = math.floor((w - width) / 2)
  16.     local y = math.floor(h/2) + dy
  17.     local str = ""
  18.     for i = 1,width do
  19.         str = str.." "
  20.     end
  21.     device.setCursorPos(x,y)
  22.     device.clearLine()
  23.     device.write(str)
  24. end
  25.  
  26. function drawProgressBar (dy, widthfilled,widthempty,colorfull,colorempty,device)
  27.  
  28.     local w,h = device.getSize()
  29.     local x = math.floor((w-(widthfilled+widthempty)) / 2)
  30.     local y = math.floor(h/2) + dy
  31.     local strfilled = ""
  32.     for i = 1,widthfilled do
  33.         strfilled = strfilled.." "
  34.     end
  35.     local strempty = ""
  36.     for i = 1,widthempty do
  37.         strempty = strempty.." "
  38.     end
  39.     device.setCursorPos(x,y)
  40.     device.clearLine()
  41.     device.setBackgroundColor(colorfull)
  42.     device.write(strfilled)
  43.     device.setBackgroundColor(colorempty)
  44.     device.write(strempty)
  45.     device.setBackgroundColor(colors.black)
  46.    
  47. end
  48.  
  49. function updateProgressbar(progress,total,device)
  50.  
  51.     local width = 40
  52.     local ratio = progress/total
  53.     local filled = 40*ratio
  54.     local empty = width-filled
  55.     drawProgressBar(0, filled,empty,color,colors.gray,device)
  56.  
  57. end
  58.  
  59. local monitor = peripheral.find("monitor", function(name, object) return object.isColour() end)
  60.  
  61. monitor.setBackgroundColor(colors.black)
  62. monitor.clear()
  63. monitor.setTextColor(color)
  64. writeCentered (-1, "-- Downloading Packages --" ,monitor)
  65. monitor.setBackgroundColor(colors.black)
  66.  
  67. local total = table.getn(newfiles)
  68.  
  69. if fs.exists(_G.osfolder) then
  70.     fs.delete(_G.osfolder)
  71. end
  72.  
  73. updateProgressbar(0,total,monitor)
  74. writeCentered (1, "0%", monitor)
  75. sleep(1)
  76.  
  77. for i,file in ipairs(newfiles) do
  78.    
  79.     shell.run("pastebin get " .. file .. " " .. osfolder.."/"..file)
  80.     updateProgressbar(i,total,monitor)
  81.     writeCentered (1, math.floor(i*100/total).."%",monitor)
  82. end
Add Comment
Please, Sign In to add comment