61 lines
2 KiB
Lua
61 lines
2 KiB
Lua
local dir = require "opendirectory"
|
||
|
||
-- 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=''
|
||
}
|
||
},
|
||
shouldHideFile = function(name)
|
||
return name == ".."
|
||
or name == "util" -- repository
|
||
or name == ".git" -- files
|
||
or name == "src" --
|
||
or name == "result" --
|
||
end,
|
||
|
||
scan = function()
|
||
local me = app.plugin.diskscan
|
||
local folder = app.opts.plugin_diskscan_dir
|
||
-- scan dirs
|
||
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
|
||
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}
|
||
}
|
||
app.pub("scan_experience", nil, experience)
|
||
print("ℹ️ ".. fullpath)
|
||
|
||
-- scan files
|
||
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
|
||
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)
|
||
if not ferr then fref:close() end
|
||
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
|
||
}
|