Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.unloadAPI("multishell")
- os.loadAPI("system/api/multishell")
- os.loadAPI("settings")
- --term.redirect(term.native())
- math.randomseed(os.time())
- colors.transparent = 0
- local screen = {
- new = function(parent, x, y, width, height)
- local s = {
- term = window.create(parent or term.current(), x or 1, y or 1, width or 51, height or 19, false),
- sscroll = 0,
- clear = function(self, color)
- self.term.setBackgroundColor(color or colors.black)
- self.term.clear()
- end,
- drawImage = function(self, sx, sy, width, height, image)
- if width > 0 and height > 0 then
- for y = 1, #image do
- local line = image[y]
- for x = 1, #line do
- if line[x] > 0 and x <= width and y <= height then
- self:setPixel(x + sx - 1, y + sy - 1, line[x])
- end
- end
- end
- end
- end,
- drawText = function(self, x, y, text, backgroundcolor, textcolor)
- self.term.setCursorPos(x, y)
- self.term.setBackgroundColor(backgroundcolor or colors.white)
- self.term.setTextColor(textcolor or colors.white)
- if not (backgroundcolor == colors.transparent) then
- if textcolor == colors.transparent then
- self.term.write("")
- else
- self.term.write(text or "")
- end
- end
- end,
- drawBox = function(self, sx, sy, width, height, color)
- for x = sx, sx + width - 1 do
- for y = sy, sy + height - 1 do
- self:setPixel(x, y, color)
- end
- end
- end,
- setPixel = function(self, x, y, color)
- self.term.setCursorPos(x, y)
- self.term.setBackgroundColor(color or colors.white)
- if not (color == colors.transparent) then
- self.term.write(" ")
- end
- end,
- draw = function(self)
- self.term.setVisible(true)
- self.term.setVisible(false)
- end,
- reposition = function(self, x, y, width, height)
- self.term.reposition(x, y, width, height)
- end,
- scroll = function(self, direction, speed)
- self.term.scroll(direction * (speed or 1))
- end
- }
- return s
- end
- }
- colors.transparent = 0
- local widget = {
- new = function(x, y, width, height)
- local w = {
- x = x or 1,
- y = y or 1,
- width = width or 1,
- height = height or 1,
- visible = true,
- focused = false,
- onclick = function(self, button, x, y)
- end,
- onscroll = function(self, direction, x, y)
- end,
- onkey = function(self, key)
- end,
- onchar = function(self, c)
- end,
- draw = function(self, screen)
- end
- }
- return w
- end
- }
- local layout = {
- new = function(x, y, width, height)
- local w = widget.new(x, y, width, height)
- w.backgroundcolor = colors.black
- w.widgets = {}
- w.screen = screen.new(term.current(), x or 1, y or 1, width or 1, height or 1)
- w.addWidget = function(self, widget)
- self.widgets[#self.widgets + 1] = widget
- end
- w.handleevent = function(self, event, p1, p2, p3, p4, p5)
- if not event then
- event, p1, p2, p3, p4, p5 = os.pullEvent()
- end
- if event == "mouse_click" then
- self:onclick(p1, p2, p3)
- elseif event == "mouse_scroll" then
- self:onscroll(p1, p2, p3)
- elseif event == "key" then
- self:onkey(p1)
- elseif event == "char" then
- self:onchar(p1)
- end
- end
- w.onclick = function(self, button, x, y)
- for i = 1, #self.widgets do
- if (self.widgets[i].width == -1 or self.widgets[i].height == -1) or (x >= self.widgets[i].x and y >= self.widgets[i].y and x <= self.widgets[i].x + self.widgets[i].width - 1 and y <= self.widgets[i].y + self.widgets[i].height - 1) then
- self.widgets[i].focused = true
- self.widgets[i]:onclick(button, x, y)
- else
- self.widgets[i].focused = false
- end
- end
- end
- w.onscroll = function(self, direction, x, y)
- for i = 1, #self.widgets do
- if (self.widgets[i].width == -1 or self.widgets[i].height == -1) or (x >= self.widgets[i].x and y >= self.widgets[i].y and x <= self.widgets[i].x + self.widgets[i].width - 1 and y <= self.widgets[i].y + self.widgets[i].height - 1) then
- self.widgets[i]:onscroll(direction, x, y)
- end
- end
- end
- w.onkey = function(self, key)
- for i = 1, #self.widgets do
- self.widgets[i]:onkey(key)
- end
- end
- w.onchar = function(self, c)
- for i = 1, #self.widgets do
- self.widgets[i]:onchar(c)
- end
- end
- w.draw = function(self, scr)
- local s = self.screen
- if scr then
- s = screen.new(scr.term, self.x or 1, self.y or 1, self.width or 1, self.height or 1)
- end
- s:clear(self.backgroundcolor)
- if self.visible then
- for i = 1, #self.widgets do
- self.widgets[i]:draw(s)
- end
- end
- s:draw()
- end
- return w
- end
- }
- local imageview = {
- new = function(x, y, width, height, image, picformat)
- local w = widget.new(x, y, width, height)
- w.image = image or {}
- w.picformat = picformat or false
- w.draw = function(self, screen)
- if self.visible then
- if self.picformat then
- local otrm = term.current()
- term.redirect(screen.term)
- drawpic(self.x, self.y, self.image, self.backgroundcolor)
- term.redirect(otrm)
- else
- screen:drawImage(self.x, self.y, self.width, self.height, self.image)
- end
- end
- end
- return w
- end
- }
- local textbox = {
- new = function(x, y, width, height, hint)
- local w = widget.new(x, y, width, height)
- w.backgroundcolor = colors.black
- w.textcolor = colors.white
- w.expandable = false
- w.centered = false
- w.hint = hint or ""
- w.text = ""
- w.setText = function(self, text)
- self.text = text
- end
- w.getText = function(self)
- return self.text
- end
- w.draw = function(self, screen)
- if self.visible and self.width >= 1 and self.height >= 1 then
- local x = self.x
- local y = self.y
- local txt = self.text == "" and self.hint or self.text
- local txtc = self.text == "" and colors.lightGray or self.textcolor
- if self.centered then
- x = self.x + math.floor(self.width / 2 - #txt / 2)
- y = self.y + math.floor(self.height / 2)
- end
- screen:drawBox(self.x, self.y, self.width, self.height, self.backgroundcolor)
- for i = 1, #txt, self.width do
- screen:drawText(x, y, string.sub(txt, i, i + self.width - 1), self.backgroundcolor, txtc)
- y = y + 1
- end
- end
- end
- w.onkey = function(self, key)
- if self.focused and key == keys.backspace then
- self.text = string.sub(self.text, 1, #self.text - 1)
- end
- end
- w.onchar = function(self, c)
- if self.focused and (self.expandable or #self.text < self.width * self.height) then
- self.text = self.text .. c
- end
- end
- return w
- end
- }
- local label = {
- new = function(x, y, width, height, text)
- local w = widget.new(x, y, width, height)
- w.multiline = false
- w.centered = true
- w.backgroundcolor = colors.black
- w.textcolor = colors.white
- w.text = text or ""
- w.setText = function(self, text)
- self.text = text
- end
- w.getText = function(self)
- return self.text
- end
- w.draw = function(self, screen)
- if self.visible and self.width >= 1 and self.height >= 1 then
- local x = self.x
- local y = self.y
- if self.centered then
- x = self.x + math.floor(self.width / 2 - #self.text / 2)
- y = self.y + math.floor(self.height / 2)
- end
- screen:drawBox(self.x, self.y, self.width, self.height, self.backgroundcolor)
- if self.multiline then
- for i = 1, #self.text, self.width do
- screen:drawText(x, y, string.sub(self.text, i, i + self.width - 1), self.backgroundcolor, self.textcolor)
- y = y + 1
- end
- else
- screen:drawText(x, y, self.text, self.backgroundcolor, self.textcolor)
- end
- end
- end
- return w
- end
- }
- local colorz = {
- ["0"] = 1,
- ["1"] = 2,
- ["2"] = 4,
- ["3"] = 8,
- ["4"] = 16,
- ["5"] = 32,
- ["6"] = 64,
- ["7"] = 128,
- ["8"] = 256,
- ["9"] = 512,
- ["a"] = 1024,
- ["b"] = 2048,
- ["c"] = 4096,
- ["d"] = 8192,
- ["e"] = 16384,
- ["f"] = 32768
- }
- term.clear()
- function split(inputstr, sep)
- sep = sep or "%s"
- local t = {}
- local i = 1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function chars(str)
- local t = {}
- for i = 1, string.len(str) do
- t[i] = string.sub(str, i, i)
- end
- return t
- end
- function loadpic(path)
- local h = fs.open(path, "r")
- if h then
- local txt = h.readAll()
- h.close()
- local parts = split(txt, ";")
- local size = split(parts[1] or "0,0", ",")
- local pic = {
- pixels = chars(parts[2] or ""),
- textcolors = chars(parts[3] or ""),
- text = chars(parts[4] or ""),
- width = tonumber(size[1]) or 0,
- height = tonumber(size[2]) or 0
- }
- return pic
- end
- return nil
- end
- function drawpic(sx, sy, pic, background)
- local x = 0
- local y = 0
- for i = 1, pic.width * pic.height do
- term.setCursorPos((sx or 1) + x, (sy or 1) + y)
- term.setBackgroundColor(colorz[pic.pixels[i]] or background or colors.black)
- if pic.textcolors[i] then
- term.setTextColor(colorz[pic.textcolors[i]])
- term.write(pic.text[i] or " ")
- else
- term.write(" ")
- end
- x = x + 1
- if x >= pic.width then
- x = 0
- y = y + 1
- end
- end
- end
- local bor = bit32.bor
- local band = bit32.band
- local bxor = bit32.bxor
- local blshift = bit32.lshift
- local brshift = bit32.arshift
- local mod = 2^32
- local function rrotate(n, b)
- local s = n/(2^b)
- local f = s%1
- return (s-f) + f*mod
- end
- local const = {[0]=
- 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
- 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
- 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
- 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
- }
- local iv = {[0]=
- 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
- 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19,
- }
- local sigma = {[0]=
- {[0]= 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15},
- {[0]=14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3},
- {[0]=11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4},
- {[0]= 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8},
- {[0]= 9, 0, 5, 7, 2, 4,10,15,14, 1,11,12, 6, 8, 3,13},
- {[0]= 2,12, 6,10, 0,11, 8, 3, 4,13, 7, 5,15,14, 1, 9},
- {[0]=12, 5, 1,15,14,13, 4,10, 0, 7, 6, 3, 9, 2, 8,11},
- {[0]=13,11, 7,14,12, 1, 3, 9, 5, 0,15, 4, 8, 6, 2,10},
- {[0]= 6,15,14, 9,11, 3, 0, 8,12, 2,13, 7, 1, 4,10, 5},
- {[0]=10, 2, 8, 4, 7, 6, 1, 5,15,11, 9,14, 3,12,13, 0}
- }
- local function quarterRound(s, a, b, c, d, m, r, i)
- local j, k = sigma[r%10][2*i], sigma[r%10][(2*i)+1]
- s[a] = (s[a]+(s[b]+(bxor(m[j], const[k]))))%mod
- s[d] = rrotate(bxor(s[d], s[a]), 16)
- s[c] = (s[c]+s[d])%mod
- s[b] = rrotate(bxor(s[b], s[c]), 12)
- s[a] = (s[a]+(s[b]+(bxor(m[k], const[j]))))%mod
- s[d] = rrotate(bxor(s[d], s[a]), 8)
- s[c] = (s[c]+s[d])%mod
- s[b] = rrotate(bxor(s[b], s[c]), 7)
- return s
- end
- local function compress(h, m, s)
- local v = {[0]=
- h[ 0], h[ 1], h[ 2], h[ 3], h[ 4], h[ 5], h[ 6], h[ 7],
- h[ 8], h[ 9], h[10], h[11], h[12], h[13], h[14], h[15]
- }
- for r = 0, 13 do
- v = quarterRound(v, 0, 4, 8,12, m, r, 0)
- v = quarterRound(v, 1, 5, 9,13, m, r, 1)
- v = quarterRound(v, 2, 6,10,14, m, r, 2)
- v = quarterRound(v, 3, 7,11,15, m, r, 3)
- v = quarterRound(v, 0, 5,10,15, m, r, 4)
- v = quarterRound(v, 1, 6,11,12, m, r, 5)
- v = quarterRound(v, 2, 7, 8,13, m, r, 6)
- v = quarterRound(v, 3, 4, 9,14, m, r, 7)
- end
- for i = 0, 7 do
- h[i] = bxor(bxor(bxor(h[i], v[i]), v[i+8]), s[i] or s[i-4])
- end
- return h
- end
- local function BE_toInt(bs, i)
- return blshift((bs[i+1] or 0), 24) + blshift((bs[i+2] or 0), 16) + blshift((bs[i+3] or 0), 8) + (bs[i+4] or 0)
- end
- local function incr(t, incr)
- if 0xFFFFFFFF - t[0] < incr then
- t[1] = t[1] + 1
- t[0] = incr - (0xFFFFFFFF - t[0]) - 1
- else
- t[0] = t[0] + incr
- end
- return t
- end
- function digest(data, salt)
- local data = type(data) == "string" and {data:byte(1,-1)} or data
- local salt = type(salt) == "string" and {salt:byte(1,-1)} or salt
- local salt = salt or {}
- local m = {}
- local v = {}
- local t = {[0]=0,0}
- local h = {[0]=iv[0], iv[1], iv[2], iv[3], iv[4], iv[5], iv[6], iv[7]}
- local s = {[0]=BE_toInt(salt, 0), BE_toInt(salt, 4), BE_toInt(salt, 8), BE_toInt(salt,12)}
- local mLen = #data
- data[#data+1] = 0x80
- while #data%64~=56 do data[#data+1] = 0 end
- data[#data] = bor(data[#data], 1)
- t = incr(t, mLen*8)
- for i = 1, 0, -1 do
- data[#data+1] = band(brshift(band(t[i], 0xFF000000), 24), 0xFF)
- data[#data+1] = band(brshift(band(t[i], 0xFF0000), 16), 0xFF)
- data[#data+1] = band(brshift(band(t[i], 0xFF00), 8), 0xFF)
- data[#data+1] = band(t[i], 0xFF)
- end
- t[0], t[1] = 0, 0
- local blockAmt = math.ceil(#data/64)
- for i = 0, blockAmt-1 do
- for j = 0, 15 do m[j] = BE_toInt(data, (64*i)+4*j) end
- if mLen == 0 then t[0], t[1] = 0, 0
- elseif (mLen-64) >= 0 then
- t = incr(t, 512)
- mLen = mLen-64
- elseif (mLen-64) < 0 then
- t = incr(t, mLen*8)
- mLen = 0
- end
- v = {[0]=
- h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7],
- bxor(s[0], const[0]), bxor(s[1], const[1]), bxor(s[2], const[2]), bxor(s[3], const[3]),
- bxor(t[0], const[4]), bxor(t[0], const[5]), bxor(t[1], const[6]), bxor(t[1], const[7]),
- }
- h = compress(v, m, s)
- end
- return (("%08x"):rep(8)):format(h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7])
- end
- local Chars = {}
- for Loop = 0, 255 do
- Chars[Loop+1] = string.char(Loop)
- end
- local String = table.concat(Chars)
- local Built = {['.'] = Chars}
- local AddLookup = function(CharSet)
- local Substitute = string.gsub(String, '[^'..CharSet..']', '')
- local Lookup = {}
- for Loop = 1, string.len(Substitute) do
- Lookup[Loop] = string.sub(Substitute, Loop, Loop)
- end
- Built[CharSet] = Lookup
- return Lookup
- end
- function string.random(Length, CharSet)
- -- Length (number)
- -- CharSet (string, optional); e.g. %l%d for lower case letters and digits
- local CharSet = CharSet or '.'
- if CharSet == '' then
- return ''
- else
- local Result = {}
- local Lookup = Built[CharSet] or AddLookup(CharSet)
- local Range = table.getn(Lookup)
- for Loop = 1,Length do
- Result[Loop] = Lookup[math.random(1, Range)]
- end
- return table.concat(Result)
- end
- end
- function __setTitle(title)
- multishell.setTitle(multishell.getCurrent(), title)
- end
- __setTitle("#")
- fs.readFile = function(path)
- local h = fs.open(path, "r")
- if h then
- local r = h.readAll()
- h.close()
- return r
- end
- return nil
- end
- function endswith(str, e)
- return e == "" or string.sub(str, -string.len(e)) == e
- end
- local program = {
- open = function(path)
- shell.openTab(path)
- multishell.setFocus(multishell.getCount())
- end
- }
- local programicon = {
- new = function(x, y, path, lnk)
- local text = fs.getName(path)
- local w = imageview.new(x, y, 5, 5, loadpic(fs.combine(path, "icon.pic")), true)
- if lnk then
- w.image.pixels[21] = "0"
- w.image.textcolors[21] = "9"
- w.image.text[21] = ">"
- text = fs.getName(lnk)
- end
- local l = label.new(x, y + 6, 9, 1, text)
- l.multiline = true
- l.backgroundcolor = colors.lightGray
- w.backgroundcolor = colors.lightGray
- w.odraw = w.draw
- w.path = path
- w.l = l
- w.onclick = function(self, button, x, y)
- program.open(fs.combine(self.path, "app"))
- end
- w.draw = function(self, screen)
- self.l:draw(screen)
- self:odraw(screen)
- end
- return w
- end
- }
- local fileicon = {
- new = function(x, y, path, pic)
- local text = fs.getName(path)
- local w = imageview.new(x, y, 5, 5, pic, true)
- local l = label.new(x, y + 6, 9, 1, text)
- l.multiline = true
- l.backgroundcolor = colors.lightGray
- w.backgroundcolor = colors.lightGray
- w.odraw = w.draw
- w.path = path
- w.l = l
- w.onclick = function(self, button, x, y)
- --program.open("system/app/Explorer.app/app", self.path)
- end
- w.draw = function(self, screen)
- self.l:draw(screen)
- self:odraw(screen)
- end
- return w
- end
- }
- local icons = {
- file = loadpic("system/pic/file.pic"),
- folder = loadpic("system/pic/folder.pic"),
- filelnk = loadpic("system/pic/filelnk.pic"),
- folderlnk = loadpic("system/pic/folderlnk.pic")
- }
- local desktop = layout.new(1, 1, 51, 19)
- desktop.backgroundcolor = colors.lightGray
- local menu = layout.new(1, 1, 12, 19)
- menu.backgroundcolor = colors.gray
- local showmenu = false
- local menub = label.new(1, 10, 1, 1, ">")
- menub.backgroundcolor = desktop.backgroundcolor
- menub.onclick = function(self, button, x, y)
- showmenu = true
- end
- local deskb = label.new(12, 10, 1, 1, "<")
- deskb.backgroundcolor = menu.backgroundcolor
- deskb.onclick = function(self, button, x, y)
- showmenu = false
- end
- local name = label.new(1, 2, 12, 1)
- name.backgroundcolor = menu.backgroundcolor
- name.textcolor = colors.lightGray
- local explorer = label.new(1, 5, 12, 1, "Explorer")
- explorer.backgroundcolor = menu.backgroundcolor
- explorer.onclick = function(self, button, x, y)
- program.open("system/apps/Explorer.app/app")
- end
- local terminal = label.new(1, 7, 12, 1, "Terminal")
- terminal.backgroundcolor = menu.backgroundcolor
- terminal.onclick = function(self, button, x, y)
- program.open("system/apps/Terminal.app/app")
- end
- local settings = label.new(1, 9, 12, 1, "Settings")
- settings.backgroundcolor = menu.backgroundcolor
- settings.onclick = function(self, button, x, y)
- program.open("system/apps/Settings.app/app")
- end
- local rebuild = label.new(1, 13, 12, 1, "Rebuild")
- rebuild.backgroundcolor = menu.backgroundcolor
- rebuild.onclick = function(self, button, x, y)
- shell.run("make")
- os.reboot()
- end
- local lock = label.new(1, 15, 12, 1, "Lock")
- lock.backgroundcolor = menu.backgroundcolor
- lock.onclick = function(self, button, x, y)
- stopDesktop()
- end
- local shutdown = label.new(1, 17, 12, 1, "Shutdown")
- shutdown.backgroundcolor = menu.backgroundcolor
- shutdown.onclick = function(self, button, x, y)
- os.shutdown()
- end
- desktop:addWidget(menub)
- function loadDesktop()
- local currentuser = settings.get("name", "")
- name.text = currentuser
- local deskpath = "users/" .. currentuser .. "/desktop/"
- local l = fs.list(deskpath)
- desktop.widgets = {}
- desktop:addWidget(menub)
- for i = 1, #l do
- local f = l[i]
- local fp = deskpath .. f
- if endswith(f, ".lnk") then
- local lnkdir = fs.readFile(fp)
- fp = lnkdir or ""
- if endswith(fp, ".app") then
- desktop:addWidget(programicon.new(4 + 14 * (i - 1), 2, fp, string.sub(f, 1, #f - 4)))
- elseif fs.isDir(fp) then
- desktop:addWidget(fileicon.new(4 + 14 * (i - 1), 2, fp, icons.folderlnk))
- else
- desktop:addWidget(fileicon.new(4 + 14 * (i - 1), 2, fp, icons.filelnk))
- end
- elseif endswith(f, ".app") then
- desktop:addWidget(programicon.new(4 + 14 * (i - 1), 2, fp))
- elseif fs.isDir(fp) then
- desktop:addWidget(fileicon.new(4 + 14 * (i - 1), 2, fp, icons.folder))
- else
- desktop:addWidget(fileicon.new(4 + 14 * (i - 1), 2, fp, icons.file))
- end
- end
- end
- menu:addWidget(name)
- menu:addWidget(deskb)
- menu:addWidget(rebuild)
- menu:addWidget(lock)
- menu:addWidget(explorer)
- menu:addWidget(terminal)
- menu:addWidget(settings)
- menu:addWidget(shutdown)
- local desktoprunning = false
- function runDesktop()
- desktoprunning = true
- --__setTitle("#")
- while desktoprunning do
- loadDesktop()
- desktop:draw()
- if showmenu then
- menu:draw()
- menu:handleevent()
- else
- desktop:handleevent()
- end
- end
- runLockScreen()
- end
- function stopDesktop()
- desktoprunning = false
- end
- function getusers()
- local userdir = "users/"
- local flist = fs.list(userdir)
- local userlist = {}
- for i = 1, #flist do
- if fs.isDir(userdir .. flist[i]) and fs.exists(fs.combine(userdir .. flist[i], ".user")) then
- table.insert(userlist, userdir .. flist[i])
- end
- end
- return userlist
- end
- function newuser()
- local r = true
- local lay = layout.new(1, 1, 51, 19)
- lay.backgroundcolor = colors.lightGray
- local lab = label.new(1, 4, 51, 1, "New user")
- lab.backgroundcolor = colors.lightGray
- local name = textbox.new(19, 9, 15, 1, "Name")
- name.backgroundcolor = colors.gray
- local pass = textbox.new(19, 11, 15, 1, "Password")
- pass.backgroundcolor = colors.gray
- local err = label.new(1, 18, 51, 1)
- err.backgroundcolor = colors.lightGray
- err.textcolor = colors.red
- err.centered = true
- local done = label.new(23, 13, 6, 1, "Done")
- done.backgroundcolor = colors.gray
- done.onclick = function(self, x, y, button)
- if string.match(name.text, "/") or string.match(name.text, "\\") then
- err.text = "Your name can't contain \"/\" or \"\\\""
- return
- end
- if fs.exists("users/" .. name.text) then
- err.text = "User already exists"
- return
- end
- lay.widgets = {}
- fs.makeDir("users/" .. name.text)
- fs.copy("system/defaults/desktop", "users/" .. name.text .. "/desktop")
- -- Idk if this is really necessary
- local f = fs.open("users/" .. name.text .. "/.user", "w")
- f.write("")
- f.close()
- local salt = string.random(8, "0123456789abcdef")
- settings.load("users/" .. name.text .. "/.user")
- settings.set("name", name.text)
- settings.set("password", digest(pass.text, salt))
- settings.set("passwordsalt", salt)
- settings.save("users/" .. name.text .. "/.user")
- r = false
- end
- lay:addWidget(lab)
- lay:addWidget(name)
- lay:addWidget(pass)
- lay:addWidget(err)
- lay:addWidget(done)
- while r do
- lay:draw()
- lay:handleevent()
- end
- settings.load("system/.settings")
- settings.set("lastuser", "users/" .. name.text)
- settings.save("system/.settings")
- end
- function selectusr(usr, info)
- info.logscreen.widgets = {}
- settings.load(usr .. "/.user")
- local name = settings.get("name", "")
- local password = settings.get("password", "")
- local salt = settings.get("passwordsalt", "")
- local pass = textbox.new(19, 9, 15, 1, "Password")
- pass.backgroundcolor = colors.gray
- local name = label.new(23, 5, 7, 1, name)
- name.backgroundcolor = colors.lightGray
- local login = label.new(23, 11, 7, 1, "Login")
- login.backgroundcolor = colors.gray
- login.onclick = function(self, x, y, button)
- info.lockscreenrunning = not (digest(pass.text, salt) == password)
- end
- info.logscreen:addWidget(back)
- info.logscreen:addWidget(name)
- info.logscreen:addWidget(pass)
- info.logscreen:addWidget(login)
- local x = 1
- for _, usr in ipairs(users) do
- local initials = string.sub(usr, 7, 7)
- for _, s in ipairs(split(string.sub(usr, 7, #usr), " ")) do
- initials = initials .. string.sub(s, 1, 1)
- end
- local usrlab = label.new(x, 17, #initials, 3, initials)
- usrlab.backgroundcolor = colors.lightGray
- usrlab.onclick = function(self, x, y, button)
- selectusr(usr, info)
- end
- logscreen:addWidget(usrlab)
- x = x + #initials
- end
- end
- function runLockScreen()
- local lockscreenrunning = true
- local lockscreen = layout.new(1, 1, 51, 19)
- lockscreen.backgroundcolor = colors.gray
- local logscreen = layout.new(1, 1, 51, 19)
- logscreen.backgroundcolor = colors.lightGray
- local curlay = lockscreen
- local bg = imageview.new(1, 1, 51, 19, loadpic("system/pic/lockscreen/bg01.pic"), true)
- bg.backgroundcolor = lockscreen.backgroundcolor
- bg.onclick = function(self, x, y, button)
- term.setBackgroundColor(logscreen.backgroundcolor)
- for i = 19, 1, -3 do
- sleep(0.05)
- term.setCursorPos(1, i)
- term.clearLine()
- term.setCursorPos(1, i + 1)
- term.clearLine()
- term.setCursorPos(1, i + 2)
- term.clearLine()
- end
- curlay = logscreen
- end
- lockscreen:addWidget(bg)
- local back = label.new(1, 1, 51, 1, "v")
- back.backgroundcolor = logscreen.backgroundcolor
- back.onclick = function(self, x, y, button)
- term.setBackgroundColor(lockscreen.backgroundcolor)
- for i = 1, 19, 3 do
- sleep(0.05)
- term.setCursorPos(1, i)
- term.clearLine()
- term.setCursorPos(1, i - 1)
- term.clearLine()
- term.setCursorPos(1, i - 2)
- term.clearLine()
- end
- curlay = lockscreen
- end
- local users = getusers()
- if #users == 0 then
- newuser()
- selectusr(getusers()[1], {["logscreen"] = logscreen, ["lockscreenrunning"] = lockscreenrunning})
- else
- settings.load("system/.settings")
- selectusr(settings.get("lastuser", users[1]), {["logscreen"] = logscreen, ["lockscreenrunning"] = lockscreenrunning})
- end
- multishell.lock()
- while lockscreenrunning do
- curlay:draw()
- curlay:handleevent()
- end
- settings.load("system/.settings")
- settings.set("lastuser", curuser)
- settings.load("system/.settings")
- multishell.unlock()
- runDesktop()
- end
- runLockScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement