Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Coded by HPWebcamAble--
- os.loadAPI("button")
- local but = button
- --[[
- This is a pretty advanced program. I don't recommend
- using it if you aren't sure how it works!
- ]]
- --Test for problems--
- but.clear(true)
- if not term.isColor() then
- print("This program requires an advanced computer")
- return
- end
- if not http then
- print("The HTTP API is not enabled")
- return
- end
- --variables--
- local vers = 1.1
- local off = colors.red
- local on = colors.lime
- local inac = colors.gray
- local w,h = term.getSize()
- local drives = false
- local saveMode = "None"
- local doWarn1 = false
- local addDir = false
- local dirName = nil
- local programs = {}
- --functions--
- function printCentered(text,ypos)
- term.setCursorPos(w/2-#text/2,ypos)
- term.write(text)
- end
- function drawMain()
- term.setBackgroundColor(colors.white)
- but.clear(true)
- term.setBackgroundColor(colors.orange)
- for i = 1, w do
- term.write(" ")
- end
- printCentered("Advanced Installer Creator",1)
- end
- function drawSaveOption()
- drawMain()
- term.setBackgroundColor(colors.white)
- printCentered("Choose a save location:",6)
- if doWarn1 then
- printCentered("No drive attached!",15)
- end
- drives = false
- for a,b in pairs(rs.getSides()) do
- if peripheral.getType(b) == "drive" then
- drives = true
- break
- end
- end
- if drives then
- but.draw("Disk",16,10,on,off,inac,2,1,nil)
- else
- but.draw("Disk",16,10,on,off,inac,2,1,nil)
- but.setState("Disk",3)
- end
- but.draw("Rom",31,10,on,off,inac,2,1,nil)
- end
- function drawDirOption()
- drawMain()
- term.setBackgroundColor(colors.white)
- printCentered("Add a directory?",6)
- but.draw("Yes",16,10,colors.lime,colors.lime,inac,2,1,nil)
- but.draw("No",31,10,colors.red,colors.red,inac,2,1,nil)
- end
- function drawYNOption(text)
- drawMain()
- term.setBackgroundColor(colors.white)
- printCentered(text,6)
- but.draw("Yes",16,10,colors.lime,colors.lime,inac,2,1,nil)
- but.draw("No",31,10,colors.red,colors.red,inac,2,1,nil)
- end
- function addProgram()
- drawMain()
- term.setBackgroundColor(colors.white)
- printCentered("Add a program",2)
- printCentered("Program name:",6)
- printCentered("Pastebin Code:",8)
- term.setCursorPos(18,7)
- tempvar = read()
- term.setCursorPos(18,9)
- programs[tempvar] = read()
- end
- function writting()
- but.clear(true)
- drawMain()
- term.setBackgroundColor(colors.white)
- printCentered("Writing program...",7)
- end
- function findDrives()
- for a,b in pairs(rs.getSides()) do
- if peripheral.getType(b) == "drive" then
- return b
- end
- end
- return false
- end
- --program--
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setTextColor(colors.black)
- printCentered("Advanced Installer Creator",6)
- printCentered("V. "..vers,h)
- but.draw("Start",22,8,on,off,inac,1,0,nil)
- while true do
- event,par1,par2,par3 = os.pullEvent()
- if event == "mouse_click" then
- if but.checkCords(par2,par3) == "Start" then
- break
- end
- end
- end
- local button = nil
- while true do
- drawSaveOption()
- event,par1,par2,par3 = os.pullEvent()
- if event == "peripheral" then
- doWarn1 = false
- elseif event == "mouse_click" then
- button = but.checkCords(par2,par3)
- if button == "Disk" and drives == false then
- doWarn1 = true
- elseif button == "Disk" and drives then
- saveMode = "Disk"
- break
- elseif button == "Rom" then
- saveMode = "Rom"
- break
- end
- end
- end
- while true do
- drawYNOption("Add a directory?")
- event,par1,par2,par3 = os.pullEvent()
- if event == "mouse_click" then
- button = but.checkCords(par2,par3)
- if button == "Yes" then
- addDir = true
- break
- elseif button == "No" then
- break
- end
- end
- end
- drawMain()
- term.setBackgroundColor(colors.white)
- if addDir then
- printCentered("Directory Name:",6)
- term.setCursorPos(18,7)
- dirName = read()
- end
- addProgram()
- while true do
- drawYNOption("Add another program?")
- event,par1,par2,par3 = os.pullEvent()
- if event == "mouse_click" then
- button = but.checkCords(par2,par3)
- if button == "Yes" then
- addProgram()
- elseif button == "No" then
- break
- end
- end
- end
- writting()
- if saveMode == "Disk" then
- drives = findDrives()
- if not drives then
- while true do
- drawMain()
- term.setBackgroundColor(colors.white)
- printCentered("No drives attached!",7)
- printCentered("Please add one",8)
- event,par1 = os.pullEvent("peripheral")
- if peripheral.getType(par1) == "drive" then
- break
- end
- end
- end
- drives = findDrives()
- if not disk.isPresent(drives) then
- while true do
- drawMain()
- term.setBackgroundColor(colors.white)
- printCentered("No disk in drive on "..drives.." side",7)
- printCentered("Please put one in and press any key",8)
- os.pullEvent("char")
- if disk.isPresent(drives) then
- break
- end
- end
- end
- but.clear()
- drawMain()
- term.setBackgroundColor(colors.white)
- printCentered("Enter a disk name:",7)
- term.setCursorPos(18,8)
- disk.setLabel(drives,read())
- writting()
- f = fs.open("/disk/installer","w")
- f.write([[
- --Made with Advanced Installer Creater--
- print("Ready to install")
- print("Press any key to continue...")
- os.pullEvent("key")
- --This is a function is part of Pastebin! I didn't write this--
- --Well, I rewrote it to be used inside of a program rather than as a program itself--
- function get(sCode,sFile)
- local sPath = shell.resolve( sFile )
- if fs.exists( sPath ) then
- return false
- end
- local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode ))
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( sPath, "w" )
- file.write( sResponse )
- file.close()
- return true
- else
- return false
- end
- end
- if not http then
- error("Http API not enabled")
- end
- print("Downloading...")]])
- if dirName then
- path = "/"..dirName.."/"
- for a,b in pairs(programs) do
- f.write([[
- fs.makeDir("]]..dirName..[[")
- if fs.exists("]]..path..a..[[") then
- print("File conflict! Deleting...")
- shell.run("delete ]]..path..a..[[")
- print("Fixed. Retrying...")
- end
- if get("]]..b..[[","]]..path..a..[[") then
- print("Successfully downloaded ]]..a..[[")
- else
- print("Something went wrong while downloading ]]..a..[[")
- return
- end
- ]])
- end
- else
- for a,b in pairs(programs) do
- f.write([[
- if fs.exits("]]..a..[[") then
- print("File conflict! Deleting...")
- shell.run("delete ]]..a..[[")
- print("Fixed. Retrying...")
- end
- if get("]]..b..[[","]]..a..[[") then
- print("Succesfully downloaded ]]..a..[[")
- else
- print("Something went wrong while downloading ]]..a..[[")
- return
- end
- ]])
- end
- end
- f.write([[
- print("Done!")
- ]])
- f.close()
- elseif saveMode == "Rom" then
- f = fs.open("installer","w")
- f.write([[
- --Made with Advanced Installer Creater--
- print("Ready to install")
- print("Press any key to continue...")
- os.pullEvent("key")
- --This is a function is part of Pastebin! I didn't write this--
- --Well, I rewrote it to be used inside of a program rather than as a program itself--
- function get(sCode,sFile)
- local sPath = shell.resolve( sFile )
- if fs.exists( sPath ) then
- return false
- end
- local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode ))
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( sPath, "w" )
- file.write( sResponse )
- file.close()
- return true
- else
- return false
- end
- end
- if not http then
- error("Http API not enabled")
- end
- print("Downloading...")]])
- if dirName then
- path = "/"..dirName.."/"
- for a,b in pairs(programs) do
- f.write([[
- fs.makeDir("]]..dirName..[[")
- if fs.exists("]]..path..a..[[") then
- print("File conflict! Deleting...")
- shell.run("delete ]]..path..a..[[")
- print("Fixed. Retrying...")
- end
- if get("]]..b..[[","]]..path..a..[[") then
- print("Successfully downloaded ]]..a..[[")
- else
- print("Something went wrong while downloading ]]..a..[[")
- return
- end
- ]])
- end
- else
- for a,b in pairs(programs) do
- f.write([[
- if fs.exits("]]..a..[[") then
- print("File conflict! Deleting...")
- shell.run("delete ]]..a..[[")
- print("Fixed. Retrying...")
- end
- if get("]]..b..[[","]]..a..[[") then
- print("Succesfully downloaded ]]..a..[[")
- else
- print("Something went wrong while downloading ]]..a..[[")
- return
- end
- ]])
- end
- end
- f.write([[
- print("Done!")
- ]])
- f.close()
- end
- printCentered("Program Created!",8)
- printCentered("Thank you for using",9)
- printCentered("Advanced Installer Creator",10)
- printCentered("Press any key...",h)
- os.pullEvent("char")
- term.setBackgroundColor(colors.black)
- shell.run("clear")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement