Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local creditHandle = io.open(shell.dir().."/credits.conf", "r")
- local credits = {}
- for line in creditHandle:lines() do
- table.insert(credits, line)
- end
- creditHandle:close()
- local fileListHandle = io.open(shell.dir().."/files.conf", "r")
- local files = {}
- local filePaths = {}
- for line in fileListHandle:lines() do
- table.insert(files, line)
- end
- fileListHandle:close()
- for i,v in ipairs(files) do
- local path = shell.resolveProgram(v)
- if path then
- filePaths[i] = path
- else
- filePaths[i] = fs.combine(shell.dir(), v)
- end
- end
- local confHandle = fs.open(shell.dir().."/name.conf", "r")
- local name = confHandle.readAll()
- confHandle.close()
- local fileContents = {}
- local dirs = {}
- for i,v in ipairs(filePaths) do
- local dirStart = string.find(v, shell.dir())+string.len(shell.dir())+1
- local path = string.sub(v, dirStart)
- if fs.isDir(v) then
- dirs[path] = true
- else
- local handle = fs.open(v, "r")
- fileContents[path] = handle.readAll()
- handle.close()
- end
- end
- local installerProgram = [[
- local function unpackFiles(files, dirs, destination)
- for i,v in pairs(dirs) do
- print("Making folder: "..fs.combine(destination, i))
- fs.makeDir(fs.combine(destination, i))
- end
- for i,v in pairs(files) do
- local namestart = string.find(i, fs.getName(i))
- namestart = namestart-1
- local basePath = string.sub(i, 1, namestart)
- if not fs.exists(fs.combine(destination, basePath)) then
- fs.makeDir(fs.combine(destination, basePath))
- end
- print("Making file: "..fs.combine(destination, i))
- local handle = fs.open( fs.combine(destination, i) , "w")
- handle.write(v)
- handle.close()
- end
- end
- local function drawLine(char)
- local maxX = term.getSize()
- print(" "..string.rep(char, maxX-2))
- end
- local function printCentered(input)
- local maxX = term.getSize()
- print(string.rep(" ", math.floor((maxX - string.len(input))/2))..input)
- end
- local function printColored(...)
- for i=1, arg["n"], 2 do
- term.setTextColor(arg[i])
- write(arg[i+1])
- end
- print("")
- term.setTextColor(colors.white)
- end
- local files = ]]..textutils.serialize(fileContents)..[[
- local credits = ]]..textutils.serialize(credits)..[[
- local program = ]].."\""..name.."\""..[[
- local dirs = ]]..textutils.serialize(dirs)..[[
- term.clear()
- term.setCursorPos(1,1)
- printCentered("Installer")
- drawLine("=")
- print(" ")
- printColored(colors.white, "You are installing: ", colors.lime, program)
- term.setCursorPos(1,18)
- term.setTextColor(colors.lightBlue)
- printCentered("Press any key to continue")
- term.setTextColor(colors.white)
- os.pullEvent("char")
- term.clear()
- term.setCursorPos(1,1)
- printCentered("Installer")
- drawLine("=")
- print(" ")
- print("Credits: ")
- textutils.pagedTabulate(colors.lime, credits)
- term.setCursorPos(1,18)
- term.setTextColor(colors.lightBlue)
- printCentered("Press any key to continue")
- term.setTextColor(colors.white)
- os.pullEvent("char")
- term.clear()
- term.setCursorPos(1,1)
- printCentered("Installer")
- drawLine("=")
- print(" ")
- printColored(colors.white, "Do you want to install ", colors.lime, program, colors.white, "?")
- print(" ")
- local installOption = false
- while true do
- local x,y = term.getCursorPos()
- term.setCursorPos(1, y-1)
- term.clearLine()
- if installOption then
- printCentered("[Yes] | No")
- else
- printCentered("Yes | [No]")
- end
- local event, key = os.pullEvent("key")
- if key == 203 then
- installOption = true
- elseif key == 205 then
- installOption = false
- elseif key == 28 then
- break
- end
- end
- if installOption then
- unpackFiles(files, dirs, shell.dir())
- end
- term.clear()
- term.setCursorPos(1,1)
- ]]
- local handle = fs.open(shell.dir().."/"..args[1], "w")
- handle.write(installerProgram)
- handle.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement