Advertisement
superanonymous

OCInstall

Nov 23rd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. --Import APIs
  2. local component = require("component")
  3. local fs = require("filesystem")
  4. local shell = require("shell")
  5. local ser = require("serialization")
  6.  
  7. --Check for internet card
  8. if not component.isAvailable("internet") then
  9.   print("Need an internet card!")
  10.   return
  11. end
  12. local internet = require("internet")
  13.  
  14. --Begin internal code
  15. local baseUrl = "http://shaunkeys.com/ccfiles"
  16. local rootFolder = "/oc"
  17. local download = baseUrl .. "/download"
  18. local list = "/recursiveList" .. rootFolder
  19.  
  20. local args = {"/bin"}
  21. if type(args[1])~="string" then
  22.     args[1]=""
  23. end
  24.  
  25. function dl(url)
  26.     local res = internet.request(url)
  27.     local string = ""
  28.     for blob in res do
  29.         string = string..blob
  30.     end
  31.     return string
  32. end
  33.  
  34. --Build download table
  35. --print(baseUrl .. fs.concat(list,( string.sub(args[1],1,1)=="/" and "" or shell.getWorkingDirectory() ),args[1]))
  36. local fileUrls = ser.unserialize(dl(baseUrl .. fs.concat(list,( string.sub(args[1],1,1)=="/" and "" or shell.getWorkingDirectory() ),args[1])))
  37. --print(ser.serialize(fileUrls))
  38. for k,v in pairs(fileUrls) do
  39.  
  40.     local remoteSegments = fs.segments(v)
  41.     table.remove(remoteSegments,1) --Remove oc folder
  42.  
  43.     local segments = fs.segments(fs.concat(table.unpack(remoteSegments)))
  44.     completedDirs = ""
  45.     for i = 1, #segments-1 do
  46.         completedDirs = completedDirs .. "/" .. segments[i]
  47.         if not fs.exists(completedDirs) then
  48.             fs.makeDirectory(completedDirs)
  49.         end
  50.     end
  51.     if v ~= "" then
  52.         local path = "/"..fs.concat(table.unpack(segments))
  53.         print(path)
  54.         local fileh = fs.open(path,"w")
  55.         fileh:write(dl(download.."/"..v))
  56.         fileh:close()
  57.     end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement