Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"}
- local FilePath = "os/System/Client"
- local PastPaths = {"os","os/System","os/System/Client"}
- local BlockedPaths = {"os/System/Security","os/System/Files/.Banking","os/System/Client/Files/.UserFile","os/System/Scripts"}
- local AllowedCreate = {"os/System/Client/Files"}
- local S = 3
- local w, h = term.getSize()
- local DisplayMode = 1
- local tArg = {...}
- settings.load(".settings")
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function CUI(m) --declare function
- n=1
- local l = #m
- while true do
- term.setCursorPos(1,5)
- for i=1, #m, 1 do --traverse the table of options
- if i==n then term.clearLine() print(i, ">",m[i]) else term.clearLine() print(i, "-", m[i]) end --print them
- end
- a, b= os.pullEvent("key") --wait for keypress
- if b==keys.w and n>1 then n=n-1 end
- if b==keys.s and n<l then n=n+1 end
- if b==keys.enter then break end
- end
- return n --return the value
- end
- function TouchCUI(m) --declare function
- n=0
- local l = #m
- while true do
- term.setCursorPos(1,3)
- for i=1, #m, 1 do --traverse the table of options
- print(m[i])
- end
- a, b, c, d = os.pullEvent("mouse_click") --wait for keypress
- for i = 1, #m do
- if d == i + 2 then n = i end
- end
- if n == 0 and d == 1 then n = 50 end
- if n > 0 then break end
- end
- return n, b --return the value
- end
- function ImageCUI(m) --declare function
- n=0
- local l = #m
- local Cords = {}
- while true do
- term.setCursorPos(1,3)
- local X = 2
- local Y = 3
- for i=1, #m, 1 do --traverse the table of options
- local W = fs.combine(FilePath,m[i])
- local Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Text.nfp")
- if string.find(W,".lua") then
- Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Lua.nfp")
- elseif string.find(W,".lua") then
- Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Text.nfp")
- elseif string.find(W,".nfp") then
- Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Image.nfp")
- elseif string.find(W,".cpf") then
- Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Compressed.nfp")
- elseif m[i] == "return" then
- Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Return.nfp")
- elseif fs.isDir(W) then
- Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_Folder.nfp")
- elseif m[i] == "create_file" then
- Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_NewFile.nfp")
- elseif m[i] == "create_folder" then
- Image = paintutils.loadImage("os/System/Saved/Images/Default_FileImage_NewFolder.nfp")
- end
- if Image ~= nil then
- paintutils.drawImage(Image,X,Y)
- end
- term.setBackgroundColor(colors.lightBlue)
- term.setCursorPos(X,(Y + 3))
- local lines = require "cc.strings".wrap(m[i], 7)
- for I = 1, #lines do
- if I < 3 then
- term.setCursorPos(X - 1, (Y + 2) + I)
- term.write(lines[I])
- end
- end
- Cords[i] = {X,Y,X + 6, Y + 2}
- if X + 8 < w then
- X = X + 8
- else
- X = 2
- Y = Y + 5
- end
- end
- paintutils.drawBox(1,h,w,h,colors.red)
- term.setCursorPos((w / 2) - 2,h)
- term.write("exit")
- a, b, c, d = os.pullEvent("mouse_click") --wait for keypress
- for i = 1, #m do
- if c >= Cords[i][1] and c <= Cords[i][3] and d >= Cords[i][2] and d <= Cords[i][4] then n = i end
- end
- if n == 0 and d == 1 then n = 50 end
- if n == 0 and d == h then n = 51 end
- if n == 0 and d == 2 and c < 14 then n = 52 end
- if n == 0 and d == 2 and c > h - 12 then n = 53 end
- if n > 0 then break end
- end
- return n, b --return the value
- end
- function Check(Items)
- if settings.get("AdminKey") == "Jta520" then
- else
- for i = 1, #Items do
- local RPath = fs.combine(FilePath,Items[i])
- for I = 1, #BlockedPaths do
- if RPath == BlockedPaths[I] then Items[i] = "blocked" end
- end
- end
- end
- local List = Items
- Items = {}
- for i = 1, #List do
- if List[i] ~= "blocked" then Items[#Items + 1] = List[i] end
- end
- return(Items)
- end
- function CreateFile()
- Clear()
- local FileType
- print("file type")
- local options = {"lua","txt"}
- local n = CUI(options)
- if options[n] == "lua" then
- FileType = ".lua"
- else
- FileType = ".txt"
- end
- print("enter name for file")
- local input
- while true do
- local event = {os.pullEvent("key")}
- if event[2] == keys.enter then break end
- input = read()
- end
- input = input..FileType
- local P = fs.combine(FilePath, input)
- local file = fs.open(P,"w")
- file.write("new file")
- file.close()
- if FileType == ".lua" then
- shell.run("edit",P)
- else
- shell.run("os/System/Programs/TextEditor","direct",P)
- end
- if DisplayMode == 0 then
- DisplayPath()
- else
- DisplayTouchPath()
- end
- end
- function CreateFolder()
- Clear()
- print("enter name for folder")
- local input
- while true do
- local event = {os.pullEvent("key")}
- if event[2] == keys.enter then break end
- input = read()
- end
- local P = fs.combine(FilePath, input)
- fs.makeDir(P)
- if DisplayMode == 0 then
- DisplayPath()
- else
- DisplayTouchPath()
- end
- end
- function SearchBar()
- term.setCursorPos(1,1)
- term.clearLine()
- paintutils.drawBox(1,1,w,1,colors.lightGray)
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(1,1)
- local completion = require "cc.completion"
- local input
- while true do
- local event = {os.pullEvent("key")}
- if event[2] == keys.enter then break end
- input = read(nil, nil, function(text) return completion.choice(text, AllPaths) end)
- end
- if input == nil then
- else
- if fs.exists(input) then
- FilePath = input
- end
- end
- if DisplayMode == 0 then
- DisplayPath()
- else
- DisplayTouchPath()
- end
- end
- function Prompt()
- Clear()
- print("options")
- local options = {"run","edit properties","edit file","delete","close"}
- local n = CUI(options)
- return(options[n])
- end
- function DisplayPath()
- local Paths = fs.list(FilePath)
- if FilePath == AllowedCreate[1] then
- Paths[#Paths + 1] = "create_file"
- Paths[#Paths + 1] = "create_folder"
- end
- if FilePath ~= "os" then
- Paths[#Paths + 1] = "return"
- end
- Paths[#Paths + 1] = "exit"
- term.setBackgroundColor(colors.lightBlue)
- Clear()
- paintutils.drawBox(1,1,26,1,colors.lightGray)
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(1,1)
- print("[",FilePath,"]")
- term.setBackgroundColor(colors.green)
- term.write("create folder")
- term.setCursorPos((w - 11), 2)
- term.write("create file")
- term.setBackgroundColor(colors.lightBlue)
- local APaths = Check(Paths)
- local n, b = TouchCUI(APaths)
- if n == 50 then
- SearchBar()
- elseif APaths[n] == "return" then
- FilePath = PastPaths[#PastPaths -1]
- PastPaths[#PastPaths] = nil
- DisplayPath()
- elseif APaths[n] == "exit" then
- elseif APaths[n] == "create_file" then
- CreateFile()
- DisplayPath()
- elseif APaths[n] == "create_folder" then
- CreateFolder()
- DisplayPath()
- elseif APaths[n] == "Blocked" then
- DisplayPath()
- elseif fs.isDir(fs.combine(FilePath,APaths[n])) then
- FilePath = fs.combine(FilePath,APaths[n])
- PastPaths[#PastPaths + 1] = FilePath
- DisplayPath()
- else
- FilePath = fs.combine(FilePath, APaths[n])
- if b == 1 then
- if fs.exists(FilePath..".lua") then
- shell.run(FilePath)
- else
- shell.run("os/System/Programs/TextEditor","direct",FilePath)
- end
- elseif b == 2 then--fixed up to this point
- local Re = Prompt()
- if Re == "run" then
- shell.run(FilePath)
- elseif Re == "edit" then
- if fs.exists(FilePath..".lua") then
- shell.run("edit",FilePath)
- else
- shell.run("os/System/Programs/TextEditor","direct",FilePath)
- end
- elseif Re == "delete" then
- fs.delete(FilePath)
- else
- DisplayPath()
- end
- end
- FilePath = PastPaths[#PastPaths]
- DisplayPath()
- end
- end
- function DisplayTouchPath(I)
- local Paths = fs.list(FilePath)
- local Scroll = false
- local List = {}
- if I ~= nil then
- for i = 1, #Paths - I do
- List[i] = Paths[i + I]
- end
- Paths = List
- end
- if #Paths > 14 and I == nil then
- Scroll = true
- end
- if Scroll == true then
- for i = 1, #Paths do
- if i < 15 then List[i] = Paths[i] end
- end
- Paths = List
- Paths[15] = "scroll"
- end
- if FilePath ~= "os" then
- if Scroll == true then
- Paths[16] = "return"
- else
- Paths[#Paths + 1] = "return"
- end
- end
- term.setBackgroundColor(colors.lightBlue)
- Clear()
- paintutils.drawBox(1,1,w,1,colors.lightGray)
- paintutils.drawBox(1,h, w, h, colors.red)
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(1,1)
- print("[",FilePath,"]")
- term.setBackgroundColor(colors.green)
- term.write("create folder")
- term.setCursorPos((w - 11), 2)
- term.write("create file")
- term.setBackgroundColor(colors.lightBlue)
- local APaths = Check(Paths)
- local n, b = ImageCUI(APaths)
- if n == 50 then--SearchBar
- SearchBar()
- elseif APaths[n] == "scroll" then
- DisplayTouchPath(14)
- elseif APaths[n] == "return" then
- FilePath = PastPaths[#PastPaths -1]
- PastPaths[#PastPaths] = nil
- DisplayTouchPath()
- elseif n == 51 then--exit
- elseif n == 53 then
- CreateFile()
- DisplayTouchPath()
- elseif n == 52 then
- CreateFolder()
- DisplayTouchPath()
- elseif APaths[n] == "Blocked" then
- DisplayTouchPath()
- elseif string.find(APaths[n],".cpf") then
- DisplayTouchPath()
- elseif fs.isDir(fs.combine(FilePath,APaths[n])) then
- FilePath = fs.combine(FilePath,APaths[n])
- PastPaths[#PastPaths + 1] = FilePath
- DisplayTouchPath()
- else
- FilePath = fs.combine(FilePath, APaths[n])
- if b == 1 then
- if string.find(FilePath,".lua") then
- shell.run(FilePath)
- elseif string.find(FilePath,".nfp") then
- local Image = paintutils.loadImage(FilePath)
- Clear()
- paintutils.drawImage(Image,3,3)
- term.setCursorPos(1,h)
- print("Press enter to exit")
- repeat
- local event, key = os.pullEvent("key")
- until key == keys.enter
- else
- shell.run("os/System/Programs/TextEditor.lua","direct",FilePath)
- end
- elseif b == 2 then--fixed up to this point
- local Re = Prompt()
- if Re == "run" then
- shell.run(FilePath)
- elseif Re == "edit file" then
- if string.find(FilePath,".lua") then
- shell.run("edit",FilePath)
- else
- shell.run("os/System/Programs/TextEditor.lua","direct",FilePath)
- end
- elseif Re == "edit properties" then
- shell.run("os/System/Programs/FilePropEdit.lua",FilePath)
- elseif Re == "delete" then
- fs.delete(FilePath)
- end
- end
- FilePath = PastPaths[#PastPaths]
- DisplayTouchPath()
- end
- end
- if tArg[1] == "Show" then
- FilePath = tArg[2]
- end
- if DisplayMode == 0 then
- DisplayPath()
- else
- DisplayTouchPath()
- end
Add Comment
Please, Sign In to add comment