Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Builder
- by Creator
- ]]--
- local ignore = {}
- local function parse(data)
- for token in string.gmatch(data,"[^\n]+") do
- ignore[#ignore+1] = token
- end
- end
- local args = {...}
- if args[3] and args[3]:sub(1,1) == "$" then
- parse(args[3]:sub(2,-1))
- elseif args[3] then
- local file = fs.open(args[3],"r")
- local data = file.readAll()
- file.close()
- parse(data)
- end
- local filesystem = {}
- local function readFile(path)
- local file = fs.open(path,"r")
- local variable = file.readAll()
- file.close()
- return variable
- end
- local function isNotBanned(path)
- for i,v in pairs(ignore) do
- if v == path then
- return false
- end
- end
- return true
- end
- local function explore(dir)
- local buffer = {}
- local sBuffer = fs.list(dir)
- for i,v in pairs(sBuffer) do
- sleep(0.05)
- if isNotBanned(dir.."/"..v) then
- if fs.isDir(dir.."/"..v) then
- if v ~= ".git" then
- print("Compressing directory: "..dir.."/"..v)
- buffer[v] = explore(dir.."/"..v)
- end
- else
- print("Compressing file: "..dir.."/"..v)
- buffer[v] = readFile(dir.."/"..v)
- end
- else
- print(dir.."/"..v)
- end
- end
- return buffer
- end
- append = [[
- local archpath = ...
- local args = {unpack({...}, 2)}
- if not type(archpath) == "string" then
- error("Please provide a path.")
- end
- archpath = fs.combine("/", archpath)
- local len = #archpath
- local nfs = {}
- local oldfs = {}
- for i,v in pairs(_G.fs) do
- oldfs[i] = v
- end
- local function getFirstElement(path)
- if not type(path) == "string" then error("This is not a string: "..tostring(path),2) end
- return string.sub(path,1,string.find(path,"/") and string.find(path,"/")-1 or -1)
- end
- local function getRest(path)
- if not type(path) == "string" then error("This is not a string: "..tostring(path),2) end
- return string.sub(path, string.find(path, "/") and string.find(path, "/") +1 or 1, -1)
- end
- local function getElement(path, tbl)
- if path == "/" or path == "" then
- return tbl
- end
- if not tbl then
- print(tbl)
- error("Error, bruh: "..path, 2)
- end
- local first = getFirstElement(path)
- if tbl[first] then
- if first == path then
- return tbl[first]
- else
- return getElement(getRest(path), tbl[first])
- end
- else
- return false
- end
- end
- local function isInPackage(path)
- local first = path:sub(1, len)
- return first == archpath
- end
- local function removePackagePath(path)
- return path:sub(len+2,-1)
- end
- local function writeFile(path, content)
- local file = fs.open(path,"w")
- file.write(content)
- file.close()
- end
- function writeDown(input, dir)
- for i,v in pairs(input) do
- if type(v) == "table" then
- writeDown(v, dir.."/"..i)
- elseif type(v) == "string" then
- writeFile(dir.."/"..i, v)
- end
- end
- end
- local function generateFileHandle(data)
- local data = data
- local self = {}
- function self.readAll()
- return data
- end
- local lineNum = 1
- local lines = {}
- for token in data:gmatch("[^\n]+") do
- lines[lineNum] = token
- lineNum = lineNum + 1
- end
- lineNum = 0
- function self.readLine()
- lineNum = lineNum + 1
- return lines[lineNum]
- end
- function self.close()
- self.readLine = nil
- self.readAll = nil
- self["close"] = nil
- self = nil
- end
- return self
- end
- nfs.open = function(path, mode)
- path = fs.combine("/",path)
- if isInPackage(path) then
- local file = getElement(removePackagePath(path), inputTable)
- if type(file) == "string" then
- if mode == "r" then
- return generateFileHandle(file)
- else
- return false, "Cannot write to executable."
- end
- else
- return false, "Cannot open folder."
- end
- else
- return oldfs.open(path, mode)
- end
- end
- nfs.getName = oldfs.getName
- nfs.combine = oldfs.combine
- nfs.isReadOnly = oldfs.isReadOnly
- nfs.move = function(path, dest)
- if isInPackage(dest) or isInPackage(path) then
- return false
- end
- return oldfs.move(path, dest)
- end
- nfs.copy = function(path, dest)
- path = fs.combine("/",path)
- dest = fs.combine("/",dest)
- if isInPackage(dest) then
- return false
- end
- if isInPackage(path) then
- local element = getElement(removePackagePath(path), inputTable)
- if type(element) == "table" then
- writeDown(element, dest)
- return true
- elseif type(element) == "string" then
- writeFile(dest, element)
- return true
- end
- return false, "Element is not directory nor file."
- else
- return oldfs.copy(path, dest)
- end
- end
- nfs.delete = function(path)
- path = fs.combine("/",path)
- if isInPackage(path) then
- return false, "Cannot delete files in executable."
- else
- return oldfs.delete(path)
- end
- end
- nfs.isDir = function(path)
- path = fs.combine("/",path)
- if isInPackage(path) then
- if path == archpath then
- return true
- end
- return type(getElement(removePackagePath(path), inputTable)) == "table" and true or false
- else
- return oldfs.isDir(path)
- end
- end
- nfs.getFreeSpace = oldfs.getFreeSpace
- nfs.complete = oldfs.complete
- nfs.getDrive = oldfs.getDrive
- nfs.getSize = function(path)
- path = fs.combine("/",path)
- if isInPackage(path) then
- local element = getElement(removePackagePath(path), inputTable)
- return type(element) == "string" and #element or 0
- else
- return oldfs.getSize(path)
- end
- end
- nfs.list = function(path)
- path = fs.combine("/",path)
- if not nfs.isDir(path) then
- return false, "Can't list file."
- end
- if isInPackage(path) then
- local element = getElement(removePackagePath(path), inputTable)
- if type(element) == "table" then
- local ret = {}
- for i,v in pairs(element) do
- ret[#ret+1] = i
- end
- return ret
- else
- return false, "Cannot list anything else than directories."
- end
- else
- return oldfs.list(path)
- end
- end
- nfs.exists = function(path)
- path = fs.combine("/",path)
- if isInPackage(path) then
- return getElement(removePackagePath(path), inputTable) and true or false
- else
- return oldfs.exists(path)
- end
- end
- nfs.makeDir = function(path)
- path = fs.combine("/",path)
- if isInPackage(path) then
- return false, "Cannot make directory in executable."
- else
- return oldfs.makeDir(path)
- end
- end
- nfs.find = function(path)
- path = fs.combine("/",path)
- if isInPackage(path) then
- return false, "Cannot search executable."
- else
- return oldfs.find(path)
- end
- end
- nfs.getDir = oldfs.getDir
- local env = {}
- --_G.fs = nfs
- for i,v in pairs(_G) do
- env[i] = v
- end
- for i,v in pairs(nfs) do
- _G.fs[i] = v
- end
- local function readFile(path)
- local file = fs.open(path,"r")
- local variable = file.readAll()
- file.close()
- return variable
- end
- local dofile = function(path,...)
- local data = readFile(path)
- local f, err = loadstring(data)
- if not f then
- print(err)
- end
- setfenv(f, env)
- return f(...)
- end
- function env.getfenv(arg)
- local e = getfenv(type(arg) == "number" and arg + 1 or arg)
- if e == _G then
- return env
- else
- return e
- end
- end
- local init = getElement("init.lua", inputTable)
- if init then
- if type(init) == "string" then
- dofile(archpath.."/init.lua", unpack(args))
- else
- error("init.lua is a directory.")
- end
- else
- error("No init file.")
- end
- ]]
- local filesystem = explore(args[1])
- local file = fs.open(args[2],"w")
- file.write("local inputTable = "..textutils.serialize(filesystem).."\n\n\n\n\n\n\n\n\n"..append)
- file.close()
- --[[Code]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement