From 3ae928522c6e94946427889d5f42734b464d0d26 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Tue, 20 Aug 2024 19:02:12 +0200 Subject: [PATCH] Fixes upon fixes --- src/init.lua | 11 +++---- src/sPhone.lua | 80 ++++++++++++++++++++++++++------------------------ 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/init.lua b/src/init.lua index d355aa6..067503c 100644 --- a/src/init.lua +++ b/src/init.lua @@ -74,11 +74,13 @@ local function recovery() print("Installing sPhone...") sleep(0.5) 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())() elseif k == 3 then 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())() elseif k == 4 then fs.delete("/.sPhone/config") @@ -124,9 +126,9 @@ while true do end end -if not fs.exists("/.sPhone/sPhone") then +if not fs.exists("/.sPhone/sPhone.lua") then printError("sPhone not installed") - shell.run("/.sPhone/init -u") + shell.run("/.sPhone/init.lua -u") return end @@ -145,7 +147,6 @@ 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 = { ... } diff --git a/src/sPhone.lua b/src/sPhone.lua index 0e96e17..51ddd07 100644 --- a/src/sPhone.lua +++ b/src/sPhone.lua @@ -76,11 +76,8 @@ local function kernel(...) term.setTextColor(colors.black) if not fs.isDir("/.sPhone/autorun/" .. v) then if not sPhone.safeMode then - local f = fs.open("/.sPhone/autorun/" .. v, "r") - local script = f.readAll() - f.close() 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 term.setTextColor(colors.red) print("Script error: " .. v .. ": " .. err) @@ -1069,53 +1066,58 @@ local function kernel(...) local f = fs.open("/.sPhone/apps/spk/" .. spk .. "/.spk", "r") local script = f.readAll() f.close() - _config = textutils.unserialize(script) + local _config = textutils.unserialize(script) if not script then return false, "config corrupted" end - local result = {} - local ok, err = pcall(function() - result = { setfenv(loadfile(fs.combine("/.sPhone/apps/spk", _config.id .. "/files/" .. _config.main)), - setmetatable({ - spk = { - getName = function() - return (_config.name or nil) - end, + local func, err = loadfile( + fs.combine("/.sPhone/apps/spk", _config.id .. "/files/" .. _config.main), + "t", + setmetatable({ + spk = { + getName = function() + return (_config.name or nil) + end, - getID = function() - return (_config.id or nil) - end, + getID = function() + return (_config.id or nil) + end, - getPath = function() - return "/.sPhone/apps/spk/" .. _config.id - end, + getPath = function() + return "/.sPhone/apps/spk/" .. _config.id + end, - getDataPath = function() - return "/.sPhone/apps/spk/" .. _config.id .. "/data" - end, + getDataPath = function() + return "/.sPhone/apps/spk/" .. _config.id .. "/data" + end, - getAuthor = function() - return (_config.author or nil) - end, + getAuthor = function() + return (_config.author or nil) + end, - getVersion = function() - return (_config.version or nil) - end, + getVersion = function() + return (_config.version or nil) + end, - getType = function() - return (_config.type or nil) - end, + getType = function() + return (_config.type or nil) + end, - open = function(file, mode) - return fs.open("/.sPhone/apps/spk/" .. _config.id .. "/data/" .. file, mode) - end, - }, - string = string, - sPhone = sPhone, - }, { __index = getfenv() }))() } - end) + open = function(file, mode) + return fs.open("/.sPhone/apps/spk/" .. _config.id .. "/data/" .. file, mode) + end, + }, + string = string, + sPhone = sPhone, + }, { __index = _ENV }) + ) + if not func then + return false, err + end + + local ok, result = pcall(func) if not ok then return false, err end