Marlingaming

CC Tweaked CCSPS 2.0.0 - Touch Compatible File Navigator

Feb 7th, 2022 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.14 KB | None | 0 0
  1. local AllPaths = {"os","os/System","os/System/Programs","os/System/Saved","os/System/Saved/Images","os/System/Files","os/System/Client","os/System/Client/Files"}
  2. local FilePath = "os/System/Client"
  3. local PastPaths = {"os","os/System","os/System/Client"}
  4. local BlockedPaths = {"os/System/Security","os/System/Files/.Banking","os/System/Client/Files/.UserFile","os/System/Scripts"}
  5. local AllowedCreate = {"os/System/Client/Files"}
  6. local S = 3
  7. local w, h = term.getSize()
  8. local DisplayMode = 1
  9. local tArg = {...}
  10. settings.load(".settings")
  11.  
  12. local function Clear()
  13. term.clear()
  14. term.setCursorPos(1,1)
  15. end
  16.  
  17. function CUI(m) --declare function
  18. n=1
  19. local l = #m
  20. while true do
  21. term.setCursorPos(1,5)
  22. for i=1, #m, 1 do --traverse the table of options
  23. if i==n then term.clearLine() print(i, ">",m[i]) else term.clearLine() print(i, "-", m[i]) end --print them
  24. end
  25. a, b= os.pullEvent("key") --wait for keypress
  26. if b==keys.w and n>1 then n=n-1 end
  27. if b==keys.s and n<l then n=n+1 end
  28. if b==keys.enter then break end
  29. end
  30. return n --return the value
  31. end
  32.  
  33. function TouchCUI(m) --declare function
  34. n=0
  35. local l = #m
  36. while true do
  37. term.setCursorPos(1,3)
  38. for i=1, #m, 1 do --traverse the table of options
  39. print(m[i])
  40. end
  41. a, b, c, d = os.pullEvent("mouse_click") --wait for keypress
  42. for i = 1, #m do
  43. if d == i + 2 then n = i end
  44. end
  45. if n == 0 and d == 1 then n = 50 end
  46. if n > 0 then break end
  47. end
  48. return n, b --return the value
  49. end
  50.  
  51. function ImageCUI(m) --declare function
  52. n=0
  53. local l = #m
  54. local Cords = {}
  55. while true do
  56. term.setCursorPos(1,3)
  57. local X = 2
  58. local Y = 3
  59. for i=1, #m, 1 do --traverse the table of options
  60. local W = fs.combine(FilePath,m[i])
  61. local Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Text.nfp")
  62. if string.find(W,".lua") then
  63. Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Lua.nfp")
  64. elseif string.find(W,".lua") then
  65. Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Text.nfp")
  66. elseif string.find(W,".nfp") then
  67. Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Image.nfp")
  68. elseif string.find(W,".cpf") then
  69. Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Compressed.nfp")
  70. elseif m[i] == "return" then
  71. Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Return.nfp")
  72. elseif fs.isDir(W) then
  73. Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Folder.nfp")
  74. elseif m[i] == "create_file" then
  75. Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_NewFile.nfp")
  76. elseif m[i] == "create_folder" then
  77. Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_NewFolder.nfp")
  78. end
  79. if Image ~= nil then
  80. paintutils.drawImage(Image,X,Y)
  81. end
  82. term.setBackgroundColor(colors.lightBlue)
  83. term.setCursorPos(X,(Y + 3))
  84. local lines = require "cc.strings".wrap(m[i], 7)
  85. for I = 1, #lines do
  86. if I < 3 then
  87. term.setCursorPos(X - 1, (Y + 2) + I)
  88. term.write(lines[I])
  89. end
  90. end
  91.  
  92. Cords[i] = {X,Y,X + 6, Y + 2}
  93. if X + 8 < w then
  94. X = X + 8
  95. else
  96. X = 2
  97. Y = Y + 5
  98. end
  99. end
  100. paintutils.drawBox(1,h,w,h,colors.red)
  101. term.setCursorPos((w / 2) - 2,h)
  102. term.write("exit")
  103. a, b, c, d = os.pullEvent("mouse_click") --wait for keypress
  104. for i = 1, #m do
  105. if c >= Cords[i][1] and c <= Cords[i][3] and d >= Cords[i][2] and d <= Cords[i][4] then n = i end
  106. end
  107. if n == 0 and d == 1 then n = 50 end
  108. if n == 0 and d == h then n = 51 end
  109. if n == 0 and d == 2 and c < 14 then n = 52 end
  110. if n == 0 and d == 2 and c > h - 12 then n = 53 end
  111. if n > 0 then break end
  112. end
  113. return n, b --return the value
  114. end
  115.  
  116. function Check(Items)
  117.  
  118. if settings.get("AdminKey") == "Jta520" then
  119.  
  120. else
  121. for i = 1, #Items do
  122. local RPath = fs.combine(FilePath,Items[i])
  123. for I = 1, #BlockedPaths do
  124. if RPath == BlockedPaths[I] then Items[i] = "blocked" end
  125. end
  126. end
  127. end
  128. local List = Items
  129. Items = {}
  130. for i = 1, #List do
  131. if List[i] ~= "blocked" then Items[#Items + 1] = List[i] end
  132. end
  133. return(Items)
  134. end
  135.  
  136. function CreateFile()
  137. Clear()
  138. local FileType
  139. print("file type")
  140. local options = {"lua","txt"}
  141. local n = CUI(options)
  142. if options[n] == "lua" then
  143. FileType = ".lua"
  144. else
  145. FileType = ".txt"
  146. end
  147. print("enter name for file")
  148. local input
  149. while true do
  150. local event = {os.pullEvent("key")}
  151. if event[2] == keys.enter then break end
  152. input = read()
  153. end
  154. input = input..FileType
  155. local P = fs.combine(FilePath, input)
  156. local file = fs.open(P,"w")
  157. file.write("new file")
  158. file.close()
  159. if FileType == ".lua" then
  160. shell.run("edit",P)
  161. else
  162. shell.run("os/System/Programs/TextEditor","direct",P)
  163. end
  164.  
  165. if DisplayMode == 0 then
  166. DisplayPath()
  167. else
  168. DisplayTouchPath()
  169. end
  170.  
  171. end
  172.  
  173. function CreateFolder()
  174. Clear()
  175. print("enter name for folder")
  176. local input
  177. while true do
  178. local event = {os.pullEvent("key")}
  179. if event[2] == keys.enter then break end
  180. input = read()
  181. end
  182. local P = fs.combine(FilePath, input)
  183. fs.makeDir(P)
  184.  
  185. if DisplayMode == 0 then
  186. DisplayPath()
  187. else
  188. DisplayTouchPath()
  189. end
  190.  
  191. end
  192.  
  193. function SearchBar()
  194. term.setCursorPos(1,1)
  195. term.clearLine()
  196. paintutils.drawBox(1,1,w,1,colors.lightGray)
  197. term.setBackgroundColor(colors.lightGray)
  198. term.setCursorPos(1,1)
  199. local completion = require "cc.completion"
  200. local input
  201. while true do
  202. local event = {os.pullEvent("key")}
  203. if event[2] == keys.enter then break end
  204. input = read(nil, nil, function(text) return completion.choice(text, AllPaths) end)
  205. end
  206. if input == nil then
  207.  
  208. else
  209. if fs.exists(input) then
  210. FilePath = input
  211. end
  212. end
  213. if DisplayMode == 0 then
  214. DisplayPath()
  215. else
  216. DisplayTouchPath()
  217. end
  218. end
  219.  
  220. function Prompt()
  221. Clear()
  222. print("options")
  223. local options = {"run","edit properties","edit file","delete","close"}
  224. local n = CUI(options)
  225. return(options[n])
  226. end
  227.  
  228. function DisplayPath()
  229.  
  230. local Paths = fs.list(FilePath)
  231.  
  232. if FilePath == AllowedCreate[1] then
  233. Paths[#Paths + 1] = "create_file"
  234. Paths[#Paths + 1] = "create_folder"
  235. end
  236. if FilePath ~= "os" then
  237. Paths[#Paths + 1] = "return"
  238. end
  239. Paths[#Paths + 1] = "exit"
  240. term.setBackgroundColor(colors.lightBlue)
  241. Clear()
  242. paintutils.drawBox(1,1,26,1,colors.lightGray)
  243. term.setBackgroundColor(colors.lightGray)
  244. term.setCursorPos(1,1)
  245. print("[",FilePath,"]")
  246. term.setBackgroundColor(colors.green)
  247. term.write("create folder")
  248. term.setCursorPos((w - 11), 2)
  249. term.write("create file")
  250. term.setBackgroundColor(colors.lightBlue)
  251. local APaths = Check(Paths)
  252. local n, b = TouchCUI(APaths)
  253. if n == 50 then
  254. SearchBar()
  255. elseif APaths[n] == "return" then
  256. FilePath = PastPaths[#PastPaths -1]
  257. PastPaths[#PastPaths] = nil
  258. DisplayPath()
  259. elseif APaths[n] == "exit" then
  260.  
  261. elseif APaths[n] == "create_file" then
  262. CreateFile()
  263. DisplayPath()
  264. elseif APaths[n] == "create_folder" then
  265. CreateFolder()
  266. DisplayPath()
  267. elseif APaths[n] == "Blocked" then
  268. DisplayPath()
  269. elseif fs.isDir(fs.combine(FilePath,APaths[n])) then
  270. FilePath = fs.combine(FilePath,APaths[n])
  271. PastPaths[#PastPaths + 1] = FilePath
  272. DisplayPath()
  273. else
  274. FilePath = fs.combine(FilePath, APaths[n])
  275. if b == 1 then
  276. if fs.exists(FilePath..".lua") then
  277. shell.run(FilePath)
  278. else
  279. shell.run("os/System/Programs/TextEditor","direct",FilePath)
  280. end
  281. elseif b == 2 then--fixed up to this point
  282. local Re = Prompt()
  283. if Re == "run" then
  284. shell.run(FilePath)
  285. elseif Re == "edit" then
  286. if fs.exists(FilePath..".lua") then
  287. shell.run("edit",FilePath)
  288. else
  289. shell.run("os/System/Programs/TextEditor","direct",FilePath)
  290. end
  291. elseif Re == "delete" then
  292. fs.delete(FilePath)
  293. else
  294. DisplayPath()
  295. end
  296. end
  297. FilePath = PastPaths[#PastPaths]
  298. DisplayPath()
  299. end
  300. end
  301.  
  302. function DisplayTouchPath(I)
  303. local Paths = fs.list(FilePath)
  304. local Scroll = false
  305. local List = {}
  306. if I ~= nil then
  307. for i = 1, #Paths - I do
  308. List[i] = Paths[i + I]
  309. end
  310. Paths = List
  311. end
  312. if #Paths > 14 and I == nil then
  313. Scroll = true
  314. end
  315.  
  316. if Scroll == true then
  317. for i = 1, #Paths do
  318. if i < 15 then List[i] = Paths[i] end
  319. end
  320. Paths = List
  321. Paths[15] = "scroll"
  322. end
  323.  
  324. if FilePath ~= "os" then
  325. if Scroll == true then
  326. Paths[16] = "return"
  327. else
  328. Paths[#Paths + 1] = "return"
  329. end
  330. end
  331. term.setBackgroundColor(colors.lightBlue)
  332. Clear()
  333. paintutils.drawBox(1,1,w,1,colors.lightGray)
  334. paintutils.drawBox(1,h, w, h, colors.red)
  335. term.setBackgroundColor(colors.lightGray)
  336. term.setCursorPos(1,1)
  337. print("[",FilePath,"]")
  338.  
  339. term.setBackgroundColor(colors.green)
  340. term.write("create folder")
  341. term.setCursorPos((w - 11), 2)
  342. term.write("create file")
  343.  
  344. term.setBackgroundColor(colors.lightBlue)
  345. local APaths = Check(Paths)
  346. local n, b = ImageCUI(APaths)
  347. if n == 50 then--SearchBar
  348. SearchBar()
  349. elseif APaths[n] == "scroll" then
  350. DisplayTouchPath(14)
  351. elseif APaths[n] == "return" then
  352. FilePath = PastPaths[#PastPaths -1]
  353. PastPaths[#PastPaths] = nil
  354. DisplayTouchPath()
  355. elseif n == 51 then--exit
  356.  
  357. elseif n == 53 then
  358. CreateFile()
  359. DisplayTouchPath()
  360. elseif n == 52 then
  361. CreateFolder()
  362. DisplayTouchPath()
  363. elseif APaths[n] == "Blocked" then
  364. DisplayTouchPath()
  365. elseif string.find(APaths[n],".cpf") then
  366. DisplayTouchPath()
  367. elseif fs.isDir(fs.combine(FilePath,APaths[n])) then
  368. FilePath = fs.combine(FilePath,APaths[n])
  369. PastPaths[#PastPaths + 1] = FilePath
  370. DisplayTouchPath()
  371. else
  372. FilePath = fs.combine(FilePath, APaths[n])
  373. if b == 1 then
  374. if string.find(FilePath,".lua") then
  375. shell.run(FilePath)
  376. elseif string.find(FilePath,".nfp") then
  377. local Image = paintutils.loadImage(FilePath)
  378. Clear()
  379. paintutils.drawImage(Image,3,3)
  380. term.setCursorPos(1,h)
  381. print("Press enter to exit")
  382. repeat
  383. local event, key = os.pullEvent("key")
  384. until key == keys.enter
  385. else
  386. shell.run("os/System/Programs/TextEditor.lua","direct",FilePath)
  387. end
  388. elseif b == 2 then--fixed up to this point
  389. local Re = Prompt()
  390. if Re == "run" then
  391. shell.run(FilePath)
  392. elseif Re == "edit file" then
  393. if string.find(FilePath,".lua") then
  394. shell.run("edit",FilePath)
  395. else
  396. shell.run("os/System/Programs/TextEditor.lua","direct",FilePath)
  397. end
  398. elseif Re == "edit properties" then
  399. shell.run("os/System/Programs/FilePropEdit.lua",FilePath)
  400. elseif Re == "delete" then
  401. fs.delete(FilePath)
  402. end
  403. end
  404. FilePath = PastPaths[#PastPaths]
  405. DisplayTouchPath()
  406. end
  407. end
  408.  
  409. if tArg[1] == "Show" then
  410. FilePath = tArg[2]
  411. end
  412.  
  413. if DisplayMode == 0 then
  414. DisplayPath()
  415. else
  416. DisplayTouchPath()
  417. end
Add Comment
Please, Sign In to add comment