Advertisement
DOGGYWOOF

Untitled

Sep 20th, 2024 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. -- Helper function to display loading bar
  2. local function displayLoadingBar(message, duration)
  3. -- Clear the screen and set up colors
  4. term.clear()
  5. term.setBackgroundColor(colors.black)
  6. term.setTextColor(colors.white)
  7. term.clear()
  8.  
  9. -- Define the width and height of the screen
  10. local width, height = term.getSize()
  11.  
  12. -- Center the message above the loading bar
  13. local function centerText(y, text, textColor)
  14. local x = math.floor((width - #text) / 2)
  15. term.setCursorPos(x, y)
  16. term.setTextColor(textColor)
  17. term.write(text)
  18. end
  19.  
  20. -- Display the message
  21.  
  22.  
  23. -- Loading bar variables
  24. local barWidth = math.floor(width * 0.6)
  25. local startX = math.floor((width - barWidth) / 2)
  26. local barY = height // 2
  27. local loadingSteps = 20
  28. local timePerStep = duration / loadingSteps
  29.  
  30. -- Draw loading bar
  31. for i = 1, loadingSteps do
  32. term.setCursorPos(startX, barY)
  33. term.write("[")
  34. term.setCursorPos(startX + barWidth - 1, barY)
  35. term.write("]")
  36.  
  37. -- Draw the loading progress
  38. local progress = math.floor((i / loadingSteps) * (barWidth - 2))
  39. term.setCursorPos(startX + 1, barY)
  40. term.write(string.rep("=", progress))
  41.  
  42. -- Pause for visual effect
  43. sleep(timePerStep)
  44. end
  45. end
  46.  
  47. -- Repair Bootloader Function with Loading Bar
  48. local function repairBootloader()
  49. displayLoadingBar("Repairing System Bootloader...", 10)
  50.  
  51. -- Delete existing startup and no-os files
  52. fs.delete("/startup")
  53. fs.delete("/no-os")
  54.  
  55. -- Copy the recovery files to the root directory
  56. fs.copy("/recovery/boot/error", "/startup")
  57. fs.copy("/recovery/bootloader/no-os.lua", "/no-os")
  58.  
  59. -- Display the "Repair Completed. Rebooting..." message in white
  60. displayMessage("Repair Completed. Rebooting...")
  61.  
  62. -- Wait for 3 seconds before rebooting
  63. sleep(3)
  64.  
  65. -- Reboot the system
  66. os.reboot()
  67. end
  68.  
  69. -- Recovery from /recovery Function with Loading Bar
  70. local function recoverFromRecovery()
  71. displayLoadingBar("Repairing File System...", 10)
  72.  
  73. -- Delete existing disk directory and copy files from /recovery
  74. fs.delete("/disk/")
  75. fs.copy("/recovery/", "/disk/")
  76.  
  77. -- Display the "Recovery Completed. Rebooting..." message in white
  78. displayMessage("Recovery Completed. Rebooting...")
  79.  
  80. -- Wait for 3 seconds before rebooting
  81. sleep(3)
  82.  
  83. -- Reboot the system
  84. os.reboot()
  85. end
  86.  
  87. -- Recovery from External Source Function with Loading Bar
  88. local function recoverFromExternalSource()
  89. displayLoadingBar("Installing System Update from /disk2/", 10)
  90.  
  91. -- Check if /disk2 exists before copying
  92. if fs.exists("/disk2/") then
  93. fs.delete("/disk/")
  94. fs.copy("/disk2/", "/disk/")
  95. -- Display the "Update Completed. Rebooting..." message in white
  96. displayMessage("Update Completed. Rebooting...")
  97. else
  98. -- Display an error message if /disk2 does not exist
  99. displayMessage("Error: /disk2 does not exist.", colors.red)
  100. end
  101.  
  102. -- Wait for 3 seconds before rebooting
  103. sleep(3)
  104.  
  105. -- Reboot the system
  106. os.reboot()
  107. end
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement