Marlingaming

Heimbriech Tablet OS - UpdateHandler

Sep 9th, 2021 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. local oldPull = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3. --Heimbriech OS Update Handler, used to gather Update Details, delete old files, download new Files, and check security.
  4. local Stage = 0
  5. local UpdateCode = nil
  6. local UpdateVersion = settings.get("OS_Version")
  7. start()
  8.  
  9. function start()
  10. if Temp_UpdateID == nil then
  11. shell.run("ErrorHandler","Update ID not Found")
  12. else
  13. ReceiveInfo()
  14. end
  15. end
  16.  
  17. function ReceiveInfo()
  18. resp = http.get("pastebin","get","hxRHKpz0","Temp_Updates.txt") --Updates File
  19. local file = fs.open("Temp_Updates.txt","r")
  20. local i = 1
  21. for i = 1, #file.list() do
  22. if file.readLine((i*3)+1) > UpdateVersion then
  23. UpdateVersion = file.readLine((i*3)+1)
  24. UpdateCode = file.readLine((i*3)+3)
  25. end
  26. end
  27. file.close()
  28. term.clear()
  29. if UpdateVersion == settings.get("OS_Version") then
  30. print("Was trying to find new update, but failed to find any new ones")
  31. print("sending User to Menu")
  32. CloseHandler("Menu")
  33. else
  34. UpdateAlert()
  35. end
  36. end
  37. function UpdateAlert()
  38. term.setCursorPos(1,1)
  39. print("New Update Avaliable!"
  40. print("Press e to download, otherwise press b to cancel")
  41. until Stage == 1 or Stage == -1 do
  42. local input = read()
  43. if input == "e" then
  44. Stage = 1
  45. else if input == "b" then"
  46. Stage = -1
  47. end
  48. input = nil
  49. end
  50. if Stage == -1 then
  51. textutils.slowWrite("Closing Update Handler",7)
  52. textutils.slowWrite("Starting Login",9)
  53. sleep(5)
  54. CloseHandler("Menu")
  55. else if Stage == 1 then
  56. print("Starting Update, User Interaction Disabled for time being")
  57. UpdateSetup()
  58. end
  59. end
  60.  
  61. function UpdateSetup()
  62. print("Setting up update tools")
  63. resp = http.get("pastebin","get",UpdateCode,"Temp_Update.PRG) --Target Update File
  64. end
  65.  
  66.  
  67.  
  68. function CloseHandler(Resolve)
  69. if Resolve == "Menu" then
  70. if settings.get("Security_Login") == "n" then
  71. shell.run(".Menu_1")
  72. else
  73. shell.run(".Login_1")
  74. end
  75. else if Resolve == "Restart" then
  76. shell.run(".ShutdownHandler","Restart","false")
  77. end
  78. end
  79. os.pullEvent = oldPull
Add Comment
Please, Sign In to add comment