用于处理Valve Pak文件的库
vpk的Python项目详细描述
vpk是valve存储游戏资源的文件格式。 pythonic通过cli工具访问vpk文件及其内容。
测试并在python2.6、python2.7、python3.2+、pypy和pypy3上工作。
快速启动
vpk实例以标准方式可访问并生成文件路径
importvpkpak1=vpk.open("/d/Steam/steamapps/common/dota 2 beta/dota/pak01_dir.vpk")forfilepathinpak1:printfilepath
读取指定的文件是通过将文件路径传递给get_file()方法来完成的,该方法 返回一个VPKFile实例,它充当一个常规的file实例。写作不是 可能的。
pakfile=pak1.get_file("scripts/emoticons.txt")pakfile=pak1["scripts/emoticons.txt"]printpakfile.read().decode('utf-16le')
------------------------------------------------- "emoticons" { // An ID of zero is invalid "1" { "image_name" "wink.png" "ms_per_frame" "100" ...
保存文件同样简单。
pakfile.save("./emoticons.txt")
该模块支持创建基本的vpk。 尚不支持多存档包。
newpak=vpk.new("./some/directory")newpak.save("file.vpk")pak=newpak.save_and_open("file.vpk")
cli工具
还包括一个命令行实用程序
usage: vpk [-h] [--version] [-l] [-la] [-x OUT_LOCATION] [-nd] [-t] [-c DIR] [-p] [-f WILDCARD | -re REGEX | -name WILDCARD] file Manage Valve Pak files optional arguments: -h, --help show this help message and exit --version show program's version number and exit Main: file Input VPK file -l, --list List file paths -la List file paths, crc, size -x OUT_LOCATION, --extract OUT_LOCATION Exctract files to directory -nd, --no-directories Don't create directries during extraction -t, --test Verify contents -c DIR, --create DIR Create VPK file from directory -p, --pipe Write file contents to stdout Filters: -f WILDCARD, --filter WILDCARD Wildcard filter for file paths -re REGEX, --regex REGEX Regular expression filter for file paths -name WILDCARD Filename wildcard filter