Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --====================================================
- --]] Nova Explore and all file apis created by
- --]] Lewisk3 CEO of Nova, all rights reservered
- --]] DO NOT REDISTRIBUTE without the permission
- --]] of Nova, Editing and/or "rebranding" is prohibited.
- --]] Any copys found outside the permission of Nova
- --]] will be taken and money will be due to the rights
- --]] of Nova Technologys
- -------------------------------------------------------
- --=] We have the rights to all the above [=-
- --=====================================================
- --]] Determine OS and load apis accordingly
- os.loadAPI(shell.resolveProgram("NovaAPI"))
- local w, h = term.getSize()
- local sbc = term.setBackgroundColor
- local stc = term.setTextColor
- local scp = term.setCursorPos
- local clr = term.clear
- local clrln = term.clearLine
- local actionkeydown = false
- local actionkey = keys.leftCtrl
- local multiselecting = false
- local diskside = "right"
- files_selected = {}
- local archiver = ""
- local pa = paintutils
- local pinnednames = {}
- local innova = true
- local iscrossbow = false
- --]] Define variables
- local file_selected = 0
- local files = {}
- -- Path isnt locked
- local path = NovaAPI.newpath("/")
- NovaAPI.setActive(false)
- NovaAPI.setInput(path:getraw())
- local fileoffs = 0
- local sideoffs = 0
- local sidemax = h-1
- local filemax = h
- local searching = false
- local selectedside = 0
- local search = ""
- local pathsearch = "/"
- local clipboard = {}
- local inmenu = false
- local inmenutype = {}
- local drawingmenu = {}
- local inmenux, inmenuy = 1, 4
- local sideitems = {}
- local pinslocation = ".novapins"
- local icons = {
- folder = "&e[=]",
- file = "&7-~-",
- executable = "&8:&7=&8:",
- game = "&4-&7=&8]",
- zip = "&5[&1=&2]",
- paint = "&2~&4* ",
- pin = "&7<&8 ",
- disk= "&8:&4^&8:"
- }
- --]] Menus
- filemenu = {
- {n="Open ",func=function(file) openHref(path:getraw() .. file.n) end},
- {n="Edit ",func=function(file)
- editfile(path:getraw() .. file.n)
- end},
- {n="Open as ",func=function(file)
- local ans = NovaAPI.openYesNo("Open File As. ","Select open option.*",novaex_redraw,"With", "Args")
- if(ans == 1)then -- open with file
- local openfile = NovaAPI.openReadDialog("Open with another file. ",novaex_redraw)
- if(file ~= "")then
- runFile(openfile,path:getraw() .. file.n,true)
- end
- elseif(ans == 2)then -- open with arguments
- local args = NovaAPI.openReadDialog("Open with arguments. ",novaex_redraw)
- runFile(path:getraw() .. file.n,args,true)
- end
- end},
- {n="Rename ",relies=function(file)
- return file.t ~= "disk"
- end,
- func=function(file)
- local sid = getSelectedFile()
- sbc(colors.lightGray)
- scp(23,(sid-fileoffs)+4)
- write(string.rep(" ",17))
- scp(23,(sid-fileoffs)+4)
- local newname = NovaAPI.readEx(17,false,file.n)
- renameFile(path:getraw(),file.n,newname)
- end},
- {n="Extract ",relies=function(file) return file.t == "zip" end,
- func=function(file)
- local eto = NovaAPI.openReadDialog("Extract to: ",novaex_redraw)
- local ans = NovaAPI.openYesNo("Extract ", "Extract contents of * " .. file.n .. " to: " .. eto .. "? ",novaex_redraw)
- if(ans == 1)then
- NovaAPI.extract(path:getraw() .. file.n,eto)
- ans = NovaAPI.openYesNo("Extract ", "Extracted to: " .. eto .. "* Open location?",novaex_redraw)
- if(ans == 1)then
- path:set(eto)
- getfiles()
- undrawFiles()
- drawFiles()
- end
- end
- end},
- {n="Archive ",relies=function(file) return file.t ~= "zip" end,
- func=function(file)
- local eto = NovaAPI.openReadDialog("Export archive to: ",novaex_redraw)
- if(NovaAPI.archive(path:getraw() .. file.n,eto))then
- NovaAPI.notify("Archive","Folder/file successfully * archived. ",novaex_redraw)
- else
- NovaAPI.notify("Archive","Failed to archive folder/file. ",novaex_redraw)
- end
- end},
- {n="Cut ",relies=function(file)
- return not fs.isReadOnly(path:getraw() .. file.n)
- end,func=function(file)
- setClipboard(path:getraw() .. file.n, file.n, "cut")
- end},
- {n="Copy ",func=function(file)
- setClipboard(path:getraw() .. file.n, file.n, "copy")
- end},
- {n="Paste ",relies=function(file)
- return clipboard.name ~= nil and
- not fs.isReadOnly(path:getraw() .. file.n)
- end,
- func=function(file)
- pasteFile(path:getraw())
- end},
- {n="Pin item",relies=function(file)
- return not isPinnedItem(path:getraw() .. file.n) end,
- func=function(file)
- addPinnedFile(
- icons[file.t] .. " &r" .. file.n,file.t,path:getraw() .. file.n
- )
- end},
- {n="Unpin ",relies=function(file)
- return isPinnedItem(path:getraw() .. file.n) end,
- func=function(file)
- removePinnedFile(path:getraw() .. file.n)
- end},
- {n="Delete ",relies=function(file)
- return not fs.isReadOnly(path:getraw() .. file.n) and
- not (file.t == "disk" and peripheral.find("drive"))
- end,func=function(file)
- local ans = NovaAPI.openYesNo("File deletion. ","Confirm &4deletion&r of *" .. file.n,novaex_redraw)
- if(ans == 1)then
- deleteFile(path:getraw() .. file.n)
- end
- end},
- }
- sidemenu = {
- {n="Open ",func=function() openHref(getSelectedSideItem().href) end},
- {n="Rename ",
- func=function(file)
- local sid = getSelectedSide()
- scp(5,(sid-sideoffs)+4)
- sbc(colors.lightGray)
- write(string.rep(" ",11))
- scp(5,(sid-sideoffs)+4)
- local newname = NovaAPI.readEx(9,false)
- renameSideItem(getSelectedSide(),newname)
- end},
- {n="Unpin ",relies=function() return getSelectedSide() >= 8 end,
- func=function(file)
- removePinnedFile(getSelectedSideItem().href)
- end},
- {n="Up ",relies=function()
- return getSideItem(getSelectedSide()-1).t ~= nil and
- getSideItem(getSelectedSide()-1).t ~= "text"
- end,
- func=function(file)
- moveSideItem(getSelectedSide(),-1)
- end},
- {n="Down ",relies=function()
- return (getSelectedSide() < getSideAmmount()) and
- (getSideItem(getSelectedSide()+1).n ~= nil) and
- (getSideItem(getSelectedSide()+1).t ~= "text")
- end,
- func=function(file)
- moveSideItem(getSelectedSide(),1)
- end},
- }
- emptymenu = {
- {n="New Folder ",func=function()
- local file = NovaAPI.openReadDialog("New Folder",novaex_redraw)
- newFileFolder("folder",path:getraw(),file)
- end},
- {n="New File ",func=function()
- local file = NovaAPI.openReadDialog("New File",novaex_redraw)
- newFileFolder("file",path:getraw(),file)
- end},
- {n="Paste ",relies=function()
- return clipboard.name ~= nil and
- not fs.isReadOnly(path:getraw())
- end,
- func=function()
- pasteFile(path:getraw())
- end},
- {n="Test Crash ",func=function() error("Lol get rekt!") end},
- }
- foldermenu = {
- filemenu[1],
- filemenu[4],
- filemenu[6],
- filemenu[7],
- filemenu[8],
- filemenu[9],
- {n="Pin item",relies=function(file)
- return not isPinnedItem(path:getraw() .. file.n) end,
- func=function(file)
- addPinnedFile(
- icons[file.t] .. " &r" .. file.n,file.t,path:getraw() .. file.n
- )
- end},
- filemenu[11],
- {n="Eject ",relies=function(file)
- return (file.t == "disk" and peripheral.find("drive"))
- end,func=function(file)
- disk.eject(getDiskside())
- end},
- filemenu[12],
- }
- if(iscrossbow)then
- sideitems = {
- {n='&5* &rQuick Access',t='text'},
- {n=' ',t='text'},
- {n=icons.folder..' &rPrograms',t='folder',href="CrossBow/programs"},
- {n=icons.folder..' &rGames',t='folder',href="CrossBow/games"},
- {n=' ',t='text'},
- {n=' ',t='text'},
- {n=icons.pin .. "&rPinned Items",t='text'},
- {n=' ',t='text'},
- {n=icons.game..' &rGameOfLife',t='game',href="CrossBow/games/GameOfLife"},
- {n=icons.game..' &r2048',t='game',href="CrossBow/games/2048"},
- {n=icons.folder..' &5Apis',t='folder',href="CrossBow/apis"},
- }
- else
- sideitems = {
- {n='&5* &rQuick Access',t='text'},
- {n=' ',t='text'},
- {n=icons.folder..' &rPrograms',t='folder',href="rom/programs"},
- {n=icons.folder..' &rGames',t='folder',href="rom/programs/fun"},
- {n=' ',t='text'},
- {n=' ',t='text'},
- {n=icons.pin .. "&rPinned Items",t='text'},
- {n=' ',t='text'},
- {n=icons.game..' &2Worm',t='game',href="rom/programs/fun/worm"},
- {n=icons.game..' &8Redirection',t='game',href="rom/programs/fun/advanced/redirection"},
- }
- end
- --]] Get functions and file definitions
- local pinnednames = {}
- if(iscrossbow)then
- pinslocation = "configs/novapins"
- end
- function writexy(text,x,y)
- term.setCursorPos(x,y)
- term.write(text)
- end
- function writec(text)
- local w, h = term.getSize()
- term.setCursorPos(w/2 - #text/2, (h/2)- 1)
- term.write(text)
- end
- function writecy(text,y)
- local w,_ = term.getSize()
- term.setCursorPos(w/2 - #text/2, y)
- term.write(text)
- end
- function getDiskside() return diskside end
- function getWorkingDir()
- return fs.getDir(shell.getRunningProgram()) .. "/"
- end
- function getConfigPinnedItems()
- if(fs.exists(getWorkingDir() .. pinslocation))then
- local pfile = (getWorkingDir() .. pinslocation)
- local itemspinned = textutils.unserialize(NovaAPI.file_readAll(pfile))
- for i = 1, #itemspinned do
- sideitems[8+(i-1)] = itemspinned[i]
- end
- getPinnedNames()
- else
- local writeitems = {}
- for i = 8, #sideitems do
- writeitems[#writeitems+1] = sideitems[i]
- end
- NovaAPI.file_write(getWorkingDir() .. pinslocation,textutils.serialize(writeitems))
- getConfigPinnedItems()
- end
- end
- function saveConfigPinnedItems()
- local writeitems = {}
- for i = 8, #sideitems do
- writeitems[#writeitems+1] = sideitems[i]
- end
- if(fs.exists(getWorkingDir() .. pinslocation))then
- NovaAPI.file_write(getWorkingDir() .. pinslocation,textutils.serialize(writeitems))
- end
- end
- function isPinnedItem(path)
- return pinnednames[formatPinPath(path)]
- end
- -- Icon drawing
- function formatPinPath(path)
- local npath = NovaAPI.newpath(path)
- local pathtbl={}
- for str in string.gmatch(path, "([^/]+)") do
- pathtbl[#pathtbl+1] = str
- end
- fname = pathtbl[#pathtbl]
- npath:goback(1)
- if(path:sub(1,1) == "/" and #npath:getraw() > 1)then path = path:sub(2,#path) end
- if(#npath:getraw() <= 1)then path = "/" .. fname end
- return path
- end
- function novaex_redraw()
- undrawFiles()
- getfiles()
- drawMain()
- drawFiles()
- end
- function moveSideItem(id,to)
- local moveitem = sideitems[id]
- local toitem = sideitems[id+to]
- sideitems[id+to] = moveitem
- sideitems[id] = toitem
- selectedside = selectedside + to
- drawSideBar()
- end
- function deleteFile(file)
- file_selected = 0
- fs.delete(file)
- undrawFiles()
- getfiles()
- drawFiles()
- end
- function newFileFolder(forf,path,file)
- if(file == "" or file:find(" "))then return false end
- if(not fs.exists(path .. file))then
- if(forf == "folder")then
- if(file:sub(1,4) == "disk")then
- NovaAPI.notify("Creation Error.","Cannot create disk directory!",novaex_redraw)
- return false
- end
- fs.makeDir(path .. file)
- elseif(forf == "file")then
- local f = fs.open(path .. file,"w")
- f.write("")
- f.close()
- end
- getfiles()
- drawFiles()
- else
- NovaAPI.notify("Creation Error.","File or folder already exists.",novaex_redraw)
- end
- end
- function drawPathSearch()
- sbc(colors.white)
- writexy(string.rep(" ",w-24),12,2)
- sbc(colors.white)
- stc(colors.black)
- scp(13,2)
- if(#path:getraw() > 25)then
- local dif = #path:getraw() - 25
- write(pathsearch:sub(dif,#path:getraw()))
- else
- write(pathsearch)
- end
- end
- function renameSideItem(id,nname)
- if(nname ~= "")then
- nname = icons[sideitems[id].t] .. "&r " .. nname
- sideitems[id].n = nname
- saveConfigPinnedItems()
- end
- drawSideBar()
- end
- function getSideItemType(id)
- return sideitems[id].t
- end
- function getSideItem(id)
- return sideitems[id]
- end
- function addPinnedFile(name,type,link)
- sideitems[#sideitems+1] = {n=name,t=type,href=formatPinPath(link)}
- pinnednames[formatPinPath(link)] = true
- saveConfigPinnedItems()
- drawFiles()
- drawSideBar()
- end
- function setClipboard(p,n,t)
- clipboard = {path=p,name=n,type=t}
- if(t == "cut")then
- drawFiles()
- end
- end
- function getSelectedSideItem()
- return sideitems[selectedside]
- end
- function getSelectedSide()
- return selectedside
- end
- function getSideAmmount()
- return #sideitems
- end
- function getSelectedFile()
- return file_selected
- end
- function getnamedpins()
- return pinnednames
- end
- function getClipboard()
- return clipboard
- end
- function removePinnedFile(link)
- for i = 8, #sideitems do
- if(sideitems[i].href == formatPinPath(link))then
- table.remove(sideitems,i)
- getPinnedNames()
- saveConfigPinnedItems()
- break
- end
- end
- selectedside = 0
- drawFiles()
- drawSideBar()
- end
- function getPinnedNames()
- pinnednames = {}
- for i = 1, #sideitems do
- if(sideitems[i].t ~= "text")then
- pinnednames[sideitems[i].href] = true
- end
- end
- end
- --]] Get files in directory
- function getfiles()
- files = {}
- local folders = {}
- for k , v in pairs(fs.list(path:getraw())) do
- if(fs.isDir(path:getraw() .. v) and (path:getraw() .. v):find(search) )then
- local spt = 'folder'
- if(v:sub(1,4) == "disk")then
- if(#v > 4)then
- if(tonumber(v:sub(5,#v)) ~= nil)then
- spt = "disk"
- end
- else
- spt = "disk"
- end
- end
- folders[#folders+1] = {n=v,t=spt}
- else if( v:find(search) )then
- local nt = 'file'
- if(v:sub(#v-3,#v) == '.zip')then nt = 'zip' end
- if(v:sub(#v-3,#v) == '.exe')then nt = 'exe' end
- if(path:getraw():find("CrossBow/games") or
- path:getraw():find("rom/programs/fun"))then nt = "game" end
- if(path:getraw():find("CrossBow/programs"))then nt = "executable" end
- if(NovaAPI.isFileImage(path:getraw() .. v))then nt = "paint" end
- files[#files+1] = {n=v,t=nt}
- end
- end
- end
- -- Sort folders before files
- for k,v in pairs(files) do
- table.insert(folders, v)
- end
- files = folders
- end
- --]] Draw program layout
- function drawSideBar()
- term.current().setVisible(false)
- sbc(colors.white)
- pa.drawFilledBox(0,4,17,h,colors.white)
- sbc(1,1)
- local loopam = #sideitems
- if(#sideitems > h-5)then
- loopam = (h-5)+sideoffs
- end
- for i = 1+sideoffs, loopam do
- if(i-sideoffs < sidemax)then
- if(sideitems[i] ~= nil)then
- scp(1,(i-sideoffs)+4)
- write(string.rep(" ",16))
- if(selectedside == i)then
- sbc(colors.lightGray)
- else
- sbc(colors.white)
- end
- NovaAPI.colorwrite(sideitems[i].n,12,1,(i-sideoffs)+4)
- end
- end
- end
- pa.drawBox(17,4,17,h,colors.gray)
- pa.drawBox(1,h,17,h,colors.gray)
- pa.drawBox(16,4,16,h-1,colors.lightGray)
- stc(colors.gray)
- writexy("^",16,4)
- writexy("v",16,h-1)
- term.current().setVisible(true)
- end
- -- Deprecidated
- function drawFile(ind)
- -- Draw selected files
- term.current().setVisible(false)
- sbc(colors.white)
- stc(colors.black)
- if(ind <= filemax)then
- scp(19,ind+fileoffs)
- write(string.rep(" ",30))
- NovaAPI.colorwrite(icons[files[ind].t] .. " &r" .. files[ind].n ,12,19,ind,file_selected == ind)
- scp(40,ind+fileoffs)
- if(not fs.isDir(path:getraw() .. files[ind].n))then
- write(tostring(fs.getSize(path:getraw() .. files[ind].n) / 1000):sub(1,4) .. "KB")
- end
- end
- term.current().setVisible(true)
- drawPathSearch()
- end
- function undrawFiles()
- pa.drawFilledBox(18,4,w-1,h,colors.white)
- end
- function drawFilePath()
- sbc(colors.white)
- writexy(string.rep(" ",w-24),12,2)
- sbc(colors.white)
- stc(colors.black)
- scp(13,2)
- if(#path:getraw() > 25)then
- local dif = #path:getraw() - 25
- write(path:getraw():sub(dif,#path:getraw()))
- else
- write(path:getraw())
- end
- end
- function drawFiles()
- term.current().setVisible(false)
- sbc(colors.white)
- stc(colors.black)
- drawFilePath()
- scp(23,4)
- stc(colors.lightGray)
- write("Name")
- scp(40,4)
- write("Size")
- if(#files == 0)then
- scp(25,5)
- stc(colors.lightGray)
- if(search ~= "")then
- scp(20,5)
- write("No items matched your search. ")
- else
- write("This folder is empty. ")
- end
- end
- local loopam = #files
- if(#files > h-4)then
- loopam = (h-4)+fileoffs
- end
- for i = 1+fileoffs, loopam do
- if(i-fileoffs <= filemax)then
- if(files[i].n ~= nil)then
- scp(19,(i-fileoffs)+4)
- write(string.rep(" ",30))
- local namecolor = " &r"
- local drawname = files[i].n
- if(path:getraw() .. files[i].n == clipboard.path and clipboard.type == "cut")then
- namecolor = " &7"
- end
- if(isPinnedItem(path:getraw() .. files[i].n))then
- namecolor = " &b"
- if(path:getraw() .. files[i].n == clipboard.path and clipboard.type == "cut")then
- namecolor = " &e"
- end
- end
- local selected = (file_selected == i)
- if(multiselecting)then
- for s = 1, #files_selected do
- if(files_selected[s].n == files[i].n and
- path:getraw() == files_selected[s].p)then
- if(clipboard.type == "cut")then
- namecolor = " &7"
- if(isPinnedItem(path:getraw() .. files[i].n))then
- namecolor = " &e"
- end
- end
- selected = true
- end
- end
- end
- local bcol = colors.white
- if(selected)then bcol = colors.lightBlue end
- NovaAPI.colorwrite(icons[files[i].t] .. namecolor .. drawname .."&r",12,19,(i-fileoffs)+4,bcol)
- if(search ~= "" )then
- local foundletters = ""
- for x = 1, #files[i].n do
- if(search:find(files[i].n:sub(x,x)) and not foundletters:find(files[i].n:sub(x,x)) )then
- foundletters = foundletters .. files[i].n:sub(x,x)
- scp( (22)+x, (i-fileoffs)+4) -- hardcoded for 3 wide icons
- sbc(colors.yellow)
- write(files[i].n:sub(x,x))
- sbc(colors.white)
- end
- end
- end
- scp(40,(i-fileoffs)+4)
- if(not fs.isDir(path:getraw() .. files[i].n))then
- write(tostring(fs.getSize(path:getraw() .. files[i].n) / 1000):sub(1,4) .. "KB")
- end
- end
- end
- end
- term.current().setVisible(true)
- end
- function renameFile(path,name,nname)
- local odir = shell.dir()
- shell.setDir("")
- if(not fs.exists(path .. nname) and nname ~= "" and not nname:find(" "))then
- if(nname:sub(1,4) == "disk" and fs.isDir(path .. name))then
- shell.setDir(odir)
- NovaAPI.notify("Rename Error.","Cannot rename directory to * disk!",novaex_redraw)
- return false
- end
- fs.move(path .. name, path .. nname)
- getfiles()
- elseif(nname ~= "" and not nname:find(" "))then
- NovaAPI.notify("Couldn't rename file.","File with name: * ".. nname .. ", already exists.",novaex_redraw)
- end
- drawFiles()
- shell.setDir(odir)
- end
- function runFile(fpath,args,noclick)
- local odir = shell.dir()
- sbc(colors.black)
- stc(colors.white)
- clr()
- scp(1,1)
- shell.setDir("")
- if(NovaAPI.isFileImage(fpath))then
- args = fpath
- fpath = "paint"
- noclick = true
- end
- if(shell.resolveProgram(fpath))then
- if(fs.exists(shell.resolveProgram(fpath)))then
- shell.run(fpath,args)
- if(not noclick)then
- writecy("Click any where to return to NovaBrowse. ",9)
- os.pullEvent("mouse_click")
- end
- else
- NovaAPI.notify("Open file.", "&4File not found. ",novaex_redraw)
- end
- end
- search = ""
- shell.setDir(odir)
- drawMain()
- getfiles()
- drawFiles()
- drawPathSearch()
- end
- function setDir(name)
- if(fs.isDir(name))then
- clearSearch()
- file_selected = 0
- if(name:sub(#name,#name) ~= "/")then name = name .. "/" end
- fileoffs = 0
- path:set(name)
- getfiles()
- undrawFiles()
- drawFiles()
- return true
- else
- drawFilePath()
- return false
- end
- NovaAPI.setInput(path:getraw())
- pathsearch = path:getraw()
- end
- function addDir(name)
- selectedside = 0
- drawSideBar()
- clearSearch()
- file_selected = 0
- fileoffs = 0
- path:add(name)
- getfiles()
- undrawFiles()
- drawFiles()
- NovaAPI.setInput(path:getraw())
- pathsearch = path:getraw()
- end
- function clearSearch()
- search = ""
- scp(40,2)
- sbc(colors.lightGray)
- write(string.rep(" ",11))
- end
- function searchDir(val)
- file_selected = 0
- fileoffs = 0
- local nfiles = {}
- undrawFiles()
- if(val == "" or val == " ")then
- getfiles()
- else
- --for i = 1, #files do
- -- if(files[i])then
- -- if(not files[i].n:find(val))then
- -- table.remove(files,i)
- -- end
- -- end
- -- end
- --files = nfiles
- end
- drawFiles()
- end
- function openHref(href)
- if(fs.isDir(href))then
- setDir(href)
- elseif(fs.exists(href))then
- return runFile(href)
- end
- end
- function editfile(filepath)
- runFile("edit",filepath,true)
- end
- function pasteMultiFile(to)
- if(multiselecting)then
- for i = 1, #files_selected do
- clipboard.path = files_selected[i].p .. files_selected[i].n
- clipboard.name = files_selected[i].n
- pasteFile(to)
- end
- end
- end
- function pasteFile(to)
- local odir = shell.dir()
- if(fs.isReadOnly(to))then
- NovaAPI.notify("Paste file ", "Access Denied. ",novaex_redraw)
- return
- end
- if(not fs.exists(to .. clipboard.name))then
- fs.copy(clipboard.path,path:getraw() .. clipboard.name)
- if(clipboard.type == "cut")then fs.delete(clipboard.path) clipboard = {} end
- getfiles()
- drawFiles()
- else
- if(to .. clipboard.name == clipboard.path)then
- clipboard = {}
- drawFiles()
- return
- end
- local ans = NovaAPI.openYesNo("File transfer","File exists, Rename file? ",novaex_redraw)
- if(ans == 1)then
- local newname = NovaAPI.openReadDialog("Rename paste file. ",novaex_redraw,clipboard.name)
- if(newname:find(" "))then
- NovaAPI.notify("File rename ", "Invalid file name. ",novaex_redraw)
- else
- clipboard.name = newname
- end
- return pasteFile(to)
- end
- end
- shell.setDir(odir)
- end
- function prevDir(ind)
- selectedside = 0
- drawSideBar()
- scp(2,2)
- sbc(colors.gray)
- stc(colors.black)
- write("<-")
- sleep(0.1)
- scp(2,2)
- sbc(colors.lightGray)
- stc(colors.gray)
- write("<-")
- clearSearch()
- file_selected = 0
- fileoffs = 0
- path:goback(ind)
- getfiles()
- undrawFiles()
- drawFiles()
- NovaAPI.setInput(path:getraw())
- pathsearch = path:getraw()
- end
- function refreshDir()
- scp(6,2)
- sbc(colors.gray)
- stc(colors.black)
- write("<>")
- sleep(0.1)
- scp(6,2)
- sbc(colors.lightGray)
- stc(colors.gray)
- write("<>")
- clearSearch()
- file_selected = 0
- fileoffs = 0
- drawMain()
- getConfigPinnedItems()
- getPinnedNames()
- drawSideBar()
- getfiles()
- drawFiles()
- checkUpdate()
- NovaAPI.setInput(path:getraw())
- pathsearch = path:getraw()
- end
- function drawfilemenu(menu,sx,sy)
- local finalmenu = {}
- for i = 1, #menu do
- if(menu[i].relies == nil)then
- finalmenu[#finalmenu+1] = menu[i]
- elseif(menu[i].relies(files[file_selected],pinnednames))then
- finalmenu[#finalmenu+1] = menu[i]
- end
- end
- if(sy+#finalmenu > h)then
- sy = sy - ((sy+#finalmenu)-h)
- end
- if(sx+#finalmenu[1].n >= w-1)then
- sx = sx - ((sx+#finalmenu[1].n)-(w-1))
- end
- pa.drawBox(sx,sy+2,sx+#finalmenu[1].n,sy+#finalmenu+1,colors.black)
- for i = 1, #finalmenu do
- if(sy+i <= h)then
- scp(sx-1,sy+i)
- sbc(colors.lightGray)
- stc(colors.white)
- write(string.rep(" ",#finalmenu[i].n+1))
- scp(sx,sy+i)
- write(finalmenu[i].n)
- end
- end
- return finalmenu, sx, sy
- end
- function drawMenuClick(mop)
- local _, dny = term.getCursorPos()
- local dnx = inmenux+1
- sbc(colors.gray)
- stc(colors.black)
- write(mop.n)
- sleep(0.2)
- scp(dnx,dny)
- sbc(colors.lightGray)
- stc(colors.white)
- write(mop.n)
- end
- function updatemenu(e,menu,sx,sy,clrfunc)
- if(e[1] == "mouse_click")then
- local x, y = e[3], e[4]
- local mlen = #menu[1].n-1
- if(x >= sx and x <= sx+mlen and y >= sy+1 and y <= sy+#menu)then
- local clicked = menu[(y-sy)]
- scp(sx,y)
- drawMenuClick(clicked)
- clrfunc()
- e[1] = nil
- inmenu = false
- return clicked.func(files[file_selected])
- else
- clrfunc()
- inmenu = false
- end
- end
- end
- function opencloseMenu(type,x,y,yind)
- if(inmenu)then
- undrawFiles()
- drawFiles()
- drawSideBar()
- inmenu = false
- elseif(type=="reg")then
- local mtodraw = filemenu
- if(fs.isDir(path:getraw() .. files[file_selected].n))then
- mtodraw = foldermenu
- end
- drawingmenu = mtodraw
- inmenutype, inmenux, inmenuy = drawfilemenu(mtodraw,x,y)
- inmenu = true
- elseif(type=="sidebar")then
- drawingmenu = sidemenu
- inmenutype, _, inmenuy = drawfilemenu(sidemenu,5,y)
- inmenux = 5
- inmenu = true
- elseif(type=="new" and not fs.isReadOnly(path:getraw()) )then
- drawingmenu = emptymenu
- inmenutype,inmenux,inmenuy = drawfilemenu(emptymenu,x,y)
- inmenu = true
- end
- end
- local function update(e)
- if(inmenu)then
- updatemenu(e,inmenutype,inmenux,inmenuy,novaex_redraw)
- end
- if(e[1] == "disk")then
- getfiles()
- drawFiles()
- diskside = e[2]
- if(fs.exists("disk/autorun"))then
- local ans = NovaAPI.openYesNo("Disk detected ","A software disk has been * detected. ",novaex_redraw,"Run","Cancel")
- if(ans == 1)then
- runFile("disk/autorun")
- end
- elseif(disk.hasAudio(e[2]))then
- local ans = NovaAPI.openYesNo("Music detected ","A music disk has been * inserted. ",novaex_redraw,"Play","Cancel")
- if(ans == 1)then
- disk.playAudio(e[2])
- end
- else
- local ans = NovaAPI.openYesNo("Disk detected ","A floppy disk has been * inserted. ",novaex_redraw,"Open","Cancel")
- if(ans == 1)then
- setDir("disk/")
- end
- end
- elseif(e[1] == "disk_eject")then
- if(path:getraw():find("disk/"))then
- path:set("/")
- end
- undrawFiles()
- getfiles()
- drawFiles()
- end
- if(e[1] == "paste")then
- if(clipboard.name ~= nil)then
- if(multiselecting)then
- pasteMultiFile(path:getraw())
- else
- pasteFile(path:getraw())
- end
- end
- end
- if(e[1] == "key")then
- local key = e[2]
- if(key == actionkey and not actionkeydown)then
- actionkeydown = true
- elseif(actionkeydown)then
- local opper = "copy"
- if(key == keys.c or key == keys.x)then
- if(key == keys.x)then opper = "cut" end
- if(file_selected ~= 0)then
- setClipboard(path:getraw() .. files[file_selected].n,
- files[file_selected].n, opper)
- end
- end
- end
- if(file_selected > 0)then
- if(key == keys.delete)then
- local ans = NovaAPI.openYesNo("File deletion. ","Confirm &4deletion&r of *" .. files[file_selected].n,novaex_redraw)
- if(ans == 1)then
- deleteFile(path:getraw() .. files[file_selected].n)
- end
- end
- end
- if(selectedside > 0)then
- if(key == keys.up and sideitems[selectedside-1].t ~= nil and
- sideitems[selectedside-1].t ~= "text" )then
- moveSideItem(selectedside,-1)
- elseif(key == keys.down and (selectedside < #sideitems) and
- (sideitems[selectedside+1].n ~= nil) and
- sideitems[selectedside+1].t ~= "text" )then
- moveSideItem(selectedside,1)
- end
- end
- elseif(e[1] == "key_up")then
- local key = e[2]
- if(key == actionkey and actionkeydown )then
- actionkeydown = false
- end
- end
- if(e[1] == "mouse_click")then
- local x,y = e[3], e[4]
- -- Left clicked
- if(e[2] == 1)then
- if(x == w and y == 1)then
- clickExit()
- innova = false
- sbc(colors.white)
- clr()
- stc(colors.gray)
- writecy("Thank you for using Nova Explore. ",9)
- writecy("Click the screen to exit. ",10)
- os.pullEvent("mouse_click")
- sbc(colors.black)
- clr()
- stc(colors.white)
- scp(1,1)
- return
- end
- if(x >= 11 and x <= 36 and y == 2)then
- NovaAPI.setInput(pathsearch)
- end
- if(x >= 38 and x <= 51 and y == 2)then
- NovaAPI.setInput(search)
- searching = true
- elseif(searching)then
- search = NovaAPI.getInput()
- searching = false
- end
- if(x >= 2 and x <= 4 and y == 2)then
- if(inmenu)then inmenu = false end
- prevDir(1)
- end
- if(x >= 6 and x <= 8 and y == 2)then
- refreshDir()
- end
- end
- -- Left or right clicked
- local yind = (y+fileoffs)-4
- local syind = (y+sideoffs)-4
- if(x < 18 and syind <= #sideitems and syind > 0)then
- if(y > 4 and x >= 1 and x <= #(sideitems[syind].n:sub(1,14)) )then
- if(e[2] == 1 and not inmenu and sideitems[syind].t ~= "text")then
- if(fs.isDir(sideitems[syind].href))then
- selectedside = syind
- openHref(sideitems[syind].href)
- drawSideBar()
- elseif(sideitems[syind].t ~= "text")then
- if(selectedside == syind)then
- openHref(sideitems[syind].href)
- else
- selectedside = syind
- drawSideBar()
- end
- end
- elseif(e[2] == 2)then
- if(selectedside ~= 0 and sideitems[syind].t ~= "text" and yind == selectedside)then
- opencloseMenu("sidebar",x,y)
- end
- end
- end
- elseif(yind <= #files and yind > 0)then
- if(y > 4 and x >= 18 and x <= 22+#files[yind].n)then
- if(e[2] == 1 and not inmenu)then
- if(file_selected == yind)then
- if(fs.isDir(path:getraw() .. files[file_selected].n))then
- if(inmenu)then inmenu = false end
- addDir(files[yind].n)
- else
- runFile(path:getraw() .. files[file_selected].n)
- end
- else
- file_selected = yind
- drawFiles()
- drawPathSearch()
- end
- elseif(e[2] == 2 )then
- if(file_selected == yind)then
- opencloseMenu("reg",x,y,yind)
- else
- opencloseMenu("new",x,y,yind)
- end
- end
- end
- end
- if(e[2] == 2 and not inmenu and x > 18)then
- opencloseMenu("new",x,y,1)
- end
- end
- if(e[1] == "mouse_scroll")then
- NovaAPI.setActive(false)
- local dir = e[2]
- local x,y = e[3], e[4]
- if(dir == -1)then
- if(x > 16 and fileoffs > 0 )then
- fileoffs = fileoffs - 1
- drawFiles()
- elseif(x <= 16 and sideoffs > 0)then
- sideoffs = sideoffs - 1
- drawSideBar()
- end
- elseif(dir == 1)then
- if(x > 16 and fileoffs < #files-(filemax-4))then
- fileoffs = fileoffs + 1
- drawFiles()
- elseif(x <= 16 and sideoffs < #sideitems-(sidemax-4))then
- sideoffs = sideoffs + 1
- drawSideBar()
- end
- end
- end
- if(pathsearch ~= "")then
- if(NovaAPI.getActive() == false)then
- drawPathSearch()
- end
- if(NovaAPI.getActive() == false and not searching)then
- if(NovaAPI.getInput() ~= pathsearch)then
- --pathsearch = NovaAPI.getInput()
- NovaAPI.setInput(pathsearch)
- end
- end
- end
- -- Searching files/commands
- if(not searching)then
- stc(colors.black)
- sbc(colors.white)
- local doneinp = NovaAPI.novaread(e,1000,25,13,2)
- if(doneinp)then
- NovaAPI.setActive(false)
- term.setCursorBlink(false)
- pathsearch = NovaAPI.getInput()
- if( fs.isDir(NovaAPI.getInput()) )then
- if( setDir(NovaAPI.getInput()) )then
- selectedside = 0
- drawSideBar()
- end
- else
- --if(fs.exists(pathsearch))then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- shell.run(pathsearch)
- NovaAPI.setInput(pathsearch)
- writecy("Click any where to return to NovaBrowse. ",9)
- os.pullEvent("mouse_click")
- NovaAPI.setInput(pathsearch)
- drawMain()
- getfiles()
- drawFiles()
- --end
- end
- end
- else
- stc(colors.black)
- sbc(colors.lightGray)
- local doneinp = NovaAPI.novaread(e,1000,10,40,2)
- if(doneinp)then
- searching = false
- NovaAPI.setActive(false)
- search = NovaAPI.getInput()
- --if(fs.isDir(NovaAPI.getInput()))then
- getfiles() -- to prevent "nested" searches.
- searchDir(NovaAPI.getInput())
- --NovaAPI.setInput("")
- --end
- end
- end
- end
- function displayError(err)
- sbc(colors.white)
- clr()
- stc(colors.gray)
- writecy(" Well, thats not supposed to happen. ",1)
- scp(2,3)
- stc(colors.lightGray)
- write(err)
- writecy(" Why you do dis to me :(. ",16)
- stc(colors.black)
- writecy(" Press any key to end NovaExplore. ",17)
- writecy(" Click to restart NovaExplore. ",18)
- local e = {os.pullEvent()}
- if(e[1] == "key")then
- sbc(colors.black)
- clr()
- stc(colors.white)
- scp(1,1)
- elseif(e[1] == "mouse_click")then
- local odir = shell.dir()
- shell.setDir("")
- shell.run(shell.resolveProgram(shell.getRunningProgram()))
- shell.setDir(odir)
- end
- end
- function clickExit()
- scp(w,1)
- stc(colors.black)
- sbc(colors.pink)
- write("X")
- sleep(0.2)
- scp(w,1)
- stc(colors.white)
- sbc(colors.red)
- write("X")
- end
- function checkUpdate()
- if(http)then
- local upd = http.get("http://pastebin.com/raw/rpipr5pT")
- if(upd ~= nil)then
- local cont = upd.readAll()
- local f = fs.open(shell.getRunningProgram(),"r")
- local pcont = f.readAll()
- f.close()
- if(cont ~= pcont)then
- local ans = NovaAPI.openYesNo("Auto update", "Update detected, would you * like to update?.",novaex_redraw)
- if(ans == 1)then
- local f = fs.open(shell.getRunningProgram(),"w")
- f.write(cont)
- f.close()
- NovaAPI.notify("Auto update", "Updated, restart required.",novaex_redraw)
- innova = false
- return shell.run(shell.resolveProgram(shell.getRunningProgram()))
- end
- end
- else
- NovaAPI.notify("Auto update", "Failed to connect to pastebin.",novaex_redraw)
- end
- else
- NovaAPI.notify("Auto update", "Http is disabled, Failed to * check for updates.",novaex_redraw)
- return
- end
- end
- function drawMain()
- sbc(colors.white)
- clr()
- scp(1,2)
- sbc(colors.lightGray)
- clrln()
- pa.drawBox(w-12,1,w,3,colors.gray)
- sbc(colors.white)
- writexy(string.rep(" ",w-12),1,2)
- pa.drawBox(10,1,w-12,3,colors.gray)
- drawSideBar()
- pa.drawFilledBox(1,1,9,3,colors.lightGray)
- scp(2,2)
- stc(colors.gray)
- write("<- <>")
- --pa.drawBox(15,h,w,h,colors.lightGray)
- pa.drawBox(w,4,w,h,colors.lightGray)
- stc(colors.gray)
- writexy("^",w,4)
- writexy("v",w,h)
- scp(w,1)
- stc(colors.white)
- sbc(colors.red)
- write("X")
- sbc(colors.black)
- end
- drawMain()
- getConfigPinnedItems()
- getPinnedNames()
- drawSideBar()
- getfiles()
- drawFiles()
- checkUpdate()
- local function loop()
- while innova do
- local e = {os.pullEvent()}
- update(e)
- end
- end
- local ok, err = pcall(loop)
- if(not ok)then
- if(term.current().setVisible)then
- term.current().setVisible(true)
- end
- displayError(err)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement