kotiq / wt-tools

War Thunder resource extraction tools
29 stars 3 forks source link

vromfs_unpacker input file list argument #4

Open prandleman opened 2 years ago

prandleman commented 2 years ago

I get that these are designed for CLI/shell use build exe's, but I'm wondering if I could just pass it a python list? I kinda got the impression this was intended to be included, but when passing a list I got error

TypeError: expected str, bytes or os.PathLike object, not list


Path = Union[AnyStr, os.PathLike, list] # not sure if this needs to be here

def unpack(filename: Path, dest_dir: Path, file_list_path: Optional[Path] = None) -> Sequence[str]:
    """
    Unpack files from .vromfs.bin
    :param filename: path to .vromfs.bin file
    :param dest_dir: path to output dir
    :param file_list_path: path to file list, if you want to unpack only few files, in json list.
    :return internal names that have been written
    """

    if file_list_path:
        if isinstance(file_list_path, list):
            file_list = file_list_path
        else:
            with open(file_list_path) as f:
                try:
                    file_list = json.load(f)
                except json.JSONDecodeError as e:
                    msg = "[FAIL] Load the file list from {}: {}".format(os.path.abspath(file_list_path), e)
                    print(msg, file=sys.stderr)
                    sys.exit(1)

this works, but would one do it like this or create another optional argument? let me know your thoughts. I can submit a pull request (I need some practice) if you approve.

kotiq commented 2 years ago

OK, then the list of files to unpack will be resolved at a higher level (main). Is the following signature acceptable for your application?

Path = Union[AnyStr, os.PathLike]

def unpack(filename: Path, dest_dir: Path, file_list: Optional[Sequence[Path]] = None) -> Sequence[str]:
    ...
prandleman commented 2 years ago

I'll need some time to look into this, I don't really know anything about type hints.

One thing I just encountered though.. First time experimenting with this I diff("2.13.0.53_aces.vromfs.bin_metadata.json", "2.13.0.60_aces.vromfs.bin_metadata.json") then used vromfs_unpacker to pull out the files I needed. This worked fine because 'nm' namemap file was listed as one of the files that changed. So when proceeding to blk_unpack it worked fine.

On the other hand, when I just went to pass in a list of fm/performance files and it failed on blk_unpack because there was no namemap file that had been unpacked when the vromfs_unpacker action took place.

All I had to do was add 'nm' to the list before unpacking. Would it be wise to always append 'nm' to index(0) of the list that will be passed or am I missing something?

kotiq commented 2 years ago

In this case, the availability of the name table will depend on the way the block is packaged. If only autonomous methods of packing blocks (BBF, BBZ, FAT, FAT_ZSTD) are required, a table of names is not required for unpacking them. In War Thunder, mainly non-autonomous packaging methods are used. The end user may not know in advance about the packaging method. Then let the nm be added to the list automatically.