Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = term.getSize()
- crash = function(reason)
- if type(reason) ~= "string" then
- error("String excepted, got "..type(reason))
- end
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- print("Something goes wrong!")
- print("Reason: "..reason)
- oslog("Crashed! Reason: "..reason)
- sleep(0.5)
- os.reboot()
- end
- local oslog = function(s)
- local a = fs.open("/bootlog","r")
- local tmp = nil
- if a ~= nil then
- tmp = a.readAll()
- a.close()
- end
- local b = fs.open("/bootlog","w")
- if tmp == nil then
- tmp = ""
- end
- b.write(tmp.."\n"..s)
- b.close()
- end
- runCons = function()
- shell.run("fg /sys/apps/console")
- end
- editWall = function()
- shell.run("fg edit /data/wallpaper")
- end
- local writeCentered = function(s,y)
- term.setCursorPos(math.floor((w/2)-(string.len(s)/2)),y)
- write(s)
- end
- local logonBasic = function()
- write("Username: ")
- local usr = read()
- write("Password: ")
- local pas = read("*")
- return usr,pas
- end
- logon = function()
- local logged = false
- while not logged do
- local user,pass = logonBasic()
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- paintutils.drawLine(1,1,w,1,colors.white)
- paintutils.drawLine(1,h,w,h,colors.white)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.setCursorPos(1,2)
- oslog("Logging data:")
- oslog(" Username: "..user)
- oslog(" Password: "..pass)
- oslog("Logging...")
- if not fs.isDir("/usr/"..user) then
- printError("Invaild Username!")
- oslog("Invaild Username!")
- else
- local a = fs.open("/usr/"..user.."/pass","r")
- local uPass = a.readLine()
- a.close()
- if pass ~= uPass then
- printError("Invaild Password!")
- oslog("Invaild Password!")
- else
- local b = fs.open("/usr/"..user.."/pimg","r")
- if b ~= nil then -- if file exists
- local tLines = {}
- repeat
- local line = b.readLine()
- table.insert(tLines,line)
- until not line
- b.close()
- local tLengths = {}
- for i=1,#tLines do
- slen = string.len(tLines[i])
- table.insert(tLengths,slen)
- table.sort(tLengths)
- end
- local xCenter = math.floor((w/2) - (tLengths[#tLengths]/2))
- local yCenter = math.floor((h/2) - (#tLengths/2))
- term.setCursorPos(xCenter,yCenter)
- local _img = paintutils.loadImage("/usr/"..user.."/pimg")
- paintutils.drawImage(_img,xCenter,yCenter)
- term.setBackgroundColor(colors.blue)
- logged = true
- writeCentered("Welcome!",h-2)
- sleep(5)
- else -- else
- logged = true
- writeCentered("Welcome!",math.floor(h/2))
- sleep(5)
- end
- end
- end
- end
- end
- formatSize = function(size)
- if type(size) ~= "number" then
- error("Attempt to format size in "..type(size))
- end
- local format = nil
- local sizes = {
- [1] = {symbol="KB",num=1},
- [2] = {symbol="MB",num=2},
- [3] = {symbol="GB",num=3},
- [4] = {symbol="TB",num=4}
- }
- for i=1,#sizes do
- if i==1 then
- if size >= 1000^sizes[i].num then
- format = math.floor(size / (1000^sizes[i].num)) .. " " .. sizes[i].symbol
- end
- else
- if size >= 1000^sizes[i].num and size < 1000^sizes[i-1].num then
- format = math.floor(size / (1000^sizes[i].num)) .. " " .. sizes[i].symbol
- end
- end
- end
- if format == nil then
- format = size.." B"
- end
- return format
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement