blob: e835c8a1ced75730a701eeb966cc50f7d435d6fa [file] [log] [blame] [raw]
local isAutorunEnabled = true
-------------------------------------------------------------------------------
fs = setmetatable({}, {__index=driver.filesystem})
fs.delete = fs.remove
fs.isFolder = fs.isDirectory
fs.list = fs.dir
fs.mkdir = fs.makeDirectory
-------------------------------------------------------------------------------
function fs.autorun(...)
local args = table.pack(...)
if args.n > 0 then
checkArg(1, args[1], "boolean")
isAutorunEnabled = args[1]
end
return isAutorunEnabled
end
-------------------------------------------------------------------------------
local function onComponentAdded(_, address)
local componentType = component.type(address)
if (componentType == "filesystem" or componentType == "disk_drive") and
address ~= os.romAddress() and
address ~= os.tmpAddress()
then
local name = address:usub(1, 3)
repeat
name = address:usub(1, name:ulen() + 1)
until not fs.exists("/mnt/" .. name)
fs.mount(address, "/mnt/" .. name)
if isAutorunEnabled then
local autorun = "/mnt/" .. name .. "/autorun"
if fs.exists(autorun .. ".lua") then
dofile(autorun .. ".lua")
elseif fs.exists(autorun) then
dofile(autorun)
end
end
end
end
local function onComponentRemoved(_, address, componentType)
if componentType == "filesystem" or componentType == "disk_drive" then
while fs.umount(address) do end -- remove *all* mounts
end
end
function fs.install()
event.listen("component_added", onComponentAdded)
event.listen("component_removed", onComponentRemoved)
end
function fs.uninstall()
event.ignore("component_added", onComponentAdded)
event.ignore("component_removed", onComponentRemoved)
end