Guest User

cpack

a guest
Jul 20th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. local filepaths = {}
  2. local data = {}
  3. function getData(a)
  4.   local b = {}
  5.   local c = a
  6.   local d
  7.   for e=1,#a do
  8.     if e == a then
  9.       error("A")
  10.     end
  11.     d = string.find(c, "\n")
  12.     if d == nil then
  13.       break
  14.     end
  15.     b[d] = string.sub(c,1,d-1)
  16.     c = string.sub(c,d+2,#c)
  17.   end
  18.   return b
  19. end
  20. function pack(filepath)
  21.   local file = fs.open(filepath, "r")
  22.   filepaths[#filepaths+1] = filepath
  23.   data[#data+1] = textutils.serialise(file.readAll())
  24.   file.close()
  25. end
  26. function export(filepath)
  27.   local file = fs.open(filepath, "w")
  28.   file.write("local filepaths = {")
  29.   for a,b in pairs(filepaths) do
  30.     file.write('"'..b..'",')
  31.   end
  32.   file.writeLine("}")
  33.   file.write("local data = {")
  34.   for a,b in pairs(data) do
  35.     local c = getData(b)
  36.     for d=1,#c-1 do
  37.       file.write(c[d])
  38.       file.write("\\n")
  39.       print(c[d])
  40.     end
  41.     file.write(c[#c])
  42.   end
  43.   file.writeLine("}")
  44.   file.writeLine("local path = shell.dir()")
  45.   for a,b in pairs(data) do
  46.     file.writeLine("local file = fs.open(path..filepaths["..a.."], 'w')")
  47.     file.writeLine("file.write(data["..a.."])")
  48.     file.writeLine("file.close()")
  49.   end
  50.   file.close()
  51. end
  52. local t = {...}
  53. if #t<2 then
  54.   print("Usage: czip <save path> <file1> <file2> ...")
  55.   error()
  56. end
  57. for a=2,#t do
  58.   pack(t[a])
  59. end
  60. export(t[1])
Advertisement
Add Comment
Please, Sign In to add comment