xrforge-v2/src/plugin/diskscan.lua

61 lines
2 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}