Advertisement
Guest User

File

a guest
Sep 2nd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.57 KB | None | 0 0
  1.  
  2. root = "/"
  3. scroll = 0
  4. allowScroll = false
  5. scrollText = ""
  6. rendLine = true
  7. fileSelected = ""
  8. clickDoubleTimer = false
  9. lasClickDoubleTimer = false
  10. cdTimer = 0
  11. cdLasTimer = 0
  12. cdTotalTimer = 0
  13. copyFile = ""
  14. deleteFiles = true
  15. openWith = ""
  16. Who = "By DmndZombieSlayer"
  17. instaClose = true
  18. Version = "Dmnd File Manager v0.1.1"
  19. timeX = ""
  20. renderTime = true
  21. dragLasY = 0
  22. changepos = true
  23. --TEXT ENTER VAR
  24. enterText = false
  25. textData = ""
  26. textPurpose = ""
  27. --END
  28. fSetFile = true
  29. loopRun = true
  30. w, h = term.getSize()
  31. h = h - 1
  32. renderXX = true
  33. --DEBUG FEATURE REMOVE
  34. renstr = ""
  35. --END
  36. blackStr = ""
  37. for i=1,w do
  38.     blackStr = blackStr.." "
  39. end
  40. menuVisible = false
  41. menuX = w + 50
  42. menuY = h + 51
  43. menuWidth = 10
  44. menuHeight = 7
  45. menuItems = {}
  46. menuItemsRenX = {}
  47. filesx = {}
  48. directoriesx = {}
  49. xtra = 3
  50. screenpos = {}
  51. filepos = {}
  52. menuCheck = false
  53.  
  54. function startMain()
  55.    
  56.     function Even(number)
  57.         even = true
  58.         for i=1,number do
  59.             if even == true then
  60.                 even = false
  61.             else
  62.                 even = true
  63.             end
  64.         end
  65.         return even
  66.     end
  67.    
  68.     function displayError(errorA)
  69.         renderXX = false
  70.         term.clear()
  71.         term.setCursorPos(w / 2 + string.len(errorA) / 2, h + 1 / 2)
  72.         write(errorA)
  73.         os.pullEvent("key")
  74.         renderXX = true
  75.     end
  76.    
  77.     function keyPressWait()
  78.         print("[Lemon] Press Any Key...")
  79.         os.pullEvent("key")
  80.     end
  81.    
  82.     function fManRun(locationPath)
  83.         if fs.exists(locationPath) == true then
  84.             if openWith ~= "" then
  85.                 renderXX = false
  86.                 term.setBackgroundColor(colors.black)
  87.                 term.setTextColor(colors.white)
  88.                 term.clear()
  89.                 term.setCursorPos(1, 1)
  90.                 function runProgram()
  91.                     shell.run(locationPath, tostring(openWith))
  92.                 end
  93.                 function terminateKey()
  94.                     while true do
  95.                         local event, key = os.pullEvent("key")
  96.                         if key == 63 then
  97.                             break
  98.                         end
  99.                     end
  100.                 end
  101.                 parallel.waitForAny(runProgram, terminateKey)
  102.                 print("[Lemon] Press Any Key...")
  103.                 os.pullEvent("key")
  104.                 renderXX = true
  105.                 openWith = ""
  106.             else
  107.                 renderXX = false
  108.                 term.setBackgroundColor(colors.black)
  109.                 term.setTextColor(colors.white)
  110.                 term.clear()
  111.                 term.setCursorPos(1, 1)
  112.                 function runProgram()
  113.                     shell.run(locationPath)
  114.                 end
  115.                 function terminateKey()
  116.                     while true do
  117.                         local event, key = os.pullEvent("key")
  118.                         if key == 63 then
  119.                             break
  120.                         end
  121.                     end
  122.                 end
  123.                 parallel.waitForAny(runProgram, terminateKey)
  124.                 print("[Lemon] Press Any Key...")
  125.                 os.pullEvent("key")
  126.                 renderXX = true
  127.             end
  128.         end
  129.     end
  130.    
  131.     function dataReader(data, sep, onelas, cooler)
  132.         if type(data) == "string" then
  133.             dataR = {}
  134.             dataR[1] = ""
  135.             readingIndex = 1
  136.             for i=1,string.len(data) do
  137.                 currChar = string.sub(data, i, i)
  138.                 if currChar == sep then
  139.                     readingIndex = readingIndex + 1
  140.                     dataR[readingIndex] = ""
  141.                 else
  142.                     dataR[readingIndex] = dataR[readingIndex]..currChar
  143.                 end
  144.             end
  145.         else
  146.             dataR[1] = ""
  147.         end
  148.         if onelas == 1 then
  149.             dataR[1] = dataR[readingIndex]
  150.         end
  151.         if cooler == 1 then
  152.             dataR[1] = readingIndex
  153.         end
  154.         return dataR
  155.     end
  156.    
  157.     function menuResolve(menuString, argsxx)
  158.         if menuString == "Run" then
  159.             if fs.isDir(root..fileSelected) == false then
  160.                 fManRun(root..fileSelected)
  161.             else
  162.                 if changepos == true then
  163.                     root = root..fileSelected.."/"
  164.                 end
  165.                 fileSelected = ""
  166.             end
  167.         elseif menuString == "Edit" then
  168.             if fs.isDir(root..fileSelected) == false then
  169.                 renderXX = false
  170.                 term.setBackgroundColor(colors.black)
  171.                 term.setTextColor(colors.white)
  172.                 term.clear()
  173.                 term.setCursorPos(1, 1)
  174.                 shell.run("edit", root..fileSelected)
  175.                 renderXX = true
  176.             end
  177.         elseif menuString == "Copy" then
  178.             copyFile = root..fileSelected
  179.         elseif menuString == "Delete" then
  180.             if fs.exists(root..fileSelected) == true then
  181.                 if deleteFiles == true then
  182.                     fs.delete(root..fileSelected)
  183.                     fileSelected = nil
  184.                 end
  185.             end
  186.         elseif menuString == "Deselect" then
  187.             if changepos == true then
  188.                 fileSelected = ""
  189.             end
  190.         elseif menuString == "Open with" then
  191.             if openWith == "" then
  192.                 openWith = root..fileSelected
  193.             else
  194.                 openWith = ""
  195.             end
  196.         elseif menuString == "Yes" then
  197.             loopRun = false
  198.             term.setBackgroundColor(colors.black)
  199.             term.setTextColor(colors.white)
  200.             term.clear()
  201.             term.setCursorPos(1, 1)
  202.             loopRun = false
  203.         elseif menuString == "No" then
  204.             fSetFile = true
  205.             if fileSelected == "" then
  206.                 menuItems = {"Paste", "New", "nfx"}
  207.                 menuItemsRenX = {"  Paste   ", "   New    ", "New Folder"}
  208.             else
  209.                 menuItems = {"Run", "----------", "Edit", "Copy", "Delete", "Deselect", "Open with", "rnm"}
  210.                 menuItemsRenX = {"   Run    ", "----------", "   Edit   ", "   Copy   ", "  Delete  ", " Deselect ", "Open With.", "  Rename  "}
  211.             end
  212.         elseif menuString == "nfx" then
  213.             enterText = true
  214.             textData = ""
  215.             textPurpose = "nf"
  216.         elseif menuString == "nf" then
  217.             if argsxx ~= nil then
  218.                 if fs.exists(root..argsxx) == false then
  219.                     fs.makeDir(argsxx)
  220.                     fileSelected = argsxx
  221.                 end
  222.             end
  223.         elseif menuString == "Paste" then
  224.             if fs.exists(copyFile) == true then
  225.                 copyFileString = dataReader(copyFile, "/", 1)[1]
  226.                 if fs.exists(root..copyFileString) == true then
  227.                    
  228.                 else
  229.                    
  230.                 end
  231.                 copyFileRoot = ""
  232.                 rootsX = tostring(dataReader(copyFile, "/", 0, 1)[1])
  233.                 --rootsX = 3
  234.                 for i=2,rootsX - 1 do
  235.                     copyFileRoot = copyFileRoot.."/"..dataReader(copyFile, "/", 0, 0)[i]
  236.                 end
  237.                 copyFileRoot = copyFileRoot.."/"
  238.                 rnn = copyFileString
  239.                 num = 2
  240.                 errorX = false
  241.                 if fs.exists(root..rnn) == true then
  242.                     while true do
  243.                         if fs.exists(root..rnn) == true then
  244.                             rnn = copyFileString
  245.                             rnn = rnn..tostring(num)
  246.                             num = num + 1
  247.                         else
  248.                             break
  249.                         end
  250.                     end
  251.                 end
  252.                 if fs.isDir(copyFile) == true then
  253.                     fs.copy(copyFile, root..rnn)
  254.                 else
  255.                     readerX = fs.open(copyFile, "r")
  256.                     copyDataX = readerX.readAll()
  257.                     readerX.close()
  258.                     writerX = fs.open(root..rnn, "w")
  259.                     writerX.write(copyDataX)
  260.                     writerX.close()
  261.                 end
  262.             end
  263.         elseif menuString == "rnm" then
  264.             changepos = false
  265.             enterText = true
  266.             textData = ""
  267.             textPurpose = "rename"
  268.         elseif menuString == "rename" then
  269.             if fileSelected ~= nil and fileSelected ~= "" then
  270.                 if fs.exists(root..tostring(argsxx)) == false then
  271.                     fs.copy(root..fileSelected, root..tostring(argsxx))
  272.                     fs.delete(root..fileSelected)
  273.                     fileSelected = nil
  274.                 end
  275.                 changepos = true
  276.             end
  277.         elseif menuString == "New" then
  278.             enterText = true
  279.             textData = ""
  280.             textPurpose = "nw"
  281.         elseif menuString == "nw" then
  282.             if fs.exists(root..argsxx) == false then
  283.                 fileNew = fs.open(root..argsxx, "w")
  284.                 fileNew.write("")
  285.                 fileNew.close()
  286.                 fileSelected = argsxx
  287.             end
  288.         else
  289.        
  290.         end
  291.     end
  292.  
  293.     function backUpRoot(rootP)
  294.         if rootP ~= "/" then
  295.             rootx = rootP
  296.             lef = string.len(rootP) - 1
  297.             for i=1,string.len(rootP) do
  298.                 check = i + lef
  299.                 check = check - 1
  300.                 if check > 0 then
  301.                     --DO CHECK HERE
  302.                     if string.sub(rootP, check, check) == "/" then
  303.                         break
  304.                     end
  305.                     --END CHECK HERE
  306.                     lef = lef - 2
  307.                 end
  308.             end
  309.             rootx = string.sub(rootx, 1, check)
  310.         else
  311.             rootx = rootP
  312.         end
  313.         return rootx
  314.     end
  315.  
  316.     function getFiles(path, many)
  317.         files = {"", ""}
  318.         mIndex = 1
  319.         cout = 0
  320.         sDir = shell.resolve( path )
  321.         local tAll = fs.list( sDir )
  322.         for n, sItem in pairs( tAll ) do
  323.             local sPath = fs.combine( sDir, sItem )
  324.             if fs.isDir( sPath ) == false then
  325.                 files[mIndex] = dataReader(sPath, "/", 1)[1]
  326.                 mIndex = mIndex + 1
  327.                 files[mIndex] = ""
  328.                 cout = cout + 1
  329.             end
  330.         end
  331.         if many == 1 then
  332.             files[1] = cout
  333.         end
  334.         return files
  335.     end
  336.  
  337.     function getDirectories(path, many)
  338.         directories = {"", ""}
  339.         mIndex = 1
  340.         cout = 0
  341.         sDir = shell.resolve( path )
  342.         local tAll = fs.list( sDir )
  343.         for n, sItem in pairs( tAll ) do
  344.             local sPath = fs.combine( sDir, sItem )
  345.             if fs.isDir( sPath ) then
  346.                 directories[mIndex] = dataReader(sPath, "/", 1)[1]
  347.                 mIndex = mIndex + 1
  348.                 directories[mIndex] = ""
  349.                 cout = cout + 1
  350.             end
  351.         end
  352.         if many == 1 then
  353.             directories[1] = cout
  354.         end
  355.         return directories
  356.     end
  357.  
  358.     function updateList()
  359.         filesMany = getFiles(root, 1)[1]
  360.         directoriesMany = getDirectories(root, 1)[1]
  361.         filesx = getFiles(root, 0)
  362.         directoriesx = getDirectories(root, 0)
  363.         scrollText = ""
  364.         for i=1,w / 2 do
  365.             scrollText = scrollText.."v"
  366.         end
  367.         for i=1,w / 2 do
  368.             scrollText = scrollText.."^"
  369.         end
  370.         if fileSelected == nil or fileSelected == " " then
  371.             fileSelected = ""
  372.         end
  373.         menuVisible = true
  374.         menuX = w - menuWidth - 1
  375.         menuY = 2
  376.         renstr = openWith
  377.         if fSetFile == true then
  378.             if fileSelected == "" or fileSelected == nil or fileSelected == " " then
  379.                 menuItems = {"Paste", "New", "nfx"}
  380.                 menuItemsRenX = {"  Paste   ", " New File ", "New Folder"}
  381.             else
  382.                 menuItems = {"Run", "----------", "Edit", "Copy", "Delete", "Deselect", "Open with", "rnm"}
  383.                 menuItemsRenX = {"   Run    ", "----------", "   Edit   ", "   Copy   ", "  Delete  ", " Deselect ", "Open With.", "  Rename  "}
  384.             end
  385.         end
  386.         menuHeight = table.getn(menuItems)
  387.         timeX = tostring(textutils.formatTime(os.time(), false))
  388.         if string.sub(root, string.len(root) - 1, string.len(root)) == "//" then
  389.             root = string.sub(root, 1, string.len(root) - 1)
  390.         end
  391.     end
  392.    
  393.     function drawScreen()
  394.         if renderXX == true then
  395.             term.setBackgroundColor(colors.white)
  396.             term.clear()
  397.             ind = 1
  398.             allowScroll = true
  399.             for i=4,h do
  400.                 term.setCursorPos(1, i)
  401.                 --RENDER AND DOCUMENT ALL FILES!!
  402.                 if directoriesx[i - 3 + scroll] ~= nil and directoriesx[i - 3 + scroll] ~= "" then
  403.                     term.setBackgroundColor(colors.gray)
  404.                     term.setTextColor(colors.white)
  405.                     write("[=]")
  406.                     term.setBackgroundColor(colors.white)
  407.                     term.setTextColor(colors.gray)
  408.                     screenpos[i] = directoriesx[i - 3 + scroll]
  409.                     if directoriesx[i - 3 + scroll] == fileSelected then
  410.                         term.setBackgroundColor(colors.lightBlue)
  411.                         write(" "..directoriesx[i - 3 + scroll]..string.sub(blackStr, 1, w))
  412.                     else
  413.                         write(" "..directoriesx[i - 3 + scroll])
  414.                     end
  415.                 end
  416.                 if ind > directoriesMany - scroll then
  417.                     if filesx[ind - directoriesMany + scroll] ~= nil and filesx[ind - directoriesMany + scroll] ~= "" then
  418.                         term.setBackgroundColor(colors.gray)
  419.                         if openWith ~= "" then
  420.                             if openWith ~= root..filesx[ind - directoriesMany + scroll] then
  421.                                 term.setTextColor(colors.orange)
  422.                             else
  423.                                 term.setTextColor(colors.lime)
  424.                             end
  425.                         else
  426.                             term.setTextColor(colors.lime)
  427.                         end
  428.                         write("-~-")
  429.                         term.setBackgroundColor(colors.white)
  430.                         term.setTextColor(colors.gray)
  431.                         filepos[i] = filesx[ind - directoriesMany + scroll]
  432.                         if filesx[ind - directoriesMany + scroll] == fileSelected then
  433.                             term.setBackgroundColor(colors.lightBlue)
  434.                             write(" "..filesx[ind - directoriesMany + scroll]..string.sub(blackStr, 1, w))
  435.                         else
  436.                             write(" "..filesx[ind - directoriesMany + scroll])
  437.                         end
  438.                     end
  439.                 end
  440.                 --END
  441.                 ind = ind + 1
  442.             end
  443.             term.setBackgroundColor(colors.lightBlue)
  444.             term.setCursorPos(1, 1)
  445.             term.clearLine()
  446.             term.setTextColor(colors.white)
  447.             write("[Close]")
  448.             if renderTime == true then
  449.                 term.setCursorPos(w - string.len(timeX), 1)
  450.                 write(timeX)
  451.             end
  452.             term.setTextColor(colors.lightGray)
  453.             term.setBackgroundColor(colors.white)
  454.             term.setCursorPos(1, 2)
  455.             write(root..string.sub(blackStr, 1, w))
  456.             term.setCursorPos(1, 3)
  457.             term.setBackgroundColor(colors.gray)
  458.             term.setTextColor(colors.lightBlue)
  459.             write("<< ")
  460.             if fileSelected == ".." then
  461.                 term.setBackgroundColor(colors.lightBlue)
  462.             else
  463.                 term.setBackgroundColor(colors.white)
  464.             end
  465.             term.setTextColor(colors.lightGray)
  466.             write(" .."..string.sub(blackStr, 1, w))
  467.             term.setCursorPos(1, h + 1)
  468.             term.setBackgroundColor(colors.yellow)
  469.             term.clearLine()
  470.             term.setTextColor(colors.cyan)
  471.             if enterText == false then
  472.                 write(Version.." "..Who)
  473.             else
  474.                 write(textData.."|")
  475.             end
  476.             if allowScroll == true then
  477.                 term.setCursorPos(w, h + 1)
  478.                 term.setBackgroundColor(colors.gray)
  479.                 term.setTextColor(colors.white)
  480.                 if scroll < directoriesMany + filesMany - h + 3 then
  481.                     write("v")
  482.                 else
  483.                     write(" ")
  484.                 end
  485.                 term.setCursorPos(w, 2)
  486.                 if scroll ~= 0 then
  487.                     write("^")
  488.                 else
  489.                     write(" ")
  490.                 end
  491.                 term.setCursorPos(w - 1, h + 1)
  492.                 term.setBackgroundColor(colors.gray)
  493.                 term.setTextColor(colors.white)
  494.                 if scroll < directoriesMany + filesMany - h + 3 then
  495.                     write("v")
  496.                 else
  497.                     write(" ")
  498.                 end
  499.                 term.setCursorPos(w - 1, 2)
  500.                 if scroll ~= 0 then
  501.                     write("^")
  502.                 else
  503.                     write(" ")
  504.                 end
  505.                 if scroll < directoriesMany + filesMany - h + 3 or scroll ~= 0 then
  506.                     switch = 1
  507.                     for i=3,h do
  508.                         if switch == 1 then
  509.                             switch = 1
  510.                             term.setBackgroundColor(colors.gray)
  511.                         else
  512.                             switch = 1
  513.                             term.setBackgroundColor(colors.lightGray)
  514.                         end
  515.                         term.setCursorPos(w, i)
  516.                         write(" ")
  517.                         term.setCursorPos(w - 1, i)
  518.                         write(" ")
  519.                     end
  520.                 else
  521.                     for i=3,h do
  522.                         term.setBackgroundColor(colors.gray)
  523.                         term.setCursorPos(w, i)
  524.                         write(" ")
  525.                         term.setCursorPos(w - 1, i)
  526.                         write(" ")
  527.                     end
  528.                 end
  529.             end
  530.             if menuVisible == true then
  531.                 if fSetFile == true then
  532.                     term.setBackgroundColor(colors.cyan)
  533.                 else
  534.                     term.setBackgroundColor(colors.green)
  535.                 end
  536.                 term.setTextColor(colors.black)
  537.                 for i=1,table.getn(menuItems) do
  538.                     term.setCursorPos(menuX, menuY + i - 1)
  539.                     if menuItemsRenX[i] ~= nil then
  540.                         write(menuItemsRenX[i])
  541.                     end
  542.                 end
  543.                 for i=table.getn(menuItems) + 1,h + 1 do
  544.                     term.setCursorPos(menuX, menuY + i - 1)
  545.                     write("          ")
  546.                 end
  547.             end
  548.         end
  549.     end
  550.    
  551.     renDef = 5
  552.     ren = renDef
  553.    
  554.     function render()
  555.         while loopRun == true do
  556.             sleep(0)
  557.             if loopRun == false then
  558.                 term.setBackgroundColor(colors.black)
  559.                 term.setTextColor(colors.white)
  560.                 term.clear()
  561.                 term.setCursorPos(1, 1)
  562.             end
  563.             if ren < 1 then
  564.                 drawScreen()
  565.                 ren = renDef
  566.             else
  567.                 ren = ren - 1
  568.             end
  569.             if loopRun == false then
  570.                 term.setBackgroundColor(colors.black)
  571.                 term.setTextColor(colors.white)
  572.                 term.clear()
  573.                 term.setCursorPos(1, 1)
  574.             end
  575.         end
  576.     end
  577.    
  578.     function guiController()
  579.         while true do
  580.             sleep(0)
  581.             if clickDoubleTimer ~= lasClickDoubleTimer then
  582.                 if clickDoubleTimer == true then
  583.                     cdTimer = os.time()
  584.                     cdLasTimer = os.time()
  585.                 else
  586.                     cdTotalTimer = 0
  587.                 end
  588.                 lasClickDoubleTimer = clickDoubleTimer
  589.             end
  590.             if clickDoubleTimer == true then
  591.                 cdTimer = os.time()
  592.                 cdTotalTimer = cdTimer - cdLasTimer
  593.                 if cdTotalTimer > 0.003 then
  594.                     clickDoubleTimer = false
  595.                 end
  596.             end
  597.         end
  598.     end
  599.    
  600.     function input()
  601.         while true do
  602.             local event, p1, p2, p3 = os.pullEvent()
  603.             if event == "mouse_click" then
  604.                 if menuVisible == false then
  605.                     menuCheck = true
  606.                 else
  607.                     if p2 > menuX - 1 and p2 < menuX - 1 + menuWidth + 1 and p3 > menuY - 1 and p3 < menuY - 1 + menuHeight + 1 then
  608.                         menuCheck = false
  609.                         itM = p3 - menuY + 1
  610.                         if menuItems[itM] ~= nil then
  611.                             if fSetFile == true then
  612.                                 if fileSelected ~= nil and fileSelected ~= "" then
  613.                                     menuResolve(tostring(menuItems[itM]))
  614.                                 end
  615.                                 if fileSelected == "" then
  616.                                     menuResolve(tostring(menuItems[itM]))
  617.                                 end
  618.                             else
  619.                                 menuResolve(tostring(menuItems[itM]))
  620.                             end
  621.                         else
  622.                             break
  623.                         end
  624.                     else
  625.                         menuCheck = true
  626.                     end
  627.                 end
  628.                 if menuCheck == true then
  629.                     if p3 == 1 then
  630.                         if p1 == 1 then
  631.                             if p2 < 8 then
  632.                                 if instaClose == true then
  633.                                     menuResolve("Yes")
  634.                                 else
  635.                                     fSetFile = false
  636.                                     menuItems = {"Yes", "No"}
  637.                                     menuItemsRenX = {"   Yes    ", "    No    "}
  638.                                 end
  639.                             end
  640.                         end
  641.                     elseif p3 == 3 then
  642.                         if changepos == true then
  643.                             fileSelected = ".."
  644.                         end
  645.                         if cdTotalTimer ~= 0 then
  646.                             if changepos == true then
  647.                                 root = backUpRoot(root)
  648.                             end
  649.                             scroll = 0
  650.                         end
  651.                         clickDoubleTimer = true
  652.                     elseif p3 < h + 1 then
  653.                         if p3 ~= 2 then
  654.                             if p2 <= w - menuWidth - 2 then
  655.                                 pe = p3 - 4
  656.                                 file11 = false
  657.                                 if pe >= directoriesMany - scroll then
  658.                                     --Clicked On A File
  659.                                     if filepos[p3] ~= nil and filepos[p3] ~= "" then
  660.                                         file11 = true
  661.                                         --renderXX = false
  662.                                         --term.setBackgroundColor(colors.black)
  663.                                         --term.setTextColor(colors.white)
  664.                                         --term.clear()
  665.                                         --term.setCursorPos(1, 1)
  666.                                         --shell.run(root..filepos[p3])
  667.                                         --renderXX = true
  668.                                         if p1 == 1 then
  669.                                             if changepos == true then
  670.                                                 fileSelected = filepos[p3]
  671.                                             end
  672.                                             if cdTotalTimer ~= 0 then
  673.                                                 fManRun(root..fileSelected)
  674.                                                 end
  675.                                                 clickDoubleTimer = true
  676.                                             end
  677.                                         else
  678.                                             if changepos == true then
  679.                                                 fileSelected = filepos[p3]
  680.                                             end
  681.                                         end
  682.                                     else
  683.                                     --Clicked On A Folder
  684.                                     if screenpos[p3] ~= nil and screenpos[p3] ~= "" then
  685.                                         if p1 == 1 then
  686.                                             if changepos == true then
  687.                                                 fileSelected = screenpos[p3]
  688.                                             end
  689.                                             if cdTotalTimer ~= 0 then
  690.                                                 if changepos == true then
  691.                                                     root = root..screenpos[p3].."/"
  692.                                                 end
  693.                                                 if changepos == true then
  694.                                                     fileSelected = ""
  695.                                                 end
  696.                                             end
  697.                                             clickDoubleTimer = true
  698.                                         else
  699.                                             if changepos == true then
  700.                                                 fileSelected = screenpos[p3]
  701.                                             end
  702.                                         end
  703.                                     end
  704.                                 end
  705.                             end
  706.                         else
  707.                             if p2 >= w - 1 then
  708.                                 if allowScroll == true then
  709.                                     if scroll ~= 0 then
  710.                                         scroll = scroll - 1
  711.                                     end
  712.                                 end
  713.                             end
  714.                         end
  715.                     elseif p3 == h + 1 then
  716.                         if p2 >= w - 1 then
  717.                             if allowScroll == true then
  718.                                 if scroll < directoriesMany + filesMany - h + 3 then
  719.                                     scroll = scroll + 1
  720.                                 end
  721.                             end
  722.                         end
  723.                     end
  724.                 end
  725.             elseif event == "mouse_drag" then
  726.                 if allowScroll == true then
  727.                     if p2 >= w - 1 then
  728.                         if dragLasY ~= p3 then
  729.                             if p3 > dragLasY then
  730.                                 if scroll < directoriesMany + filesMany - h + 3 then
  731.                                     scroll = scroll + 1
  732.                                 end
  733.                             else
  734.                                 if scroll ~= 0 then
  735.                                     scroll = scroll - 1
  736.                                 end
  737.                             end
  738.                         end
  739.                         dragLasY = p3
  740.                     end
  741.                 end
  742.             elseif event == "mouse_scroll" then
  743.                 if allowScroll == true then
  744.                     if p1 == 1 then
  745.                         if scroll < directoriesMany + filesMany - h + 3 then
  746.                             scroll = scroll + 1
  747.                         end
  748.                     else
  749.                         if scroll ~= 0 then
  750.                             scroll = scroll - 1
  751.                         end
  752.                     end
  753.                 end
  754.             elseif event == "key" then
  755.                 if enterText == true then
  756.                     if p1 == 28 then
  757.                         local ok, err = (menuResolve(textPurpose, textData))
  758.                         textData = ""
  759.                         textPurpose = ""
  760.                         enterText = false
  761.                     elseif p1 == 14 then
  762.                         textData = string.sub(textData, 1, string.len(textData) - 1)
  763.                     end
  764.                 end
  765.             elseif event == "char" then
  766.                 if enterText == true then
  767.                     textData = textData..p1
  768.                 end
  769.             end
  770.             updateList()
  771.         end
  772.     end
  773.     updateList()
  774.    
  775.     parallel.waitForAny(render, input, guiController)
  776.  
  777. end
  778.  
  779. while true do
  780.     ok, err = pcall(startMain)
  781.     if not ok then
  782.         term.setBackgroundColor(colors.blue)
  783.         for i=-5,5 do
  784.             term.setCursorPos(1, h / 2 + i)
  785.             term.clearLine()
  786.         end
  787.         term.setTextColor(1)
  788.         term.setCursorPos(math.floor(w-string.len(" Runtime Error! "))/2, h / 2 - 4)
  789.         term.setBackgroundColor(colors.white)
  790.         term.setTextColor(colors.blue)
  791.         write(" Runtime Error! ")
  792.         term.setCursorPos(math.floor(w-string.len(err))/2, h / 2 - 2)
  793.         term.setBackgroundColor(colors.blue)
  794.         term.setTextColor(1)
  795.         write(err)
  796.         term.setCursorPos(math.floor(w-string.len("A/?? - Continue Program"))/2, h / 2 + 2)
  797.         write("A/?? - Continue Program")
  798.         term.setCursorPos(math.floor(w-string.len("B - Terminate Program"))/2, h / 2 + 4)
  799.         write("B - Terminate Program")
  800.         local event, p1 = os.pullEvent("char")
  801.         if p1 == "B" or p1 == "b" then
  802.             term.setBackgroundColor(colors.black)
  803.             term.setTextColor(colors.white)
  804.             term.setCursorPos(1, 1)
  805.             term.clear()
  806.             break
  807.         else
  808.             changepos = true
  809.             enterText = false
  810.             textData = ""
  811.             textPurpose = ""
  812.             updateList()
  813.         end
  814.     else
  815.         break
  816.     end
  817. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement