pepeknamornik

Update manager

Jul 6th, 2020 (edited)
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.04 KB | None | 0 0
  1. local verze = "21.0628.R1"
  2. local anim = 0.1
  3. local RamCesta = ("/C/system/RAM/updates")
  4. local w, h = term.getSize()
  5. ----------------------------------------------------
  6. local f=fs.open("/C/system/RAM/user","r")
  7. user=f.readLine()
  8. pass=f.readLine()
  9. Fname=f.readLine()
  10. Lname=f.readLine()
  11. f.close()
  12. ----------------------------------------------------
  13. local f=fs.open("/C/system/Users/"..user.."/.Registry/colors","r")
  14. local cnt=f.readAll()
  15. f.close()
  16. local nastaveni=textutils.unserialize(cnt)
  17. ----------------------------------------------------  
  18. local f=fs.open("/C/system/Users/"..user.."/.Registry/textcol","r")
  19. local tnt=f.readAll()
  20. f.close()
  21. local text=textutils.unserialize(tnt)
  22. ----------------------------------------------------
  23. function ukonceni ()
  24.     fs.delete (RamCesta)
  25.     error()
  26. end
  27.  
  28. function cbarva()
  29. lista.setTextColor(colors.black)
  30. lista.setBackgroundColor(colors.gray)
  31. end
  32.  
  33. function defaultvalue()
  34. end
  35.  
  36. function kontrola()
  37.     if fs.exists("/C/system/server/rules/AD/period.cfg") then
  38.         local data = fs.open("/C/system/server/rules/AD/period.cfg", "r")
  39.         stahovani = data.readLine()
  40.         data.close()
  41.     else
  42.         local data = fs.open("/C/system/server/rules/AD/period.cfg", "w")
  43.         data.writeLine("3600")
  44.         data.close()
  45.         kontrola()
  46.     end
  47.    
  48.     if not fs.exists ("/C/service/updateAD") and not fs.exists ("/C/service/updateAD.lua") then
  49.         if not fs.exists ("/C/stopService/updateAD.lua") then
  50.         shell.run("pastebin get 4ZmxiiV6 /C/service/updateAD.lua")
  51.         multishell.launch({}, "/C/service/updateAD.lua")
  52.         end
  53.     end
  54.    
  55.     local dat = fs.open("/C/service/updateAD.lua", "r")
  56.     verzeS = dat.readLine()
  57.     dat.close()
  58.     verzeS = string.sub(verzeS,10,19)
  59. end
  60.  
  61. function start()
  62. defaultvalue()
  63. local myWindow = window.create(term.current(),w/2-11,h/2-5,25,9)
  64. myWindow.setBackgroundColor(colors.green)
  65. myWindow.setTextColor(colors.white)
  66. myWindow.clear()
  67. myWindow.setCursorPos (8, 5)
  68. myWindow.write"Update Manager"
  69. myWindow.setCursorPos (1, 9)
  70. myWindow.write(verze)
  71. myWindow.setCursorPos (1, 1)
  72. myWindow.write"Pepek@Soft"
  73. myWindow.setCursorPos (22, 9)
  74. myWindow.write"2020"
  75. sleep(1)
  76. kontrola()
  77. menu()
  78. end
  79.  
  80. function plocha()
  81. w, h = term.getSize()
  82. paintutils.drawLine(1, 1, 51, 1, nastaveni.barva)
  83. paintutils.drawPixel (51,1, colors.red)
  84. term.setCursorPos (51,1)
  85. term.setTextColor(text.barva)
  86. write "*"
  87. barW = window.create(term.current(),1,2,w,1)
  88. barW.setBackgroundColor(colors.gray)
  89. barW.clear()
  90. barW.setTextColor(colors.white)
  91. barW.setCursorPos(2,1)
  92. barW.write"Update Manager >"
  93. pozadi = window.create(term.current(),13,3,w,h-2)
  94. pozadi.setBackgroundColor(colors.white)
  95. pozadi.setTextColor(colors.black)
  96. pozadi.clear()
  97. lista = window.create(term.current(),1,3,12,h-2)
  98. lista.setBackgroundColor(nastaveni.barva)
  99. lista.setTextColor(text.barva)
  100. lista.clear()
  101. lista.setCursorPos(2,3)
  102. lista.write"Dashboard"
  103. lista.setCursorPos(2,h-2)
  104. lista.setTextColor(colors.white)
  105. lista.write("Pepek@Soft")
  106. term.setBackgroundColor(colors.lightGray)
  107. end
  108. -----------------------------------------------------------------------------
  109. local page = "main"
  110.  
  111. function main()
  112. barW.setCursorPos(19,1)
  113. barW.write"Dashboard"
  114. pozadi.setCursorPos(2,2)
  115. pozadi.write ("Manager version: "..verze)
  116. pozadi.setCursorPos(2,3)
  117. pozadi.write ("Service version: "..verzeS)
  118. pozadi.setCursorPos(2,5)
  119. pozadi.write"Download updates"
  120. pozadi.setCursorPos(2,7)
  121. pozadi.write"Every"
  122. pozadi.setCursorPos(20,7)
  123. pozadi.write"sec."
  124.     if varovani then
  125.     pozadi.setTextColor(colors.red)
  126.     pozadi.setCursorPos(2,9)
  127.     pozadi.write"Setting has been changed, please"
  128.     pozadi.setCursorPos(2,10)
  129.     pozadi.write"terminate and start service"
  130.     pozadi.setCursorPos(2,11)
  131.     pozadi.write"manually, or restart your computer."
  132.     pozadi.setTextColor(colors.black)
  133.     end
  134.  
  135. pozadi.setBackgroundColor(colors.lightGray)
  136. pozadi.setCursorPos(8,7)
  137. pozadi.write"           "
  138. pozadi.setCursorPos(9,7)
  139. pozadi.write(stahovani)
  140. pozadi.setCursorPos(2,13)
  141. pozadi.write" Start Service "
  142. pozadi.setCursorPos(20,13)
  143. pozadi.write" Update Service "
  144. end
  145.  
  146. function menu()
  147.     plocha()
  148.     if (page == "main") then
  149.         main ()
  150.     end
  151.  
  152.     while true do
  153.         local event, button, x, y = os.pullEvent("mouse_click")
  154.         xy = x..","..y
  155.        
  156.         if event == "mouse_click" and x >= 2 and x <= 12 and y == 5 then
  157.         cbarva()
  158.         lista.setCursorPos(1,3)--
  159.         lista.write" Dashboard  "
  160.         sleep(anim)
  161.         page = "main"
  162.         menu()
  163.         elseif event == "mouse_click" and x >= 20 and x <= 30 and y == 9 then
  164.         pozadi.setBackgroundColor(colors.lightBlue)
  165.         term.setBackgroundColor(colors.lightBlue)
  166.         pozadi.setCursorPos(8,7)
  167.         pozadi.write"           "
  168.         pozadi.setCursorPos(9,7)
  169.         stahovani = read()
  170.         local data = fs.open("/C/system/server/rules/AD/period.cfg", "w")
  171.         data.writeLine(stahovani)
  172.         data.close()
  173.         pozadi.setBackgroundColor(colors.white)
  174.         varovani = true
  175.         elseif event == "mouse_click" and x >= 14 and x <= 28 and y == 15 then
  176.             pozadi.setBackgroundColor(colors.gray)
  177.             pozadi.setCursorPos(2,13)
  178.             pozadi.write" Start Service "
  179.             pozadi.setBackgroundColor(colors.white)
  180.             sleep(anim)
  181.             if fs.exists ("/C/service/updateAD.lua") then
  182.             multishell.launch({}, "/C/service/updateAD.lua")
  183.             pozadi.setTextColor(colors.green)
  184.             pozadi.setCursorPos(2,14)
  185.             pozadi.write"Started successfully"
  186.             sleep(0.5)
  187.             varovani = false
  188.             end
  189.         elseif event == "mouse_click" and x >= 32 and x <= 47 and y == 15 then
  190.             pozadi.setBackgroundColor(colors.gray)
  191.             pozadi.setCursorPos(20,13)
  192.             pozadi.write" Update Service "
  193.             pozadi.setBackgroundColor(colors.white)
  194.             sleep(anim)
  195.             term.setTextColor(colors.white)
  196.             term.setBackgroundColor(colors.white)
  197.             pozadi.setCursorPos(1,14)
  198.             fs.delete("/C/service/updateAD.lua")
  199.             shell.run("pastebin get 4ZmxiiV6 /C/service/updateAD.lua")
  200.             pozadi.setCursorPos(1,14)
  201.             fs.delete("/C/system/server/rules/AD/Update.lua")
  202.             shell.run("pastebin get mCfZSJgY /C/system/server/rules/AD/Update.lua")
  203.             varovani = true
  204.         end
  205.                
  206.         if x == 51 and y == 1 then
  207.             ukonceni ()
  208.         else
  209.             menu() -------- stejne jako nazev funkce
  210.         end
  211.     end
  212. end
  213.  
  214. start()
Advertisement
Add Comment
Please, Sign In to add comment