Advertisement
MCFunRide

GameBox Installer

Jun 7th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. local files = {
  2. }
  3.  
  4. local githubUser = "MCFunRide"
  5. local githubRepo = "GameBox"
  6. local githubBranch = "master"
  7.  
  8. local installerName = nil -- if you need one, this will replace "Installer for user/repo, branch branch"
  9.  
  10. local function clear()
  11. term.clear()
  12. term.setCursorPos(1, 1)
  13. end
  14.  
  15. local function httpGet(url, save)
  16. if not url then
  17. error("not enough arguments, expected 1 or 2", 2)
  18. end
  19. local remote = http.get(url)
  20. if not remote then
  21. return false
  22. end
  23. local text = remote.readAll()
  24. remote.close()
  25. if save then
  26. local file = fs.open(save, "w")
  27. file.write(text)
  28. file.close()
  29. return true
  30. end
  31. return text
  32. end
  33.  
  34. local function get(user, repo, bran, path, save)
  35. if not user or not repo or not bran or not path then
  36. error("not enough arguments, expected 4 or 5", 2)
  37. end
  38. local url = "https://raw.github.com/"..user.."/"..repo.."/"..bran.."/"..path
  39. local remote = http.get(url)
  40. if not remote then
  41. return false
  42. end
  43. local text = remote.readAll()
  44. remote.close()
  45. if save then
  46. local file = fs.open(save, "w")
  47. file.write(text)
  48. file.close()
  49. return true
  50. end
  51. return text
  52. end
  53.  
  54. local function getFile(file, target)
  55. return get(githubUser, githubRepo, githubBranch, file, target)
  56. end
  57.  
  58. shell.setDir("")
  59.  
  60. clear()
  61.  
  62. print(installerName or ("Installer for " .. githubUser .. "/" .. githubRepo .. ", branch " .. githubBranch))
  63. print("Getting files...")
  64. local fileCount = 0
  65. for _ in pairs(files) do
  66. fileCount = fileCount + 1
  67. end
  68. local filesDownloaded = 0
  69.  
  70. local w, h = term.getSize()
  71.  
  72. for k, v in pairs(files) do
  73. term.setTextColor(colors.black)
  74. term.setBackgroundColor(colors.white)
  75. clear()
  76. term.setCursorPos(2, 2)
  77. print(installerName or ("Installer for " .. githubUser .. "/" .. githubRepo .. ", branch " .. githubBranch))
  78. term.setCursorPos(2, 4)
  79. print("File: "..v)
  80. term.setCursorPos(2, h - 1)
  81. print(tostring(math.floor(filesDownloaded / fileCount * 100)).."% - "..tostring(filesDownloaded + 1).."/"..tostring(fileCount))
  82. local ok = k:sub(1, 4) == "ext:" and httpGet(k:sub(5), v) or getFile(k, v)
  83. if not ok then
  84. if term.isColor() then
  85. term.setTextColor(colors.red)
  86. end
  87. term.setCursorPos(2, 6)
  88. print("Error getting file:")
  89. term.setCursorPos(2, 7)
  90. print(k)
  91. sleep(1)
  92. end
  93. filesDownloaded = filesDownloaded + 1
  94. end
  95. clear()
  96. term.setCursorPos(2, 2)
  97. print("Press any key to continue.")
  98. local w, h = term.getSize()
  99. term.setCursorPos(2, h-1)
  100. print("100% - "..tostring(filesDownloaded).."/"..tostring(fileCount))
  101. os.pullEvent("key")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement