KittenPixel

Untitled

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