This commit is contained in:
Astronand committed 2025-09-29 00:03:57 -04:00
1 parent 5111182a4b
commit abd573f686
64 files changed
+2407 -157

No files matched your search

+137
View File
@@ -0,0 +1,137 @@
local fss = {}
local object = {}
local uObject = {}
local function getFs(self)
return fss[tostring(self.__UDATA_id)]
end
local function normalize(path)
if path:sub(1,1)=="/" then
path=path:sub(2)
end
return path
end
function object:open(path)
path=normalize(path)
local f = getFs(self)
return {
read=function()
local file = fs.open(f..path, "r")
local text = file.readAll()
file.close()
return text
end,
write=function(text)
local file = fs.open(f..path, "w")
file.write(text)
file.close()
end,
append=function(text)
local file = fs.open(f..path, "a")
file.write(text)
file.close()
end
}
end
function object:list(path)
path=normalize(path)
local f = getFs(self)
return fs.list(f..path)
end
function object:fileExists(path)
path=normalize(path)
local f = getFs(self)
return fs.exists(f..path) and not fs.isDir(f..path)
end
function object:directoryExists(path)
path=normalize(path)
local f = getFs(self)
return fs.exists(f..path) and fs.isDir(f..path)
end
function object:makeDirectory(path)
path=normalize(path)
local f = getFs(self)
fs.makeDir(f..path)
end
function object:delete(path)
path=normalize(path)
local f = getFs(self)
fs.delete(f..path)
end
function object:getSize(path)
path=normalize(path)
local f = getFs(self)
return fs.getSize(f..path)
end
function uObject:readBytes(start, length)
local f = getFs(self)
local file=fs.open(f, "r")
local data=fs.readAll()
file.close()
return data:sub(start, start+length)
end
function uObject:writeBytes(start, dat)
local f = getFs(self)
local file=fs.open(f, "r")
local data=fs.readAll()
file.close()
return data:sub(1, start)..dat..data:sub(start+#dat, #data)
end
function uObject:getSize()
local f = getFs(self)
local file=fs.open(f, "r")
local data=fs.readAll()
file.close()
return #data
end
local function findDisks(tble)
for i,v in ipairs(tble) do
if fs.exists("/disks/"..tostring(v).."h") then
local obj = deepcopy(object)
obj.__UDATA_id=v
obj.id="disk_"..tostring(v)
obj.type="hdd"
newComponent("disk", obj)
fss[tostring(v)]="/disks/"..tostring(v).."h/"
elseif fs.exists("/disks/"..tostring(v).."f") then
local obj = deepcopy(object)
obj.__UDATA_id=v
obj.id="disk_"..tostring(v)
obj.type="fdd"
newComponent("disk", obj)
fss[tostring(v)]="/disks/"..tostring(v).."f/"
elseif fs.exists("/disks/"..tostring(v).."u") then
local obj = deepcopy(uObject)
obj.__UDATA_id=v
obj.id="disk_"..tostring(v)
obj.type="udd"
newComponent("disk", obj)
fss[tostring(v)]="/disks/"..tostring(v).."u"
else
fs.makeDir("/disks/"..tostring(v).."f/")
local obj = deepcopy(object)
obj.__UDATA_id=v
obj.id="disk_"..tostring(v)
obj.type="fdd"
newComponent("disk", obj)
fss[tostring(v)]="/disks/"..tostring(v).."f/"
end
end
end
local file = fs.open("/computers/0/computer.ltable", "r")
local config = load("return "..file.readAll())()
file.close()
findDisks(config.disks)