Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- COPY RIGHT @Redxone or Lewisk3
- -- MC Ign: trainerred2000
- local arg = { ... }
- local selFile = ""
- local fPath = "rom/"
- local fDefault = fPath
- local fPrePath = fPath
- local printoff = 0
- local mfoff = 0
- local fs_ver = "v1.0 Alpha"
- local copy_path = ""
- local copy_file = ""
- local fName = ""
- local theme = {
- foldercolor = colors.lime,
- filecolor = colors.orange,
- iconbgcolor = colors.gray,
- folderIcon = "[=]",
- fileIcon = "-~-",
- bgcolor = colors.white,
- tbcolor = colors.gray,
- tbtcolor = colors.yellow,
- textcolor = colors.black,
- dimtextcolor = colors.gray,
- selectedcolor = colors.blue,
- mbcolor = colors.black,
- mtcolor = colors.white,
- infocolor = colors.lightGray,
- }
- if(#arg > 0)then
- f = fs.open(arg[1],"r")
- filetheme = textutils.unserialize(f.readAll())
- f.close()
- theme = setmetatable(filetheme, {__index = theme})
- end
- inRun = true
- inContext=false
- local contextEmpty = {
- ["____________"] = {x=0,y=0,yoff = 1, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};
- [" New Folder "] = {x=0,y=0,yoff = 2, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(1,1) ea.sbc(theme.tbcolor) ea.stc(theme.mtcolor); term.clearLine() write("New Folder: ") nFn = read(); if(not fs.isDir(nFn) and nFn ~= "")then fs.makeDir(fPath.."/"..nFn) inContext = false; inRun = true; cEmpty = false; fileSystem() end end};
- [" New File "] = {x=0,y=0,yoff = 3, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(1,1) ea.sbc(theme.tbcolor) ea.stc(theme.mtcolor); term.clearLine() write("New File: ") nFn = read(); if(not fs.exists(fPath.."/"..nFn) and nFn ~= "")then f=fs.open(fPath.."/"..nFn,"w") f.writeLine(" ") f.close(); cEmpty = false; inContext = false; inRun = true; fileSystem() end end};
- [" Paste "] = {x=0,y=0,yoff = 4, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() if(fs.exists(fPath.."/"..copy_file))then cut =false inContext = false inRun = true selFile = fPath..copy_file; copy_path = "" copy_file = "" fileSystem() end if(copy_path ~= "" and not fs.exists(fPath.."/"..copy_file))then if(not cut)then fs.copy(copy_path,fPath.."/"..copy_file); else fs.move(copy_path,fPath.."/"..copy_file); cut =false end inContext = false inRun = true selFile = fPath..copy_file; copy_path = "" copy_file = "" fileSystem() end end};
- ["------------"] = {x=0,y=0,yoff = 5, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};
- }
- local folderMenu = {
- ["_____________"] = {yoff = 1, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};
- [" Open Folder "] = {yoff = 2, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() fPrePath = fPath; fPath = fPath..fName.."/"; selFile = ""; loadFS(fPath); inContext=false inRun = true fileSystem(); end};
- [" New Folder "] = {yoff = 3, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(1,1) ea.sbc(theme.tbcolor) ea.stc(theme.textcolor); term.clearLine() write("New Folder: ") nFn = read(); if(not fs.isDir(nFn) and nFn ~= "")then fs.makeDir(fPath.."/"..nFn) inContext = false; inRun = true; fileSystem() end end};
- [" Cut "] = {yoff= 4, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() cut = true; copy_path = selFile; copy_file = fName inContext = false inRun = true fileSystem() end};
- [" Copy "] = {yoff= 5, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() cut = false; copy_path = selFile; copy_file = fName inContext = false inRun = true fileSystem() end};
- ["Rename Folder"] = {yoff = 6, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.sbc(theme.bgcolor) ea.stc(theme.textcolor); ea.scp(4,renameY) write(string.rep(" ",15)) ea.scp(4,renameY); nFn = read(); if(not fs.isDir(fPath.."/"..nFn))then fs.move(selFile, fPath.."/"..nFn) inContext = false inRun = true fileSystem(); end end};
- ["Delete Folder"] = {yoff = 7, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() fs.delete(selFile); selFile = ""; inContext = false; inRun = true fileSystem(); end};
- ["-------------"] = {yoff = 8, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};
- }
- local contextMenu = {
- --["____________"] = {yoff = 1, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};
- --["Run File "] = {yoff = 2, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() os.run({},selFile) inContext = false; inRun = true; fileSystem() ;end};
- ["Edit File "] = {yoff = 1, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() shell.run("edit",selFile); inContext = false; inRun = true; fileSystem() end};
- ["New File "] = {yoff = 2, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function()
- ea.scp(1,1)
- ea.sbc(theme.tbcolor)
- ea.stc(theme.mtcolor);
- term.clearLine()
- write("New File: ")
- nFn = read();
- if(not fs.exists(nFn) and nFn ~= "")then
- f = fs.open(fPath.."/"..nFn,"w")
- f.writeLine(" ")
- f.close();
- inContext = false;
- inRun = true;
- fileSystem()
- end end};
- ["New Folder "] = {yoff = 3, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(1,1) ea.sbc(theme.tbcolor) ea.stc(theme.mtcolor); term.clearLine() write("New Folder: ") nFn = read(); if(not fs.isDir(nFn) and nFn ~= "")then fs.makeDir(fPath.."/"..nFn) inContext = false; inRun = true; fileSystem() end end};
- ["Cut "] = {yoff= 4, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() cut = true; copy_path = selFile; copy_file = fName inContext = false inRun = true fileSystem() end};
- ["Copy "] = {yoff= 5, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() cut = false; copy_path = selFile; copy_file = fName inContext = false inRun = true fileSystem() end};
- ["Rename File "] = {yoff = 6, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() ea.scp(4,renameY); ea.stc(theme.textcolor) ea.sbc(theme.bgcolor); print(" ") ea.scp(5,renameY) nFn = read() if(not fs.exists(fPath..nFn) and nFn ~= "")then fs.move(selFile,fPath..nFn); end inRun = true; inContext = false; fileSystem() end};
- ["Delete File "] = {yoff = 7, bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() if(fs.exists(selFile))then fs.delete(selFile); inContext = false; inRun = true; fileSystem(); end end};
- ["------------"] = {yoff = 8,bcol=theme.mbcolor,tcol=theme.mtcolor,fcmd = function() end};
- }
- local w,h = term.getSize()
- os.loadAPI("ea")
- os.loadAPI("cozy_string")
- function clear() ea.sbc(theme.bgcolor); term.clear() end
- clear()
- --]] FILE SYSTEM [[--
- local filetable = {}
- function loadFS(fsl)
- mfoff = 0
- if(filetable ~= {})then filetable = {}
- for k, v in pairs(fs.list(fsl)) do
- if(fs.isDir(fsl..v))then isdir=true; else isdir = false; end
- if(not filetable[v])then
- filetable[v] = v
- filetable[v] = {offset = k, dir = isdir};
- mfoff = mfoff + 1
- end
- end
- end
- end
- function drawMenu(x,y)
- for k, v in pairs(contextMenu)do
- ea.sbc(v.bcol)
- ea.stc(v.tcol)
- ea.scp(x+2,y+v.yoff)
- print(k)
- end
- end
- function drawEmptyContext(x,y)
- for k, v in pairs(contextEmpty)do
- v.x=x
- v.y=y+v.yoff
- ea.sbc(v.bcol)
- ea.stc(v.tcol)
- ea.scp(x+2,y+v.yoff)
- print(k)
- end
- end
- function drawFolderMenu(x,y)
- for k, v in pairs(folderMenu)do
- ea.sbc(v.bcol)
- ea.stc(v.tcol)
- ea.scp(x+2,y+v.yoff)
- print(k)
- end
- end
- function fileSystem()
- while inRun do
- clear()
- ea.scp(1,2)
- moff = 14
- loadFS(fPath)
- ea.sbc(theme.bgcolor)
- term.clear()
- ea.sbc(theme.tbcolor)
- ea.scp(1,1)
- term.clearLine()
- ea.stc(theme.tbtcolor)
- ea.scp(1,1)
- print("Cozy File Manager ")
- ea.scp(w-#fs_ver,1)
- print(fs_ver)
- ea.stc(theme.infocolor)
- ea.sbc(theme.bgcolor)
- print(fPath)
- print("[BACK] [EXIT]")
- for k, v in pairs(filetable) do
- if(v.offset-printoff < moff+1 and v.offset >= printoff)then
- if( ((v.offset)-printoff)+3 < 4)then addl = 4 else addl = ( (v.offset) - printoff )+3 end
- if(v.dir)then ea.stc(theme.foldercolor); ea.sbc(theme.iconbgcolor); ea.scp(1,addl); write(theme.folderIcon); if(cut and copy_path == fPath..k)then ea.stc(theme.dimtextcolor) else ea.stc(theme.textcolor); end ea.sbc(theme.bgcolor); if(fPath..k == selFile)then ea.sbc(theme.selectedcolor) else ea.sbc(theme.bgcolor) end; print(" "..k) end
- if(not v.dir)then ea.stc(theme.filecolor); ea.sbc(theme.iconbgcolor); ea.scp(1,addl); write(theme.fileIcon); ea.sbc(theme.bgcolor); if(cut and copy_path == fPath..k)then ea.stc(theme.dimtextcolor) else ea.stc(theme.textcolor); end if(fPath..k == selFile)then ea.sbc(theme.selectedcolor) else ea.sbc(theme.bgcolor) end; print(" "..k) end
- end
- if(mfoff-printoff > moff)then
- ea.stc(theme.infocolor)
- ea.scp(10,3)
- print("+")
- end
- if(printoff+1 > 1)then
- ea.stc(theme.infocolor)
- ea.scp(11,3)
- print("-")
- end
- end
- mi = {os.pullEvent()}
- if(mi[1] == "mouse_click" and mi[2] == 1)then
- fBi = 1
- clkF = 0
- for k, v in pairs(filetable) do
- if(mi[3] >= 1 and mi[3] <= 4+#k and mi[4] == (v.offset-printoff)+3)then
- clkF = 1
- if(v.dir and selFile == fPath..k)then fPrePath = fPath; fPath = fPath..k.."/"; loadFS(fPath); selFile = ""; printoff = 0 end
- if(selFile == fPath..k)then ea.stc(colors.white); ea.sbc(colors.black); ea.scp(1,1); os.run({},fPath..k); term.setCursorBlink(false) ea.sbc(colors.black) ea.stc(colors.white) term.clear() print("Press Any Key") os.pullEvent("key")
- else selFile = ""; selFile = fPath..k; fName = k end
- end
- end
- if(clkF == 0)then selFile = "" end
- if( mi[3] >= 1 and mi[3] <= 6 and mi[4] == 3)then
- fPrePath = cozy_string.split(fPrePath,"/",(cozy_string.pathLen(fPath)-fBi))
- fPath = fPrePath;
- printoff = 0
- selFile = ""
- loadFS(fPath)
- fBi = 0
- end
- if( mi[3] >= w-6 and mi[3] <= w and mi[4] == 3)then inRun=false; ea.sbc(colors.black) ea.stc(colors.white) ea.scp(1,1) end
- else
- fBi = 1
- if(mi[1] == "key" or mi[1] == "mouse_scroll")then
- ea.scp(1,1)
- pfc = mfoff
- if(mi[2] == keys.up or mi[2] == -1)then if(printoff > 0)then printoff = printoff - 1 end end
- if(mi[2] == keys.down or mi[2] == 1)then if(printoff < mfoff-moff)then printoff = printoff + 1 end end
- end
- end
- if(mi[1] == "mouse_click" and mi[2] == 2)then
- i = 0
- for k, v in pairs(filetable) do
- i = i + 1
- if(mi[3] >= 1 and mi[3] <= #k+5 and mi[4] == (v.offset-printoff)+3 and not inContext)then
- if(selFile == fPath..k)then
- if(mi[4] >= h-9)then
- prntedY = ((v.offset-printoff)+3)-9
- else
- prntedY = (v.offset-printoff)+3
- end
- renameY = (v.offset-printoff)+3
- if(not fs.isDir(selFile))then drawMenu(1,prntedY) else if(mi[4] >= h-10)then end drawFolderMenu(1,prntedY) end
- contextY = prntedY
- cEmpty=false
- inContext = true
- inRun = false
- fileSystem()
- end
- end
- if(selFile == "" and not (mi[3] >= w-6 and mi[3] <= w and mi[4] == 3) )then
- if(mi[4] >= h-5)then pY = mi[4]-10 else pY = mi[4] end
- if(mi[3] >= w-12)then pX = w-22 else pX = mi[3] end
- drawEmptyContext(pX,pY)
- cEmpty = true
- inContext=true
- inRun=false
- end
- end
- if(i == 0 )then
- if(mi[4] >= h-5)then
- pY = mi[4]-10
- else
- pY = mi[4]
- end
- if(mi[3] >= w-12)then
- pX = w-22
- else
- pX = mi[3]
- end
- drawEmptyContext(pX,pY)
- cEmpty = true
- inContext=true
- inRun=false
- end
- end
- end
- while inContext and not inRun do
- m = {os.pullEvent()}
- if(m[1] == "mouse_click")then
- if(m[2] == 2)then inContext = false; inRun = true; fileSystem() end
- if(cEmpty)then
- for k, v in pairs(contextEmpty) do
- if(m[2] == 1 and m[3] >= v.x and m[3] <= (#k)+v.x and m[4] == v.y)then
- v.fcmd()
- end
- end
- end
- if(not fs.isDir(selFile) and not cEmpty)then
- for k, v in pairs(contextMenu) do
- if(m[2] == 1 and m[3] >=3 and m[3] <= #k+3 and m[4] == v.yoff+contextY)then
- v.fcmd()
- end
- end
- end
- if(not cEmpty and fs.isDir(selFile))then
- for k, v in pairs(folderMenu) do
- if(m[2] == 1 and m[3] >=3 and m[3] <= #k+3 and m[4] == v.yoff+contextY)then
- v.fcmd()
- end
- end
- end
- end
- end
- end
- fileSystem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement