KittenPixel

Untitled

Dec 30th, 2023 (edited)
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 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. return instData
  100. end
  101.  
  102. --Conditions
  103. if nOption == 1 then
  104. print(("Setup will create %d directories and will install %d files."):format(#getInstallationInformation("zwm").directories, #getInstallationInformation("zwm").files))
  105. write("Confirm? Y/n ")
  106. local ready = read()
  107. if string.lower(ready) == "n" then
  108. print("Installation canceled.")
  109. else
  110. print("Creating directories...")
  111. for i, v in pairs(getInstallationInformation.directories) do
  112. print(("Creating: %s"):format(v))
  113. fs.makeDir(v)
  114. end
  115. term.clear()
  116.  
  117. print("Downloading files...")
  118. for i, v in pairs(getInstallationInformation.files) do
  119. print(("Downloading: %s"):format(v))
  120. downloadFile(v)
  121. end
  122.  
  123. print("Installation complete")
  124. --[[shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Startup.lua startup.lua")
  125. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Boot.lua boot.lua")
  126. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/API/GuiScreens.lua Wrench/API/GuiScreens")
  127. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/File.lua Wrench/File.lua")
  128. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/API/BSOD.lua Wrench/API/BSOD")
  129. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/IMGS/Wrench.nfp Wrench/IMGS/Wrench.nfp")
  130. shell.run("wget https://raw.githubusercontent.com/KittenPixel-cell/Wrench-OS-Computercraft/main/Wrench/Desktop.lua Wrench/Desktop.lua")--]]
  131. end
  132.  
  133. else
  134. term.clear()
  135. print("Install Canceled Rebooting...")
  136. os.reboot()
  137. end
Advertisement
Add Comment
Please, Sign In to add comment