Enable the use of startup directories

This commit is contained in:
Lignum 2017-05-10 23:02:08 +02:00
parent 25128dfb66
commit 2e7c9b163d
No known key found for this signature in database
GPG Key ID: 0889206F5A8A700D
1 changed files with 27 additions and 7 deletions

View File

@ -209,22 +209,42 @@ if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
end
end
local function findStartups( sBaseDir )
local tStartups = nil
local sBasePath = "/" .. fs.combine( sBaseDir, "startup" )
local sStartupNode = shell.resolveProgram( sBasePath )
if sStartupNode then
tStartups = { sStartupNode }
else
if fs.isDir( sBasePath ) then
tStartups = {}
for _,v in pairs( fs.list( sBasePath ) ) do
tStartups[ #tStartups + 1 ] = shell.resolveProgram( "/" .. fs.combine( sBasePath, v ) )
end
end
end
return tStartups
end
-- Run the user created startup, either from disk drives or the root
local sUserStartup = nil
local tUserStartups = nil
if settings.get( "shell.allow_startup" ) then
sUserStartup = shell.resolveProgram( "/startup" )
tUserStartups = findStartups( "/" )
end
if settings.get( "shell.allow_disk_startup" ) then
for n,sName in pairs( peripheral.getNames() ) do
if disk.isPresent( sName ) and disk.hasData( sName ) then
local sDiskStartup = shell.resolveProgram( "/" .. disk.getMountPath( sName ) .. "/startup" )
if sDiskStartup then
sUserStartup = sDiskStartup
local startups = findStartups( disk.getMountPath( sName ) )
if startups then
tUserStartups = startups
break
end
end
end
end
if sUserStartup then
shell.run( sUserStartup )
if type( tUserStartups ) == "table" then
table.sort( tUserStartups )
for _,v in pairs( tUserStartups ) do
shell.run( v )
end
end