Fixes upon fixes

This commit is contained in:
Alessandro Proto 2024-08-20 19:02:12 +02:00
parent f48288f1a3
commit 3ae928522c
2 changed files with 47 additions and 44 deletions

View file

@ -74,11 +74,13 @@ local function recovery()
print("Installing sPhone...") print("Installing sPhone...")
sleep(0.5) sleep(0.5)
setfenv( setfenv(
loadstring(http.get("https://raw.githubusercontent.com/SertexTeam/sPhone/master/src/installer.lua").readAll()), loadstring(http.get("https://raw.githubusercontent.com/SertexTeam/sPhone/master/src/installer.lua")
.readAll()),
getfenv())() getfenv())()
elseif k == 3 then elseif k == 3 then
setfenv( setfenv(
loadstring(http.get("https://raw.githubusercontent.com/SertexTeam/sPhone/master/src/installer.lua").readAll()), loadstring(http.get("https://raw.githubusercontent.com/SertexTeam/sPhone/master/src/installer.lua")
.readAll()),
getfenv())() getfenv())()
elseif k == 4 then elseif k == 4 then
fs.delete("/.sPhone/config") fs.delete("/.sPhone/config")
@ -124,9 +126,9 @@ while true do
end end
end end
if not fs.exists("/.sPhone/sPhone") then if not fs.exists("/.sPhone/sPhone.lua") then
printError("sPhone not installed") printError("sPhone not installed")
shell.run("/.sPhone/init -u") shell.run("/.sPhone/init.lua -u")
return return
end end
@ -145,7 +147,6 @@ end
if not pocket or not term.isColor() then if not pocket or not term.isColor() then
printError("Computer not supported: use an Advanced Pocket Computer or an Advanced Wireless Pocket Computer") printError("Computer not supported: use an Advanced Pocket Computer or an Advanced Wireless Pocket Computer")
return
end end
local tArgs = { ... } local tArgs = { ... }

View file

@ -76,11 +76,8 @@ local function kernel(...)
term.setTextColor(colors.black) term.setTextColor(colors.black)
if not fs.isDir("/.sPhone/autorun/" .. v) then if not fs.isDir("/.sPhone/autorun/" .. v) then
if not sPhone.safeMode then if not sPhone.safeMode then
local f = fs.open("/.sPhone/autorun/" .. v, "r")
local script = f.readAll()
f.close()
print("Loading script " .. v) print("Loading script " .. v)
local ok, err = pcall(function() setfenv(loadstring(script), getfenv())() end) local ok, err = pcall(loadfile("/.sPhone/autorun/" .. v, "t", _ENV))
if not ok then if not ok then
term.setTextColor(colors.red) term.setTextColor(colors.red)
print("Script error: " .. v .. ": " .. err) print("Script error: " .. v .. ": " .. err)
@ -1069,14 +1066,14 @@ local function kernel(...)
local f = fs.open("/.sPhone/apps/spk/" .. spk .. "/.spk", "r") local f = fs.open("/.sPhone/apps/spk/" .. spk .. "/.spk", "r")
local script = f.readAll() local script = f.readAll()
f.close() f.close()
_config = textutils.unserialize(script) local _config = textutils.unserialize(script)
if not script then if not script then
return false, "config corrupted" return false, "config corrupted"
end end
local result = {} local func, err = loadfile(
local ok, err = pcall(function() fs.combine("/.sPhone/apps/spk", _config.id .. "/files/" .. _config.main),
result = { setfenv(loadfile(fs.combine("/.sPhone/apps/spk", _config.id .. "/files/" .. _config.main)), "t",
setmetatable({ setmetatable({
spk = { spk = {
getName = function() getName = function()
@ -1113,9 +1110,14 @@ local function kernel(...)
}, },
string = string, string = string,
sPhone = sPhone, sPhone = sPhone,
}, { __index = getfenv() }))() } }, { __index = _ENV })
end) )
if not func then
return false, err
end
local ok, result = pcall(func)
if not ok then if not ok then
return false, err return false, err
end end