Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- SkyOS 0.0.1 Copyright Max Thor (thormax5@gmail.com)
- --]]
- -- Variables
- local w, h = term.getSize()
- --[[
- States:
- 0: setup
- 1: running
- 2: programs
- 3: BSOD
- 4: Menu on start
- 5: Run window
- --]]
- local state = 0
- local bgC = colors.blue
- -- Splitlines
- function split(str, max_line_length)
- local lines = {}
- local line
- str:gsub('(%s*)(%S+)',
- function(spc, word)
- if not line or #line + #spc + #word > max_line_length then
- table.insert(lines, line)
- line = word
- else
- line = line..spc..word
- end
- end
- )
- table.insert(lines, line)
- return lines
- end
- function desktop()
- state = 1
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.cyan)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.blue)
- term.clearLine()
- term.setBackgroundColor(colors.cyan)
- print("Programs")
- end
- function run()
- desktop()
- paintutils.drawFilledBox(w/2, h/2, w/2+10, h/2+2, colors.gray)
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(w/2+2, h/2+1)
- term.setTextColor(colors.yellow)
- print("> ")
- term.setCursorPos(w/2+3, h/2+1)
- local prog = read()
- shell.switchTab( shell.openTab(prog) )
- desktop()
- end
- function files()
- desktop()
- if not fs.exists("FileX") then
- shell.run("pastebin run AVqAFH8h")
- else
- shell.switchTab(shell.openTab("FileX"))
- end
- end
- function login()
- term.setBackgroundColor(colors.cyan)
- term.clear()
- cPrint("SkyOS - Login", 2)
- cPrint("Name: ", 4)
- cPrint("Pass: ", 6)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Name: ") / 2)), 0)+5, 4)
- term.setBackgroundColor(colors.white)
- print(" ")
- term.setBackgroundColor(colors.cyan)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Pass: ") / 2)), 0)+5, 6)
- term.setBackgroundColor(colors.white)
- print(" ")
- term.setBackgroundColor(colors.cyan)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Name: ") / 2)), 0)+5, 4)
- local name = read()
- term.setTextColor(colors.black)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Pass: ") / 2)), 0)+5, 6)
- local pass = read('*')
- if(fs.exists("users/"..name)) then
- local f = fs.open("users/"..name, "r")
- local bPass = f.readAll()
- f.close()
- if pass == bPass then
- term.setTextColor(colors.white)
- return true
- else
- print("Wrong password or username!")
- sleep(1)
- os.reboot()
- end
- else
- print("Wrong password or username!")
- sleep(1)
- os.reboot()
- end
- end
- -- Run OS
- function start()
- if login() then
- state = 1
- term.setBackgroundColor(colors.cyan)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.blue)
- term.clearLine()
- term.setBackgroundColor(colors.cyan)
- print("Programs")
- -- Events
- while true do
- e, p1, p2, p3, p4, p5 = os.pullEvent()
- if e == "mouse_click" then
- if state == 1 then
- if p3 == 1 then
- if p2 >= 1 and p2 <= string.len("Programs") then
- state = 4
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1, 2)
- print(" Run ")
- term.setCursorPos(1, 3)
- print(" Files ")
- term.setCursorPos(1, 4)
- print("Shutdown")
- term.setCursorPos(1, 5)
- print(" Reboot ")
- term.setCursorPos(1, 6)
- print(" Exit ")
- end
- end
- elseif state == 4 then
- if p3 == 2 and p2 >= 1 and p2 <= string.len(" Run ") then
- run()
- elseif p3 == 3 and p2 >= 1 and p2 <= string.len(" Files ") then
- files()
- elseif p3 == 4 and p2 >= 1 and p2 <= string.len("Shutdown") then
- os.shutdown()
- elseif p3 == 5 and p2 >= 1 and p2 <= string.len(" Reboot ") then
- os.reboot()
- elseif p3 == 6 and p2 >= 1 and p2 <= string.len(" Exit ") then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- return true
- else
- state = 1
- desktop()
- end
- end
- end
- end
- end
- end
- -- First Run
- -- Center print text
- function cPrint(sText, y)
- local x = math.max(math.floor((w / 2) - (#sText / 2)), 0)
- term.setCursorPos(x, y)
- print(sText)
- end
- function setup()
- if not fs.exists("FileX") then
- shell.run("pastebin run AVqAFH8h")
- end
- term.setBackgroundColor(colors.cyan)
- term.clear()
- cPrint("SkyOS Installer", 1)
- cPrint("Name: ", 3)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Name: ") / 2)), 0)+5, 3)
- term.setBackgroundColor(colors.white)
- print(" ")
- term.setBackgroundColor(colors.cyan)
- cPrint("Label: ", 5)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Label: ") / 2)), 0)+5, 5)
- term.setBackgroundColor(colors.white)
- print(" ")
- term.setBackgroundColor(colors.cyan)
- cPrint("Pass: ", 7)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Pass: ") / 2)), 0)+5, 7)
- term.setBackgroundColor(colors.white)
- print(" ")
- term.setBackgroundColor(colors.blue)
- cPrint(" Done! ", 9)
- --[[TODO:
- cPrint("Background Color: ", 7)
- --paintutils.drawPixel(math.max(math.floor((w / 2) - (string.len("Background Color: ") / 2)), 0)+string.len("Background Color: "), 7, bgC)
- -- BG Color choose
- local cols = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
- local x = 0
- for k, v in pairs(cols) do
- term.setBackgroundColor(v)
- if k < 9 then
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len(" ") / 2)), 0)+x, 9)
- print(" ")
- x = x+1
- else
- x = x-1
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len(" ") / 2)), 0)+x, 10)
- print(" ")
- end
- end
- --]]
- -- Catch events
- while true do
- e, p1, p2, p3, p4, p5 = os.pullEvent()
- if e == "mouse_click" then
- if state == 0 then
- if p3 == 3 and p2 >= math.max(math.floor((w / 2) - (string.len("Name: ") / 2)), 0) and p2 <= math.max(math.floor((w / 2) - (string.len("Name: ") / 2)), 0)+5 then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Name: ") / 2)), 0)+5, 3)
- name = read()
- print(name)
- elseif p3 == 5 and p2 >= math.max(math.floor((w / 2) - (string.len("Label: ") / 2)), 0) and p2 <= math.max(math.floor((w / 2) - (string.len("Label: ") / 2)), 0)+5 then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Label: ") / 2)), 0)+5, 5)
- local label = read()
- os.setComputerLabel(label)
- elseif p3 == 7 and p2 >= math.max(math.floor((w / 2) - (string.len("Pass: ") / 2)), 0) and p2 <= math.max(math.floor((w / 2) - (string.len("Pass: ") / 2)), 0)+6 then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(math.max(math.floor((w / 2) - (string.len("Pass: ") / 2)), 0)+5, 7)
- pass = read('*')
- elseif p3 == 9 and p2 >= math.max(math.floor((w / 2) - (string.len(" Done! ") / 2)), 0) and p2 <= math.max(math.floor((w / 2) - (string.len(" Done! ") / 2)), 0)+7 then
- local f = fs.open("./config.cfg", "w")
- if not fs.exists("./users") then
- fs.makeDir("./users")
- end
- local q = fs.open("./users/"..name, "w")
- q.write(pass)
- q.close()
- --local data = textutils.serialize()
- f.write("Setup")
- f.close()
- os.reboot()
- end
- end
- end
- end
- return true
- end
- -- BSOD
- function bsod(error)
- state = 3
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.cyan)
- term.clear()
- cPrint("Error!", 2)
- local x = 4
- local btn1 = 6
- local btn2 = 8
- for _, line in ipairs(split(error, 20)) do
- cPrint(line, x)
- x = x+1
- btn1 = btn1+1
- btn2 = btn2+1
- end
- term.setBackgroundColor(colors.blue)
- cPrint(" Exit ", btn1)
- cPrint(" Reboot ", btn2)
- -- Events
- while true do
- e, p1, p2, p3, p4, p5 = os.pullEvent()
- if e == "mouse_click" then
- if state == 3 then
- if p3 == btn1 and p2 >= math.max(math.floor((w / 2) - (string.len(" Exit ") / 2)), 0) and p2 <= math.max(math.floor((w / 2) - (string.len(" Exit ") / 2)), 0)+6 then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- return true
- elseif p3 == btn2 and p2 >= math.max(math.floor((w / 2) - (string.len(" Reboot ") / 2)), 0) and p2 <= math.max(math.floor((w / 2) - (string.len(" Reboot ") / 2)), 0)+8 then
- os.reboot()
- end
- end
- end
- end
- end
- -- Boot thingy
- if term.isColor() then
- if fs.exists('./config.cfg') then
- local ok, err = pcall(start)
- if not ok then
- -- BSOD
- bsod(err)
- end
- else
- local ok, err = pcall(setup)
- if not ok then
- -- BSOD
- bsod(err)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement