Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Set these
- local pastebinIds = {"tjzbPDf2","8R0XnyNq"}
- local pastebinFileNames = {"gps","fsa"}
- local dropboxUserId = 0
- local dropboxIds = {}
- local dropboxFileNames = {}
- if not http then
- error( "Pastebin requires the HTTP API\nSet enableAPI_http to 1 in mod_ComputerCraft.cfg" )
- end
- local function dropboxGet(fileName,path,userId)
- if userId == nil then
- local iDropboxUser = 2813860
- else
- iDropboxUser = userId
- end
- local sVersion = string.sub(os.version(), -3)
- local fileGet = {}
- if sVersion == "1.4" then
- fileGet = http.get("https://dl.dropbox.com/u/" .. iDropboxUser .. "/" .. fileName)
- else
- fileGet = http.get("http://dl.dropbox.com/u/" .. iDropboxUser .. "/" ..fileName)
- end
- if path ~= nil then
- if fs.exists(path) == true then
- fs.delete(path)
- end
- local tFile = fs.open(path, "w")
- tFile.write(fileGet.readAll())
- tFile.close()
- fileGet.close()
- return true
- elseif path == nil then
- return fileGet.readAll()
- end
- end
- local function pastebinGet(code,path)
- local sCode = code
- local sFile = path
- local sPath = shell.resolve( sFile )
- if fs.exists( sPath ) then
- fs.delete(sPath)
- end
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( sPath, "w" )
- file.write( sResponse )
- file.close()
- return true
- else
- return false
- end
- end
- local function errorCheck()
- if pastebinIds == nil and dropboxIds == nil then
- return "Nothing to download!"
- end
- if #pastebinIds ~= pastebinFileNames then
- if #dropboxIds < #dropboxFileNames then
- return "Need more filenames for Pastebin!"
- elseif #pastebinFileNames < #pastebinIds then
- return "Need more ids for Pastebin!"
- end
- end
- if #dropboxIds ~= dropboxFileNames then
- if #dropboxIds < #dropboxFileNames then
- return "Need more filenames for Dropbox!"
- elseif #dropboxFileNames < #dropboxIds then
- return "Need more ids for Dropbox!"
- end
- end
- end
- if not errorCheck() then
- error(errorCheck())
- end
- print("Downloading the following files:")
- for i=1,#pastebinFileNames do
- print(pastebinFileNames[i])
- end
- for i=1,#dropboxFileNames do
- print(dropboxFileNames[i])
- end
- sleep(1)
- print()
- if pastebinIds ~= nil then
- for i=1,#pastebinIds do
- sleep(0.1)
- x,y = term.getCursorPos()
- term.clearLine()
- term.setCursorPos(1,y)
- write("Downloading from pastebin "..i.."/"..#pastebinIds)
- if pastebinGet(pastebinIds[i],pastebinFileNames[i]) then
- else
- error("Something went wrong with pastebin!")
- end
- end
- end
- if dropboxIds ~= nil then
- for i=1,#dropboxIds do
- sleep(0.1)
- x,y = term.getCursorPos()
- term.clearLine()
- term.setCursorPos(1,y)
- write("Downloading from dropbox "..i.."/"..#dropboxIds)
- if dropboxGet(dropboxFileNames[i],dropboxIds[i],dropboxUserId) then
- else
- error("Something went wrong with dropbox!")
- end
- end
- end
- print()
- term.setCursorPos(1,y)
- print("Downloaded Program Pack")
- return true
Add Comment
Please, Sign In to add comment