2026-07-23 15:20:25 +02:00
|
|
|
|
local dir = require "opendirectory"
|
|
|
|
|
|
|
2026-07-23 18:17:55 +02:00
|
|
|
|
-- this registers the plugin UI /funcs
|
|
|
|
|
|
return {
|
|
|
|
|
|
name = "Content (from disk)",
|
2026-07-24 21:43:36 +02:00
|
|
|
|
info = '',
|
2026-07-23 18:17:55 +02:00
|
|
|
|
opts = {
|
|
|
|
|
|
{
|
|
|
|
|
|
key='app.opts.plugin_diskscan_dir',
|
|
|
|
|
|
title='Directory',
|
|
|
|
|
|
info="Directory to scan for experiences (use '.' for current) ",
|
2026-07-24 17:06:31 +02:00
|
|
|
|
default="./myverse",
|
2026-07-23 18:17:55 +02:00
|
|
|
|
values=''
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2026-07-23 15:20:25 +02:00
|
|
|
|
shouldHideFile = function(name)
|
2026-07-24 17:06:31 +02:00
|
|
|
|
return name == ".." -- parent
|
2026-07-23 15:20:25 +02:00
|
|
|
|
or name == "util" -- repository
|
2026-07-24 17:06:31 +02:00
|
|
|
|
or name:match("^%.") -- hidden
|
|
|
|
|
|
or name == "src" -- repository
|
|
|
|
|
|
or name == "result" -- repository
|
2026-07-23 15:20:25 +02:00
|
|
|
|
end,
|
|
|
|
|
|
|
2026-07-24 17:06:31 +02:00
|
|
|
|
scan = function(scandir,parent,seen)
|
|
|
|
|
|
seen = seen or {}
|
2026-07-23 18:17:55 +02:00
|
|
|
|
local me = app.plugin.diskscan
|
2026-07-23 15:20:25 +02:00
|
|
|
|
-- scan dirs
|
2026-07-24 17:06:31 +02:00
|
|
|
|
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)
|
2026-07-23 15:20:25 +02:00
|
|
|
|
app.pub("scan_experience", nil, experience)
|
2026-07-24 17:06:31 +02:00
|
|
|
|
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
|
2026-07-23 15:20:25 +02:00
|
|
|
|
print("ℹ️ ".. fullpath)
|
2026-07-24 17:06:31 +02:00
|
|
|
|
app.pub("scan_experience_file", nil, experience)
|
|
|
|
|
|
local size = attr:size()
|
2026-07-23 15:20:25 +02:00
|
|
|
|
end
|
2026-07-24 17:06:31 +02:00
|
|
|
|
|
2026-07-23 15:20:25 +02:00
|
|
|
|
end)
|
2026-07-23 18:17:55 +02:00
|
|
|
|
if not derr then dref:close() end
|
2026-07-23 15:20:25 +02:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
}
|