Spiker985

Auto Program Downloader

May 15th, 2014
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1. --[[Auto Downloader v1.0 by Spiker985]]--
  2.  
  3. --[[Edit]]--
  4. local mon = peripheral.wrap("right")
  5. mon.setTextColor(colors.white)
  6. mon.setBackgroundColor(colors.black)
  7. mon.setTextScale(1)
  8. local program1Names = {"ModularManager", "MM", "TaskManager", "TM"}
  9. local program1Reference = "Modular_Manager"
  10. local program1Code = "SibWgs68"
  11. local program2Names = {"ModularTerminal", "MT", "TerminalGlasses"}
  12. local program2Reference = "Modular_Terminal"
  13. local program2Code = "F5Q5mFxb"
  14. --[[Edit]]--
  15.  
  16. --[[Don't edit anything below this]]--
  17. tArgs = {...}
  18. mon.clear()
  19. mon.setCursorPos(1,1)
  20.  
  21. function pastebinDownloader(apiName, apiPastebin)
  22.   shell.run("pastebin","get",apiPastebin,apiName)
  23. end
  24.  
  25. if #tArgs <= 0 or #tArgs > 1 then
  26.     mon.clear()
  27.     mon.setCursorPos(2,2)
  28.     mon.write("ERROR, invalid number of arguments")
  29.     mon.setCursorPos(2,3)
  30.     mon.write("Number of arguments: 1")
  31. end
  32.  
  33. if #tArgs == 1 then
  34.     mon.clear()
  35.     for i = 1, #program1Names + #program2Names do
  36.         if tArgs[1] == program1Names[i] then
  37.             if fs.exists(program1Reference) then
  38.                 mon.clear()
  39.                 mon.setCursorPos(2,2)
  40.                 mon.write("ERROR - File exists")
  41.                 sleep(2)
  42.             elseif fs.exists(program1Reference) == false then
  43.                 mon.clear()
  44.                 mon.setCursorPos(2,2)
  45.                 mon.write("Status - Downloading")
  46.                 pastebinDownloader(program1Reference, program1Code)
  47.                 sleep(1)
  48.                 mon.setCursorPos(2,3)
  49.                 mon.write("Download complete!")
  50.                 sleep(1)
  51.                 mon.setCursorPos(2,4)
  52.                 mon.write("Saved as "..program1Reference)
  53.                 sleep(2)
  54.                 term.clear()
  55.                 term.setCursorPos(1,1)
  56.                 return
  57.             end
  58.         end
  59.         if tArgs[1] == program2Names[i] then
  60.             if fs.exists(program2Reference) then
  61.                 mon.clear()
  62.                 mon.setCursorPos(2,2)
  63.                 mon.write("ERROR - File exists")
  64.                 sleep(2)
  65.             elseif fs.exists(program2Reference) == false then
  66.                 mon.clear()
  67.                 mon.setCursorPos(2,2)
  68.                 mon.write("Status - Downloading")
  69.                 pastebinDownloader(program2Reference, program2Code)
  70.                 sleep(1)
  71.                 mon.setCursorPos(2,3)
  72.                 mon.write("Download complete!")
  73.                 sleep(1)
  74.                 mon.setCursorPos(2,4)
  75.                 mon.write("Saved as "..program2Reference)
  76.                 sleep(2)
  77.                 term.clear()
  78.                 term.setCursorPos(1,1)
  79.                 return
  80.             end
  81.         end
  82.     end
  83. end
  84.  
  85. for i = 1, #program1Names + #program2Names do
  86.     if tArgs[1] == program1Names[i] or tArgs[1] == program2Names[i] then
  87.         return
  88.     else
  89.         mon.clear()
  90.         mon.setCursorPos(2,2)
  91.         mon.write(tArgs[1].." is not a valid command")
  92.     end
  93. end
  94.  
  95. term.clear()
  96. term.setCursorPos(1,1)
Add Comment
Please, Sign In to add comment