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)",
|
|
|
|
|
|
info = 'XRForge can search in (unnested) folders for XR/image/video files.',
|
|
|
|
|
|
opts = {
|
|
|
|
|
|
{
|
|
|
|
|
|
key='app.opts.plugin_diskscan_dir',
|
|
|
|
|
|
title='Directory',
|
|
|
|
|
|
info="Directory to scan for experiences (use '.' for current) ",
|
|
|
|
|
|
default=".",
|
|
|
|
|
|
values=''
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2026-07-23 15:20:25 +02:00
|
|
|
|
shouldHideFile = function(name)
|
|
|
|
|
|
return name == ".."
|
|
|
|
|
|
or name == "util" -- repository
|
|
|
|
|
|
or name == ".git" -- files
|
|
|
|
|
|
or name == "src" --
|
|
|
|
|
|
or name == "result" --
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
|
|
|
|
scan = function()
|
2026-07-23 18:17:55 +02:00
|
|
|
|
local me = app.plugin.diskscan
|
|
|
|
|
|
local folder = app.opts.plugin_diskscan_dir
|
2026-07-23 15:20:25 +02:00
|
|
|
|
-- scan dirs
|
2026-07-23 18:17:55 +02:00
|
|
|
|
local dref, derr= dir.foreach( folder, function(path,stat,state,name,kind,ino,off,attr,fullpath)
|
|
|
|
|
|
if (kind == unix.DT_DIR or kind == unix.DT_LNK) and not me.shouldHideFile(name) then
|
2026-07-23 15:20:25 +02:00
|
|
|
|
local experience = {
|
|
|
|
|
|
path = fullpath,
|
|
|
|
|
|
name = name,
|
2026-07-23 18:17:55 +02:00
|
|
|
|
title = name,
|
2026-07-23 15:20:25 +02:00
|
|
|
|
tag = {},
|
|
|
|
|
|
file = {stat=stat,state=state,kind=kind,ino=ino,off=off,attr=attr,fullpath=fullpath,name=name,path=path}
|
|
|
|
|
|
}
|
|
|
|
|
|
app.pub("scan_experience", nil, experience)
|
|
|
|
|
|
print("ℹ️ ".. fullpath)
|
|
|
|
|
|
|
|
|
|
|
|
-- scan files
|
2026-07-23 18:17:55 +02:00
|
|
|
|
local fref, ferr = dir.foreach(fullpath, function(path,stat,state,name,kind,ino,off,attr, fullpath)
|
|
|
|
|
|
if kind ~= unix.DT_DIR and not me.shouldHideFile(name) then
|
2026-07-23 15:20:25 +02:00
|
|
|
|
experience.file = {stat=stat,state=state,kind=kind,ino=ino,off=off,attr=attr,fullpath=fullpath,name=name,path=path}
|
|
|
|
|
|
app.pub("scan_experience_file", nil, experience)
|
|
|
|
|
|
local size = attr:size()
|
|
|
|
|
|
trace("ℹ️ ".. fullpath)
|
|
|
|
|
|
end
|
|
|
|
|
|
end)
|
2026-07-23 18:17:55 +02:00
|
|
|
|
if not ferr then fref:close() end
|
2026-07-23 15:20:25 +02:00
|
|
|
|
end
|
|
|
|
|
|
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
|
|
|
|
|
|
}
|