neptune12100

Pack v0.2

Nov 10th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. version = "v0.2"
  2.  
  3. function usage()
  4.     print([[
  5.     Usage: pack LIST_FILE ARCHIVE [TITLE]
  6.     The file LIST_FILE is just a list
  7.     the names of the files to be archived
  8.     one per line.
  9.     TITLE is displayed by the unpacker, if given.
  10.     That's it.]])
  11.     os.exit()
  12. end
  13.  
  14. banner = string.format([[
  15. Pack %s by neptune12100
  16. This is FREE SOFWARE released under the GNU GPL
  17. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. ]],version)
  19.  
  20. obanner = string.format([[
  21. Unpacker %s by neptune12100
  22. This is FREE SOFTWARE released under the GNU GPL
  23. ]],version)
  24.  
  25. print(banner)
  26.  
  27. if #arg ~= 3 and #arg ~= 2 then
  28.     usage()
  29. end
  30.  
  31. title = arg[3] -- even if it's nil!
  32.  
  33. files = {}
  34.  
  35. print(string.format("Packing to %q",arg[2]))
  36.  
  37. ls = io.open(arg[1],"rb")
  38.  
  39. for f in ls:lines() do
  40.     local infile,err = io.open(f,"rb")
  41.     if err then print(err)
  42.     else
  43.         files[f] = infile:read("*a")
  44.         print(string.format("Packed %q",f))
  45.         infile:close()
  46.     end
  47. end
  48.  
  49. ls:close()
  50.  
  51. outfile = io.open(arg[2],"wb")
  52.  
  53. sfiles = {}
  54.  
  55. for f,c in pairs(files) do
  56.     local s = string.format([[ [ %q ] = %q ]],f,c)
  57.     table.insert(sfiles,s)
  58. end
  59.  
  60. out = string.format([[
  61. print("Installing %s")
  62. ]],title) ..
  63. string.format([[
  64. print(%q)
  65. ]],obanner) ..
  66. [[
  67.  
  68. files = {
  69.  
  70. ]] .. table.concat(sfiles," , ") ..
  71. [[
  72.  
  73. }
  74.  
  75. for f,c in pairs(files) do
  76.     print(string.format("Creating %q",f))
  77.     local ofile,err = io.open(f,"wb")
  78.     if err then
  79.         print(err)
  80.     else
  81.         ofile:write(c)
  82.         ofile:close()
  83.     end
  84. end
  85.  
  86. os.remove(arg[0])
  87. ]]
  88.  
  89. outfile:write(out)
  90. outfile:close()
Advertisement
Add Comment
Please, Sign In to add comment