Advertisement
jack2838

HLPAK

Mar 26th, 2023
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. local args = {...}
  2.  
  3. local function unrip(contents)
  4.     local str = ''
  5.     for s in contents:gmatch("([^,]+)") do
  6.         str = str .. string.char(s)
  7.     end
  8.     return str
  9. end
  10.  
  11. local function unpack(filename)
  12.     if not fs.exists(filename) then return end
  13.     local file = fs.open('output.hlpk',args[2] or 'r')
  14.  
  15.     local input = {
  16.         dir = {},
  17.         file = {}
  18.     }
  19.     repeat
  20.         local str = file.readLine()
  21.         if not str then break end
  22.         if str:sub(1,1) == '@' then
  23.             table.insert(input.dir,str:sub(2))
  24.         end
  25.         if str:sub(1,1) == '$' then
  26.             --print(str)
  27.             table.insert(input.file,{
  28.                 name = str:sub(str:find("/[^/]*$")+1, str:find('{')-1),
  29.                 path = str:sub(2,(str:find("/[^/]*$")-1))..'/',
  30.                 contents = str:sub(str:find('{')+1,str:find('}')-1)
  31.             })
  32.         end
  33.     until (false)
  34.     file.close()
  35.     for k,v in pairs(input.dir) do
  36.         fs.makeDir(v)
  37.     end
  38.     for k,v in pairs(input.file) do
  39.         local str = unrip(v.contents)
  40.         local file = fs.open(v.path..'/'..v.name,'w')
  41.         file.write(str)
  42.         file.close()
  43.     end
  44. end
  45.  
  46. local function rip(str)
  47.     local acc = ''
  48.     for s in str:gmatch('.') do
  49.         acc = acc .. (acc ~= '' and ',' or '') .. string.byte(s)
  50.     end
  51.     return acc
  52. end
  53.  
  54.  
  55. local function compress(path,n)
  56.     n = n or 0
  57.     local output = fs.open(args[3] or 'output.hlpk','a')
  58.     print(output)
  59.     if not fs.isDir(path) then return end
  60.     if path:sub(-1) ~= '/' then
  61.         path = path .. '/'
  62.     end
  63.     for k,v in pairs(fs.list(path)) do
  64.         if fs.isDir(path..v) then
  65.             output.writeLine('@'..path..v..'')
  66.             output.flush()
  67.             compress(path..v..'/',n + 1)
  68.         elseif fs.exists(path..v) then
  69.             local file = fs.open(path..v,'r')
  70.             output.write('$'..path..v..'{')
  71.             output.write(rip(file.readAll()))
  72.             output.writeLine('}')
  73.             file.close()
  74.         end
  75.     end
  76.     output.close()
  77. end
  78.  
  79. if args[1] == 'pk' then
  80.     local dir = args[2]
  81.     fs.open(args[3] or 'output.hlpk','w').close()
  82.     compress(dir)
  83. elseif args[1] == 'up' then
  84.     unpack(args[3] or 'output.hlpk')
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement