KittenPixel

Untitled

Dec 30th, 2023 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w,h = term.getSize()
  4.  
  5. function printCentered( y,s )
  6. local x = math.floor((w - string.len(s)) / 2)
  7. term.setCursorPos(x,y)
  8. term.clearLine()
  9. term.write( s )
  10. end
  11.  
  12. local nOption = 1
  13.  
  14. local function getFile(name)
  15. local file, second = http.get(rootPath .. name .. "?" .. os.epoch('utc'))
  16. local content
  17. if file then
  18. content = file.readAll()
  19. end
  20. return content, second
  21. end
  22.  
  23. local function downloadFile(name)
  24. local content = getFile(name)
  25. local file = fs.open(name, "w")
  26. file.write(content)
  27. file.close()
  28. return true
  29. end
  30.  
  31. local function drawMenu()
  32. term.clear()
  33. term.setCursorPos(1,1)
  34. term.write("Wrench OS Install Menu // ")
  35. term.setCursorPos(1,2)
  36.  
  37. term.setCursorPos(w-11,1)
  38. if nOption == 1 then
  39. term.write("Install")
  40. elseif nOption == 2 then
  41. term.write("Cancel")
  42. end
  43.  
  44. end
  45.  
  46. --GUI
  47. term.clear()
  48. local function drawFrontend()
  49. printCentered( math.floor(h/2) - 3, "")
  50. printCentered( math.floor(h/2) - 2, "Install Menu" )
  51. printCentered( math.floor(h/2) - 1, "")
  52. printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ Install ]") or "Install" )
  53. printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Cancel ]") or "Cancel" )
  54. printCentered( math.floor(h/2) + 4, "")
  55. end
  56.  
  57. --Display
  58. drawMenu()
  59. drawFrontend()
  60.  
  61. while true do
  62. local e,p = os.pullEvent()
  63. if e == "key" then
  64. local key = p
  65. if key == 17 or key == 200 then
  66.  
  67. if nOption > 1 then
  68. nOption = nOption - 1
  69. drawMenu()
  70. drawFrontend()
  71. end
  72. elseif key == 31 or key == 208 then
  73. if nOption < 4 then
  74. nOption = nOption + 1
  75. drawMenu()
  76. drawFrontend()
  77. end
  78. elseif key == 28 then
  79. --End should not be here!!
  80. break
  81. end --End should be here!!
  82. end
  83. end
  84. term.clear()
  85.  
  86. local function getInstallationInformation(tag)
  87. rootPath = "https://raw.githubusercontent.com/znepb-cc/zwm/" .. tag or "master"
  88. print("Fetching installation information...")
  89. local inst, err = getFile("/inst/installation.lua")
  90. if not inst then
  91. printError(("Could not fetch installation information for branch %s."):format(tag))
  92. return
  93. else
  94. instData = textutils.unserialize(inst)
  95. end
  96. if not instData then
  97. error("Error parsing installing information")
  98. end
  99. print(instData.files)
  100. return instData
  101. end
  102.  
  103. --Conditions
  104. if nOption == 1 then
  105. print(getInstallationInformation("zwm"))
  106. print(("Setup will create %d directories and will install %d files."):format(#getInstallationInformation("zwm").directories, #getInstallationInformation("zwm").files))
  107. write("Confirm? Y/n ")
  108. local ready = read()
  109. if string.lower(ready) == "n" then
  110. print("Installation canceled.")
  111. else
  112. print("Creating directories...")
  113. for i, v in pairs(inst.directories) do
  114. print(("Creating: %s"):format(v))
  115. fs.makeDir(v)
  116. end
  117. term.clear()
  118. --[[hell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Startup.lua startup.lua")
  119. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Boot.lua boot.lua")
  120. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/API/GuiScreens.lua Wrench/API/GuiScreens")
  121. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/File.lua Wrench/File.lua")
  122. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/API/BSOD.lua Wrench/API/BSOD")
  123. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/IMGS/Wrench.nfp Wrench/IMGS/Wrench.nfp")
  124. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/Desktop.lua Wrench/Desktop.lua")--]]
  125. end
  126.  
  127. else
  128. term.clear()
  129. print("Install Canceled Rebooting...")
  130. os.reboot()
  131. end
Advertisement
Add Comment
Please, Sign In to add comment