EuroCreeper

Downloader

May 12th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.34 KB | None | 0 0
  1. -- load function for LEOS (LEOS is made by mikesch96 and evoliprofi and EuroCreeper)
  2. function downloadmenue(option,x,y)
  3.     term.clear()
  4.     term.setCursorPos(x,y)
  5.     ret = nil
  6.     if option == 1 then
  7.             print ("->rootreader")
  8.             ret = nil
  9.         else
  10.             print ("  rootreader")
  11.     end
  12.     term.setCursorPos(x,y+1)
  13.     if option == 2 then
  14.             print ("->LEOS installer")
  15.             ret = nil
  16.         else
  17.             print ("  LEOS installer")
  18.     end
  19.     term.setCursorPos(x,y+2)
  20.     if option == 3 then
  21.             print ("->RC_Drone")
  22.             ret = "http://dl.dropboxusercontent.com/u/25121005/RC_Drone.txt"
  23.         else
  24.             print ("  RC_Drone")
  25.     end
  26.     term.setCursorPos(x,y+3)
  27.     if option == 4 then
  28.             print ("->RC_Computer")
  29.             ret = "http://dl.dropboxusercontent.com/u/25121005/RC_Computer.txt"
  30.         else
  31.             print ("  RC_Computer")
  32.     end
  33.     return ret
  34. end
  35. function rundownloadmenue()
  36.     term.clear()
  37.     print("make your selection and then hit return/enter")
  38.     running = true
  39.     option = 1
  40.     while running do
  41.         ret = downloadmenue(option,20,6)
  42.         e,key = os.pullEvent( "key" )
  43.         if key == 208 then
  44.             if option > 3 then
  45.                 option = 1
  46.             else
  47.                 option = option + 1
  48.             end
  49.         elseif key == 200 then
  50.             if option < 2 then
  51.                 option = 4
  52.             else
  53.                 option = option - 1
  54.             end
  55.         elseif key == 28 then
  56.             running = false
  57.         end
  58.     end
  59.     print("selection will be used")
  60.     return ret
  61. end
  62.  
  63. -- run the downloader
  64. print("type filename:")
  65. local filename = read()
  66. if filename == "+" then
  67.     print ("type filename again:")
  68.     local filename = read()
  69.     print ("wich data you want to download?")
  70.     local path = rundownloadmenue()
  71.     if path == nil then
  72.         print ("no path given for this programm yet")
  73.     else
  74.         local url = http.get(path)
  75.         f = fs.open(filename, "w")
  76.         f.write(url.readAll())
  77.         f.close()
  78.         print("Downloaded")
  79.     end
  80. else -- when a normal filename was typed run this
  81.     print("type url here:")
  82.     local url = http.get(read())
  83.     f = fs.open(filename, "w")
  84.     f.write(url.readAll())
  85.     f.close()
  86.     print("Downloaded")
  87. end
Add Comment
Please, Sign In to add comment