1515import os
1616import sys
1717import argparse
18+ import pathlib
1819
1920from 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
3842if __name__ == '__main__' :
0 commit comments