Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

wilsonbits

By: a guest on Dec 12th, 2012  |  syntax: Lua  |  size: 1.32 KB  |  views: 281  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. local function explodeString(d,p)
  2.  local t, ll
  3.  t = {}
  4.  ll = 0
  5.  if (#p == 1) then return {p} end
  6.   while true do
  7.    l = string.find(p,d,ll,true)
  8.    if l ~= nil then
  9.     table.insert(t, string.sub(p,ll,l-1))
  10.     ll = l + 1
  11.    else
  12.     table.insert(t, string.sub(p,ll))
  13.     break
  14.    end
  15.   end
  16.  return t
  17. end
  18.  
  19. local function printUsage()
  20.  local filePath = shell.getRunningProgram()
  21.  if string.find(filePath, "/") ~= nil then
  22.   local path = explodeString("/", shell.getRunningProgram())
  23.   programName = path[#path]
  24.  else
  25.   programName = filePath
  26.  end
  27.  
  28.  print("Usage:")
  29.  print(programName.." <code> <filename>")
  30. end
  31.  
  32. tArgs = { ... }
  33. if #tArgs ~= 2 then
  34.  printUsage()
  35.  return
  36. end
  37.  
  38. if not http then
  39.  print("This program requires http API")
  40.  print("Please enable in the mod config")
  41.  return
  42. end
  43.  
  44. local code = tArgs[1]
  45. local filename = tArgs[2]
  46. local path = shell.resolve(filename)
  47. if fs.exists(path) then
  48.  print("File already exists")
  49.  return
  50. end
  51.  
  52. write("Connecting to site... ")
  53. local response = http.get("http://wilsonbits.com/scripts/"..textutils.urlEncode(code))
  54.  
  55. if response then
  56.  print("Success")
  57.  
  58.  local sCode = response.readAll()
  59.  response.close()
  60.  
  61.  local file = fs.open(filename, "w")
  62.  file.write(sCode)
  63.  file.close()
  64.  
  65.  print("Downloaded as "..filename)
  66.  
  67. else
  68.  print("Failed")
  69. end