FoxWorn3365

hackos_desktop

Dec 5th, 2021 (edited)
290
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. term.setCursorPos(1, 1)
  2. term.setBackgroundColor(colors.white)
  3. term.clear()
  4.  
  5. -- Hack OS - v0.19
  6. -- By FoxWorn3365
  7.  
  8.  
  9. -- APPUNTI
  10. -- Configurazioni sistema: .localConf
  11. -- Configurazioni pubbliche: .publicConf
  12. -- Immagini: /Hack/images/
  13. -- APP: /Hack/programmi/
  14. -- App di esempio:
  15. --   Directory: /Hack/programmi/fileManager/
  16. --   Icona: /Hack/programmi/fileManager/app.ico
  17. --   File da eseguire: /Hack/programmi/fileManager/exec.luaDir
  18. --   Configurazioni (facoltativo) (OBBLIGO AUTOGENERAZIONE): /Hack/programmi/fileManager/conf.public
  19. --   Nome dell'APP (massimo 4 caratteri): /Hack/programmi/fileManager/app.name
  20. --   API: https://fcosma.it/hackos/api
  21.  
  22. maxw, maxh = term.getSize()
  23. local function drawPixelInternal(xPos, yPos)
  24.     term.setCursorPos(xPos, yPos)
  25.     term.write(" ")
  26. end
  27.  
  28. local tColourLookup = {}
  29. for n = 1, 16 do
  30.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  31. end
  32.  
  33. function drawFilledBox(startX, startY, endX, endY, nColour)
  34.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  35.         "number" or type(endY) ~= "number" or
  36.         (nColour ~= nil and type(nColour) ~= "number") then
  37.         error("Expected startX, startY, endX, endY, colour", 2)
  38.     end
  39.  
  40.     startX = math.floor(startX)
  41.     startY = math.floor(startY)
  42.     endX = math.floor(endX)
  43.     endY = math.floor(endY)
  44.  
  45.     if nColour then term.setBackgroundColor(nColour) end
  46.     if startX == endX and startY == endY then
  47.         drawPixelInternal(startX, startY)
  48.         return
  49.     end
  50.  
  51.     local minX = math.min(startX, endX)
  52.     if minX == startX then
  53.         minY = startY
  54.         maxX = endX
  55.         maxY = endY
  56.     else
  57.         minY = endY
  58.         maxX = startX
  59.         maxY = startY
  60.     end
  61.  
  62.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  63. end
  64.  
  65. function  giremu(inputstr, sep)
  66.         local t={}
  67.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  68.                 table.insert(t, str)
  69.         end
  70.         return t
  71. end
  72.  
  73. function clear()
  74.     sfondo(colors.black)
  75.     term.clear()
  76.     term.setCursorPos(1, 1)
  77. end
  78.  
  79. function clearRed()
  80.     sfondo(colors.red)
  81.     term.clear()
  82.     term.setCursorPos(1, 1)
  83. end
  84.  
  85. function titolo(testo)
  86.     drawFilledBox(1, 1, maxw, 1, colors.orange)
  87.     term.setCursorPos((maxw - #testo) / 2, 1)
  88.     term.setTextColor(colors.white)
  89.     term.write(testo)
  90. end
  91.  
  92. function alarm(testo, colore, y)
  93.     drawFilledBox(1, y, maxw, y, colors[colore])
  94.     term.setCursorPos((maxw - #testo) / 2, y)
  95.     term.setTextColor(colors.white)
  96.     term.write(testo)
  97.     no()
  98. end
  99.  
  100.  
  101. function ico(x, y, color, text)
  102.    term.setBackgroundColor(colors[color])
  103.    term.setTextColor(colors.white)
  104.    term.setCursorPos(x, y)
  105.    print(text)
  106. end
  107.  
  108. function drawA()
  109.    term.setBackgroundColor(colors.white)
  110.    term.setTextColor(colors.black)
  111. end
  112.  
  113. function programExec(programDir, type)
  114.     if type == "default_program_app" then
  115.        -- Apro il programma in modo default, eseguendolo
  116.        -- Consigliato solo con le app ufficiali
  117.        don = "execProgram"
  118.        program = programDir
  119.      elseif type == "external_program_app" then
  120.        shell.run(programDir.."/exec.luaDir")
  121.      end
  122. end
  123.  
  124. function loadDesktopBackground()
  125.     if fs.exists("/.bkgConf") == true then
  126.         local h = fs.open("/.bkgConf", "r")
  127.         local backImage = h.readAll()
  128.         h.close()
  129.         drawA()
  130.         term.clear()
  131.         local image = paintutils.loadImage("/Hack/files/"..backImage)
  132.         paintutils.drawImage(image, 1, 2)
  133.     elseif fs.exists("/.bkgColor") == true then
  134.         local h = fs.open("/.bkgColor", "r")
  135.         local backColor = h.readAll()
  136.         h.close()
  137.         term.setBackgroundColor(colors[backColor])
  138.         term.setTextColor(colors.black)
  139.         term.clear()
  140.     else
  141.         term.setBackgroundColor(colors.white)
  142.         term.setTextColor(colors.black)
  143.         term.clear()    
  144.     end
  145. end
  146.  
  147. don = 1
  148.  
  149. while true do
  150. if don == 0 then
  151. -- Login
  152.   drawA()
  153.   term.clear()
  154.   local image = paintutils.loadImage('Hack/sfondo.png')
  155.   paintutils.drawImage(image, 1, 2)
  156.   titolo("Accedi al computer di "..conf[1].."!")
  157.   drawA()
  158.   print("\n\nInserisci la password:")
  159.   local pass = read()
  160.   if pass ~= conf[3] then
  161.     term.setTextColor(colors.red)
  162.     print("\nPassword errata! Potrai riprovare tra 3 secondi..")
  163.     sleep(3)
  164.     drawA()
  165.     term.clear()
  166.     term.setTextColor(colors.black)
  167.     local image = paintutils.loadImage('Hack/sfondo.png')
  168.     paintutils.drawImage(image, 1, 2)
  169.     titolo("Accedi al computer di "..conf[1])
  170.     drawA()
  171.     print("\n\nInserisci la password:")
  172.     local pass = read()
  173.     if pass ~= conf[3] then
  174.        term.setTextColor(colors.red)
  175.        print("Password errata!\nProcedo con il riavvio.\nHo salvato nel LOG l'errore di accesso!")
  176.        sleep(4)
  177.        shell.run("reboot")
  178.     else
  179.        don = 1
  180.     end
  181.   else
  182.     don = 1
  183.   end
  184. elseif don == 1 then
  185.   loadDesktopBackground()
  186.   appList = {}
  187.   app = 1
  188.   titolo("Computer di "..conf[1].."  -  /Hack/Desktop")
  189.   ico(48, 1, "red", "ESCI")
  190.   term.setCursorPos(1, 3)
  191.   oldX = 0
  192.   oldY = 0
  193.   y = 3
  194.   for i, k in pairs(fs.list("/Hack/programmi/")) do
  195.     if fs.isDir("/Hack/programmi/"..k) == true then
  196.         x = 2 + oldX
  197.       term.setCursorPos(x, y)
  198.       ico = paintutils.loadImage("/Hack/programmi/"..k.."/app.ico")
  199.       local h = fs.open("/Hack/programmi/"..k.."/app.name", "r")
  200.       aName = h.readAll()
  201.       h.close()
  202.       paintutils.drawImage(ico, x, y)
  203.       oldX, oldY = term.getCursorPos()
  204.       term.setCursorPos(oldX-4, y+3)
  205.       drawA()
  206.       term.write(aName)
  207.       term.setCursorPos(oldX, oldY)
  208.       for i=x, x+3 do
  209.         for b=y, y+3 do
  210.           appList[tostring(i).." "..tostring(b)] = k
  211.         end
  212.       end
  213.       x = x + 4
  214.       if x >= 47 then
  215.          x = 0
  216.          oldX = 0
  217.          y = y+5
  218.       end
  219.     end
  220.   end
  221.   local event, key, x, y = os.pullEvent()
  222.   if event == "mouse_click" and y == 1 and x > 48 then
  223.     shell.run("reboot")
  224.   elseif event == "key" and keys.getName(key) == "h" then
  225.     local event, key2 = os.pullEvent("key")
  226.     if keys.getName(key2) == "i" then
  227.       shell.run("/Hack/programmi/settings/exec.luaDir")
  228.     end
  229.   elseif appList[tostring(x).." "..tostring(y)] ~= nil and appList[tostring(x).." "..tostring(y)] ~= '' then
  230.        shell.run("/Hack/programmi/"..appList[tostring(x).." "..tostring(y)].."/exec.luaDir")
  231.   end
  232. end
  233. sleep(1)
  234. end
  235.  
  236.    
  237.  
  238.  
RAW Paste Data