Update sPhone.lua

This commit is contained in:
Ale32bit 2015-11-18 16:54:17 +01:00
parent 974dcb72f8
commit 55db5b3c12

View file

@ -50,6 +50,7 @@ local function recovery()
print("[2] Update sPhone") print("[2] Update sPhone")
print("[3] Reset User Config") print("[3] Reset User Config")
print("[4] Continue Booting") print("[4] Continue Booting")
print("[5] Boot in safe mode")
while true do while true do
local _, k = os.pullEvent("key") local _, k = os.pullEvent("key")
if k == 2 then if k == 2 then
@ -79,6 +80,10 @@ local function recovery()
os.reboot() os.reboot()
elseif k == 5 then elseif k == 5 then
break break
elseif k == 6 then
recoverym = {}
recoverym.safemode = true
break
end end
end end
end end
@ -133,6 +138,16 @@ local function kernel()
f.close() f.close()
end end
if not fs.exists("/.sPhone/apis") then
fs.makeDir("/.sPhone/apis")
end
for k, v in pairs(fs.list("/.sPhone/apis")) do
if not fs.isDir("/.sPhone/apis/"..v) then
os.loadAPI("/.sPhone/apis/"..v)
end
end
if not fs.exists("/.sPhone/autorun") then if not fs.exists("/.sPhone/autorun") then
fs.makeDir("/.sPhone/autorun") fs.makeDir("/.sPhone/autorun")
end end
@ -140,26 +155,28 @@ local function kernel()
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
for k, v in pairs(fs.list("/.sPhone/autorun")) do for k, v in pairs(fs.list("/.sPhone/autorun")) do
term.setTextColor(colors.black) term.setTextColor(colors.black)
if not fs.isDir("/.sPhone/autorun/"..v) then if not fs.isDir("/.sPhone/autorun/"..v) then
local f = fs.open("/.sPhone/autorun/"..v,"r") if not recoverym.safemode then
local script = f.readAll() local f = fs.open("/.sPhone/autorun/"..v,"r")
f.close() local script = f.readAll()
print("Loading script "..v) f.close()
sleep(0) print("Loading script "..v)
local ok, err = pcall(function() setfenv(loadstring(script),getfenv())() end) sleep(0)
if not ok then local ok, err = pcall(function() setfenv(loadstring(script),getfenv())() end)
term.setTextColor(colors.red) if not ok then
print("Script error: "..v..": "..err) term.setTextColor(colors.red)
fs.move("/.sPhone/autorun/"..v, "/.sPhone/autorun/disabled/"..v) print("Script error: "..v..": "..err)
term.setTextColor(colors.blue) fs.move("/.sPhone/autorun/"..v, "/.sPhone/autorun/disabled/"..v)
print(v.." disabled to prevent errors") term.setTextColor(colors.blue)
sleep(0.5) print(v.." disabled to prevent errors")
sleep(0.5)
end
else
print("Script "..v.." not loaded because Safe Mode")
sleep(0)
end end
end end
end end
@ -173,16 +190,6 @@ local function kernel()
u.close() u.close()
end end
if not fs.exists("/.sPhone/apis") then
fs.makeDir("/.sPhone/apis")
end
for k, v in pairs(fs.list("/.sPhone/apis")) do
if not fs.isDir("/.sPhone/apis/"..v) then
os.loadAPI("/.sPhone/apis/"..v)
end
end
if not fs.exists("/.sPhone/config/sPhone") then if not fs.exists("/.sPhone/config/sPhone") then
config.write("/.sPhone/config/sPhone","devMode",false) config.write("/.sPhone/config/sPhone","devMode",false)
end end