From bb9924ad5a657de6cca123dfc2f68d4e8ecd12e9 Mon Sep 17 00:00:00 2001 From: Alessandro <4512372+Ale32bit@users.noreply.github.com> Date: Mon, 28 Oct 2019 19:29:25 +0100 Subject: [PATCH 1/3] Final update Bug fixes --- src/apps/spks/appList.spk | 160 +++++++++++----------- src/apps/spks/chat.spk | 9 +- src/apps/spks/explorer.spk | 192 +++++++++++++------------- src/apps/spks/gps.spk | 9 +- src/apps/spks/home.spk | 266 +++++++++++++++++++++---------------- src/apps/spks/info.spk | 11 +- src/apps/spks/settings.spk | 20 +-- src/apps/spks/shell.spk | 9 +- src/apps/spks/store.spk | 11 +- src/apps/spks/themes.spk | 73 +++++----- 10 files changed, 402 insertions(+), 358 deletions(-) diff --git a/src/apps/spks/appList.spk b/src/apps/spks/appList.spk index 95666e5..4452b9e 100644 --- a/src/apps/spks/appList.spk +++ b/src/apps/spks/appList.spk @@ -1,93 +1,95 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { files = "{\ - [ \"appList.lua\" ] = \"local apps = {}\\r\\\ -local function update()\\r\\\ - apps = config.list(\\\"/.sPhone/config/spklist\\\")\\r\\\ - for k,v in pairs(apps) do\\r\\\ - local h = config.read(\\\"/.sPhone/apps/spk/\\\"..k..\\\"/.spk\\\",\\\"hidden\\\")\\r\\\ - if h then\\r\\\ - apps[k] = nil\\r\\\ - end\\r\\\ - end\\r\\\ -end\\r\\\ -local function menu(id)\\r\\\ - local data = config.list(\\\"/.sPhone/apps/spk/\\\"..id..\\\"/.spk\\\")\\r\\\ - if data then\\r\\\ - term.setBackgroundColor(sPhone.theme[\\\"backgroundColor\\\"])\\r\\\ - term.setTextColor(sPhone.theme[\\\"text\\\"])\\r\\\ - term.clear()\\r\\\ - sPhone.header(\\\" Apps\\\",\\\"X\\\")\\r\\\ - term.setCursorPos(2,3)\\r\\\ - print(data.name)\\r\\\ - term.setCursorPos(2,6)\\r\\\ - term.setTextColor(colors.black)\\r\\\ - print(\\\"Author:\\\")\\r\\\ - term.setTextColor(colors.gray)\\r\\\ - term.setCursorPos(2,7)\\r\\\ - print(data.author)\\r\\\ - term.setCursorPos(2,9)\\r\\\ - term.setTextColor(colors.black)\\r\\\ - print(\\\"Type:\\\")\\r\\\ - term.setTextColor(colors.gray)\\r\\\ - term.setCursorPos(2,10)\\r\\\ - print((data.type or \\\"Normal\\\"))\\r\\\ - term.setCursorPos(2,12)\\r\\\ - term.setTextColor(colors.black)\\r\\\ - print(\\\"Version:\\\")\\r\\\ - term.setTextColor(colors.gray)\\r\\\ - term.setCursorPos(2,13)\\r\\\ - print(data.version)\\r\\\ - paintutils.drawLine(19,4,25,4,colors.red)\\r\\\ - term.setTextColor(colors.white)\\r\\\ - term.setCursorPos(19,4)\\r\\\ - write(\\\"Delete\\\")\\r\\\ - local w,h = term.getSize()\\r\\\ - while true do\\r\\\ - local _,_,mx,my = os.pullEvent(\\\"mouse_click\\\")\\r\\\ - if my == 1 and mx == w then\\r\\\ - break\\r\\\ - elseif (mx >= 19 and mx <= 25) and my == 4 then\\r\\\ - if fs.exists(\\\"/.sPhone/apps/spk/\\\"..data.id) then\\r\\\ - fs.delete(\\\"/.sPhone/apps/spk/\\\"..data.id)\\r\\\ - end\\r\\\ - config.write(\\\"/.sPhone/config/spklist\\\",data.id,nil)\\r\\\ - break\\r\\\ - end\\r\\\ - end\\r\\\ - end\\r\\\ -end\\r\\\ -\\r\\\ -update()\\r\\\ -\\r\\\ -while true do\\r\\\ - local id, _, mouse = sPhone.list(nil,{\\r\\\ - list = apps,\\r\\\ - pairs = true,\\r\\\ - title = \\\" Apps\\\"\\r\\\ - })\\r\\\ - if not id then\\r\\\ - break\\r\\\ - end\\r\\\ - if mouse == 1 then\\r\\\ - sPhone.launch(id)\\r\\\ - break\\r\\\ - elseif mouse == 2 then\\r\\\ - menu(id)\\r\\\ - update()\\r\\\ - end\\r\\\ -end\",\ + [ \"appList.lua\" ] = \"local apps = {}\\\ +local function update()\\\ + apps = config.list(\\\"/.sPhone/config/spklist\\\")\\\ + for k,v in pairs(apps) do\\\ + local h = config.read(\\\"/.sPhone/apps/spk/\\\"..k..\\\"/.spk\\\",\\\"hidden\\\")\\\ + if h then\\\ + apps[k] = nil\\\ + end\\\ + end\\\ +end\\\ +local function menu(id)\\\ + local data = config.list(\\\"/.sPhone/apps/spk/\\\"..id..\\\"/.spk\\\")\\\ + if data then\\\ + term.setBackgroundColor(sPhone.theme[\\\"backgroundColor\\\"])\\\ + term.setTextColor(sPhone.theme[\\\"text\\\"])\\\ + term.clear()\\\ + sPhone.header(\\\" Apps\\\",\\\"X\\\")\\\ + term.setCursorPos(2,3)\\\ + print(data.name)\\\ + term.setCursorPos(2,6)\\\ + term.setTextColor(colors.black)\\\ + print(\\\"Author:\\\")\\\ + term.setTextColor(colors.gray)\\\ + term.setCursorPos(2,7)\\\ + print(data.author)\\\ + term.setCursorPos(2,9)\\\ + term.setTextColor(colors.black)\\\ + print(\\\"Type:\\\")\\\ + term.setTextColor(colors.gray)\\\ + term.setCursorPos(2,10)\\\ + print((data.type or \\\"Normal\\\"))\\\ + term.setCursorPos(2,12)\\\ + term.setTextColor(colors.black)\\\ + print(\\\"Version:\\\")\\\ + term.setTextColor(colors.gray)\\\ + term.setCursorPos(2,13)\\\ + print(data.version)\\\ + paintutils.drawLine(19,4,25,4,colors.red)\\\ + term.setTextColor(colors.white)\\\ + term.setCursorPos(19,4)\\\ + write(\\\"Delete\\\")\\\ + local w,h = term.getSize()\\\ + while true do\\\ + local _,_,mx,my = os.pullEvent(\\\"mouse_click\\\")\\\ + if my == 1 and mx == w then\\\ + break\\\ + elseif (mx >= 19 and mx <= 25) and my == 4 then\\\ + if fs.exists(\\\"/.sPhone/apps/spk/\\\"..data.id) then\\\ + fs.delete(\\\"/.sPhone/apps/spk/\\\"..data.id)\\\ + end\\\ + config.write(\\\"/.sPhone/config/spklist\\\",data.id,nil)\\\ + break\\\ + end\\\ + end\\\ + end\\\ +end\\\ +\\\ +update()\\\ +\\\ +while true do\\\ + local id, _, mouse = sPhone.list(nil,{\\\ + list = apps,\\\ + pairs = true,\\\ + title = \\\" Apps\\\"\\\ + })\\\ + if not id then\\\ + break\\\ + end\\\ + if mouse == 1 then\\\ + sPhone.launch(id)\\\ + break\\\ + elseif mouse == 2 then\\\ + menu(id)\\\ + update()\\\ + end\\\ +end\\\ +\\\ +return true\",\ }", config = "{\ type = \"app\",\ name = \"Apps\",\ version = 1,\ - main = \"appList.lua\",\ id = \"sphone.appList\",\ - author = \"BeaconNet\",\ + author = \"Sertex\",\ hidden = true,\ + main = \"appList.lua\",\ }", } \ No newline at end of file diff --git a/src/apps/spks/chat.spk b/src/apps/spks/chat.spk index ba54253..73284b1 100644 --- a/src/apps/spks/chat.spk +++ b/src/apps/spks/chat.spk @@ -1,5 +1,5 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { @@ -20,16 +20,15 @@ if not peripheral.isPresent(\\\"back\\\") or not peripheral.getType(\\\"back\\\" end\\\ write(\\\"Host: \\\")\\\ local h = read() term.setCursorPos(2,6)\\\ -shell.run(\\\"/rom/programs/rednet/chat\\\", \\\"join\\\", h, sPhone.user)\\\ -\",\ +shell.run(\\\"/rom/programs/rednet/chat\\\", \\\"join\\\", h, sPhone.user)\",\ }", config = "{\ type = \"app\",\ name = \"RedNet Chat\",\ version = 1,\ - main = \"chat.lua\",\ id = \"sphone.chat\",\ - author = \"BeaconNet\",\ + author = \"Sertex\",\ hidden = true,\ + main = \"chat.lua\",\ }", } \ No newline at end of file diff --git a/src/apps/spks/explorer.spk b/src/apps/spks/explorer.spk index 0039eaa..fcaf7f3 100644 --- a/src/apps/spks/explorer.spk +++ b/src/apps/spks/explorer.spk @@ -1,109 +1,111 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { files = "{\ - [ \"explorer.lua\" ] = \"local dir = nil\\r\\\ -\\r\\\ -local function split(inputstr, sep)\\r\\\ - if sep == nil then\\r\\\ - sep = \\\"%s\\\"\\r\\\ - end\\r\\\ - local t={} ; i=1\\r\\\ - for str in string.gmatch(inputstr, \\\"([^\\\"..sep..\\\"]+)\\\") do\\r\\\ - t[i] = str\\r\\\ - i = i + 1\\r\\\ - end\\r\\\ - return t\\r\\\ -end\\r\\\ -\\r\\\ -local function run(path, args)\\r\\\ - return pcall(function()\\r\\\ - os.run(setmetatable({\\r\\\ - shell = shell,\\r\\\ - multishell = multishell,\\r\\\ - }, {__index = getfenv()}), path, args)\\r\\\ - end)\\r\\\ -end\\r\\\ -while true do\\r\\\ - local path, mouse = sPhone.list(dir,{\\r\\\ - fg1b = colors.green,\\r\\\ - })\\r\\\ - if not path then\\r\\\ - break\\r\\\ - end\\r\\\ - if mouse == 1 then\\r\\\ - run(path)\\r\\\ - elseif mouse == 2 then\\r\\\ - while true do\\r\\\ - local w,h = term.getSize()\\r\\\ - term.setBackgroundColor(sPhone.theme[\\\"backgroundColor\\\"])\\r\\\ - term.setTextColor(sPhone.theme[\\\"text\\\"])\\r\\\ - term.clear()\\r\\\ - sPhone.header(fs.getName(path),\\\"X\\\")\\r\\\ - term.setCursorPos(2,3)\\r\\\ - write(\\\"Size: \\\")\\r\\\ - term.setTextColor(colors.gray)\\r\\\ - local siz = fs.getSize(path)\\r\\\ - local text\\r\\\ - if siz == 1 then\\r\\\ - text = siz..\\\" byte\\\"\\r\\\ - else\\r\\\ - text = siz..\\\" bytes\\\"\\r\\\ - end\\r\\\ - print(text)\\r\\\ - term.setTextColor(sPhone.theme[\\\"text\\\"])\\r\\\ - term.setCursorPos(2,5)\\r\\\ - write(\\\"Type: \\\")\\r\\\ - term.setTextColor(colors.gray)\\r\\\ - print(string.getExtension(fs.getName(path)) or \\\"none\\\")\\r\\\ - term.setTextColor(sPhone.theme[\\\"text\\\"])\\r\\\ - term.setCursorPos(2,8)\\r\\\ - print(\\\"Actions\\\")\\r\\\ - term.setTextColor(colors.gray)\\r\\\ - term.setCursorPos(2,10)\\r\\\ - print(\\\"Run with arguments\\\")\\r\\\ - term.setCursorPos(2,11)\\r\\\ - print(\\\"Edit\\\")\\r\\\ - term.setCursorPos(2,12)\\r\\\ - print(\\\"Rename\\\")\\r\\\ - term.setCursorPos(2,13)\\r\\\ - print(\\\"Delete\\\")\\r\\\ - term.setTextColor(sPhone.theme[\\\"text\\\"])\\r\\\ - local _,_,x,y = os.pullEvent(\\\"mouse_click\\\")\\r\\\ - if y == 1 and x == w then\\r\\\ - break\\r\\\ - elseif y == 10 then\\r\\\ - term.setCursorPos(2,h-1)\\r\\\ - write(\\\"Args: \\\")\\r\\\ - term.setTextColor(colors.gray)\\r\\\ - shell.run(path..\\\" \\\"..read())\\r\\\ - elseif y == 11 then\\r\\\ - shell.run(\\\"edit\\\",path)\\r\\\ - elseif y == 12 then\\r\\\ - term.setCursorPos(2,h-1)\\r\\\ - write(\\\"Rename: \\\")\\r\\\ - term.setTextColor(colors.gray)\\r\\\ - local oldPath = path\\r\\\ - path = fs.getDir(path)..\\\"/\\\"..read()\\r\\\ - fs.move(oldPath,path)\\r\\\ - elseif y == 13 then\\r\\\ - fs.delete(path)\\r\\\ - break\\r\\\ - end\\r\\\ - end\\r\\\ - end\\r\\\ - dir = fs.getDir(path)\\r\\\ -end\",\ + [ \"explorer.lua\" ] = \"local dir = nil\\\ +\\\ +local function split(inputstr, sep)\\\ + if sep == nil then\\\ + sep = \\\"%s\\\"\\\ + end\\\ + local t={} ; i=1\\\ + for str in string.gmatch(inputstr, \\\"([^\\\"..sep..\\\"]+)\\\") do\\\ + t[i] = str\\\ + i = i + 1\\\ + end\\\ + return t\\\ +end\\\ +\\\ +local function run(path, args)\\\ + return pcall(function()\\\ + os.run(setmetatable({\\\ + shell = shell,\\\ + multishell = multishell,\\\ + }, {__index = getfenv()}), path, args)\\\ + end)\\\ +end\\\ +while true do\\\ + local path, mouse = sPhone.list(dir,{\\\ + fg1b = colors.green,\\\ + })\\\ + if not path then\\\ + break\\\ + end\\\ + if mouse == 1 then\\\ + run(path)\\\ + elseif mouse == 2 then\\\ + while true do\\\ + local w,h = term.getSize()\\\ + term.setBackgroundColor(sPhone.theme[\\\"backgroundColor\\\"])\\\ + term.setTextColor(sPhone.theme[\\\"text\\\"])\\\ + term.clear()\\\ + sPhone.header(fs.getName(path),\\\"X\\\")\\\ + term.setCursorPos(2,3)\\\ + write(\\\"Size: \\\")\\\ + term.setTextColor(colors.gray)\\\ + local siz = fs.getSize(path)\\\ + local text\\\ + if siz == 1 then\\\ + text = siz..\\\" byte\\\"\\\ + else\\\ + text = siz..\\\" bytes\\\"\\\ + end\\\ + print(text)\\\ + term.setTextColor(sPhone.theme[\\\"text\\\"])\\\ + term.setCursorPos(2,5)\\\ + write(\\\"Type: \\\")\\\ + term.setTextColor(colors.gray)\\\ + print(string.getExtension(fs.getName(path)) or \\\"none\\\")\\\ + term.setTextColor(sPhone.theme[\\\"text\\\"])\\\ + term.setCursorPos(2,8)\\\ + print(\\\"Actions\\\")\\\ + term.setTextColor(colors.gray)\\\ + term.setCursorPos(2,10)\\\ + print(\\\"Run with arguments\\\")\\\ + term.setCursorPos(2,11)\\\ + print(\\\"Edit\\\")\\\ + term.setCursorPos(2,12)\\\ + print(\\\"Rename\\\")\\\ + term.setCursorPos(2,13)\\\ + print(\\\"Delete\\\")\\\ + term.setTextColor(sPhone.theme[\\\"text\\\"])\\\ + local _,_,x,y = os.pullEvent(\\\"mouse_click\\\")\\\ + if y == 1 and x == w then\\\ + break\\\ + elseif y == 10 then\\\ + term.setCursorPos(2,h-1)\\\ + write(\\\"Args: \\\")\\\ + term.setTextColor(colors.gray)\\\ + shell.run(path..\\\" \\\"..read())\\\ + elseif y == 11 then\\\ + shell.run(\\\"edit\\\",path)\\\ + elseif y == 12 then\\\ + term.setCursorPos(2,h-1)\\\ + write(\\\"Rename: \\\")\\\ + term.setTextColor(colors.gray)\\\ + local oldPath = path\\\ + path = fs.getDir(path)..\\\"/\\\"..read()\\\ + fs.move(oldPath,path)\\\ + elseif y == 13 then\\\ + fs.delete(path)\\\ + break\\\ + end\\\ + end\\\ + end\\\ + dir = fs.getDir(path)\\\ +end\\\ +\\\ +return true\",\ }", config = "{\ type = \"app\",\ main = \"explorer.lua\",\ name = \"File Explorer\",\ - version = 1,\ id = \"sphone.explorer\",\ author = \"Sertex\",\ hidden = true,\ + version = 1,\ }", -} +} \ No newline at end of file diff --git a/src/apps/spks/gps.spk b/src/apps/spks/gps.spk index 56a6a1e..b53e6dc 100644 --- a/src/apps/spks/gps.spk +++ b/src/apps/spks/gps.spk @@ -1,5 +1,5 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { @@ -13,15 +13,16 @@ if tonumber(x) then\\\ else\\\ sPhone.winOk(\\\"X Y Z\\\",\\\"? ? ?\\\")\\\ end\\\ -\",\ +\\\ +return true\",\ }", config = "{\ type = \"app\",\ name = \"GPS\",\ version = 1,\ - main = \"gps.lua\",\ id = \"sphone.gps\",\ - author = \"BeaconNet\",\ + author = \"Sertex\",\ hidden = true,\ + main = \"gps.lua\",\ }", } \ No newline at end of file diff --git a/src/apps/spks/home.spk b/src/apps/spks/home.spk index 85bd2e2..0d13330 100644 --- a/src/apps/spks/home.spk +++ b/src/apps/spks/home.spk @@ -1,128 +1,168 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { files = "{\ - [ \"home.lua\" ] = \"local buttonsInHome = {\\\ - {\\\"sphone.header\\\",23,1,25,1,sPhone.theme[\\\"header\\\"],sPhone.theme[\\\"headerText\\\"],\\\"vvv\\\"},\\\ - {\\\"sphone.appList\\\",12,20,14,20,sPhone.theme[\\\"backgroundColor\\\"],sPhone.theme[\\\"header\\\"],\\\"===\\\"},\\\ - {\\\"sphone.shell\\\",2,3,8,5,colors.black,colors.yellow,\\\" Shell\\\",2},\\\ - {\\\"sphone.explorer\\\",11,3,17,5,colors.blue,colors.white,\\\" Files\\\",2},\\\ - {\\\"sphone.lock\\\",20,3,25,5,colors.lightGray,colors.black,\\\" Lock\\\",2},\\\ - {\\\"sphone.gps\\\",11,7,15,9,colors.red,colors.black,\\\" GPS\\\",2},\\\ - {\\\"sphone.info\\\",18,7,23,9,colors.lightGray,colors.black,\\\" Info\\\",2},\\\ - {\\\"sphone.store\\\",2,7,8,9,colors.green,colors.white,\\\" Store\\\",2},\\\ - }\\\ - \\\ - local function clear()\\\ - term.setBackgroundColor(sPhone.theme[\\\"backgroundColor\\\"])\\\ - term.clear()\\\ - term.setCursorPos(1,1)\\\ - term.setTextColor(sPhone.theme[\\\"text\\\"])\\\ - end\\\ + [ \"home.lua\" ] = \"local currentTime\\\ \\\ - local function drawHome()\\\ - clear()\\\ - visum.buttons(buttonsInHome,true)\\\ - \\\ - local w, h = term.getSize()\\\ - paintutils.drawLine(1,1,w,1, sPhone.theme[\\\"header\\\"])\\\ - term.setTextColor(sPhone.theme[\\\"headerText\\\"])\\\ - visum.align(\\\"right\\\",\\\"vvv \\\",false,1)\\\ - end\\\ - local function footerMenu()\\\ - sPhone.isFooterMenuOpen = true\\\ - function redraw()\\\ - drawHome()\\\ - local w, h = term.getSize()\\\ - paintutils.drawFilledBox(1,2,w,4,sPhone.theme[\\\"header\\\"])\\\ - term.setTextColor(sPhone.theme[\\\"headerText\\\"])\\\ - term.setBackgroundColor(sPhone.theme[\\\"header\\\"])\\\ - visum.align(\\\"right\\\",\\\"^^^ \\\",false,1)\\\ - visum.align(\\\"right\\\", \\\"Reboot \\\",false,3)\\\ - term.setCursorPos(11,3)\\\ - write(\\\"Settings\\\")\\\ - term.setCursorPos(2,3)\\\ - write(\\\"Shutdown\\\")\\\ - end\\\ - while true do\\\ - term.redirect(sPhone.mainTerm)\\\ - drawHome()\\\ - redraw()\\\ - local _,_,x,y = os.pullEvent(\\\"mouse_click\\\")\\\ - if y == 3 then\\\ - if x > 1 and x < 10 then\\\ - os.shutdown()\\\ - sPhone.inHome = true\\\ - elseif x > 19 and x < 26 then\\\ - os.reboot()\\\ - sPhone.inHome = true\\\ - elseif x > 10 and x < 19 then\\\ - sPhone.inHome = false\\\ - sPhone.launch(\\\"sphone.settings\\\")\\\ - sPhone.inHome = true\\\ - drawHome()\\\ - end\\\ - elseif y == 1 then\\\ - if x < 26 and x > 22 then\\\ - sPhone.isFooterMenuOpen = false\\\ - return\\\ - end\\\ - end\\\ - end\\\ - end\\\ - local function buttonHomeLoop()\\\ - while true do\\\ - drawHome()\\\ - term.setCursorBlink(false)\\\ - local autoLockTimer = os.startTimer(10)\\\ - local id = visum.buttons(buttonsInHome)\\\ +local function launch(id)\\\ +\\\ + local ok, par = sPhone.launch(id);\\\ +\\\ + if not ok then\\\ + term.setBackgroundColor(colors.black)\\\ + term.setTextColor(colors.white)\\\ + term.clear()\\\ + term.setCursorPos(1,1)\\\ + print(id .. \\\" has errored:\\\")\\\ + printError(par)\\\ + print(\\\"Press any key to continue\\\")\\\ + os.pullEvent(\\\"key\\\")\\\ +\\\ + else\\\ + if #par == 0 or not par[1] and par[1] ~= nil then\\\ + term.setBackgroundColor(colors.black)\\\ + term.setTextColor(colors.white)\\\ + print(\\\"Press any key to continue\\\")\\\ + os.pullEvent(\\\"key\\\")\\\ + end\\\ + end\\\ +end\\\ +\\\ +local buttonsInHome = {\\\ + {\\\"sphone.header\\\",23,1,25,1,sPhone.theme[\\\"header\\\"],sPhone.theme[\\\"headerText\\\"],\\\"vvv\\\"},\\\ + {\\\"sphone.appList\\\",12,20,14,20,sPhone.theme[\\\"backgroundColor\\\"],sPhone.theme[\\\"header\\\"],\\\"===\\\"},\\\ + {\\\"sphone.shell\\\",2,3,8,5,colors.black,colors.yellow,\\\" Shell\\\",2},\\\ + {\\\"sphone.explorer\\\",11,3,17,5,colors.blue,colors.white,\\\" Files\\\",2},\\\ + {\\\"sphone.lock\\\",20,3,25,5,colors.lightGray,colors.black,\\\" Lock\\\",2},\\\ + {\\\"sphone.gps\\\",11,7,15,9,colors.red,colors.black,\\\" GPS\\\",2},\\\ + {\\\"sphone.info\\\",18,7,23,9,colors.lightGray,colors.black,\\\" Info\\\",2},\\\ + {\\\"sphone.store\\\",2,7,8,9,colors.green,colors.white,\\\" Store\\\",2},\\\ +}\\\ +\\\ +local function clear()\\\ + term.setBackgroundColor(sPhone.theme[\\\"backgroundColor\\\"])\\\ + term.clear()\\\ + term.setCursorPos(1,1)\\\ + term.setTextColor(sPhone.theme[\\\"text\\\"])\\\ +end\\\ +\\\ +local function drawClock(time)\\\ + term.setBackgroundColor(sPhone.theme[\\\"header\\\"])\\\ + term.setTextColor(sPhone.theme[\\\"headerText\\\"])\\\ + term.setCursorPos(1,1)\\\ + write(\\\" \\\")\\\ + term.setCursorPos(1,1)\\\ + write(\\\" \\\"..time)\\\ +end\\\ +\\\ +local function drawHome()\\\ + clear()\\\ + visum.buttons(buttonsInHome,true)\\\ +\\\ + local w, h = term.getSize()\\\ + paintutils.drawLine(1,1,w,1, sPhone.theme[\\\"header\\\"])\\\ + term.setTextColor(sPhone.theme[\\\"headerText\\\"])\\\ + visum.align(\\\"right\\\",\\\"vvv \\\",false,1)\\\ + drawClock(currentTime or \\\"\\\")\\\ +end\\\ +local function footerMenu()\\\ + sPhone.isFooterMenuOpen = true\\\ + function redraw()\\\ + drawHome()\\\ + drawClock(currentTime)\\\ + local w, h = term.getSize()\\\ + paintutils.drawFilledBox(1,2,w,4,sPhone.theme[\\\"header\\\"])\\\ + term.setTextColor(sPhone.theme[\\\"headerText\\\"])\\\ + term.setBackgroundColor(sPhone.theme[\\\"header\\\"])\\\ + visum.align(\\\"right\\\",\\\"^^^ \\\",false,1)\\\ + visum.align(\\\"right\\\", \\\"Reboot \\\",false,3)\\\ + term.setCursorPos(11,3)\\\ + write(\\\"Settings\\\")\\\ + term.setCursorPos(2,3)\\\ + write(\\\"Shutdown\\\")\\\ + end\\\ + redraw()\\\ + while true do\\\ + term.redirect(sPhone.mainTerm)\\\ + local _,_,x,y = os.pullEvent(\\\"mouse_click\\\")\\\ + if y == 3 then\\\ + if x > 1 and x < 10 then\\\ + os.shutdown()\\\ + sPhone.inHome = true\\\ + elseif x > 19 and x < 26 then\\\ + os.reboot()\\\ + sPhone.inHome = true\\\ + elseif x > 10 and x < 19 then\\\ + sPhone.inHome = false\\\ + launch(\\\"sphone.settings\\\")\\\ + sPhone.inHome = true\\\ \\\ - if id == \\\"sphone.header\\\" then\\\ - footerMenu()\\\ - elseif id == \\\"sphone.lock\\\" then\\\ - sPhone.inHome = false\\\ - sPhone.login()\\\ - sPhone.inHome = true\\\ - else\\\ - sPhone.inHome = false\\\ - os.pullEvent = os.oldPullEvent\\\ - sPhone.launch(id)\\\ - os.pullEvent = os.pullEventRaw\\\ - sPhone.inHome = true\\\ - end\\\ - end\\\ - \\\ - sPhone.inHome = false\\\ - \\\ - end\\\ - \\\ - local function updateClock()\\\ - while true do\\\ - if sPhone.inHome then\\\ - term.setCursorPos(1,1)\\\ - term.setBackgroundColor(sPhone.theme[\\\"header\\\"])\\\ - term.setTextColor(sPhone.theme[\\\"headerText\\\"])\\\ - term.setCursorPos(1,1)\\\ - write(\\\" \\\")\\\ - term.setCursorPos(1,1)\\\ - write(\\\" \\\"..textutils.formatTime(os.time(), not config.read(\\\"/.sPhone/config/sPhone\\\",\\\"format12time\\\")))\\\ - end\\\ - sleep(0)\\\ - end\\\ - end\\\ - \\\ - parallel.waitForAll(buttonHomeLoop, updateClock)\\\ -\",\ + drawHome()\\\ + break\\\ + end\\\ + elseif y == 1 then\\\ + if x < 26 and x > 22 then\\\ + sPhone.isFooterMenuOpen = false\\\ + return\\\ + end\\\ + end\\\ + end\\\ +end\\\ +local function buttonHomeLoop()\\\ + drawHome()\\\ + while true do\\\ + term.setCursorBlink(false)\\\ + local autoLockTimer = os.startTimer(10)\\\ + local id = visum.buttons(buttonsInHome)\\\ +\\\ + if id == \\\"sphone.header\\\" then\\\ + footerMenu()\\\ + drawHome()\\\ + elseif id == \\\"sphone.lock\\\" then\\\ + sPhone.inHome = false\\\ + sPhone.login()\\\ + drawHome()\\\ + sPhone.inHome = true\\\ + else\\\ + sPhone.inHome = false\\\ + os.pullEvent = os.oldPullEvent\\\ + launch(id)\\\ + drawHome()\\\ + os.pullEvent = os.pullEventRaw\\\ + sPhone.inHome = true\\\ + end\\\ + end\\\ +\\\ + sPhone.inHome = false\\\ +\\\ +end\\\ +\\\ +local function updateClock()\\\ + local old\\\ + while true do\\\ + if sPhone.inHome then\\\ + local time = textutils.formatTime(os.time(), not config.read(\\\"/.sPhone/config/sPhone\\\",\\\"format12time\\\"))\\\ + if time ~= old then\\\ + old = time\\\ + currentTime = time\\\ + drawClock(time)\\\ + end\\\ + end\\\ + sleep(0.3)\\\ + end\\\ +end\\\ +\\\ +parallel.waitForAll(buttonHomeLoop, updateClock)\",\ }", config = "{\ type = \"home\",\ main = \"home.lua\",\ name = \"sPhone Home\",\ - version = 1,\ id = \"sphone.home\",\ - author = \"BeaconNet\",\ + author = \"Sertex\",\ hidden = true,\ + version = 1,\ }", -} +} \ No newline at end of file diff --git a/src/apps/spks/info.spk b/src/apps/spks/info.spk index f1ac0bb..5c6bea5 100644 --- a/src/apps/spks/info.spk +++ b/src/apps/spks/info.spk @@ -1,5 +1,5 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { @@ -29,18 +29,17 @@ while true do\\\ local w, h = term.getSize()\\\ local _, _, x, y = os.pullEvent(\\\"mouse_click\\\")\\\ if y == 1 and x == w then\\\ - return\\\ + return true\\\ end\\\ -end\\\ -\",\ +end\",\ }", config = "{\ type = \"system\",\ name = \"Info\",\ main = \"info.lua\",\ - version = 1,\ id = \"sphone.info\",\ author = \"Sertex\",\ hidden = true,\ + version = 1,\ }", -} +} \ No newline at end of file diff --git a/src/apps/spks/settings.spk b/src/apps/spks/settings.spk index b8ca39f..2937b3c 100644 --- a/src/apps/spks/settings.spk +++ b/src/apps/spks/settings.spk @@ -1,5 +1,5 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { @@ -239,6 +239,7 @@ local function editTheme()\\\ \\\"Background Color\\\",\\\ \\\"Window Options\\\",\\\ \\\"Login Options\\\",\\\ + \\\"\\\",\\\ \\\"Save\\\",\\\ \\\"Load\\\",\\\ \\\"Reset\\\",\\\ @@ -307,7 +308,7 @@ local function editTheme()\\\ sPhone.applyTheme(\\\"lock.error\\\", sPhone.colorPicker(\\\"Error\\\",sPhone.getTheme(\\\"lock.error\\\")))\\\ end\\\ end\\\ - elseif id == 9 then\\\ + elseif id == 10 then\\\ local saveTheme\\\ sPhone.header(sPhone.user)\\\ term.setCursorPos(w,1)\\\ @@ -334,7 +335,7 @@ local function editTheme()\\\ end\\\ fs.copy(\\\"/.sPhone/config/theme\\\", saveTheme)\\\ sPhone.winOk(\\\"Theme saved!\\\")\\\ - elseif id == 10 then\\\ + elseif id == 11 then\\\ local loadTheme = sPhone.list()\\\ if loadTheme then\\\ if fs.exists(loadTheme) and not fs.isDir(loadTheme) then\\\ @@ -349,7 +350,7 @@ local function editTheme()\\\ sPhone.winOk(\\\"Theme not found!\\\")\\\ end\\\ end\\\ - elseif id == 11 then\\\ + elseif id == 12 then\\\ fs.delete(\\\"/.sPhone/config/theme\\\")\\\ sPhone.theme = sPhone.defaultTheme\\\ sPhone.winOk(\\\"Removed Theme\\\")\\\ @@ -409,8 +410,8 @@ while true do\\\ end\\\ local name, id = sPhone.menu(menu, \\\"Settings\\\",\\\"X\\\")\\\ if id == 0 then\\\ - task.kill(temp.get(\\\"homePID\\\"))\\\ - return\\\ + --task.kill(temp.get(\\\"homePID\\\"))\\\ + return true\\\ elseif id == 1 then\\\ setfenv(loadstring(http.get(\\\"https://raw.githubusercontent.com/SertexTeam/sPhone/master/src/installer.lua\\\").readAll()),getfenv())()\\\ elseif id == 2 then\\\ @@ -428,16 +429,15 @@ while true do\\\ elseif id == 8 then\\\ config.write(\\\"/.sPhone/config/sPhone\\\",\\\"showUpdate\\\", not config.read(\\\"/.sPhone/config/sPhone\\\",\\\"showUpdate\\\"))\\\ end\\\ -end\\\ -\",\ +end\",\ }", config = "{\ type = \"system\",\ name = \"Settings\",\ main = \"settings.lua\",\ - version = 1,\ id = \"sphone.settings\",\ author = \"Sertex\",\ hidden = true,\ + version = 1,\ }", -} +} \ No newline at end of file diff --git a/src/apps/spks/shell.spk b/src/apps/spks/shell.spk index 5c66024..389f526 100644 --- a/src/apps/spks/shell.spk +++ b/src/apps/spks/shell.spk @@ -1,5 +1,5 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { @@ -9,15 +9,16 @@ term.setTextColor(colors.white)\\\ term.clear()\\\ term.setCursorPos(1,1)\\\ shell.run(\\\"/rom/programs/shell\\\")\\\ -\",\ +\\\ +return true\",\ }", config = "{\ type = \"app\",\ name = \"Shell\",\ version = 1,\ - main = \"shell.lua\",\ id = \"sphone.shell\",\ - author = \"BeaconNet\",\ + author = \"Sertex\",\ hidden = true,\ + main = \"shell.lua\",\ }", } \ No newline at end of file diff --git a/src/apps/spks/store.spk b/src/apps/spks/store.spk index 0baaf23..c7c6b3f 100644 --- a/src/apps/spks/store.spk +++ b/src/apps/spks/store.spk @@ -1,5 +1,5 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { @@ -69,7 +69,7 @@ while true do\\\ })\\\ \\\ if not path then\\\ - return\\\ + return true\\\ end\\\ \\\ local data = http.get(\\\"https://raw.github.com/SertexTeam/sPhone-Store/master/apps/\\\"..path).readAll()\\\ @@ -132,16 +132,15 @@ while true do\\\ \\\ \\\ \\\ - end\\\ -\",\ + end\",\ }", config = "{\ type = \"app\",\ name = \"Store\",\ version = 1,\ - main = \"store.lua\",\ id = \"sphone.store\",\ author = \"Sertex\",\ hidden = true,\ + main = \"store.lua\",\ }", -} +} \ No newline at end of file diff --git a/src/apps/spks/themes.spk b/src/apps/spks/themes.spk index b9daf2a..98fbc07 100644 --- a/src/apps/spks/themes.spk +++ b/src/apps/spks/themes.spk @@ -1,50 +1,51 @@ -- --- sPhone Application Package +-- Sertex Application Package -- Built with SPK builder 1.2 -- { files = "{\ - [ \"themes.lua\" ] = \"if not sPhone then\\r\\\ - printError(\\\"sPhone must be installed and loaded before running this program\\\")\\r\\\ - return\\r\\\ -end\\r\\\ -\\r\\\ -\\r\\\ -print(\\\"Downloading theme list\\\")\\r\\\ -local url = \\\"https://raw.github.com/Ale32bit/sPhone-Mods/master/themes.lua\\\"\\r\\\ -\\r\\\ -local ht = http.get(url)\\r\\\ -local themesRaw = ht.readAll()\\r\\\ -local themes = textutils.unserialize(themesRaw)\\r\\\ -ht.close()\\r\\\ -\\r\\\ -local li = {}\\r\\\ -for k,v in pairs(themes) do\\r\\\ - table.insert(li,k)\\r\\\ -end\\r\\\ -while true do\\r\\\ - local g, c = sPhone.menu(li,\\\" Themes\\\",\\\"X\\\")\\r\\\ - if c == 0 then\\r\\\ - return\\r\\\ - elseif c > #li then\\r\\\ - \\r\\\ - else\\r\\\ - for k,v in pairs(themes[g]) do\\r\\\ - sPhone.applyTheme(k,v)\\r\\\ - end\\r\\\ - sPhone.winOk(\\\"Theme applied\\\")\\r\\\ - break\\r\\\ - end\\r\\\ -end\\r\\\ -\",\ + [ \"themes.lua\" ] = \"if not sPhone then\\\ + printError(\\\"sPhone must be installed and loaded before running this program\\\")\\\ + return\\\ +end\\\ +\\\ +\\\ +print(\\\"Downloading theme list\\\")\\\ +local url = \\\"https://raw.github.com/Ale32bit/sPhone-Mods/master/themes.lua\\\"\\\ +\\\ +local ht = http.get(url)\\\ +local themesRaw = ht.readAll()\\\ +local themes = textutils.unserialize(themesRaw)\\\ +ht.close()\\\ +\\\ +local li = {}\\\ +for k,v in pairs(themes) do\\\ + table.insert(li,k)\\\ +end\\\ +while true do\\\ + local g, c = sPhone.menu(li,\\\" Themes\\\",\\\"X\\\")\\\ + if c == 0 then\\\ + return\\\ + elseif c > #li then\\\ + \\\ + else\\\ + for k,v in pairs(themes[g]) do\\\ + sPhone.applyTheme(k,v)\\\ + end\\\ + sPhone.winOk(\\\"Theme applied\\\")\\\ + break\\\ + end\\\ +end\\\ +\\\ +return true\",\ }", config = "{\ type = \"app\",\ name = \"Theme List\",\ version = 1,\ - main = \"themes.lua\",\ id = \"sphone.themes\",\ - author = \"BeaconNet\",\ + author = \"Sertex\",\ hidden = true,\ + main = \"themes.lua\",\ }", } \ No newline at end of file From dcbd5753da5917f519eef4ba302d800a6417469c Mon Sep 17 00:00:00 2001 From: Alessandro <4512372+Ale32bit@users.noreply.github.com> Date: Mon, 28 Oct 2019 19:30:17 +0100 Subject: [PATCH 2/3] Final update Bug fixes --- src/sPhone | 1419 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1419 insertions(+) create mode 100644 src/sPhone diff --git a/src/sPhone b/src/sPhone new file mode 100644 index 0000000..6e54700 --- /dev/null +++ b/src/sPhone @@ -0,0 +1,1419 @@ +local function kernel(...) + _G.sPhone = { + version = "Beta 1.2.2", + user = "Guest", + devMode = false, + mainTerm = term.current(), + safeMode = false, + } + + if safemode then + sPhone.safeMode = true + safemode = nil + end + + sPhone.defaultApps = { + ["home"] = "sphone.home", + } + + sPhone.theme = { --Default colors + ["header"] = colors.blue, + ["headerText"] = colors.white, + ["text"] = colors.black, + ["background"] = "", + ["backgroundColor"] = colors.white, + ["window.background"] = colors.lightBlue, + ["window.side"] = colors.blue, + ["window.button"] = colors.lightBlue, + ["window.text"] = colors.white, + ["lock.background"] = colors.white, + ["lock.text"] = colors.black, + ["lock.inputBackground"] = colors.white, + ["lock.inputText"] = colors.black, + ["lock.inputSide"] = colors.lightBlue, + ["lock.error"] = colors.red, + } + + sPhone.defaultTheme = sPhone.theme + + 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 config.write("/.sPhone/config/sPhone","configVersion",1) then + config.convert("/.sPhone/config/sPhone") + config.write("/.sPhone/config/sPhone","configVersion",1) + end + + if not fs.exists("/.sPhone/system") then + fs.makeDir("/.sPhone/system") + end + + for k, v in pairs(fs.list("/.sPhone/system")) do + if not fs.isDir("/.sPhone/system/"..v) then + dofile("/.sPhone/system/"..v) + end + end + + local sPath = shell.path() + sPath = sPath..":/bin" + shell.setPath(sPath) + + if not fs.exists("/.sPhone/autorun") then + fs.makeDir("/.sPhone/autorun") + end + + term.setBackgroundColor(colors.white) + term.clear() + term.setCursorPos(1,1) + for k, v in pairs(fs.list("/.sPhone/autorun")) do + 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) + if not ok then + term.setTextColor(colors.red) + print("Script error: "..v..": "..err) + fs.move("/.sPhone/autorun/"..v, "/.sPhone/autorun/disabled/"..v) + term.setTextColor(colors.blue) + print(v.." disabled to prevent errors") + end + else + print("Script "..v.." not loaded because Safe Mode") + end + end + end + + if config.read("/.sPhone/config/sPhone","username") then + sPhone.user = config.read("/.sPhone/config/sPhone","username") + end + + if not fs.exists("/.sPhone/config/sPhone") then + config.write("/.sPhone/config/sPhone","devMode",false) + end + + sPhone.devMode = config.read("/.sPhone/config/sPhone","devMode") + + if sPhone.devMode then + sPhone.crash = crash + end + + crash = nil + + function os.version() + return "sPhone "..sPhone.version + end + + function sPhone.getSize() + return term.getSize() + end + + local fileTheme = "/.sPhone/config/theme" + if fs.exists(fileTheme) then + sPhone.theme["header"] = (config.read(fileTheme, "header") or sPhone.theme["header"]) + sPhone.theme["headerText"] = (config.read(fileTheme, "headerText") or sPhone.theme["headerText"]) + sPhone.theme["text"] = (config.read(fileTheme, "text") or sPhone.theme["text"]) + sPhone.theme["background"] = (config.read(fileTheme, "background") or sPhone.theme["background"]) + sPhone.theme["backgroundColor"] = (config.read(fileTheme, "backgroundColor") or sPhone.theme["backgroundColor"]) + sPhone.theme["window.background"] = (config.read(fileTheme, "window.background") or sPhone.theme["window.background"]) + sPhone.theme["window.side"] = (config.read(fileTheme, "window.side") or sPhone.theme["window.side"]) + sPhone.theme["window.button"] = (config.read(fileTheme, "window.button") or sPhone.theme["window.button"]) + sPhone.theme["window.text"] = (config.read(fileTheme, "window.text") or sPhone.theme["window.text"]) + sPhone.theme["lock.background"] = (config.read(fileTheme, "lock.background") or sPhone.theme["lock.background"]) + sPhone.theme["lock.text"] = (config.read(fileTheme, "lock.text") or sPhone.theme["lock.text"]) + sPhone.theme["lock.inputBackground"] = (config.read(fileTheme, "lock.inputBackground") or sPhone.theme["lock.inputBackground"]) + sPhone.theme["lock.inputText"] = (config.read(fileTheme, "lock.inputText") or sPhone.theme["lock.inputText"]) + sPhone.theme["lock.inputSide"] = (config.read(fileTheme, "lock.inputSide") or sPhone.theme["lock.inputSide"]) + sPhone.theme["lock.error"] = (config.read(fileTheme, "lock.error") or sPhone.theme["lock.error"]) + else + for k, v in pairs(sPhone.theme) do + config.write(fileTheme, k, v) + end + end + + function sPhone.applyTheme(id, value) + if not value or not id then + error("bad arguement: double expected, got nil",2) + end + sPhone.theme[id] = value + config.write(fileTheme, id, value) + end + + function sPhone.getTheme(id) + if not id then + error("bad arguement: double expected, got nil",2) + end + local n = config.read(fileTheme, id) + if n then + return n + end + return sPhone.defaultTheme[id] + end + + function sPhone.setDefaultApp(app, path) + if not path then + error("got nil",2) + end + + sPhone.defaultApps[app] = path + config.write("/.sPhone/config/defaultApps",app,path) + end + + function sPhone.getDefaultApp(app) + if not app then + error("got nil",2) + end + + local n = config.read("/.sPhone/config/defaultApps",app) + return n + end + + if not fs.exists("/.sPhone/config/defaultApps") then + sPhone.setDefaultApp("home","sphone.home") + end + + function string.getExtension(name) + local ext = "" + local exten = false + name = string.reverse(name) + for i = 1, #name do + local s = string.sub(name,i,i) + if s == "." then + ch = i - 1 + exten = true + break + end + end + if exten then + ext = string.sub(name, 1, ch) + return string.reverse(ext) + else + return nil + end + end + + function sPhone.list(path, opt) + opt = opt or {} + opt.bg1 = opt.bg1 or sPhone.getTheme("backgroundColor") + opt.fg1 = opt.fg1 or sPhone.getTheme("text") + opt.fg1b = opt.fg1b or colors.lime + opt.bg2 = opt.bg2 or sPhone.getTheme("header") + opt.fg2 = opt.fg2 or sPhone.getTheme("headerText") + opt.bg3 = opt.bg3 or sPhone.getTheme("header") + opt.fg3 = opt.fg3 or sPhone.getTheme("headerText") + opt.output = opt.output or true + opt.list = opt.list or false + opt.pairs = opt.pairs or false + opt.title = opt.title or false + if not path then + path = "" + end + if not fs.isDir(path) and not opt.list then + error("Invalid path") + end + local scroll = 0 + local items + local cho = {} + local w, h + local function rebuild() + local files, dirs = {}, {} + items = {} + local flist + if not opt.list then + flist = fs.list(path) + else + flist = opt.list + end + + local function pair(tab) + if opt.pairs then + return pairs(tab) + end + return ipairs(tab) + end + + for i, v in pair(flist) do + if fs.isDir(fs.combine(path, v)) then + table.insert(dirs, v) + else + table.insert(files, v) + end + end + table.sort(files) + table.sort(dirs) + for i, v in pair(dirs) do + table.insert(items, v) + end + for i, v in pair(files) do + table.insert(items, v) + end + + if opt.pairs then + for k, v in pairs(flist) do + cho[v] = k + end + end + scroll = 0 + end + rebuild() + local setVisible = term.current().setVisible + or function()end + local function redraw() + w, h = term.getSize() + setVisible(false) + term.setBackgroundColor(opt.bg1) + term.clear() + for i = scroll + 1, h + scroll - 1 do + local str = items[i] + if str then + term.setCursorPos(2, 1 + i - scroll) + local isDir + if not opt.pairs then + isDir = fs.isDir(fs.combine(path, str)) + else + isDir = false + end + term.setTextColor(isDir and opt.fg1b or opt.fg1) + local _w = w - (isDir and 2 or 1) + if #str > _w then + str = str:sub(1, _w - 2) .. ".." + end + if isDir then + str = str .. "/" + end + term.write(str) + end + end + term.setBackgroundColor(opt.bg2) + term.setTextColor(opt.fg2) + term.setCursorPos(1, 1) + term.clearLine() + local _path = path .. "/" + if #_path > w - 2 then + _path = ".." .. _path:sub(-w + 4) + end + if opt.title then + _path = opt.title + end + term.write(_path) + term.setBackgroundColor(opt.bg3) + term.setTextColor(opt.fg3) + term.setCursorPos(w, 1) + term.write("X") + term.setCursorPos(w, 2) + term.write("^") + term.setCursorPos(w, h) + term.write("v") + setVisible(true) + end + while true do + redraw() + local ev = {os.pullEventRaw()} + if ev[1] == "terminate" then + return nil + elseif ev[1] == "mouse_scroll" and ev[4] > 1 then + scroll = scroll + ev[2] + elseif ev[1] == "mouse_click" then + if ev[3] == w and ev[2] == 1 then + if ev[4] == 1 then + return nil + elseif ev[4] == 2 then + scroll = scroll - 1 + elseif ev[4] == h then + scroll = scroll + 1 + end + elseif ev[3] < w and ev[4] == 1 and ev[2] == 1 then + path = fs.getDir(path) + if path == ".." then + path = "" + end + rebuild() + elseif ev[3] < w and ev[4] > 1 then + local item = items[ev[4] + scroll - 1] + if item then + local fullPath = fs.combine(path, item) + if fs.isDir(fullPath) then + path = fullPath + rebuild() + else + if opt.output then + if opt.pairs then + return cho[fullPath], fullPath, ev[2] + end + return fullPath, ev[2] + end + end + end + end + end + scroll = math.min(math.max(0, scroll), math.max(0, #items - h + 1)) + end + end + + function sPhone.read( _sReplaceChar, _tHistory, _fnComplete, _MouseEvent, _presetInput ) + term.setCursorBlink( true ) + + local sLine = _presetInput + + if type(sLine) ~= "string" then + sLine = "" + end + local nPos = #sLine + local nHistoryPos + local _MouseX + local _MouseY + local param + local sEvent + local usedMouse = false + if _sReplaceChar then + _sReplaceChar = string.sub( _sReplaceChar, 1, 1 ) + end + + local tCompletions + local nCompletion + local function recomplete() + if _fnComplete and nPos == string.len(sLine) then + tCompletions = _fnComplete( sLine ) + if tCompletions and #tCompletions > 0 then + nCompletion = 1 + else + nCompletion = nil + end + else + tCompletions = nil + nCompletion = nil + end + end + + local function uncomplete() + tCompletions = nil + nCompletion = nil + end + + local w = term.getSize() + local sx = term.getCursorPos() + + local function redraw( _bClear ) + local nScroll = 0 + if sx + nPos >= w then + nScroll = (sx + nPos) - w + end + + local cx,cy = term.getCursorPos() + term.setCursorPos( sx, cy ) + local sReplace = (_bClear and " ") or _sReplaceChar + if sReplace then + term.write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) ) + else + term.write( string.sub( sLine, nScroll + 1 ) ) + end + + if nCompletion then + local sCompletion = tCompletions[ nCompletion ] + local oldText, oldBg + if not _bClear then + oldText = term.getTextColor() + oldBg = term.getBackgroundColor() + term.setTextColor( colors.white ) + term.setBackgroundColor( colors.gray ) + end + if sReplace then + term.write( string.rep( sReplace, string.len( sCompletion ) ) ) + else + term.write( sCompletion ) + end + if not _bClear then + term.setTextColor( oldText ) + term.setBackgroundColor( oldBg ) + end + end + + term.setCursorPos( sx + nPos - nScroll, cy ) + end + + local function clear() + redraw( true ) + end + + recomplete() + redraw() + + local function acceptCompletion() + if nCompletion then + -- Clear + clear() + + -- Find the common prefix of all the other suggestions which start with the same letter as the current one + local sCompletion = tCompletions[ nCompletion ] + sLine = sLine .. sCompletion + nPos = string.len( sLine ) + + -- Redraw + recomplete() + redraw() + end + end + while true do + sEvent, param,_MouseX,_MouseY = os.pullEvent() + if sEvent == "char" then + -- Typed key + clear() + sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 ) + nPos = nPos + 1 + recomplete() + redraw() + + elseif sEvent == "paste" then + -- Pasted text + clear() + sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 ) + nPos = nPos + string.len( param ) + recomplete() + redraw() + + elseif sEvent == "key" then + if param == keys.enter then + -- Enter + if nCompletion then + clear() + uncomplete() + redraw() + end + break + + elseif param == keys.left then + -- Left + if nPos > 0 then + clear() + nPos = nPos - 1 + recomplete() + redraw() + end + + elseif param == keys.right then + -- Right + if nPos < string.len(sLine) then + -- Move right + clear() + nPos = nPos + 1 + recomplete() + redraw() + else + -- Accept autocomplete + acceptCompletion() + end + + elseif param == keys.up or param == keys.down then + -- Up or down + if nCompletion then + -- Cycle completions + clear() + if param == keys.up then + nCompletion = nCompletion - 1 + if nCompletion < 1 then + nCompletion = #tCompletions + end + elseif param == keys.down then + nCompletion = nCompletion + 1 + if nCompletion > #tCompletions then + nCompletion = 1 + end + end + redraw() + + elseif _tHistory then + -- Cycle history + clear() + if param == keys.up then + -- Up + if nHistoryPos == nil then + if #_tHistory > 0 then + nHistoryPos = #_tHistory + end + elseif nHistoryPos > 1 then + nHistoryPos = nHistoryPos - 1 + end + else + -- Down + if nHistoryPos == #_tHistory then + nHistoryPos = nil + elseif nHistoryPos ~= nil then + nHistoryPos = nHistoryPos + 1 + end + end + if nHistoryPos then + sLine = _tHistory[nHistoryPos] + nPos = string.len( sLine ) + else + sLine = "" + nPos = 0 + end + uncomplete() + redraw() + + end + + elseif param == keys.backspace then + -- Backspace + if nPos > 0 then + clear() + sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 ) + nPos = nPos - 1 + recomplete() + redraw() + end + + elseif param == keys.home then + -- Home + if nPos > 0 then + clear() + nPos = 0 + recomplete() + redraw() + end + + elseif param == keys.delete then + -- Delete + if nPos < string.len(sLine) then + clear() + sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 ) + recomplete() + redraw() + end + + elseif param == keys["end"] then + -- End + if nPos < string.len(sLine ) then + clear() + nPos = string.len(sLine) + recomplete() + redraw() + end + + elseif param == keys.tab then + -- Tab (accept autocomplete) + acceptCompletion() + + end + + elseif sEvent == "term_resize" then + -- Terminal resized + w = term.getSize() + redraw() + + elseif sEvent == "mouse_click" and _MouseEvent then + if nCompletion then + clear() + uncomplete() + redraw() + end + usedMouse = true + break + end + end + + local cx, cy = term.getCursorPos() + term.setCursorBlink( false ) + term.setCursorPos( w + 1, cy ) + print() + if sEvent == "mouse_click" then + return sLine, param, _MouseX, _MouseY + end + return sLine + end + + local function clear() + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.clear() + term.setCursorPos(1,1) + term.setTextColor(sPhone.theme["text"]) + end + + sPhone.forceShutdown = os.shutdown + sPhone.forceReboot = os.reboot + + function os.shutdown() + local w, h = term.getSize() + local text = "Shutting down" + local x = math.ceil(w/2)-math.ceil(#text/2)+1 + local y = math.ceil(h/2) + sPhone.inHome = false + os.pullEvent = os.pullEventRaw + local function printMsg(color) + term.setBackgroundColor(color) + term.setTextColor(colors.white) + term.clear() + term.setCursorPos(x,y) + print(text) + sleep(0.1) + end + printMsg(colors.white) + printMsg(colors.lightGray) + printMsg(colors.gray) + printMsg(colors.black) + sleep(0.6) + sPhone.forceShutdown() + end + + function os.reboot() + local w, h = term.getSize() + local text = "Rebooting" + local x = math.ceil(w/2)-math.ceil(#text/2)+1 + local y = math.ceil(h/2) + sPhone.inHome = false + os.pullEvent = os.pullEventRaw + local function printMsg(color) + term.setBackgroundColor(color) + term.setTextColor(colors.white) + term.clear() + term.setCursorPos(x,y) + print(text) + sleep(0.1) + end + printMsg(colors.white) + printMsg(colors.lightGray) + printMsg(colors.gray) + printMsg(colors.black) + sleep(0.6) + sPhone.forceReboot() + end + + function sPhone.header(title, butt) + + if not title then + title = "sPhone" + end + + local w, h = term.getSize() + paintutils.drawLine(1,1,w,1, sPhone.theme["header"]) + term.setTextColor(sPhone.theme["headerText"]) + term.setCursorPos(1,1) + write(" "..title) + term.setCursorPos(w,1) + if butt then + write(butt) + end + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.setTextColor(sPhone.theme["text"]) + term.setCursorPos(1,3) + end + + function sPhone.menu(items, title, closeButton) + local function cprint(text) + if type(text) ~= 'table' then + text = {text} + end + + local w, h = term.getSize() + + for i=1,#text do + local x, y = term.getCursorPos() + term.setCursorPos(math.floor(w/2)-math.floor(text[i]:len()/2), y) + print(text[i]) + end + end + local function clear() + term.clear() + term.setCursorPos(1, 1) + end + + local termWidth, termHeight = term.getSize() + local drawSize = termHeight - 2 + + local function maxPages() + local itemCount = #items + local pageCount = 0 + while itemCount > 0 do + itemCount = itemCount - drawSize + pageCount = pageCount + 1 + end + return pageCount + end + + local function iif(cond, trueval, falseval) + if cond then + return trueval + else + return falseval + end + end + + local function pagedItems() + local ret = {} + for i = 1, maxPages() do + local tmp = {} + local nElements = 0 + for j = drawSize*(i-1)+1, iif(drawSize*(i+1) > #items, #items, drawSize*(i+1)) do + if nElements < drawSize then + table.insert(tmp, items[j]) + nElements = nElements + 1 + end + end + table.insert(ret, tmp) + end + return ret + end + + local selected = 1 + if start then + selected = start + end + local page = 1 + + local function redraw() + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.setTextColor(sPhone.theme["text"]) + term.clear() + term.setCursorPos(1,1) + if not title then + title = "" + end + sPhone.header(title,closeButton) + term.setCursorPos(1,3) + if moreTitle then + head = moreTitle + else + head = {} + if not allowNil or allowNil == true then + --head[3] = 'Terminate to cancel.' + end + end + for i=1,#head do + print(head[i]) + end + if maxPages() > 1 then + pages = "<- (page "..page.." of "..maxPages()..") ->" + print(pages) + end + for i = 1, #pagedItems()[page] do + if selected == drawSize*(page-1)+i then + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.setTextColor(sPhone.theme["text"]) + else + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.setTextColor(sPhone.theme["text"]) + end + term.clearLine() + cprint(iif(selected == drawSize*(page-1)+i,"","").." "..pagedItems()[page][i]) + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.setTextColor(sPhone.theme["text"]) + end + end + + local function changePage(pW) + if pW == 1 and page < maxPages() then + page = page + 1 + if selected + drawSize > #items then + selected = #items + else + selected = selected + drawSize + end + elseif pW == -1 and page > 1 then + page = page - 1 + if selected - drawSize < 1 then + selected = 1 + else + selected = selected - drawSize + end + end + end + + redraw() + while true do + local eventData = {os.pullEventRaw()} + if eventData[1] == 'mouse_click' then + if eventData[4] == 1 and eventData[3] == termWidth then + return false, 0 + elseif eventData[4] > 2 then + clear() + selected = (eventData[4]-3+((page-1)*drawSize))+1 + if selected then + return items[selected], selected + end + end + end + end +end + + function sPhone.yesNo(title, desc, hideUser) + term.setCursorBlink(false) + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.clear() + term.setCursorPos(1,1) + term.setTextColor(sPhone.theme["text"]) + local w, h = term.getSize() + paintutils.drawLine(1,1,w,1, sPhone.theme["header"]) + term.setTextColor(sPhone.theme["headerText"]) + term.setCursorPos(1,1) + if not hideUser then + if not sPhone.user then + write(" sPhone") + else + write(" "..sPhone.user) + end + end + term.setCursorPos(1,3) + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.setTextColor(sPhone.theme["text"]) + visum.align("center", " "..title, false, 3) + if desc then + term.setCursorPos(2,6) + print(desc) + end + paintutils.drawFilledBox(3, 16, 9, 18, colors.green) + paintutils.drawFilledBox(18, 16, 24, 18, colors.red) + term.setTextColor(colors.white) + term.setCursorPos(5,17) + term.setBackgroundColor(colors.green) + write("Yes") + term.setCursorPos(20,17) + term.setBackgroundColor(colors.red) + write("No") + while true do + local _,_,x,y = os.pullEvent("mouse_click") + if (x > 2 and y > 15) and (x < 10 and y < 19) then + return true + elseif (x > 17 and y > 15) and (x < 25 and y < 19) then + return false + end + end + end + + function sPhone.winOk(fmessage, smessage, bg, side, text, button) + if not fmessage then + fmessage = "" + end + if not smessage then + smessage = "" + end + if not bg then + bg = sPhone.theme["window.background"] + end + if not text then + text = sPhone.theme["window.text"] + end + if not button then + button = sPhone.theme["window.button"] + end + if not side then + side = sPhone.theme["window.side"] + end + term.setCursorBlink(false) + if #fmessage >= #smessage then + local w, h = term.getSize + term.setBackgroundColor(side) + paintutils.drawBox(12 - math.ceil(#fmessage / 2), 5, 15 + math.ceil(#fmessage / 2), 10, side) + term.setBackgroundColor(bg) + paintutils.drawFilledBox(13 - math.ceil(#fmessage / 2), 6, 14 + math.ceil(#fmessage / 2), 9, bg) + term.setCursorPos(14 - math.ceil(#fmessage / 2), 7) + term.setTextColor(text) + write(fmessage) + term.setCursorPos(14 - math.ceil(#smessage / 2), 8) + write(smessage) + else + local w, h = term.getSize + term.setBackgroundColor(side) + paintutils.drawBox(12 - math.ceil(#smessage / 2), 5, 15 + math.ceil(#smessage / 2), 10, side) + term.setBackgroundColor(bg) + paintutils.drawFilledBox(13 - math.ceil(#smessage / 2), 6, 14 + math.ceil(#smessage / 2), 9, bg) + term.setCursorPos(14 - math.ceil(#fmessage / 2), 7) + term.setTextColor(text) + write(fmessage) + term.setCursorPos(14 - math.ceil(#smessage / 2), 8) + write(smessage) + end + term.setCursorPos(13,10) + term.setBackgroundColor(button) + write("Ok") + while true do + local e, k, x,y = os.pullEvent() + if e == "mouse_click" then + if y == 10 then + if x == 13 or x == 14 then + return + end + end + elseif e == "key" then + if k == 28 then + return + end + end + end + end + + function sPhone.colorPicker(message, old) -- From Impulse + local current = math.log(old) / math.log(2) + -- first line is already code wizardry + local function redraw() + term.setBackgroundColour(sPhone.theme["backgroundColor"]) + term.clear() + sPhone.header(message) + term.setCursorPos(2,5) + term.setTextColor(colors.white) + term.setBackgroundColor(colors.lime) + write(" Ok ") + term.setCursorPos(7,5) + term.setTextColor(colors.white) + term.setBackgroundColor(colors.red) + write(" Cancel ") + term.setTextColor(colors.black) + term.setCursorPos(2, 3) + for i = 0, 15 do + term.setBackgroundColour(2^i) + term.write(i == current and "#" or ":") + end + end + while true do + redraw() + local ev = {os.pullEvent()} + if ev[1] == "key" and ev[2] == keys.enter then + return 2^current + elseif ev[1] == "mouse_click" then + if ev[4] == 3 and ev[3] >= 2 and ev[3] <= 17 then + current = ev[3] - 2 % 16 + elseif ev[4] == 5 and ev[3] >= 2 and ev[3] <= 6 then + return 2^current + elseif ev[4] == 5 and ev[3] >= 7 and ev[3] <= 14 then + return old + end + end + end + end + + sPhone.colourPicker = sPhone.colorPicker -- For UK + + function sPhone.install(spk) + if not fs.exists("/.sPhone/config/spklist") then + local f = fs.open("/.sPhone/config/spklist","w") + f.write("{}") + f.close() + end + if string.getExtension(spk) == "spk" then + if fs.exists(spk) and not fs.isDir(spk) then + local f = fs.open(spk,"r") + local script = f.readAll() + f.close() + script = textutils.unserialize(script) + if not script then + error("spk corrupted",2) + end + + local function writeFile(patha,contenta) + local file = fs.open(patha,"w") + file.write(contenta) + file.close() + end + function writeDown(inputa,dira) + for i,v in pairs(inputa) do + if type(v) == "table" then + writeDown(v,dira.."/"..i) + elseif type(v) == "string" then + writeFile(dira.."/"..i,v) + end + end + end + + local _config = textutils.unserialize(script.config) + if not _config.id then + error("SPK: id not found",2) + end + if not _config.main then + error("SPK: main not found",2) + end + writeDown(textutils.unserialize(script.files),"/.sPhone/apps/spk/".._config.id.."/files") + local f = fs.open("/.sPhone/apps/spk/".._config.id.."/.spk","w") + f.write(textutils.serialize(_config)) + f.close() + local f = fs.open("/.sPhone/config/spklist","r") + local lists = f.readAll() + f.close() + lists = textutils.unserialize(lists) + if not lists then + error("Cannot open config",2) + end + + if not _config.name then + _config.name = _config.id + end + + lists[_config.id] = _config.name + + local f = fs.open("/.sPhone/config/spklist","w") + f.write(textutils.serialize(lists)) + f.close() + return true, _config.id + else + return false, "not a spk file" + end + else + return false, "not a spk file" + end + end + + function sPhone.launch(spk) + if not fs.exists("/.sPhone/config/spklist") then + local f = fs.open("/.sPhone/config/spklist","w") + f.write("{}") + f.close() + end + local f = fs.open("/.sPhone/config/spklist","r") + local lists = f.readAll() + f.close() + lists = textutils.unserialize(lists) + if not lists then + error("Cannot open config",2) + end + + if not lists[spk] then + return false, "not installed" + end + + if not fs.exists("/.sPhone/apps/spk/"..spk.."/.spk") then + return false, "Invalid SPK, .spk not found" + end + + local f = fs.open("/.sPhone/apps/spk/"..spk.."/.spk","r") + local script = f.readAll() + f.close() + _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, + + getID = function() + return (_config.id or nil) + end, + + getPath = function() + return "/.sPhone/apps/spk/".._config.id + end, + + getDataPath = function() + return "/.sPhone/apps/spk/".._config.id.."/data" + end, + + getAuthor = function() + return (_config.author or nil) + end, + + getVersion = function() + return (_config.version 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) + + if not ok then + return false, err + end + return true, result + end + + local function home() + sPhone.inHome = true + local errorCount = 0 + local ok, err + local homeID + local homeSPKs = { + "sphone.home", + } + while true do + + + if not config.read("/.sPhone/config/spklist","sphone.home") then + sPhone.install("/.sPhone/apps/home.spk") + end + os.pullEvent = os.oldPullEvent + term.setBackgroundColor(colors.black) + term.setTextColor(colors.white) + term.clear() + term.setCursorPos(1,1) + if errorCount >= 5 and errorCount < 10 then + homeID = "sphone.home" + elseif errorCount >= 10 then + error("Cannot load home: "..err,0) + else + homeID = sPhone.getDefaultApp("home") + end + if not sPhone.safeMode then + if not config.list("/.sPhone/config/spklist")[homeID] then + homeID = "sphone.home" + end + else + homeID = "sphone.home" + end + temp.set("homePID",task.add(function() + ok,err = sPhone.launch(homeID) + end)) + task.run() + if not ok then + errorCount = errorCount + 1 + end + sleep(0) + + end + sPhone.inHome = false + end + + function login() + if config.read("/.sPhone/config/sPhone","lockEnabled") == nil then + config.write("/.sPhone/config/sPhone","lockEnabled",true) + end + local usingPW = config.read("/.sPhone/config/sPhone","lockEnabled") + if not usingPW then + local old = os.pullEvent + os.pullEvent = os.pullEventRaw + local fEvents = { + ["mouse_drag"] = true, + ["mouse_click"] = true, + ["key"] = false, + } + while true do + local w,h = term.getSize() + local clockS = textutils.formatTime(os.time(), not config.read("/.sPhone/config/sPhone","format12time")) + term.setBackgroundColor(sPhone.theme["lock.background"]) + term.clear() + term.setCursorPos(1,1) + sPhone.header(sPhone.user) + term.setBackgroundColor(sPhone.theme["lock.background"]) + term.setTextColor(sPhone.theme["lock.text"]) + term.setCursorPos(6,4) + bigfont.bigPrint(clockS) + visum.align("center"," Slide to unlock",false,h) + local clockUpdate = os.startTimer(1) + local e = {os.pullEvent()} + if fEvents[e[1]] then + os.pullEvent = old + break + end + end + return + end + local old = os.pullEvent + os.pullEvent = os.pullEventRaw + sPhone.locked = true + if config.read("/.sPhone/config/sPhone","password") then + while true do + term.setBackgroundColor(sPhone.theme["lock.background"]) + term.clear() + term.setCursorPos(1,1) + sPhone.header(sPhone.user) + paintutils.drawBox(7,9,20,11,sPhone.theme["lock.inputSide"]) + if sPhone.wrongPassword then + term.setTextColor(sPhone.theme["lock.error"]) + term.setBackgroundColor(sPhone.theme["lock.background"]) + visum.align("center"," Wrong Password",false,13) + end + term.setTextColor(sPhone.theme["lock.text"]) + term.setBackgroundColor(sPhone.theme["lock.background"]) + visum.align("center"," Insert Password",false,7) + local loginTerm = window.create(term.native(), 8,10,12,1, true) + term.redirect(loginTerm) + term.setBackgroundColor(sPhone.theme["lock.inputBackground"]) + term.clear() + term.setCursorPos(1,1) + term.setTextColor(sPhone.theme["lock.inputText"]) + local passwordLogin = read("*") + term.redirect(sPhone.mainTerm) + local fpw = config.read("/.sPhone/config/sPhone","password") + if sha256.sha256(passwordLogin) == fpw then + sPhone.wrongPassword = false + os.pullEvent = old + return + else + sPhone.wrongPassword = true + end + end + else + local name + local pw + local pwr + local rServer + local password1,mouse,x,y + local w, h = term.getSize() + local skipped = false + sPhone.firstBoot = true + + for k,v in ipairs(fs.list("/.sPhone/apps/system")) do + sPhone.install("/.sPhone/apps/system/"..v) + end + + while not skipped do + + term.setBackgroundColor(sPhone.theme["lock.background"]) + term.clear() + term.setCursorPos(1,1) + sPhone.header("Setup") + paintutils.drawBox(7,9,20,11,sPhone.theme["lock.inputSide"]) + if sPhone.wrongPassword then + term.setTextColor(sPhone.theme["lock.error"]) + term.setBackgroundColor(sPhone.theme["lock.background"]) + visum.align("center"," Wrong Password",false,13) + end + term.setTextColor(sPhone.theme["lock.text"]) + term.setBackgroundColor(sPhone.theme["lock.background"]) + visum.align("center"," Insert Password",false,7) + local t = "Skip" + term.setCursorPos(w-#t+1,h) + write(t) + local loginTerm = window.create(term.native(), 8,10,12,1, true) + term.redirect(loginTerm) + term.setBackgroundColor(sPhone.theme["lock.inputBackground"]) + term.clear() + term.setCursorPos(1,1) + term.setTextColor(sPhone.theme["lock.inputText"]) + while true do + password1,mouse,x,y = sPhone.read("*",nil,nil,true) + if mouse then + if y == h and (x >= 23 and x <= w) then + skipped = true + config.write("/.sPhone/config/sPhone","lockEnabled",false) + break + end + else + break + end + end + term.redirect(sPhone.mainTerm) + if not skipped then + term.setBackgroundColor(sPhone.theme["lock.background"]) + term.clear() + term.setCursorPos(1,1) + sPhone.header("Setup") + paintutils.drawBox(7,9,20,11,sPhone.theme["lock.inputSide"]) + term.setTextColor(sPhone.theme["lock.text"]) + term.setBackgroundColor(sPhone.theme["lock.background"]) + visum.align("center"," Repeat",false,7) + local loginTerm = window.create(term.native(), 8,10,12,1, true) + term.redirect(loginTerm) + term.setBackgroundColor(sPhone.theme["lock.inputBackground"]) + term.clear() + term.setCursorPos(1,1) + term.setTextColor(sPhone.theme["lock.inputText"]) + local password2 = read("*") + term.redirect(sPhone.mainTerm) + if password1 == password2 then + config.write("/.sPhone/config/sPhone", "password",sha256.sha256(password1)) + term.setTextColor(colors.lime) + visum.align("center"," Password set!",false,13) + sleep(2) + break + else + sPhone.wrongPassword = true + end + end + end + + local name + + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.clear() + sPhone.header("Setup") + term.setCursorPos(1,1) + term.setTextColor(sPhone.theme["text"]) + term.setCursorPos(2,3) + visum.align("center","Username",false,3) + term.setCursorPos(2,5) + local newUsername = read() + config.write("/.sPhone/config/sPhone","username",newUsername) + + if fs.exists("/.sPhone/config/sPhone") then + name = config.read("/.sPhone/config/sPhone","username") + else + name = "Guest" + end + config.write("/.sPhone/config/sPhone","showUpdate",true) + term.setBackgroundColor(sPhone.theme["backgroundColor"]) + term.clear() + sPhone.header("Setup") + term.setCursorPos(1,1) + term.setTextColor(sPhone.theme["text"]) + sPhone.user = name + os.setComputerLabel(sPhone.user.."'s sPhone") + visum.align("center"," All Set!",false,3) + visum.align("center"," Have fun with sPhone",false,5) + sleep(2) + sPhone.locked = false + sPhone.inHome = true + sPhone.firstBoot = false + os.pullEvent = old + return + end + end + + sPhone.lock = login + sPhone.login = login + local showUpdate = config.read("/.sPhone/config/sPhone","showUpdate") + + http.request("https://raw.githubusercontent.com/SertexTeam/sPhone/master/src/version") + local newVersion + local timeout = os.startTimer(2) + while true do + local event,url, sourceText = os.pullEvent() + if event == "http_success" then + newVersion = sourceText.readLine() + sourceText.close() + break + elseif event == "http_failure" then + newVersion = sPhone.version + break + end + end + + if newVersion ~= sPhone.version and showUpdate then + sPhone.newUpdate = true + else + sPhone.newUpdate = false + end + + if config.read("/.sPhone/config/sPhone","updated") then + for k,v in pairs(fs.list("/.sPhone/apps/system")) do + sPhone.install("/.sPhone/apps/system/"..v) + end + config.write("/.sPhone/config/sPhone","updated",false) + end + + if config.read("/.sPhone/config/sPhone","showUpdate") == nil then + config.write("/.sPhone/config/sPhone","showUpdate", true) + end + + login() + if sPhone.newUpdate then + sPhone.winOk("New Update:",newVersion) + end + home() + +end +if not sPhone then + kernel({...}) +else + print("sPhone already started") +end \ No newline at end of file From 4ebdc9e87acf4e392bc1eab51a22cd8b3594fa94 Mon Sep 17 00:00:00 2001 From: Alessandro <4512372+Ale32bit@users.noreply.github.com> Date: Mon, 28 Oct 2019 19:30:38 +0100 Subject: [PATCH 3/3] fucked up --- src/sPhone | 1419 ---------------------------------------------------- 1 file changed, 1419 deletions(-) delete mode 100644 src/sPhone diff --git a/src/sPhone b/src/sPhone deleted file mode 100644 index 6e54700..0000000 --- a/src/sPhone +++ /dev/null @@ -1,1419 +0,0 @@ -local function kernel(...) - _G.sPhone = { - version = "Beta 1.2.2", - user = "Guest", - devMode = false, - mainTerm = term.current(), - safeMode = false, - } - - if safemode then - sPhone.safeMode = true - safemode = nil - end - - sPhone.defaultApps = { - ["home"] = "sphone.home", - } - - sPhone.theme = { --Default colors - ["header"] = colors.blue, - ["headerText"] = colors.white, - ["text"] = colors.black, - ["background"] = "", - ["backgroundColor"] = colors.white, - ["window.background"] = colors.lightBlue, - ["window.side"] = colors.blue, - ["window.button"] = colors.lightBlue, - ["window.text"] = colors.white, - ["lock.background"] = colors.white, - ["lock.text"] = colors.black, - ["lock.inputBackground"] = colors.white, - ["lock.inputText"] = colors.black, - ["lock.inputSide"] = colors.lightBlue, - ["lock.error"] = colors.red, - } - - sPhone.defaultTheme = sPhone.theme - - 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 config.write("/.sPhone/config/sPhone","configVersion",1) then - config.convert("/.sPhone/config/sPhone") - config.write("/.sPhone/config/sPhone","configVersion",1) - end - - if not fs.exists("/.sPhone/system") then - fs.makeDir("/.sPhone/system") - end - - for k, v in pairs(fs.list("/.sPhone/system")) do - if not fs.isDir("/.sPhone/system/"..v) then - dofile("/.sPhone/system/"..v) - end - end - - local sPath = shell.path() - sPath = sPath..":/bin" - shell.setPath(sPath) - - if not fs.exists("/.sPhone/autorun") then - fs.makeDir("/.sPhone/autorun") - end - - term.setBackgroundColor(colors.white) - term.clear() - term.setCursorPos(1,1) - for k, v in pairs(fs.list("/.sPhone/autorun")) do - 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) - if not ok then - term.setTextColor(colors.red) - print("Script error: "..v..": "..err) - fs.move("/.sPhone/autorun/"..v, "/.sPhone/autorun/disabled/"..v) - term.setTextColor(colors.blue) - print(v.." disabled to prevent errors") - end - else - print("Script "..v.." not loaded because Safe Mode") - end - end - end - - if config.read("/.sPhone/config/sPhone","username") then - sPhone.user = config.read("/.sPhone/config/sPhone","username") - end - - if not fs.exists("/.sPhone/config/sPhone") then - config.write("/.sPhone/config/sPhone","devMode",false) - end - - sPhone.devMode = config.read("/.sPhone/config/sPhone","devMode") - - if sPhone.devMode then - sPhone.crash = crash - end - - crash = nil - - function os.version() - return "sPhone "..sPhone.version - end - - function sPhone.getSize() - return term.getSize() - end - - local fileTheme = "/.sPhone/config/theme" - if fs.exists(fileTheme) then - sPhone.theme["header"] = (config.read(fileTheme, "header") or sPhone.theme["header"]) - sPhone.theme["headerText"] = (config.read(fileTheme, "headerText") or sPhone.theme["headerText"]) - sPhone.theme["text"] = (config.read(fileTheme, "text") or sPhone.theme["text"]) - sPhone.theme["background"] = (config.read(fileTheme, "background") or sPhone.theme["background"]) - sPhone.theme["backgroundColor"] = (config.read(fileTheme, "backgroundColor") or sPhone.theme["backgroundColor"]) - sPhone.theme["window.background"] = (config.read(fileTheme, "window.background") or sPhone.theme["window.background"]) - sPhone.theme["window.side"] = (config.read(fileTheme, "window.side") or sPhone.theme["window.side"]) - sPhone.theme["window.button"] = (config.read(fileTheme, "window.button") or sPhone.theme["window.button"]) - sPhone.theme["window.text"] = (config.read(fileTheme, "window.text") or sPhone.theme["window.text"]) - sPhone.theme["lock.background"] = (config.read(fileTheme, "lock.background") or sPhone.theme["lock.background"]) - sPhone.theme["lock.text"] = (config.read(fileTheme, "lock.text") or sPhone.theme["lock.text"]) - sPhone.theme["lock.inputBackground"] = (config.read(fileTheme, "lock.inputBackground") or sPhone.theme["lock.inputBackground"]) - sPhone.theme["lock.inputText"] = (config.read(fileTheme, "lock.inputText") or sPhone.theme["lock.inputText"]) - sPhone.theme["lock.inputSide"] = (config.read(fileTheme, "lock.inputSide") or sPhone.theme["lock.inputSide"]) - sPhone.theme["lock.error"] = (config.read(fileTheme, "lock.error") or sPhone.theme["lock.error"]) - else - for k, v in pairs(sPhone.theme) do - config.write(fileTheme, k, v) - end - end - - function sPhone.applyTheme(id, value) - if not value or not id then - error("bad arguement: double expected, got nil",2) - end - sPhone.theme[id] = value - config.write(fileTheme, id, value) - end - - function sPhone.getTheme(id) - if not id then - error("bad arguement: double expected, got nil",2) - end - local n = config.read(fileTheme, id) - if n then - return n - end - return sPhone.defaultTheme[id] - end - - function sPhone.setDefaultApp(app, path) - if not path then - error("got nil",2) - end - - sPhone.defaultApps[app] = path - config.write("/.sPhone/config/defaultApps",app,path) - end - - function sPhone.getDefaultApp(app) - if not app then - error("got nil",2) - end - - local n = config.read("/.sPhone/config/defaultApps",app) - return n - end - - if not fs.exists("/.sPhone/config/defaultApps") then - sPhone.setDefaultApp("home","sphone.home") - end - - function string.getExtension(name) - local ext = "" - local exten = false - name = string.reverse(name) - for i = 1, #name do - local s = string.sub(name,i,i) - if s == "." then - ch = i - 1 - exten = true - break - end - end - if exten then - ext = string.sub(name, 1, ch) - return string.reverse(ext) - else - return nil - end - end - - function sPhone.list(path, opt) - opt = opt or {} - opt.bg1 = opt.bg1 or sPhone.getTheme("backgroundColor") - opt.fg1 = opt.fg1 or sPhone.getTheme("text") - opt.fg1b = opt.fg1b or colors.lime - opt.bg2 = opt.bg2 or sPhone.getTheme("header") - opt.fg2 = opt.fg2 or sPhone.getTheme("headerText") - opt.bg3 = opt.bg3 or sPhone.getTheme("header") - opt.fg3 = opt.fg3 or sPhone.getTheme("headerText") - opt.output = opt.output or true - opt.list = opt.list or false - opt.pairs = opt.pairs or false - opt.title = opt.title or false - if not path then - path = "" - end - if not fs.isDir(path) and not opt.list then - error("Invalid path") - end - local scroll = 0 - local items - local cho = {} - local w, h - local function rebuild() - local files, dirs = {}, {} - items = {} - local flist - if not opt.list then - flist = fs.list(path) - else - flist = opt.list - end - - local function pair(tab) - if opt.pairs then - return pairs(tab) - end - return ipairs(tab) - end - - for i, v in pair(flist) do - if fs.isDir(fs.combine(path, v)) then - table.insert(dirs, v) - else - table.insert(files, v) - end - end - table.sort(files) - table.sort(dirs) - for i, v in pair(dirs) do - table.insert(items, v) - end - for i, v in pair(files) do - table.insert(items, v) - end - - if opt.pairs then - for k, v in pairs(flist) do - cho[v] = k - end - end - scroll = 0 - end - rebuild() - local setVisible = term.current().setVisible - or function()end - local function redraw() - w, h = term.getSize() - setVisible(false) - term.setBackgroundColor(opt.bg1) - term.clear() - for i = scroll + 1, h + scroll - 1 do - local str = items[i] - if str then - term.setCursorPos(2, 1 + i - scroll) - local isDir - if not opt.pairs then - isDir = fs.isDir(fs.combine(path, str)) - else - isDir = false - end - term.setTextColor(isDir and opt.fg1b or opt.fg1) - local _w = w - (isDir and 2 or 1) - if #str > _w then - str = str:sub(1, _w - 2) .. ".." - end - if isDir then - str = str .. "/" - end - term.write(str) - end - end - term.setBackgroundColor(opt.bg2) - term.setTextColor(opt.fg2) - term.setCursorPos(1, 1) - term.clearLine() - local _path = path .. "/" - if #_path > w - 2 then - _path = ".." .. _path:sub(-w + 4) - end - if opt.title then - _path = opt.title - end - term.write(_path) - term.setBackgroundColor(opt.bg3) - term.setTextColor(opt.fg3) - term.setCursorPos(w, 1) - term.write("X") - term.setCursorPos(w, 2) - term.write("^") - term.setCursorPos(w, h) - term.write("v") - setVisible(true) - end - while true do - redraw() - local ev = {os.pullEventRaw()} - if ev[1] == "terminate" then - return nil - elseif ev[1] == "mouse_scroll" and ev[4] > 1 then - scroll = scroll + ev[2] - elseif ev[1] == "mouse_click" then - if ev[3] == w and ev[2] == 1 then - if ev[4] == 1 then - return nil - elseif ev[4] == 2 then - scroll = scroll - 1 - elseif ev[4] == h then - scroll = scroll + 1 - end - elseif ev[3] < w and ev[4] == 1 and ev[2] == 1 then - path = fs.getDir(path) - if path == ".." then - path = "" - end - rebuild() - elseif ev[3] < w and ev[4] > 1 then - local item = items[ev[4] + scroll - 1] - if item then - local fullPath = fs.combine(path, item) - if fs.isDir(fullPath) then - path = fullPath - rebuild() - else - if opt.output then - if opt.pairs then - return cho[fullPath], fullPath, ev[2] - end - return fullPath, ev[2] - end - end - end - end - end - scroll = math.min(math.max(0, scroll), math.max(0, #items - h + 1)) - end - end - - function sPhone.read( _sReplaceChar, _tHistory, _fnComplete, _MouseEvent, _presetInput ) - term.setCursorBlink( true ) - - local sLine = _presetInput - - if type(sLine) ~= "string" then - sLine = "" - end - local nPos = #sLine - local nHistoryPos - local _MouseX - local _MouseY - local param - local sEvent - local usedMouse = false - if _sReplaceChar then - _sReplaceChar = string.sub( _sReplaceChar, 1, 1 ) - end - - local tCompletions - local nCompletion - local function recomplete() - if _fnComplete and nPos == string.len(sLine) then - tCompletions = _fnComplete( sLine ) - if tCompletions and #tCompletions > 0 then - nCompletion = 1 - else - nCompletion = nil - end - else - tCompletions = nil - nCompletion = nil - end - end - - local function uncomplete() - tCompletions = nil - nCompletion = nil - end - - local w = term.getSize() - local sx = term.getCursorPos() - - local function redraw( _bClear ) - local nScroll = 0 - if sx + nPos >= w then - nScroll = (sx + nPos) - w - end - - local cx,cy = term.getCursorPos() - term.setCursorPos( sx, cy ) - local sReplace = (_bClear and " ") or _sReplaceChar - if sReplace then - term.write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) ) - else - term.write( string.sub( sLine, nScroll + 1 ) ) - end - - if nCompletion then - local sCompletion = tCompletions[ nCompletion ] - local oldText, oldBg - if not _bClear then - oldText = term.getTextColor() - oldBg = term.getBackgroundColor() - term.setTextColor( colors.white ) - term.setBackgroundColor( colors.gray ) - end - if sReplace then - term.write( string.rep( sReplace, string.len( sCompletion ) ) ) - else - term.write( sCompletion ) - end - if not _bClear then - term.setTextColor( oldText ) - term.setBackgroundColor( oldBg ) - end - end - - term.setCursorPos( sx + nPos - nScroll, cy ) - end - - local function clear() - redraw( true ) - end - - recomplete() - redraw() - - local function acceptCompletion() - if nCompletion then - -- Clear - clear() - - -- Find the common prefix of all the other suggestions which start with the same letter as the current one - local sCompletion = tCompletions[ nCompletion ] - sLine = sLine .. sCompletion - nPos = string.len( sLine ) - - -- Redraw - recomplete() - redraw() - end - end - while true do - sEvent, param,_MouseX,_MouseY = os.pullEvent() - if sEvent == "char" then - -- Typed key - clear() - sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 ) - nPos = nPos + 1 - recomplete() - redraw() - - elseif sEvent == "paste" then - -- Pasted text - clear() - sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 ) - nPos = nPos + string.len( param ) - recomplete() - redraw() - - elseif sEvent == "key" then - if param == keys.enter then - -- Enter - if nCompletion then - clear() - uncomplete() - redraw() - end - break - - elseif param == keys.left then - -- Left - if nPos > 0 then - clear() - nPos = nPos - 1 - recomplete() - redraw() - end - - elseif param == keys.right then - -- Right - if nPos < string.len(sLine) then - -- Move right - clear() - nPos = nPos + 1 - recomplete() - redraw() - else - -- Accept autocomplete - acceptCompletion() - end - - elseif param == keys.up or param == keys.down then - -- Up or down - if nCompletion then - -- Cycle completions - clear() - if param == keys.up then - nCompletion = nCompletion - 1 - if nCompletion < 1 then - nCompletion = #tCompletions - end - elseif param == keys.down then - nCompletion = nCompletion + 1 - if nCompletion > #tCompletions then - nCompletion = 1 - end - end - redraw() - - elseif _tHistory then - -- Cycle history - clear() - if param == keys.up then - -- Up - if nHistoryPos == nil then - if #_tHistory > 0 then - nHistoryPos = #_tHistory - end - elseif nHistoryPos > 1 then - nHistoryPos = nHistoryPos - 1 - end - else - -- Down - if nHistoryPos == #_tHistory then - nHistoryPos = nil - elseif nHistoryPos ~= nil then - nHistoryPos = nHistoryPos + 1 - end - end - if nHistoryPos then - sLine = _tHistory[nHistoryPos] - nPos = string.len( sLine ) - else - sLine = "" - nPos = 0 - end - uncomplete() - redraw() - - end - - elseif param == keys.backspace then - -- Backspace - if nPos > 0 then - clear() - sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 ) - nPos = nPos - 1 - recomplete() - redraw() - end - - elseif param == keys.home then - -- Home - if nPos > 0 then - clear() - nPos = 0 - recomplete() - redraw() - end - - elseif param == keys.delete then - -- Delete - if nPos < string.len(sLine) then - clear() - sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 ) - recomplete() - redraw() - end - - elseif param == keys["end"] then - -- End - if nPos < string.len(sLine ) then - clear() - nPos = string.len(sLine) - recomplete() - redraw() - end - - elseif param == keys.tab then - -- Tab (accept autocomplete) - acceptCompletion() - - end - - elseif sEvent == "term_resize" then - -- Terminal resized - w = term.getSize() - redraw() - - elseif sEvent == "mouse_click" and _MouseEvent then - if nCompletion then - clear() - uncomplete() - redraw() - end - usedMouse = true - break - end - end - - local cx, cy = term.getCursorPos() - term.setCursorBlink( false ) - term.setCursorPos( w + 1, cy ) - print() - if sEvent == "mouse_click" then - return sLine, param, _MouseX, _MouseY - end - return sLine - end - - local function clear() - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.clear() - term.setCursorPos(1,1) - term.setTextColor(sPhone.theme["text"]) - end - - sPhone.forceShutdown = os.shutdown - sPhone.forceReboot = os.reboot - - function os.shutdown() - local w, h = term.getSize() - local text = "Shutting down" - local x = math.ceil(w/2)-math.ceil(#text/2)+1 - local y = math.ceil(h/2) - sPhone.inHome = false - os.pullEvent = os.pullEventRaw - local function printMsg(color) - term.setBackgroundColor(color) - term.setTextColor(colors.white) - term.clear() - term.setCursorPos(x,y) - print(text) - sleep(0.1) - end - printMsg(colors.white) - printMsg(colors.lightGray) - printMsg(colors.gray) - printMsg(colors.black) - sleep(0.6) - sPhone.forceShutdown() - end - - function os.reboot() - local w, h = term.getSize() - local text = "Rebooting" - local x = math.ceil(w/2)-math.ceil(#text/2)+1 - local y = math.ceil(h/2) - sPhone.inHome = false - os.pullEvent = os.pullEventRaw - local function printMsg(color) - term.setBackgroundColor(color) - term.setTextColor(colors.white) - term.clear() - term.setCursorPos(x,y) - print(text) - sleep(0.1) - end - printMsg(colors.white) - printMsg(colors.lightGray) - printMsg(colors.gray) - printMsg(colors.black) - sleep(0.6) - sPhone.forceReboot() - end - - function sPhone.header(title, butt) - - if not title then - title = "sPhone" - end - - local w, h = term.getSize() - paintutils.drawLine(1,1,w,1, sPhone.theme["header"]) - term.setTextColor(sPhone.theme["headerText"]) - term.setCursorPos(1,1) - write(" "..title) - term.setCursorPos(w,1) - if butt then - write(butt) - end - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.setTextColor(sPhone.theme["text"]) - term.setCursorPos(1,3) - end - - function sPhone.menu(items, title, closeButton) - local function cprint(text) - if type(text) ~= 'table' then - text = {text} - end - - local w, h = term.getSize() - - for i=1,#text do - local x, y = term.getCursorPos() - term.setCursorPos(math.floor(w/2)-math.floor(text[i]:len()/2), y) - print(text[i]) - end - end - local function clear() - term.clear() - term.setCursorPos(1, 1) - end - - local termWidth, termHeight = term.getSize() - local drawSize = termHeight - 2 - - local function maxPages() - local itemCount = #items - local pageCount = 0 - while itemCount > 0 do - itemCount = itemCount - drawSize - pageCount = pageCount + 1 - end - return pageCount - end - - local function iif(cond, trueval, falseval) - if cond then - return trueval - else - return falseval - end - end - - local function pagedItems() - local ret = {} - for i = 1, maxPages() do - local tmp = {} - local nElements = 0 - for j = drawSize*(i-1)+1, iif(drawSize*(i+1) > #items, #items, drawSize*(i+1)) do - if nElements < drawSize then - table.insert(tmp, items[j]) - nElements = nElements + 1 - end - end - table.insert(ret, tmp) - end - return ret - end - - local selected = 1 - if start then - selected = start - end - local page = 1 - - local function redraw() - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.setTextColor(sPhone.theme["text"]) - term.clear() - term.setCursorPos(1,1) - if not title then - title = "" - end - sPhone.header(title,closeButton) - term.setCursorPos(1,3) - if moreTitle then - head = moreTitle - else - head = {} - if not allowNil or allowNil == true then - --head[3] = 'Terminate to cancel.' - end - end - for i=1,#head do - print(head[i]) - end - if maxPages() > 1 then - pages = "<- (page "..page.." of "..maxPages()..") ->" - print(pages) - end - for i = 1, #pagedItems()[page] do - if selected == drawSize*(page-1)+i then - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.setTextColor(sPhone.theme["text"]) - else - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.setTextColor(sPhone.theme["text"]) - end - term.clearLine() - cprint(iif(selected == drawSize*(page-1)+i,"","").." "..pagedItems()[page][i]) - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.setTextColor(sPhone.theme["text"]) - end - end - - local function changePage(pW) - if pW == 1 and page < maxPages() then - page = page + 1 - if selected + drawSize > #items then - selected = #items - else - selected = selected + drawSize - end - elseif pW == -1 and page > 1 then - page = page - 1 - if selected - drawSize < 1 then - selected = 1 - else - selected = selected - drawSize - end - end - end - - redraw() - while true do - local eventData = {os.pullEventRaw()} - if eventData[1] == 'mouse_click' then - if eventData[4] == 1 and eventData[3] == termWidth then - return false, 0 - elseif eventData[4] > 2 then - clear() - selected = (eventData[4]-3+((page-1)*drawSize))+1 - if selected then - return items[selected], selected - end - end - end - end -end - - function sPhone.yesNo(title, desc, hideUser) - term.setCursorBlink(false) - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.clear() - term.setCursorPos(1,1) - term.setTextColor(sPhone.theme["text"]) - local w, h = term.getSize() - paintutils.drawLine(1,1,w,1, sPhone.theme["header"]) - term.setTextColor(sPhone.theme["headerText"]) - term.setCursorPos(1,1) - if not hideUser then - if not sPhone.user then - write(" sPhone") - else - write(" "..sPhone.user) - end - end - term.setCursorPos(1,3) - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.setTextColor(sPhone.theme["text"]) - visum.align("center", " "..title, false, 3) - if desc then - term.setCursorPos(2,6) - print(desc) - end - paintutils.drawFilledBox(3, 16, 9, 18, colors.green) - paintutils.drawFilledBox(18, 16, 24, 18, colors.red) - term.setTextColor(colors.white) - term.setCursorPos(5,17) - term.setBackgroundColor(colors.green) - write("Yes") - term.setCursorPos(20,17) - term.setBackgroundColor(colors.red) - write("No") - while true do - local _,_,x,y = os.pullEvent("mouse_click") - if (x > 2 and y > 15) and (x < 10 and y < 19) then - return true - elseif (x > 17 and y > 15) and (x < 25 and y < 19) then - return false - end - end - end - - function sPhone.winOk(fmessage, smessage, bg, side, text, button) - if not fmessage then - fmessage = "" - end - if not smessage then - smessage = "" - end - if not bg then - bg = sPhone.theme["window.background"] - end - if not text then - text = sPhone.theme["window.text"] - end - if not button then - button = sPhone.theme["window.button"] - end - if not side then - side = sPhone.theme["window.side"] - end - term.setCursorBlink(false) - if #fmessage >= #smessage then - local w, h = term.getSize - term.setBackgroundColor(side) - paintutils.drawBox(12 - math.ceil(#fmessage / 2), 5, 15 + math.ceil(#fmessage / 2), 10, side) - term.setBackgroundColor(bg) - paintutils.drawFilledBox(13 - math.ceil(#fmessage / 2), 6, 14 + math.ceil(#fmessage / 2), 9, bg) - term.setCursorPos(14 - math.ceil(#fmessage / 2), 7) - term.setTextColor(text) - write(fmessage) - term.setCursorPos(14 - math.ceil(#smessage / 2), 8) - write(smessage) - else - local w, h = term.getSize - term.setBackgroundColor(side) - paintutils.drawBox(12 - math.ceil(#smessage / 2), 5, 15 + math.ceil(#smessage / 2), 10, side) - term.setBackgroundColor(bg) - paintutils.drawFilledBox(13 - math.ceil(#smessage / 2), 6, 14 + math.ceil(#smessage / 2), 9, bg) - term.setCursorPos(14 - math.ceil(#fmessage / 2), 7) - term.setTextColor(text) - write(fmessage) - term.setCursorPos(14 - math.ceil(#smessage / 2), 8) - write(smessage) - end - term.setCursorPos(13,10) - term.setBackgroundColor(button) - write("Ok") - while true do - local e, k, x,y = os.pullEvent() - if e == "mouse_click" then - if y == 10 then - if x == 13 or x == 14 then - return - end - end - elseif e == "key" then - if k == 28 then - return - end - end - end - end - - function sPhone.colorPicker(message, old) -- From Impulse - local current = math.log(old) / math.log(2) - -- first line is already code wizardry - local function redraw() - term.setBackgroundColour(sPhone.theme["backgroundColor"]) - term.clear() - sPhone.header(message) - term.setCursorPos(2,5) - term.setTextColor(colors.white) - term.setBackgroundColor(colors.lime) - write(" Ok ") - term.setCursorPos(7,5) - term.setTextColor(colors.white) - term.setBackgroundColor(colors.red) - write(" Cancel ") - term.setTextColor(colors.black) - term.setCursorPos(2, 3) - for i = 0, 15 do - term.setBackgroundColour(2^i) - term.write(i == current and "#" or ":") - end - end - while true do - redraw() - local ev = {os.pullEvent()} - if ev[1] == "key" and ev[2] == keys.enter then - return 2^current - elseif ev[1] == "mouse_click" then - if ev[4] == 3 and ev[3] >= 2 and ev[3] <= 17 then - current = ev[3] - 2 % 16 - elseif ev[4] == 5 and ev[3] >= 2 and ev[3] <= 6 then - return 2^current - elseif ev[4] == 5 and ev[3] >= 7 and ev[3] <= 14 then - return old - end - end - end - end - - sPhone.colourPicker = sPhone.colorPicker -- For UK - - function sPhone.install(spk) - if not fs.exists("/.sPhone/config/spklist") then - local f = fs.open("/.sPhone/config/spklist","w") - f.write("{}") - f.close() - end - if string.getExtension(spk) == "spk" then - if fs.exists(spk) and not fs.isDir(spk) then - local f = fs.open(spk,"r") - local script = f.readAll() - f.close() - script = textutils.unserialize(script) - if not script then - error("spk corrupted",2) - end - - local function writeFile(patha,contenta) - local file = fs.open(patha,"w") - file.write(contenta) - file.close() - end - function writeDown(inputa,dira) - for i,v in pairs(inputa) do - if type(v) == "table" then - writeDown(v,dira.."/"..i) - elseif type(v) == "string" then - writeFile(dira.."/"..i,v) - end - end - end - - local _config = textutils.unserialize(script.config) - if not _config.id then - error("SPK: id not found",2) - end - if not _config.main then - error("SPK: main not found",2) - end - writeDown(textutils.unserialize(script.files),"/.sPhone/apps/spk/".._config.id.."/files") - local f = fs.open("/.sPhone/apps/spk/".._config.id.."/.spk","w") - f.write(textutils.serialize(_config)) - f.close() - local f = fs.open("/.sPhone/config/spklist","r") - local lists = f.readAll() - f.close() - lists = textutils.unserialize(lists) - if not lists then - error("Cannot open config",2) - end - - if not _config.name then - _config.name = _config.id - end - - lists[_config.id] = _config.name - - local f = fs.open("/.sPhone/config/spklist","w") - f.write(textutils.serialize(lists)) - f.close() - return true, _config.id - else - return false, "not a spk file" - end - else - return false, "not a spk file" - end - end - - function sPhone.launch(spk) - if not fs.exists("/.sPhone/config/spklist") then - local f = fs.open("/.sPhone/config/spklist","w") - f.write("{}") - f.close() - end - local f = fs.open("/.sPhone/config/spklist","r") - local lists = f.readAll() - f.close() - lists = textutils.unserialize(lists) - if not lists then - error("Cannot open config",2) - end - - if not lists[spk] then - return false, "not installed" - end - - if not fs.exists("/.sPhone/apps/spk/"..spk.."/.spk") then - return false, "Invalid SPK, .spk not found" - end - - local f = fs.open("/.sPhone/apps/spk/"..spk.."/.spk","r") - local script = f.readAll() - f.close() - _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, - - getID = function() - return (_config.id or nil) - end, - - getPath = function() - return "/.sPhone/apps/spk/".._config.id - end, - - getDataPath = function() - return "/.sPhone/apps/spk/".._config.id.."/data" - end, - - getAuthor = function() - return (_config.author or nil) - end, - - getVersion = function() - return (_config.version 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) - - if not ok then - return false, err - end - return true, result - end - - local function home() - sPhone.inHome = true - local errorCount = 0 - local ok, err - local homeID - local homeSPKs = { - "sphone.home", - } - while true do - - - if not config.read("/.sPhone/config/spklist","sphone.home") then - sPhone.install("/.sPhone/apps/home.spk") - end - os.pullEvent = os.oldPullEvent - term.setBackgroundColor(colors.black) - term.setTextColor(colors.white) - term.clear() - term.setCursorPos(1,1) - if errorCount >= 5 and errorCount < 10 then - homeID = "sphone.home" - elseif errorCount >= 10 then - error("Cannot load home: "..err,0) - else - homeID = sPhone.getDefaultApp("home") - end - if not sPhone.safeMode then - if not config.list("/.sPhone/config/spklist")[homeID] then - homeID = "sphone.home" - end - else - homeID = "sphone.home" - end - temp.set("homePID",task.add(function() - ok,err = sPhone.launch(homeID) - end)) - task.run() - if not ok then - errorCount = errorCount + 1 - end - sleep(0) - - end - sPhone.inHome = false - end - - function login() - if config.read("/.sPhone/config/sPhone","lockEnabled") == nil then - config.write("/.sPhone/config/sPhone","lockEnabled",true) - end - local usingPW = config.read("/.sPhone/config/sPhone","lockEnabled") - if not usingPW then - local old = os.pullEvent - os.pullEvent = os.pullEventRaw - local fEvents = { - ["mouse_drag"] = true, - ["mouse_click"] = true, - ["key"] = false, - } - while true do - local w,h = term.getSize() - local clockS = textutils.formatTime(os.time(), not config.read("/.sPhone/config/sPhone","format12time")) - term.setBackgroundColor(sPhone.theme["lock.background"]) - term.clear() - term.setCursorPos(1,1) - sPhone.header(sPhone.user) - term.setBackgroundColor(sPhone.theme["lock.background"]) - term.setTextColor(sPhone.theme["lock.text"]) - term.setCursorPos(6,4) - bigfont.bigPrint(clockS) - visum.align("center"," Slide to unlock",false,h) - local clockUpdate = os.startTimer(1) - local e = {os.pullEvent()} - if fEvents[e[1]] then - os.pullEvent = old - break - end - end - return - end - local old = os.pullEvent - os.pullEvent = os.pullEventRaw - sPhone.locked = true - if config.read("/.sPhone/config/sPhone","password") then - while true do - term.setBackgroundColor(sPhone.theme["lock.background"]) - term.clear() - term.setCursorPos(1,1) - sPhone.header(sPhone.user) - paintutils.drawBox(7,9,20,11,sPhone.theme["lock.inputSide"]) - if sPhone.wrongPassword then - term.setTextColor(sPhone.theme["lock.error"]) - term.setBackgroundColor(sPhone.theme["lock.background"]) - visum.align("center"," Wrong Password",false,13) - end - term.setTextColor(sPhone.theme["lock.text"]) - term.setBackgroundColor(sPhone.theme["lock.background"]) - visum.align("center"," Insert Password",false,7) - local loginTerm = window.create(term.native(), 8,10,12,1, true) - term.redirect(loginTerm) - term.setBackgroundColor(sPhone.theme["lock.inputBackground"]) - term.clear() - term.setCursorPos(1,1) - term.setTextColor(sPhone.theme["lock.inputText"]) - local passwordLogin = read("*") - term.redirect(sPhone.mainTerm) - local fpw = config.read("/.sPhone/config/sPhone","password") - if sha256.sha256(passwordLogin) == fpw then - sPhone.wrongPassword = false - os.pullEvent = old - return - else - sPhone.wrongPassword = true - end - end - else - local name - local pw - local pwr - local rServer - local password1,mouse,x,y - local w, h = term.getSize() - local skipped = false - sPhone.firstBoot = true - - for k,v in ipairs(fs.list("/.sPhone/apps/system")) do - sPhone.install("/.sPhone/apps/system/"..v) - end - - while not skipped do - - term.setBackgroundColor(sPhone.theme["lock.background"]) - term.clear() - term.setCursorPos(1,1) - sPhone.header("Setup") - paintutils.drawBox(7,9,20,11,sPhone.theme["lock.inputSide"]) - if sPhone.wrongPassword then - term.setTextColor(sPhone.theme["lock.error"]) - term.setBackgroundColor(sPhone.theme["lock.background"]) - visum.align("center"," Wrong Password",false,13) - end - term.setTextColor(sPhone.theme["lock.text"]) - term.setBackgroundColor(sPhone.theme["lock.background"]) - visum.align("center"," Insert Password",false,7) - local t = "Skip" - term.setCursorPos(w-#t+1,h) - write(t) - local loginTerm = window.create(term.native(), 8,10,12,1, true) - term.redirect(loginTerm) - term.setBackgroundColor(sPhone.theme["lock.inputBackground"]) - term.clear() - term.setCursorPos(1,1) - term.setTextColor(sPhone.theme["lock.inputText"]) - while true do - password1,mouse,x,y = sPhone.read("*",nil,nil,true) - if mouse then - if y == h and (x >= 23 and x <= w) then - skipped = true - config.write("/.sPhone/config/sPhone","lockEnabled",false) - break - end - else - break - end - end - term.redirect(sPhone.mainTerm) - if not skipped then - term.setBackgroundColor(sPhone.theme["lock.background"]) - term.clear() - term.setCursorPos(1,1) - sPhone.header("Setup") - paintutils.drawBox(7,9,20,11,sPhone.theme["lock.inputSide"]) - term.setTextColor(sPhone.theme["lock.text"]) - term.setBackgroundColor(sPhone.theme["lock.background"]) - visum.align("center"," Repeat",false,7) - local loginTerm = window.create(term.native(), 8,10,12,1, true) - term.redirect(loginTerm) - term.setBackgroundColor(sPhone.theme["lock.inputBackground"]) - term.clear() - term.setCursorPos(1,1) - term.setTextColor(sPhone.theme["lock.inputText"]) - local password2 = read("*") - term.redirect(sPhone.mainTerm) - if password1 == password2 then - config.write("/.sPhone/config/sPhone", "password",sha256.sha256(password1)) - term.setTextColor(colors.lime) - visum.align("center"," Password set!",false,13) - sleep(2) - break - else - sPhone.wrongPassword = true - end - end - end - - local name - - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.clear() - sPhone.header("Setup") - term.setCursorPos(1,1) - term.setTextColor(sPhone.theme["text"]) - term.setCursorPos(2,3) - visum.align("center","Username",false,3) - term.setCursorPos(2,5) - local newUsername = read() - config.write("/.sPhone/config/sPhone","username",newUsername) - - if fs.exists("/.sPhone/config/sPhone") then - name = config.read("/.sPhone/config/sPhone","username") - else - name = "Guest" - end - config.write("/.sPhone/config/sPhone","showUpdate",true) - term.setBackgroundColor(sPhone.theme["backgroundColor"]) - term.clear() - sPhone.header("Setup") - term.setCursorPos(1,1) - term.setTextColor(sPhone.theme["text"]) - sPhone.user = name - os.setComputerLabel(sPhone.user.."'s sPhone") - visum.align("center"," All Set!",false,3) - visum.align("center"," Have fun with sPhone",false,5) - sleep(2) - sPhone.locked = false - sPhone.inHome = true - sPhone.firstBoot = false - os.pullEvent = old - return - end - end - - sPhone.lock = login - sPhone.login = login - local showUpdate = config.read("/.sPhone/config/sPhone","showUpdate") - - http.request("https://raw.githubusercontent.com/SertexTeam/sPhone/master/src/version") - local newVersion - local timeout = os.startTimer(2) - while true do - local event,url, sourceText = os.pullEvent() - if event == "http_success" then - newVersion = sourceText.readLine() - sourceText.close() - break - elseif event == "http_failure" then - newVersion = sPhone.version - break - end - end - - if newVersion ~= sPhone.version and showUpdate then - sPhone.newUpdate = true - else - sPhone.newUpdate = false - end - - if config.read("/.sPhone/config/sPhone","updated") then - for k,v in pairs(fs.list("/.sPhone/apps/system")) do - sPhone.install("/.sPhone/apps/system/"..v) - end - config.write("/.sPhone/config/sPhone","updated",false) - end - - if config.read("/.sPhone/config/sPhone","showUpdate") == nil then - config.write("/.sPhone/config/sPhone","showUpdate", true) - end - - login() - if sPhone.newUpdate then - sPhone.winOk("New Update:",newVersion) - end - home() - -end -if not sPhone then - kernel({...}) -else - print("sPhone already started") -end \ No newline at end of file