Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local files = {}
- local function pUsage()
- error("Usage: depman pack <dir> <output file> || depman unpack <depman output file> <optional -o (forces overwrites)>")
- end
- if not args[1] then
- pUsage()
- elseif not args[2] then
- pUsage()
- end
- if args[1] == "pack" then
- if fs.isDir(args[2]) then
- for k,v in pairs(fs.list(args[2])) do
- files[v] = fs.open(args[2].."/"..v,"r").readAll()
- end
- if not args[3] then
- pUsage()
- end
- local output = fs.open(args[3],"w")
- output.write(textutils.serialise(files))
- output.flush()
- output.close()
- end
- elseif args[1] == "unpack" then
- if fs.exists(args[2]) then
- local a = fs.open(args[2],"r")
- local R = textutils.unserialise(a.readAll())
- a.close()
- for k,v in pairs(R) do
- if args[3] == "-o" or not fs.exists(k) then
- if fs.exists(k) then
- fs.delete(k)
- end
- output = fs.open(k,"w")
- output.write(v)
- output.flush()
- output.close()
- elseif fs.exists(k) and args[3] ~= "-o" then
- error("File already exists | Run with '-o' to force overwrite")
- end
- end
- fs.delete(args[2])
- end
- else
- pUsage()
- end
Add Comment
Please, Sign In to add comment