Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function displayHelp()
- print("Basic packager by Eldidi")
- print(" red -d <source> <dest>")
- print(" red -c <dest> <file1>, [file2]...")
- end
- function compress(files, dest)
- if type(files) ~= "table" then
- error("table expected, somehow got " .. type(files))
- end
- if type(dest) ~= "string" then
- error("string expected, somehow got " .. type(dest))
- end
- fileList = files
- fileTable = {}
- for a = 1, #fileList do
- file = fs.open(fileList[a], "r")
- contents = file.readAll()
- table.insert(fileTable, {fileList[a], contents})
- file.close()
- end
- file = fs.open(dest, "w")
- file.write(fileTable)
- file.close()
- end
- function decompress(source, dest)
- if type(source) ~= "string" then
- error("string expected, got " .. type(source))
- end
- if type(dest) ~= "string" then
- error("string expected, got " .. type(dest))
- end
- if not fs.exists(source) then
- error(source .. " does not exist")
- end
- if fs.exists(dest) then
- print("overwrite " .. dest .. "? (Y/N)")
- ans = tostring(read())
- if string.lower(ans) == "n" then
- error("overwrite declined")
- end
- end
- file = fs.open(source, "r")
- contents = file.readAll()
- file.close()
- tabContents = textutils.unserialize(contents)
- for a = 1, #tabContents do
- fileContents = tabContents[a]
- fileName = fileContents[1]
- table.delete(1, fileContents)
- file = fs.open(fileName, "w")
- file.writeLine(textutils.serialize(fileContents))
- file.close()
- end
- end
- tArg = {...}
- if #tArg < 2 then
- displayHelp()
- return
- end
- if tArg[1] == "-d" then
- decompress(tArg[2], tArg[3])
- return
- elseif tArg[1] == "-c" then
- arguments = {}
- for a = 3, #tArg do
- table.insert(arguments, tArg[a])
- end
- compress(arguments, tArg[2])
- return
- else
- displayHelp()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement