lego11

GEM GeneralPurpose

Sep 5th, 2020 (edited)
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pref = {}
  2. w, h = term.getSize()
  3. pref["w"] = w
  4. pref["h"] = h
  5. icoreg = {}
  6.  
  7.  
  8. if os.getComputerLabel() == nil then
  9.   lab = math.random(100000)
  10.   os.setComputerLabel("GemPC-"..tostring(lab))
  11. end
  12.  
  13. pref["pcname"] = os.getComputerLabel()
  14.  
  15. local settings = {}
  16.  
  17. if not fs.exists("/programs") then
  18.   fs.makeDir("/programs")
  19.   fs.makeDir("/programs/icons")
  20. end
  21.  
  22. if not fs.exists("/data") then
  23.   fs.makeDir("/data")
  24. end
  25.  
  26. if not fs.exists("/.settings") then
  27.   shell.run("pastebin get khtTEKeW /.settings")
  28. end
  29.  
  30. if not fs.exists("/programs/lenet") then
  31.   shell.run("pastebin get EQgHhsAA /programs/lenet")
  32.   shell.run("pastebin get LtqRbjn6 /programs/icons/lenet")
  33. end
  34.  
  35. if not fs.exists("/programs/fman") then
  36.   shell.run("pastebin get huiuVc0V /programs/fman")
  37.   shell.run("pastebin get 9NP17Ev2 /programs/icons/fman")
  38. end
  39.  
  40. if not fs.exists("/programs/luaint") then
  41.   shell.run("pastebin get RBMbTH66 /programs/luaint")
  42.   shell.run("pastebin get wUwjr0ge /programs/icons/luaint")
  43. end
  44.  
  45. if not fs.exists("/programs/xterm") then
  46.   shell.run("pastebin get iPuysQxu /programs/xterm")
  47.   shell.run("pastebin get RU9Jcuwr /programs/icons/xterm")
  48. end
  49.  
  50. if not fs.exists("/.settings") then
  51.   shell.run("pastebin get 5tq5WgFL /.settings")
  52. end
  53.  
  54. if not fs.exists("/settings") then
  55.   shell.run("pastebin get 1NphnkqB /settings")
  56. end
  57.  
  58. function loadDeskSettings()
  59.   file = fs.open("/.settings", "r")
  60.   settings = textutils.unserialize(file.readAll())
  61.   file.close()
  62.   pref["background"] = settings["background"]
  63. end
  64.  
  65.  
  66. function drawDesktop()
  67.   loadDeskSettings()
  68.   term.setBackgroundColor(settings["background"])
  69.   term.clear()
  70.   term.setCursorPos(1, 1)
  71.   term.setBackgroundColor(colors.white)
  72.   for i=1, pref["w"] do
  73.     term.write(" ")
  74.   end
  75.   term.setTextColor(colors.black)
  76.   term.setCursorPos((pref["w"]/2)-(#pref["pcname"]/2), 1)
  77.   term.write(pref["pcname"])
  78.   term.setCursorPos(1, 1)
  79.   term.setBackgroundColor(colors.lightGray)
  80.   term.write("Menu")
  81.   term.setCursorPos(2, 3)
  82.   term.setBackgroundColor(colors.white)
  83.   x, y = term.getCursorPos()
  84.   for i, k in pairs(fs.list("/programs")) do
  85.     if fs.isDir("/programs/"..k) ~= true then
  86.       if x >= 51 then
  87.         x = 2
  88.         y = y + 7
  89.       end
  90.       term.setCursorPos(x, y)
  91.       ico = paintutils.loadImage("/programs/icons/"..k)
  92.       paintutils.drawImage(ico, x, y)
  93.       term.setCursorPos(x, y+5)
  94.       term.setBackgroundColor(settings["background"])
  95.       term.write(string.sub(k, 1, 5))
  96.       for i=x, x+4 do
  97.         for b=y, y+4 do
  98.           icoreg[tostring(i).." "..tostring(b)] = "/programs/"..k
  99.         end
  100.       end
  101.       x = x + 6
  102.     end
  103.   end
  104. end
  105.  
  106. function drawMenu()
  107.   term.setCursorPos(1, 2)
  108.   term.setBackgroundColor(colors.lightGray)
  109.   term.setTextColor(colors.black)
  110.   term.setTextColor(colors.red)
  111.   term.write("Spegni      ")
  112.   term.setCursorPos(1, 3)
  113.   term.setTextColor(colors.yellow)
  114.   term.write("Riavvia     ")
  115.   term.setCursorPos(1, 4)
  116.   term.setTextColor(colors.black)
  117.   term.write("Impostazioni")
  118. end
  119.  
  120. function drawClock()
  121.   term.setBackgroundColor(colors.white)
  122.   term.setCursorPos(pref["w"]-#textutils.formatTime(os.time(), true), 1)
  123.   term.setTextColor(colors.black)
  124.   term.write(textutils.formatTime(os.time(), true))
  125. end
  126.  
  127. function getInput()
  128.   menu = false
  129.   while true do
  130.     if not menu then
  131.       drawDesktop()
  132.     end
  133.     drawClock()
  134.     timerclock = os.startTimer(1)
  135.     _, bt, x, y = os.pullEventRaw()
  136.     if _ == "timer" and bt == timerclock then
  137.       drawClock()
  138.     end
  139.     if _ == "terminate" then
  140.       if settings["terminable"] then
  141.         term.setBackgroundColor(colors.black)
  142.         term.clear()
  143.         term.setCursorPos(1, 1)
  144.         if settings["live"] then
  145.         for i, k in pairs(fs.list("/data")) do
  146.           fs.delete("/data/"..k)
  147.         end
  148.         end
  149.         return
  150.       end
  151.     end
  152.     if bt == 1 and _ == "mouse_click" and x >= 1 and x <= 4 and y == 1 then
  153.         if menu then
  154.           drawDesktop()
  155.           drawClock()
  156.           menu = false
  157.         else
  158.           drawDesktop()
  159.           drawMenu()
  160.           drawClock()
  161.           menu = true
  162.         end
  163.     elseif bt == 1 and _ == "mouse_click" and x >= 1 and x <= 12 and menu and y >= 2 and y <= 4 then
  164.       if y == 2 then
  165.         if settings["live"] then
  166.           for i, k in pairs(fs.list("/data")) do
  167.             fs.delete("/data/"..k)
  168.           end
  169.         end
  170.         os.shutdown()
  171.       elseif y == 3 then
  172.         if settings["live"] then
  173.           for i, k in pairs(fs.list("/data")) do
  174.             fs.delete("/data/"..k)
  175.           end
  176.         end
  177.         os.reboot()
  178.       elseif y == 4 then
  179.         menu = false
  180.         shell.run("/settings")
  181.         loadDeskSettings()
  182.         drawDesktop()
  183.       end
  184.     elseif _ == "mouse_click" then
  185.       if icoreg[tostring(x).." "..tostring(y)] ~= nil then
  186.         shell.run(icoreg[tostring(x).." "..tostring(y)])
  187.       end
  188.       menu = false
  189.     end
  190.   end
  191. end
  192.  
  193. getInput()
Add Comment
Please, Sign In to add comment