Advertisement
TheRockettek

KrapFile

Dec 27th, 2016
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.77 KB | None | 0 0
  1. version = "1.4"
  2. ----------------------------------------------------------
  3. --   ~". _^_ "~       --    KrapFile Version 1.4        --
  4. --   ~" (____) "~     --     Created by TehRockettek    --
  5. --   ~"(______) "~    --                                --
  6. --  " (________) "~   --    KrapFile is a simple file   --
  7. --  (____________) "  --    managing program and is     --
  8. --  KRAP    SOFTWARE  --    a much more optimized       --
  9. -- "Its like someone  --    version. This program will  --
  10. --  litteraly made    --    have much more features     --
  11. --  this whilst on    --    over time!                  --
  12. --  the toilet...  "  --                                --
  13. ----------------------------------------------------------
  14.  
  15. -- I sometimes livestream to youtube!                            --
  16. -- https://www.youtube.com/channel/UC_WsSgl1UL1USK4K0RplcnQ/live --
  17.  
  18. -- Older versions of craftOS dont support the characters used in
  19. -- KrapFile, if this is so just run -o after the program
  20.  
  21. term.setTextColour(colours.white)
  22. term.setBackgroundColour(colours.black)
  23. term.clear()
  24. term.setCursorPos(1,1)
  25.  
  26. if shell then
  27.     pgrm = "/" .. shell.getRunningProgram()
  28. else
  29.     pgrm = "/KrapFile.lua"
  30.     printError("Hmm, cant find shell api.")
  31.     os.pullEvent("key")
  32. end
  33.  
  34. args = { ... }
  35.  
  36. if http then
  37.     local pbl = http.get("http://pastebin.com/raw/wscpHypE")
  38.     if not pbl then
  39.         printError("Could not connect to pastebin")
  40.     else
  41.         latestver = string.gsub(pbl.readLine(),"version = ","")
  42.         latestver = string.gsub(latestver,"\"","")
  43.     end
  44. end
  45.  
  46. term.clear()
  47. terminal = term.current()
  48. resolution = {term.getSize()}
  49. dialoguevisible = false
  50. print("Debug use only")
  51. if _CC_VERSION then
  52.     ver = string.gsub(_CC_VERSION,"pr","")
  53.     supportspecialchars = (tonumber(ver) >= 1.76)
  54.     print("cc-ver: " .. _CC_VERSION)
  55. elseif _HOST then
  56.     supportspecialchars = true
  57.     --[[ver = string.gsub(_HOST,"pr","")
  58.     supportspecialchars = (tonumber(ver)) >= 1.76)
  59.     print("host: " .. _HOST)]]
  60. end
  61. if not supportspecialchars or args[1] == "-o" then
  62.     back = "<"
  63.     up = "^"
  64.     print("ssc: false")
  65. else
  66.     back = ""
  67.     up = ""
  68.     print("ssc: true")
  69. end
  70. print("kf-ver: " .. version)
  71. print("pb-ver: " .. latestver)
  72. print("rpgrm: " .. pgrm)
  73. sleep(1)
  74. local function minBytes(bytes)
  75.     if bytes > 1000000 then
  76.         return string.sub(bytes/1000000,1,string.len(math.ceil(bytes/1000000))+2) .. "M"
  77.     elseif bytes > 1000 then
  78.         return string.sub(bytes/1000,1,string.len(math.ceil(bytes/1000))+2) .. "K"
  79.     else
  80.         return bytes .. "B"
  81.     end
  82. end
  83.  
  84. if string.find(pgrm,"pastebin") then -- Detect if using pastebin run (show installer)
  85.     term.clear()
  86.     paintutils.drawFilledBox(1,1,resolution[1],resolution[2],colours.cyan)
  87.     local pastebin = http.get("http://www.pastebin.com/raw/wscpHypE")
  88.     filesize = minBytes(string.len(pastebin.readAll()))
  89.     term.setCursorPos(1,resolution[2])
  90.     term.write("File size: " .. filesize)
  91.     term.setCursorPos((resolution[1]-9)/2,resolution[2]/2)
  92.     term.write("Download!")
  93.     os.pullEvent("mouse_click")
  94.     term.clear()
  95.     paintutils.drawFilledBox(1,1,resolution[1],3,colours.cyan)
  96.     paintutils.drawFilledBox(1,4,resolution[1],resolution[2],colours.white)
  97.     term.setCursorPos(2,2)
  98.     term.setBackgroundColour(colours.cyan)
  99.     term.setTextColour(colours.white)
  100.     textutils.slowPrint("KrapFile installer")
  101.     term.setTextColour(colours.cyan)
  102.     term.setBackgroundColour(colours.white)
  103.     term.setCursorPos(1,5)
  104.     term.write(" Loading...")
  105.     sleep(2)
  106.     local pbl = http.get("http://pastebin.com/raw/wscpHypE")
  107.     if not pbl then
  108.         printError(" Could not connect to pastebin!")
  109.         print(" Error during update!\n Computer will now reboot...")
  110.         textutils.slowPrint(string.rep("*",resolution[1]-2))
  111.         os.reboot()
  112.     end
  113.     latestver = string.gsub(pbl.readLine(),"version = ","")
  114.     latestver = string.gsub(latestver,"\"","")
  115.     pbl.close()
  116.     term.setCursorPos(1,5)
  117.     print(" Latest version: " .. latestver .. "\n Download? (Y/N)")
  118.     term.setCursorPos(2,10)
  119.     local _,id = os.pullEvent("key")
  120.     if id == 21 then
  121.         print("\n Downloading...")
  122.         term.setCursorPos(1,12)
  123.         term.write(" Connecting to pastebin...")
  124.         local pbl = http.get("http://pastebin.com/raw/wscpHypE")
  125.         if pbl then
  126.             print(" Success")
  127.         else
  128.             printError(" Failed")
  129.             print(" Error during update!\n Computer will reboot...")
  130.             textutils.slowPrint(string.rep("*",resolution[1]-2))
  131.             os.reboot()
  132.         end
  133.         print(" Saving to file...")
  134.         if fs.exists("KrapFile") then fs.delete("/KrapFile") end
  135.         krapfile = fs.open("/KrapFile","w")
  136.         krapfile.write(pbl.readAll())
  137.         print(" Finished! Downloaded " .. latestver .. "\n\n Computer will reboot...")
  138.         term.setCursorPos(2,resolution[2])
  139.         textutils.slowPrint(string.rep("*",resolution[1]-2))
  140.         os.reboot()
  141.     else
  142.         print("Returing to Shell...")
  143.         term.setCursorPos(2,resolution[2])
  144.         textutils.slowPrint(string.rep("*",resolution[1]-2))
  145.         term.clear()
  146.         term.setTextColour(colours.white)
  147.         term.setBackgroundColour(colours.black)
  148.         term.setCursorPos(1,1)
  149.         shell.run("shell")
  150.     end
  151. end
  152.  
  153. if resolution[1] < 26 or resolution[2] < 5 then
  154.     printError("Sorry! Your computer must be atleast 26x5 to run this! (" .. resolution[1] .. "x" .. resolution[2] .. ")")
  155.     return
  156. elseif not colors then
  157.     printError("Sorry! Your computer doesn't seem to support colour. Monochrome support for KrapFile will be released shortly")
  158.     return
  159. end
  160.  
  161. paintutils.drawFilledBox(1,1,resolution[1],resolution[2],colours.cyan)
  162. term.setCursorPos((resolution[1]-string.len("KrapFile"))/2,(resolution[2]/5)*2)
  163. term.write("KrapFile")
  164. term.setCursorPos(1,resolution[2])
  165. term.write(version)
  166. term.setCursorPos(resolution[1]-string.len("By TehRockettek")+1,resolution[2])
  167.  
  168. term.write("By TehRockettek")
  169. local comments = {"To continue, enter your SS Number:","Piorjade liking pie is a conspiracy","Enter your credit card details","Free one-time payment of £499","Now with more loading time!","May include nuts","Attempt to index nil","Now in 1080p!","I got molested by a toaster","I am bender, insert girder","May include bugs","This litteraly took 12 hours to make","Im not joking","You pirated free software!","Child Lock is enabled","Have you tried a gun? I have","Screw switchcraft,i want my plot back","Sample comment","Wow, thats so racist","file.flushDownToilet()","I cunt speel properply","What's the wecommended amount of dedotated wam","Subscribe to my YT: Teh Rockettek","Try doing 5x26, It works!","If stuff is showing as ?, run with -o","I have a fetish for keemstar's beard","I play pokemon go","Redirection is a good game","Dan200, more like err... dan smelly hundred","*Air horns*","~You hear the windows xp startup noise~"}
  170. local fits = {}
  171. for i=1,#comments,1 do
  172.     if #comments[i] <= resolution[1] then
  173.         table.insert(fits,comments[i])
  174.     end
  175. end
  176. if resolution[2] < 10 then
  177.     fits = {"This is small!"}
  178. end
  179. local num = math.random(1,#fits)
  180. term.setCursorPos((resolution[1]-string.len(fits[num]))/2,(resolution[2]/5)*4)
  181. term.write(fits[num])
  182.  
  183. sleep(2)
  184. term.clear()
  185.  
  186. local windows = {}
  187. windows.HUD = window.create(terminal,1,1,resolution[1],3)
  188. windows.FILES = window.create(terminal,1,4,resolution[1]-1,resolution[2]-4)
  189. windows.SCROLLBAR = window.create(terminal,resolution[1],4,resolution[1],resolution[2]-4)
  190. windows.BOTTOM = window.create(terminal,1,resolution[2],resolution[1],1)
  191. windows.EXTRA = window.create(terminal,1,1,1,1,false)
  192.  
  193. path = "/"
  194. offset = 0
  195.  
  196. local function cut(text,length)
  197.     if string.len(text) > length then
  198.         return string.sub(text,1,length)
  199.     else
  200.         return text
  201.     end
  202. end
  203.  
  204. local function getSize(path)
  205.     local size = fs.getSize(path)
  206.     if fs.isDir(path) then
  207.         local l = fs.list(path)
  208.         for i = 1, #l do
  209.             size = size + getSize(fs.combine(path, l[i]))
  210.         end
  211.     end
  212.     return size
  213. end
  214.  
  215. local function getName(path)
  216.     num = -1
  217.     while not string.find(path,"/",num) do
  218.         num = num - 1
  219.     end
  220.     return string.sub(path,string.find(path,"/",num)+1,#path)
  221. end
  222.  
  223. local function loadHUD()
  224.     term.redirect(windows.HUD)
  225.     paintutils.drawFilledBox(1,1,resolution[1],3,colours.cyan)
  226.     term.setBackgroundColour(colours.cyan)
  227.     if path == "" or not path then path = "/" end
  228.     term.setTextColour(colours.white)
  229.     term.setCursorPos(2,2)
  230.     term.write(back)
  231.     if offset < 0 then offset = 0 end
  232.     term.setTextColour(colours.white)
  233.     term.setCursorPos(5,2)
  234.     term.write(up)
  235.     term.setCursorPos(8,2)
  236.     term.setTextColour(colours.white)
  237.     term.write(cut(path,resolution[1]-8))
  238.     term.redirect(terminal)
  239. end
  240.  
  241. local function loadDETAILS(path)
  242.     fileList = fs.list(path)
  243.     folderSize = 0
  244.     filesinfolder = 0
  245.     foldersinfolder = 0
  246.     for i=1,#fileList,1 do
  247.         local filePath = "/" .. fs.combine(path,fileList[i])
  248.         if fs.isDir(filePath) then foldersinfolder = foldersinfolder + 1 else filesinfolder = filesinfolder + 1 end
  249.         folderSize = folderSize + getSize(filePath)
  250.     end
  251. end
  252.  
  253.  
  254. local function loadFILES()
  255.     loadDETAILS(path)
  256.     term.redirect(windows.FILES)
  257.     paintutils.drawFilledBox(1,1,resolution[1]-1,resolution[2]-4,colours.white)
  258.     fileList = fs.list(path)
  259.     containerWidth,containerHeight = term.getSize()    
  260.     if #fileList-offset == containerHeight then
  261.         for i=1,containerHeight,1 do
  262.             filePath = "/" .. fs.combine(path,fileList[i+offset])
  263.             if fs.isDir(filePath) then
  264.                 fileSize = "("..minBytes(getSize(filePath))..")"
  265.             else
  266.                 fileSize = minBytes(fs.getSize(filePath))
  267.             end
  268.             if filePath == pgrm then
  269.                 paintutils.drawFilledBox(1,i,1,i,colours.green)
  270.             elseif fs.isDir(filePath) then
  271.                 paintutils.drawFilledBox(1,i,1,i,colours.yellow)
  272.             elseif fs.isReadOnly(filePath) then
  273.                 paintutils.drawFilledBox(1,i,1,i,colours.red)
  274.             else
  275.                 paintutils.drawFilledBox(1,i,1,i,colours.blue)
  276.             end
  277.             term.setCursorPos(3,i)
  278.             term.setBackgroundColour(colours.white)
  279.             if string.sub(fileList[i],1,1) == "." then
  280.                 term.setTextColour(colours.grey)
  281.             elseif ("/" .. fileList[i+offset] == pgrm) and (tonumber(version) < tonumber(latestver)) then
  282.                 term.setTextColour(colours.green)
  283.             else
  284.                 term.setTextColour(colours.black)
  285.             end
  286.             term.write(cut(fileList[i+offset],containerWidth-10) .. string.rep(" ",containerWidth - (string.len(cut(fileList[i+offset],containerWidth-10))+2+string.len(fileSize))) .. fileSize)
  287.         end
  288.     elseif #fileList < containerHeight then
  289.         for i=1,#fileList,1 do
  290.             filePath = "/" .. fs.combine(path,fileList[i])
  291.             if fs.isDir(filePath) then
  292.                 fileSize = "("..minBytes(getSize(filePath))..")"
  293.             else
  294.                 fileSize = minBytes(fs.getSize(filePath))
  295.             end
  296.             if filePath == pgrm then
  297.                 paintutils.drawFilledBox(1,i,1,i,colours.green)
  298.             elseif fs.isDir(filePath) then
  299.                 paintutils.drawFilledBox(1,i,1,i,colours.yellow)
  300.             elseif fs.isReadOnly(filePath) then
  301.                 paintutils.drawFilledBox(1,i,1,i,colours.red)
  302.             else
  303.                 paintutils.drawFilledBox(1,i,1,i,colours.blue)
  304.             end
  305.             term.setCursorPos(3,i)
  306.             term.setBackgroundColour(colours.white)
  307.             if string.sub(fileList[i],1,1) == "." then
  308.                 term.setTextColour(colours.grey)
  309.             elseif ("/" .. fileList[i] == pgrm) and (tonumber(version) < tonumber(latestver)) then
  310.                 term.setTextColour(colours.green)
  311.             else
  312.                 term.setTextColour(colours.black)
  313.             end
  314.             term.write(cut(fileList[i],containerWidth-10) .. string.rep(" ",containerWidth - (string.len(cut(fileList[i],containerWidth-10))+2+string.len(fileSize))) .. fileSize)
  315.         end
  316.     else
  317.         for i=1,containerHeight,1 do
  318.             filePath = "/" .. fs.combine(path,fileList[i+offset])
  319.             if fs.isDir(filePath) then
  320.                 fileSize = "("..minBytes(getSize(filePath))..")"
  321.             else
  322.                 fileSize = minBytes(fs.getSize(filePath))
  323.             end
  324.             if filePath == pgrm then
  325.                 paintutils.drawFilledBox(1,i,1,i,colours.green)
  326.             elseif fs.isDir(filePath) then
  327.                 paintutils.drawFilledBox(1,i,1,i,colours.yellow)
  328.             elseif fs.isReadOnly(filePath) then
  329.                 paintutils.drawFilledBox(1,i,1,i,colours.red)
  330.             else
  331.                 paintutils.drawFilledBox(1,i,1,i,colours.blue)
  332.             end
  333.             term.setCursorPos(3,i)
  334.             term.setBackgroundColour(colours.white)
  335.             if string.sub(fileList[i],1,1) == "." then
  336.                 term.setTextColour(colours.grey)
  337.             elseif ("/" .. fileList[i+offset] == pgrm) and (tonumber(version) < tonumber(latestver)) then
  338.                 term.setTextColour(colours.green)
  339.             else
  340.                 term.setTextColour(colours.black)
  341.             end
  342.             term.write(cut(fileList[i+offset],containerWidth-10) .. string.rep(" ",containerWidth - (string.len(cut(fileList[i+offset],containerWidth-10))+2+string.len(fileSize))) .. fileSize)
  343.         end
  344.     end
  345.     term.redirect(terminal)
  346. end
  347.  
  348. local function loadBAR()
  349.     term.redirect(windows.SCROLLBAR)
  350.     local _,containerHeightb = term.getSize()
  351.     if #fileList <= containerHeight then
  352.         paintutils.drawFilledBox(1,1,1,containerHeightb,colours.grey)
  353.     else
  354.         paintutils.drawFilledBox(1,1,1,containerHeightb,colours.lightGrey)
  355.     end
  356.     barryscott = (containerHeightb/100) * ((offset/(#fileList - containerHeight))*100)
  357.     if barryscott < 1 then
  358.         barryscott = 1
  359.     end
  360.     if offset == 0 then
  361.         barryscott = 1
  362.     end
  363.     paintutils.drawFilledBox(1,barryscott,1,barryscott,colours.grey)
  364.     term.redirect(terminal)
  365. end
  366.  
  367. local function loadBOTTOM()
  368.     if not dialoguevisible then
  369.         term.redirect(windows.BOTTOM)
  370.         term.setBackgroundColour(colours.lightGrey)
  371.         term.setTextColour(colours.grey)
  372.         term.clearLine()
  373.         term.setCursorPos(1,1)
  374.         local info = filesinfolder .. " files " .. foldersinfolder .. " folders"
  375.         local posstats = offset .. "/" .. #fileList
  376.         bottombar = info .. string.rep(" ",resolution[1]-string.len(info)-string.len(posstats)) .. posstats
  377.         term.write(bottombar)
  378.         term.redirect(terminal)
  379.     end
  380. end
  381.  
  382. local function loadALL()
  383.     dialoguevisible = false
  384.     loadHUD()
  385.     loadFILES()
  386.     loadBAR()
  387.     loadBOTTOM()
  388. end
  389.  
  390. local function loadDIALOGUE(text)
  391.     term.redirect(windows.BOTTOM)
  392.     term.setBackgroundColour(colours.lightGrey)
  393.     term.setTextColour(colours.grey)
  394.     term.clearLine()
  395.     term.setCursorPos(1,1)
  396.     term.write(text)
  397.     term.redirect(terminal)
  398. end
  399. -- INIT
  400.  
  401. loadALL()
  402.  
  403. -- Hint: Pretty much screwing arround with anything below will pretty much completely break the gui part of it ;)
  404. --       But to be honest, you shouldnt be screwing arround with the entire program at all...
  405.  
  406. -- key,id,false
  407. -- key_up,id
  408. -- mouse_click,left(1)/right(2),X,Y
  409. -- mouse_scroll,down(-1)/up(1),X,Y
  410.  
  411. os.pullEvent = os.pullEventRaw -- Just so i can say thanks for using it ;)
  412. while true do
  413.     if not fs.exists(path) then
  414.         path = "/"
  415.     end
  416.     local a,b,c,d = os.pullEvent()
  417.     if a == "mouse_up" then
  418.         if b == 1 then -- left
  419.             if c < 4 and d < 4 then
  420.                 if path ~= "/" then
  421.                     path = "/" .. fs.combine(path,"..")
  422.                     offset = 0
  423.                     loadALL()
  424.                 end
  425.             elseif c > 3 and c < 7 and d < 4 then
  426.                 if offset > 0 then
  427.                     offset = 0
  428.                     dialoguevisible = false
  429.                     windows.FILES.redraw()
  430.                     loadBAR()
  431.                     loadFILES()
  432.                     loadBOTTOM()
  433.                 end
  434.             elseif dialoguevisible and d == resolution[2] then
  435.                 if c >= 1 and c <= 7 then
  436.                     finished = false
  437.                     while finished == false do
  438.                         if selectedfileDir == pgrm then
  439.                             term.clear()
  440.                             paintutils.drawFilledBox(1,1,resolution[1],3,colours.cyan)
  441.                             paintutils.drawFilledBox(1,4,resolution[1],resolution[2],colours.white)
  442.                             term.redirect(terminal)
  443.                             term.setCursorPos(2,2)
  444.                             term.setBackgroundColour(colours.cyan)
  445.                             term.setTextColour(colours.white)
  446.                             textutils.slowPrint("KrapFile updater")
  447.                             term.setTextColour(colours.cyan)
  448.                             term.setBackgroundColour(colours.white)
  449.                             term.setCursorPos(1,5)
  450.                             term.write(" Loading...")
  451.                             sleep(2)
  452.                             local pbl = http.get("http://pastebin.com/raw/wscpHypE")
  453.                             if not pbl then
  454.                                 printError(" Could not connect to pastebin!")
  455.                                 print(" Error during update!\n Computer will now reboot...")
  456.                                 textutils.slowPrint(string.rep("*",resolution[1]-2))
  457.                                 os.reboot()
  458.                             end
  459.                             latestver = string.gsub(pbl.readLine(),"version = ","")
  460.                             latestver = string.gsub(latestver,"\"","")
  461.                             pbl.close()
  462.                             term.setCursorPos(1,5)
  463.                             print(" My version: " .. version)
  464.                             print(" New version: " .. latestver .. "\n Update? (Y/N)")
  465.                             term.setCursorPos(2,10)
  466.                             _,id = os.pullEvent("key")
  467.                             if id == 21 then
  468.                                 if version == latestver then
  469.                                     print("\n Redownloading...")
  470.                                 else
  471.                                     print("\n Downloading...")
  472.                                 end
  473.                                 sleep(3)
  474.                                 term.setCursorPos(1,12)
  475.                                 term.write(" Connecting to pastebin...")
  476.                                 local pbl = http.get("http://pastebin.com/raw/wscpHypE")
  477.                                 if pbl then
  478.                                     print(" Success")
  479.                                 else
  480.                                     printError(" Failed")
  481.                                     print(" Error during update!\n Computer will reboot...")
  482.                                     textutils.slowPrint(string.rep("*",resolution[1]-2))
  483.                                     os.reboot()
  484.                                 end
  485.                                 print(" Saving to file...")
  486.                                 krapfile = fs.open(pgrm,"w")
  487.                                 krapfile.write(pbl.readAll())
  488.                                 print(" Finished!\n " .. version .. " => " .. latestver .. "\n\n Computer will reboot...")
  489.                                 term.setCursorPos(2,resolution[2])
  490.                                 textutils.slowPrint(string.rep("*",resolution[1]-2))
  491.                                 os.reboot()
  492.                             else
  493.                                 print("Returing to KrapFile...")
  494.                                 term.setCursorPos(2,resolution[2])
  495.                                 textutils.slowPrint(string.rep("*",resolution[1]-2))
  496.                             end
  497.                             finished = true
  498.                             editname = ""
  499.                         else
  500.                             loadDIALOGUE("Rename to: ")
  501.                             term.redirect(windows.BOTTOM)
  502.                             term.setCursorPos(12,1)
  503.                             editname = io.read()
  504.                             if fs.isReadOnly(selectedfileDir) then
  505.                                 loadDIALOGUE("File is read-only!")
  506.                                 editname = ""
  507.                                 sleep(2)
  508.                                 finished = true
  509.                             elseif not fs.exists(fs.combine(selectedfileDir,"..").."/"..editname) or editname == "" then
  510.                                 finished = true
  511.                             else
  512.                                 loadDIALOGUE("File already exists!")
  513.                                 sleep(2)
  514.                             end
  515.                         end
  516.                     end
  517.                     if editname ~= "" then
  518.                         loadDIALOGUE("Working...")
  519.                         if fs.move(selectedfileDir,fs.combine(selectedfileDir,"..").."/"..editname) then
  520.                             loadDIALOGUE("An error occured!")
  521.                             sleep(5)
  522.                         end
  523.                     end
  524.                     loadALL()
  525.                 elseif c >= 8 and c <= 14 then
  526.                     finished = false
  527.                     while finished == false do
  528.                         loadDIALOGUE("Copy to: ")
  529.                         term.redirect(windows.BOTTOM)
  530.                         term.setCursorPos(10,1)
  531.                         editname = io.read()
  532.                         if fs.isReadOnly(editname) then
  533.                             loadDIALOGUE("Directory is read-only!")
  534.                             sleep(2)
  535.                         elseif not fs.exists(editname) or editname == "" then
  536.                             finished = true
  537.                         else
  538.                             loadDIALOGUE("File already exists!")
  539.                             sleep(2)
  540.                         end
  541.                     end
  542.                     if editname ~= "" then
  543.                         loadDIALOGUE("Working...")
  544.                         fs.copy(selectedfileDir,editname)
  545.                         if not fs.exists(editname) then
  546.                             loadDIALOGUE("An error occured!")
  547.                             sleep(5)
  548.                         end
  549.                     end
  550.                     loadALL()
  551.                 elseif c >= 15 and c <= 17 then
  552.                     finished = false
  553.                     while finished == false do
  554.                         loadDIALOGUE("Move to: ")
  555.                         term.redirect(windows.BOTTOM)
  556.                         term.setCursorPos(12,1)
  557.                         editname = io.read()
  558.                         if fs.isReadOnly(selectedfileDir) then
  559.                             loadDIALOGUE("File is read-only!")
  560.                             editname = ""
  561.                             sleep(2)
  562.                             finished = true
  563.                         elseif fs.isReadOnly(editname) then
  564.                             loadDIALOGUE("Directory is read-only!")
  565.                             sleep(2)
  566.                         elseif not fs.exists(editname) or editname == "" then
  567.                             finished = true
  568.                         else
  569.                             loadDIALOGUE("File already exists!")
  570.                             sleep(2)
  571.                         end
  572.                     end
  573.                     if editname ~= "" then
  574.                         loadDIALOGUE("Working...")
  575.                         if fs.move(selectedfileDir,editname) then
  576.                             loadDIALOGUE("An error occured!")
  577.                             sleep(5)
  578.                         end
  579.                     end
  580.                     loadALL()
  581.                 elseif c >= 18 and c <= 26 then
  582.                     if selectedfileDir == pgrm then
  583.                         loadDIALOGUE("Nope...")
  584.                         sleep(2)
  585.                         finished = true
  586.                         key = 1
  587.                     end
  588.                     finished = false
  589.                     loadDIALOGUE("Are you sure? (Y/N)")
  590.                     if fs.isReadOnly(selectedfileDir) then
  591.                         finished = true
  592.                         loadDIALOGUE("File is read-only!")
  593.                         sleep(2)
  594.                     end
  595.                     while finished == false do
  596.                         _,id = os.pullEvent("key")
  597.                         if id then
  598.                             finished = true
  599.                         end
  600.                     end
  601.                     if id == 21 and not fs.isReadOnly(selectedfileDir) then
  602.                         loadDIALOGUE("Working...")
  603.                         fs.delete(selectedfileDir)
  604.                         if fs.exists(selectedfileDir) then
  605.                             loadDIALOGUE("An error occured!")
  606.                             sleep(5)
  607.                         end
  608.                     end
  609.                     dialoguevisible = false
  610.                     windows.FILES.redraw()
  611.                     loadBOTTOM()
  612.                     loadFILES()
  613.                 end
  614.             elseif c < resolution[1] - 1 and d > 3 and d < resolution[2] then
  615.                 if fileList[d - 3 + offset] then
  616.                     selectedfileDir = "/" .. fs.combine(path,fileList[d - 3 + offset])
  617.                     if fs.isDir(selectedfileDir) then
  618.                         path = selectedfileDir
  619.                         offset = 0
  620.                         loadALL()
  621.                     elseif selectedfileDir ~= selectedfileDir then
  622.                         dialoguevisible = false
  623.                         windows.FILES.redraw()
  624.                         loadBOTTOM()
  625.                     end
  626.                 elseif dialoguevisible then
  627.                     dialoguevisible = false
  628.                     windows.FILES.redraw()
  629.                     loadBOTTOM()
  630.                 end
  631.             end
  632.         elseif b == 2 then -- right
  633.             if c < resolution[1] - 1 and d > 3 and d < resolution[2] then
  634.                 if selectedfileDir then
  635.                     if selectedfileDir == "/" .. fs.combine(path,fileList[d - 3 + offset]) then
  636.                         term.setTextColour(colours.white)
  637.                         term.setBackgroundColour(colours.black)
  638.                         term.clear()
  639.                         term.setCursorPos(1,1)
  640.                         pcall(loadfile(selectedfileDir))
  641.                         loadALL()
  642.                     end
  643.                 end
  644.                 if fileList[d - 3 + offset] then
  645.                     windows.FILES.redraw()
  646.                     term.setBackgroundColour(colours.white)
  647.                     term.setCursorPos(3,d)
  648.                     term.setTextColour(colours.blue)
  649.                     term.write(fileList[d-3+offset])
  650.                     selectedfileDir = "/" .. fs.combine(path,fileList[d - 3 + offset])
  651.                     dialoguevisible = true
  652.                     local filepercentage = string.sub(tostring((getSize(selectedfileDir)/getSize("/"))*100),1,string.len(math.ceil((getSize(selectedfileDir)/getSize("/"))*100))+2)
  653.                     if selectedfileDir == pgrm then
  654.                         loadDIALOGUE("Update  Copy  Move  Delete".. string.rep(" ",resolution[1]-1-#filepercentage) .. filepercentage .. "%")
  655.                     else
  656.                         loadDIALOGUE("Rename  Copy  Move  Delete".. string.rep(" ",resolution[1]-1-#filepercentage) .. filepercentage .. "%")
  657.                     end
  658.                 end
  659.             end
  660.         end
  661.     elseif a == "mouse_scroll" then
  662.         if b == -1 then -- down
  663.             if offset + containerHeight < #fileList then
  664.                 offset = offset + 1
  665.                 loadBAR()
  666.                 loadFILES()
  667.                 loadBOTTOM()
  668.                 dialoguevisible = false
  669.             end
  670.         elseif b == 1 then -- up
  671.             if offset > 0 then
  672.                 offset = offset - 1
  673.                 loadBAR()
  674.                 loadFILES()
  675.                 loadBOTTOM()
  676.                 dialoguevisible = false
  677.             end
  678.         end
  679.     elseif a == "key" then
  680.         if b == 208 then -- down
  681.             if offset + containerHeight < #fileList then
  682.                 offset = offset + 1
  683.                 loadBAR()
  684.                 loadFILES()
  685.                 loadBOTTOM()
  686.                 dialoguevisible = false
  687.             end
  688.         elseif b == 200 then -- up
  689.             if offset > 0 then
  690.                 offset = offset - 1
  691.                 loadBAR()
  692.                 loadFILES()
  693.                 loadBOTTOM()
  694.                 dialoguevisible = false
  695.             end
  696.         end
  697.     elseif a == "terminate" then
  698.         term.setCursorPos(1,1)
  699.         term.setTextColour(colours.white)
  700.         term.setBackgroundColour(colours.black)
  701.         term.clear()
  702.         print("Thank you for using KrapFile!\n Please go onto the forums to post any bugs or issues that occured.\nAnd thank you for supporting us!")
  703.         return
  704.     end
  705.     loadBOTTOM()
  706. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement