list functionality that is not even finished XD
This commit is contained in:
53
main.lua
53
main.lua
@@ -0,0 +1,53 @@
|
||||
-- http://justus.l--n.de:3000/JUFS/MDB/raw/branch/main/main.lua
|
||||
-- or use bootstrapper
|
||||
print("Copyright JUFS Technologies aka. Justus Wolff 2026")
|
||||
print("MDB - Multi disk Data Base")
|
||||
print("init API")
|
||||
|
||||
local API = {}
|
||||
function API.getDisks()
|
||||
local disks = {peripheral.find("drive")}
|
||||
local out = {}
|
||||
for _,v in pairs(disks) do
|
||||
if v.isDiskPresent() and v.hasData() then table.insert(out, v.getMountPath()) end
|
||||
end
|
||||
return out
|
||||
end
|
||||
function API._builtCandidateTree(...)
|
||||
local path = {...}
|
||||
local candidates = {}
|
||||
for _,v in pairs(API.getDisks()) do
|
||||
table.insert(candidates, fs.combine(v, fs.list(v)))
|
||||
end
|
||||
|
||||
for _,v in pairs(path) do
|
||||
local temp = {}
|
||||
for _,cc in pairs(candidates) do
|
||||
if fs.getName(cc) == v then
|
||||
table.insert(temp, cc)
|
||||
end
|
||||
end
|
||||
candidates = temp
|
||||
end
|
||||
|
||||
return candidates
|
||||
end
|
||||
function API.list(...)
|
||||
local final = {}
|
||||
for _,v in pairs(API._builtCandidateTree(...)) do
|
||||
table.insert(final, fs.list(v))
|
||||
end
|
||||
return final
|
||||
end
|
||||
|
||||
print("Disks: ")
|
||||
local disks = API.getDisks()
|
||||
for _,v in pairs(disks) do
|
||||
print(v..": "..tostring(fs.getFreeSpace()).."/"..tostring(fs.getCapacity()))
|
||||
end
|
||||
|
||||
for _,v in pairs(API.list()) do
|
||||
print(v)
|
||||
end
|
||||
|
||||
return API
|
||||
Reference in New Issue
Block a user