SHARE
TWEET

[ComputerCraft] - Nova Explore [Standalone, zip]

Redxone Jun 7th, 2016 (edited) 224 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local content = {
  2.   [ "novaexplore/" ] = {
  3.     content = "--====================================================\
  4. --]] Nova Explore and all file apis created by\
  5. --]] Lewisk3 CEO of Nova, all rights reservered \
  6. --]] DO NOT REDISTRIBUTE without the permission \
  7. --]] of Nova, Editing and/or \"rebranding\" is prohibited.\
  8. --]] Any copys found outside the permission of Nova\
  9. --]] will be taken and money will be due to the rights\
  10. --]] of Nova Technologys\
  11. -------------------------------------------------------\
  12. --=]      We have the rights to all the above       [=-       \
  13. --=====================================================\
  14. --]] Determine OS and load apis accordingly\
  15. os.loadAPI(shell.resolveProgram(\"NovaAPI\")) \
  16. local w, h = term.getSize()\
  17. local sbc = term.setBackgroundColor\
  18. local stc = term.setTextColor\
  19. local scp = term.setCursorPos\
  20. local clr = term.clear\
  21. local clrln = term.clearLine\
  22. local actionkeydown = false\
  23. local actionkey = keys.leftCtrl\
  24. local multiselecting = false\
  25. local diskside = \"right\"\
  26. files_selected = {}\
  27. local archiver = \"\"\
  28. local pa = paintutils\
  29. local pinnednames = {}\
  30. local innova = true\
  31. local iscrossbow = false\
  32. \
  33. --]] Define variables \
  34. local file_selected = 0\
  35. local files = {}\
  36. -- Path isnt locked\
  37. local path = NovaAPI.newpath(\"/\")\
  38. NovaAPI.setActive(false)\
  39. NovaAPI.setInput(path:getraw())\
  40. local fileoffs = 0\
  41. local sideoffs = 0\
  42. local sidemax = h-1\
  43. local filemax = h\
  44. local searching = false\
  45. local selectedside = 0\
  46. local search = \"\"\
  47. local pathsearch = \"/\"\
  48. local clipboard = {}\
  49. local inmenu = false\
  50. local inmenutype = {}\
  51. local drawingmenu = {}\
  52. local inmenux, inmenuy = 1, 4\
  53. local sideitems = {}\
  54. local pinslocation = \".novapins\"\
  55. local icons = {\
  56. \009folder = \"&e[=]\",\
  57. \009file = \"&7-~-\",\
  58. \009executable = \"&8:&7=&8:\",\
  59. \009game = \"&4-&7=&8]\",\
  60. \009zip = \"&5[&1=&2]\",\
  61. \009paint = \"&2~&4* \",\
  62. \009pin = \"&7<&8 \",\
  63. \009disk= \"&8:&4^&8:\"\
  64. }\
  65. --]] Menus \
  66. filemenu = {\
  67. \009 {n=\"Open    \",func=function(file) openHref(path:getraw() .. file.n) end},\
  68. \009 {n=\"Edit    \",func=function(file) \
  69. \009 \009editfile(path:getraw() .. file.n)\
  70. \009 end},\
  71. \009 {n=\"Open as \",func=function(file) \
  72. \009 \009local ans = NovaAPI.openYesNo(\"Open File As. \",\"Select open option.*\",novaex_redraw,\"With\", \"Args\")\
  73. \009 \009if(ans == 1)then -- open with file\
  74. \009 \009\009local openfile = NovaAPI.openReadDialog(\"Open with another file. \",novaex_redraw)\
  75. \009 \009\009if(file ~= \"\")then\
  76. \009 \009\009\009runFile(openfile,path:getraw() .. file.n,true)\
  77. \009 \009\009end\
  78. \009 \009elseif(ans == 2)then -- open with arguments\
  79. \009 \009\009local args = NovaAPI.openReadDialog(\"Open with arguments. \",novaex_redraw)\
  80. \009 \009\009runFile(path:getraw() .. file.n,args,true)\
  81. \009 \009end\
  82. \009 end},\
  83. \009 {n=\"Rename  \",relies=function(file) \
  84. \009 \009return file.t ~= \"disk\"\
  85. \009 end,\
  86. \009 func=function(file)\
  87. \009 \009\009local sid = getSelectedFile()\
  88. \009 \009\009sbc(colors.lightGray)\
  89. \009 \009\009scp(23,(sid-fileoffs)+4)\
  90. \009 \009\009write(string.rep(\" \",17))\
  91. \009 \009\009scp(23,(sid-fileoffs)+4)\
  92. \009 \009\009local newname = NovaAPI.readEx(17,false,file.n)\
  93. \009 \009\009renameFile(path:getraw(),file.n,newname)\
  94. \009 end},\
  95. \009 {n=\"Extract \",relies=function(file) return file.t == \"zip\" end,\
  96. \009 func=function(file) \
  97. \009 \009 local eto = NovaAPI.openReadDialog(\"Extract to: \",novaex_redraw)\
  98. \009 \009 local ans = NovaAPI.openYesNo(\"Extract \", \"Extract contents of * \" .. file.n .. \" to: \" .. eto .. \"? \",novaex_redraw)\
  99. \009 \009 if(ans == 1)then\
  100. \009 \009 \009 NovaAPI.extract(path:getraw() .. file.n,eto)\
  101. \009 \009 \009 ans = NovaAPI.openYesNo(\"Extract \", \"Extracted to: \" .. eto .. \"* Open location?\",novaex_redraw)\
  102. \009 \009 \009 if(ans == 1)then\
  103. \009 \009 \009 \009 path:set(eto)\
  104. \009 \009 \009 \009 getfiles()\
  105. \009 \009 \009 \009 undrawFiles()\
  106. \009 \009 \009 \009 drawFiles()\
  107. \009 \009 \009 end\
  108. \009 \009 end\
  109. \009 end},\
  110. \009 {n=\"Archive \",relies=function(file) return file.t ~= \"zip\" end,\
  111. \009 func=function(file) \
  112. \009 \009 local eto = NovaAPI.openReadDialog(\"Export archive to: \",novaex_redraw)\
  113. \009 \009 if(NovaAPI.archive(path:getraw() .. file.n,eto))then\
  114. \009 \009\009 NovaAPI.notify(\"Archive\",\"Folder/file successfully * archived. \",novaex_redraw)\
  115. \009     else\
  116. \009     \009 NovaAPI.notify(\"Archive\",\"Failed to archive folder/file. \",novaex_redraw)\
  117. \009 \009 end\
  118. \009 end},\
  119. \009 {n=\"Cut     \",relies=function(file) \
  120. \009\009return not fs.isReadOnly(path:getraw() .. file.n)\
  121. \009 end,func=function(file) \
  122. \009 \009setClipboard(path:getraw() .. file.n, file.n, \"cut\")\
  123. \009 end},\
  124. \009 {n=\"Copy    \",func=function(file) \
  125. \009 \009setClipboard(path:getraw() .. file.n, file.n, \"copy\")\
  126. \009 end},\
  127. \009 {n=\"Paste   \",relies=function(file) \
  128. \009 \009return clipboard.name ~= nil and \
  129. \009 \009\009not fs.isReadOnly(path:getraw() .. file.n)\
  130. \009 end,\
  131. \009 func=function(file) \
  132. \009 \009pasteFile(path:getraw()) \
  133. \009 end},\
  134. \009 {n=\"Pin item\",relies=function(file) \
  135. \009 \009return not isPinnedItem(path:getraw() .. file.n) end,\
  136. \009 func=function(file)\
  137. \009 \009 addPinnedFile(\
  138. \009 \009 \009icons[file.t] .. \" &r\" .. file.n,file.t,path:getraw() .. file.n\
  139. \009 \009 )\
  140. \009 end},\
  141. \009 {n=\"Unpin   \",relies=function(file) \
  142. \009 \009return isPinnedItem(path:getraw() .. file.n) end,\
  143. \009 func=function(file) \
  144. \009 \009 removePinnedFile(path:getraw() .. file.n)\
  145. \009 end},\
  146. \009 {n=\"Delete  \",relies=function(file) \
  147. \009 \009 return not fs.isReadOnly(path:getraw() .. file.n) and \
  148. \009 \009 \009not (file.t == \"disk\" and peripheral.find(\"drive\"))\
  149. \009 end,func=function(file) \
  150. \009 \009\009local ans = NovaAPI.openYesNo(\"File deletion. \",\"Confirm &4deletion&r of *\" .. file.n,novaex_redraw)\
  151. \009 \009\009if(ans == 1)then\
  152. \009 \009\009\009deleteFile(path:getraw() .. file.n)\
  153. \009 \009\009end\
  154. \009 end},\
  155. }\
  156. sidemenu = {\
  157. \009 {n=\"Open   \",func=function() openHref(getSelectedSideItem().href) end},\
  158. \009 {n=\"Rename \",\
  159. \009 func=function(file)\
  160. \009 \009\009local sid = getSelectedSide()\
  161. \009 \009\009scp(5,(sid-sideoffs)+4)\
  162. \009 \009\009sbc(colors.lightGray)\
  163. \009 \009\009write(string.rep(\" \",11))\
  164. \009 \009\009scp(5,(sid-sideoffs)+4)\
  165. \009 \009\009local newname = NovaAPI.readEx(9,false)\
  166. \009 \009\009renameSideItem(getSelectedSide(),newname)\
  167. \009 end},\
  168. \009 {n=\"Unpin  \",relies=function() return getSelectedSide() >= 8 end,\
  169. \009 func=function(file) \
  170. \009 \009removePinnedFile(getSelectedSideItem().href)\
  171. \009 end},\
  172. \009 {n=\"Up     \",relies=function() \
  173. \009 \009\009return getSideItem(getSelectedSide()-1).t ~= nil and  \
  174. \009 \009\009\009   getSideItem(getSelectedSide()-1).t ~= \"text\" \
  175. \009 \009\009end,\
  176. \009 func=function(file) \
  177. \009 \009\009moveSideItem(getSelectedSide(),-1)\
  178. \009 end},\
  179. \009 {n=\"Down   \",relies=function() \
  180. \009 \009return (getSelectedSide() < getSideAmmount()) and \
  181. \009 \009\009   (getSideItem(getSelectedSide()+1).n ~= nil) and\
  182. \009 \009\009   (getSideItem(getSelectedSide()+1).t ~= \"text\")\
  183. \009 end,\
  184. \009 func=function(file) \
  185. \009 \009moveSideItem(getSelectedSide(),1)\
  186. \009 end},\
  187. }\
  188. emptymenu = {\
  189. \009{n=\"New Folder \",func=function() \
  190. \009\009local file = NovaAPI.openReadDialog(\"New Folder\",novaex_redraw)\
  191. \009\009newFileFolder(\"folder\",path:getraw(),file) \
  192. \009end},\
  193. \009{n=\"New File   \",func=function() \
  194. \009\009local file = NovaAPI.openReadDialog(\"New File\",novaex_redraw)\
  195. \009\009newFileFolder(\"file\",path:getraw(),file) \
  196. \009end},\
  197. \009 {n=\"Paste      \",relies=function() \
  198. \009 \009return clipboard.name ~= nil and \
  199. \009 \009\009not fs.isReadOnly(path:getraw())\
  200. \009 end,\
  201. \009 func=function() \
  202. \009 \009pasteFile(path:getraw()) \
  203. \009 end},\
  204. \009 {n=\"Test Crash \",func=function() error(\"Lol get rekt!\") end},\
  205. }\
  206. foldermenu = {\
  207. \009 filemenu[1],\
  208. \009 filemenu[4],\
  209. \009 filemenu[6],\
  210. \009 filemenu[7],\
  211. \009 filemenu[8],\
  212. \009 filemenu[9],\
  213. \009 {n=\"Pin item\",relies=function(file) \
  214. \009 \009return not isPinnedItem(path:getraw() .. file.n) end,\
  215. \009 func=function(file) \
  216. \009 \009 addPinnedFile(\
  217. \009 \009 \009icons[file.t] .. \" &r\" .. file.n,file.t,path:getraw() .. file.n\
  218. \009 \009 )\
  219. \009 end},\
  220. \009 filemenu[11],\
  221. \009 {n=\"Eject   \",relies=function(file) \
  222. \009 \009 return (file.t == \"disk\" and peripheral.find(\"drive\"))\
  223. \009 end,func=function(file) \
  224. \009 \009\009disk.eject(getDiskside())\
  225. \009 end},\
  226. \009 filemenu[12],\
  227. }\
  228. if(iscrossbow)then\
  229. \009sideitems = {\
  230. \009\009{n='&5* &rQuick Access',t='text'},\
  231. \009\009{n=' ',t='text'},\
  232. \009\009{n=icons.folder..' &rPrograms',t='folder',href=\"CrossBow/programs\"},\
  233. \009\009{n=icons.folder..' &rGames',t='folder',href=\"CrossBow/games\"},\
  234. \009\009{n=' ',t='text'},\
  235. \009\009{n=' ',t='text'},\
  236. \009\009{n=icons.pin .. \"&rPinned Items\",t='text'},\
  237. \009\009{n=' ',t='text'},\
  238. \009\009{n=icons.game..' &rGameOfLife',t='game',href=\"CrossBow/games/GameOfLife\"},\
  239. \009\009{n=icons.game..' &r2048',t='game',href=\"CrossBow/games/2048\"},\
  240. \009\009{n=icons.folder..' &5Apis',t='folder',href=\"CrossBow/apis\"},\
  241. \009}\
  242. else\
  243. \009sideitems = {\
  244. \009\009{n='&5* &rQuick Access',t='text'},\
  245. \009\009{n=' ',t='text'},\
  246. \009\009{n=icons.folder..' &rPrograms',t='folder',href=\"rom/programs\"},\
  247. \009\009{n=icons.folder..' &rGames',t='folder',href=\"rom/programs/fun\"},\
  248. \009\009{n=' ',t='text'},\
  249. \009\009{n=' ',t='text'},\
  250. \009\009{n=icons.pin .. \"&rPinned Items\",t='text'},\
  251. \009\009{n=' ',t='text'},\
  252. \009\009{n=icons.game..' &2Worm',t='game',href=\"rom/programs/fun/worm\"},\
  253. \009\009{n=icons.game..' &8Redirection',t='game',href=\"rom/programs/fun/advanced/redirection\"},\
  254. \009}\
  255. end\
  256. --]] Get functions and file definitions\
  257. local pinnednames = {}\
  258. if(iscrossbow)then\
  259. \009pinslocation = \"configs/novapins\"\
  260. end\
  261. \
  262. function writexy(text,x,y)\
  263.  term.setCursorPos(x,y)\
  264.  term.write(text)\
  265. end\
  266. \
  267. function writec(text)\
  268.  local w, h = term.getSize()\
  269.  term.setCursorPos(w/2 - #text/2, (h/2)- 1)\
  270.  term.write(text)\
  271. end\
  272. \
  273. function writecy(text,y)\
  274.    local w,_ = term.getSize()\
  275.    term.setCursorPos(w/2 - #text/2, y)\
  276.    term.write(text)\
  277. end\
  278. \
  279. function getDiskside() return diskside end\
  280. function getWorkingDir()\
  281. \009return fs.getDir(shell.getRunningProgram()) .. \"/\"\
  282. end\
  283. function getConfigPinnedItems()\
  284. \009if(fs.exists(getWorkingDir() .. pinslocation))then\
  285. \009\009local pfile = (getWorkingDir() .. pinslocation)\
  286. \009\009local itemspinned = textutils.unserialize(NovaAPI.file_readAll(pfile))\
  287. \009\009for i = 1, #itemspinned do\
  288. \009\009\009sideitems[8+(i-1)] = itemspinned[i]\
  289. \009\009end\
  290. \009\009getPinnedNames()\
  291. \009else\
  292. \009\009local writeitems = {}\
  293. \009\009for i = 8, #sideitems do\
  294. \009\009\009writeitems[#writeitems+1] = sideitems[i]\
  295. \009\009end\
  296. \009\009NovaAPI.file_write(getWorkingDir() .. pinslocation,textutils.serialize(writeitems))\
  297. \009\009getConfigPinnedItems()\
  298. \009end\
  299. end\
  300. function saveConfigPinnedItems()\
  301. \009local writeitems = {}\
  302. \009for i = 8, #sideitems do\
  303. \009\009writeitems[#writeitems+1] = sideitems[i]\
  304. \009end\
  305. \009if(fs.exists(getWorkingDir() .. pinslocation))then\
  306. \009\009NovaAPI.file_write(getWorkingDir() .. pinslocation,textutils.serialize(writeitems))\
  307. \009end\
  308. end\
  309. \
  310. function isPinnedItem(path)\
  311. \009return pinnednames[formatPinPath(path)]\
  312. end\
  313. \
  314. -- Icon drawing\
  315. \
  316. \
  317. function formatPinPath(path)\
  318. \009local npath  = NovaAPI.newpath(path)\
  319.    local pathtbl={}\
  320.    for str in string.gmatch(path, \"([^/]+)\") do\
  321.        pathtbl[#pathtbl+1] = str  \
  322.    end\
  323.    fname = pathtbl[#pathtbl]\
  324.    npath:goback(1)\
  325. \
  326. \009if(path:sub(1,1) == \"/\" and #npath:getraw() > 1)then path = path:sub(2,#path) end \
  327. \009if(#npath:getraw() <= 1)then path = \"/\" .. fname end\
  328. \009return path\
  329. end\
  330. \
  331. function novaex_redraw()\
  332. \009undrawFiles()\
  333. \009getfiles()\
  334. \009drawMain()\
  335. \009drawFiles()\
  336. end\
  337. \
  338. function moveSideItem(id,to)\
  339. \009local moveitem = sideitems[id]\
  340. \009local toitem = sideitems[id+to]\
  341. \
  342. \009sideitems[id+to] = moveitem\
  343. \009sideitems[id] = toitem\
  344. \009selectedside = selectedside + to\
  345. \009drawSideBar()\
  346. end\
  347. function deleteFile(file)\
  348. \009file_selected = 0\
  349. \009fs.delete(file)\
  350. \009undrawFiles()\
  351. \009getfiles()\
  352. \009drawFiles()\
  353. end\
  354. function newFileFolder(forf,path,file)\
  355. \009if(file == \"\" or file:find(\" \"))then return false end\
  356. \009if(not fs.exists(path .. file))then\
  357. \009\009if(forf == \"folder\")then\
  358. \009\009\009if(file:sub(1,4) == \"disk\")then\
  359. \009\009\009\009NovaAPI.notify(\"Creation Error.\",\"Cannot create disk directory!\",novaex_redraw)\
  360. \009\009\009\009return false\
  361. \009\009\009end\
  362. \009\009\009fs.makeDir(path .. file)\
  363. \009\009elseif(forf == \"file\")then\
  364. \009\009\009local f = fs.open(path .. file,\"w\")\
  365. \009\009\009f.write(\"\")\
  366. \009\009\009f.close()\
  367. \009\009end\
  368. \009\009getfiles()\
  369. \009\009drawFiles()\
  370. \009else\
  371. \009\009NovaAPI.notify(\"Creation Error.\",\"File or folder already exists.\",novaex_redraw)\
  372. \009end\
  373. end\
  374. function drawPathSearch()\
  375. \009sbc(colors.white)\
  376. \009writexy(string.rep(\" \",w-24),12,2)\
  377. \009sbc(colors.white)\
  378. \009stc(colors.black)\
  379. \009scp(13,2)\
  380. \009if(#path:getraw() > 25)then\
  381. \009\009local dif = #path:getraw() - 25\
  382. \009\009write(pathsearch:sub(dif,#path:getraw()))\
  383. \009else\
  384. \009\009write(pathsearch)\
  385. \009end\
  386. end\
  387. \
  388. function renameSideItem(id,nname)\
  389.     if(nname ~= \"\")then\
  390.     \009 nname = icons[sideitems[id].t] .. \"&r \" .. nname\
  391.     \009 sideitems[id].n = nname\
  392.     \009 saveConfigPinnedItems()\
  393.     end\
  394.       drawSideBar()\
  395. end\
  396. function getSideItemType(id)\
  397. \009return sideitems[id].t\
  398. end\
  399. function getSideItem(id)\
  400. \009return sideitems[id]\
  401. end\
  402. function addPinnedFile(name,type,link)\
  403. \009sideitems[#sideitems+1] = {n=name,t=type,href=formatPinPath(link)}\
  404. \009pinnednames[formatPinPath(link)] = true\
  405. \009saveConfigPinnedItems()\
  406. \009drawFiles()\
  407. \009drawSideBar()\
  408. end\
  409. function setClipboard(p,n,t)\
  410. \009clipboard = {path=p,name=n,type=t}\
  411. \009if(t == \"cut\")then\
  412. \009\009drawFiles()\
  413. \009end\
  414. end\
  415. function getSelectedSideItem()\
  416. \009return sideitems[selectedside]\
  417. end\
  418. function getSelectedSide()\
  419. \009return selectedside\
  420. end\
  421. function getSideAmmount()\
  422. \009return #sideitems\
  423. end\
  424. function getSelectedFile()\
  425. \009return file_selected\
  426. end\
  427. function getnamedpins()\
  428. \009return pinnednames\
  429. end\
  430. function getClipboard()\
  431. \009return clipboard\
  432. end\
  433. function removePinnedFile(link)\
  434. \009for i = 8, #sideitems do\
  435. \009\009if(sideitems[i].href == formatPinPath(link))then\
  436. \009\009\009table.remove(sideitems,i)\
  437. \009\009\009getPinnedNames()\
  438. \009\009\009saveConfigPinnedItems()\
  439. \009\009\009break\
  440. \009\009end\
  441. \009end\
  442. \009selectedside = 0\
  443. \009drawFiles()\
  444. \009drawSideBar()\
  445. end\
  446. function getPinnedNames()\
  447. \009pinnednames = {}\
  448. \009for i = 1, #sideitems do\
  449. \009\009if(sideitems[i].t ~= \"text\")then\
  450. \009\009\009pinnednames[sideitems[i].href] = true\
  451. \009\009end\
  452. \009end\
  453. end\
  454. \
  455. --]] Get files in directory\
  456. \
  457. function getfiles()\
  458. \009files = {}\
  459. \009local folders = {}\
  460. \009for k , v in pairs(fs.list(path:getraw())) do\
  461. \009\009if(fs.isDir(path:getraw() .. v) and (path:getraw() .. v):find(search) )then\
  462. \009\009\009local spt = 'folder'\
  463. \009\009\009if(v:sub(1,4) == \"disk\")then \
  464. \009\009\009\009if(#v > 4)then\
  465. \009\009\009\009\009if(tonumber(v:sub(5,#v)) ~= nil)then\
  466. \009\009\009\009\009\009spt = \"disk\"\
  467. \009\009\009\009\009end\
  468. \009\009\009\009else\
  469. \009\009\009\009\009spt = \"disk\" \
  470. \009\009\009\009end\
  471. \009\009\009end\
  472. \009\009\009folders[#folders+1] = {n=v,t=spt}\
  473. \009\009else if( v:find(search) )then\
  474. \009\009\009local nt = 'file'\
  475. \009\009\009if(v:sub(#v-3,#v) == '.zip')then nt = 'zip' end\
  476. \009\009\009if(v:sub(#v-3,#v) == '.exe')then nt = 'exe' end\
  477. \009\009\009if(path:getraw():find(\"CrossBow/games\") or \
  478. \009\009\009\009path:getraw():find(\"rom/programs/fun\"))then nt = \"game\" end\
  479. \009\009\009if(path:getraw():find(\"CrossBow/programs\"))then nt = \"executable\" end\
  480. \009\009\009if(NovaAPI.isFileImage(path:getraw() .. v))then nt = \"paint\" end\
  481. \009\009\009files[#files+1] = {n=v,t=nt}\
  482. \009\009end\
  483. \009\009end\
  484. \009end\
  485. \009-- Sort folders before files\
  486. \009for k,v in pairs(files) do \
  487. \009\009table.insert(folders, v) \
  488. \009end\
  489. \009files = folders\
  490. end\
  491. \
  492. --]] Draw program layout\
  493. function drawSideBar()\
  494. \009term.current().setVisible(false)\
  495. \009sbc(colors.white)\
  496. \009pa.drawFilledBox(0,4,17,h,colors.white)\
  497. \009sbc(1,1)\
  498. \009local loopam = #sideitems\
  499. \009if(#sideitems > h-5)then\
  500. \009\009loopam = (h-5)+sideoffs\
  501. \009end\
  502. \009for i = 1+sideoffs, loopam do\
  503. \009\009if(i-sideoffs < sidemax)then\
  504. \009\009\009if(sideitems[i] ~= nil)then\
  505. \009\009\009\009scp(1,(i-sideoffs)+4)\
  506. \009\009\009\009write(string.rep(\" \",16))\
  507. \009\009\009\009if(selectedside == i)then\
  508. \009\009\009\009\009sbc(colors.lightGray)\
  509. \009\009\009\009else\
  510. \009\009\009\009\009sbc(colors.white)\
  511. \009\009\009\009end\
  512. \009\009\009\009NovaAPI.colorwrite(sideitems[i].n,12,1,(i-sideoffs)+4)\
  513. \009\009\009end\
  514. \009\009end\
  515. \009end\
  516. \009pa.drawBox(17,4,17,h,colors.gray)\
  517. \009pa.drawBox(1,h,17,h,colors.gray)\
  518. \009pa.drawBox(16,4,16,h-1,colors.lightGray)\
  519. \009stc(colors.gray)\
  520. \009writexy(\"^\",16,4)\
  521. \009writexy(\"v\",16,h-1)\
  522. \009term.current().setVisible(true)\
  523. end\
  524. -- Deprecidated\
  525. function drawFile(ind)\
  526. \009 -- Draw selected files\
  527. \009term.current().setVisible(false)\
  528. \009sbc(colors.white)\
  529. \009stc(colors.black)\
  530. \009  if(ind <= filemax)then\
  531. \009 \009    scp(19,ind+fileoffs)\
  532. \009\009\009write(string.rep(\" \",30))\
  533. \009\009\009NovaAPI.colorwrite(icons[files[ind].t] .. \" &r\" .. files[ind].n ,12,19,ind,file_selected == ind)\
  534. \009\009\009scp(40,ind+fileoffs)\
  535. \009\009 if(not fs.isDir(path:getraw() .. files[ind].n))then\
  536. \009\009     \009write(tostring(fs.getSize(path:getraw() .. files[ind].n) / 1000):sub(1,4) .. \"KB\")\
  537. \009\009 end\
  538. \009  end\
  539. \009  term.current().setVisible(true)\
  540. \009  drawPathSearch()\
  541. end\
  542. function undrawFiles()\
  543. \009pa.drawFilledBox(18,4,w-1,h,colors.white)\
  544. end\
  545. function drawFilePath()\
  546. \009sbc(colors.white)\
  547. \009writexy(string.rep(\" \",w-24),12,2)\
  548. \009sbc(colors.white)\
  549. \009stc(colors.black)\
  550. \009scp(13,2)\
  551. \009if(#path:getraw() > 25)then\
  552. \009\009local dif = #path:getraw() - 25\
  553. \009\009write(path:getraw():sub(dif,#path:getraw()))\
  554. \009else\
  555. \009\009write(path:getraw())\
  556. \009end\
  557. \
  558. end\
  559. function drawFiles()\
  560. \009term.current().setVisible(false)\
  561. \009sbc(colors.white)\
  562. \009stc(colors.black)\
  563. \009drawFilePath()\
  564. \009 scp(23,4)\
  565. \009 stc(colors.lightGray)\
  566. \009 write(\"Name\")\
  567. \009 scp(40,4)\
  568. \009 write(\"Size\")\
  569. \009if(#files == 0)then\
  570. \009\009scp(25,5)\
  571. \009\009stc(colors.lightGray)\
  572. \009\009if(search ~= \"\")then\
  573. \009\009\009scp(20,5)\
  574. \009\009\009write(\"No items matched your search. \")\
  575. \009\009else\
  576. \009\009\009write(\"This folder is empty. \")\
  577. \009\009end\
  578. \009end\
  579. \009local loopam = #files\
  580. \009if(#files > h-4)then\
  581. \009\009loopam = (h-4)+fileoffs\
  582. \009end\
  583. \009 for i = 1+fileoffs, loopam do\
  584. \009 \009  if(i-fileoffs <= filemax)then\
  585. \009 \009  \009if(files[i].n ~= nil)then\
  586. \009 \009  \009 scp(19,(i-fileoffs)+4)\
  587. \009\009\009 write(string.rep(\" \",30))\
  588. \009\009\009 local namecolor = \" &r\"\
  589. \009\009\009 local drawname = files[i].n\
  590. \009\009\009 if(path:getraw() .. files[i].n == clipboard.path and clipboard.type == \"cut\")then\
  591. \009\009\009  \009namecolor = \" &7\"\
  592. \009\009\009end\
  593. \009\009\009 if(isPinnedItem(path:getraw() .. files[i].n))then \
  594. \009\009\009 \009 namecolor = \" &b\"\
  595. \009\009\009 \009if(path:getraw() .. files[i].n == clipboard.path and clipboard.type == \"cut\")then\
  596. \009\009\009 \009 \009namecolor = \" &e\"\
  597. \009\009\009 \009end\
  598. \009\009\009 end\
  599. \009\009\009 local selected = (file_selected == i)\
  600. \009\009\009 if(multiselecting)then\
  601. \009\009\009 \009for s = 1, #files_selected do\
  602. \009\009\009 \009\009if(files_selected[s].n == files[i].n and \
  603. \009\009\009 \009\009\009path:getraw() == files_selected[s].p)then\
  604. \009\009\009 \009\009\009if(clipboard.type == \"cut\")then\
  605. \009\009\009 \009\009\009\009namecolor = \" &7\"\
  606. \009\009\009 \009\009\009\009if(isPinnedItem(path:getraw() .. files[i].n))then \
  607. \009\009\009 \009\009\009\009\009namecolor = \" &e\"\
  608. \009\009\009 \009\009\009\009end\
  609. \009\009\009 \009\009\009end\
  610. \009\009\009 \009\009\009selected = true\
  611. \009\009\009 \009\009end\
  612. \009\009\009 \009end\
  613. \009\009\009 end\
  614. \
  615. \009\009\009 local bcol = colors.white\
  616. \009\009\009 if(selected)then bcol = colors.lightBlue end\
  617. \009\009\009 NovaAPI.colorwrite(icons[files[i].t] .. namecolor .. drawname ..\"&r\",12,19,(i-fileoffs)+4,bcol)\
  618. \009\009\009 if(search ~= \"\" )then\
  619. \009\009\009 \009local foundletters = \"\"\
  620. \009\009\009 \009 for x = 1, #files[i].n do\
  621. \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\
  622. \009\009\009 \009 \009 \009 foundletters = foundletters .. files[i].n:sub(x,x)\
  623. \009\009\009 \009 \009 \009 scp( (22)+x, (i-fileoffs)+4) -- hardcoded for 3 wide icons\
  624. \009\009\009 \009 \009 \009 sbc(colors.yellow)\
  625. \009\009\009 \009 \009 \009 write(files[i].n:sub(x,x))\
  626. \009\009\009 \009 \009 \009 sbc(colors.white)\
  627. \009\009\009 \009 \009 end\
  628. \009\009\009 \009 end\
  629. \009\009\009 end\
  630. \009\009\009 scp(40,(i-fileoffs)+4)\
  631. \009\009\009 if(not fs.isDir(path:getraw() .. files[i].n))then\
  632. \009\009\009 \009write(tostring(fs.getSize(path:getraw() .. files[i].n) / 1000):sub(1,4) .. \"KB\")\
  633. \009\009\009 end\
  634. \009 \009  end\
  635. \009 \009 end\
  636. \009 end \
  637. \009 term.current().setVisible(true)\
  638. end\
  639. function renameFile(path,name,nname)\
  640. \009local odir = shell.dir()\
  641. \009shell.setDir(\"\")\
  642. \009if(not fs.exists(path .. nname) and nname ~= \"\" and not nname:find(\" \"))then\
  643. \009\009if(nname:sub(1,4) == \"disk\" and fs.isDir(path .. name))then\
  644. \009\009\009shell.setDir(odir)\
  645. \009\009\009NovaAPI.notify(\"Rename Error.\",\"Cannot rename directory to * disk!\",novaex_redraw)\
  646. \009\009\009return false\
  647. \009\009end\
  648. \009\009fs.move(path .. name, path .. nname)\
  649. \009\009getfiles()\
  650. \009elseif(nname ~= \"\" and not nname:find(\" \"))then\
  651. \009\009NovaAPI.notify(\"Couldn't rename file.\",\"File with name:  * \".. nname .. \", already exists.\",novaex_redraw)\
  652. \009end\
  653. \009drawFiles()\
  654. \009shell.setDir(odir)\
  655. end\
  656. function runFile(fpath,args,noclick)\
  657. \009local odir = shell.dir()\
  658. \009sbc(colors.black)\
  659. \009stc(colors.white)\
  660. \009clr()\
  661. \009scp(1,1)\
  662. \009shell.setDir(\"\")\
  663. \009if(NovaAPI.isFileImage(fpath))then \
  664. \009\009args = fpath\
  665. \009\009fpath = \"paint\"\
  666. \009\009noclick = true\
  667. \009end\
  668. \009if(shell.resolveProgram(fpath))then\
  669. \009\009if(fs.exists(shell.resolveProgram(fpath)))then \
  670. \009\009\009shell.run(fpath,args)\
  671. \009\009\009if(not noclick)then\
  672. \009\009\009\009writecy(\"Click any where to return to NovaBrowse. \",9)\
  673. \009\009\009\009os.pullEvent(\"mouse_click\")\
  674. \009\009\009end\
  675. \009\009else\
  676. \009\009\009NovaAPI.notify(\"Open file.\", \"&4File not found. \",novaex_redraw)\
  677. \009\009end\
  678. \009end\
  679. \009search = \"\"\
  680. \009shell.setDir(odir)\
  681. \009drawMain()\
  682. \009getfiles()\
  683. \009drawFiles()\
  684. \009drawPathSearch()\
  685. end\
  686. function setDir(name)\
  687. \009if(fs.isDir(name))then\
  688. \009\009clearSearch()\
  689. \009\009file_selected = 0\
  690. \009\009if(name:sub(#name,#name) ~= \"/\")then name = name .. \"/\" end\
  691. \009\009fileoffs = 0\
  692. \009\009path:set(name)\
  693. \009\009getfiles()\
  694. \009\009undrawFiles()\
  695. \009\009drawFiles()\
  696. \009\009return true\
  697. \009else\
  698. \009\009drawFilePath()\
  699. \009\009return false\
  700. \009end\
  701. \009NovaAPI.setInput(path:getraw())\
  702. \009pathsearch = path:getraw()\
  703. end\
  704. function addDir(name)\
  705. \009selectedside = 0\
  706. \009drawSideBar() \
  707. \009clearSearch()\
  708. \009file_selected = 0\
  709. \009fileoffs = 0\
  710. \009path:add(name)\
  711. \009getfiles()\
  712. \009undrawFiles()\
  713. \009drawFiles()\
  714. \009NovaAPI.setInput(path:getraw())\
  715. \009pathsearch = path:getraw()\
  716. end\
  717. function clearSearch()\
  718. \009search = \"\"\
  719. \009scp(40,2)\
  720. \009sbc(colors.lightGray)\
  721. \009write(string.rep(\" \",11))\
  722. end\
  723. function searchDir(val)\
  724. \009file_selected = 0\
  725. \009fileoffs = 0\
  726. \009local nfiles = {}\
  727. \009undrawFiles()\
  728. \009if(val == \"\" or val == \" \")then\
  729. \009\009getfiles()\
  730. \009else\
  731. \009\009--for i = 1, #files do\
  732. \009\009--\009if(files[i])then\
  733. \009\009--\009\009if(not files[i].n:find(val))then\
  734. \009\009\009--\009\009table.remove(files,i)\
  735. \009\009--\009\009end\
  736. \009\009--\009end\
  737. \009--\009end\
  738. \009\009--files = nfiles\
  739. \009end\
  740. \009drawFiles()\
  741. end\
  742. function openHref(href)\
  743. if(fs.isDir(href))then\
  744. \009setDir(href)\
  745. elseif(fs.exists(href))then\
  746. \009return runFile(href)\
  747. end\
  748. end\
  749. function editfile(filepath)\
  750. \009runFile(\"edit\",filepath,true)\
  751. end\
  752. function pasteMultiFile(to)\
  753. \009if(multiselecting)then\
  754. \009\009for i = 1, #files_selected do\
  755. \009\009\009clipboard.path = files_selected[i].p .. files_selected[i].n\
  756. \009\009\009clipboard.name = files_selected[i].n\
  757. \009\009\009pasteFile(to)\
  758. \009\009end\
  759. \009end\
  760. end\
  761. function pasteFile(to)\
  762. \009local odir = shell.dir()\
  763. \009if(fs.isReadOnly(to))then\
  764. \009\009NovaAPI.notify(\"Paste file \", \"Access Denied. \",novaex_redraw)\
  765. \009\009return\
  766. \009end\
  767. \009if(not fs.exists(to .. clipboard.name))then\
  768. \009\009fs.copy(clipboard.path,path:getraw() .. clipboard.name)\
  769. \009\009if(clipboard.type == \"cut\")then fs.delete(clipboard.path) clipboard = {} end\
  770. \009\009getfiles()\
  771. \009\009drawFiles()\
  772. \009else\
  773. \009\009if(to .. clipboard.name == clipboard.path)then\
  774. \009\009\009clipboard = {}\
  775. \009\009\009drawFiles()\
  776. \009\009\009return\
  777. \009\009end\
  778. \009\009local ans = NovaAPI.openYesNo(\"File transfer\",\"File exists, Rename file? \",novaex_redraw)\
  779. \009\009if(ans == 1)then\
  780. \009\009\009local newname = NovaAPI.openReadDialog(\"Rename paste file. \",novaex_redraw,clipboard.name)\
  781. \009\009\009if(newname:find(\" \"))then\
  782. \009\009\009\009NovaAPI.notify(\"File rename \", \"Invalid file name. \",novaex_redraw)\
  783. \009\009\009else\
  784. \009\009\009\009clipboard.name = newname\
  785. \009\009\009end\
  786. \009\009\009return pasteFile(to)\
  787. \009\009end\
  788. \009end\
  789. \
  790. \009shell.setDir(odir)\
  791. end\
  792. function prevDir(ind) \
  793. \009selectedside = 0 \
  794. \009drawSideBar()\
  795. \009scp(2,2)\
  796. \009sbc(colors.gray)\
  797. \009stc(colors.black)\
  798. \009write(\"<-\")\
  799. \009sleep(0.1)\
  800. \009scp(2,2)\
  801. \009sbc(colors.lightGray)\
  802. \009stc(colors.gray)\
  803. \009write(\"<-\")\
  804. \009clearSearch()\
  805. \009file_selected = 0\
  806. \009fileoffs = 0\
  807. \009path:goback(ind)\
  808. \009getfiles()\
  809. \009undrawFiles()\
  810. \009drawFiles()\009\
  811. \009NovaAPI.setInput(path:getraw())\
  812. \009pathsearch = path:getraw()\
  813. end\
  814. function refreshDir()\
  815. \009scp(6,2)\
  816. \009sbc(colors.gray)\
  817. \009stc(colors.black)\
  818. \009write(\"<>\")\
  819. \009sleep(0.1)\
  820. \009scp(6,2)\
  821. \009sbc(colors.lightGray)\
  822. \009stc(colors.gray)\
  823. \009write(\"<>\")\
  824. \009clearSearch()\
  825. \009file_selected = 0\
  826. \009fileoffs = 0\
  827. \009drawMain()\
  828. \009getConfigPinnedItems()\
  829. \009getPinnedNames()\
  830. \009drawSideBar()\
  831. \009getfiles()\
  832. \009drawFiles()\
  833. \009checkUpdate()\
  834. \009NovaAPI.setInput(path:getraw())\
  835. \009pathsearch = path:getraw()\
  836. end\
  837. function drawfilemenu(menu,sx,sy)\
  838. \009local finalmenu = {}\
  839. \009for i = 1, #menu do\
  840. \009\009if(menu[i].relies == nil)then\
  841. \009\009\009finalmenu[#finalmenu+1] = menu[i]\
  842. \009\009elseif(menu[i].relies(files[file_selected],pinnednames))then\
  843. \009\009\009finalmenu[#finalmenu+1] = menu[i]\
  844. \009\009end\
  845. \009end\
  846. \009if(sy+#finalmenu > h)then\
  847. \009\009sy = sy - ((sy+#finalmenu)-h)\
  848. \009end\
  849. \009if(sx+#finalmenu[1].n >= w-1)then\
  850. \009\009sx = sx - ((sx+#finalmenu[1].n)-(w-1))\
  851. \009end\
  852. \009pa.drawBox(sx,sy+2,sx+#finalmenu[1].n,sy+#finalmenu+1,colors.black)\
  853. \009for i = 1, #finalmenu do\
  854. \009\009if(sy+i <= h)then\
  855. \009\009\009scp(sx-1,sy+i)\
  856. \009\009\009sbc(colors.lightGray)\
  857. \009\009\009stc(colors.white)\
  858. \009\009\009write(string.rep(\" \",#finalmenu[i].n+1))\
  859. \009\009\009scp(sx,sy+i)\
  860. \009\009\009write(finalmenu[i].n)\
  861. \009\009end\
  862. \009end\
  863. \009return finalmenu, sx, sy\
  864. end\
  865. function drawMenuClick(mop)\
  866. \009local _, dny = term.getCursorPos()\
  867. \009local dnx = inmenux+1\
  868. \009sbc(colors.gray)\
  869. \009stc(colors.black)\
  870. \009write(mop.n)\
  871. \009sleep(0.2)\
  872. \009scp(dnx,dny)\
  873. \009sbc(colors.lightGray)\
  874. \009stc(colors.white)\
  875. \009write(mop.n)\
  876. end\
  877. function updatemenu(e,menu,sx,sy,clrfunc)\
  878. \009if(e[1] == \"mouse_click\")then\
  879. \009\009local x, y = e[3], e[4]\
  880. \009\009local mlen = #menu[1].n-1\
  881. \009\009if(x >= sx and x <= sx+mlen and y >= sy+1 and y <= sy+#menu)then\
  882. \009\009\009 local clicked = menu[(y-sy)]\
  883. \009\009\009 scp(sx,y)\
  884. \009\009\009 drawMenuClick(clicked)\
  885. \009\009\009 clrfunc()\
  886. \009\009\009 e[1] = nil\
  887. \009\009\009 inmenu = false\
  888. \009\009\009 return clicked.func(files[file_selected])\
  889. \009\009else\
  890. \009\009\009clrfunc()\
  891. \009\009\009inmenu = false\
  892. \009\009end\
  893. \009end\
  894. end\
  895. function opencloseMenu(type,x,y,yind)\
  896. \009if(inmenu)then\
  897. \009\009undrawFiles()\
  898. \009\009drawFiles()\
  899. \009\009drawSideBar()\
  900. \009\009inmenu = false\
  901. \009elseif(type==\"reg\")then\
  902. \009\009local mtodraw = filemenu\
  903. \009\009if(fs.isDir(path:getraw() .. files[file_selected].n))then\
  904. \009\009\009mtodraw = foldermenu\
  905. \009\009end\
  906. \009\009drawingmenu = mtodraw\
  907. \009\009inmenutype, inmenux, inmenuy = drawfilemenu(mtodraw,x,y)\
  908. \009\009inmenu = true\
  909. \009elseif(type==\"sidebar\")then\
  910. \009\009drawingmenu = sidemenu\
  911. \009\009inmenutype, _, inmenuy = drawfilemenu(sidemenu,5,y)\
  912. \009\009inmenux = 5\
  913. \009\009inmenu = true\
  914. \009elseif(type==\"new\" and not fs.isReadOnly(path:getraw()) )then\
  915. \009\009drawingmenu = emptymenu\
  916. \009\009inmenutype,inmenux,inmenuy = drawfilemenu(emptymenu,x,y)\
  917. \009\009inmenu = true\
  918. \009end\
  919. end\
  920. local function update(e)\
  921. \009if(inmenu)then\
  922. \009\009updatemenu(e,inmenutype,inmenux,inmenuy,novaex_redraw)\
  923. \009end\
  924. \
  925. \009if(e[1] == \"disk\")then\
  926. \009\009getfiles()\
  927. \009\009drawFiles()\
  928. \009\009diskside = e[2]\
  929. \009\009if(fs.exists(\"disk/autorun\"))then\
  930. \009\009\009local ans = NovaAPI.openYesNo(\"Disk detected \",\"A software disk has been * detected. \",novaex_redraw,\"Run\",\"Cancel\")\
  931. \009\009\009if(ans == 1)then\
  932. \009\009\009\009runFile(\"disk/autorun\")\
  933. \009\009\009end\
  934. \009\009elseif(disk.hasAudio(e[2]))then\
  935. \009\009\009local ans = NovaAPI.openYesNo(\"Music detected \",\"A music disk has been * inserted. \",novaex_redraw,\"Play\",\"Cancel\")\
  936. \009\009\009if(ans == 1)then\
  937. \009\009\009\009disk.playAudio(e[2])\
  938. \009\009\009end\
  939. \009\009else\
  940. \009\009\009local ans = NovaAPI.openYesNo(\"Disk detected \",\"A floppy disk has been * inserted. \",novaex_redraw,\"Open\",\"Cancel\")\
  941. \009\009\009if(ans == 1)then\
  942. \009\009\009\009setDir(\"disk/\")\
  943. \009\009\009end\
  944. \009\009end\
  945. \009elseif(e[1] == \"disk_eject\")then\
  946. \009\009if(path:getraw():find(\"disk/\"))then\
  947. \009\009\009path:set(\"/\")\
  948. \009\009end\
  949. \009\009undrawFiles()\
  950. \009\009getfiles()\
  951. \009\009drawFiles()\
  952. \009end\
  953. \009if(e[1] == \"paste\")then\
  954. \009\009if(clipboard.name ~= nil)then\
  955. \009\009\009if(multiselecting)then\
  956. \009\009\009\009pasteMultiFile(path:getraw())\
  957. \009\009\009else\
  958. \009\009\009\009pasteFile(path:getraw())\
  959. \009\009\009end\
  960. \009\009end\
  961. \009end\
  962. \009if(e[1] == \"key\")then\
  963. \009\009local key = e[2] \
  964. \009\009if(key == actionkey and not actionkeydown)then\
  965. \009\009\009actionkeydown = true\
  966. \009\009elseif(actionkeydown)then\
  967. \009\009\009local opper = \"copy\"\
  968. \009\009\009if(key == keys.c or key == keys.x)then\
  969. \009\009\009\009if(key == keys.x)then opper = \"cut\" end\
  970. \009\009\009\009if(file_selected ~= 0)then\
  971. \009\009\009\009\009setClipboard(path:getraw() .. files[file_selected].n, \
  972. \009\009\009\009\009files[file_selected].n, opper)\
  973. \009\009\009\009end\
  974. \009\009\009end\
  975. \009\009end\
  976. \009\009if(file_selected > 0)then\
  977. \009\009\009if(key == keys.delete)then\
  978. \009\009 \009\009local ans = NovaAPI.openYesNo(\"File deletion. \",\"Confirm &4deletion&r of *\" .. files[file_selected].n,novaex_redraw)\
  979. \009\009 \009\009if(ans == 1)then\
  980. \009\009 \009\009\009deleteFile(path:getraw() .. files[file_selected].n)\
  981. \009\009 \009\009end\
  982. \009\009\009end\
  983. \009\009end\
  984. \009\009if(selectedside > 0)then\
  985. \009\009\009if(key == keys.up and sideitems[selectedside-1].t ~= nil and  \
  986. \009 \009\009   sideitems[selectedside-1].t ~= \"text\" )then\
  987. \009\009\009\009moveSideItem(selectedside,-1)\
  988. \009\009\009elseif(key == keys.down and (selectedside < #sideitems) and \
  989. \009 \009\009   (sideitems[selectedside+1].n ~= nil) and \
  990. \009 \009\009    sideitems[selectedside+1].t ~= \"text\" )then\
  991. \009\009\009\009moveSideItem(selectedside,1)\
  992. \009\009\009end\
  993. \009\009end\
  994. \009elseif(e[1] == \"key_up\")then\
  995. \009\009\009local key = e[2] \
  996. \009\009if(key == actionkey and actionkeydown )then\
  997. \009\009\009actionkeydown = false\
  998. \009\009end\
  999. \009end\
  1000. \009if(e[1] == \"mouse_click\")then\
  1001. \009\009 local x,y = e[3], e[4]    \
  1002. \009\009 -- Left clicked\
  1003. \009\009if(e[2] == 1)then\
  1004. \009\009\009if(x == w and y == 1)then\
  1005. \009\009\009\009clickExit()\
  1006. \009\009\009\009innova = false\
  1007. \009\009\009\009sbc(colors.white)\
  1008. \009\009\009\009clr()\
  1009. \009\009\009\009stc(colors.gray)\
  1010. \009\009\009\009writecy(\"Thank you for using Nova Explore. \",9)\
  1011. \009\009\009\009writecy(\"Click the screen to exit. \",10)\
  1012. \009\009\009\009os.pullEvent(\"mouse_click\")\
  1013. \009\009\009\009sbc(colors.black)\
  1014. \009\009\009\009clr()\
  1015. \009\009\009\009stc(colors.white)\
  1016. \009\009\009\009scp(1,1)\
  1017. \009\009\009\009return \
  1018. \009\009\009end\
  1019. \009\009\009if(x >= 11 and x <= 36 and y == 2)then\
  1020. \009\009\009\009NovaAPI.setInput(pathsearch)\
  1021. \009\009\009end\
  1022. \009\009 \009if(x >= 38 and x <= 51 and y == 2)then\
  1023. \009\009 \009\009NovaAPI.setInput(search)\
  1024. \009\009 \009\009searching = true\
  1025. \009\009 \009elseif(searching)then\
  1026. \009\009 \009\009search = NovaAPI.getInput()\
  1027. \009\009 \009\009searching = false\
  1028. \009\009 \009end\
  1029. \009\009 \009if(x >= 2 and x <= 4 and y == 2)then\
  1030. \009\009 \009\009if(inmenu)then inmenu = false end\
  1031. \009\009 \009\009prevDir(1)\
  1032. \009\009 \009end\
  1033. \009\009 \009if(x >= 6 and x <= 8 and y == 2)then\
  1034. \009\009 \009\009refreshDir()\
  1035. \009\009 \009end\
  1036. \009\009end \
  1037. \009\009-- Left or right clicked\
  1038. \009\009 \009local yind = (y+fileoffs)-4\
  1039. \009\009 \009local syind = (y+sideoffs)-4\
  1040. \009\009 \009if(x < 18 and syind <= #sideitems and syind > 0)then\
  1041. \009\009\009 \009 if(y > 4 and x >= 1 and x <= #(sideitems[syind].n:sub(1,14)) )then\
  1042. \009\009\009 \009   if(e[2] == 1 and not inmenu and sideitems[syind].t ~= \"text\")then\
  1043. \009\009\009\009 \009 \009if(fs.isDir(sideitems[syind].href))then\
  1044. \009\009\009\009 \009 \009    selectedside = syind\
  1045. \009\009\009\009 \009 \009  \009openHref(sideitems[syind].href)\
  1046. \009\009\009\009 \009 \009  \009drawSideBar()\
  1047. \009\009\009\009 \009 \009elseif(sideitems[syind].t ~= \"text\")then\
  1048. \009\009\009\009 \009 \009  \009if(selectedside == syind)then\
  1049. \009\009\009\009 \009 \009  \009 \009openHref(sideitems[syind].href)\
  1050. \009\009\009\009 \009 \009  \009else\
  1051. \009\009\009\009 \009 \009  \009    selectedside = syind\
  1052. \009\009\009\009 \009 \009  \009 \009drawSideBar()\
  1053. \009\009\009\009 \009 \009  \009end\
  1054. \009\009\009\009 \009 \009end\
  1055. \009\009\009\009   elseif(e[2] == 2)then\
  1056. \009\009\009\009   \009\009if(selectedside ~= 0  and sideitems[syind].t ~= \"text\" and yind == selectedside)then\
  1057. \009\009\009\009 \009 \009\009opencloseMenu(\"sidebar\",x,y)\009\
  1058. \009\009\009\009 \009 \009end\
  1059. \009\009\009 \009   end\
  1060. \009\009\009 \009 end\
  1061. \009\009\009 elseif(yind <= #files and yind > 0)then\
  1062. \009\009 \009 \009if(y > 4 and x >= 18 and x <= 22+#files[yind].n)then\
  1063. \009\009 \009 \009   if(e[2] == 1 and not inmenu)then\
  1064. \009\009\009 \009 \009  if(file_selected == yind)then\
  1065. \009\009\009\009 \009 \009  \009if(fs.isDir(path:getraw() .. files[file_selected].n))then\
  1066. \009\009\009\009 \009 \009  \009\009if(inmenu)then inmenu = false end\
  1067. \009\009\009\009 \009 \009  \009 \009addDir(files[yind].n)\
  1068. \009\009\009\009 \009 \009  \009 else\
  1069. \009\009\009\009 \009 \009  \009 \009runFile(path:getraw() .. files[file_selected].n)\
  1070. \009\009\009\009 \009 \009  \009end\
  1071. \009\009\009\009 \009 \009  else\
  1072. \009\009\009\009 \009 \009  \009 file_selected = yind\
  1073. \009\009\009\009 \009 \009  \009 drawFiles()\
  1074. \009\009\009\009 \009 \009  \009 drawPathSearch()\
  1075. \009\009\009\009 \009 \009  end\
  1076. \009\009\009 \009   elseif(e[2] == 2 )then\
  1077. \009\009\009 \009   \009   if(file_selected == yind)then\
  1078. \009\009\009 \009   \009   \009\009opencloseMenu(\"reg\",x,y,yind)\
  1079. \009\009\009 \009   \009   else\
  1080. \009\009\009 \009   \009   \009\009opencloseMenu(\"new\",x,y,yind)\
  1081. \009\009\009\009\009   end\
  1082. \009\009\009\009end\
  1083. \009\009 end\
  1084. \009\009end\
  1085. \009\009if(e[2] == 2 and not inmenu and x > 18)then\
  1086. \009\009 \009opencloseMenu(\"new\",x,y,1)\
  1087. \009\009end\
  1088. \009end\
  1089. \009if(e[1] == \"mouse_scroll\")then\
  1090. \009\009NovaAPI.setActive(false)\
  1091. \009\009local dir = e[2]\
  1092. \009\009local x,y = e[3], e[4]\
  1093. \009\009if(dir == -1)then\
  1094. \009\009\009if(x > 16 and fileoffs > 0 )then\
  1095. \009\009\009\009fileoffs = fileoffs - 1\
  1096. \009\009\009\009drawFiles()\
  1097. \009\009\009elseif(x <= 16 and sideoffs > 0)then\
  1098. \009\009\009\009sideoffs = sideoffs - 1\
  1099. \009\009\009\009drawSideBar()\
  1100. \009\009\009end\
  1101. \009\009elseif(dir == 1)then\
  1102. \009\009\009if(x > 16 and fileoffs < #files-(filemax-4))then\
  1103. \009\009\009\009fileoffs = fileoffs + 1\
  1104. \009\009\009\009drawFiles()\
  1105. \009\009\009elseif(x <= 16 and sideoffs < #sideitems-(sidemax-4))then\
  1106. \009\009\009\009sideoffs = sideoffs + 1\
  1107. \009\009\009\009drawSideBar()\
  1108. \009\009\009end\
  1109. \009\009end\
  1110. \009end\
  1111. \009if(pathsearch ~= \"\")then\
  1112. \009\009if(NovaAPI.getActive() == false)then\
  1113. \009\009\009drawPathSearch()\
  1114. \009\009end\
  1115. \009\009if(NovaAPI.getActive() == false and not searching)then\
  1116. \009\009\009if(NovaAPI.getInput() ~= pathsearch)then\
  1117. \009\009\009\009pathsearch = NovaAPI.getInput()\
  1118. \009\009\009\009NovaAPI.setInput(pathsearch) \
  1119. \009\009\009end\
  1120. \009\009end\
  1121. \009end\
  1122. \
  1123. \009\009-- Searching files/commands\
  1124. \
  1125. \009if(not searching)then\
  1126. \009\009stc(colors.black)\
  1127. \009\009sbc(colors.white)\
  1128. \009\009local doneinp = NovaAPI.novaread(e,1000,25,13,2)\
  1129. \009\009if(doneinp)then\
  1130. \009    \009NovaAPI.setActive(false)\
  1131. \009    \009term.setCursorBlink(false)\
  1132. \009    \009pathsearch = NovaAPI.getInput()\
  1133. \009    \009if( fs.isDir(NovaAPI.getInput()) )then\
  1134. \009\009\009\009if( setDir(NovaAPI.getInput()) )then\
  1135. \009\009\009\009\009selectedside = 0\
  1136. \009\009\009\009\009drawSideBar()\
  1137. \009\009\009\009end\
  1138. \009\009\009else\
  1139. \009\009\009\009--if(fs.exists(pathsearch))then\
  1140. \009\009\009\009\009term.setBackgroundColor(colors.black)\
  1141. \009\009\009\009\009term.setTextColor(colors.white)\
  1142. \009\009\009\009\009term.clear()\
  1143. \009\009\009\009\009term.setCursorPos(1, 1)\
  1144. \009\009\009\009\009shell.run(pathsearch)\
  1145. \009\009\009\009\009NovaAPI.setInput(pathsearch)\
  1146. \009\009\009\009\009writecy(\"Click any where to return to NovaBrowse. \",9)\
  1147. \009\009\009\009\009os.pullEvent(\"mouse_click\") \
  1148. \009\009\009\009\009NovaAPI.setInput(pathsearch)\
  1149. \009\009\009\009\009drawMain()\
  1150. \009\009\009\009\009getfiles()\
  1151. \009\009\009\009\009drawFiles()\
  1152. \009\009\009\009--end\
  1153. \009\
  1154. \009\009\009end\
  1155. \009\009end\
  1156. \009else\
  1157. \009\009stc(colors.black)\
  1158. \009\009sbc(colors.lightGray)\
  1159. \009\009local doneinp = NovaAPI.novaread(e,1000,10,40,2)\
  1160. \009\009if(doneinp)then\
  1161. \009\009\009searching = false\
  1162. \009    \009NovaAPI.setActive(false)\
  1163. \009    \009search = NovaAPI.getInput()\
  1164. \009    \009--if(fs.isDir(NovaAPI.getInput()))then\
  1165. \009    \009\009getfiles() -- to prevent \"nested\" searches.\
  1166. \009\009\009\009searchDir(NovaAPI.getInput()) \
  1167. \009\009\009\009--NovaAPI.setInput(\"\")\
  1168. \009\009\009--end\
  1169. \
  1170. \009\009end\
  1171. \009end\
  1172. end\
  1173. function displayError(err)\
  1174. \009sbc(colors.white)\
  1175. \009clr()\
  1176. \009stc(colors.gray)\
  1177. \009writecy(\" Well, thats not supposed to happen. \",1)\
  1178. \009scp(2,3)\
  1179. \009stc(colors.lightGray)\
  1180. \009write(err)\
  1181. \009writecy(\" Why you do dis to me :(. \",16)\
  1182. \009stc(colors.black)\
  1183. \009writecy(\" Press any key to end NovaExplore. \",17)\
  1184. \009writecy(\"  Click to restart NovaExplore. \",18)\
  1185. \009local e = {os.pullEvent()}\
  1186. \009if(e[1] == \"key\")then \
  1187. \009\009sbc(colors.black)\
  1188. \009\009clr()\
  1189. \009\009stc(colors.white)\
  1190. \009\009scp(1,1)\
  1191. \009elseif(e[1] == \"mouse_click\")then\
  1192. \009\009local odir = shell.dir()\
  1193. \009\009shell.setDir(\"\")\
  1194. \009\009shell.run(shell.resolveProgram(shell.getRunningProgram()))\
  1195. \009\009shell.setDir(odir)\
  1196. \009end\
  1197. end\
  1198. function clickExit()\
  1199. \009scp(w,1)\
  1200. \009stc(colors.black)\
  1201. \009sbc(colors.pink)\
  1202. \009write(\"X\")\
  1203. \009sleep(0.2)\
  1204. \009scp(w,1)\
  1205. \009stc(colors.white)\
  1206. \009sbc(colors.red)\
  1207. \009write(\"X\")\
  1208. end\
  1209. function checkUpdate()\
  1210. \009if(http)then\
  1211. \009\009local upd = http.get(\"http://pastebin.com/raw/rpipr5pT\")\
  1212. \009\009if(upd ~= nil)then\
  1213. \009\009\009local cont = upd.readAll()\
  1214. \009\009\009local f = fs.open(shell.getRunningProgram(),\"r\")\
  1215. \009\009\009local pcont = f.readAll()\
  1216. \009\009\009f.close()\
  1217. \009\009\009if(cont ~= pcont)then\
  1218. \009\009\009\009local ans = NovaAPI.openYesNo(\"Auto update\", \"Update detected, would you * like to update?.\",novaex_redraw)\
  1219. \009\009\009\009if(ans == 1)then\
  1220. \009\009\009\009\009local f = fs.open(shell.getRunningProgram(),\"w\")\
  1221. \009\009\009\009\009f.write(cont)\
  1222. \009\009\009\009\009f.close()\
  1223. \009\009\009\009\009NovaAPI.notify(\"Auto update\", \"Updated, restart required.\",novaex_redraw)\
  1224. \009\009\009\009\009innova = false\
  1225. \009\009\009\009\009return shell.run(shell.resolveProgram(shell.getRunningProgram()))\
  1226. \009\009\009\009end\
  1227. \009\009\009end\
  1228. \009\009else\
  1229. \009\009\009NovaAPI.notify(\"Auto update\", \"Failed to connect to pastebin.\",novaex_redraw)\
  1230. \009\009end\
  1231. \009else\
  1232. \009\009NovaAPI.notify(\"Auto update\", \"Http is disabled, Failed to * check for updates.\",novaex_redraw)\
  1233. \009\009return\
  1234. \009end\
  1235. end\
  1236. function drawMain()\
  1237. \009sbc(colors.white)\
  1238. \009clr()\
  1239. \009scp(1,2)\
  1240. \009sbc(colors.lightGray)\
  1241. \009clrln()\
  1242. \009pa.drawBox(w-12,1,w,3,colors.gray)\
  1243. \009sbc(colors.white)\
  1244. \009writexy(string.rep(\" \",w-12),1,2)\
  1245. \009pa.drawBox(10,1,w-12,3,colors.gray)\
  1246. \009drawSideBar()\
  1247. \009pa.drawFilledBox(1,1,9,3,colors.lightGray)\
  1248. \009scp(2,2)\
  1249. \009stc(colors.gray)\
  1250. \009write(\"<-  <>\")\
  1251. \009--pa.drawBox(15,h,w,h,colors.lightGray)\
  1252. \009pa.drawBox(w,4,w,h,colors.lightGray)\
  1253. \009stc(colors.gray)\
  1254. \009writexy(\"^\",w,4)\
  1255. \009writexy(\"v\",w,h)\
  1256. \009scp(w,1)\
  1257. \009stc(colors.white)\
  1258. \009sbc(colors.red)\
  1259. \009write(\"X\")\
  1260. \009sbc(colors.black)\
  1261. end\
  1262. drawMain()\
  1263. getConfigPinnedItems()\
  1264. getPinnedNames()\
  1265. drawSideBar()\
  1266. getfiles()\
  1267. drawFiles()\
  1268. checkUpdate()\
  1269. \
  1270. local function loop()\
  1271. \009while innova do \
  1272. \009\009local e = {os.pullEvent()}\
  1273. \009\009update(e)\
  1274. \009end\
  1275. end\
  1276. local ok, err = pcall(loop)\
  1277. if(not ok)then\
  1278. \009if(term.current().setVisible)then\
  1279. \009\009term.current().setVisible(true)\
  1280. \009end\
  1281. \009displayError(err)\
  1282. end",
  1283.   },
  1284.   [ "NovaAPI/" ] = {
  1285.     content = "local w, h = term.getSize()\
  1286. local sbc = term.setBackgroundColor\
  1287. local stc = term.setTextColor\
  1288. local scp = term.setCursorPos\
  1289. local clr = term.clear\
  1290. local clrln = term.clearLine\
  1291. local shell = {}\
  1292. local str = \"\"\
  1293. local active = true\
  1294. local inputindex = #str\
  1295. local cursorX = #str\
  1296. local viewX = 1\
  1297. \
  1298. local function path_goback(path,amm)\
  1299.    pathtbl={}\
  1300.    s=\"\"\
  1301.    pathsize=0\
  1302.    -- Divide string and count the number of \
  1303.    -- divisions.\
  1304.     for str in string.gmatch(path, \"([^/]+)\") do\
  1305.         pathtbl[#pathtbl+1] = str  \
  1306.     end\
  1307.     for k, v in pairs(pathtbl) do\
  1308.         pathsize=k\
  1309.     end\
  1310.     pathsize = pathsize - amm\
  1311.    -- Split string into words based on seperator.\
  1312.    pathtbl={}\
  1313.    for str in string.gmatch(path, \"([^/]+)\") do\
  1314.        pathtbl[#pathtbl+1] = str  \
  1315.    end\
  1316.    -- Based on how large the user wants the string to be \
  1317.    -- add only the string bits that led up to the user defined\
  1318.    -- size.\
  1319.    for k, v in pairs(pathtbl) do\
  1320.        if(k <= pathsize)then s = s..pathtbl[k]..\"/\" end\
  1321.    end\
  1322.    return s\
  1323. end\
  1324. local function path_getsize(path)\
  1325.    pathtbl={}\
  1326.    pathsize=0\
  1327.    -- Divide string and count the number of \
  1328.    -- divisions.\
  1329.     for str in string.gmatch(path, \"([^/]+)\") do\
  1330.         pathtbl[#pathtbl+1] = str  \
  1331.     end\
  1332.     for k, v in pairs(pathtbl) do\
  1333.         pathsize=k\
  1334.     end\
  1335.     return pathsize\
  1336. end\
  1337. \
  1338. function newpath(name,stuckindex)\
  1339.    if(name == nil or type(name) ~= \"string\")then error(\"PathAPI: Name must be provided for new paths. \") end\
  1340.    if(string.sub(name,#name,#name) ~= \"/\")then\
  1341.        name = name .. \"/\"\
  1342.    end\
  1343.    if(type(stuckindex) ~= \"number\")then stuckindex = 0 end\
  1344.    local pathobj = {\
  1345.        path = name,\
  1346.        stuckind = stuckindex,\
  1347.        getsize = function(self)\
  1348.           return path_getsize(self.path)\
  1349.        end,\
  1350.        goback = function(self,amm)\
  1351.            if(self:getsize() - amm >= self.stuckind)then\
  1352.               self.path = path_goback(self.path,amm)\
  1353.               return self.path\
  1354.            else\
  1355.                return false\
  1356.            end\
  1357.        end,\
  1358.        getraw = function(self)\
  1359.            return self.path\
  1360.        end,\
  1361.        add = function(self,new)\
  1362.            self.path = self.path .. new .. \"/\"\
  1363.            return self.path\
  1364.        end,\
  1365.        set = function(self,npath)\
  1366.            self.path = npath\
  1367.            return self.path\
  1368.        end,\
  1369.        lockpath = function(self)\
  1370.            self.stuckind = self:getsize()\
  1371.        end,\
  1372.        unlockpath = function(self)\
  1373.            self.stuckind = 0\
  1374.        end,\
  1375.    }\
  1376.    return pathobj\
  1377. end\
  1378. \
  1379. ------------------------------------------------\
  1380. --]] futils - API\
  1381. ------------------------------------------------\
  1382. \
  1383. function file_readAll(file,s)\
  1384.    local f = fs.open(file,\"r\")\
  1385.    local cont = f.readAll()\
  1386.    f.close()\
  1387.    if(s)then return textutils.unserialize(s) end\
  1388.    return cont\
  1389. end\
  1390. function file_readLine(file,s)\
  1391.    local f = fs.open(file,\"r\")\
  1392.    local cont = f.readLine()\
  1393.    f.close()\
  1394.    if(s)then return textutils.unserialize(s) end\
  1395.    return cont\
  1396. end\
  1397. function file_write(file,data,s)\
  1398.    local f = fs.open(file,\"w\")\
  1399.    if(s)then f.write(textutils.serialize(data)) else\
  1400.    f.write(data) end\
  1401.    f.close()\
  1402. end\
  1403. function file_writeline(file,data,s)\
  1404.    local f = fs.open(file,\"w\")\
  1405.    if(s)then f.writeLine(textutils.serialize(data)) else\
  1406.    f.writeLine(data) end\
  1407.    f.close()\
  1408. end\
  1409. local function formatpath(path)\
  1410.    local pathtbl={}\
  1411.    local s=\"\"\
  1412.    local pathsize=0\
  1413.    -- Divide string and count the number of \
  1414.    -- divisions.\
  1415.     for str in string.gmatch(path, \"([^/]+)\") do\
  1416.         pathtbl[#pathtbl+1] = str  \
  1417.     end\
  1418.     table.remove(pathtbl,1)\
  1419.     for i = 1, #pathtbl do\
  1420.        s = s .. pathtbl[i] .. \"/\"\
  1421.     end\
  1422.    return s\
  1423. end\
  1424. \
  1425. local function getcontent(data,wdata,ctbl)\
  1426.    -- Returns a table --\
  1427.    for k, v in pairs(fs.list(data)) do\
  1428.     \
  1429.      if(fs.isDir(data..\"/\"..v) )then\
  1430.        getcontent(data..v..\"/\",v..\"/\",ctbl)\
  1431.      else\
  1432.      --print(data..v)\
  1433.        local f = fs.open(data..v,\"r\")\
  1434.        ctbl[formatpath(data..v)] = {content=f.readAll()}\
  1435.        f.close()\
  1436.      end\
  1437.    end\
  1438.     return textutils.serialize(ctbl)\
  1439. end\
  1440. function archive(data,export)\
  1441.    local content = {}\
  1442.    content = getcontent('/' .. data .. \"/\",\"/\",content)\
  1443.    file_write(export,content)\
  1444.    return true\
  1445. end\
  1446. \
  1447. function extract(file,to)\
  1448.    local cont = textutils.unserialize(file_readAll(file))\
  1449.    for k,v in pairs(cont) do\
  1450.         file_write(to .. \"/\" .. k,v.content)\
  1451.    end\
  1452. end\
  1453. \
  1454. -----------------------------------------------------------------------\
  1455. --]] Read - API, HUGE thanks to Valithor for pretty much re-writing it\
  1456. -----------------------------------------------------------------------\
  1457. \
  1458. local function setStartStr(nstr)\
  1459.    str = nstr\
  1460. end\
  1461. function novaread(e,maxlen,mslen,x,y)\
  1462.    term.setCursorBlink(active)\
  1463.    local function drawstr()\
  1464.        term.setCursorPos(x,y)\
  1465.        write(string.rep(\" \",mslen+1))\
  1466.        term.setCursorPos(x,y)       \
  1467.      term.write(str:sub(viewX,viewX+mslen))\
  1468.      if(cursorX ~= #str and (cursorX+1) < mslen)then\
  1469.          term.setCursorPos((cursorX+1)+x,y)\
  1470.      else\
  1471.          term.setCursorPos((cursorX)+x,y)\
  1472.      end\
  1473.    end\
  1474.    local function undrawstr()\
  1475.        term.setCursorPos(x,y)\
  1476.        write(string.rep(\" \",mslen))\
  1477.    end\
  1478.    local function updatestr()\
  1479.        inputindex = inputindex + 1\
  1480.        drawstr()\
  1481.    end\
  1482.    if(active)then\
  1483.        if(e[1] == \"char\" and #str < maxlen)then\
  1484.            if cursorX < mslen and cursorX < #str then\
  1485.              cursorX = cursorX+1\
  1486.            end\
  1487.            if cursorX == mslen and viewX <= #str-mslen then\
  1488.              viewX = viewX+1\
  1489.            end\
  1490.            str = str:sub(1,inputindex) .. tostring(e[2]) .. str:sub(inputindex+1,#str)\
  1491.            updatestr()\
  1492.        end\
  1493.        if(e[1] == \"key\")then\
  1494.            local key = e[2]\
  1495.             if(key == keys.enter)then\
  1496.                term.setCursorBlink(false)\
  1497.                active = false\
  1498.                return true\
  1499.             end\
  1500.             if(key == keys.backspace and inputindex > 0)then\
  1501.             undrawstr()\
  1502.              if cursorX > 0 then\
  1503.                cursorX = cursorX-1\
  1504.              end\
  1505.              if cursorX == 0 and viewX > 0 then\
  1506.                viewX = viewX-1\
  1507.              end\
  1508.                 str =  string.sub( str, 1, inputindex - 1 ) .. string.sub( str, inputindex + 1 )\
  1509.                 inputindex = inputindex - 1\
  1510.                 drawstr()\
  1511.             end\
  1512.             if(key == keys.left and inputindex > 0)then\
  1513.                 inputindex = inputindex - 1 --\
  1514.                  if cursorX > 0 then\
  1515.                    cursorX = cursorX-1\
  1516.                  end\
  1517.                  if cursorX == 0 and viewX > 0 then\
  1518.                    viewX = viewX-1\
  1519.                  end\
  1520.                 drawstr()\
  1521.             end\
  1522.             if(key == keys.right and inputindex < #str)then\
  1523.                 inputindex = inputindex + 1\
  1524.                  if cursorX < mslen and viewX+cursorX<#str+x then\
  1525.                    cursorX = cursorX+1        \
  1526.                  end\
  1527.                  if cursorX == mslen and viewX < #str-mslen then\
  1528.                    viewX = viewX+1\
  1529.                  end\
  1530.                 drawstr()\
  1531.             end\
  1532.             if(key == keys.delete and inputindex < #str)then\
  1533.                  if cursorX > mslen then\
  1534.                    cursorX = cursorX+1\
  1535.                  end\
  1536.                 undrawstr()\
  1537.                 str = string.sub( str, 1, inputindex ) .. string.sub( str, inputindex + 2 )\
  1538.                 drawstr()\
  1539.             end\
  1540.        end\
  1541.    end\
  1542.    if(e[1] == \"mouse_click\" and (e[4] ~= y or e[3] < x or e[3] > x+maxlen) )then\
  1543.        active = false\
  1544.        term.setCursorBlink(false)\
  1545.    elseif(e[1] == \"mouse_click\" and e[4] == y)then\
  1546.        if(not active)then\
  1547.            active = true\
  1548.            term.setCursorPos(x+inputindex,y)\
  1549.            term.setCursorBlink(true)\
  1550.            drawstr()\
  1551.        end\
  1552.        if(e[3]-x >= 0 and e[3]<=#str) then\
  1553.            -- Broken until furthur notice - Lewisk -- \
  1554.            --inputindex = (viewX+e[3])-x\
  1555.            --cursorX = e[3]-x\
  1556.            --drawstr()\
  1557.        end\
  1558.    end\
  1559. end\
  1560. function getInput()\
  1561.    return str\
  1562. end\
  1563. function resetInput()\
  1564.    str = \"\"\
  1565.    inputindex = #str\
  1566.    cursorX = #str\
  1567. end\
  1568. function setInput(nstr)\
  1569.    str = nstr\
  1570.    inputindex = #str\
  1571.    cursorX = #str\
  1572. end\
  1573. function setActive(act)\
  1574.    active = act\
  1575. end\
  1576. function getActive()\
  1577.    return active\
  1578. end\
  1579. \
  1580. function readEx(mlen,scroll,startw)\
  1581.    setActive(false)\
  1582.    if(startw == nil)then startw = \"\" end\
  1583.    setInput(startw)\
  1584.    local x, y = term.getCursorPos()\
  1585.    local readxoff = x\
  1586.    if(startw ~= \"\")then\
  1587.        scp(readxoff,y)\
  1588.        write(getInput())\
  1589.    end\
  1590.    local oinp = getInput()\
  1591.    local ininp = true\
  1592.    if(scroll)then\
  1593.        mslen = 1000\
  1594.    else\
  1595.        mslen = mlen+1\
  1596.    end\
  1597.    term.setCursorBlink(true)\
  1598.    while ininp do\
  1599.        local e = {os.pullEvent()}\
  1600.        local inp = novaread(e,mslen,mlen-1,readxoff,y)\
  1601.        setActive(true)\
  1602.        if(inp)then \
  1603.            ininp = false\
  1604.            setActive(false)\
  1605.            local inp = getInput()\
  1606.            setInput(oinp)\
  1607.            if(inp == startw)then\
  1608.                inp = \"\"\
  1609.            end\
  1610.            return inp\
  1611.        end\
  1612.        -- Dont let the user out of the read!\
  1613.        if(getActive() == \"false\")then setActive(true) end\
  1614.    end\
  1615. end\
  1616. \
  1617. \
  1618. \
  1619. ------------------------------------------------\
  1620. --]] Utils - API\
  1621. ------------------------------------------------\
  1622. \
  1623. function init(nshell)\
  1624.    shell = nshell\
  1625. end\
  1626. \
  1627. function openReadDialog(title,clrfunc,startread)\
  1628.    local bw, bh = 30,0\
  1629.    local sx, sy = w/2-math.ceil(bw/2), (h/2)-math.ceil(bh/2)-1\
  1630.    local ex, ey = w/2+math.ceil(bw/2), (h/2)+math.floor(bh/2)-1\
  1631.    paintutils.drawFilledBox(sx+1,sy,ex+2,ey+2,colors.black)\
  1632.    paintutils.drawFilledBox(sx,sy,ex,ey,colors.lightGray)\
  1633.    paintutils.drawBox(sx-1,sy-1,ex+1,ey+1,colors.gray)\
  1634.    scp(sx,sy-1)\
  1635.    stc(colors.white)\
  1636.    write(title)\
  1637.    scp(sx,sy)\
  1638.    sbc(colors.lightGray)\
  1639.    local inp = readEx(30,true,startread)\
  1640.    clrfunc()\
  1641.    return inp\
  1642. end\
  1643. \
  1644. function notify(title,txt,clrfunc)\
  1645.    local bw, bh = 30,5\
  1646.    local sx, sy = w/2-math.ceil(bw/2), (h/2)-math.ceil(bh/2)+2\
  1647.    local ex, ey = w/2+math.ceil(bw/2), (h/2)+math.floor(bh/2)+1\
  1648.    paintutils.drawLine(sx,sy-1,ex,sy-1,colors.gray)\
  1649.    paintutils.drawFilledBox(sx+1,sy+1,ex+1,ey+1,colors.black)\
  1650.    paintutils.drawFilledBox(sx,sy,ex,ey,colors.lightGray)\
  1651.    scp(sx,sy-1)\
  1652.    stc(colors.white)\
  1653.    sbc(colors.gray)\
  1654.    write(title)\
  1655.    sbc(colors.lightGray)\
  1656.    local msg = {}\
  1657.     for str in string.gmatch(txt, \"([^*]+)\") do\
  1658.         msg[#msg+1] = str  \
  1659.     end\
  1660.     for i = 1, #msg do\
  1661.        sbc(colors.lightGray)\
  1662.        colorwrite(\" \" .. msg[i],45,sx,sy+i)\
  1663.     end\
  1664.     colorwrite(\"&4Click&r to close. \",45,sx+8,sy+#msg+2)\
  1665.    os.pullEvent(\"mouse_click\")\
  1666.    clrfunc()\
  1667. end\
  1668. function openYesNo(title,txt,clrfunc,y,n)\
  1669.    if(y == nil or n == nil)then \
  1670.         y = \"Yes\"\
  1671.         n = \"No\"\
  1672.    end\
  1673.    local ynm = {y, n}\
  1674.    local inynm = true\
  1675.    local bw, bh = 30,5\
  1676.    local opinc = 9\
  1677.    local sx, sy = w/2-math.ceil(bw/2), (h/2)-math.ceil(bh/2)+2\
  1678.    local ex, ey = w/2+math.ceil(bw/2), (h/2)+math.floor(bh/2)+1\
  1679.    paintutils.drawLine(sx,sy-1,ex,sy-1,colors.gray)\
  1680.    paintutils.drawFilledBox(sx+1,sy+1,ex+1,ey+1,colors.black)\
  1681.    paintutils.drawFilledBox(sx,sy,ex,ey,colors.lightGray)\
  1682.    scp(sx,sy-1)\
  1683.    stc(colors.white)\
  1684.    sbc(colors.gray)\
  1685.    write(title)\
  1686.    sbc(colors.lightGray)\
  1687.     local msg = {}\
  1688.     for str in string.gmatch(txt, \"([^*]+)\") do\
  1689.         msg[#msg+1] = str  \
  1690.     end\
  1691.     for i = 1, #msg do\
  1692.        sbc(colors.lightGray)\
  1693.        colorwrite(\" \" .. msg[i],45,sx,sy+i)\
  1694.     end\
  1695.    stc(colors.white)\
  1696.    local function drawm()\
  1697.          for i = 1, #ynm do\
  1698.                sbc(colors.red)\
  1699.                if(i==1)then\
  1700.                    sbc(colors.green)\
  1701.                end\
  1702.                scp(sx+(i*opinc),ey-1)\
  1703.                write(ynm[i])\
  1704.          end\
  1705.    end\
  1706.    local function drawmopt(id,clk)\
  1707.         sbc(colors.red)\
  1708.         if(i==1)then\
  1709.            sbc(colors.green)\
  1710.         end\
  1711.         if(clk)then sbc(colors.gray) end\
  1712.         scp(sx+(id*opinc),ey-1)\
  1713.         write(ynm[id])\
  1714.         sleep(0.2)\
  1715.    end\
  1716.    local function mupdate()\
  1717.        while inynm do\
  1718.            local ev = {os.pullEvent()}\
  1719.            if(ev[1] == \"mouse_click\")then\
  1720.                local x, y = ev[3], ev[4]\
  1721.                for i = 1, #ynm do\
  1722.                    if( x >= sx+(i*opinc)-1 and x <= sx+(i*opinc)+#ynm[i] and y == math.floor(ey-1) )then\
  1723.                        inynm = false\
  1724.                        drawmopt(i,true)\
  1725.                        return i\
  1726.                    end\
  1727.                end\
  1728.            end\
  1729.        end\
  1730.    end\
  1731.    drawm()\
  1732.    local res = mupdate()\
  1733.    clrfunc()\
  1734.    return res\
  1735. end\
  1736. \
  1737. function isFileImage(file)\
  1738.    local isImg = false\
  1739.    local f = fs.open(file,\"r\")\
  1740.    if(f)then\
  1741.        if(tonumber(f.readAll():gsub(\"%s+\",\"\"),16) ~= nil) then\
  1742.             isImg = true\
  1743.        end\
  1744.        f.close()\
  1745.    end\
  1746.    return isImg\
  1747. end\
  1748. \
  1749. function getApisFrom(loc,apis)\
  1750.    local inloc = false\
  1751.    if(fs.isDir(loc))then\
  1752.        inloc = true\
  1753.        for i = 1, #apis do\
  1754.                if(fs.exists(\"CrossBow/apis/\"..apis[i]))then\
  1755.                    apis[i] = \"CrossBow/apis/\" ..apis[i]\
  1756. \
  1757.                else\
  1758.                    error(\"Program had to Quit: CrossBow install outdated or malformed. \")\
  1759.                end\
  1760.        end \
  1761.    end\
  1762. \
  1763.    for i = 1, #apis do\
  1764.        if(inloc)then\
  1765.            os.loadAPI((apis[i]))\
  1766.        else\
  1767.            os.loadAPI(shell.resolveProgram((apis[i])))\
  1768.        end\
  1769.    end\
  1770. \
  1771.    return inloc\
  1772. end\
  1773. \
  1774. function colorwrite(str,smax,x,y,special)\
  1775.    scp(x,y)\
  1776.        local colorencode = {\
  1777.        ['&r'] = \"black\",\
  1778.        ['&1'] = \"blue\",\
  1779.        ['&2'] = \"green\",\
  1780.        ['&3'] = \"cyan\",\
  1781.        ['&4'] = \"red\",\
  1782.        ['&5'] = \"purple\",\
  1783.        ['&6'] = \"brown\",\
  1784.        ['&7'] = \"lightGray\",\
  1785.        ['&8'] = \"gray\",\
  1786.        ['&9'] = \"lightBlue\",\
  1787.        ['&a'] = \"lime\",\
  1788.        ['&b'] = \"orange\",\
  1789.        ['&c'] = \"pink\",\
  1790.        ['&d'] = \"magenta\",\
  1791.        ['&e'] = \"yellow\",\
  1792.        ['&f'] = \"white\",\
  1793.    }\
  1794.    if(special)then sbc(special) end\
  1795.    for a = 1, #str do\
  1796.        if(string.sub(str,a,a) == \"&\")then\
  1797.            if(colorencode[string.sub(str,a,a+1)] ~= nil)then\
  1798.                stc(colors[colorencode[string.sub(str,a,a+1)]])\
  1799.            end\
  1800.            str = string.sub(str,1,a-1) .. string.sub(str,a+1,#str)\
  1801.        else\
  1802.            write(string.sub(str,a,a))\
  1803.        end\
  1804.    end  \
  1805.    sbc(colors.white)\
  1806. end\
  1807. \
  1808. ------------------------------------------------\
  1809. --]] Zip - API\
  1810. ------------------------------------------------\
  1811. \
  1812. local function formatpath(path)\
  1813.    local pathtbl={}\
  1814.    local s=\"\"\
  1815.    local pathsize=0\
  1816.    -- Divide string and count the number of \
  1817.    -- divisions.\
  1818.     for str in string.gmatch(path, \"([^/]+)\") do\
  1819.         pathtbl[#pathtbl+1] = str  \
  1820.     end\
  1821.     for k, v in pairs(pathtbl) do\
  1822.         pathsize=k\
  1823.     end\
  1824.     pathsize = pathsize - 1\
  1825.    -- Based on how large the user wants the string to be \
  1826.    -- add only the string bits that led up to the user defined\
  1827.    -- size.\
  1828.    for k, v in pairs(pathtbl) do\
  1829.        if(k <= pathsize)then s = s..pathtbl[k]..\"/\" end\
  1830.    end\
  1831.    return s\
  1832. end\
  1833. local function pathlen(path)\
  1834.    local pathtbl={}\
  1835.    local s=\"\"\
  1836.    local pathsize=0\
  1837.    -- Divide string and count the number of \
  1838.    -- divisions.\
  1839.     for str in string.gmatch(path, \"([^/]+)\") do\
  1840.         pathtbl[#pathtbl+1] = str  \
  1841.     end\
  1842.     return #pathtbl\
  1843. end\
  1844. local function filterdirpath(dir,path)\
  1845.    local pathtbl={}\
  1846.    local s=\"\"\
  1847.    local pathsize=0\
  1848.    -- Divide string and count the number of \
  1849.    -- divisions.\
  1850.     local la = 0\
  1851.     for str in string.gmatch(path, \"([^/]+)\") do\
  1852.        if(la >= pathlen(dir))then\
  1853.            pathtbl[#pathtbl+1] = str  \
  1854.        end\
  1855.        la = la + 1\
  1856.     end\
  1857.        for i = 1, #pathtbl do\
  1858.            s  = s .. pathtbl[i] .. \"/\"\
  1859.        end \
  1860.    return s\
  1861. end\
  1862. local function comparesubpath(flpath,subpath)\
  1863.    return (formatpath(subpath) == flpath) or (subpath:find(flpath) and pathlen(formatpath(subpath)) == pathlen(flpath)+1 )\
  1864. end\
  1865. local function comparefolderpath(flpath,subpath)\
  1866.    return \
  1867. end\
  1868. local function getend(path)\
  1869.    local pathtbl={}\
  1870.    local s=\"\"\
  1871.    local pathsize=0\
  1872.    -- Divide string and count the number of \
  1873.    -- divisions.\
  1874.     for str in string.gmatch(path, \"([^/]+)\") do\
  1875.         pathtbl[#pathtbl+1] = str  \
  1876.     end\
  1877.     return pathtbl[#pathtbl]\
  1878. end\
  1879. function iszip(file)\
  1880.    local f = fs.open(file,\"r\")\
  1881.    local c = f.readAll()\
  1882.    f.close()\
  1883.    return type(c) == \"table\"\
  1884. end\
  1885. local function intable(tbl,am)\
  1886.    for i = 1, #tbl do\
  1887.        if(tbl[i].n == am)then\
  1888.            return true\
  1889.        end\
  1890.    end\
  1891.    return false \
  1892. end\
  1893. function ziplist(zip,dir)\
  1894.    local folders = {}\
  1895.    local files = {}\
  1896.    local list = {}\
  1897.    local startls = false\
  1898.    local f = fs.open(zip,\"r\")\
  1899.    local c = (f.readAll())\
  1900.    c = textutils.unserialize(c)\
  1901.    f.close()\
  1902.    for k, v in pairs(c) do\
  1903.        if(comparesubpath(dir,k))then\
  1904.            if(pathlen(formatpath(k)) == pathlen(dir))then\
  1905.                files[getend(k)] = {t=\"file\",c=v.content}\
  1906.                --print(\"File:\" .. getend(k))\
  1907.                --print(\"------------------\")\
  1908.                --os.pullEvent(\"key\")\
  1909.            elseif(pathlen(formatpath(k)) < 2+pathlen(dir) and \
  1910.            not intable(folders,filterdirpath(dir,formatpath(k))))then\
  1911.                folders[#folders+1] = {n=filterdirpath(dir,formatpath(k)),t=\"folder\",c=v.content}\
  1912.                --print(\"Folder: \" .. filterdirpath(dir,formatpath(k)))\
  1913.                --os.pullEvent(\"key\")\
  1914.            end\
  1915.        end\
  1916.    end\
  1917.    for k, v in pairs(files) do\
  1918.        folders[#folders+1] = {n=k,type=v.t,data=v.c}\
  1919.    end\
  1920.    for i = 1, #folders do\
  1921.        list[i] = {n=folders[i].n,type=folders[i].t,data=folders[i].c}\
  1922.    end\
  1923.    return list\
  1924. end",}
  1925. }
  1926.  
  1927. function file_write(file,data,s)
  1928.     local f = fs.open(file,"w")
  1929.     if(s)then f.write(textutils.serialize(data)) else
  1930.     f.write(data) end
  1931.     f.close()
  1932. end
  1933.  
  1934. write("Extract to: ")
  1935. local loc = read()
  1936. if(loc == "")then
  1937.   write("Extraction cancelled. ")
  1938. else
  1939.     local cont = textutils.serialize(content)
  1940.     for k,v in pairs(textutils.unserialize(cont)) do
  1941.           file_write(loc .. "/" .. k,v.content)
  1942.           print("Extracting " .. k .. " to " .. loc .. k)
  1943.     end
  1944.     print("Files extracted to: " .. loc)
  1945. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top