Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local findFile = function(name)
- if not name or type(name) ~= "string" then
- error("Argument #1 when getting path: Requires string file name, got '"..type(name).."'.")
- end
- local gotPath = false
- local files = fs.list("//")
- for _,path in pairs(files) do
- if fs.getName(path) == name or path == name then
- return path
- elseif fs.isDir(path) and path ~= "rom" then
- local dir = fs.list(path)
- for _,file in pairs(dir) do
- table.insert(files,path.."/"..file)
- end
- end
- end
- end
- local loadFile = function(path)
- local data = nil
- if fs.exists(path) then
- local fileHandle = fs.open(path,"r")
- data = fileHandle.readAll()
- fileHandle.close()
- local table = textutils.unserialise(data)
- if type(table) == "table" then
- return table
- end
- end
- return data
- end
- saveFile = function(path, data)
- if type(data) == "table" then
- data = textutils.serialise(data)
- end
- local fileHandle = fs.open(path,"w")
- fileHandle.write(data)
- fileHandle.close()
- end
- local getMonitors = function()
- local monitors = {}
- for _,side in pairs({"top","bottom","left","right","front","back"}) do
- if peripheral.getType(side) == "monitor" then
- table.insert(monitors,side)
- elseif peripheral.getType(side) == "modem" then
- local check = peripheral.wrap(side)
- if not check.isWireless() then
- wired = check.getNamesRemote()
- for _,name in pairs(wired) do
- if check.getTypeRemote(name) == "monitor" then
- table.insert(monitors,name)
- end
- end
- end
- end
- end
- return monitors
- end
- return {
- findFile = findFile,
- loadFile = loadFile,
- saveFile = saveFile,
- monitors = getMonitors,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement