Advertisement
DOGGYWOOF

Untitled

Aug 7th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. -- Function to check if a file exists
  2. local function fileExists(path)
  3. local file = fs.open(path, "r")
  4. if file then
  5. file.close()
  6. return true
  7. else
  8. return false
  9. end
  10. end
  11.  
  12. -- Function to clear the screen
  13. local function clearScreen()
  14. term.clear()
  15. term.setCursorPos(1, 1)
  16. end
  17.  
  18. -- Function to display a styled message
  19. local function displayMessage(message)
  20. clearScreen()
  21. term.setTextColor(colors.lightGray)
  22. term.setBackgroundColor(colors.black)
  23. term.setCursorPos(1, 1)
  24. print("Doggy OS Developer System Bootloader")
  25. print("===================================")
  26. print()
  27. term.setTextColor(colors.red)
  28. print("WARNING: UNSTABLE DEVELOPER BUILD")
  29. term.setTextColor(colors.white)
  30. print("This bootloader is intended for modifying and testing Doggy OS.")
  31. print()
  32. print(message)
  33. print()
  34. end
  35.  
  36. -- Function to display the GUI
  37. local function displayGUI(message, options)
  38. displayMessage(message)
  39.  
  40. term.setTextColor(colors.cyan)
  41. term.setBackgroundColor(colors.black)
  42. term.setCursorPos(1, 8)
  43. print("Select an option:")
  44. term.setTextColor(colors.yellow)
  45.  
  46. local maxOptionWidth = 0
  47. for _, option in ipairs(options) do
  48. local optionText = string.format(" %d. %s", _, option)
  49. if #optionText > maxOptionWidth then
  50. maxOptionWidth = #optionText
  51. end
  52. end
  53.  
  54. local baseLine = 9
  55. for i, option in ipairs(options) do
  56. local optionText = string.format(" %d. %s", i, option)
  57. term.setCursorPos(1, baseLine + i)
  58. print(optionText .. string.rep(" ", maxOptionWidth - #optionText + 2))
  59. end
  60. end
  61.  
  62. -- Function to shutdown the system
  63. local function shutdownSystem()
  64. clearScreen()
  65. displayMessage("Shutting down the system...")
  66. sleep(2) -- Simulate shutdown process
  67. os.shutdown()
  68. end
  69.  
  70. -- Function to handle user choice
  71. local function getUserChoice(numOptions)
  72. local choice
  73. repeat
  74. term.setTextColor(colors.white)
  75. term.setBackgroundColor(colors.black)
  76. term.setCursorPos(1, 11 + numOptions)
  77. print("Enter choice (1-" .. numOptions .. "): ")
  78. term.setTextColor(colors.yellow)
  79. choice = tonumber(read())
  80. until choice and choice >= 1 and choice <= numOptions
  81. return choice
  82. end
  83.  
  84. -- Main program logic
  85. local function main()
  86. local devCfgPath = "dev.cfg"
  87. local biosPath = "/disk/boot/BIOS"
  88.  
  89. -- Check if dev.cfg exists
  90. if not fileExists(devCfgPath) then
  91. displayGUI("dev.cfg not found. Please select an option below:", {"Run BIOS"})
  92. if fileExists(biosPath) then
  93. shell.run(biosPath)
  94. else
  95. displayMessage("Error: BIOS file not found.")
  96. end
  97. return
  98. end
  99.  
  100. -- The disk paths to check
  101. local startupFilePath = "startup"
  102. local startupFileFound = false
  103.  
  104. -- Check if startup file exists
  105. if fileExists(startupFilePath) or fileExists(startupFilePath .. ".lua") then
  106. startupFileFound = true
  107. end
  108.  
  109. if startupFileFound then
  110. displayGUI("Boot Device found. Select an option below:", {"Boot", "Shutdown system"})
  111. local choice = getUserChoice(2)
  112.  
  113. if choice == 1 then
  114. clearScreen()
  115. if fileExists(startupFilePath .. ".lua") then
  116. shell.run(startupFilePath .. ".lua")
  117. elseif fileExists(startupFilePath) then
  118. shell.run(startupFilePath)
  119. end
  120. elseif choice == 2 then
  121. shutdownSystem()
  122. end
  123. else
  124. displayGUI("No boot device found. Please select an option below:", {"Run BIOS"})
  125. if fileExists(biosPath) then
  126. shell.run(biosPath)
  127. else
  128. displayMessage("Error: BIOS file not found.")
  129. end
  130. end
  131. end
  132.  
  133. -- Run the main function
  134. main()
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement