Posted 30 May 2018 - 02:12 PM
So, right now I have this code:
When I go install an OS, it installs fine, but even though I used setPath, it copies the files into the root directory.
Is there any way around this?
local nOption = 1
function drawMenu()
term.clear()
term.setCursorPos(1, 1)
paintutils.drawFilledBox(0, 0, 51, 19, colors.cyan)
term.setCursorPos(1, 1)
term.setBackgroundColor(colors.blue)
term.setTextColor(colors.white)
for i=1, 51 do
term.write(" ")
end
printCentered("BIOS SETUP UTILITY")
print("")
term.setCursorPos(3, 3)
term.setBackgroundColor(colors.cyan)
printStayX(nOption == 1 and "[ Set Default OS ]" or "Set Default OS")
printStayX("")
printStayX(nOption == 2 and "[ Install Pastebin OS ]" or "Install Pastebin OS")
printStayX("")
printStayX(nOption == 3 and "[ Exit and Reboot ]" or "Exit and Reboot")
term.setCursorPos(30, 3)
printStayX(textutils.formatTime(os.time()))
printStayX("")
printStayX("Free Space: "..math.ceil(fs.getFreeSpace("/") / 1024).." KB")
end
drawMenu()
function pasteget(code, file)
local response = http.get("https://pastebin.com/raw/"..textutils.urlEncode(code))
if response then
local data = response.readAll()
response.close()
local hfile = fs.open(file, "w")
hfile.write(data)
hfile.close()
return true
else
return false
end
end
function pastebinMenu()
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1, 1)
print("OS name:")
local name = read()
print("OS Pastebin code:")
local code = read()
if pasteget(code, "bios/"..name.."/installer") then
print("Installer successfully downloaded, about to install...")
local oldpath = shell.path()
shell.setPath(oldpath..":bios/"..name)
shell.run("bios/"..name.."/installer")
shell.setPath(oldpath)
end
end
while true do
local event, key, _ = os.pullEvent("key")
if key == keys.up then
if nOption > 1 then
nOption = nOption - 1
drawMenu()
end
elseif key == keys.down then
if nOption < 3 then
nOption = nOption + 1
drawMenu()
end
elseif key == keys.enter then
if nOption == 3 then
sleep(1)
os.reboot()
elseif nOption == 2 then
pastebinMenu()
end
end
end
When I go install an OS, it installs fine, but even though I used setPath, it copies the files into the root directory.
Is there any way around this?