Advertisement
MCFunRide

GameBox Installer

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