Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local content = {
- [ "novaexplore/" ] = {
- content = "--====================================================\
- --]] 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 = {\
- \009folder = \"&e[=]\",\
- \009file = \"&7-~-\",\
- \009executable = \"&8:&7=&8:\",\
- \009game = \"&4-&7=&8]\",\
- \009zip = \"&5[&1=&2]\",\
- \009paint = \"&2~&4* \",\
- \009pin = \"&7<&8 \",\
- \009disk= \"&8:&4^&8:\"\
- }\
- --]] Menus \
- filemenu = {\
- \009 {n=\"Open \",func=function(file) openHref(path:getraw() .. file.n) end},\
- \009 {n=\"Edit \",func=function(file) \
- \009 \009editfile(path:getraw() .. file.n)\
- \009 end},\
- \009 {n=\"Open as \",func=function(file) \
- \009 \009local ans = NovaAPI.openYesNo(\"Open File As. \",\"Select open option.*\",novaex_redraw,\"With\", \"Args\")\
- \009 \009if(ans == 1)then -- open with file\
- \009 \009\009local openfile = NovaAPI.openReadDialog(\"Open with another file. \",novaex_redraw)\
- \009 \009\009if(file ~= \"\")then\
- \009 \009\009\009runFile(openfile,path:getraw() .. file.n,true)\
- \009 \009\009end\
- \009 \009elseif(ans == 2)then -- open with arguments\
- \009 \009\009local args = NovaAPI.openReadDialog(\"Open with arguments. \",novaex_redraw)\
- \009 \009\009runFile(path:getraw() .. file.n,args,true)\
- \009 \009end\
- \009 end},\
- \009 {n=\"Rename \",relies=function(file) \
- \009 \009return file.t ~= \"disk\"\
- \009 end,\
- \009 func=function(file)\
- \009 \009\009local sid = getSelectedFile()\
- \009 \009\009sbc(colors.lightGray)\
- \009 \009\009scp(23,(sid-fileoffs)+4)\
- \009 \009\009write(string.rep(\" \",17))\
- \009 \009\009scp(23,(sid-fileoffs)+4)\
- \009 \009\009local newname = NovaAPI.readEx(17,false,file.n)\
- \009 \009\009renameFile(path:getraw(),file.n,newname)\
- \009 end},\
- \009 {n=\"Extract \",relies=function(file) return file.t == \"zip\" end,\
- \009 func=function(file) \
- \009 \009 local eto = NovaAPI.openReadDialog(\"Extract to: \",novaex_redraw)\
- \009 \009 local ans = NovaAPI.openYesNo(\"Extract \", \"Extract contents of * \" .. file.n .. \" to: \" .. eto .. \"? \",novaex_redraw)\
- \009 \009 if(ans == 1)then\
- \009 \009 \009 NovaAPI.extract(path:getraw() .. file.n,eto)\
- \009 \009 \009 ans = NovaAPI.openYesNo(\"Extract \", \"Extracted to: \" .. eto .. \"* Open location?\",novaex_redraw)\
- \009 \009 \009 if(ans == 1)then\
- \009 \009 \009 \009 path:set(eto)\
- \009 \009 \009 \009 getfiles()\
- \009 \009 \009 \009 undrawFiles()\
- \009 \009 \009 \009 drawFiles()\
- \009 \009 \009 end\
- \009 \009 end\
- \009 end},\
- \009 {n=\"Archive \",relies=function(file) return file.t ~= \"zip\" end,\
- \009 func=function(file) \
- \009 \009 local eto = NovaAPI.openReadDialog(\"Export archive to: \",novaex_redraw)\
- \009 \009 if(NovaAPI.archive(path:getraw() .. file.n,eto))then\
- \009 \009\009 NovaAPI.notify(\"Archive\",\"Folder/file successfully * archived. \",novaex_redraw)\
- \009 else\
- \009 \009 NovaAPI.notify(\"Archive\",\"Failed to archive folder/file. \",novaex_redraw)\
- \009 \009 end\
- \009 end},\
- \009 {n=\"Cut \",relies=function(file) \
- \009\009return not fs.isReadOnly(path:getraw() .. file.n)\
- \009 end,func=function(file) \
- \009 \009setClipboard(path:getraw() .. file.n, file.n, \"cut\")\
- \009 end},\
- \009 {n=\"Copy \",func=function(file) \
- \009 \009setClipboard(path:getraw() .. file.n, file.n, \"copy\")\
- \009 end},\
- \009 {n=\"Paste \",relies=function(file) \
- \009 \009return clipboard.name ~= nil and \
- \009 \009\009not fs.isReadOnly(path:getraw() .. file.n)\
- \009 end,\
- \009 func=function(file) \
- \009 \009pasteFile(path:getraw()) \
- \009 end},\
- \009 {n=\"Pin item\",relies=function(file) \
- \009 \009return not isPinnedItem(path:getraw() .. file.n) end,\
- \009 func=function(file)\
- \009 \009 addPinnedFile(\
- \009 \009 \009icons[file.t] .. \" &r\" .. file.n,file.t,path:getraw() .. file.n\
- \009 \009 )\
- \009 end},\
- \009 {n=\"Unpin \",relies=function(file) \
- \009 \009return isPinnedItem(path:getraw() .. file.n) end,\
- \009 func=function(file) \
- \009 \009 removePinnedFile(path:getraw() .. file.n)\
- \009 end},\
- \009 {n=\"Delete \",relies=function(file) \
- \009 \009 return not fs.isReadOnly(path:getraw() .. file.n) and \
- \009 \009 \009not (file.t == \"disk\" and peripheral.find(\"drive\"))\
- \009 end,func=function(file) \
- \009 \009\009local ans = NovaAPI.openYesNo(\"File deletion. \",\"Confirm &4deletion&r of *\" .. file.n,novaex_redraw)\
- \009 \009\009if(ans == 1)then\
- \009 \009\009\009deleteFile(path:getraw() .. file.n)\
- \009 \009\009end\
- \009 end},\
- }\
- sidemenu = {\
- \009 {n=\"Open \",func=function() openHref(getSelectedSideItem().href) end},\
- \009 {n=\"Rename \",\
- \009 func=function(file)\
- \009 \009\009local sid = getSelectedSide()\
- \009 \009\009scp(5,(sid-sideoffs)+4)\
- \009 \009\009sbc(colors.lightGray)\
- \009 \009\009write(string.rep(\" \",11))\
- \009 \009\009scp(5,(sid-sideoffs)+4)\
- \009 \009\009local newname = NovaAPI.readEx(9,false)\
- \009 \009\009renameSideItem(getSelectedSide(),newname)\
- \009 end},\
- \009 {n=\"Unpin \",relies=function() return getSelectedSide() >= 8 end,\
- \009 func=function(file) \
- \009 \009removePinnedFile(getSelectedSideItem().href)\
- \009 end},\
- \009 {n=\"Up \",relies=function() \
- \009 \009\009return getSideItem(getSelectedSide()-1).t ~= nil and \
- \009 \009\009\009 getSideItem(getSelectedSide()-1).t ~= \"text\" \
- \009 \009\009end,\
- \009 func=function(file) \
- \009 \009\009moveSideItem(getSelectedSide(),-1)\
- \009 end},\
- \009 {n=\"Down \",relies=function() \
- \009 \009return (getSelectedSide() < getSideAmmount()) and \
- \009 \009\009 (getSideItem(getSelectedSide()+1).n ~= nil) and\
- \009 \009\009 (getSideItem(getSelectedSide()+1).t ~= \"text\")\
- \009 end,\
- \009 func=function(file) \
- \009 \009moveSideItem(getSelectedSide(),1)\
- \009 end},\
- }\
- emptymenu = {\
- \009{n=\"New Folder \",func=function() \
- \009\009local file = NovaAPI.openReadDialog(\"New Folder\",novaex_redraw)\
- \009\009newFileFolder(\"folder\",path:getraw(),file) \
- \009end},\
- \009{n=\"New File \",func=function() \
- \009\009local file = NovaAPI.openReadDialog(\"New File\",novaex_redraw)\
- \009\009newFileFolder(\"file\",path:getraw(),file) \
- \009end},\
- \009 {n=\"Paste \",relies=function() \
- \009 \009return clipboard.name ~= nil and \
- \009 \009\009not fs.isReadOnly(path:getraw())\
- \009 end,\
- \009 func=function() \
- \009 \009pasteFile(path:getraw()) \
- \009 end},\
- \009 {n=\"Test Crash \",func=function() error(\"Lol get rekt!\") end},\
- }\
- foldermenu = {\
- \009 filemenu[1],\
- \009 filemenu[4],\
- \009 filemenu[6],\
- \009 filemenu[7],\
- \009 filemenu[8],\
- \009 filemenu[9],\
- \009 {n=\"Pin item\",relies=function(file) \
- \009 \009return not isPinnedItem(path:getraw() .. file.n) end,\
- \009 func=function(file) \
- \009 \009 addPinnedFile(\
- \009 \009 \009icons[file.t] .. \" &r\" .. file.n,file.t,path:getraw() .. file.n\
- \009 \009 )\
- \009 end},\
- \009 filemenu[11],\
- \009 {n=\"Eject \",relies=function(file) \
- \009 \009 return (file.t == \"disk\" and peripheral.find(\"drive\"))\
- \009 end,func=function(file) \
- \009 \009\009disk.eject(getDiskside())\
- \009 end},\
- \009 filemenu[12],\
- }\
- if(iscrossbow)then\
- \009sideitems = {\
- \009\009{n='&5* &rQuick Access',t='text'},\
- \009\009{n=' ',t='text'},\
- \009\009{n=icons.folder..' &rPrograms',t='folder',href=\"CrossBow/programs\"},\
- \009\009{n=icons.folder..' &rGames',t='folder',href=\"CrossBow/games\"},\
- \009\009{n=' ',t='text'},\
- \009\009{n=' ',t='text'},\
- \009\009{n=icons.pin .. \"&rPinned Items\",t='text'},\
- \009\009{n=' ',t='text'},\
- \009\009{n=icons.game..' &rGameOfLife',t='game',href=\"CrossBow/games/GameOfLife\"},\
- \009\009{n=icons.game..' &r2048',t='game',href=\"CrossBow/games/2048\"},\
- \009\009{n=icons.folder..' &5Apis',t='folder',href=\"CrossBow/apis\"},\
- \009}\
- else\
- \009sideitems = {\
- \009\009{n='&5* &rQuick Access',t='text'},\
- \009\009{n=' ',t='text'},\
- \009\009{n=icons.folder..' &rPrograms',t='folder',href=\"rom/programs\"},\
- \009\009{n=icons.folder..' &rGames',t='folder',href=\"rom/programs/fun\"},\
- \009\009{n=' ',t='text'},\
- \009\009{n=' ',t='text'},\
- \009\009{n=icons.pin .. \"&rPinned Items\",t='text'},\
- \009\009{n=' ',t='text'},\
- \009\009{n=icons.game..' &2Worm',t='game',href=\"rom/programs/fun/worm\"},\
- \009\009{n=icons.game..' &8Redirection',t='game',href=\"rom/programs/fun/advanced/redirection\"},\
- \009}\
- end\
- --]] Get functions and file definitions\
- local pinnednames = {}\
- if(iscrossbow)then\
- \009pinslocation = \"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()\
- \009return fs.getDir(shell.getRunningProgram()) .. \"/\"\
- end\
- function getConfigPinnedItems()\
- \009if(fs.exists(getWorkingDir() .. pinslocation))then\
- \009\009local pfile = (getWorkingDir() .. pinslocation)\
- \009\009local itemspinned = textutils.unserialize(NovaAPI.file_readAll(pfile))\
- \009\009for i = 1, #itemspinned do\
- \009\009\009sideitems[8+(i-1)] = itemspinned[i]\
- \009\009end\
- \009\009getPinnedNames()\
- \009else\
- \009\009local writeitems = {}\
- \009\009for i = 8, #sideitems do\
- \009\009\009writeitems[#writeitems+1] = sideitems[i]\
- \009\009end\
- \009\009NovaAPI.file_write(getWorkingDir() .. pinslocation,textutils.serialize(writeitems))\
- \009\009getConfigPinnedItems()\
- \009end\
- end\
- function saveConfigPinnedItems()\
- \009local writeitems = {}\
- \009for i = 8, #sideitems do\
- \009\009writeitems[#writeitems+1] = sideitems[i]\
- \009end\
- \009if(fs.exists(getWorkingDir() .. pinslocation))then\
- \009\009NovaAPI.file_write(getWorkingDir() .. pinslocation,textutils.serialize(writeitems))\
- \009end\
- end\
- \
- function isPinnedItem(path)\
- \009return pinnednames[formatPinPath(path)]\
- end\
- \
- -- Icon drawing\
- \
- \
- function formatPinPath(path)\
- \009local npath = NovaAPI.newpath(path)\
- local pathtbl={}\
- for str in string.gmatch(path, \"([^/]+)\") do\
- pathtbl[#pathtbl+1] = str \
- end\
- fname = pathtbl[#pathtbl]\
- npath:goback(1)\
- \
- \009if(path:sub(1,1) == \"/\" and #npath:getraw() > 1)then path = path:sub(2,#path) end \
- \009if(#npath:getraw() <= 1)then path = \"/\" .. fname end\
- \009return path\
- end\
- \
- function novaex_redraw()\
- \009undrawFiles()\
- \009getfiles()\
- \009drawMain()\
- \009drawFiles()\
- end\
- \
- function moveSideItem(id,to)\
- \009local moveitem = sideitems[id]\
- \009local toitem = sideitems[id+to]\
- \
- \009sideitems[id+to] = moveitem\
- \009sideitems[id] = toitem\
- \009selectedside = selectedside + to\
- \009drawSideBar()\
- end\
- function deleteFile(file)\
- \009file_selected = 0\
- \009fs.delete(file)\
- \009undrawFiles()\
- \009getfiles()\
- \009drawFiles()\
- end\
- function newFileFolder(forf,path,file)\
- \009if(file == \"\" or file:find(\" \"))then return false end\
- \009if(not fs.exists(path .. file))then\
- \009\009if(forf == \"folder\")then\
- \009\009\009if(file:sub(1,4) == \"disk\")then\
- \009\009\009\009NovaAPI.notify(\"Creation Error.\",\"Cannot create disk directory!\",novaex_redraw)\
- \009\009\009\009return false\
- \009\009\009end\
- \009\009\009fs.makeDir(path .. file)\
- \009\009elseif(forf == \"file\")then\
- \009\009\009local f = fs.open(path .. file,\"w\")\
- \009\009\009f.write(\"\")\
- \009\009\009f.close()\
- \009\009end\
- \009\009getfiles()\
- \009\009drawFiles()\
- \009else\
- \009\009NovaAPI.notify(\"Creation Error.\",\"File or folder already exists.\",novaex_redraw)\
- \009end\
- end\
- function drawPathSearch()\
- \009sbc(colors.white)\
- \009writexy(string.rep(\" \",w-24),12,2)\
- \009sbc(colors.white)\
- \009stc(colors.black)\
- \009scp(13,2)\
- \009if(#path:getraw() > 25)then\
- \009\009local dif = #path:getraw() - 25\
- \009\009write(pathsearch:sub(dif,#path:getraw()))\
- \009else\
- \009\009write(pathsearch)\
- \009end\
- end\
- \
- function renameSideItem(id,nname)\
- if(nname ~= \"\")then\
- \009 nname = icons[sideitems[id].t] .. \"&r \" .. nname\
- \009 sideitems[id].n = nname\
- \009 saveConfigPinnedItems()\
- end\
- drawSideBar()\
- end\
- function getSideItemType(id)\
- \009return sideitems[id].t\
- end\
- function getSideItem(id)\
- \009return sideitems[id]\
- end\
- function addPinnedFile(name,type,link)\
- \009sideitems[#sideitems+1] = {n=name,t=type,href=formatPinPath(link)}\
- \009pinnednames[formatPinPath(link)] = true\
- \009saveConfigPinnedItems()\
- \009drawFiles()\
- \009drawSideBar()\
- end\
- function setClipboard(p,n,t)\
- \009clipboard = {path=p,name=n,type=t}\
- \009if(t == \"cut\")then\
- \009\009drawFiles()\
- \009end\
- end\
- function getSelectedSideItem()\
- \009return sideitems[selectedside]\
- end\
- function getSelectedSide()\
- \009return selectedside\
- end\
- function getSideAmmount()\
- \009return #sideitems\
- end\
- function getSelectedFile()\
- \009return file_selected\
- end\
- function getnamedpins()\
- \009return pinnednames\
- end\
- function getClipboard()\
- \009return clipboard\
- end\
- function removePinnedFile(link)\
- \009for i = 8, #sideitems do\
- \009\009if(sideitems[i].href == formatPinPath(link))then\
- \009\009\009table.remove(sideitems,i)\
- \009\009\009getPinnedNames()\
- \009\009\009saveConfigPinnedItems()\
- \009\009\009break\
- \009\009end\
- \009end\
- \009selectedside = 0\
- \009drawFiles()\
- \009drawSideBar()\
- end\
- function getPinnedNames()\
- \009pinnednames = {}\
- \009for i = 1, #sideitems do\
- \009\009if(sideitems[i].t ~= \"text\")then\
- \009\009\009pinnednames[sideitems[i].href] = true\
- \009\009end\
- \009end\
- end\
- \
- --]] Get files in directory\
- \
- function getfiles()\
- \009files = {}\
- \009local folders = {}\
- \009for k , v in pairs(fs.list(path:getraw())) do\
- \009\009if(fs.isDir(path:getraw() .. v) and (path:getraw() .. v):find(search) )then\
- \009\009\009local spt = 'folder'\
- \009\009\009if(v:sub(1,4) == \"disk\")then \
- \009\009\009\009if(#v > 4)then\
- \009\009\009\009\009if(tonumber(v:sub(5,#v)) ~= nil)then\
- \009\009\009\009\009\009spt = \"disk\"\
- \009\009\009\009\009end\
- \009\009\009\009else\
- \009\009\009\009\009spt = \"disk\" \
- \009\009\009\009end\
- \009\009\009end\
- \009\009\009folders[#folders+1] = {n=v,t=spt}\
- \009\009else if( v:find(search) )then\
- \009\009\009local nt = 'file'\
- \009\009\009if(v:sub(#v-3,#v) == '.zip')then nt = 'zip' end\
- \009\009\009if(v:sub(#v-3,#v) == '.exe')then nt = 'exe' end\
- \009\009\009if(path:getraw():find(\"CrossBow/games\") or \
- \009\009\009\009path:getraw():find(\"rom/programs/fun\"))then nt = \"game\" end\
- \009\009\009if(path:getraw():find(\"CrossBow/programs\"))then nt = \"executable\" end\
- \009\009\009if(NovaAPI.isFileImage(path:getraw() .. v))then nt = \"paint\" end\
- \009\009\009files[#files+1] = {n=v,t=nt}\
- \009\009end\
- \009\009end\
- \009end\
- \009-- Sort folders before files\
- \009for k,v in pairs(files) do \
- \009\009table.insert(folders, v) \
- \009end\
- \009files = folders\
- end\
- \
- --]] Draw program layout\
- function drawSideBar()\
- \009term.current().setVisible(false)\
- \009sbc(colors.white)\
- \009pa.drawFilledBox(0,4,17,h,colors.white)\
- \009sbc(1,1)\
- \009local loopam = #sideitems\
- \009if(#sideitems > h-5)then\
- \009\009loopam = (h-5)+sideoffs\
- \009end\
- \009for i = 1+sideoffs, loopam do\
- \009\009if(i-sideoffs < sidemax)then\
- \009\009\009if(sideitems[i] ~= nil)then\
- \009\009\009\009scp(1,(i-sideoffs)+4)\
- \009\009\009\009write(string.rep(\" \",16))\
- \009\009\009\009if(selectedside == i)then\
- \009\009\009\009\009sbc(colors.lightGray)\
- \009\009\009\009else\
- \009\009\009\009\009sbc(colors.white)\
- \009\009\009\009end\
- \009\009\009\009NovaAPI.colorwrite(sideitems[i].n,12,1,(i-sideoffs)+4)\
- \009\009\009end\
- \009\009end\
- \009end\
- \009pa.drawBox(17,4,17,h,colors.gray)\
- \009pa.drawBox(1,h,17,h,colors.gray)\
- \009pa.drawBox(16,4,16,h-1,colors.lightGray)\
- \009stc(colors.gray)\
- \009writexy(\"^\",16,4)\
- \009writexy(\"v\",16,h-1)\
- \009term.current().setVisible(true)\
- end\
- -- Deprecidated\
- function drawFile(ind)\
- \009 -- Draw selected files\
- \009term.current().setVisible(false)\
- \009sbc(colors.white)\
- \009stc(colors.black)\
- \009 if(ind <= filemax)then\
- \009 \009 scp(19,ind+fileoffs)\
- \009\009\009write(string.rep(\" \",30))\
- \009\009\009NovaAPI.colorwrite(icons[files[ind].t] .. \" &r\" .. files[ind].n ,12,19,ind,file_selected == ind)\
- \009\009\009scp(40,ind+fileoffs)\
- \009\009 if(not fs.isDir(path:getraw() .. files[ind].n))then\
- \009\009 \009write(tostring(fs.getSize(path:getraw() .. files[ind].n) / 1000):sub(1,4) .. \"KB\")\
- \009\009 end\
- \009 end\
- \009 term.current().setVisible(true)\
- \009 drawPathSearch()\
- end\
- function undrawFiles()\
- \009pa.drawFilledBox(18,4,w-1,h,colors.white)\
- end\
- function drawFilePath()\
- \009sbc(colors.white)\
- \009writexy(string.rep(\" \",w-24),12,2)\
- \009sbc(colors.white)\
- \009stc(colors.black)\
- \009scp(13,2)\
- \009if(#path:getraw() > 25)then\
- \009\009local dif = #path:getraw() - 25\
- \009\009write(path:getraw():sub(dif,#path:getraw()))\
- \009else\
- \009\009write(path:getraw())\
- \009end\
- \
- end\
- function drawFiles()\
- \009term.current().setVisible(false)\
- \009sbc(colors.white)\
- \009stc(colors.black)\
- \009drawFilePath()\
- \009 scp(23,4)\
- \009 stc(colors.lightGray)\
- \009 write(\"Name\")\
- \009 scp(40,4)\
- \009 write(\"Size\")\
- \009if(#files == 0)then\
- \009\009scp(25,5)\
- \009\009stc(colors.lightGray)\
- \009\009if(search ~= \"\")then\
- \009\009\009scp(20,5)\
- \009\009\009write(\"No items matched your search. \")\
- \009\009else\
- \009\009\009write(\"This folder is empty. \")\
- \009\009end\
- \009end\
- \009local loopam = #files\
- \009if(#files > h-4)then\
- \009\009loopam = (h-4)+fileoffs\
- \009end\
- \009 for i = 1+fileoffs, loopam do\
- \009 \009 if(i-fileoffs <= filemax)then\
- \009 \009 \009if(files[i].n ~= nil)then\
- \009 \009 \009 scp(19,(i-fileoffs)+4)\
- \009\009\009 write(string.rep(\" \",30))\
- \009\009\009 local namecolor = \" &r\"\
- \009\009\009 local drawname = files[i].n\
- \009\009\009 if(path:getraw() .. files[i].n == clipboard.path and clipboard.type == \"cut\")then\
- \009\009\009 \009namecolor = \" &7\"\
- \009\009\009end\
- \009\009\009 if(isPinnedItem(path:getraw() .. files[i].n))then \
- \009\009\009 \009 namecolor = \" &b\"\
- \009\009\009 \009if(path:getraw() .. files[i].n == clipboard.path and clipboard.type == \"cut\")then\
- \009\009\009 \009 \009namecolor = \" &e\"\
- \009\009\009 \009end\
- \009\009\009 end\
- \009\009\009 local selected = (file_selected == i)\
- \009\009\009 if(multiselecting)then\
- \009\009\009 \009for s = 1, #files_selected do\
- \009\009\009 \009\009if(files_selected[s].n == files[i].n and \
- \009\009\009 \009\009\009path:getraw() == files_selected[s].p)then\
- \009\009\009 \009\009\009if(clipboard.type == \"cut\")then\
- \009\009\009 \009\009\009\009namecolor = \" &7\"\
- \009\009\009 \009\009\009\009if(isPinnedItem(path:getraw() .. files[i].n))then \
- \009\009\009 \009\009\009\009\009namecolor = \" &e\"\
- \009\009\009 \009\009\009\009end\
- \009\009\009 \009\009\009end\
- \009\009\009 \009\009\009selected = true\
- \009\009\009 \009\009end\
- \009\009\009 \009end\
- \009\009\009 end\
- \
- \009\009\009 local bcol = colors.white\
- \009\009\009 if(selected)then bcol = colors.lightBlue end\
- \009\009\009 NovaAPI.colorwrite(icons[files[i].t] .. namecolor .. drawname ..\"&r\",12,19,(i-fileoffs)+4,bcol)\
- \009\009\009 if(search ~= \"\" )then\
- \009\009\009 \009local foundletters = \"\"\
- \009\009\009 \009 for x = 1, #files[i].n do\
- \009\009\009 \009 \009 if(search:find(files[i].n:sub(x,x)) and not foundletters:find(files[i].n:sub(x,x)) )then\
- \009\009\009 \009 \009 \009 foundletters = foundletters .. files[i].n:sub(x,x)\
- \009\009\009 \009 \009 \009 scp( (22)+x, (i-fileoffs)+4) -- hardcoded for 3 wide icons\
- \009\009\009 \009 \009 \009 sbc(colors.yellow)\
- \009\009\009 \009 \009 \009 write(files[i].n:sub(x,x))\
- \009\009\009 \009 \009 \009 sbc(colors.white)\
- \009\009\009 \009 \009 end\
- \009\009\009 \009 end\
- \009\009\009 end\
- \009\009\009 scp(40,(i-fileoffs)+4)\
- \009\009\009 if(not fs.isDir(path:getraw() .. files[i].n))then\
- \009\009\009 \009write(tostring(fs.getSize(path:getraw() .. files[i].n) / 1000):sub(1,4) .. \"KB\")\
- \009\009\009 end\
- \009 \009 end\
- \009 \009 end\
- \009 end \
- \009 term.current().setVisible(true)\
- end\
- function renameFile(path,name,nname)\
- \009local odir = shell.dir()\
- \009shell.setDir(\"\")\
- \009if(not fs.exists(path .. nname) and nname ~= \"\" and not nname:find(\" \"))then\
- \009\009if(nname:sub(1,4) == \"disk\" and fs.isDir(path .. name))then\
- \009\009\009shell.setDir(odir)\
- \009\009\009NovaAPI.notify(\"Rename Error.\",\"Cannot rename directory to * disk!\",novaex_redraw)\
- \009\009\009return false\
- \009\009end\
- \009\009fs.move(path .. name, path .. nname)\
- \009\009getfiles()\
- \009elseif(nname ~= \"\" and not nname:find(\" \"))then\
- \009\009NovaAPI.notify(\"Couldn't rename file.\",\"File with name: * \".. nname .. \", already exists.\",novaex_redraw)\
- \009end\
- \009drawFiles()\
- \009shell.setDir(odir)\
- end\
- function runFile(fpath,args,noclick)\
- \009local odir = shell.dir()\
- \009sbc(colors.black)\
- \009stc(colors.white)\
- \009clr()\
- \009scp(1,1)\
- \009shell.setDir(\"\")\
- \009if(NovaAPI.isFileImage(fpath))then \
- \009\009args = fpath\
- \009\009fpath = \"paint\"\
- \009\009noclick = true\
- \009end\
- \009if(shell.resolveProgram(fpath))then\
- \009\009if(fs.exists(shell.resolveProgram(fpath)))then \
- \009\009\009shell.run(fpath,args)\
- \009\009\009if(not noclick)then\
- \009\009\009\009writecy(\"Click any where to return to NovaBrowse. \",9)\
- \009\009\009\009os.pullEvent(\"mouse_click\")\
- \009\009\009end\
- \009\009else\
- \009\009\009NovaAPI.notify(\"Open file.\", \"&4File not found. \",novaex_redraw)\
- \009\009end\
- \009end\
- \009search = \"\"\
- \009shell.setDir(odir)\
- \009drawMain()\
- \009getfiles()\
- \009drawFiles()\
- \009drawPathSearch()\
- end\
- function setDir(name)\
- \009if(fs.isDir(name))then\
- \009\009clearSearch()\
- \009\009file_selected = 0\
- \009\009if(name:sub(#name,#name) ~= \"/\")then name = name .. \"/\" end\
- \009\009fileoffs = 0\
- \009\009path:set(name)\
- \009\009getfiles()\
- \009\009undrawFiles()\
- \009\009drawFiles()\
- \009\009return true\
- \009else\
- \009\009drawFilePath()\
- \009\009return false\
- \009end\
- \009NovaAPI.setInput(path:getraw())\
- \009pathsearch = path:getraw()\
- end\
- function addDir(name)\
- \009selectedside = 0\
- \009drawSideBar() \
- \009clearSearch()\
- \009file_selected = 0\
- \009fileoffs = 0\
- \009path:add(name)\
- \009getfiles()\
- \009undrawFiles()\
- \009drawFiles()\
- \009NovaAPI.setInput(path:getraw())\
- \009pathsearch = path:getraw()\
- end\
- function clearSearch()\
- \009search = \"\"\
- \009scp(40,2)\
- \009sbc(colors.lightGray)\
- \009write(string.rep(\" \",11))\
- end\
- function searchDir(val)\
- \009file_selected = 0\
- \009fileoffs = 0\
- \009local nfiles = {}\
- \009undrawFiles()\
- \009if(val == \"\" or val == \" \")then\
- \009\009getfiles()\
- \009else\
- \009\009--for i = 1, #files do\
- \009\009--\009if(files[i])then\
- \009\009--\009\009if(not files[i].n:find(val))then\
- \009\009\009--\009\009table.remove(files,i)\
- \009\009--\009\009end\
- \009\009--\009end\
- \009--\009end\
- \009\009--files = nfiles\
- \009end\
- \009drawFiles()\
- end\
- function openHref(href)\
- if(fs.isDir(href))then\
- \009setDir(href)\
- elseif(fs.exists(href))then\
- \009return runFile(href)\
- end\
- end\
- function editfile(filepath)\
- \009runFile(\"edit\",filepath,true)\
- end\
- function pasteMultiFile(to)\
- \009if(multiselecting)then\
- \009\009for i = 1, #files_selected do\
- \009\009\009clipboard.path = files_selected[i].p .. files_selected[i].n\
- \009\009\009clipboard.name = files_selected[i].n\
- \009\009\009pasteFile(to)\
- \009\009end\
- \009end\
- end\
- function pasteFile(to)\
- \009local odir = shell.dir()\
- \009if(fs.isReadOnly(to))then\
- \009\009NovaAPI.notify(\"Paste file \", \"Access Denied. \",novaex_redraw)\
- \009\009return\
- \009end\
- \009if(not fs.exists(to .. clipboard.name))then\
- \009\009fs.copy(clipboard.path,path:getraw() .. clipboard.name)\
- \009\009if(clipboard.type == \"cut\")then fs.delete(clipboard.path) clipboard = {} end\
- \009\009getfiles()\
- \009\009drawFiles()\
- \009else\
- \009\009if(to .. clipboard.name == clipboard.path)then\
- \009\009\009clipboard = {}\
- \009\009\009drawFiles()\
- \009\009\009return\
- \009\009end\
- \009\009local ans = NovaAPI.openYesNo(\"File transfer\",\"File exists, Rename file? \",novaex_redraw)\
- \009\009if(ans == 1)then\
- \009\009\009local newname = NovaAPI.openReadDialog(\"Rename paste file. \",novaex_redraw,clipboard.name)\
- \009\009\009if(newname:find(\" \"))then\
- \009\009\009\009NovaAPI.notify(\"File rename \", \"Invalid file name. \",novaex_redraw)\
- \009\009\009else\
- \009\009\009\009clipboard.name = newname\
- \009\009\009end\
- \009\009\009return pasteFile(to)\
- \009\009end\
- \009end\
- \
- \009shell.setDir(odir)\
- end\
- function prevDir(ind) \
- \009selectedside = 0 \
- \009drawSideBar()\
- \009scp(2,2)\
- \009sbc(colors.gray)\
- \009stc(colors.black)\
- \009write(\"<-\")\
- \009sleep(0.1)\
- \009scp(2,2)\
- \009sbc(colors.lightGray)\
- \009stc(colors.gray)\
- \009write(\"<-\")\
- \009clearSearch()\
- \009file_selected = 0\
- \009fileoffs = 0\
- \009path:goback(ind)\
- \009getfiles()\
- \009undrawFiles()\
- \009drawFiles()\009\
- \009NovaAPI.setInput(path:getraw())\
- \009pathsearch = path:getraw()\
- end\
- function refreshDir()\
- \009scp(6,2)\
- \009sbc(colors.gray)\
- \009stc(colors.black)\
- \009write(\"<>\")\
- \009sleep(0.1)\
- \009scp(6,2)\
- \009sbc(colors.lightGray)\
- \009stc(colors.gray)\
- \009write(\"<>\")\
- \009clearSearch()\
- \009file_selected = 0\
- \009fileoffs = 0\
- \009drawMain()\
- \009getConfigPinnedItems()\
- \009getPinnedNames()\
- \009drawSideBar()\
- \009getfiles()\
- \009drawFiles()\
- \009checkUpdate()\
- \009NovaAPI.setInput(path:getraw())\
- \009pathsearch = path:getraw()\
- end\
- function drawfilemenu(menu,sx,sy)\
- \009local finalmenu = {}\
- \009for i = 1, #menu do\
- \009\009if(menu[i].relies == nil)then\
- \009\009\009finalmenu[#finalmenu+1] = menu[i]\
- \009\009elseif(menu[i].relies(files[file_selected],pinnednames))then\
- \009\009\009finalmenu[#finalmenu+1] = menu[i]\
- \009\009end\
- \009end\
- \009if(sy+#finalmenu > h)then\
- \009\009sy = sy - ((sy+#finalmenu)-h)\
- \009end\
- \009if(sx+#finalmenu[1].n >= w-1)then\
- \009\009sx = sx - ((sx+#finalmenu[1].n)-(w-1))\
- \009end\
- \009pa.drawBox(sx,sy+2,sx+#finalmenu[1].n,sy+#finalmenu+1,colors.black)\
- \009for i = 1, #finalmenu do\
- \009\009if(sy+i <= h)then\
- \009\009\009scp(sx-1,sy+i)\
- \009\009\009sbc(colors.lightGray)\
- \009\009\009stc(colors.white)\
- \009\009\009write(string.rep(\" \",#finalmenu[i].n+1))\
- \009\009\009scp(sx,sy+i)\
- \009\009\009write(finalmenu[i].n)\
- \009\009end\
- \009end\
- \009return finalmenu, sx, sy\
- end\
- function drawMenuClick(mop)\
- \009local _, dny = term.getCursorPos()\
- \009local dnx = inmenux+1\
- \009sbc(colors.gray)\
- \009stc(colors.black)\
- \009write(mop.n)\
- \009sleep(0.2)\
- \009scp(dnx,dny)\
- \009sbc(colors.lightGray)\
- \009stc(colors.white)\
- \009write(mop.n)\
- end\
- function updatemenu(e,menu,sx,sy,clrfunc)\
- \009if(e[1] == \"mouse_click\")then\
- \009\009local x, y = e[3], e[4]\
- \009\009local mlen = #menu[1].n-1\
- \009\009if(x >= sx and x <= sx+mlen and y >= sy+1 and y <= sy+#menu)then\
- \009\009\009 local clicked = menu[(y-sy)]\
- \009\009\009 scp(sx,y)\
- \009\009\009 drawMenuClick(clicked)\
- \009\009\009 clrfunc()\
- \009\009\009 e[1] = nil\
- \009\009\009 inmenu = false\
- \009\009\009 return clicked.func(files[file_selected])\
- \009\009else\
- \009\009\009clrfunc()\
- \009\009\009inmenu = false\
- \009\009end\
- \009end\
- end\
- function opencloseMenu(type,x,y,yind)\
- \009if(inmenu)then\
- \009\009undrawFiles()\
- \009\009drawFiles()\
- \009\009drawSideBar()\
- \009\009inmenu = false\
- \009elseif(type==\"reg\")then\
- \009\009local mtodraw = filemenu\
- \009\009if(fs.isDir(path:getraw() .. files[file_selected].n))then\
- \009\009\009mtodraw = foldermenu\
- \009\009end\
- \009\009drawingmenu = mtodraw\
- \009\009inmenutype, inmenux, inmenuy = drawfilemenu(mtodraw,x,y)\
- \009\009inmenu = true\
- \009elseif(type==\"sidebar\")then\
- \009\009drawingmenu = sidemenu\
- \009\009inmenutype, _, inmenuy = drawfilemenu(sidemenu,5,y)\
- \009\009inmenux = 5\
- \009\009inmenu = true\
- \009elseif(type==\"new\" and not fs.isReadOnly(path:getraw()) )then\
- \009\009drawingmenu = emptymenu\
- \009\009inmenutype,inmenux,inmenuy = drawfilemenu(emptymenu,x,y)\
- \009\009inmenu = true\
- \009end\
- end\
- local function update(e)\
- \009if(inmenu)then\
- \009\009updatemenu(e,inmenutype,inmenux,inmenuy,novaex_redraw)\
- \009end\
- \
- \009if(e[1] == \"disk\")then\
- \009\009getfiles()\
- \009\009drawFiles()\
- \009\009diskside = e[2]\
- \009\009if(fs.exists(\"disk/autorun\"))then\
- \009\009\009local ans = NovaAPI.openYesNo(\"Disk detected \",\"A software disk has been * detected. \",novaex_redraw,\"Run\",\"Cancel\")\
- \009\009\009if(ans == 1)then\
- \009\009\009\009runFile(\"disk/autorun\")\
- \009\009\009end\
- \009\009elseif(disk.hasAudio(e[2]))then\
- \009\009\009local ans = NovaAPI.openYesNo(\"Music detected \",\"A music disk has been * inserted. \",novaex_redraw,\"Play\",\"Cancel\")\
- \009\009\009if(ans == 1)then\
- \009\009\009\009disk.playAudio(e[2])\
- \009\009\009end\
- \009\009else\
- \009\009\009local ans = NovaAPI.openYesNo(\"Disk detected \",\"A floppy disk has been * inserted. \",novaex_redraw,\"Open\",\"Cancel\")\
- \009\009\009if(ans == 1)then\
- \009\009\009\009setDir(\"disk/\")\
- \009\009\009end\
- \009\009end\
- \009elseif(e[1] == \"disk_eject\")then\
- \009\009if(path:getraw():find(\"disk/\"))then\
- \009\009\009path:set(\"/\")\
- \009\009end\
- \009\009undrawFiles()\
- \009\009getfiles()\
- \009\009drawFiles()\
- \009end\
- \009if(e[1] == \"paste\")then\
- \009\009if(clipboard.name ~= nil)then\
- \009\009\009if(multiselecting)then\
- \009\009\009\009pasteMultiFile(path:getraw())\
- \009\009\009else\
- \009\009\009\009pasteFile(path:getraw())\
- \009\009\009end\
- \009\009end\
- \009end\
- \009if(e[1] == \"key\")then\
- \009\009local key = e[2] \
- \009\009if(key == actionkey and not actionkeydown)then\
- \009\009\009actionkeydown = true\
- \009\009elseif(actionkeydown)then\
- \009\009\009local opper = \"copy\"\
- \009\009\009if(key == keys.c or key == keys.x)then\
- \009\009\009\009if(key == keys.x)then opper = \"cut\" end\
- \009\009\009\009if(file_selected ~= 0)then\
- \009\009\009\009\009setClipboard(path:getraw() .. files[file_selected].n, \
- \009\009\009\009\009files[file_selected].n, opper)\
- \009\009\009\009end\
- \009\009\009end\
- \009\009end\
- \009\009if(file_selected > 0)then\
- \009\009\009if(key == keys.delete)then\
- \009\009 \009\009local ans = NovaAPI.openYesNo(\"File deletion. \",\"Confirm &4deletion&r of *\" .. files[file_selected].n,novaex_redraw)\
- \009\009 \009\009if(ans == 1)then\
- \009\009 \009\009\009deleteFile(path:getraw() .. files[file_selected].n)\
- \009\009 \009\009end\
- \009\009\009end\
- \009\009end\
- \009\009if(selectedside > 0)then\
- \009\009\009if(key == keys.up and sideitems[selectedside-1].t ~= nil and \
- \009 \009\009 sideitems[selectedside-1].t ~= \"text\" )then\
- \009\009\009\009moveSideItem(selectedside,-1)\
- \009\009\009elseif(key == keys.down and (selectedside < #sideitems) and \
- \009 \009\009 (sideitems[selectedside+1].n ~= nil) and \
- \009 \009\009 sideitems[selectedside+1].t ~= \"text\" )then\
- \009\009\009\009moveSideItem(selectedside,1)\
- \009\009\009end\
- \009\009end\
- \009elseif(e[1] == \"key_up\")then\
- \009\009\009local key = e[2] \
- \009\009if(key == actionkey and actionkeydown )then\
- \009\009\009actionkeydown = false\
- \009\009end\
- \009end\
- \009if(e[1] == \"mouse_click\")then\
- \009\009 local x,y = e[3], e[4] \
- \009\009 -- Left clicked\
- \009\009if(e[2] == 1)then\
- \009\009\009if(x == w and y == 1)then\
- \009\009\009\009clickExit()\
- \009\009\009\009innova = false\
- \009\009\009\009sbc(colors.white)\
- \009\009\009\009clr()\
- \009\009\009\009stc(colors.gray)\
- \009\009\009\009writecy(\"Thank you for using Nova Explore. \",9)\
- \009\009\009\009writecy(\"Click the screen to exit. \",10)\
- \009\009\009\009os.pullEvent(\"mouse_click\")\
- \009\009\009\009sbc(colors.black)\
- \009\009\009\009clr()\
- \009\009\009\009stc(colors.white)\
- \009\009\009\009scp(1,1)\
- \009\009\009\009return \
- \009\009\009end\
- \009\009\009if(x >= 11 and x <= 36 and y == 2)then\
- \009\009\009\009NovaAPI.setInput(pathsearch)\
- \009\009\009end\
- \009\009 \009if(x >= 38 and x <= 51 and y == 2)then\
- \009\009 \009\009NovaAPI.setInput(search)\
- \009\009 \009\009searching = true\
- \009\009 \009elseif(searching)then\
- \009\009 \009\009search = NovaAPI.getInput()\
- \009\009 \009\009searching = false\
- \009\009 \009end\
- \009\009 \009if(x >= 2 and x <= 4 and y == 2)then\
- \009\009 \009\009if(inmenu)then inmenu = false end\
- \009\009 \009\009prevDir(1)\
- \009\009 \009end\
- \009\009 \009if(x >= 6 and x <= 8 and y == 2)then\
- \009\009 \009\009refreshDir()\
- \009\009 \009end\
- \009\009end \
- \009\009-- Left or right clicked\
- \009\009 \009local yind = (y+fileoffs)-4\
- \009\009 \009local syind = (y+sideoffs)-4\
- \009\009 \009if(x < 18 and syind <= #sideitems and syind > 0)then\
- \009\009\009 \009 if(y > 4 and x >= 1 and x <= #(sideitems[syind].n:sub(1,14)) )then\
- \009\009\009 \009 if(e[2] == 1 and not inmenu and sideitems[syind].t ~= \"text\")then\
- \009\009\009\009 \009 \009if(fs.isDir(sideitems[syind].href))then\
- \009\009\009\009 \009 \009 selectedside = syind\
- \009\009\009\009 \009 \009 \009openHref(sideitems[syind].href)\
- \009\009\009\009 \009 \009 \009drawSideBar()\
- \009\009\009\009 \009 \009elseif(sideitems[syind].t ~= \"text\")then\
- \009\009\009\009 \009 \009 \009if(selectedside == syind)then\
- \009\009\009\009 \009 \009 \009 \009openHref(sideitems[syind].href)\
- \009\009\009\009 \009 \009 \009else\
- \009\009\009\009 \009 \009 \009 selectedside = syind\
- \009\009\009\009 \009 \009 \009 \009drawSideBar()\
- \009\009\009\009 \009 \009 \009end\
- \009\009\009\009 \009 \009end\
- \009\009\009\009 elseif(e[2] == 2)then\
- \009\009\009\009 \009\009if(selectedside ~= 0 and sideitems[syind].t ~= \"text\" and yind == selectedside)then\
- \009\009\009\009 \009 \009\009opencloseMenu(\"sidebar\",x,y)\009\
- \009\009\009\009 \009 \009end\
- \009\009\009 \009 end\
- \009\009\009 \009 end\
- \009\009\009 elseif(yind <= #files and yind > 0)then\
- \009\009 \009 \009if(y > 4 and x >= 18 and x <= 22+#files[yind].n)then\
- \009\009 \009 \009 if(e[2] == 1 and not inmenu)then\
- \009\009\009 \009 \009 if(file_selected == yind)then\
- \009\009\009\009 \009 \009 \009if(fs.isDir(path:getraw() .. files[file_selected].n))then\
- \009\009\009\009 \009 \009 \009\009if(inmenu)then inmenu = false end\
- \009\009\009\009 \009 \009 \009 \009addDir(files[yind].n)\
- \009\009\009\009 \009 \009 \009 else\
- \009\009\009\009 \009 \009 \009 \009runFile(path:getraw() .. files[file_selected].n)\
- \009\009\009\009 \009 \009 \009end\
- \009\009\009\009 \009 \009 else\
- \009\009\009\009 \009 \009 \009 file_selected = yind\
- \009\009\009\009 \009 \009 \009 drawFiles()\
- \009\009\009\009 \009 \009 \009 drawPathSearch()\
- \009\009\009\009 \009 \009 end\
- \009\009\009 \009 elseif(e[2] == 2 )then\
- \009\009\009 \009 \009 if(file_selected == yind)then\
- \009\009\009 \009 \009 \009\009opencloseMenu(\"reg\",x,y,yind)\
- \009\009\009 \009 \009 else\
- \009\009\009 \009 \009 \009\009opencloseMenu(\"new\",x,y,yind)\
- \009\009\009\009\009 end\
- \009\009\009\009end\
- \009\009 end\
- \009\009end\
- \009\009if(e[2] == 2 and not inmenu and x > 18)then\
- \009\009 \009opencloseMenu(\"new\",x,y,1)\
- \009\009end\
- \009end\
- \009if(e[1] == \"mouse_scroll\")then\
- \009\009NovaAPI.setActive(false)\
- \009\009local dir = e[2]\
- \009\009local x,y = e[3], e[4]\
- \009\009if(dir == -1)then\
- \009\009\009if(x > 16 and fileoffs > 0 )then\
- \009\009\009\009fileoffs = fileoffs - 1\
- \009\009\009\009drawFiles()\
- \009\009\009elseif(x <= 16 and sideoffs > 0)then\
- \009\009\009\009sideoffs = sideoffs - 1\
- \009\009\009\009drawSideBar()\
- \009\009\009end\
- \009\009elseif(dir == 1)then\
- \009\009\009if(x > 16 and fileoffs < #files-(filemax-4))then\
- \009\009\009\009fileoffs = fileoffs + 1\
- \009\009\009\009drawFiles()\
- \009\009\009elseif(x <= 16 and sideoffs < #sideitems-(sidemax-4))then\
- \009\009\009\009sideoffs = sideoffs + 1\
- \009\009\009\009drawSideBar()\
- \009\009\009end\
- \009\009end\
- \009end\
- \009if(pathsearch ~= \"\")then\
- \009\009if(NovaAPI.getActive() == false)then\
- \009\009\009drawPathSearch()\
- \009\009end\
- \009\009if(NovaAPI.getActive() == false and not searching)then\
- \009\009\009if(NovaAPI.getInput() ~= pathsearch)then\
- \009\009\009\009pathsearch = NovaAPI.getInput()\
- \009\009\009\009NovaAPI.setInput(pathsearch) \
- \009\009\009end\
- \009\009end\
- \009end\
- \
- \009\009-- Searching files/commands\
- \
- \009if(not searching)then\
- \009\009stc(colors.black)\
- \009\009sbc(colors.white)\
- \009\009local doneinp = NovaAPI.novaread(e,1000,25,13,2)\
- \009\009if(doneinp)then\
- \009 \009NovaAPI.setActive(false)\
- \009 \009term.setCursorBlink(false)\
- \009 \009pathsearch = NovaAPI.getInput()\
- \009 \009if( fs.isDir(NovaAPI.getInput()) )then\
- \009\009\009\009if( setDir(NovaAPI.getInput()) )then\
- \009\009\009\009\009selectedside = 0\
- \009\009\009\009\009drawSideBar()\
- \009\009\009\009end\
- \009\009\009else\
- \009\009\009\009--if(fs.exists(pathsearch))then\
- \009\009\009\009\009term.setBackgroundColor(colors.black)\
- \009\009\009\009\009term.setTextColor(colors.white)\
- \009\009\009\009\009term.clear()\
- \009\009\009\009\009term.setCursorPos(1, 1)\
- \009\009\009\009\009shell.run(pathsearch)\
- \009\009\009\009\009NovaAPI.setInput(pathsearch)\
- \009\009\009\009\009writecy(\"Click any where to return to NovaBrowse. \",9)\
- \009\009\009\009\009os.pullEvent(\"mouse_click\") \
- \009\009\009\009\009NovaAPI.setInput(pathsearch)\
- \009\009\009\009\009drawMain()\
- \009\009\009\009\009getfiles()\
- \009\009\009\009\009drawFiles()\
- \009\009\009\009--end\
- \009\
- \009\009\009end\
- \009\009end\
- \009else\
- \009\009stc(colors.black)\
- \009\009sbc(colors.lightGray)\
- \009\009local doneinp = NovaAPI.novaread(e,1000,10,40,2)\
- \009\009if(doneinp)then\
- \009\009\009searching = false\
- \009 \009NovaAPI.setActive(false)\
- \009 \009search = NovaAPI.getInput()\
- \009 \009--if(fs.isDir(NovaAPI.getInput()))then\
- \009 \009\009getfiles() -- to prevent \"nested\" searches.\
- \009\009\009\009searchDir(NovaAPI.getInput()) \
- \009\009\009\009--NovaAPI.setInput(\"\")\
- \009\009\009--end\
- \
- \009\009end\
- \009end\
- end\
- function displayError(err)\
- \009sbc(colors.white)\
- \009clr()\
- \009stc(colors.gray)\
- \009writecy(\" Well, thats not supposed to happen. \",1)\
- \009scp(2,3)\
- \009stc(colors.lightGray)\
- \009write(err)\
- \009writecy(\" Why you do dis to me :(. \",16)\
- \009stc(colors.black)\
- \009writecy(\" Press any key to end NovaExplore. \",17)\
- \009writecy(\" Click to restart NovaExplore. \",18)\
- \009local e = {os.pullEvent()}\
- \009if(e[1] == \"key\")then \
- \009\009sbc(colors.black)\
- \009\009clr()\
- \009\009stc(colors.white)\
- \009\009scp(1,1)\
- \009elseif(e[1] == \"mouse_click\")then\
- \009\009local odir = shell.dir()\
- \009\009shell.setDir(\"\")\
- \009\009shell.run(shell.resolveProgram(shell.getRunningProgram()))\
- \009\009shell.setDir(odir)\
- \009end\
- end\
- function clickExit()\
- \009scp(w,1)\
- \009stc(colors.black)\
- \009sbc(colors.pink)\
- \009write(\"X\")\
- \009sleep(0.2)\
- \009scp(w,1)\
- \009stc(colors.white)\
- \009sbc(colors.red)\
- \009write(\"X\")\
- end\
- function checkUpdate()\
- \009if(http)then\
- \009\009local upd = http.get(\"http://pastebin.com/raw/rpipr5pT\")\
- \009\009if(upd ~= nil)then\
- \009\009\009local cont = upd.readAll()\
- \009\009\009local f = fs.open(shell.getRunningProgram(),\"r\")\
- \009\009\009local pcont = f.readAll()\
- \009\009\009f.close()\
- \009\009\009if(cont ~= pcont)then\
- \009\009\009\009local ans = NovaAPI.openYesNo(\"Auto update\", \"Update detected, would you * like to update?.\",novaex_redraw)\
- \009\009\009\009if(ans == 1)then\
- \009\009\009\009\009local f = fs.open(shell.getRunningProgram(),\"w\")\
- \009\009\009\009\009f.write(cont)\
- \009\009\009\009\009f.close()\
- \009\009\009\009\009NovaAPI.notify(\"Auto update\", \"Updated, restart required.\",novaex_redraw)\
- \009\009\009\009\009innova = false\
- \009\009\009\009\009return shell.run(shell.resolveProgram(shell.getRunningProgram()))\
- \009\009\009\009end\
- \009\009\009end\
- \009\009else\
- \009\009\009NovaAPI.notify(\"Auto update\", \"Failed to connect to pastebin.\",novaex_redraw)\
- \009\009end\
- \009else\
- \009\009NovaAPI.notify(\"Auto update\", \"Http is disabled, Failed to * check for updates.\",novaex_redraw)\
- \009\009return\
- \009end\
- end\
- function drawMain()\
- \009sbc(colors.white)\
- \009clr()\
- \009scp(1,2)\
- \009sbc(colors.lightGray)\
- \009clrln()\
- \009pa.drawBox(w-12,1,w,3,colors.gray)\
- \009sbc(colors.white)\
- \009writexy(string.rep(\" \",w-12),1,2)\
- \009pa.drawBox(10,1,w-12,3,colors.gray)\
- \009drawSideBar()\
- \009pa.drawFilledBox(1,1,9,3,colors.lightGray)\
- \009scp(2,2)\
- \009stc(colors.gray)\
- \009write(\"<- <>\")\
- \009--pa.drawBox(15,h,w,h,colors.lightGray)\
- \009pa.drawBox(w,4,w,h,colors.lightGray)\
- \009stc(colors.gray)\
- \009writexy(\"^\",w,4)\
- \009writexy(\"v\",w,h)\
- \009scp(w,1)\
- \009stc(colors.white)\
- \009sbc(colors.red)\
- \009write(\"X\")\
- \009sbc(colors.black)\
- end\
- drawMain()\
- getConfigPinnedItems()\
- getPinnedNames()\
- drawSideBar()\
- getfiles()\
- drawFiles()\
- checkUpdate()\
- \
- local function loop()\
- \009while innova do \
- \009\009local e = {os.pullEvent()}\
- \009\009update(e)\
- \009end\
- end\
- local ok, err = pcall(loop)\
- if(not ok)then\
- \009if(term.current().setVisible)then\
- \009\009term.current().setVisible(true)\
- \009end\
- \009displayError(err)\
- end",
- },
- [ "NovaAPI/" ] = {
- content = "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 shell = {}\
- local str = \"\"\
- local active = true\
- local inputindex = #str\
- local cursorX = #str\
- local viewX = 1\
- \
- local function path_goback(path,amm)\
- pathtbl={}\
- s=\"\"\
- pathsize=0\
- -- Divide string and count the number of \
- -- divisions.\
- for str in string.gmatch(path, \"([^/]+)\") do\
- pathtbl[#pathtbl+1] = str \
- end\
- for k, v in pairs(pathtbl) do\
- pathsize=k\
- end\
- pathsize = pathsize - amm\
- -- Split string into words based on seperator.\
- pathtbl={}\
- for str in string.gmatch(path, \"([^/]+)\") do\
- pathtbl[#pathtbl+1] = str \
- end\
- -- Based on how large the user wants the string to be \
- -- add only the string bits that led up to the user defined\
- -- size.\
- for k, v in pairs(pathtbl) do\
- if(k <= pathsize)then s = s..pathtbl[k]..\"/\" end\
- end\
- return s\
- end\
- local function path_getsize(path)\
- pathtbl={}\
- pathsize=0\
- -- Divide string and count the number of \
- -- divisions.\
- for str in string.gmatch(path, \"([^/]+)\") do\
- pathtbl[#pathtbl+1] = str \
- end\
- for k, v in pairs(pathtbl) do\
- pathsize=k\
- end\
- return pathsize\
- end\
- \
- function newpath(name,stuckindex)\
- if(name == nil or type(name) ~= \"string\")then error(\"PathAPI: Name must be provided for new paths. \") end\
- if(string.sub(name,#name,#name) ~= \"/\")then\
- name = name .. \"/\"\
- end\
- if(type(stuckindex) ~= \"number\")then stuckindex = 0 end\
- local pathobj = {\
- path = name,\
- stuckind = stuckindex,\
- getsize = function(self)\
- return path_getsize(self.path)\
- end,\
- goback = function(self,amm)\
- if(self:getsize() - amm >= self.stuckind)then\
- self.path = path_goback(self.path,amm)\
- return self.path\
- else\
- return false\
- end\
- end,\
- getraw = function(self)\
- return self.path\
- end,\
- add = function(self,new)\
- self.path = self.path .. new .. \"/\"\
- return self.path\
- end,\
- set = function(self,npath)\
- self.path = npath\
- return self.path\
- end,\
- lockpath = function(self)\
- self.stuckind = self:getsize()\
- end,\
- unlockpath = function(self)\
- self.stuckind = 0\
- end,\
- }\
- return pathobj\
- end\
- \
- ------------------------------------------------\
- --]] futils - API\
- ------------------------------------------------\
- \
- function file_readAll(file,s)\
- local f = fs.open(file,\"r\")\
- local cont = f.readAll()\
- f.close()\
- if(s)then return textutils.unserialize(s) end\
- return cont\
- end\
- function file_readLine(file,s)\
- local f = fs.open(file,\"r\")\
- local cont = f.readLine()\
- f.close()\
- if(s)then return textutils.unserialize(s) end\
- return cont\
- end\
- function file_write(file,data,s)\
- local f = fs.open(file,\"w\")\
- if(s)then f.write(textutils.serialize(data)) else\
- f.write(data) end\
- f.close()\
- end\
- function file_writeline(file,data,s)\
- local f = fs.open(file,\"w\")\
- if(s)then f.writeLine(textutils.serialize(data)) else\
- f.writeLine(data) end\
- f.close()\
- end\
- local function formatpath(path)\
- local pathtbl={}\
- local s=\"\"\
- local pathsize=0\
- -- Divide string and count the number of \
- -- divisions.\
- for str in string.gmatch(path, \"([^/]+)\") do\
- pathtbl[#pathtbl+1] = str \
- end\
- table.remove(pathtbl,1)\
- for i = 1, #pathtbl do\
- s = s .. pathtbl[i] .. \"/\"\
- end\
- return s\
- end\
- \
- local function getcontent(data,wdata,ctbl)\
- -- Returns a table --\
- for k, v in pairs(fs.list(data)) do\
- \
- if(fs.isDir(data..\"/\"..v) )then\
- getcontent(data..v..\"/\",v..\"/\",ctbl)\
- else\
- --print(data..v)\
- local f = fs.open(data..v,\"r\")\
- ctbl[formatpath(data..v)] = {content=f.readAll()}\
- f.close()\
- end\
- end\
- return textutils.serialize(ctbl)\
- end\
- function archive(data,export)\
- local content = {}\
- content = getcontent('/' .. data .. \"/\",\"/\",content)\
- file_write(export,content)\
- return true\
- end\
- \
- function extract(file,to)\
- local cont = textutils.unserialize(file_readAll(file))\
- for k,v in pairs(cont) do\
- file_write(to .. \"/\" .. k,v.content)\
- end\
- end\
- \
- -----------------------------------------------------------------------\
- --]] Read - API, HUGE thanks to Valithor for pretty much re-writing it\
- -----------------------------------------------------------------------\
- \
- local function setStartStr(nstr)\
- str = nstr\
- end\
- function novaread(e,maxlen,mslen,x,y)\
- term.setCursorBlink(active)\
- local function drawstr()\
- term.setCursorPos(x,y)\
- write(string.rep(\" \",mslen+1))\
- term.setCursorPos(x,y) \
- term.write(str:sub(viewX,viewX+mslen))\
- if(cursorX ~= #str and (cursorX+1) < mslen)then\
- term.setCursorPos((cursorX+1)+x,y)\
- else\
- term.setCursorPos((cursorX)+x,y)\
- end\
- end\
- local function undrawstr()\
- term.setCursorPos(x,y)\
- write(string.rep(\" \",mslen))\
- end\
- local function updatestr()\
- inputindex = inputindex + 1\
- drawstr()\
- end\
- if(active)then\
- if(e[1] == \"char\" and #str < maxlen)then\
- if cursorX < mslen and cursorX < #str then\
- cursorX = cursorX+1\
- end\
- if cursorX == mslen and viewX <= #str-mslen then\
- viewX = viewX+1\
- end\
- str = str:sub(1,inputindex) .. tostring(e[2]) .. str:sub(inputindex+1,#str)\
- updatestr()\
- end\
- if(e[1] == \"key\")then\
- local key = e[2]\
- if(key == keys.enter)then\
- term.setCursorBlink(false)\
- active = false\
- return true\
- end\
- if(key == keys.backspace and inputindex > 0)then\
- undrawstr()\
- if cursorX > 0 then\
- cursorX = cursorX-1\
- end\
- if cursorX == 0 and viewX > 0 then\
- viewX = viewX-1\
- end\
- str = string.sub( str, 1, inputindex - 1 ) .. string.sub( str, inputindex + 1 )\
- inputindex = inputindex - 1\
- drawstr()\
- end\
- if(key == keys.left and inputindex > 0)then\
- inputindex = inputindex - 1 --\
- if cursorX > 0 then\
- cursorX = cursorX-1\
- end\
- if cursorX == 0 and viewX > 0 then\
- viewX = viewX-1\
- end\
- drawstr()\
- end\
- if(key == keys.right and inputindex < #str)then\
- inputindex = inputindex + 1\
- if cursorX < mslen and viewX+cursorX<#str+x then\
- cursorX = cursorX+1 \
- end\
- if cursorX == mslen and viewX < #str-mslen then\
- viewX = viewX+1\
- end\
- drawstr()\
- end\
- if(key == keys.delete and inputindex < #str)then\
- if cursorX > mslen then\
- cursorX = cursorX+1\
- end\
- undrawstr()\
- str = string.sub( str, 1, inputindex ) .. string.sub( str, inputindex + 2 )\
- drawstr()\
- end\
- end\
- end\
- if(e[1] == \"mouse_click\" and (e[4] ~= y or e[3] < x or e[3] > x+maxlen) )then\
- active = false\
- term.setCursorBlink(false)\
- elseif(e[1] == \"mouse_click\" and e[4] == y)then\
- if(not active)then\
- active = true\
- term.setCursorPos(x+inputindex,y)\
- term.setCursorBlink(true)\
- drawstr()\
- end\
- if(e[3]-x >= 0 and e[3]<=#str) then\
- -- Broken until furthur notice - Lewisk -- \
- --inputindex = (viewX+e[3])-x\
- --cursorX = e[3]-x\
- --drawstr()\
- end\
- end\
- end\
- function getInput()\
- return str\
- end\
- function resetInput()\
- str = \"\"\
- inputindex = #str\
- cursorX = #str\
- end\
- function setInput(nstr)\
- str = nstr\
- inputindex = #str\
- cursorX = #str\
- end\
- function setActive(act)\
- active = act\
- end\
- function getActive()\
- return active\
- end\
- \
- function readEx(mlen,scroll,startw)\
- setActive(false)\
- if(startw == nil)then startw = \"\" end\
- setInput(startw)\
- local x, y = term.getCursorPos()\
- local readxoff = x\
- if(startw ~= \"\")then\
- scp(readxoff,y)\
- write(getInput())\
- end\
- local oinp = getInput()\
- local ininp = true\
- if(scroll)then\
- mslen = 1000\
- else\
- mslen = mlen+1\
- end\
- term.setCursorBlink(true)\
- while ininp do\
- local e = {os.pullEvent()}\
- local inp = novaread(e,mslen,mlen-1,readxoff,y)\
- setActive(true)\
- if(inp)then \
- ininp = false\
- setActive(false)\
- local inp = getInput()\
- setInput(oinp)\
- if(inp == startw)then\
- inp = \"\"\
- end\
- return inp\
- end\
- -- Dont let the user out of the read!\
- if(getActive() == \"false\")then setActive(true) end\
- end\
- end\
- \
- \
- \
- ------------------------------------------------\
- --]] Utils - API\
- ------------------------------------------------\
- \
- function init(nshell)\
- shell = nshell\
- end\
- \
- function openReadDialog(title,clrfunc,startread)\
- local bw, bh = 30,0\
- local sx, sy = w/2-math.ceil(bw/2), (h/2)-math.ceil(bh/2)-1\
- local ex, ey = w/2+math.ceil(bw/2), (h/2)+math.floor(bh/2)-1\
- paintutils.drawFilledBox(sx+1,sy,ex+2,ey+2,colors.black)\
- paintutils.drawFilledBox(sx,sy,ex,ey,colors.lightGray)\
- paintutils.drawBox(sx-1,sy-1,ex+1,ey+1,colors.gray)\
- scp(sx,sy-1)\
- stc(colors.white)\
- write(title)\
- scp(sx,sy)\
- sbc(colors.lightGray)\
- local inp = readEx(30,true,startread)\
- clrfunc()\
- return inp\
- end\
- \
- function notify(title,txt,clrfunc)\
- local bw, bh = 30,5\
- local sx, sy = w/2-math.ceil(bw/2), (h/2)-math.ceil(bh/2)+2\
- local ex, ey = w/2+math.ceil(bw/2), (h/2)+math.floor(bh/2)+1\
- paintutils.drawLine(sx,sy-1,ex,sy-1,colors.gray)\
- paintutils.drawFilledBox(sx+1,sy+1,ex+1,ey+1,colors.black)\
- paintutils.drawFilledBox(sx,sy,ex,ey,colors.lightGray)\
- scp(sx,sy-1)\
- stc(colors.white)\
- sbc(colors.gray)\
- write(title)\
- sbc(colors.lightGray)\
- local msg = {}\
- for str in string.gmatch(txt, \"([^*]+)\") do\
- msg[#msg+1] = str \
- end\
- for i = 1, #msg do\
- sbc(colors.lightGray)\
- colorwrite(\" \" .. msg[i],45,sx,sy+i)\
- end\
- colorwrite(\"&4Click&r to close. \",45,sx+8,sy+#msg+2)\
- os.pullEvent(\"mouse_click\")\
- clrfunc()\
- end\
- function openYesNo(title,txt,clrfunc,y,n)\
- if(y == nil or n == nil)then \
- y = \"Yes\"\
- n = \"No\"\
- end\
- local ynm = {y, n}\
- local inynm = true\
- local bw, bh = 30,5\
- local opinc = 9\
- local sx, sy = w/2-math.ceil(bw/2), (h/2)-math.ceil(bh/2)+2\
- local ex, ey = w/2+math.ceil(bw/2), (h/2)+math.floor(bh/2)+1\
- paintutils.drawLine(sx,sy-1,ex,sy-1,colors.gray)\
- paintutils.drawFilledBox(sx+1,sy+1,ex+1,ey+1,colors.black)\
- paintutils.drawFilledBox(sx,sy,ex,ey,colors.lightGray)\
- scp(sx,sy-1)\
- stc(colors.white)\
- sbc(colors.gray)\
- write(title)\
- sbc(colors.lightGray)\
- local msg = {}\
- for str in string.gmatch(txt, \"([^*]+)\") do\
- msg[#msg+1] = str \
- end\
- for i = 1, #msg do\
- sbc(colors.lightGray)\
- colorwrite(\" \" .. msg[i],45,sx,sy+i)\
- end\
- stc(colors.white)\
- local function drawm()\
- for i = 1, #ynm do\
- sbc(colors.red)\
- if(i==1)then\
- sbc(colors.green)\
- end\
- scp(sx+(i*opinc),ey-1)\
- write(ynm[i])\
- end\
- end\
- local function drawmopt(id,clk)\
- sbc(colors.red)\
- if(i==1)then\
- sbc(colors.green)\
- end\
- if(clk)then sbc(colors.gray) end\
- scp(sx+(id*opinc),ey-1)\
- write(ynm[id])\
- sleep(0.2)\
- end\
- local function mupdate()\
- while inynm do\
- local ev = {os.pullEvent()}\
- if(ev[1] == \"mouse_click\")then\
- local x, y = ev[3], ev[4]\
- for i = 1, #ynm do\
- if( x >= sx+(i*opinc)-1 and x <= sx+(i*opinc)+#ynm[i] and y == math.floor(ey-1) )then\
- inynm = false\
- drawmopt(i,true)\
- return i\
- end\
- end\
- end\
- end\
- end\
- drawm()\
- local res = mupdate()\
- clrfunc()\
- return res\
- end\
- \
- function isFileImage(file)\
- local isImg = false\
- local f = fs.open(file,\"r\")\
- if(f)then\
- if(tonumber(f.readAll():gsub(\"%s+\",\"\"),16) ~= nil) then\
- isImg = true\
- end\
- f.close()\
- end\
- return isImg\
- end\
- \
- function getApisFrom(loc,apis)\
- local inloc = false\
- if(fs.isDir(loc))then\
- inloc = true\
- for i = 1, #apis do\
- if(fs.exists(\"CrossBow/apis/\"..apis[i]))then\
- apis[i] = \"CrossBow/apis/\" ..apis[i]\
- \
- else\
- error(\"Program had to Quit: CrossBow install outdated or malformed. \")\
- end\
- end \
- end\
- \
- for i = 1, #apis do\
- if(inloc)then\
- os.loadAPI((apis[i]))\
- else\
- os.loadAPI(shell.resolveProgram((apis[i])))\
- end\
- end\
- \
- return inloc\
- end\
- \
- function colorwrite(str,smax,x,y,special)\
- scp(x,y)\
- local colorencode = {\
- ['&r'] = \"black\",\
- ['&1'] = \"blue\",\
- ['&2'] = \"green\",\
- ['&3'] = \"cyan\",\
- ['&4'] = \"red\",\
- ['&5'] = \"purple\",\
- ['&6'] = \"brown\",\
- ['&7'] = \"lightGray\",\
- ['&8'] = \"gray\",\
- ['&9'] = \"lightBlue\",\
- ['&a'] = \"lime\",\
- ['&b'] = \"orange\",\
- ['&c'] = \"pink\",\
- ['&d'] = \"magenta\",\
- ['&e'] = \"yellow\",\
- ['&f'] = \"white\",\
- }\
- if(special)then sbc(special) end\
- for a = 1, #str do\
- if(string.sub(str,a,a) == \"&\")then\
- if(colorencode[string.sub(str,a,a+1)] ~= nil)then\
- stc(colors[colorencode[string.sub(str,a,a+1)]])\
- end\
- str = string.sub(str,1,a-1) .. string.sub(str,a+1,#str)\
- else\
- write(string.sub(str,a,a))\
- end\
- end \
- sbc(colors.white)\
- end\
- \
- ------------------------------------------------\
- --]] Zip - API\
- ------------------------------------------------\
- \
- local function formatpath(path)\
- local pathtbl={}\
- local s=\"\"\
- local pathsize=0\
- -- Divide string and count the number of \
- -- divisions.\
- for str in string.gmatch(path, \"([^/]+)\") do\
- pathtbl[#pathtbl+1] = str \
- end\
- for k, v in pairs(pathtbl) do\
- pathsize=k\
- end\
- pathsize = pathsize - 1\
- -- Based on how large the user wants the string to be \
- -- add only the string bits that led up to the user defined\
- -- size.\
- for k, v in pairs(pathtbl) do\
- if(k <= pathsize)then s = s..pathtbl[k]..\"/\" end\
- end\
- return s\
- end\
- local function pathlen(path)\
- local pathtbl={}\
- local s=\"\"\
- local pathsize=0\
- -- Divide string and count the number of \
- -- divisions.\
- for str in string.gmatch(path, \"([^/]+)\") do\
- pathtbl[#pathtbl+1] = str \
- end\
- return #pathtbl\
- end\
- local function filterdirpath(dir,path)\
- local pathtbl={}\
- local s=\"\"\
- local pathsize=0\
- -- Divide string and count the number of \
- -- divisions.\
- local la = 0\
- for str in string.gmatch(path, \"([^/]+)\") do\
- if(la >= pathlen(dir))then\
- pathtbl[#pathtbl+1] = str \
- end\
- la = la + 1\
- end\
- for i = 1, #pathtbl do\
- s = s .. pathtbl[i] .. \"/\"\
- end \
- return s\
- end\
- local function comparesubpath(flpath,subpath)\
- return (formatpath(subpath) == flpath) or (subpath:find(flpath) and pathlen(formatpath(subpath)) == pathlen(flpath)+1 )\
- end\
- local function comparefolderpath(flpath,subpath)\
- return \
- end\
- local function getend(path)\
- local pathtbl={}\
- local s=\"\"\
- local pathsize=0\
- -- Divide string and count the number of \
- -- divisions.\
- for str in string.gmatch(path, \"([^/]+)\") do\
- pathtbl[#pathtbl+1] = str \
- end\
- return pathtbl[#pathtbl]\
- end\
- function iszip(file)\
- local f = fs.open(file,\"r\")\
- local c = f.readAll()\
- f.close()\
- return type(c) == \"table\"\
- end\
- local function intable(tbl,am)\
- for i = 1, #tbl do\
- if(tbl[i].n == am)then\
- return true\
- end\
- end\
- return false \
- end\
- function ziplist(zip,dir)\
- local folders = {}\
- local files = {}\
- local list = {}\
- local startls = false\
- local f = fs.open(zip,\"r\")\
- local c = (f.readAll())\
- c = textutils.unserialize(c)\
- f.close()\
- for k, v in pairs(c) do\
- if(comparesubpath(dir,k))then\
- if(pathlen(formatpath(k)) == pathlen(dir))then\
- files[getend(k)] = {t=\"file\",c=v.content}\
- --print(\"File:\" .. getend(k))\
- --print(\"------------------\")\
- --os.pullEvent(\"key\")\
- elseif(pathlen(formatpath(k)) < 2+pathlen(dir) and \
- not intable(folders,filterdirpath(dir,formatpath(k))))then\
- folders[#folders+1] = {n=filterdirpath(dir,formatpath(k)),t=\"folder\",c=v.content}\
- --print(\"Folder: \" .. filterdirpath(dir,formatpath(k)))\
- --os.pullEvent(\"key\")\
- end\
- end\
- end\
- for k, v in pairs(files) do\
- folders[#folders+1] = {n=k,type=v.t,data=v.c}\
- end\
- for i = 1, #folders do\
- list[i] = {n=folders[i].n,type=folders[i].t,data=folders[i].c}\
- end\
- return list\
- end",}
- }
- function file_write(file,data,s)
- local f = fs.open(file,"w")
- if(s)then f.write(textutils.serialize(data)) else
- f.write(data) end
- f.close()
- end
- write("Extract to: ")
- local loc = read()
- if(loc == "")then
- write("Extraction cancelled. ")
- else
- local cont = textutils.serialize(content)
- for k,v in pairs(textutils.unserialize(cont)) do
- file_write(loc .. "/" .. k,v.content)
- print("Extracting " .. k .. " to " .. loc .. k)
- end
- print("Files extracted to: " .. loc)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement