Skip to content

Commit 2f0bbfc

Browse files
committed
tools/unpack.py: Output the files from pbpack in the right order and into a directory
Signed-off-by: Stasia Michalska <hel@lcp.world>
1 parent 113a92a commit 2f0bbfc

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/unpack.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import sys
1717
import argparse
18+
import pathlib
1819

1920
from pbpack import ResourcePack
2021

@@ -23,16 +24,19 @@ def main():
2324
'Unpack pbpacked data to recover original file content.')
2425

2526
parser.add_argument('pbpack', type=str, help='app_resources.pbpack file to unpack')
27+
parser.add_argument('--output', default='.', help='the directory to output the files to')
2628
parser.add_argument('--app', default=False, action='store_true',
2729
help='Indicate this pbpack is an app pbpack')
28-
30+
2931
args = parser.parse_args()
3032

3133
if os.path.exists(args.pbpack):
32-
resource_pack = ResourcePack().deserialize(open(args.pbpack,'rb'), is_system=not args.app)
33-
for idx, resource_data in enumerate(resource_pack.contents):
34-
with open(str(idx) + '.dat','wb') as outfile:
35-
outfile.write(resource_data)
34+
pathlib.Path(args.output).mkdir(parents=True, exist_ok=True)
35+
36+
resource_pack = ResourcePack.deserialize(open(args.pbpack,'rb'), is_system=not args.app)
37+
for idx, resource_data in enumerate(resource_pack.table_entries):
38+
with open(os.path.join(args.output, str(idx) + '.dat'),'wb') as outfile:
39+
outfile.write(resource_pack.contents[resource_data.content_index])
3640

3741

3842
if __name__ == '__main__':

0 commit comments

Comments
 (0)