Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ /gitget
- GitHub downloading utility for CC.
- Developed by apemanzilla.
- Modified into an installer by Detective_Smith
- This requires ElvishJerricco's JSON parsing API.
- Direct link: http://pastebin.com/raw.php?i=4nRg9CHU
- --]]
- if not http then
- error("HTTP API Must be Enabled.")
- end
- if not term.isColor() then
- error("Advanced Computer Required to play this game")
- end
- local function save(data, file, p)
- local p = p or ""
- local file = shell.resolve(file)
- if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
- if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
- fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
- end
- local f = fs.open(file, "w")
- if file == p.. "/MiniatureCraft" then
- local line = "local MainFolder = '" ..p.. "'"
- f.writeLine(line)
- end
- f.write(data)
- f.close()
- end
- local function download(url, file, p)
- save(http.get(url).readAll(), file, p)
- end
- if not json then
- print()
- print("Temporarily Downloading JSON api...\n(Credits to ElvishJerricco!)")
- print()
- download("http://pastebin.com/raw.php?i=4nRg9CHU","json")
- os.loadAPI("json")
- sleep(1)
- end
- local blacklist = {
- ".gitattributes",
- ".gitignore",
- "LICENSE",
- "README.md"
- }
- local function allowed(str)
- for i = 1, #blacklist do
- if blacklist[i] == str then
- return false
- end
- end
- return true
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Folder to install to: ")
- print()
- print("Leave Blank for default 'MiniatureCraft' Folder")
- print("Put '/' for root")
- term.setCursorPos(23, 1)
- term.setTextColor(colors.green)
- local path = read()
- if path == "" then
- path = "MiniatureCraft"
- end
- term.setCursorPos(1, 6)
- term.setTextColor(colors.blue)
- print("Beginning Installation.")
- print()
- local data = json.decode(http.get("https://api.github.com/repos/DetectiveSmith/MiniatureCraft/git/trees/master?recursive=1").readAll())
- if data.message and data.message == "Not found" then error("Could not find files.",2) else
- for k,v in pairs(data.tree) do -- Create Directories
- if v.type == "tree" then
- fs.makeDir(fs.combine(path, v.path))
- term.setTextColor(colors.green)
- print("Creating Directory: " ..fs.combine(path, v.path))
- end
- end
- print()
- for k,v in pairs(data.tree) do -- Download Files
- if v.type == "blob" then
- if allowed(v.path) then
- download("https://raw.github.com/DetectiveSmith/MiniatureCraft/master/"..v.path, fs.combine(path, v.path), path)
- term.setTextColor(colors.yellow)
- term.write("Downloading File: ")
- term.setTextColor(colors.green)
- term.write(path.. "/")
- term.setTextColor(colors.white)
- term.write(v.path)
- print()
- end
- end
- end
- end
- os.unloadAPI("json")
- fs.delete("json")
- term.setTextColor(colors.blue)
- if path == "/" then path = "" else path = path.. "/" end
- print()
- print("Installation Complete. Run " ..path.. "MiniatureCraft to play.")
- print()
- term.setTextColor(colors.white)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement