Advertisement
Marlingaming

CC Tweaked CCSPS 20 - File Navigator

Feb 23rd, 2022 (edited)
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. local FilePath = "os"
  2. local PastPaths = {"os"}
  3. local S = 3
  4. local w, h = term.getSize()
  5. local Icons = {"ImageFile.nfp","ProgramFile.nfp","TextFile.nfp","Shortcut.nfp","LuaFile.nfp","Folder.nfp"}
  6. local Return = false
  7. local Scroll = false
  8. local tArg = {...}
  9. settings.load(".settings")
  10.  
  11. local function Clear()
  12. term.clear()
  13. term.setCursorPos(1,1)
  14. end
  15.  
  16. function ImageCUI(m) --declare function
  17. n=0
  18. local l = #m
  19. local Cords = {}
  20. local X = 2
  21. local Y = 5
  22. for i=1, #m, 1 do --traverse the table of options
  23. local W = fs.combine(FilePath,m[i])
  24. local Image
  25. if string.find(m[i],".nfp") then Image = Icons[1] end
  26. if string.find(m[i],".cpf") then Image = Icons[2] end
  27. if string.find(m[i],".txt") then Image = Icons[3] end
  28. if string.find(m[i],".lnk") then Image = Icons[4] end
  29. if string.find(m[i],".lua") then Image = Icons[5] end
  30. if Image == nil then Image = Icons[6] end
  31. Cords[i] = {X,Y,X + 6, Y + 2}
  32. Image = fs.combine("os/SystemFiles/FileNavigator.cpf/Images",Image)
  33. local Img = paintutils.loadImage(Image)
  34. paintutils.drawImage(Img,X,Y)
  35. term.setBackgroundColor(colors.lightBlue)
  36. term.setCursorPos(X - 1, Y + 3)
  37. term.write(string.sub(m[i],1,9))
  38. if X + 8 < w then
  39. X = X + 8
  40. else
  41. X = 2
  42. Y = Y + 5
  43. end
  44. end
  45. while true do
  46. term.setCursorPos(1,3)
  47. a, b, c, d = os.pullEvent() --wait for keypress
  48. for i = 1, #m do
  49. if a == "mouse_click" and c >= Cords[i][1] and c <= Cords[i][3] and d >= Cords[i][2] and d <= Cords[i][4] then n = i end
  50. end
  51. if n == 0 and Return == true and a == "mouse_click" and c == w and d == 3 then n = 50 end
  52. if Scroll == true and a == "key" and b == keys.w then term.scroll(-1) end
  53.  
  54. if Scroll == true and a == "key" and b == keys.s then term.scroll(1) end
  55.  
  56. if n > 0 then break end
  57. end
  58. return n, b --return the value
  59. end
  60.  
  61. function Check(Items)
  62.  
  63. if settings.get("AdminKey") == "Jta520" then
  64.  
  65. else
  66. for i = 1, #Items do
  67. local RPath = fs.combine(FilePath,Items[i])
  68. for I = 1, #BlockedPaths do
  69. if RPath == BlockedPaths[I] then Items[i] = "blocked" end
  70. end
  71. end
  72. end
  73. local List = Items
  74. Items = {}
  75. for i = 1, #List do
  76. if List[i] ~= "blocked" then Items[#Items + 1] = List[i] end
  77. end
  78. return(Items)
  79. end
  80.  
  81. function CreateFile()
  82. Clear()
  83. local FileType
  84. print("file type")
  85. local options = {"lua","txt"}
  86. local n = CUI(options)
  87. if options[n] == "lua" then
  88. FileType = ".lua"
  89. else
  90. FileType = ".txt"
  91. end
  92. print("enter name for file")
  93. local input
  94. while true do
  95. local event = {os.pullEvent("key")}
  96. if event[2] == keys.enter then break end
  97. input = read()
  98. end
  99. input = input..FileType
  100. local P = fs.combine(FilePath, input)
  101. local file = fs.open(P,"w")
  102. file.write("new file")
  103. file.close()
  104. if FileType == ".lua" then
  105. shell.run("edit",P)
  106. else
  107. shell.run("os/System/Programs/TextEditor","direct",P)
  108. end
  109. Display()
  110.  
  111. end
  112.  
  113. function CreateFolder()
  114. Clear()
  115. print("enter name for folder")
  116. local input
  117. while true do
  118. local event = {os.pullEvent("key")}
  119. if event[2] == keys.enter then break end
  120. input = read()
  121. end
  122. local P = fs.combine(FilePath, input)
  123. fs.makeDir(P)
  124.  
  125. Display()
  126.  
  127. end
  128.  
  129. function SearchBar()
  130. term.setCursorPos(1,1)
  131. term.clearLine()
  132. paintutils.drawBox(1,1,w,1,colors.lightGray)
  133. term.setBackgroundColor(colors.lightGray)
  134. term.setCursorPos(1,1)
  135. local completion = require "cc.completion"
  136. local input
  137. while true do
  138. local event = {os.pullEvent("key")}
  139. if event[2] == keys.enter then break end
  140. input = read(nil, nil, function(text) return completion.choice(text, AllPaths) end)
  141. end
  142. if input == nil then
  143.  
  144. else
  145. if fs.exists(input) then
  146. FilePath = input
  147. end
  148. end
  149. Display()
  150. end
  151.  
  152. function Prompt()
  153. Clear()
  154. print("options")
  155. local options = {"run","edit properties","edit file","delete","close"}
  156. local n = CUI(options)
  157. return(options[n])
  158. end
  159.  
  160. function ViewImage(file)
  161. Clear()
  162. local Image = paintutils.loadImage(file)
  163. paintutils.drawImage(Image,1,1)
  164. term.setCursorPos(1,h)
  165. term.write("press enter to exit")
  166. repeat
  167. local event, key = os.pullEvent("key")
  168. until key == keys.enter
  169. end
  170.  
  171. function OpenProgram(file)
  172. local List = fs.list(file)
  173. local Loc
  174. local File
  175. for i = 1, #List do
  176. if string.find(List[n],"AppData.txt") then Loc = fs.combine(file,List[n]) end
  177. end
  178. if Loc == nil then
  179.  
  180. else
  181. local F = fs.open(Loc,"r")
  182. local Content
  183. repeat
  184. Content = F.readLine()
  185. if string.find(Content,"StartFile = ") then File = string.sub(Content, 13, string.len(Content)) end
  186. until Content == nil
  187. if File ~= nil then shell.run(File) end
  188. end
  189. end
  190.  
  191. function ViewTxt(file)
  192.  
  193. end
  194.  
  195. function Display(I)
  196. term.setBackgroundColor(colors.lightBlue)
  197. Clear()
  198. local Paths = fs.list(FilePath)
  199. Scroll = false
  200. Return = false
  201. local List = {}
  202. if #Paths > 14 and I == nil then
  203. Scroll = true
  204. end
  205.  
  206. if FilePath ~= "os" then
  207. Return = true
  208. end
  209. paintutils.drawFilledBox(1,1,w,3,colors.lightGray)
  210. paintutils.drawFilledBox(1,1,3,3,colors.green)
  211. paintutils.drawFilledBox(4,1,7,3,colors.red)
  212. if Return == true then
  213. paintutils.drawBox(w,3,w,3,colors.red)
  214. end
  215. term.setBackgroundColor(colors.lightBlue)
  216. local options = Paths
  217. local n = ImageCUI(options)
  218. if string.find(options[n],".txt") then
  219. ViewTxt(fs.combine(FilePath,options[n]))
  220. elseif string.find(options[n],".lua") then
  221. shell.run(fs.combine(FilePath,options[n]))
  222. elseif string.find(options[n],".cpf") then
  223. OpenProgram(fs.combine(FilePath,options[n]))
  224. elseif string.find(options[n],".nfp") then
  225. ViewImage(fs.combine(FilePath,options[n]))
  226. else
  227. FilePath = fs.combine(FilePath,options[n])
  228. end
  229. Display()
  230. end
  231.  
  232. if tArg[1] == "Show" then
  233. FilePath = tArg[2]
  234. end
  235.  
  236. Display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement