Sirshark10

depman

Jul 28th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local args = {...}
  2. local files = {}
  3. local function pUsage()
  4. error("Usage: depman pack <dir> <output file> || depman unpack <depman output file> <optional -o (forces overwrites)>")
  5. end
  6. if not args[1] then
  7. pUsage()
  8. elseif not args[2] then
  9. pUsage()
  10. end
  11. if args[1] == "pack" then
  12.   if fs.isDir(args[2]) then
  13.     for k,v in pairs(fs.list(args[2])) do
  14.       files[v] = fs.open(args[2].."/"..v,"r").readAll()
  15.     end
  16.     if not args[3] then
  17.     pUsage()
  18.     end
  19.     local output = fs.open(args[3],"w")
  20.     output.write(textutils.serialise(files))
  21.     output.flush()
  22.     output.close()
  23.   end
  24. elseif args[1] == "unpack" then
  25.   if fs.exists(args[2]) then
  26.     local a = fs.open(args[2],"r")
  27.     local R = textutils.unserialise(a.readAll())
  28.     a.close()
  29.     for k,v in pairs(R) do
  30.       if args[3] == "-o" or not fs.exists(k) then
  31.           if fs.exists(k) then
  32.             fs.delete(k)
  33.           end
  34.           output = fs.open(k,"w")
  35.           output.write(v)
  36.           output.flush()
  37.           output.close()
  38.       elseif fs.exists(k) and args[3] ~= "-o" then
  39.       error("File already exists | Run with '-o' to force overwrite")  
  40.       end
  41.     end
  42.     fs.delete(args[2])
  43.   end
  44. else
  45. pUsage()
  46. end
Add Comment
Please, Sign In to add comment