Update sPhone.lua

This commit is contained in:
Ale32bit 2015-12-15 18:54:15 +01:00
parent 33afe31976
commit e55c719a49

View file

@ -1,142 +1,11 @@
os.forceShutdown = os.shutdown
local function crash(err)
if not sPhone then
sPhone = {
devMode = false,
}
end
term.setCursorBlink(false)
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.black)
if not err then
err = "Undefined Error"
end
print("sPhone got an error :(\n")
term.setTextColor(colors.red)
print(err)
term.setTextColor(colors.black)
print("")
if sPhone.version then
print("sPhone "..sPhone.version)
end
print("Computer ID: "..os.getComputerID())
if _CC_VERSION then
print("CC Version: ".._CC_VERSION)
print("MC Version: ".._MC_VERSION)
else
print("CC Version: Under 1.74")
print("MC Version: Undefined")
term.setTextColor(colors.red)
print("Update CC to 1.74 or higher")
term.setTextColor(colors.black)
end
print("LUA Version: ".._VERSION)
print("LUAJ Version: ".._LUAJ_VERSION)
print("Contact sPhone devs: GitHub: Sertex-Team/sPhone")
print("Thanks for using sPhone")
print("Press any key")
repeat
sleep(0)
until os.pullEvent("key")
if not sPhone.devMode then
_G.term = nil
end
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1,1)
sleep(0.1)
shell.run("/rom/programs/shell")
end
local function recovery()
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.clear()
term.setCursorPos(1,1)
print("sPhone Recovery")
print("[1] Hard Reset")
print("[2] Update sPhone")
print("[3] Reset User Config")
print("[4] Continue Booting")
print("[5] Boot in safe mode")
while true do
local _, k = os.pullEvent("key")
if k == 2 then
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
for k, v in pairs(fs.list("/")) do
if not fs.isReadOnly(v) then
if fs.isDir(v) then
shell.setDir(v)
for k, v in pairs(fs.list("/"..v)) do
fs.delete(v)
print("Removed "..shell.dir().."/"..v)
end
shell.setDir(shell.resolve(".."))
end
fs.delete(v)
print("Removed "..v)
end
end
print("Installing sPhone...")
sleep(0.5)
setfenv(loadstring(http.get("https://raw.githubusercontent.com/Sertex-Team/sPhone/master/src/installer.lua").readAll()),getfenv())()
elseif k == 3 then
setfenv(loadstring(http.get("https://raw.githubusercontent.com/Sertex-Team/sPhone/master/src/installer.lua").readAll()),getfenv())()
elseif k == 4 then
fs.delete("/.sPhone/config")
fs.delete("/.sPhone/cache")
os.reboot()
elseif k == 5 then
_G.safemode = false
break
elseif k == 6 then
_G.safemode = true
break
end
end
end
local function kernel() local function kernel()
term.setBackgroundColor(colors.white)
term.setCursorPos(1,1)
term.clear()
term.setTextColor(colors.black)
if fs.exists("/.sPhone/interfaces/bootImage") then
local bootImage = paintutils.loadImage("/.sPhone/interfaces/bootImage")
paintutils.drawImage(bootImage, 11,7)
else
print("Missing bootImage")
end
local w, h = term.getSize()
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.setCursorPos(1,h)
write("Press ALT to recovery mode")
local bootTimer = os.startTimer(1)
while true do
local e,k = os.pullEvent()
if e == "key" and k == 56 then
recovery()
break
elseif e == "timer" then
_G.safemode = false
break
end
end
_G.sPhone = { _G.sPhone = {
version = "Alpha 2.10.1", version = "Alpha 2.11",
user = "Run sID", user = "Run sID",
devMode = false, devMode = false,
mainTerm = term.current() mainTerm = term.current()
} }
if not fs.exists("/.sPhone/config/newIDSystem") then if not fs.exists("/.sPhone/config/newIDSystem") then
fs.delete("/.sPhone/config/username") fs.delete("/.sPhone/config/username")
fs.delete("/.sPhone/config/.sIDpw") fs.delete("/.sPhone/config/.sIDpw")
@ -218,6 +87,7 @@ local function kernel()
sPhone.crash = crash sPhone.crash = crash
end end
_G.crash = nil
function os.version() function os.version()
return "sPhone "..sPhone.version return "sPhone "..sPhone.version
end end
@ -912,57 +782,8 @@ end
home() home()
end end
if not sPhone then
local runningOnStartup kernel(...)
else
term.setBackgroundColor(colors.black) print("sPhone already started")
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.white)
if sPhone then
printError("sPhone already started")
return
end end
if not pocket or not term.isColor() then
printError("Computer not supported: use an Advanced Pocket Computer or an Advanced Wireless Pocket Computer")
return
end
local tArgs = {...}
os.oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local argData = {
["-u"] = false,
["-s"] = false,
}
if #tArgs > 0 then
while #tArgs > 0 do
local tArgs = table.remove(tArgs, 1)
if argData[tArgs] ~= nil then
argData[tArgs] = true
end
end
end
if argData["-u"] then
print("Getting installer...")
setfenv(loadstring(http.get("https://raw.githubusercontent.com/Sertex-Team/sPhone/master/src/installer.lua").readAll()),getfenv())()
end
if argData["-s"] then
runningOnStartup = true
end
local ok, error = pcall(kernel)
if not ok then
crash(error)
end
crash("Something went wrong...")
_G.term = nil -- The OS ends here - This string force to crash the pda and shutdown