2015-07-31 20:27:52 +02:00
|
|
|
local function kernel()
|
2015-08-19 11:45:35 +02:00
|
|
|
_G.sPhone = {
|
2016-03-19 23:01:02 +01:00
|
|
|
version = "Alpha 2.12.2 DEV",
|
2015-12-24 16:17:55 +01:00
|
|
|
user = "Guest",
|
2015-09-26 11:32:04 +02:00
|
|
|
devMode = false,
|
2015-09-20 16:06:47 +02:00
|
|
|
mainTerm = term.current()
|
2015-08-19 11:45:35 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 17:30:26 +02:00
|
|
|
if not fs.exists("/.sPhone/config/newIDSystem") then
|
|
|
|
fs.delete("/.sPhone/config/username")
|
|
|
|
fs.delete("/.sPhone/config/.sIDpw")
|
|
|
|
f = fs.open("/.sPhone/config/newIDSystem","w")
|
|
|
|
f.write("Ignore Me. I just check if you use the new Sertex ID system to fix password issues")
|
|
|
|
f.close()
|
|
|
|
end
|
|
|
|
|
2015-11-13 23:22:02 +01:00
|
|
|
if not fs.exists("/.sPhone/config/newPassword") and fs.exists("/.sPhone/.password") then
|
|
|
|
fs.move("/.sPhone/.password","/.sPhone/config/.password")
|
|
|
|
f = fs.open("/.sPhone/config/newPassword","w")
|
|
|
|
f.write("Ignore Me. I just check if the password is moved to the config folder")
|
|
|
|
f.close()
|
|
|
|
end
|
|
|
|
|
2015-11-18 16:54:17 +01:00
|
|
|
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
|
|
|
|
|
2015-09-22 18:49:37 +02:00
|
|
|
if not fs.exists("/.sPhone/autorun") then
|
|
|
|
fs.makeDir("/.sPhone/autorun")
|
|
|
|
end
|
|
|
|
|
2015-09-23 14:09:20 +02:00
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.clear()
|
2015-10-10 16:18:02 +02:00
|
|
|
term.setCursorPos(1,1)
|
2015-09-22 18:49:37 +02:00
|
|
|
for k, v in pairs(fs.list("/.sPhone/autorun")) do
|
2015-09-23 14:09:20 +02:00
|
|
|
term.setTextColor(colors.black)
|
2015-09-23 14:04:24 +02:00
|
|
|
if not fs.isDir("/.sPhone/autorun/"..v) then
|
2015-11-18 16:56:20 +01:00
|
|
|
if not safemode then
|
2015-11-18 16:54:17 +01:00
|
|
|
local f = fs.open("/.sPhone/autorun/"..v,"r")
|
|
|
|
local script = f.readAll()
|
|
|
|
f.close()
|
|
|
|
print("Loading script "..v)
|
|
|
|
sleep(0)
|
|
|
|
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")
|
|
|
|
sleep(0.5)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print("Script "..v.." not loaded because Safe Mode")
|
|
|
|
sleep(0)
|
2015-09-23 14:04:24 +02:00
|
|
|
end
|
|
|
|
end
|
2015-09-22 18:49:37 +02:00
|
|
|
end
|
2015-11-18 16:56:20 +01:00
|
|
|
|
|
|
|
if safemode then
|
|
|
|
_G.safemode = nil
|
|
|
|
end
|
2015-09-22 18:49:37 +02:00
|
|
|
|
2015-09-09 17:31:27 +02:00
|
|
|
if runningOnStartup then
|
|
|
|
fs.open("/startup","r")
|
|
|
|
end
|
|
|
|
|
2015-08-19 11:45:35 +02:00
|
|
|
if fs.exists("/.sPhone/config/username") then
|
|
|
|
local u = fs.open("/.sPhone/config/username","r")
|
|
|
|
sPhone.user = u.readLine()
|
|
|
|
u.close()
|
|
|
|
end
|
|
|
|
|
2015-11-10 16:48:13 +01:00
|
|
|
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
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
|
2015-12-15 18:54:15 +01:00
|
|
|
_G.crash = nil
|
2015-08-19 11:45:35 +02:00
|
|
|
function os.version()
|
|
|
|
return "sPhone "..sPhone.version
|
|
|
|
end
|
|
|
|
|
2016-03-19 23:01:02 +01:00
|
|
|
function sPhone.getSize()
|
|
|
|
return term.getSize()
|
|
|
|
end
|
|
|
|
|
2015-08-19 11:45:35 +02:00
|
|
|
local function clear()
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
end
|
|
|
|
|
|
|
|
sPhone.forceShutdown = os.shutdown
|
|
|
|
sPhone.forceReboot = os.reboot
|
|
|
|
|
|
|
|
function os.shutdown()
|
2016-03-19 23:01:02 +01:00
|
|
|
sPhone.inHome = false
|
2015-08-19 11:45:35 +02:00
|
|
|
os.pullEvent = os.pullEventRaw
|
|
|
|
if sPhone.doneShutdown then
|
|
|
|
clear()
|
|
|
|
w, h = term.getSize()
|
|
|
|
term.setCursorPos( (w/2)- 7, h/2)
|
2015-12-24 16:17:55 +01:00
|
|
|
write("Shutdown Aborted.")
|
|
|
|
sPhone.winOk("Error","Can not shutdown",colors.lightBlue,colors.red, colors.white, colors.lightBlue)
|
|
|
|
return
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
sPhone.doneShutdown = true
|
|
|
|
clear()
|
|
|
|
w, h = term.getSize()
|
2015-09-02 14:47:30 +02:00
|
|
|
term.setCursorPos( (w / 2) - 1, h / 2)
|
2015-08-19 11:45:35 +02:00
|
|
|
for i = 1,3 do
|
|
|
|
sleep(0.3)
|
|
|
|
write(".")
|
|
|
|
end
|
|
|
|
sleep(0.2)
|
|
|
|
sPhone.forceShutdown()
|
|
|
|
end
|
|
|
|
|
|
|
|
function os.reboot()
|
2016-03-19 23:01:02 +01:00
|
|
|
sPhone.inHome = false
|
2015-08-19 11:45:35 +02:00
|
|
|
os.pullEvent = os.pullEventRaw
|
|
|
|
if sPhone.doneShutdown then
|
|
|
|
clear()
|
|
|
|
w, h = term.getSize()
|
|
|
|
term.setCursorPos( (w/2)- 7, h/2)
|
2015-12-24 16:17:55 +01:00
|
|
|
write("Reboot Aborted.")
|
|
|
|
sPhone.winOk("Error","Can not reboot",colors.lightBlue,colors.red, colors.white, colors.lightBlue)
|
|
|
|
return
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
sPhone.doneShutdown = true
|
|
|
|
clear()
|
|
|
|
w, h = term.getSize()
|
2015-08-29 15:32:33 +02:00
|
|
|
term.setCursorPos( (w / 2) - 1, h / 2)
|
2015-08-19 11:45:35 +02:00
|
|
|
for i = 1,3 do
|
|
|
|
sleep(0.3)
|
|
|
|
write(".")
|
|
|
|
end
|
|
|
|
sleep(0.2)
|
|
|
|
sPhone.forceReboot()
|
|
|
|
end
|
2015-09-21 21:34:14 +02:00
|
|
|
|
2016-03-19 23:31:00 +01:00
|
|
|
function sPhone.header(title, butt)
|
|
|
|
|
|
|
|
if not title then
|
|
|
|
title = "sPhone"
|
|
|
|
end
|
2015-09-21 21:34:14 +02:00
|
|
|
|
2016-03-19 23:31:00 +01:00
|
|
|
local w, h = term.getSize()
|
|
|
|
paintutils.drawLine(1,1,w,1, colors.blue)
|
|
|
|
term.setTextColor(colors.white)
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
write(" "..title)
|
|
|
|
term.setCursorPos(w,1)
|
|
|
|
if butt then
|
|
|
|
write(butt)
|
2016-03-19 23:01:02 +01:00
|
|
|
end
|
2016-03-19 23:31:00 +01:00
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
term.setCursorPos(1,3)
|
2015-09-21 21:34:14 +02:00
|
|
|
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 - 6
|
|
|
|
|
|
|
|
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(colors.white)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
2016-03-19 23:31:00 +01:00
|
|
|
sPhone.header("",closeButton)
|
2015-09-21 21:34:14 +02:00
|
|
|
term.setCursorPos(1,3)
|
|
|
|
if not title then
|
2016-03-19 23:01:02 +01:00
|
|
|
title = " sPhone"
|
2015-09-21 21:34:14 +02:00
|
|
|
end
|
|
|
|
cprint(" "..title)
|
|
|
|
if moreTitle then
|
|
|
|
head = moreTitle
|
|
|
|
else
|
|
|
|
head = {"\n",}
|
|
|
|
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(colors.white)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
else
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
end
|
|
|
|
term.clearLine()
|
|
|
|
cprint(iif(selected == drawSize*(page-1)+i,"","").." "..pagedItems()[page][i])
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
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
|
|
|
|
|
|
|
|
while true do
|
|
|
|
redraw()
|
|
|
|
local eventData = {os.pullEventRaw()}
|
|
|
|
if eventData[1] == 'mouse_click' then
|
2016-03-19 23:01:02 +01:00
|
|
|
if eventData[4] == 1 and eventData[3] == termWidth then
|
2015-09-21 21:34:14 +02:00
|
|
|
return false, 0
|
2016-03-19 23:01:02 +01:00
|
|
|
elseif eventData[4] > 3 then
|
2015-09-21 21:34:14 +02:00
|
|
|
clear()
|
|
|
|
selected = (eventData[4]-6+((page-1)*drawSize))+1
|
|
|
|
if selected then
|
|
|
|
return items[selected], selected
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-19 11:45:35 +02:00
|
|
|
|
2015-09-02 14:47:30 +02:00
|
|
|
function sPhone.yesNo(title, desc, hideUser)
|
2015-11-02 22:08:38 +01:00
|
|
|
term.setCursorBlink(false)
|
2015-08-24 20:49:02 +02:00
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
local w, h = term.getSize()
|
2015-09-21 21:34:14 +02:00
|
|
|
paintutils.drawLine(1,1,w,1, colors.blue)
|
2015-08-24 20:49:02 +02:00
|
|
|
term.setTextColor(colors.white)
|
|
|
|
term.setCursorPos(1,1)
|
2015-09-02 14:48:37 +02:00
|
|
|
if not hideUser then
|
2015-09-02 14:47:30 +02:00
|
|
|
if not sPhone.user then
|
|
|
|
write(" sPhone")
|
|
|
|
else
|
|
|
|
write(" "..sPhone.user)
|
|
|
|
end
|
2015-08-24 20:49:02 +02:00
|
|
|
end
|
|
|
|
term.setCursorPos(1,3)
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.setTextColor(colors.black)
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center", " "..title, false, 3)
|
2015-08-24 20:49:02 +02:00
|
|
|
if desc then
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center", " "..desc,false,6)
|
2015-08-24 20:49:02 +02:00
|
|
|
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
|
|
|
|
|
2015-08-19 11:45:35 +02:00
|
|
|
function sPhone.winOk(fmessage, smessage, bg, side, text, button)
|
|
|
|
if not fmessage then
|
|
|
|
fmessage = ""
|
|
|
|
end
|
2015-09-16 15:39:18 +02:00
|
|
|
if not smessage then
|
|
|
|
smessage = ""
|
|
|
|
end
|
2015-08-19 11:45:35 +02:00
|
|
|
if not bg then
|
2015-09-21 21:34:14 +02:00
|
|
|
bg = colors.lightBlue
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
if not text then
|
|
|
|
text = colors.white
|
|
|
|
end
|
|
|
|
if not button then
|
2015-09-21 21:36:44 +02:00
|
|
|
button = colors.lightBlue
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
if not side then
|
2015-09-21 21:34:14 +02:00
|
|
|
side = colors.blue
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
2015-11-02 22:08:38 +01:00
|
|
|
term.setCursorBlink(false)
|
2015-09-16 15:39:18 +02:00
|
|
|
if #fmessage >= #smessage then
|
|
|
|
local w, h = term.getSize
|
|
|
|
term.setBackgroundColor(side)
|
2015-10-09 17:51:06 +02:00
|
|
|
paintutils.drawBox(12 - math.ceil(#fmessage / 2), 5, 15 + math.ceil(#fmessage / 2), 10, side)
|
2015-09-16 15:39:18 +02:00
|
|
|
term.setBackgroundColor(bg)
|
2015-10-09 17:51:06 +02:00
|
|
|
paintutils.drawFilledBox(13 - math.ceil(#fmessage / 2), 6, 14 + math.ceil(#fmessage / 2), 9, bg)
|
2015-09-16 15:39:18 +02:00
|
|
|
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)
|
2015-10-09 17:51:06 +02:00
|
|
|
paintutils.drawBox(12 - math.ceil(#smessage / 2), 5, 15 + math.ceil(#smessage / 2), 10, side)
|
2015-09-16 15:39:18 +02:00
|
|
|
term.setBackgroundColor(bg)
|
2015-10-09 17:51:06 +02:00
|
|
|
paintutils.drawFilledBox(13 - math.ceil(#smessage / 2), 6, 14 + math.ceil(#smessage / 2), 9, bg)
|
2015-09-16 15:39:18 +02:00
|
|
|
term.setCursorPos(14 - math.ceil(#fmessage / 2), 7)
|
|
|
|
term.setTextColor(text)
|
|
|
|
write(fmessage)
|
2015-08-19 11:45:35 +02:00
|
|
|
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
|
2015-10-10 18:28:12 +02:00
|
|
|
|
|
|
|
function sPhone.run(_rApp)
|
|
|
|
if not fs.exists(_rApp) or fs.isDir(_rApp) then
|
|
|
|
sPhone.winOk("App not found")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local f = fs.open(_rApp, "r")
|
|
|
|
local script = f.readAll()
|
|
|
|
f.close()
|
2016-03-19 23:01:02 +01:00
|
|
|
if sPhone.inHome then
|
|
|
|
local sPhoneWasInHome = true
|
|
|
|
sPhone.inHome = false
|
|
|
|
end
|
2015-11-02 22:08:38 +01:00
|
|
|
os.pullEvent = os.oldPullEvent
|
2015-10-10 18:28:12 +02:00
|
|
|
local ok, err = pcall(function() setfenv(loadstring(script),getfenv())() end)
|
|
|
|
if not ok then
|
2015-12-24 16:17:55 +01:00
|
|
|
os.pullEvent = os.pullEventRaw
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,2)
|
|
|
|
visum.align("center"," "..fs.getName(_rApp).." crashed",false,2)
|
|
|
|
term.setCursorPos(1,4)
|
|
|
|
print(err)
|
|
|
|
print("")
|
|
|
|
visum.align("center"," Press Any Key")
|
|
|
|
os.pullEvent("key")
|
2015-10-10 18:28:12 +02:00
|
|
|
end
|
2015-11-02 22:08:38 +01:00
|
|
|
os.pullEvent = os.pullEventRaw
|
2016-03-19 23:01:02 +01:00
|
|
|
if sPhoneWasInHome then
|
|
|
|
sPhone.inHome = true
|
|
|
|
end
|
2015-10-10 18:28:12 +02:00
|
|
|
end
|
2015-08-19 11:45:35 +02:00
|
|
|
|
2015-09-02 14:41:09 +02:00
|
|
|
local function lChat()
|
2015-08-19 11:45:35 +02:00
|
|
|
clear()
|
|
|
|
local w, h = term.getSize()
|
2015-09-21 21:34:14 +02:00
|
|
|
paintutils.drawLine(1,1,w,1,colors.blue)
|
2015-11-02 22:08:38 +01:00
|
|
|
term.setCursorBlink(false)
|
2015-08-19 11:45:35 +02:00
|
|
|
term.setTextColor(colors.white)
|
2015-11-30 11:38:00 +01:00
|
|
|
visum.align("center"," Chat",false,1)
|
2015-08-19 11:45:35 +02:00
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
term.setCursorPos(2, 5)
|
|
|
|
if not peripheral.isPresent("back") or not peripheral.getType("back") == "modem" then
|
|
|
|
print("Modem not found")
|
|
|
|
print(" Press any key")
|
|
|
|
os.pullEvent("key")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
write("Host: ")
|
|
|
|
local h = read()
|
|
|
|
term.setCursorPos(2,6)
|
|
|
|
shell.run("/rom/programs/rednet/chat", "join", h, sPhone.user)
|
|
|
|
sleep(1)
|
|
|
|
end
|
|
|
|
|
2015-12-24 16:17:55 +01:00
|
|
|
local function installedApps()
|
|
|
|
sPhone.winOk("Work In","Progress")
|
|
|
|
local dir = "/.sPhone/apps/storeApps/"
|
|
|
|
if not fs.exists(dir) then
|
|
|
|
fs.makeDir(dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
local apps = {}
|
|
|
|
local appsName = {}
|
|
|
|
|
|
|
|
for k, v in pairs(fs.list(dir)) do
|
|
|
|
if fs.isDir(dir..v) then
|
|
|
|
if fs.exists(dir..v.."/sPhone-Main.lua") then
|
|
|
|
local nDir = dir..v.."/sPhone-Main.lua"
|
|
|
|
|
|
|
|
pDir = dir..v
|
|
|
|
local run = config.read(nDir, "run")
|
|
|
|
local name = config.read(nDir, "name")
|
|
|
|
local author = config.read(nDir, "author")
|
|
|
|
local version = config.read(nDir, "version")
|
|
|
|
|
|
|
|
appsName[name] = run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for k, v in pairs(appsName) do
|
|
|
|
table.insert(apps, v)
|
|
|
|
end
|
|
|
|
local function drawHome()
|
|
|
|
clear()
|
|
|
|
local w, h = term.getSize()
|
|
|
|
paintutils.drawLine(1,1,w,1, colors.blue)
|
|
|
|
term.setTextColor(colors.white)
|
|
|
|
visum.align("right","X",false,1)
|
|
|
|
visum.align("center", " Apps",false,1)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.setCursorPos(1,3)
|
|
|
|
for k, v in pairs(appsName) do
|
|
|
|
print(k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
drawHome()
|
|
|
|
|
|
|
|
local w, h = term.getSize()
|
|
|
|
|
|
|
|
while true do
|
|
|
|
drawHome()
|
|
|
|
local _,_,x,y = os.pullEvent("mouse_click")
|
|
|
|
if x == w and y == 1 then
|
|
|
|
break
|
|
|
|
elseif y >= 2 then
|
|
|
|
if apps[y-2] then
|
|
|
|
sPhone.run("/.sPhone/apps/storeApps/"..pDir.."/"..apps[y-2])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-19 11:45:35 +02:00
|
|
|
local function home()
|
2015-12-24 16:17:55 +01:00
|
|
|
|
2016-03-19 23:01:02 +01:00
|
|
|
sPhone.inHome = true
|
|
|
|
|
2015-12-24 16:17:55 +01:00
|
|
|
local buttonsInHome = {
|
|
|
|
{"sPhone.header",23,1,25,1,colors.blue,colors.white,"vvv"},
|
|
|
|
{"sPhone.appsButton",12,20,14,20,colors.white,colors.blue,"==="},
|
|
|
|
{"sPhone.shell",2,3,8,5,colors.black,colors.yellow," Shell",2},
|
|
|
|
{"sPhone.sID",11,3,15,5,colors.red,colors.white," sID",2},
|
|
|
|
{"sPhone.lock",19,3,24,5,colors.lightGray,colors.black," Lock",2},
|
|
|
|
{"sPhone.buddies",2,7,10,9,colors.brown,colors.white," Buddies",2},
|
|
|
|
{"sPhone.chat",12,7,17,9,colors.black,colors.white," Chat",2},
|
|
|
|
{"sPhone.SMS",19,7,23,9,colors.green,colors.white," SMS",2},
|
|
|
|
{"sPhone.kst",3,11,7,13,colors.green,colors.lime," KST",2},
|
|
|
|
{"sPhone.gps",10,11,14,13,colors.red,colors.black," GPS",2},
|
|
|
|
{"sPhone.info",18,11,23,13,colors.lightGray,colors.black," Info",2},
|
|
|
|
{"sPhone.store",2,15,8,17,colors.orange,colors.white," Store",2},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local appsOnHome = {
|
2015-12-25 21:58:58 +01:00
|
|
|
["sPhone.shell"] = "/.sPhone/apps/shell",
|
2015-12-24 16:17:55 +01:00
|
|
|
["sPhone.sID"] = "/.sPhone/apps/system/sID",
|
|
|
|
["sPhone.buddies"] = "/.sPhone/apps/buddies",
|
|
|
|
["sPhone.SMS"] = "/.sPhone/apps/sms",
|
|
|
|
["sPhone.gps"] = "/.sPhone/apps/gps",
|
|
|
|
["sPhone.kst"] = "/.sPhone/apps/kstwallet",
|
|
|
|
["sPhone.info"] = "/.sPhone/apps/system/info",
|
|
|
|
["sPhone.store"] = "/.sPhone/apps/store",
|
|
|
|
}
|
2015-11-20 18:38:55 +01:00
|
|
|
|
|
|
|
if not sPhone.locked then
|
2015-11-20 18:39:41 +01:00
|
|
|
sPhone.lock()
|
2015-11-20 18:38:55 +01:00
|
|
|
end
|
2015-10-11 13:09:18 +02:00
|
|
|
if fs.exists("/.sPhone/config/resetDBNews") then
|
|
|
|
fs.delete("/.sPhone/config/resetDBNews")
|
2015-10-06 13:30:45 +02:00
|
|
|
end
|
2015-08-19 11:45:35 +02:00
|
|
|
local function drawHome()
|
|
|
|
local function box(x,y,text,bg,colorText,page)
|
|
|
|
graphics.box(x,y,x+1+#text,y+2,bg)
|
|
|
|
term.setCursorPos(x+1,y+1)
|
|
|
|
term.setTextColor(colorText)
|
|
|
|
write(text)
|
|
|
|
end
|
|
|
|
clear()
|
2016-03-19 23:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
visum.buttons(buttonsInHome,true)
|
|
|
|
|
2015-08-19 11:45:35 +02:00
|
|
|
local w, h = term.getSize()
|
2015-09-21 21:34:14 +02:00
|
|
|
paintutils.drawLine(1,1,w,1, colors.blue)
|
2015-08-19 11:45:35 +02:00
|
|
|
term.setTextColor(colors.white)
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("right","vvv ",false,1)
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
local function footerMenu()
|
|
|
|
sPhone.isFooterMenuOpen = true
|
|
|
|
function redraw()
|
2015-12-24 16:17:55 +01:00
|
|
|
drawHome()
|
2015-08-19 11:45:35 +02:00
|
|
|
local w, h = term.getSize()
|
2015-09-21 21:34:14 +02:00
|
|
|
graphics.box(1,2,w,4,colors.blue)
|
2015-08-19 11:45:35 +02:00
|
|
|
term.setTextColor(colors.white)
|
2015-09-21 21:34:14 +02:00
|
|
|
term.setBackgroundColor(colors.blue)
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("right","^^^ ",false,1)
|
|
|
|
visum.align("right", "Reboot ",false,3)
|
2015-08-19 11:45:35 +02:00
|
|
|
term.setCursorPos(11,3)
|
|
|
|
write("Settings")
|
|
|
|
term.setCursorPos(2,3)
|
|
|
|
write("Shutdown")
|
|
|
|
end
|
|
|
|
while true do
|
2015-09-20 16:06:47 +02:00
|
|
|
term.redirect(sPhone.mainTerm)
|
2016-03-19 23:01:02 +01:00
|
|
|
drawHome()
|
2015-08-19 11:45:35 +02:00
|
|
|
redraw()
|
|
|
|
local _,_,x,y = os.pullEvent("mouse_click")
|
|
|
|
if y == 3 then
|
|
|
|
if x > 1 and x < 10 then
|
|
|
|
os.shutdown()
|
|
|
|
elseif x > 19 and x < 26 then
|
|
|
|
os.reboot()
|
|
|
|
elseif x > 10 and x < 19 then
|
2016-03-19 23:01:02 +01:00
|
|
|
sPhone.inHome = false
|
|
|
|
sPhone.run("/.sPhone/apps/system/settings")
|
|
|
|
sPhone.inHome = true
|
2015-08-19 11:45:35 +02:00
|
|
|
drawHome()
|
|
|
|
end
|
|
|
|
elseif y == 1 then
|
|
|
|
if x < 26 and x > 22 then
|
|
|
|
sPhone.isFooterMenuOpen = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-03-19 23:01:02 +01:00
|
|
|
local function buttonHomeLoop()
|
|
|
|
while true do
|
|
|
|
drawHome()
|
|
|
|
term.setCursorBlink(false)
|
|
|
|
local autoLockTimer = os.startTimer(10)
|
|
|
|
local id = visum.buttons(buttonsInHome)
|
|
|
|
|
|
|
|
if id == "sPhone.header" then
|
|
|
|
footerMenu()
|
|
|
|
elseif id == "sPhone.appsButton" then
|
|
|
|
sPhone.inHome = false
|
|
|
|
installedApps()
|
|
|
|
sPhone.inHome = true
|
|
|
|
elseif id == "sPhone.lock" then
|
|
|
|
sPhone.inHome = false
|
|
|
|
login()
|
|
|
|
sPhone.inHome = true
|
|
|
|
elseif id == "sPhone.chat" then
|
|
|
|
sPhone.inHome = false
|
|
|
|
lChat()
|
|
|
|
sPhone.inHome = true
|
|
|
|
elseif appsOnHome[id] then
|
|
|
|
sPhone.inHome = false
|
|
|
|
sPhone.run(appsOnHome[id])
|
|
|
|
sPhone.inHome = true
|
|
|
|
end
|
|
|
|
end
|
2015-08-19 11:45:35 +02:00
|
|
|
|
2016-03-19 23:01:02 +01:00
|
|
|
sPhone.inHome = false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local function updateClock()
|
|
|
|
while true do
|
|
|
|
if sPhone.inHome then
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.setBackgroundColor(colors.blue)
|
|
|
|
term.setTextColor(colors.white)
|
|
|
|
write(" ")
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
write(" "..textutils.formatTime(os.time(),true))
|
|
|
|
end
|
|
|
|
sleep(0)
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
end
|
2016-03-19 23:01:02 +01:00
|
|
|
|
|
|
|
parallel.waitForAll(buttonHomeLoop, updateClock)
|
|
|
|
|
|
|
|
sPhone.inHome = false
|
|
|
|
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function login()
|
2015-11-20 18:38:55 +01:00
|
|
|
sPhone.locked = true
|
2015-11-13 23:24:31 +01:00
|
|
|
if fs.exists("/.sPhone/config/.password") then
|
2015-08-19 11:45:35 +02:00
|
|
|
while true do
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
|
|
|
|
term.setTextColor(colors.white)
|
2015-09-21 21:34:14 +02:00
|
|
|
term.setBackgroundColor(colors.blue)
|
2015-08-19 11:45:35 +02:00
|
|
|
term.setCursorPos(1,1)
|
|
|
|
write(" "..sPhone.user)
|
|
|
|
if sPhone.wrongPassword then
|
|
|
|
term.setTextColor(colors.red)
|
|
|
|
term.setBackgroundColor(colors.white)
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center"," Wrong Password",false,13)
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
term.setBackgroundColor(colors.white)
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center"," Insert Password",false,7)
|
2015-09-21 21:34:14 +02:00
|
|
|
local loginTerm = window.create(term.native(), 8,10,12,1, true)
|
|
|
|
term.redirect(loginTerm)
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.setTextColor(colors.black)
|
2016-03-19 23:01:02 +01:00
|
|
|
local passwordLogin = read("*")
|
2015-09-21 21:34:14 +02:00
|
|
|
term.redirect(sPhone.mainTerm)
|
2016-03-19 23:01:02 +01:00
|
|
|
local fpw = fs.open("/.sPhone/config/.password","r")
|
|
|
|
if sha256.sha256(passwordLogin) == fpw.readLine() then
|
|
|
|
sPhone.wrongPassword = false
|
|
|
|
return
|
|
|
|
else
|
|
|
|
sPhone.wrongPassword = true
|
|
|
|
end
|
|
|
|
end
|
2015-08-19 11:45:35 +02:00
|
|
|
else
|
2015-08-25 17:46:25 +02:00
|
|
|
local name
|
|
|
|
local pw
|
|
|
|
local pwr
|
2015-08-25 17:56:00 +02:00
|
|
|
local rServer
|
2015-08-19 11:45:35 +02:00
|
|
|
while true do
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
|
|
|
|
if sPhone.wrongPassword then
|
|
|
|
term.setTextColor(colors.red)
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center"," Wrong Password",false,13)
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
term.setBackgroundColor(colors.white)
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center"," Setup",false,3)
|
|
|
|
visum.align("center"," Insert Password",false,5)
|
2015-09-21 21:34:14 +02:00
|
|
|
local loginTerm = window.create(term.native(), 8,10,12,1, true)
|
2015-10-05 17:24:13 +02:00
|
|
|
term.redirect(loginTerm)
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.setTextColor(colors.black)
|
2015-09-21 21:34:14 +02:00
|
|
|
local password1 = read("*")
|
2015-10-05 17:24:13 +02:00
|
|
|
term.redirect(sPhone.mainTerm)
|
2015-08-19 11:45:35 +02:00
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
term.setBackgroundColor(colors.white)
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center"," Setup",false,3)
|
|
|
|
visum.align("center"," Repeat",false,7)
|
2015-09-21 21:34:14 +02:00
|
|
|
local loginTerm = window.create(term.native(), 8,10,12,1, true)
|
2015-10-05 17:24:13 +02:00
|
|
|
term.redirect(loginTerm)
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.setTextColor(colors.black)
|
2015-09-21 21:34:14 +02:00
|
|
|
local password2 = read("*")
|
2015-10-05 17:24:13 +02:00
|
|
|
term.redirect(sPhone.mainTerm)
|
2015-08-19 11:45:35 +02:00
|
|
|
if password1 == password2 then
|
2015-11-13 23:22:02 +01:00
|
|
|
local f = fs.open("/.sPhone/config/.password", "w")
|
2015-08-19 11:45:35 +02:00
|
|
|
f.write(sha256.sha256(password1))
|
|
|
|
f.close()
|
|
|
|
term.setTextColor(colors.lime)
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center"," Password set!",false,13)
|
2015-08-19 11:45:35 +02:00
|
|
|
sleep(2)
|
|
|
|
break
|
|
|
|
else
|
|
|
|
sPhone.wrongPassword = true
|
|
|
|
end
|
|
|
|
end
|
2015-08-29 15:57:40 +02:00
|
|
|
|
2015-12-24 16:17:55 +01:00
|
|
|
sPhone.run("/.sPhone/apps/system/sID")
|
|
|
|
|
|
|
|
local name
|
|
|
|
|
|
|
|
if fs.exists("/.sPhone/config/username") then
|
|
|
|
local f = fs.open("/.sPhone/config/username","r")
|
|
|
|
name = f.readLine()
|
|
|
|
f.close()
|
|
|
|
else
|
|
|
|
name = "Guest"
|
|
|
|
end
|
2015-08-29 15:57:40 +02:00
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.setTextColor(colors.black)
|
2015-12-24 16:17:55 +01:00
|
|
|
_G.sPhone.user = name
|
2015-11-10 19:11:25 +01:00
|
|
|
os.setComputerLabel(sPhone.user.."'s sPhone")
|
2015-08-29 16:17:03 +02:00
|
|
|
term.setCursorPos(1,13)
|
|
|
|
term.clearLine()
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center"," All Set!",false,13)
|
2015-08-29 16:17:03 +02:00
|
|
|
term.setCursorPos(1,14)
|
|
|
|
term.clearLine()
|
2015-11-27 22:39:21 +01:00
|
|
|
visum.align("center"," Have fun with sPhone",false,14)
|
2015-08-25 17:56:00 +02:00
|
|
|
sleep(2)
|
2015-11-20 18:38:55 +01:00
|
|
|
sPhone.locked = false
|
|
|
|
return
|
2015-08-19 11:45:35 +02:00
|
|
|
end
|
|
|
|
end
|
2015-11-20 18:38:55 +01:00
|
|
|
|
|
|
|
sPhone.lock = login
|
2015-11-20 18:39:41 +01:00
|
|
|
sPhone.login = login
|
2015-12-24 16:25:13 +01:00
|
|
|
|
|
|
|
local newVersion = http.get("https://raw.githubusercontent.com/Sertex-Team/sPhone/master/src/version").readLine()
|
2015-08-19 11:45:35 +02:00
|
|
|
|
2015-12-24 16:25:13 +01:00
|
|
|
if newVersion ~= sPhone.version then
|
2015-09-02 14:41:09 +02:00
|
|
|
sPhone.newUpdate = true
|
|
|
|
else
|
|
|
|
sPhone.newUpdate = false
|
|
|
|
end
|
2015-09-02 14:44:57 +02:00
|
|
|
|
2015-11-20 18:38:55 +01:00
|
|
|
home()
|
2015-09-02 14:41:09 +02:00
|
|
|
|
2015-07-31 19:52:45 +02:00
|
|
|
end
|
2015-12-15 18:54:15 +01:00
|
|
|
if not sPhone then
|
|
|
|
kernel(...)
|
|
|
|
else
|
|
|
|
print("sPhone already started")
|
2015-09-09 17:31:27 +02:00
|
|
|
end
|