Update sPhone.lua

This commit is contained in:
Ale32bit 2016-11-02 21:02:04 +01:00 committed by GitHub
parent 18d597d8d4
commit 3f821c3c7b

View file

@ -1,6 +1,6 @@
local function kernel() local function kernel()
_G.sPhone = { _G.sPhone = {
version = "Alpha 3.4", version = "Alpha 3.5",
user = "Guest", user = "Guest",
devMode = false, devMode = false,
mainTerm = term.current(), mainTerm = term.current(),
@ -90,10 +90,8 @@ local function kernel()
fs.open("/startup","r") fs.open("/startup","r")
end end
if fs.exists("/.sPhone/config/username") then if config.read("/.sPhone/config/sPhone","username") then
local u = fs.open("/.sPhone/config/username","r") sPhone.user = config.read("/.sPhone/config/sPhone","username")
sPhone.user = u.readLine()
u.close()
end end
if not fs.exists("/.sPhone/config/sPhone") then if not fs.exists("/.sPhone/config/sPhone") then
@ -560,7 +558,8 @@ end
term.setTextColor(sPhone.theme["text"]) term.setTextColor(sPhone.theme["text"])
visum.align("center", " "..title, false, 3) visum.align("center", " "..title, false, 3)
if desc then if desc then
visum.align("center", " "..desc,false,6) term.setCursorPos(2,6)
print(desc)
end end
paintutils.drawFilledBox(3, 16, 9, 18, colors.green) paintutils.drawFilledBox(3, 16, 9, 18, colors.green)
paintutils.drawFilledBox(18, 16, 24, 18, colors.red) paintutils.drawFilledBox(18, 16, 24, 18, colors.red)
@ -831,7 +830,16 @@ end
local old = os.pullEvent local old = os.pullEvent
os.pullEvent = os.pullEventRaw os.pullEvent = os.pullEventRaw
sPhone.locked = true sPhone.locked = true
if fs.exists("/.sPhone/config/.password") then if not config.write("/.sPhone/config/sPhone","newConfigFormat",true) then
local c = sPhone.yesNo("Config Format","We updated the config\n format\n\n All configs will be\n erased",true)
if not c then
os.shutdown()
else
fs.delete("/.sPhone/config")
os.reboot()
end
end
if config.read("/.sPhone/config/sPhone","password") then
while true do while true do
term.setBackgroundColor(sPhone.theme["backgroundColor"]) term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear() term.clear()
@ -854,8 +862,8 @@ end
term.setTextColor(sPhone.theme["text"]) term.setTextColor(sPhone.theme["text"])
local passwordLogin = read("*") local passwordLogin = read("*")
term.redirect(sPhone.mainTerm) term.redirect(sPhone.mainTerm)
local fpw = fs.open("/.sPhone/config/.password","r") local fpw = config.read("/.sPhone/config/sPhone","password")
if sha256.sha256(passwordLogin) == fpw.readLine() then if sha256.sha256(passwordLogin) == fpw then
sPhone.wrongPassword = false sPhone.wrongPassword = false
os.pullEvent = old os.pullEvent = old
return return
@ -907,9 +915,7 @@ end
local password2 = read("*") local password2 = read("*")
term.redirect(sPhone.mainTerm) term.redirect(sPhone.mainTerm)
if password1 == password2 then if password1 == password2 then
local f = fs.open("/.sPhone/config/.password", "w") config.write("/.sPhone/config/sPhone", "password",sha256.sha256(password1))
f.write(sha256.sha256(password1))
f.close()
term.setTextColor(colors.lime) term.setTextColor(colors.lime)
visum.align("center"," Password set!",false,13) visum.align("center"," Password set!",false,13)
sleep(2) sleep(2)
@ -930,14 +936,10 @@ end
visum.align("center","Username",false,3) visum.align("center","Username",false,3)
term.setCursorPos(2,5) term.setCursorPos(2,5)
local newUsername = read() local newUsername = read()
local f = fs.open("/.sPhone/config/username","w") config.write("/.sPhone/config/sPhone","username",newUsername)
f.write(newUsername)
f.close()
if fs.exists("/.sPhone/config/username") then if fs.exists("/.sPhone/config/sPhone") then
local f = fs.open("/.sPhone/config/username","r") name = config.read("/.sPhone/config/sPhone","username")
name = f.readLine()
f.close()
else else
name = "Guest" name = "Guest"
end end