Advertisement
dannysmc95

xPlore

Mar 26th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.12 KB | None | 0 0
  1. --[[
  2.     Name: xPlore
  3.     Creator: DannySMc (dannysmc95)
  4.     Platform: Lua Virtual Machine
  5.  
  6.     Description:
  7.     A new advanced file browser, xPlore uses a minimal design to provide advanced functionality. xPlore can offers a key term file searcher allowing you to search for characters and strings inside of file names, giving a list as a file or on-screen. Auto-refresh to files to make sure you have the updated list. Folder/File Creation. Move, copy and delete files/folders.
  8.  
  9.     Future:
  10.     + An easy to use command line tool, writing content to a screen instead in a super minimal format.
  11.     + Supports Turtles, Pocket Computers and Non-advanced computers.
  12.     + CCSystems FTP file management.
  13.     + CCSystems URL Browser, with a in-built HTML parser.
  14. ]]
  15.  
  16. local tArgs = {...}
  17.  
  18. xplore = {}
  19. xplore.__index = xplore
  20.  
  21. xplore.draw = {}
  22. xplore.draw.__index = xplore.draw
  23.  
  24. LoggedIn = false
  25. username = "Guest"
  26. password = nil
  27. pathurl = "/"
  28. -- URL/FTP/DIR
  29. pathtype = "DIR"
  30. tHistory = {
  31.     "/",
  32. }
  33.  
  34. nTries = 0
  35.  
  36. function xplore.get()
  37.     local ok, err = pcall( function()
  38.         if http then
  39.             if fs.exists("--") then
  40.                 os.loadAPI("--")
  41.             else
  42.                 aa = aa or {}
  43.                 local a = http.get("http://api.dannysmc.com/files/apis/progutils.lua")
  44.                 a = a.readAll()
  45.                 local env = {}
  46.                 a = loadstring(a)
  47.                 local env = getfenv()
  48.                 setfenv(a,env)
  49.                 local status, err = pcall(a, unpack(aa))
  50.                 if (not status) and err then
  51.                     printError("Error loading api")
  52.                     return false
  53.                 end
  54.                 local returned = err
  55.                 env = env
  56.                 _G["snet"] = env
  57.             end
  58.             xplore.init()
  59.         else
  60.             xplore.error("HTTP needs to be enabled.")
  61.         end
  62.     end)
  63.     if not ok then
  64.         if nTries == 3 then
  65.             print("The program has tried 3 times to get the API, We shall run shell instead.")
  66.             sleep(5)
  67.             shell.run("clear")
  68.             shell.run("shell")
  69.         else
  70.             nTries = nTries + 1
  71.             print("Program, failed to download API, Re-trying...")
  72.             sleep(1)
  73.             xplore.get()
  74.         end
  75.     end
  76. end
  77.  
  78. function xplore.listall(start)
  79.     local function yieldFsList(startPath)
  80.         local list = fs.list(startPath)
  81.         for _, file in ipairs(list) do
  82.             local path = fs.combine(startPath, file)
  83.             if fs.isDir(path) then
  84.                 yieldFsList(path)
  85.             else
  86.                 coroutine.yield(path, file)
  87.             end
  88.         end
  89.     end
  90.     return coroutine.wrap(function() yieldFsList(start or "/") end)
  91. end
  92.  
  93. function xplore.find()
  94.     foundfiles = {{},{}}
  95.     outputavailable = false
  96.     col.screen("white")
  97.     draw.box(1, 51, 1, 1, " ", "grey", "grey")
  98.     draw.texta("Search", 1, 1, false, "cyan", "grey")
  99.     count = 0
  100.  
  101.     draw.textc(" -< Search the file system for key word >-", 2, false, "lightGrey", "white")
  102.     draw.texta("Search term:", 8, 7, false, "lightGrey", "white")
  103.     draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
  104.  
  105.     draw.box(1, 51, 19, 1, " ", "grey", "grey")
  106.     draw.texta("  Search  ", 3, 19, false, "blue", "lightGrey")
  107.     draw.texta("   Exit   ", 40, 19, false, "blue", "lightGrey")
  108.  
  109.     while true do
  110.         local args = { os.pullEvent() }
  111.         if args[1] == "mouse_click" and args[2] == 1 then
  112.             if (args[3] >= 8 and args[3] <= 42) and (args[4] == 8) then
  113.                 draw.box(8, 36, 8, 1, " ", "cyan", "cyan")
  114.                 col.set("white", "cyan")
  115.                 term.setCursorPos(8, 8)
  116.                 write(": ")
  117.                 keyterm = tostring(read())
  118.                 count = 0
  119.             elseif (args[3] >= 19 and args[3] <= 32) and (args[4] == 14) then
  120.                 if outputavailable then
  121.                     col.screen("white")
  122.                     draw.box(1, 51, 1, 1, " ", "grey", "grey")
  123.                     draw.texta("Search Results", 1, 1, false, "cyan", "grey")
  124.                     draw.box(1, 51, 19, 1, " ", "grey", "grey")
  125.                     draw.texta(" Exit ", 2, 19, false, "blue", "lightGrey")
  126.                     draw.textc(" File Name -> File Path ", 2, false, "lightGrey", "white")
  127.  
  128.                     for i = 1, #tFiles[1] do
  129.                         draw.texta(tFiles[1][i].." -> "..tFiles[2][i], 1, i + 3, false, "grey", "white")
  130.                     end
  131.                
  132.                     while true do
  133.                         local arg = { os.pullEvent() }
  134.                         if arg[1] == "mouse_click" and arg[2] == 1 then
  135.                             if (arg[3] >= 2 and arg[3] <= 7) and (arg[4] == 19) then
  136.                                 xplore.find()
  137.                             end
  138.                         end
  139.                     end
  140.                 end
  141.             elseif (args[3] >= 3 and args[3] <= 12) and (args[4] == 19) then
  142.                 -- Do search
  143.                 if not keyterm then
  144.                     draw.popup("Please enter a keyword to search")
  145.                     sleep(2)
  146.                     xplore.find()
  147.                 end
  148.                 jcount = 0
  149.                 for fullpath, filename in xplore.listall() do
  150.                     count = count + 1
  151.                     table.insert(foundfiles[1], filename)
  152.                     table.insert(foundfiles[2], fullpath)
  153.                     sleep(0)
  154.                     draw.textc(" Indexed "..count.." files", 10, false, "red", "white")
  155.                 end
  156.                 draw.textc(" Indexed "..count.." files", 10, false, "red", "white")
  157.                 tFiles = {{},{}}
  158.  
  159.                 for i = 1, #foundfiles[1] do
  160.                     if foundfiles[1][i]:find(keyterm) then
  161.                         table.insert(tFiles[1], foundfiles[1][i])
  162.                         table.insert(tFiles[2], foundfiles[2][i])
  163.                     end
  164.                 end
  165.  
  166.                 draw.textc(" Search completed, found "..#tFiles[1].." that match", 12, false, "red", "white")
  167.                 if #tFiles[1] >= 15 then
  168.                     local temp = fs.open("searchoutput", "w")
  169.                     temp.write(textutils.serialize(tFiles))
  170.                     temp.close()
  171.                     draw.textc(" Search results were > 15:", 14, false, "grey", "white")
  172.                     draw.textc(" Saved to '/searchoutput' ", 15, false, "grey", "white")
  173.                 else
  174.                     draw.texta(" View Results ", 19, 14, false, "white", "cyan")
  175.                     outputavailable = true
  176.                     assert(type(tFiles) == "table")
  177.                 end
  178.             elseif (args[3] >= 40 and args[3] <= 49) and (args[4] == 19) then
  179.                 -- Exit
  180.                 xplore.main()
  181.             end
  182.         end
  183.     end
  184. end
  185.  
  186. function xplore.init()
  187.     local ok, err = pcall(function()
  188.         if term.isColour() then
  189.             if fs.exists(".xPlore") then
  190.                 local settings = config.load(".xPlore")
  191.                 username = settings["username"]
  192.                 password = settings["password"]
  193.                 returnprog = settings["return"]
  194.             end
  195.  
  196.             xplore.main()
  197.         end
  198.     end)
  199.     if not ok then
  200.         xplore.error(err)
  201.     end
  202. end
  203.  
  204. function xplore.getdir(pathurl)
  205.     if pathurl:sub(1, 7) == "http://" then
  206.         pathtype = "URL"
  207.         -- Do online request
  208.     elseif pathurl:sub(1, 6) == "ftp://" then
  209.         -- Do FTP type of request using database
  210.         pathtype = "FTP"
  211.     else
  212.         -- Load via local files
  213.         pathtype = "DIR"
  214.         local filelist = {{},{}}
  215.         for _, v in ipairs(fs.list(pathurl)) do
  216.             if fs.isDir(fs.combine(pathurl, v)) then
  217.                 table.insert(filelist[1], v)
  218.                 table.insert(filelist[2], "dir")
  219.             end
  220.         end
  221.         for _, v in ipairs(fs.list(pathurl)) do
  222.             if not fs.isDir(fs.combine(pathurl, v)) then
  223.                 table.insert(filelist[1], v)
  224.                 table.insert(filelist[2], "file")
  225.             end
  226.         end
  227.         return filelist
  228.     end
  229. end
  230.  
  231. function xplore.bar(start)
  232.     draw.box(1, 51, 1, 1, " ", "grey", "grey")
  233.     --draw.box(5, 41, 1, 1, false, "lightGrey", "lightGrey")
  234.     if pathurl:len() >= 38 then
  235.         pathfix = "..."..pathurl:sub(pathurl:len() - 35)
  236.     else
  237.         pathfix = pathurl
  238.     end
  239.     draw.texta(pathfix, 3, 1, false, "lightBlue", "grey")
  240.     draw.texta("<", 1, 1, false, "lime", "grey")
  241.     draw.texta("X", 51, 1, false, "lime", "grey")
  242.     draw.texta("["..pathtype.."]", 45, 1, false, "lightGrey", "grey")
  243.     xplore.menu(start)
  244.     draw.texta("Create", 41, 3, false, "lime", "cyan")
  245.     draw.texta("----------", 41, 4, false, "lime", "cyan")
  246.     draw.texta("Folder", 42, 5, false, "white", "cyan")
  247.     draw.texta("File", 42, 6, false, "white", "cyan")
  248.     draw.texta("Download", 41, 8, false, "lime", "cyan")
  249.     draw.texta("----------", 41, 9, false, "lime", "cyan")
  250.     draw.texta("Pastebin", 42, 10, false, "white", "cyan")
  251.     draw.texta("URL", 42, 11, false, "white", "cyan")
  252.     draw.texta("Functions", 41, 13, false, "lime", "cyan")
  253.     draw.texta("----------", 41, 14, false, "lime", "cyan")
  254.     draw.texta("Search", 42, 15, false, "white", "cyan")
  255. end
  256.  
  257. function xplore.menu(start)
  258.     if start then
  259.         draw.box(51, 1, 2, 18, " ", "cyan", "cyan")
  260.         sleep(0.05)
  261.         draw.box(50, 1, 2, 18, " ", "cyan", "cyan")
  262.         sleep(0.05)
  263.         draw.box(49, 1, 2, 18, " ", "cyan", "cyan")
  264.         sleep(0.05)
  265.         draw.box(48, 1, 2, 18, " ", "cyan", "cyan")
  266.         sleep(0.05)
  267.         draw.box(47, 1, 2, 18, " ", "cyan", "cyan")
  268.         sleep(0.05)
  269.         draw.box(46, 1, 2, 18, " ", "cyan", "cyan")
  270.         sleep(0.05)
  271.         draw.box(45, 1, 2, 18, " ", "cyan", "cyan")
  272.         sleep(0.05)
  273.         draw.box(44, 1, 2, 18, " ", "cyan", "cyan")
  274.         sleep(0.05)
  275.         draw.box(43, 1, 2, 18, " ", "cyan", "cyan")
  276.         sleep(0.05)
  277.         draw.box(42, 1, 2, 18, " ", "cyan", "cyan")
  278.         sleep(0.05)
  279.         draw.box(41, 1, 2, 18, " ", "cyan", "cyan")
  280.         sleep(0.05)
  281.         draw.box(40, 1, 2, 18, " ", "cyan", "cyan")
  282.     else
  283.         draw.box(51, 1, 2, 18, " ", "cyan", "cyan")
  284.         draw.box(50, 1, 2, 18, " ", "cyan", "cyan")
  285.         draw.box(49, 1, 2, 18, " ", "cyan", "cyan")
  286.         draw.box(48, 1, 2, 18, " ", "cyan", "cyan")
  287.         draw.box(47, 1, 2, 18, " ", "cyan", "cyan")
  288.         draw.box(46, 1, 2, 18, " ", "cyan", "cyan")
  289.         draw.box(45, 1, 2, 18, " ", "cyan", "cyan")
  290.         draw.box(44, 1, 2, 18, " ", "cyan", "cyan")
  291.         draw.box(43, 1, 2, 18, " ", "cyan", "cyan")
  292.         draw.box(42, 1, 2, 18, " ", "cyan", "cyan")
  293.         draw.box(41, 1, 2, 18, " ", "cyan", "cyan")
  294.         draw.box(40, 1, 2, 18, " ", "cyan", "cyan")
  295.     end
  296. end
  297.  
  298. function xplore.scrollbar(fileslen, scroll)
  299.     draw.box(1, 1, 2, 18, false, "grey", "grey")
  300.     draw.texta("^", 1, 2, false, "white", "grey")
  301.     draw.texta("v", 1, 19, false, "white", "grey")
  302.     size = math.ceil(fileslen / 16)
  303.     pos = 2 + math.ceil(scroll + fileslen / 16)
  304.     draw.box(1, 1, pos, size, " ", "lightGrey", "lightGrey")
  305. end
  306.  
  307. function xplore.drawdir(files, scroll, start)
  308.     if not start then
  309.         for i = 2, 39 do
  310.             draw.box(i, 1, 2, 19, " ", "white", "white")
  311.         end
  312.         for i = 1, 17 do
  313.             j = i
  314.             i = i + scroll
  315.             if i <= #files[1] then
  316.                 if files[1][i]:len() >= 35 then
  317.                     name = files[1][i]:sub(1,32).."..."
  318.                 else
  319.                     name = files[1][i]
  320.                 end
  321.                 if files[2][i] == "dir" then
  322.                     draw.texta(name, 3, j+2, false, "orange", "white")
  323.                 elseif files[2][i] == "file" then
  324.                     draw.texta(name, 3, j+2, false, "lightBlue", "white")
  325.                 end
  326.             else
  327.                 break
  328.             end
  329.         end
  330.     else
  331.         for i = 2, 39 do
  332.             draw.box(i, 1, 2, 19, " ", "white", "white")
  333.         end
  334.         for i = 1, 17 do
  335.             j = i
  336.             i = i + scroll
  337.             if i <= #files[1] then
  338.                 if files[1][i]:len() >= 35 then
  339.                     name = files[1][i]:sub(1,32).."..."
  340.                 else
  341.                     name = files[1][i]
  342.                 end
  343.                 if files[2][i] == "dir" then
  344.                     draw.texta(name, 3, j+2, false, "orange", "white")
  345.                 elseif files[2][i] == "file" then
  346.                     draw.texta(name, 3, j+2, false, "lightBlue", "white")
  347.                 end
  348.             else
  349.                 break
  350.             end
  351.             sleep(0.05)
  352.         end
  353.     end
  354.     xplore.scrollbar(#files, scroll)
  355. end
  356.  
  357. function xplore.popup(question)
  358.     draw.box(5, 43, 8, 3, " ", "grey", "grey")
  359.     draw.box(5, 43, 9, 1, " ", "grey", "grey")
  360.     draw.textc(" "..question, 8, false, "white", "grey")
  361.     draw.texta("    Accept     ", 7, 10, false, "blue", "lightGrey")
  362.     draw.texta("    Decline    ", 31, 10, false, "blue", "lightGrey")
  363.     while true do
  364.         local args = { os.pullEvent() }
  365.         if args[1] == "mouse_click" and args[2] == 1 then
  366.             if (args[3] >= 7 and args[3] <= 21) and (args[4] == 10) then
  367.                 return true
  368.             elseif (args[3] >= 31 and args[3] <= 46) and (args[4] == 10) then
  369.                 return false
  370.             end
  371.         elseif args[1] == "char" then
  372.             if args[2] == "1" then
  373.                 return true
  374.             elseif args[2] == "2" then
  375.                 return false
  376.             end
  377.         end
  378.     end
  379. end
  380.  
  381. function xplore.main()
  382.     scroll = 0
  383.     col.screen("white", "white")
  384.     xplore.bar(true)
  385.     files = xplore.getdir(pathurl)
  386.     assert(type(files) == "table")
  387.  
  388.     xplore.drawdir(files, scroll, true)
  389.     os.startTimer(1.5)
  390.  
  391.     while true do
  392.         local args = { os.pullEvent() }
  393.         if args[1] == "timer" then
  394.             files = xplore.getdir(pathurl)
  395.             xplore.drawdir(files, scroll, false)
  396.             os.startTimer(1.5)
  397.         elseif args[1] == "mouse_click" then
  398.             if args[2] == 1 then
  399.                 if args[3] == 51 and args[4] == 1 then
  400.                     local shalldo = xplore.popup("Exit xPlore?")
  401.                     if shalldo then
  402.                         col.screen("black")
  403.                         term.setCursorPos(1, 1)
  404.                         shell.run("shell")
  405.                     else
  406.                         xplore.bar()
  407.                         files = xplore.getdir(pathurl)
  408.                         scroll = 0
  409.                         xplore.drawdir(files, scroll, true)
  410.                         os.startTimer(1.5)
  411.                     end
  412.                 elseif (args[3] >= 3 and args[3] <= 40) and (args[4] >= 3 and args[4] <= 18) then
  413.                     if files[2][args[4] + scroll - 2] == "dir" then
  414.                         pathurl = pathurl..""..files[1][args[4] + scroll - 2].."/"
  415.                         table.insert(tHistory, pathurl)
  416.                         xplore.bar()
  417.                         files = xplore.getdir(pathurl)
  418.                         scroll = 0
  419.                         xplore.drawdir(files, scroll, true)
  420.                         os.startTimer(1.5)
  421.                     elseif files[2][args[4] + scroll - 2] == "file" then
  422.                         local shalldo = xplore.popup("Do you wish to run this file?")
  423.                         if shalldo then
  424.                             col.screen("black")
  425.                             term.setCursorPos(1, 1)
  426.                             shell.run(fs.combine(pathurl, files[1][args[4] + scroll - 2]))
  427.                         end
  428.                         col.screen("white", "white")
  429.                         xplore.bar()
  430.                         files = xplore.getdir(pathurl)
  431.                         scroll = 0
  432.                         xplore.drawdir(files, scroll, false)
  433.                         os.startTimer(1.5)
  434.                     end
  435.                 elseif args[3] == 1 and args[4] == 1 then
  436.                     if #tHistory > 1 then
  437.                         table.remove(tHistory, #tHistory)
  438.                         pathurl = tHistory[#tHistory]
  439.                         xplore.bar()
  440.                         files = xplore.getdir(pathurl)
  441.                         scroll = 0
  442.                         xplore.drawdir(files, scroll, true)
  443.                         os.startTimer(1.5)
  444.                     end
  445.                 elseif (args[3] >= 41 and args[3] <= 50) then
  446.                     if args[4] == 5 then
  447.                         -- Create Folder
  448.                         local nameinput = xplore.input("Folder name:")
  449.                         if nameinput:find("/") then
  450.                             draw.popup("Please do not add a '/'; this is automatic")
  451.                             sleep(1)
  452.                             xplore.main()
  453.                         else
  454.                             fs.makeDir(fs.combine(pathurl, nameinput))
  455.                             col.screen("white", "white")
  456.                             xplore.bar()
  457.                             files = xplore.getdir(pathurl)
  458.                             scroll = 0
  459.                             xplore.drawdir(files, scroll, false)
  460.                             os.startTimer(1.5)
  461.                         end
  462.                     elseif args[4] == 6 then
  463.                         -- Create Empty File
  464.                         local nameinput = xplore.input("File name:")
  465.                         if nameinput:find("/") then
  466.                             draw.popup("Please do not add a '/'; this is automatic")
  467.                             sleep(1)
  468.                             xplore.main()
  469.                         else
  470.                             local temp = fs.open(fs.combine(pathurl, nameinput), "w")
  471.                             temp.write(" ")
  472.                             temp.close()
  473.                             col.screen("white", "white")
  474.                             xplore.bar()
  475.                             files = xplore.getdir(pathurl)
  476.                             scroll = 0
  477.                             xplore.drawdir(files, scroll, false)
  478.                             os.startTimer(1.5)
  479.                         end
  480.                     elseif args[4] == 10 then
  481.                         -- Download File (Pastebin)
  482.                         local pastecode = xplore.input("Pastebin code (8 chars):")
  483.                         local filename = xplore.input("Save as:")
  484.                         if pastecode:len() == 8 then
  485.                             shell.run("pastebin get "..pastecode.." "..fs.combine(pathurl, filename))
  486.                             xplore.bar()
  487.                             files = xplore.getdir(pathurl)
  488.                             scroll = 0
  489.                             xplore.drawdir(files, scroll, false)
  490.                             os.startTimer(1.5)
  491.                         else
  492.                             draw.popup("A pastebin code has 8 characters")
  493.                             sleep(1)
  494.                             xplore.main()
  495.                         end
  496.                     elseif args[4] == 11 then
  497.                         -- Download File (URL)
  498.  
  499.                         local urlcode = xplore.input("URL code:")
  500.                         local filename = xplore.input("Save as:")
  501.                         req = http.get(urlcode)
  502.                         if req then
  503.                             req = req.readAll()
  504.                             local temp = fs.open(fs.combine(pathurl, filename), "w")
  505.                             temp.write(req)
  506.                             temp.close()
  507.                             draw.popup("Downloaded...")
  508.                             sleep(1.5)
  509.                             xplore.bar()
  510.                             files = xplore.getdir(pathurl)
  511.                             scroll = 0
  512.                             xplore.drawdir(files, scroll, false)
  513.                             os.startTimer(1.5)
  514.                         else
  515.                             draw.popup("Failed to download file...")
  516.                             sleep(1.5)
  517.                             xplore.bar()
  518.                             files = xplore.getdir(pathurl)
  519.                             scroll = 0
  520.                             xplore.drawdir(files, scroll, false)
  521.                             os.startTimer(1.5)
  522.                         end
  523.                     elseif args[4] == 15 then
  524.                         -- Search Files
  525.                         xplore.find()
  526.                     end
  527.                 end
  528.             elseif args[2] == 2 then
  529.                 if (args[3] >= 3 and args[3] <= 40) and (args[4] >= 3 and args[4] <= 18) then
  530.                     if args[4] + scroll - 2 <= #files[1] then
  531.                         local command = xplore.filemenu(fs.combine(pathurl, files[1][args[4] + scroll - 2]), files[2][args[4] + scroll - 2], pathurl)
  532.                         xplore.bar()
  533.                         files = xplore.getdir(pathurl)
  534.                         scroll = 0
  535.                         xplore.drawdir(files, scroll, false)
  536.                         os.startTimer(1.5)
  537.                     else
  538.                         local command = xplore.filemenu("nil", "nil", pathurl)
  539.                         xplore.bar()
  540.                         files = xplore.getdir(pathurl)
  541.                         scroll = 0
  542.                         xplore.drawdir(files, scroll, false)
  543.                         os.startTimer(1.5)
  544.                     end
  545.                 end
  546.             end
  547.         elseif args[1] == "mouse_scroll" then
  548.             if args[2] == -1 then
  549.                 -- Scroll up
  550.                 if scroll > 0 then
  551.                     scroll = scroll - 1
  552.                     xplore.drawdir(files, scroll)
  553.                 end
  554.             elseif args[2] == 1 then
  555.                 -- Scroll down
  556.                 if scroll < #files[1] - 16 then
  557.                     scroll = scroll + 1
  558.                     xplore.drawdir(files, scroll)
  559.                 end
  560.             end
  561.         end
  562.     end
  563. end
  564.  
  565. function xplore.filemenu(filepath, filetype, pathdata)
  566.     if filetype == "dir" then
  567.         draw.texta(" Options: ", 17, 6, false, "lime", "cyan")
  568.         sleep(0.05)
  569.         draw.texta(" -------- ", 17, 7, false, "lime", "cyan")
  570.         sleep(0.05)
  571.         draw.texta(" Rename   ", 17, 8, false, "white", "cyan")
  572.         sleep(0.05)
  573.         if datacopied then
  574.             draw.texta(" Paste    ", 17, 9, false, "white", "cyan")
  575.         else
  576.             draw.texta(" Copy     ", 17, 9, false, "white", "cyan")
  577.         end
  578.         sleep(0.05)
  579.         draw.texta(" Delete   ", 17, 10, false, "white", "cyan")
  580.         while true do
  581.             local args = { os.pullEvent("mouse_click") }
  582.             if args[2] == 1 then
  583.                 if (args[3] >= 17 and args[3] <= 26) then
  584.                     if args[4] == 8 then
  585.                         -- Move folder
  586.                         local newpath = xplore.input("New folder name:")
  587.                         fs.move(filepath, newpath)
  588.                         draw.popup("Completed..")
  589.                         sleep(1)
  590.                         break
  591.                     elseif args[4] == 9 then
  592.                         -- Copy folder
  593.                         if datacopied then
  594.                             fs.copy(CLIPBOARD[1], fs.combine(pathdata, CLIPBOARD[2]))
  595.                             datacopied = false
  596.                             CLIPBOARD = nil
  597.                             draw.popup("Pasted..")
  598.                             sleep(1)
  599.                             break
  600.                         else
  601.                             CLIPBOARD = {filepath, filepath:sub(pathdata:len())}
  602.                             datacopied = true
  603.                             draw.popup("Copied..")
  604.                             sleep(1)
  605.                             break
  606.                         end
  607.                     elseif args[4] == 10 then
  608.                         -- Delete folder
  609.                         local shalldo = xplore.popup("Delete folder?")
  610.                         if shalldo then
  611.                             fs.delete(filepath)
  612.                             draw.popup("Completed..")
  613.                             sleep(1)
  614.                         end
  615.                         break
  616.                     end
  617.                 end
  618.             end
  619.             break
  620.         end
  621.     elseif filetype == "file" then
  622.         draw.texta(" Options: ", 17, 6, false, "lime", "cyan")
  623.         sleep(0.05)
  624.         draw.texta(" -------- ", 17, 7, false, "lime", "cyan")
  625.         sleep(0.05)
  626.         draw.texta(" Rename   ", 17, 8, false, "white", "cyan")
  627.         sleep(0.05)
  628.         if datacopied then
  629.             draw.texta(" Paste    ", 17, 9, false, "white", "cyan")
  630.         else
  631.             draw.texta(" Copy     ", 17, 9, false, "white", "cyan")
  632.         end
  633.         sleep(0.05)
  634.         draw.texta(" Delete   ", 17, 10, false, "white", "cyan")
  635.         sleep(0.05)
  636.         draw.texta(" Edit     ", 17, 11, false, "white", "cyan")
  637.         while true do
  638.             local args = { os.pullEvent("mouse_click") }
  639.             if args[2] == 1 then
  640.                 if (args[3] >= 17 and args[3] <= 26) then
  641.                     if args[4] == 8 then
  642.                         -- Move file
  643.                         local newpath = xplore.input("New file name:")
  644.                         fs.move(filepath, newpath)
  645.                         draw.popup("Completed..")
  646.                         sleep(1)
  647.                         break
  648.                     elseif args[4] == 9 then
  649.                         -- Copy folder
  650.                         if datacopied then
  651.                             fs.copy(CLIPBOARD[1], fs.combine(pathdata, CLIPBOARD[2]))
  652.                             datacopied = false
  653.                             CLIPBOARD = nil
  654.                             draw.popup("Pasted..")
  655.                             sleep(1)
  656.                             break
  657.                         else
  658.                             CLIPBOARD = {filepath, filepath:sub(pathdata:len())}
  659.                             datacopied = true
  660.                             draw.popup("Copied..")
  661.                             sleep(1)
  662.                             break
  663.                         end
  664.                     elseif args[4] == 10 then
  665.                         -- Delete file
  666.                         local shalldo = xplore.popup("Delete file?")
  667.                         if shalldo then
  668.                             fs.delete(filepath)
  669.                             draw.popup("Completed..")
  670.                             sleep(1)
  671.                         end
  672.                         break
  673.                     elseif args[4] == 11 then
  674.                         -- Edit
  675.                         local shalldo = xplore.popup("Edit file?")
  676.                         if shalldo then
  677.                             shell.run("edit "..filepath)
  678.                         end
  679.                         break
  680.                     end
  681.                 end
  682.             end
  683.             break
  684.         end
  685.     elseif filetype == "nil" then
  686.         draw.texta(" Options: ", 17, 6, false, "lime", "cyan")
  687.         sleep(0.05)
  688.         draw.texta(" -------- ", 17, 7, false, "lime", "cyan")
  689.         sleep(0.05)
  690.         if datacopied then
  691.             draw.texta(" Paste    ", 17, 8, false, "white", "cyan")
  692.         end
  693.         while true do
  694.             local args = { os.pullEvent("mouse_click") }
  695.             if args[2] == 1 then
  696.                 if (args[3] >= 17 and args[3] <= 26) then
  697.                     if args[4] == 8 then
  698.                         -- Copy folder
  699.                         if datacopied then
  700.                             fs.copy(CLIPBOARD[1], fs.combine(pathdata, CLIPBOARD[2]))
  701.                             datacopied = false
  702.                             CLIPBOARD = nil
  703.                             draw.popup("Pasted..")
  704.                             sleep(1)
  705.                             break
  706.                         end
  707.                     end
  708.                 end
  709.             end
  710.             break
  711.         end
  712.     end
  713. end
  714.  
  715. function xplore.input(inputname)
  716.     draw.box(5, 43, 8, 3, " ", "grey", "grey")
  717.     draw.box(5, 43, 9, 1, " ", "grey", "grey")
  718.     draw.textc(" "..inputname, 8, false, "white", "grey")
  719.     draw.box(7, 39, 9, 1, " ", "cyan", "cyan")
  720.     term.setCursorPos(7, 9)
  721.     col.set("white", "cyan")
  722.     write(": ")
  723.     return tostring(read())
  724. end
  725.  
  726. function xplore.error(errormessage)
  727.     col.screen("white")
  728.     draw.box(1, 51, 1, 1, false, "grey", "grey")
  729.     draw.textc(" xPlore: An error occured", 1, false, "lightBlue", "grey")
  730.     local sText = "xPlore has ran into an error that it could not fix, or find a work around. We will attempt to restart the script again, if this error persists you will be redirected to a terminal. Please use the settings to set a return program in case of crashes."
  731.     for k,v in ipairs(data.wordwrap(sText, 51)) do
  732.         draw.texta(v, 1, k+2, false, "lightGrey", "white")
  733.     end
  734.     draw.texta("FYI (Error Code):", 3, 10, false, "black", "white")
  735.     for k,v in ipairs(data.wordwrap(errormessage, 51)) do
  736.         draw.texta(v, 1, k+11, false, "red", "white")
  737.     end
  738.  
  739.     for i = 1, 47 do
  740.         draw.texta(" ", i+2, 15, false, "blue", "blue")
  741.         sleep(0.25)
  742.     end
  743.  
  744.     local ok, err = pcall(function()
  745.         xplore.main()
  746.     end)
  747.  
  748.     if not ok then
  749.         col.screen("black")
  750.         term.setCursorPos(1, 1)
  751.         shell.run("shell")
  752.     end
  753. end
  754.  
  755. xplore.get()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement