Advertisement
Siftos

sif-standard-update-installer

Oct 11th, 2023 (edited)
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. --sif-standard-installer
  2. local url = "https://raw.github.com/Siftos/sif-standard/latest-release/"
  3. --Vars
  4. --Functions
  5. local function save(content, filename)
  6.     if fs.exists("sif-standard/"..filename) then
  7.         fs.delete("sif-standard"..filename)
  8.     end
  9.     local file = fs.open("sif-standard/"..filename, "w")
  10.     file.write(content)
  11.     file.close()
  12. end
  13.  
  14. local function download(file)
  15.    
  16.     save(http.get(url..file).readAll(), file)
  17. end
  18.  
  19. --RUN
  20.  
  21. if not fs.isDir("/sif-standard") then
  22.     fs.makeDir("/sif-standard")
  23. end
  24.  
  25. download("json.lua")
  26.  
  27. os.loadAPI("sif-standard/json.lua")
  28.  
  29. local filenames = {}
  30.  
  31. print(" ")
  32. print("Fetching update...")
  33. local err, response_table = json.decode(http.get("https://api.github.com/repos/Siftos/sif-standard/git/trees/latest-release?recursive=1").readAll())
  34.  
  35. for i, v in ipairs(response_table["tree"]) do
  36.     filenames[#filenames + 1] = v["path"]
  37. end
  38.  
  39. local x, y = term.getCursorPos()
  40. local percent = 0
  41. term.setTextColor(colors.white)
  42. term.write("Updating sif-standard... ["..percent.."%]")
  43. for i = 1, #filenames do
  44.     term.setCursorPos(x,y)
  45.     download(filenames[i])
  46.     percent = math.floor(i/#filenames * 100)
  47.     term.setTextColor(colors.white)
  48.     term.write("Updating sif-standard... ")
  49.     term.setTextColor(colors.yellow)
  50.     if percent == 100 then
  51.         term.setTextColor(colors.lime)
  52.     end
  53.     term.write("["..percent.."%]")
  54. end
  55.  
  56. term.setTextColor(colors.white)
  57. print(" ")
  58. print("Sif-standard libraries are updated!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement