diff --git a/src/main/resources/assets/computercraft/lua/rom/startup b/src/main/resources/assets/computercraft/lua/rom/startup index b3b02f67a..6becd27a1 100644 --- a/src/main/resources/assets/computercraft/lua/rom/startup +++ b/src/main/resources/assets/computercraft/lua/rom/startup @@ -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