Advertisement
Guest User

Ind

a guest
Jul 2nd, 2014
1,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 0 0
  1. --[[ /gitget
  2.     GitHub downloading utility for CC.
  3.     Developed by apemanzilla.
  4.  
  5.     Modified into an installer by Detective_Smith
  6.    
  7.     This requires ElvishJerricco's JSON parsing API.
  8.     Direct link: http://pastebin.com/raw.php?i=4nRg9CHU
  9. --]]
  10.  
  11. if not http then
  12.   error("HTTP API Must be Enabled.")
  13. end
  14.  
  15. if not term.isColor() then
  16.   error("Advanced Computer Required to play this game")
  17. end
  18.  
  19. local function save(data, file, p)
  20.     local p = p or ""
  21.     local file = shell.resolve(file)
  22.     if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
  23.       if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
  24.       fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
  25.     end
  26.     local f = fs.open(file, "w")
  27.     if file == p.. "/MiniatureCraft" then
  28.       local line = "local MainFolder = '" ..p.. "'"
  29.       f.writeLine(line)
  30.     end
  31.     f.write(data)
  32.     f.close()
  33. end
  34.  
  35. local function download(url, file, p)
  36.     save(http.get(url).readAll(), file, p)
  37. end
  38.  
  39. if not json then
  40.     print()
  41.     print("Temporarily Downloading JSON api...\n(Credits to ElvishJerricco!)")
  42.     print()
  43.     download("http://pastebin.com/raw.php?i=4nRg9CHU","json")
  44.     os.loadAPI("json")
  45.     sleep(1)
  46. end
  47.  
  48. local blacklist = {
  49.   ".gitattributes",
  50.   ".gitignore",
  51.   "LICENSE",
  52.   "README.md"
  53. }
  54.  
  55. local function allowed(str)
  56.   for i = 1, #blacklist do
  57.     if blacklist[i] == str then
  58.       return false
  59.     end
  60.   end
  61.   return true
  62. end
  63.  
  64. term.clear()
  65. term.setCursorPos(1,1)
  66. print("Folder to install to: ")
  67. print()
  68. print("Leave Blank for default 'MiniatureCraft' Folder")
  69. print("Put '/' for root")
  70. term.setCursorPos(23, 1)
  71. term.setTextColor(colors.green)
  72. local path = read()
  73.  
  74. if path == "" then
  75.     path = "MiniatureCraft"
  76. end
  77.  
  78. term.setCursorPos(1, 6)
  79. term.setTextColor(colors.blue)
  80. print("Beginning Installation.")
  81. print()
  82.  
  83. local data = json.decode(http.get("https://api.github.com/repos/DetectiveSmith/MiniatureCraft/git/trees/master?recursive=1").readAll())
  84. if data.message and data.message == "Not found" then error("Could not find files.",2) else
  85.   for k,v in pairs(data.tree) do -- Create Directories
  86.         if v.type == "tree" then
  87.             fs.makeDir(fs.combine(path, v.path))
  88.             term.setTextColor(colors.green)
  89.             print("Creating Directory: " ..fs.combine(path, v.path))
  90.         end
  91.     end
  92.      print()
  93.   for k,v in pairs(data.tree) do -- Download Files
  94.         if v.type == "blob" then
  95.              if allowed(v.path) then
  96.         download("https://raw.github.com/DetectiveSmith/MiniatureCraft/master/"..v.path, fs.combine(path, v.path), path)
  97.             term.setTextColor(colors.yellow)
  98.                  term.write("Downloading File: ")
  99.         term.setTextColor(colors.green)
  100.         term.write(path.. "/")
  101.         term.setTextColor(colors.white)
  102.         term.write(v.path)
  103.         print()
  104.           end
  105.     end
  106.      end
  107. end
  108.  
  109. os.unloadAPI("json")
  110. fs.delete("json")
  111. term.setTextColor(colors.blue)
  112. if path == "/" then path = "" else path = path.. "/" end
  113. print()
  114. print("Installation Complete. Run " ..path.. "MiniatureCraft to play.")
  115. print()
  116. term.setTextColor(colors.white)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement