Skip to content

Commit

Permalink
vromfs_unpacker: fixed bug with file path
Browse files Browse the repository at this point in the history
deps: zstandard upadated 0.13 to 0.14
  • Loading branch information
klensy committed Aug 11, 2020
1 parent d92d241 commit 41e9681
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
construct==2.9.38

# for unpacking
zstandard==0.13 --install-option="--legacy"
zstandard==0.14 --install-option="--legacy"
# git+https://github.com/indygreg/python-zstandard.git@0.10.2 --install-option="--legacy"
pylzma==0.5.0

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

setup(
name="wt_tools",
version="0.2.2.7-dev",
version="0.2.2.8-dev",
author='klensy',
description="War Thunder resource extraction tools",
url="https://github.com/klensy/wt-tools",
Expand Down
2 changes: 1 addition & 1 deletion src/wt_tools/dxp_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def main():
total_files = struct.unpack_from('H', data, 0x8)[0]
print("total files:", total_files)
cur_p = file_names_block_offset

# TODO: fix path, like in vromfs_unpacker with abs path
file_names = []
for i in range(total_files):
old_cur_p = cur_p
Expand Down
8 changes: 4 additions & 4 deletions src/wt_tools/formats/vromfs_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ def _decode(self, obj, context, path):

vromfs_zstd_packed_body = Struct(
Embedded(zstd_stream),
"data"/ RestreamData(this.decompressed_data, not_packed_stream),
"data" / RestreamData(this.decompressed_data, not_packed_stream),
)

vromfs_zlib_packed_body = Struct(
Embedded(zlib_stream),
"data"/ RestreamData(this.decompressed_body, not_packed_stream),
"data" / RestreamData(this.decompressed_body, not_packed_stream),
)

vromfs_header = Struct(
Expand All @@ -148,7 +148,7 @@ def _decode(self, obj, context, path):
"vromfs_type" / vromfs_type,
"vromfs_packed_type" / Computed(lambda ctx: "zstd_packed" if ctx.vromfs_type == "zstd_packed" else
("not_packed" if ctx.vromfs_type == "maybe_packed" and ctx.packed_size == 0 else
("zlib_packed" if ctx.vromfs_type == "maybe_packed" and ctx.packed_size > 0 else "hoo")))
("zlib_packed" if ctx.vromfs_type == "maybe_packed" and ctx.packed_size > 0 else "hoo"))),
)

vromfs_body = Struct(
Expand All @@ -169,5 +169,5 @@ def _decode(self, obj, context, path):
vromfs_ext_header),
"body" / vromfs_body,
# "tail" / Bytes(272)
"tail" / GreedyBytes
"tail" / GreedyBytes,
)
2 changes: 2 additions & 0 deletions src/wt_tools/vromfs_unpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def unpack(filename: os.PathLike, dist_dir: os.PathLike, file_list_path: Optiona
with click.progressbar(range(parsed.body.data.data.files_count), label="Unpacking files") as bar:
for i in bar:
vromfs_internal_file_path = parsed.body.data.data.filename_table.filenames[i]
# clean leading slashes, there was a bug in 1.99.1.70 with "/version" file path
vromfs_internal_file_path = vromfs_internal_file_path.lstrip('/\\')
if file_list_path:
if os.path.normcase(vromfs_internal_file_path) in file_list:
unpacked_filename = os.path.join(dist_dir, vromfs_internal_file_path)
Expand Down

0 comments on commit 41e9681

Please sign in to comment.