From 130a7b3c42360227080a45154185bfc39bd63908 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 12 Dec 2018 04:16:23 +0300 Subject: [PATCH] scripts: move makepak.py from android project repo to engine main repo, port to python3, replace spaces by tabs --- scripts/makepak.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scripts/makepak.py diff --git a/scripts/makepak.py b/scripts/makepak.py new file mode 100644 index 00000000..72e61710 --- /dev/null +++ b/scripts/makepak.py @@ -0,0 +1,46 @@ +from __future__ import print_function +import sys +import struct +import os + +#dummy class for stuffing the file headers into +class FileEntry: + pass + +#arguments are source directory, then target filename e.g. "pak1.pak" +rootdir = sys.argv[1] +pakfilename = sys.argv[2] + +pakfile = open(pakfilename,"wb") + +#write a dummy header to start with +pakfile.write(struct.Struct("<4s2l").pack(b"PACK",0,0)) + +#walk the directory recursively, add the files and record the file entries +offset = 12 +fileentries = [] +for root, subFolders, files in os.walk(rootdir): + for file in files: + entry = FileEntry() + impfilename = os.path.join(root,file) + entry.filename = os.path.relpath(impfilename,rootdir).replace("\\","/") + if(entry.filename.startswith(".git")):continue + print("pak: "+entry.filename) + with open(impfilename, "rb") as importfile: + pakfile.write(importfile.read()) + entry.offset = offset + entry.length = importfile.tell() + offset = offset + entry.length + fileentries.append(entry) +tablesize = 0 + +#after all the file data, write the list of entries +for entry in fileentries: + pakfile.write(struct.Struct("<56s").pack(entry.filename.encode("ascii"))) + pakfile.write(struct.Struct("