Advertisement
Guest User

FileX

a guest
Jul 3rd, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.12 KB | None | 0 0
  1. --------------FileX v1.2-------------
  2. ---------------Program---------------
  3. --------------by Creator-------------
  4.  
  5. --Variables--
  6. local duser = "Mumbai"
  7. local dpass = "MAXGAMES2013"
  8. term.current(term.native())
  9. local copyPath = ""
  10. local copyHelp = ""
  11. local settDir = "FTPconfig"
  12. local progsDir = "subPrograms"
  13. local textutilsserialize = textutils.serialize
  14. local textutilsunserialize = textutils.unserialize
  15. local w, h = term.getSize()
  16. local folderMenu = {
  17.     term.current(),
  18.     16,
  19.     "Folder Options",
  20.     colors.white,
  21.     colors.blue,
  22.     colors.black,
  23.     colors.lightGray,
  24.     {
  25.         {
  26.             "Open",
  27.             "open",
  28.         },
  29.         {
  30.             "Delete",
  31.             "delete",
  32.         },
  33.         {
  34.             "Rename",
  35.             "rename",
  36.         },
  37.         {
  38.             "Move",
  39.             "move",
  40.         },
  41.         {
  42.             "Copy",
  43.             "copy",
  44.         },
  45.         {
  46.             "Cancel",
  47.             "cancel",
  48.         },
  49.     },
  50. }
  51. local fileMenu = {
  52.     term.current(),
  53.     16,
  54.     "File Options",
  55.     colors.white,
  56.     colors.blue,
  57.     colors.black,
  58.     colors.lightGray,
  59.     {
  60.         {
  61.             "Open",
  62.             "open",
  63.         },
  64.         {
  65.             "Delete",
  66.             "delete",
  67.         },
  68.         {
  69.             "Rename",
  70.             "rename",
  71.         },
  72.         {
  73.             "Move",
  74.             "move",
  75.         },
  76.         {
  77.             "Cancel",
  78.             "cancel",
  79.         },
  80.         {
  81.             "Run",
  82.             "run",
  83.         },
  84.         {
  85.             "Copy",
  86.             "copy",
  87.         },
  88.         {
  89.             "Open with",
  90.             "openWith",
  91.         },
  92.   {
  93.    "Upload"
  94.   },
  95.     },
  96. }
  97. local nilMenu = {
  98.     term.current(),
  99.     16,
  100.     "Options",
  101.     colors.white,
  102.     colors.blue,
  103.     colors.black,
  104.     colors.lightGray,
  105.     {
  106.         {
  107.             "Make a folder",
  108.             "makeFolder",
  109.         },
  110.         {
  111.             "Make a file",
  112.             "makeFile",
  113.         },
  114.         {
  115.             "Cancel",
  116.             "cancel",
  117.         },
  118.     },
  119. }
  120. local newFolderWindow = {
  121.     term.current(),
  122.     math.floor((w-32)/2),
  123.     math.floor((h-8)/2),
  124.     32,
  125.     8,
  126.     true,
  127.     "New folder name",
  128.     colors.white,
  129.     colors.blue,
  130.     "Write the name of%the new folder.",
  131.     colors.black,
  132.     colors.lightGray,
  133.     colors.white,
  134.     colors.black,
  135. }
  136. local newFileWindow = {
  137.     term.current(),
  138.     math.floor((w-32)/2),
  139.     math.floor((h-8)/2),
  140.     32,
  141.     8,
  142.     true,
  143.     "New file name",
  144.     colors.white,
  145.     colors.blue,
  146.     "Write the name of%the new file.",
  147.     colors.black,
  148.     colors.lightGray,
  149.     colors.white,
  150.     colors.black,
  151. }
  152. local upFileWindow = {
  153.     term.current(),
  154.     math.floor((w-32)/2),
  155.     math.floor((h-8)/2),
  156.     32,
  157.     8,
  158.     true,
  159.     "File path",
  160.     colors.white,
  161.     colors.blue,
  162.     "Write the path of%the file.",
  163.     colors.black,
  164.     colors.lightGray,
  165.     colors.white,
  166.     colors.black,
  167. }
  168. local moveFolderWindow = {
  169.     term.current(),
  170.     math.floor((w-32)/2),
  171.     math.floor((h-8)/2),
  172.     32,
  173.     8,
  174.     true,
  175.     "New folder path",
  176.     colors.white,
  177.     colors.blue,
  178.     "Write the name of%the new folder path.",
  179.     colors.black,
  180.     colors.lightGray,
  181.     colors.white,
  182.     colors.black,
  183. }
  184. local bgColor = colors.black
  185. local txtColor = colors.white
  186. local domain = {}
  187. local currDir = ""
  188. local files = {}
  189. local Buttons = {
  190.     {
  191.         2,
  192.         2,
  193.         7,
  194.         1,
  195.         "Refresh",
  196.         colors.white,
  197.         colors.green,
  198.         "refresh"
  199.     },
  200.     {
  201.         11,
  202.         2,
  203.         2,
  204.         1,
  205.         "Up",
  206.         colors.white,
  207.         colors.green,
  208.         "up"
  209.     },
  210.     {
  211.         15,
  212.         2,
  213.         5,
  214.         1,
  215.         "Paste",
  216.         colors.white,
  217.         colors.green,
  218.         "paste"
  219.     },
  220. }
  221. local folderIcon = {
  222.     {
  223.     2,
  224.     2,
  225.     2,
  226.     2,
  227.     16,
  228.     16,
  229.     16,
  230.     16,
  231.     },
  232.     {
  233.     2,
  234.     2,
  235.     2,
  236.     2,
  237.     2,
  238.     2,
  239.     2,
  240.     2,
  241.     },
  242.     {
  243.     2,
  244.     2,
  245.     2,
  246.     2,
  247.     2,
  248.     2,
  249.     2,
  250.     2,
  251.     },
  252.     {
  253.     2,
  254.     2,
  255.     2,
  256.     2,
  257.     2,
  258.     2,
  259.     2,
  260.     2,
  261.     },
  262. }
  263. local fileIcon = {
  264.     {
  265.     8192,
  266.     8192,
  267.     8192,
  268.     8192,
  269.     8192,
  270.     8192,
  271.     8192,
  272.     8192,
  273.     },
  274.     {
  275.     8192,
  276.     8192,
  277.     8192,
  278.     8192,
  279.     8192,
  280.     8192,
  281.     8192,
  282.     8192,
  283.     },
  284.     {
  285.     8192,
  286.     8192,
  287.     8192,
  288.     8192,
  289.     8192,
  290.     8192,
  291.     8192,
  292.     8192,
  293.     },
  294.     {
  295.     8192,
  296.     8192,
  297.     8192,
  298.     8192,
  299.     8192,
  300.     8192,
  301.     8192,
  302.     8192,
  303.     },
  304. }
  305. local scroll = 0
  306. local globalButtonList = {}
  307. local notEnded = true
  308. local fileExtensions = {
  309. nfp = "nPaintPro",
  310. nfa = "nPaintPro",
  311. txt = "edit",
  312. exe = "shell",
  313. lua = "shell",
  314. }
  315.  
  316. --Functions--
  317.  
  318. local function detectButtonHit(buttonsToTest)
  319.     local event, button, x, y
  320.     repeat
  321.         event, button, x, y = os.pullEvent()
  322.     until event == "mouse_click" or event == "key"
  323.     if event == "mouse_click" then
  324.         for i,v in pairs(buttonsToTest) do
  325.             if v[1] <= x and x <= v[3] and v[2] <= y and y <= v[4] then
  326.                 return {v[5], button, x, y}
  327.             end
  328.         end
  329.     elseif event == "key" then
  330.         return {"key:"..tostring(button)}
  331.     end
  332.     return {"pong"}
  333. end
  334.  
  335. local function mkStrShort(str,lenght,n)
  336.     local bufferTable = {}
  337.     local toReturnTable = {}
  338.     local lenghtN = tonumber(lenght)
  339.     if lenghtN == nil then return false end
  340.     for i = 0,n-1 do
  341.         bufferTable[i+1] = string.sub(tostring(str),(i*lenghtN)+1,(i*lenghtN)+lenghtN)
  342.     end
  343.     for i,v in pairs(bufferTable) do
  344.         if v ~= nil then
  345.             toReturnTable[#toReturnTable+1] = v
  346.         end
  347.     end
  348.     return toReturnTable
  349. end
  350.  
  351. local function clear(bgColorArg)
  352.     term.setBackgroundColor(bgColorArg or bgColor)
  353.     term.setTextColor(txtColor)
  354.     term.setCursorPos(1,1)
  355.     term.clear()
  356.     globalButtonList = {}
  357. end
  358.  
  359. local function dropDownMenu(tableInput,clearBg,x,y)
  360.     term.setCursorPos(1,1)
  361.     if clearBg ~= false then
  362.         clear(colors.cyan)
  363.     end
  364.     globalButtonList = {}
  365.     local nTable = {}
  366.     local dropDownMenuWindow = window.create(tableInput[1],x,y,tableInput[2],#tableInput[8]+1,true)
  367.     dropDownMenuWindow.setTextColor(tableInput[4])
  368.     dropDownMenuWindow.setBackgroundColor(tableInput[5])
  369.     dropDownMenuWindow.setCursorPos(1,1)
  370.     dropDownMenuWindow.clearLine()
  371.     dropDownMenuWindow.write(tableInput[3])
  372.     dropDownMenuWindow.setTextColor(tableInput[6])
  373.     dropDownMenuWindow.setBackgroundColor(tableInput[7])
  374.     for i = 1 , #tableInput[8] do
  375.         dropDownMenuWindow.setCursorPos(1,i+1)
  376.         dropDownMenuWindow.clearLine()
  377.         dropDownMenuWindow.write(tableInput[8][i][1])
  378.         globalButtonList[#globalButtonList+1] = {x+1,y+i,x+tableInput[2],y+i,tableInput[8][i][2]}
  379.     end
  380.     local result
  381.     repeat
  382.         result =  detectButtonHit(globalButtonList)
  383.     until result[1] ~= "pong"
  384.     return result[1]
  385. end
  386.  
  387. local function dialogBox(tableInput,clearBg)
  388.     if clearBg ~= false then
  389.         clear(colors.cyan)
  390.     end
  391.     local nTable = {}
  392.     dialogBoxWindow = window.create(
  393.     tableInput[1],
  394.     tableInput[2],
  395.     tableInput[3],
  396.     tableInput[4],
  397.     tableInput[5])
  398.     dialogBoxWindow.setBackgroundColor(tableInput[9])
  399.     dialogBoxWindow.setCursorPos(2,1)
  400.     dialogBoxWindow.clearLine()
  401.     dialogBoxWindow.setTextColor(tableInput[8])
  402.     dialogBoxWindow.write(tableInput[7])
  403.     dialogBoxWindow.setCursorPos(1,2)
  404.     dialogBoxWindow.setBackgroundColor(tableInput[12])
  405.     for i = 2 , tableInput[5] do
  406.         dialogBoxWindow.setCursorPos(1,i)
  407.         dialogBoxWindow.clearLine()
  408.     end
  409.     dialogBoxWindow.setCursorPos(1,2)
  410.     dialogBoxWindow.setTextColor(tableInput[11])
  411.     for token in string.gmatch(tableInput[10],"[^%%]+") do
  412.         nTable[#nTable+1] = token
  413.     end
  414.     for i,v in pairs(nTable) do
  415.         dialogBoxWindow.setCursorPos(2,1+i)
  416.         dialogBoxWindow.write(v)
  417.     end
  418.     local totalLenght = 0
  419.     globalButtonList = {}
  420.     for i,v in pairs(tableInput[13]) do
  421.         dialogBoxWindow.setCursorPos(2+totalLenght,tableInput[5]-1)
  422.         dialogBoxWindow.setTextColor(v[2])
  423.         dialogBoxWindow.setBackgroundColor(v[3])
  424.         local toWrite = " "..v[1].." "
  425.         dialogBoxWindow.write(toWrite)
  426.         if globalButtonList == nil then
  427.             globalButtonList = {{tableInput[2]+1+totalLenght,tableInput[3] + tableInput[5]-2,tableInput[2]+totalLenght + #toWrite,tableInput[3] + tableInput[5]-1,v[4]}}
  428.         else
  429.             globalButtonList[#globalButtonList+1] = {tableInput[2]+1+totalLenght,tableInput[3] + tableInput[5]-2,tableInput[2]+totalLenght + #toWrite,tableInput[3] + tableInput[5]-1,v[4]}
  430.         end
  431.         totalLenght = #toWrite + totalLenght + 2
  432.     end
  433.     local repeatIt = true
  434.     while repeatIt == true do
  435.         local unparsedResult = detectButtonHit(globalButtonList)
  436.         result = unparsedResult[1]
  437.         if result ~= "pong" then
  438.             repeatIt = false
  439.         end
  440.     end
  441.     return result
  442. end
  443.  
  444. local function textBox(tableInput,secret,clearBg)
  445.     if clearBg ~= false then
  446.         clear(colors.cyan)
  447.     end
  448.     local nTable = {}
  449.     textBoxWindow = window.create(tableInput[1],tableInput[2],tableInput[3],tableInput[4],tableInput[5])
  450.     textBoxWindow.setCursorPos(2,1)
  451.     textBoxWindow.setBackgroundColor(tableInput[9])
  452.     textBoxWindow.clearLine()
  453.     textBoxWindow.setTextColor(tableInput[8])
  454.     textBoxWindow.write(tableInput[7])
  455.     textBoxWindow.setCursorPos(1,2)
  456.     textBoxWindow.setBackgroundColor(tableInput[12])
  457.     for i = 2 , tableInput[5] do
  458.         textBoxWindow.setCursorPos(1,i)
  459.         textBoxWindow.clearLine()
  460.     end
  461.     textBoxWindow.setTextColor(tableInput[11])
  462.     for token in string.gmatch(tableInput[10],"[^%%]+") do
  463.         nTable[#nTable+1] = token
  464.     end
  465.     for i,v in pairs(nTable) do
  466.         textBoxWindow.setCursorPos(2,1+i)
  467.         textBoxWindow.write(v)
  468.     end
  469.     textBoxWindow.setTextColor(tableInput[13])
  470.     textBoxWindow.setBackgroundColor(tableInput[14])
  471.     textBoxWindow.setCursorPos(2,tableInput[5]-1)
  472.     textBoxWindow.clearLine()
  473.     textBoxWindow.setCursorPos(2,tableInput[5]-1)
  474.     textBoxWindow.setTextColor(tableInput[13])
  475.     textBoxWindow.setBackgroundColor(tableInput[14])
  476.     if secret then
  477.         return read("*")
  478.     else
  479.         return read()
  480.     end
  481. end
  482.  
  483. local function refresh(dir)
  484.     local bufferFiles = {}
  485.     for i,v in pairs(fs.list(dir)) do
  486.         if fs.isDir(currDir.."/"..v) then
  487.             bufferFiles[#bufferFiles+1] = {v,"folder"}
  488.         else
  489.             bufferFiles[#bufferFiles+1] = {v,"file"}
  490.         end
  491.     end
  492.     return bufferFiles
  493. end
  494.  
  495. local function drawOptions(tableInputDrawOptions)
  496.     for i,v in pairs(tableInputDrawOptions) do
  497.         term.setCursorPos(v[1],v[2])
  498.         paintutils.drawFilledBox(v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,v[7])
  499.         term.setCursorPos(v[1],v[2])
  500.         term.setTextColor(v[6])
  501.         term.write(v[5])
  502.         if globalButtonList == nil then
  503.             globalButtonList = {{v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,"button:"..v[8]}}
  504.         else
  505.             globalButtonList[#globalButtonList+1] = {v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,"button:"..v[8]}
  506.         end
  507.     end
  508. end
  509.  
  510. local function drawFiles(filesToDisplay)
  511.     local numItemsX = math.floor((w-1)/10)
  512.     numItemsY = math.ceil(#filesToDisplay/numItemsX)
  513.     local currFile = 1
  514.     for i = 0 , numItemsY-1 do
  515.         for k = 0 , numItemsX - 1 do
  516.             if currFile > #filesToDisplay then
  517.                 break
  518.             else
  519.                 term.setTextColor(colors.black)
  520.                 if filesToDisplay[currFile][2] == "file" then
  521.                     paintutils.drawImage(fileIcon,(k*10)+2,(i*5)+4-scroll)
  522.                     for l,m in pairs(mkStrShort(filesToDisplay[currFile][1],6,3)) do
  523.                         term.setCursorPos((k*10)+3,(i*5)+4+l-scroll)
  524.                         term.write(m)
  525.                     end
  526.                     if ((i*5)+4-scroll) < 4 then
  527.                         if ((i*5)+7-scroll) >= 4 then
  528.                             if globalButtonList == nil then
  529.                                 globalButtonList = {{((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),"file:"..filesToDisplay[currFile][1]}}
  530.                             else
  531.                                 globalButtonList[#globalButtonList+1] = {((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),"file:"..filesToDisplay[currFile][1]}
  532.                             end
  533.                         end
  534.                     else
  535.                         if globalButtonList == nil then
  536.                             globalButtonList = {{((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),"file:"..filesToDisplay[currFile][1]}}
  537.                         else
  538.                             globalButtonList[#globalButtonList+1] = {((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),"file:"..filesToDisplay[currFile][1]}
  539.                         end
  540.                     end
  541.                 elseif filesToDisplay[currFile][2] == "folder" then
  542.                     paintutils.drawImage(folderIcon,(k*10)+2,(i*5)+4-scroll)
  543.                     for l,m in pairs(mkStrShort(filesToDisplay[currFile][1],6,3)) do
  544.                         term.setCursorPos((k*10)+3,(i*5)+4+l-scroll)
  545.                         term.write(m)
  546.                     end
  547.                     if ((i*5)+4-scroll) < 4 then
  548.                         if ((i*5)+7-scroll) >= 4 then
  549.                             if globalButtonList == nil then
  550.                                 globalButtonList = {{((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),"folder:"..filesToDisplay[currFile][1]}}
  551.                             else
  552.                                 globalButtonList[#globalButtonList+1] = {((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),"folder:"..filesToDisplay[currFile][1]}
  553.                             end
  554.                         end
  555.                     else
  556.                         if globalButtonList == nil then
  557.                             globalButtonList = {{((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),"folder:"..filesToDisplay[currFile][1]}}
  558.                         else
  559.                             globalButtonList[#globalButtonList+1] = {((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),"folder:"..filesToDisplay[currFile][1]}
  560.                         end
  561.                     end
  562.                 end
  563.                 currFile = currFile + 1
  564.             end
  565.         end
  566.     end
  567. end
  568.  
  569. local function drawSideBar()
  570.     local lenghtSideBar = h-4
  571.     if numItemsY ~= 0 then
  572.          lenghtSideBar = math.ceil(((h-5)*(h-5))/(numItemsY*5))
  573.     end
  574.     paintutils.drawLine(w,3,w,3+lenghtSideBar,colors.green)
  575.     term.setBackgroundColor(colors.blue)
  576.     term.setCursorPos(w,3)
  577.     term.write("^")
  578.     term.setCursorPos(w,h-1)
  579.     term.write("v")
  580.     if globalButtonList == nil then
  581.         globalButtonList = {{w,3,w,3,"button:scrollUp"}}
  582.     else
  583.         globalButtonList[#globalButtonList+1] = {w,3,w,3,"button:scrollUp"}
  584.     end
  585.     if globalButtonList == nil then
  586.         globalButtonList = {{w,h-1,w,h-1,"button:scrollDown"}}
  587.     else
  588.         globalButtonList[#globalButtonList+1] = {w,h-1,w,h-1,"button:scrollDown"}
  589.     end
  590. end
  591.  
  592. local function program(extension)
  593.     if fileExtensions[extension] ~= nil then
  594.         return fileExtensions[extension]
  595.     else
  596.         return "edit"
  597.     end
  598. end
  599.  
  600. local function main(filesToDisplay,buttonsToDisplay)
  601.     clear(colors.white)
  602.     drawFiles(filesToDisplay)
  603.     drawSideBar()
  604.     term.setBackgroundColor(colors.orange)
  605.     for i = 1,2 do
  606.         term.setCursorPos(1,i)
  607.         term.clearLine()
  608.     end
  609.     term.setCursorPos(1,1)
  610.     term.setTextColor(colors.black)
  611.     term.write("Creator\'s FileX v1.0")
  612.     term.setCursorPos(w,1)
  613.     term.setBackgroundColor(colors.magenta)
  614.     term.write("X")
  615.     if globalButtonList == nil then
  616.         globalButtonList = {{w,1,w,1,"button:x"}}
  617.     else
  618.         globalButtonList[#globalButtonList+1] = {w,1,w,1,"button:x"}
  619.     end
  620.     if globalButtonList == nil then
  621.         globalButtonList = {{1,3,w,h,"nil:nil"}}
  622.     else
  623.         globalButtonList[#globalButtonList+1] = {1,4,w,h,"nil:nil"}
  624.     end
  625.     drawOptions(buttonsToDisplay)
  626.     if globalButtonList == nil then
  627.         globalButtonList = {{1,1,w,3,"nil:nilnil"}}
  628.     else
  629.         globalButtonList[#globalButtonList+1] = {1,1,w,3,"nil:nilnil"}
  630.     end
  631.     term.setCursorPos(1,h)
  632.     term.setBackgroundColor(colors.orange)
  633.     term.clearLine()
  634.     term.setTextColor(colors.black)
  635.     term.write(currDir)
  636.     term.setCursorPos(1,1)
  637.     local detectedButtonUnparsedTable = detectButtonHit(globalButtonList)
  638.     local detectedButtonUnparsed = detectedButtonUnparsedTable[1]
  639.     local button = detectedButtonUnparsedTable[2]
  640.     local detectedButtonParsedTable = {}
  641.     for token in string.gmatch(detectedButtonUnparsed,"[^:]+") do
  642.         detectedButtonParsedTable[#detectedButtonParsedTable + 1] = token
  643.     end
  644.     local action = detectedButtonParsedTable[2]
  645.     if detectedButtonParsedTable[1] == "button" then
  646.         if action == "x" then
  647.             term.setBackgroundColor(colors.black)
  648.             clear()
  649.             print("Thank you for using Creator\'s FTPclient. More coming soon...\nSpecial thanks to:\nNitrogenFinger\'s for nPaintPro")
  650.             notEnded = false
  651.         elseif action == "up" then
  652.             scroll = 0
  653.             if currDir == "/" then
  654.             else
  655.                 local currDirBuffer = {}
  656.                 for token in string.gmatch(currDir,"(/[^/]+)") do
  657.                     currDirBuffer[#currDirBuffer + 1] = token
  658.                 end
  659.                 currDir = ""
  660.                 if #currDirBuffer == 1 then
  661.                     currDir = ""
  662.                 else
  663.                     for i = 1, #currDirBuffer-1 do
  664.                         if i == 1 then
  665.                             currDir = currDirBuffer[1]
  666.                         else
  667.                             currDir = currDir..currDirBuffer[i]
  668.                         end
  669.                     end
  670.                 end
  671.                 files = refresh(currDir)
  672.             end
  673.         elseif action == "refresh" then
  674.             files = refresh(currDir)
  675.         elseif action == "scrollUp" then
  676.             scroll = scroll - 1
  677.             if scroll < 0 then
  678.                 scroll = 0
  679.             end
  680.         elseif action == "scrollDown" then
  681.             scroll = scroll + 1
  682.             if scroll > numItemsY*6 - h then
  683.                 scroll = scroll - 1
  684.             end
  685.         elseif action == "paste" then
  686.             term.setCursorPos(1,1)
  687.             print(pathToCopy)
  688.             print(currDir)
  689.             print(copyHelp)
  690.             sleep(3)
  691.             fs.copy(copyPath,currDir.."/"..copyHelp)
  692.             files = refresh(currDir)
  693.            
  694.         end
  695.     elseif detectedButtonParsedTable[1] == "key" then
  696.         if tonumber(action) == keys.up then
  697.             scroll = scroll - 1
  698.             if scroll < 0 then
  699.                 scroll = 0
  700.             end
  701.         elseif tonumber(action) == keys.down then
  702.             scroll = scroll + 1
  703.             if scroll > numItemsY*6 - h then
  704.                 scroll = scroll - 1
  705.             end
  706.         end
  707.     elseif detectedButtonParsedTable[1] == "folder" then
  708.         if button == 1 then
  709.             currDir = currDir.."/"..action
  710.             files = refresh(currDir)
  711.             scroll = 0
  712.         elseif button == 2 then
  713.             local result = dropDownMenu(folderMenu,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4])
  714.             if result == "open" then
  715.                 currDir = currDir.."/"..action
  716.                 files = refresh(currDir)
  717.                 scroll = 0
  718.             elseif result == "copy" then
  719.                 pathToCopy = currDir..action
  720.             elseif result == "delete" then
  721.                 fs.delete(currDir.."/"..action)
  722.                 files = refresh(currDir)
  723.             elseif result == "rename" then
  724.                 local answ = textBox(newFolderWindow,false,false)
  725.                 fs.move(currDir.."/"..action,currDir.."/"..answ)
  726.                 files = refresh(currDir)
  727.             elseif result == "move" then
  728.                 local answ = textBox(moveFolderWindow,false,false)
  729.                 if string.sub(answ,1,1) ~= "/" then
  730.                     answ = "/"..answ
  731.                 end
  732.                 fs.move(currDir.."/"..action,answ)
  733.                 files = refresh(currDir)
  734.             elseif result == "copy" then
  735.                 copyPath = currDir.."/"..action
  736.                 copyHelp = action
  737.             end
  738.         end
  739.     elseif detectedButtonParsedTable[1] == "file" then
  740.         if button == 1 then
  741.             local fileExtension
  742.             for token in string.gmatch(action,"[^%.]+") do
  743.                 fileExtension = token
  744.             end
  745.             if fileExtension == action then
  746.                 fileExtension = "txt"
  747.             end
  748.             programT = program(fileExtension)
  749.             shell.run(progsDir.."/"..programT.." "..currDir.."/"..action)
  750.         elseif button == 2 then
  751.             local result = dropDownMenu(fileMenu,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4])
  752.             if result == "open" then
  753.                 local fileExtension
  754.                 for token in string.gmatch(action,"[^%.]+") do
  755.                     fileExtension = token
  756.                 end
  757.                 if fileExtension == action then
  758.                     fileExtension = "txt"
  759.                 end
  760.                 programT = program(fileExtension)
  761.                 shell.run(progsDir.."/"..programT.." "..currDir.."/"..action)
  762.             elseif result == "delete" then
  763.                 fs.delete(currDir.."/"..action)
  764.                 files = refresh(currDir)
  765.             elseif result == "rename" then
  766.                 local answ = textBox(newFolderWindow,false,false)
  767.                 fs.move(currDir.."/"..action,currDir.."/"..answ)
  768.                 files = refresh(currDir)
  769.             elseif result == "move" then
  770.                 local answ = textBox(moveFolderWindow,false,false)
  771.                 if string.sub(answ,1,1) ~= "/" then
  772.                     answ = "/"..answ
  773.                 end
  774.                 fs.move(currDir.."/"..action,answ)
  775.                 files = refresh(currDir)
  776.             elseif result == "run" then
  777.                 shell.run(progsDir.."/shell "..currDir.."/"..action)
  778.    -- IMPLEMENTED BY MUMBAI
  779.    elseif result == "upload" then
  780.     local status, err = Discover.User:Login("".. duser .. "", "".. dpass .. "")
  781.     if not status then
  782.      print(tostring(err))
  783.     end
  784.     local dupload = Discover.Cloud:Create("dtest")
  785.     if not dupload then
  786.     end
  787.             elseif result == "openWith" then
  788.                 local possibleExtensions = {}
  789.                 for i,v in pairs(fileExtensions) do
  790.                     local alreadyRegistered = false
  791.                     for m,k in pairs(possibleExtensions) do
  792.                         if v == k then
  793.                             alreadyRegistered = true
  794.                         end
  795.                     end
  796.                     if not alreadyRegistered then
  797.                         possibleExtensions[#possibleExtensions+1] = v
  798.                     end
  799.                 end
  800.                 local openWith = {
  801.                     term.current(),
  802.                     16,
  803.                     "Open with:",
  804.                     colors.white,
  805.                     colors.blue,
  806.                     colors.black,
  807.                     colors.lightGray,
  808.                     {}
  809.                 }
  810.                 for i,v in pairs(possibleExtensions) do
  811.                     openWith[8][#openWith[8]+1] = {v,v}
  812.                 end
  813.                 openWith[8][#openWith[8]+1] = {"Cancel","cancel"}
  814.                 globalButtonList = {}
  815.                 result = dropDownMenu(openWith,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4]+6)
  816.                 shell.run(progsDir.."/"..result.." "..currDir.."/"..action)
  817.             elseif result == "copy" then
  818.                 copyPath = currDir.."/"..action
  819.                 copyHelp = action
  820.             end
  821.         end
  822.     elseif detectedButtonParsedTable[1] == "nil" then
  823.         if button == 2 then
  824.             if action == "nil" then
  825.                 local result = dropDownMenu(nilMenu,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4])
  826.                 if result == "makeFolder" then
  827.                     local answ = textBox(newFolderWindow,false,false)
  828.                     fs.makeDir(currDir.."/"..answ)
  829.                     files = refresh(currDir)
  830.                     scroll = 0
  831.                 elseif result == "makeFile" then
  832.                     local answ = textBox(newFileWindow,false,false)
  833.                     f = fs.open(currDir.."/"..answ,"w")
  834.                     f.close()
  835.                     files = refresh(currDir)
  836.                     scroll = 0
  837.                 end
  838.             end
  839.         end
  840.     end
  841. end
  842.  
  843. --Code--
  844.  
  845. clear()
  846. files = refresh(currDir)
  847. while notEnded do
  848.     main(files,Buttons)
  849. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement