1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-27 01:14:46 +00:00

Merge pull request #228 from Lignum/startup-dir

Startup directories
This commit is contained in:
Daniel Ratcliffe 2017-05-16 22:56:00 +01:00 committed by GitHub
commit 2bc72a883f
3 changed files with 435 additions and 408 deletions

View File

@ -31,6 +31,7 @@ New Features in ComputerCraft 1.80:
* shell.resolveProgram now picks up on *.lua files
* Fixed a handful of bugs in ComputerCraft
* Added speaker block, turtle upgrade, pocket upgrade, and peripheral api
* Startup can now be a directory containing multiple startup files
New Features in ComputerCraft 1.79:

View File

@ -31,5 +31,6 @@ New Features in ComputerCraft 1.80:
* shell.resolveProgram now picks up on *.lua files
* Fixed a handful of bugs in ComputerCraft
* Added speaker block, turtle upgrade, pocket upgrade, and peripheral api
* Startup can now be a directory containing multiple startup files
Type "help changelog" to see the full version history.

View File

@ -209,22 +209,47 @@ 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 }
end
-- It's possible that there is a startup directory and a startup.lua file, so this has to be
-- executed even if a file has already been found.
if fs.isDir( sBasePath ) then
if tStartups == nil then
tStartups = {}
end
for _,v in pairs( fs.list( sBasePath ) ) do
local sPath = "/" .. fs.combine( sBasePath, v )
if not fs.isDir( sPath ) then
tStartups[ #tStartups + 1 ] = sPath
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 tUserStartups then
for _,v in pairs( tUserStartups ) do
shell.run( v )
end
end