local dir = require "opendirectory" -- this registers the plugin UI /funcs return { name = "Content (from disk)", info = '', opts = { { key='app.opts.plugin_diskscan_dir', title='Directory', info="Directory to scan for experiences (use '.' for current) ", default="./myverse", values='' } }, shouldHideFile = function(name) return name == ".." -- parent or name == "util" -- repository or name:match("^%.") -- hidden or name == "src" -- repository or name == "result" -- repository end, scan = function(scandir,parent,seen) seen = seen or {} local me = app.plugin.diskscan -- scan dirs local dref, derr = dir.foreach( scandir, function(path,stat,state,name,kind,ino,off,attr,fullpath) local experience = { path = fullpath, name = name, title = name, tag = {}, file = {stat=stat,state=state,kind=kind,ino=ino,off=off,attr=attr,fullpath=fullpath,name=name,path=path} } -- found directory if not seen[ino] and (kind == unix.DT_DIR or kind == unix.DT_LNK) and not me.shouldHideFile(name) then seen[ino] = true -- prevent recursion with symlinks print("✅ ".. fullpath) app.pub("scan_experience", nil, experience) table.insert( app.cache.items, experience) me.scan(fullpath, dir,seen) end ---- found file if not seen[ino] and (kind ~= unix.DT_DIR and kind ~= unix.DT_LNK) and not me.shouldHideFile(name) then seen[ino] = true -- prevent recursion with symlinks print("ℹ️ ".. fullpath) app.pub("scan_experience_file", nil, experience) local size = attr:size() end end) if not derr then dref:close() end foreach( app.cache.items, function(k,v) -- remove file attributes (which are closed already) v.file.stat = nil v.file.attr = nil v.file.state = nil end) end }