Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.white)
- term.clear()
- -- Hack OS - v0.19
- -- By FoxWorn3365
- -- APPUNTI
- -- Configurazioni sistema: .localConf
- -- Configurazioni pubbliche: .publicConf
- -- Immagini: /Hack/images/
- -- APP: /Hack/programmi/
- -- App di esempio:
- -- Directory: /Hack/programmi/fileManager/
- -- Icona: /Hack/programmi/fileManager/app.ico
- -- File da eseguire: /Hack/programmi/fileManager/exec.luaDir
- -- Configurazioni (facoltativo) (OBBLIGO AUTOGENERAZIONE): /Hack/programmi/fileManager/conf.public
- -- Nome dell'APP (massimo 4 caratteri): /Hack/programmi/fileManager/app.name
- -- API: https://fcosma.it/hackos/api
- maxw, maxh = term.getSize()
- local function drawPixelInternal(xPos, yPos)
- term.setCursorPos(xPos, yPos)
- term.write(" ")
- end
- local tColourLookup = {}
- for n = 1, 16 do
- tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
- end
- function drawFilledBox(startX, startY, endX, endY, nColour)
- if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
- "number" or type(endY) ~= "number" or
- (nColour ~= nil and type(nColour) ~= "number") then
- error("Expected startX, startY, endX, endY, colour", 2)
- end
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- if nColour then term.setBackgroundColor(nColour) end
- if startX == endX and startY == endY then
- drawPixelInternal(startX, startY)
- return
- end
- local minX = math.min(startX, endX)
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
- end
- function giremu(inputstr, sep)
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function clear()
- sfondo(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function clearRed()
- sfondo(colors.red)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function titolo(testo)
- drawFilledBox(1, 1, maxw, 1, colors.orange)
- term.setCursorPos((maxw - #testo) / 2, 1)
- term.setTextColor(colors.white)
- term.write(testo)
- end
- function alarm(testo, colore, y)
- drawFilledBox(1, y, maxw, y, colors[colore])
- term.setCursorPos((maxw - #testo) / 2, y)
- term.setTextColor(colors.white)
- term.write(testo)
- no()
- end
- function bottone(color, text, x, y)
- term.setBackgroundColor(colors[color])
- term.setTextColor(colors.white)
- term.setCursorPos(x, y)
- print(text)
- end
- function drawA()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- end
- function programExec(programDir, type)
- if type == "default_program_app" then
- -- Apro il programma in modo default, eseguendolo
- -- Consigliato solo con le app ufficiali
- don = "execProgram"
- program = programDir
- elseif type == "external_program_app" then
- shell.run(programDir.."/exec.luaDir")
- end
- end
- function loadDesktopBackground()
- if fs.exists("/.bkgConf") == true then
- local h = fs.open("/.bkgConf", "r")
- local backImage = h.readAll()
- h.close()
- drawA()
- term.clear()
- local image = paintutils.loadImage("/Hack/files/"..backImage)
- paintutils.drawImage(image, 1, 2)
- elseif fs.exists("/.bkgColor") == true then
- local h = fs.open("/.bkgColor", "r")
- local backColor = h.readAll()
- h.close()
- term.setBackgroundColor(colors[backColor])
- term.setTextColor(colors.black)
- term.clear()
- else
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- end
- end
- if fs.exists(".localConf") == false then
- titolo("Hack OS - Installazione")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- print("\n\nInserisci il tuo nome:")
- name = read()
- dir = "hackPC_VERIFIED"
- print("\nInserisci la password (vuoto per non usarla)")
- pass = read()
- term.setTextColor(colors.green)
- local h = fs.open(".localConf", "w")
- if pass == nil or pass == '' then
- h.writeLine(name.."$"..dir)
- shell.run("label set hack_osPC-"..name)
- elseif pass ~= nil and pass ~= '' and name ~= nil and name ~= '' then
- h.writeLine(name.."$"..dir.."$"..pass)
- shell.run("label set hack_osPC-"..name)
- elseif pass == nil or pass == '' and name == nil or name == '' then
- h.writeLine("HackPC$"..dir.."$"..pass)
- shell.run("label set hack_osPC-defaultName")
- end
- h.flush()
- h.close()
- print("\nFatto! Premi un tasto qualsiasi")
- os.pullEvent("key")
- shell.run("reboot")
- else
- local h = fs.open(".localConf", "r")
- confInit = h.readAll()
- h.close()
- conf = giremu(confInit, "$")
- end
- don = 0
- while true do
- if don == 0 then
- -- Login
- if conf[3] == nil then
- shell.run("desktop")
- else
- drawA()
- term.clear()
- local image = paintutils.loadImage('Hack/sfondo.png')
- paintutils.drawImage(image, 1, 2)
- titolo("Accedi al computer di "..conf[1].."!")
- drawA()
- print("\n\nInserisci la password:")
- local pass = read()
- if pass ~= conf[3] then
- term.setTextColor(colors.red)
- print("\nPassword errata! Potrai riprovare tra 3 secondi..")
- sleep(3)
- drawA()
- term.clear()
- term.setTextColor(colors.black)
- local image = paintutils.loadImage('Hack/sfondo.png')
- paintutils.drawImage(image, 1, 2)
- titolo("Accedi al computer di "..conf[1])
- drawA()
- print("\n\nInserisci la password:")
- local pass = read()
- if pass ~= conf[3] then
- term.setTextColor(colors.red)
- print("Password errata!\nProcedo con il riavvio.\nHo salvato nel LOG l'errore di accesso!")
- sleep(4)
- shell.run("reboot")
- else
- don = 1
- end
- else
- don = 1
- end
- end
- elseif don == 1 then
- loadDesktopBackground()
- appList = {}
- app = 1
- titolo("Computer di "..conf[1].." - /Hack/Desktop")
- term.setCursorPos(1, 3)
- oldX = 0
- oldY = 0
- y = 3
- for i, k in pairs(fs.list("/Hack/programmi/")) do
- if fs.isDir("/Hack/programmi/"..k) == true then
- x = 2 + oldX
- term.setCursorPos(x, y)
- ico = paintutils.loadImage("/Hack/programmi/"..k.."/app.ico")
- local h = fs.open("/Hack/programmi/"..k.."/app.name", "r")
- aName = h.readAll()
- h.close()
- paintutils.drawImage(ico, x, y)
- oldX, oldY = term.getCursorPos()
- term.setCursorPos(oldX-4, y+3)
- drawA()
- term.write(aName)
- term.setCursorPos(oldX, oldY)
- for i=x, x+3 do
- for b=y, y+3 do
- appList[tostring(i).." "..tostring(b)] = k
- end
- end
- x = x + 4
- if x >= 47 then
- x = 0
- oldX = 0
- y = y+5
- end
- end
- end
- local event, key, x, y = os.pullEvent("mouse_click")
- if appList[tostring(x).." "..tostring(y)] ~= nil and appList[tostring(x).." "..tostring(y)] ~= '' then
- shell.run("/Hack/programmi/"..appList[tostring(x).." "..tostring(y)].."/exec.luaDir")
- end
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement