Advertisement
Guest User

Rednet file sender and receiver

a guest
May 12th, 2013
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.56 KB | None | 0 0
  1. --Easy to use RedNet file Sender and Receiver with graphical interface
  2. --    - To open file browser just run the program
  3. --      - In file browser you can choose your file, open menu (press m) and send it to any other computer that has this program
  4. --      - File browser also has functions like open, edit, create folder/file, delete
  5. --    - You can also run this program with arguments (this way you can send and get files using other programs; eg.: shell.run("rn", "send", "14", "myfile"))
  6. --      - Sending: rn send <computer id> <file>
  7. --          rn - this program
  8. --          send - 1st argument tells what to do, in this case 'send'
  9. --          <computer id> - 2nd argument is ID of computer that you want to send to (recipient)
  10. --          <file> 3rd argument is file you want to send
  11. --          
  12. --          Example: rn send 28 myprogram
  13. --        
  14. --      - Getting: rn get <computer id>
  15. --          rn - this program
  16. --          get - 1st argument tells what to do, in this case 'get'
  17. --          <computer id> - 2nd argument is optional; use it if you want to get file from a specific computer
  18. --          
  19. --          Example: rn get 28
  20. --    
  21. --     features:
  22. --       - Sending any type of file with any characters
  23. --       - When getting a file you can save it where ever you want
  24. --       - If there is 1 modem attached on a computer - uses that; If there is more than 1 modem - lets you choose wich one you want to use
  25. --       - See proggress in percents when sending and getting a file (try sending rom/programs/secret/alongtimeago, it will crash when it will try to save it, but you will see how it shows the proggress)
  26. --       - You can use this as your file browser
  27. --       - Working on Advanced and normal computers
  28.  
  29. local sides = {}
  30. local side = ""
  31. local col = term.isColor()
  32. local arg = {...}
  33. local path = ""
  34. local sendID = 0
  35. local sendb = false
  36. local getb = false
  37. local running = true
  38.  
  39. --Helper functions
  40.  
  41. local function getSides ()
  42.   local sides = {}
  43.  
  44.   for _, sid in pairs(rs.getSides()) do
  45.     if peripheral.isPresent(sid) and peripheral.getType(sid) == "modem" then
  46.      sides[#sides + 1] = sid
  47.     end
  48.   end
  49.  
  50.   return sides
  51. end
  52.  
  53. local function clear ()
  54.   term.clear()
  55.   term.setCursorPos(1, 1)
  56. end
  57.  
  58. local function resetColors ()
  59.   term.setTextColor(colors.white)
  60.   term.setBackgroundColor(colors.black)
  61. end
  62.  
  63. local function reset ()
  64.   resetColors()
  65.   clear()
  66. end
  67.  
  68. local function conTColor (ColorColor)
  69.   if col or ColorColor == colors.white or ColorColor == colors.black then
  70.     return ColorColor or colors.white
  71.   else
  72.     return colors.black
  73.   end
  74. end
  75.  
  76. local function conBColor (ColorColor)
  77.   if col or ColorColor == colors.white or ColorColor == colors.black then
  78.     return ColorColor or colors.black
  79.   else
  80.     return colors.white
  81.   end
  82. end
  83.  
  84. local function writeText (text, tColor, bColor, x, y, clear)
  85.   if not x then
  86.     x = term.getCursorPos()
  87.   end
  88.  
  89.   if not y then
  90.     _, y = term.getCursorPos()
  91.   end
  92.  
  93.   if tColor then
  94.     term.setTextColor(conTColor(tColor))
  95.   end
  96.  
  97.   if bColor then
  98.     term.setBackgroundColor(conBColor(bColor))
  99.   end
  100.  
  101.   term.setCursorPos(x, y)
  102.  
  103.   if clear == true then
  104.     term.clear()
  105.   end
  106.  
  107.   term.write(tostring(text))
  108. end
  109.  
  110. local function vRep (text, times, tColor, bColor, x, y)
  111.   local w, h = term.getSize()
  112.  
  113.   if not x then
  114.     x = term.getCursorPos()
  115.   end
  116.  
  117.   if not y then
  118.     _, y = term.getCursorPos()
  119.   end
  120.  
  121.   times = times or 1
  122.  
  123.   for i = 1, times do
  124.     writeText(text, tColor, bColor, x, y)
  125.     y = y + 1
  126.   end
  127. end
  128.  
  129. local function selectionMenu(TableSelections, NumberKey)
  130.   local xO, yO = term.getCursorPos()
  131.   local x, y = term.getCursorPos()
  132.   local selection = 1
  133.  
  134.   while true do
  135.   x, y = xO, yO
  136.   term.setCursorPos(x, y)
  137.  
  138.   for n = 1, #TableSelections do
  139.     if TableSelections[n] == "" then
  140.       term.setCursorPos(x, y)
  141.       term.write(TableSelections[n])
  142.       y = y + 1
  143.     else
  144.       term.setCursorPos(x, y)
  145.      
  146.       if selection == n then
  147.         term.write(">" .. TableSelections[n])
  148.       else
  149.         term.write(TableSelections[n] .. " ")
  150.       end
  151.       y = y + 1
  152.     end
  153.   end
  154.  
  155.   y = y + 1
  156.   term.setCursorPos(x, y)
  157.  
  158.   local keyE, keyP1 = os.pullEvent("key")
  159.  
  160.   if keyP1 == 208 then
  161.     if selection < #TableSelections then
  162.       if TableSelections[selection + 1] == "" and TableSelections[selection + 2] then
  163.         selection = selection + 2
  164.       else
  165.         selection = selection + 1
  166.       end
  167.     end
  168.   elseif keyP1 == 200 then
  169.     if selection > 1 then
  170.       if TableSelections[selection - 1] == "" and TableSelections[selection - 2] then
  171.         selection = selection - 2
  172.       else
  173.         selection = selection - 1
  174.       end
  175.     end
  176.   elseif keyP1 == 28 then
  177.     return selection
  178.   elseif NumberKey and keyP1 == NumberKey then
  179.     return selection, true
  180.   else
  181.     x, y = xO, yO
  182.     term.setCursorPos(x, y)
  183.   end
  184.   end
  185. end
  186.  
  187. local function readAll (StringPath)
  188.   if not fs.exists(StringPath) then
  189.     return
  190.   end
  191.  
  192.   local file = fs.open(StringPath, "r")
  193.   local line = file.readLine()
  194.   local lines = {}
  195.  
  196.   while line ~= nil do
  197.     table.insert(lines, line)
  198.     line = file.readLine()
  199.   end
  200.  
  201.   file.close()
  202.  
  203.   return lines
  204. end
  205.  
  206. local function list (StringPath, StringType)
  207.   if not fs.isDir(StringPath) then
  208.     return
  209.   end
  210.  
  211.   local list = {}
  212.   local files = {}
  213.  
  214.   if string.sub(StringPath, #StringPath - 1) ~= "/" then
  215.     StringPath = StringPath .. "/"
  216.   end
  217.  
  218.   list = fs.list(StringPath)
  219.  
  220.   if list ~= {} then
  221.     if StringType == "files" or StringType == "file" or StringType == "doc" or StringType == "document" or StringType == "documents" then
  222.       for _, file in pairs(list) do
  223.         if not fs.isDir(StringPath .. file) and fs.exists(StringPath .. file) then
  224.           table.insert(files, file)
  225.         end
  226.       end
  227.     elseif StringType == "folders" or StringType == "directories" or StringType == "folder" or StringType == "dir" or StringType == "directorie" then
  228.       for _, file in pairs(list) do
  229.         if fs.isDir(StringPath .. file) then
  230.           table.insert(files, file .. "/")
  231.         end
  232.       end
  233.     else
  234.       files = list
  235.     end
  236.   end
  237.  
  238.   table.sort(files)
  239.  
  240.   return files
  241. end
  242.  
  243. local function toString (TableText)
  244.   local text = ""
  245.  
  246.   for i = 1, #TableText do
  247.     text = text .. TableText[i] .. "\n"
  248.   end
  249.  
  250.   text = text:sub(1, #text - 1)
  251.  
  252.   return text
  253. end
  254.  
  255. local function writeAll (StringPath, StringText)
  256.   local file = fs.open(StringPath, "w")
  257.  
  258.   file.write(StringText or "")
  259.  
  260.   file.close()
  261. end
  262.  
  263. local function checkFolders (text)
  264.   local folders = {}
  265.   local p1, p2
  266.   local path = ""
  267.  
  268.   text = shell.resolve(text)
  269.  
  270.   for i = 1, #text do
  271.     if text:sub(i, i) ~= "/" then
  272.       if not p1 then
  273.         p1 = i
  274.       end
  275.      
  276.       if i == #text then
  277.         folders[#folders + 1] = text:sub(p1)
  278.       end
  279.     else
  280.       p2 = i - 1
  281.      
  282.       folders[#folders + 1] = text:sub(p1, p2)
  283.      
  284.       p1, p2 = nil, nil
  285.     end
  286.   end
  287.  
  288.   for _, folder in pairs(folders) do
  289.     if not fs.isDir(folder) then
  290.       fs.makeDir(path .. folder)
  291.     end
  292.    
  293.     path = path .. folder .. "/"
  294.   end
  295. end
  296.  
  297. --Error checking and setting variables
  298.  
  299. local function usage (err)
  300.   if err then
  301.     writeText(err, colors.yellow)
  302.     print()
  303.   end
  304.  
  305.   resetColors()
  306.  
  307.   print("Usage:")
  308.   print("rn send <computer id> <file to send>")
  309.   print("rn get <computer id>")
  310.   print()
  311.   print("Don't use any arguments to run GUI version of this utility.")
  312.   print()
  313.   print('Ps: only specify "<computer id>" when getting a file if you want to get it from a specific computer.')
  314.  
  315.   error()
  316. end
  317.  
  318. if #arg > 0 then
  319.   if arg[1]:lower() == "send" then
  320.     if #arg == 3 then
  321.       if fs.exists(arg[3]) and not fs.isDir(arg[3]) then
  322.         path = arg[3]
  323.       else
  324.         usage("Invalid argument (3); specified file doesn't exist.")
  325.       end
  326.      
  327.       if tonumber(arg[2]) and tonumber(arg[2]) > 0 then
  328.         sendID = tonumber(arg[2])
  329.       else
  330.         usage("Invalid argument (2); specified computer id is not valid.")
  331.       end
  332.     else
  333.       usage()
  334.     end
  335.    
  336.     sendb = true
  337.   elseif arg[1]:lower() == "get" then
  338.     if tonumber(arg[2]) and tonumber(arg[2]) > 0 then
  339.       sendID = tonumber(arg[2])
  340.     end
  341.    
  342.     getb = true
  343.   else
  344.     usage()
  345.   end
  346. end
  347.  
  348. --{{Main Code}}
  349.  
  350. local function drawFrame (small, ColorClear)
  351.   local x, y = 1, 1
  352.   local w, h = term.getSize()
  353.  
  354.   if small == true then
  355.     x = w / 4
  356.     y = h / 4
  357.     w = w / 2
  358.     h = h / 2
  359.    
  360.     x = math.floor(x + 0.5)
  361.     y = math.floor(y + 0.5)
  362.     w = math.floor(w + 0.5)
  363.     h = math.floor(h + 0.5)
  364.   end
  365.  
  366.   vRep(" ", h, nil, colors.lightBlue, x, y)
  367.   vRep(" ", h, nil, colors.lightBlue, x + w - 1, y)
  368.   writeText(string.rep(" ", w), nil, colors.lightBlue, x, y)
  369.   writeText(string.rep(" ", w), nil, colors.lightBlue, x, y + h - 1)
  370.  
  371.   for x = x + 1, w + x - 2 do
  372.     for y = y + 1, h + y - 2 do
  373.       writeText(" ", nil, ColorClear or colors.black, x, y)
  374.     end
  375.   end
  376.  
  377.   resetColors()
  378. end
  379.  
  380. local function window (TableContent)
  381.   local x, y = 1, 1
  382.   local w, h = term.getSize()
  383.  
  384.   w, h = w - 1, h - 1
  385.   x, y = w / 4 + 2, h / 4 + 2
  386.  
  387.   drawFrame(true)
  388.  
  389.   for i = 1, #TableContent do
  390.     writeText(TableContent[i], nil, nil, x, y + i - 1)
  391.   end
  392. end
  393.  
  394. --Checking for modems
  395.  
  396. local function waitForModem ()
  397.   drawFrame(true)
  398.  
  399.   local x, y = 1, 1
  400.   local w, h = term.getSize()
  401.  
  402.   w, h = w - 1, h - 1
  403.  
  404.   while running do
  405.     sides = getSides()
  406.     x, y = w / 4 + 2, h / 4 + 2
  407.    
  408.     if #sides > 0 then
  409.       if #sides == 1 then
  410.         side = sides[1]
  411.         running = false
  412.       else
  413.         writeText("Select modem:", nil, nil, x, y)
  414.         term.setCursorPos(x, y + 1)
  415.        
  416.         side = sides[selectionMenu(sides)]
  417.         running = false
  418.       end
  419.     else
  420.       writeText("Attach a modem", nil, nil, x, y)
  421.       writeText("Press any key to cancel", nil, nil, x, y + 2)
  422.      
  423.       repeat
  424.         local event, side = os.pullEvent()
  425.        
  426.         if event == "key" then
  427.           return false
  428.         end
  429.       until event == "peripheral" and peripheral.getType(side) == "modem"
  430.     end
  431.   end
  432.  
  433.   rednet.open(side)
  434.  
  435.   running = true
  436.   return true
  437. end
  438.  
  439. --Sending function
  440.  
  441. local function send ()
  442.   if not waitForModem() then
  443.     return false
  444.   end
  445.  
  446.   local event, id, message
  447.   local name = fs.getName(path)
  448.   local percent = 0
  449.   local file = toString(readAll(path))
  450.   local subfile = ""
  451.   local i = 0
  452.   local x, y = 1, 1
  453.   local w, h = term.getSize()
  454.  
  455.   w, h = w - 1, h - 1
  456.   x, y = w / 4 + 2, h / 4 + 2
  457.  
  458.   local function toPercent ()
  459.     local per = tostring(percent)
  460.    
  461.     while #per < 3 do
  462.       per = per .. " "
  463.     end
  464.    
  465.     return per
  466.   end
  467.  
  468.   while running do
  469.     window({"Waiting for recipient ".. sendID, "Press \"R\" to retry", "", "Press any key to cancel"})
  470.    
  471.     rednet.send(sendID, "request " .. name)
  472.    
  473.     repeat
  474.       event, id, message = os.pullEvent()
  475.      
  476.       if event == "key" then
  477.         if id == keys.r then
  478.           rednet.send(sendID, "request " .. name)
  479.         else
  480.           return false
  481.         end
  482.       end
  483.     until event == "rednet_message" and id == sendID
  484.    
  485.     if message == "get" then
  486.       window({"Sending: " .. name, percent .. "%"})
  487.      
  488.       if #file <= 300 then
  489.         writeText(percent .. "%", nil, nil, x, y + 1)
  490.        
  491.         rednet.send(sendID, toPercent() .. " " .. file)
  492.        
  493.         repeat
  494.           event, id = os.pullEvent("rednet_message")
  495.         until id == sendID
  496.        
  497.         rednet.send(sendID, "sent")
  498.        
  499.         window({"Successfully sent:", name, "", "Press any key to exit"})
  500.         os.pullEvent("key")
  501.         return true
  502.       else
  503.         while true do
  504.         if i ~= #file then
  505.           writeText(percent .. "%", nil, nil, x, y + 1)
  506.          
  507.           if #file <= i + 300 then
  508.             subfile = file:sub(i + 1)
  509.            
  510.             i = #file
  511.           else
  512.             subfile = file:sub(i + 1, i + 300)
  513.            
  514.             percent = math.floor(i / #file * 100)
  515.             i = i + 300
  516.           end
  517.          
  518.           rednet.send(sendID, toPercent() .. " " .. subfile)
  519.          
  520.           repeat
  521.             event, id = os.pullEvent("rednet_message")
  522.           until id == sendID
  523.         else
  524.           rednet.send(sendID, "sent")
  525.          
  526.           window({"Successfully sent:", name, "", "Press any key to exit"})
  527.           os.pullEvent("key")
  528.           return true
  529.         end
  530.         end
  531.       end
  532.     elseif message == "refuse" then
  533.       window({"Recipient refused", "", "Press any key to exit"})
  534.       os.pullEvent("key")
  535.       return false
  536.     end
  537.   end
  538.  
  539.   running = true
  540. end
  541.  
  542. --Getting function
  543.  
  544. local function get ()
  545.   if not waitForModem() then
  546.     return false
  547.   end
  548.  
  549.   local getName = "unknown"
  550.   local text = {"Waiting for request", "Sender ID: any", "", "Press any key to cancel"}
  551.   local event, id, message
  552.   local selection = 0
  553.   local percent = 0
  554.   local file = ""
  555.   local x, y = 1, 1
  556.   local w, h = term.getSize()
  557.  
  558.   w, h = w - 1, h - 1
  559.   x, y = w / 4 + 2, h / 4 + 2
  560.  
  561.   if sendID ~= 0 then
  562.     text[2] = "Sender ID: " .. sendID
  563.   end
  564.  
  565.   while running do
  566.     window(text)
  567.    
  568.     repeat
  569.       event, id, message = os.pullEvent()
  570.      
  571.       if event == "key" then
  572.         return false
  573.       end
  574.     until event == "rednet_message" and (id == sendID or sendID == 0)
  575.    
  576.     if sendID == 0 then
  577.       sendID = id
  578.     end
  579.    
  580.     if message:sub(1, 7) == "request" then
  581.       getName = message:sub(9)
  582.     end
  583.    
  584.     window({"Getting file from " .. sendID, "Name: " .. getName})
  585.     term.setCursorPos(x, y + 3)
  586.     selection = selectionMenu({"Save", "Cancel"})
  587.    
  588.     if selection == 2 then
  589.       rednet.send(sendID, "refuse")
  590.       return false
  591.     else
  592.       window({"Enter save path:"})
  593.       term.setCursorPos(x, y + 1)
  594.       path = shell.resolve(read())
  595.       rednet.send(sendID, "get")
  596.     end
  597.    
  598.     window({"Getting: " .. getName, percent .. "%"})
  599.    
  600.     repeat
  601.       writeText(percent .. "%", nil, nil, x, y + 1)
  602.      
  603.       event, id, message = os.pullEvent("rednet_message")
  604.      
  605.       if id == sendID and message ~= "sent" then
  606.         percent = tonumber(message:sub(1, 3))
  607.        
  608.         file = file .. message:sub(5)
  609.        
  610.         rednet.send(sendID, "ok")
  611.       end
  612.     until id == sendID and message == "sent"
  613.    
  614.     window({"Saving: " .. getName, "Path: " .. path .. "/" .. getName})
  615.     checkFolders(path)
  616.     writeAll(path .. "/" .. getName, file)
  617.     window({"Saved " .. getName, "Path: " .. path .. "/" .. getName, "", "Press any key to exit"})
  618.     os.pullEvent("key")
  619.     return true
  620.   end
  621.  
  622.   running = true
  623. end
  624.  
  625. if sendb == true then
  626.   send()
  627. elseif getb == true then
  628.   get()
  629. else
  630.   local currentPath = "/"
  631.   local files = list(currentPath, "files")
  632.   local folders = list(currentPath, "folders")
  633.   local fileList = {}
  634.   local x, y = 2, 2
  635.   local selection = 0
  636.   local menu = false
  637.   local selected = 0
  638.  
  639.   local function combine ()
  640.     if #files == 0 then
  641.       return folders
  642.     end
  643.    
  644.     if #folders == 0 then
  645.       return files
  646.     end
  647.    
  648.     local all = folders
  649.    
  650.     for _, file in pairs(files) do
  651.       all[#all + 1] = file
  652.     end
  653.    
  654.     return all
  655.   end
  656.  
  657.   local function back (StringPath)
  658.     if StringPath == "/" then
  659.       return StringPath
  660.     end
  661.    
  662.     repeat
  663.       StringPath = string.sub(StringPath, 1, #StringPath - 1)
  664.     until string.sub(StringPath, #StringPath) == "/" or #StringPath <= 1
  665.    
  666.     return StringPath
  667.   end
  668.  
  669.   local function getFolder (StringPath)
  670.     local string = back(StringPath)
  671.    
  672.     return string.sub(StringPath, #string + 1)
  673.   end
  674.  
  675.   while running do
  676.     files = list(currentPath, "files")
  677.     folders = list(currentPath, "folders")
  678.     fileList = combine()
  679.    
  680.     table.insert(fileList, 1, "/")
  681.     fileList[#fileList + 1] = ""
  682.     fileList[#fileList + 1] = "Exit"
  683.    
  684.     if menu then
  685.       local x, y = 1, 1
  686.       local w, h = term.getSize()
  687.      
  688.       w, h = w - 1, h - 1
  689.       x, y = w / 4 + 2, h / 4 + 2
  690.      
  691.       drawFrame(true)
  692.       term.setCursorPos(x, y)
  693.       selection = selectionMenu({"Open", "Edit", "Send", "Get", "New Folder", "New File", "Delete", "Back"})
  694.      
  695.       if selection == 1 then
  696.         if selected then
  697.           if fs.isDir(currentPath .. selected) then
  698.             currentPath = currentPath .. selected
  699.             menu = false
  700.           else
  701.             shell.run(currentPath .. selected)
  702.             menu = false
  703.           end
  704.         else
  705.           window({"Choose a file first", "", "Press any key"})
  706.           os.pullEvent("key")
  707.           menu = false
  708.         end
  709.       elseif selection == 2 then
  710.         if selected then
  711.           if fs.isDir(currentPath .. selected) then
  712.             window({"Can't edit a folder", "", "Press any key"})
  713.             os.pullEvent("key")
  714.             menu = false
  715.           else
  716.             shell.run("edit", currentPath .. selected)
  717.             menu = false
  718.           end
  719.         else
  720.           window({"Choose a file first", "", "Press any key"})
  721.           os.pullEvent("key")
  722.           menu = false
  723.         end
  724.       elseif selection == 3 then
  725.         if selected then
  726.           path = currentPath .. selected
  727.           window({"Enter recipient ID:"})
  728.           term.setCursorPos(x, y + 1)
  729.           sendID = tonumber(read()) or 0
  730.           send()
  731.           path = ""
  732.           sendID = 0
  733.           menu = false
  734.         else
  735.           window({"Choose a file first", "", "Press any key"})
  736.           os.pullEvent("key")
  737.           menu = false
  738.         end
  739.       elseif selection == 4 then
  740.         window({"Enter sender ID:", "", "", "Leave it blank if you", "don't know sender id"})
  741.         term.setCursorPos(x, y + 1)
  742.         sendID = tonumber(read()) or 0
  743.         get()
  744.         sendID = 0
  745.         path = ""
  746.         menu = false
  747.       elseif selection == 5 then
  748.         window({"Create new folder:"})
  749.         term.setCursorPos(x, y + 1)
  750.         local name = read()
  751.        
  752.         if not fs.exists(currentPath .. name) then
  753.           fs.makeDir(currentPath .. name)
  754.           menu = false
  755.         else
  756.           window({"Couldn't create folder", "", "Press any key"})
  757.           os.pullEvent("key")
  758.           menu = false
  759.         end
  760.       elseif selection == 6 then
  761.         window({"Create new file:"})
  762.         term.setCursorPos(x, y + 1)
  763.         local name = read()
  764.        
  765.         if not fs.exists(currentPath .. name) then
  766.           shell.run("edit", currentPath .. name)
  767.           menu = false
  768.         else
  769.           window({"Couldn't create file", "", "Press any key"})
  770.           os.pullEvent("key")
  771.           menu = false
  772.         end
  773.       elseif selection == 7 then
  774.         if selected then
  775.           window({"Delete " .. selected .. "?"})
  776.           term.setCursorPos(x, y + 1)
  777.           local selection = selectionMenu({"No", "Yes"})
  778.          
  779.           if selection == 2 then
  780.             fs.delete(currentPath .. selected)
  781.             window({"Deleted " .. selected, "", "Press any key"})
  782.             os.pullEvent("key")
  783.             menu = false
  784.           end
  785.         else
  786.           window({"Choose a file first", "", "Press any key"})
  787.           os.pullEvent("key")
  788.           menu = false
  789.         end
  790.       elseif selection == 8 then
  791.         menu = false
  792.       end
  793.     else
  794.       drawFrame()
  795.       writeText("File Browser | press [M] for menu | ID: " .. os.getComputerID(), nil, nil, x, y)
  796.       writeText("Current path: " .. currentPath, nil, nil, x, y + 1)
  797.       term.setCursorPos(x, y + 3)
  798.       selection, menu = selectionMenu(fileList, keys.m)
  799.      
  800.       if not menu then
  801.         if selection == 1 then
  802.           currentPath = back(currentPath)
  803.         elseif selection == #fileList then
  804.           running = false
  805.         else
  806.           selected = fileList[selection]
  807.          
  808.           if not fs.isDir(currentPath .. selected) then
  809.             menu = true
  810.           else
  811.             currentPath = currentPath .. selected
  812.           end
  813.         end
  814.       else
  815.         if selection ~= 1 and selection ~= #fileList then
  816.           selected = fileList[selection]
  817.         else
  818.           selected = nil
  819.         end
  820.       end
  821.     end
  822.   end
  823. end
  824.  
  825. sides = getSides()
  826.  
  827. if #sides > 0 then
  828.   for _, s in pairs(sides) do
  829.     rednet.close(s)
  830.   end
  831. end
  832.  
  833. reset()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement