Advertisement
DOGGYWOOF

Untitled

Jul 24th, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. term.clear()
  2.  
  3. -- Function to get the terminal dimensions
  4. function getTerminalSize()
  5. local width, height = term.getSize()
  6. return width, height
  7. end
  8.  
  9. -- Function to draw the loading bar centered
  10. function drawLoadingBar(current, total, message)
  11. local width, _ = getTerminalSize()
  12. local barLength = 30 -- Length of the loading bar
  13. local filledLength = math.floor((current / total) * barLength)
  14. local emptyLength = barLength - filledLength
  15. local bar = "[" .. string.rep("=", filledLength) .. string.rep(" ", emptyLength) .. "]"
  16.  
  17. -- Calculate the position to center the bar
  18. local barPos = math.floor((width - barLength - 2) / 2)
  19.  
  20. -- Move the UI down by adjusting the row numbers
  21. local barRow = 8
  22. local messageRow = 10
  23.  
  24. term.setCursorPos(barPos, barRow)
  25. term.write(bar .. " " .. math.floor((current / total) * 100) .. "%")
  26.  
  27. -- Print the current message centered below the bar
  28. if message then
  29. term.setCursorPos(1, messageRow)
  30. term.write(string.rep(" ", width)) -- Clear the previous message
  31. term.setCursorPos(math.floor((width - #message) / 2), messageRow)
  32. term.write(message)
  33. end
  34. end
  35.  
  36. -- Function to center and stylize text
  37. function printCenteredText(text, row)
  38. local width, _ = getTerminalSize()
  39. local textLength = #text
  40. local pos = math.floor((width - textLength) / 2)
  41. term.setCursorPos(pos, row)
  42. term.write(text)
  43. end
  44.  
  45. -- Function to display an error message
  46. function showError(message)
  47. term.clear()
  48. local width, height = getTerminalSize()
  49. local errorMessage = "Error: " .. message
  50. local midHeight = math.floor(height / 2)
  51.  
  52. term.setCursorPos(1, midHeight)
  53. term.write(string.rep(" ", width)) -- Clear the row
  54. term.setCursorPos(math.floor((width - #errorMessage) / 2), midHeight)
  55. term.write(errorMessage)
  56.  
  57. term.setCursorPos(1, midHeight + 1)
  58. term.write("Press any key to exit...")
  59. os.pullEvent("key") -- Wait for any key press
  60. term.clear()
  61. end
  62.  
  63. -- Print the initial status messages
  64. printCenteredText("Installing...", 4) -- Moved down to row 4
  65. printCenteredText("DO NOT Interrupt Install", 6) -- Moved down to row 6
  66.  
  67. -- Define installation steps with updated messages
  68. local steps = {
  69. { message = "Creating Secure boot configuration file", action = function()
  70. -- Attempt to copy to the root directory
  71. local success, err = pcall(function()
  72. fs.copy("/disk/.settings", "/.settings")
  73. end)
  74. if not success then
  75. showError("Failed to create secure boot configuration file: " .. err)
  76. end
  77. end },
  78. { message = "Setup copying files...", action = function()
  79. -- Attempt to copy files to the root directory
  80. local success, err = pcall(function()
  81. fs.copy("/disk/", "/")
  82. end)
  83. if not success then
  84. showError("Failed to copy files: " .. err)
  85. end
  86. end },
  87. { message = "Unmounting installation disk...", action = function()
  88. -- Attempt to eject disks
  89. local success, err = pcall(function()
  90. disk.eject("top")
  91. disk.eject("bottom")
  92. disk.eject("left")
  93. disk.eject("right")
  94. end)
  95. if not success then
  96. showError("Failed to eject installation disk: " .. err)
  97. end
  98. end },
  99. { message = "Formatting file system...", action = function()
  100. -- Attempt to rename directories
  101. local success, err = pcall(function()
  102. shell.run("rename", "/", "/disk")
  103. end)
  104. if not success then
  105. showError("Failed to format file system: " .. err)
  106. end
  107. end },
  108. { message = "Creating boot recovery directory...", action = function()
  109. -- Attempt to create recovery directory
  110. local success, err = pcall(function()
  111. fs.copy("/disk/", "/recovery")
  112. end)
  113. if not success then
  114. showError("Failed to create boot recovery directory: " .. err)
  115. end
  116. end },
  117. { action = function()
  118. -- Attempt to run the install assistant
  119. local success, err = pcall(function()
  120. shell.run("/disk/install-assist")
  121. end)
  122. if not success then
  123. showError("Failed to run install assistant: " .. err)
  124. end
  125. end }
  126. }
  127.  
  128. -- Simulate the installation process with updates
  129. local totalSteps = #steps
  130. for i, step in ipairs(steps) do
  131. local success, err = pcall(function()
  132. drawLoadingBar(i - 1, totalSteps, step.message) -- Start at 0% progress
  133. step.action() -- Execute the installation step
  134. sleep(4) -- Increased sleep duration to slow down the process
  135. end)
  136.  
  137. if not success then
  138. showError(err)
  139. return
  140. end
  141. end
  142.  
  143. -- Final message indicating completion
  144. local _, height = getTerminalSize()
  145. term.setCursorPos(1, height - 2)
  146. term.write(string.rep(" ", term.getSize()))
  147. term.setCursorPos(math.floor((term.getSize() - #("Installation complete!")) / 2), height - 2)
  148. term.write("Installation complete!")
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement