“版本文件"有什么作用?看起来像? [英] What does a "version file" look like?

查看:45
本文介绍了“版本文件"有什么作用?看起来像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在谷歌上搜索这个,但没有结果.PyInstaller 手册说:

<前>--version-file=文件将 FILE 中的版本资源添加到 exe

听起来不错.我想将版本信息放在我的可执行文件中.问题是我不知道版本文件"是什么样的,而且我找不到一个可以使用的示例.我会考虑一个版本文件的例子作为这个问题的可接受答案.

<小时>

我的尝试

手册还说:

<块引用>

版本
仅限 Windows NT 系列.版本='myversion.txt'.用GrabVersion.py 从可执行文件中窃取版本资源,以及然后编辑输出以创建您自己的输出.(版本的语法资源太神秘了,我不会尝试从从头开始.)

我现在已经尝试使用系统中无数的可执行文件进行此操作.我只是不断收到这些错误:

回溯(最近一次调用最后一次):文件C:\pyinstaller-2.0\utils\GrabVersion.py",第 42 行,在vs = versioninfo.decode(sys.argv[1])文件C:\pyinstaller-2.0\PyInstaller\utils\versioninfo.py",第 33 行,解码nm = win32api.EnumResourceNames(h, RT_VERSION)[0]索引错误:列表索引超出范围

在没有版本信息的可执行文件上,以及:

回溯(最近一次调用最后一次):文件C:\pyinstaller-2.0\utils\GrabVersion.py",第 43 行,在打印与文件C:\pyinstaller-2.0\PyInstaller\utils\versioninfo.py",第 147 行,在 __repr__%(缩进,self.ffi.__repr__(缩进),缩进,文件C:\pyinstaller-2.0\PyInstaller\utils\versioninfo.py",第 251 行,在 __repr__"filevers=%s," % fv,类型错误:并非所有参数都在字符串格式化期间转换

其他.

解决方案

刚刚快速浏览了一下资源.似乎版本文件应该是 Python 源代码本身,因为提供的版本文件被读取然后 eval'ed.

GrabVersion.py 脚本似乎会生成您已经发现的错误,因此我将 FixedFileInfo__repr__ 函数修改为手动将元组参数转换为字符串.

Windows cmd.exe 嵌入了 Windows 版本资源,这是 GrabVersion.py 的输出,您可以将其保存到文件中并提供给 PyInstaller.

VSVersionInfo(ffi=固定文件信息(filevers=(6, 1, 7601, 17514),供应商=(6, 1, 7601, 17514),掩码=0x3f,标志=0x0,操作系统=0x40004,文件类型=0x1,子类型=0x0,日期=(0, 0)),孩子们=[字符串文件信息([字符串表(u'040904B0',[StringStruct(u'CompanyName', u'Microsoft Corporation'),StringStruct(u'FileDescription', u'Windows 命令处理器'),StringStruct(u'FileVersion', u'6.1.7601.17514 (win7sp1_rtm.101119-1850)'),StringStruct(u'InternalName', u'cmd'),StringStruct(u'LegalCopyright', u'\xa9 Microsoft Corporation.保留所有权利.'),StringStruct(u'OriginalFilename', u'Cmd.Exe'),StringStruct(u'ProductName', u'Microsoft\xae Windows\xae 操作系统'),StringStruct(u'ProductVersion', u'6.1.7601.17514')])]),VarFileInfo([VarStruct(u'Translation', [1033, 1200])])])

我还没有尝试使用 PyInstaller 设置版本资源,所以我不确定这是否可行,我会对您的反馈感兴趣.

I've been googling this for ages now without results. The PyInstaller manual says:

--version-file=FILE
    add a version resource from FILE to the exe

That sounds nice. I want to put version information in my executables. The problem is that I have no clue what a "version file" looks like and I can't find a single example of one that I can use. I would consider an example of a version file as an acceptable answer to this question.


What I've tried

The manual also says:

version
Windows NT family only. version='myversion.txt'. Use GrabVersion.py to steal a version resource from an executable, and then edit the ouput to create your own. (The syntax of version resources is so arcane that I wouldn't attempt to write one from scratch.)

I have attempted this with countless executable files from my system now. I just keep getting these errors:

Traceback (most recent call last):
  File "C:\pyinstaller-2.0\utils\GrabVersion.py", line 42, in 
    vs  = versioninfo.decode(sys.argv[1])
  File "C:\pyinstaller-2.0\PyInstaller\utils\versioninfo.py", line 33, in decode
    nm = win32api.EnumResourceNames(h, RT_VERSION)[0]
IndexError: list index out of range

on executables that has no version information, and:

Traceback (most recent call last):
  File "C:\pyinstaller-2.0\utils\GrabVersion.py", line 43, in 
    print vs
  File "C:\pyinstaller-2.0\PyInstaller\utils\versioninfo.py", line 147, in __repr__
    % (indent, self.ffi.__repr__(indent), indent,
  File "C:\pyinstaller-2.0\PyInstaller\utils\versioninfo.py", line 251, in __repr__
    "filevers=%s," % fv,
TypeError: not all arguments converted during string formatting

On the rest.

解决方案

Just had a quick look at the sources. It appears that the version file is expected to be Python source itself as the provided version file with be read and then eval'ed.

The GrabVersion.py script appears to generate errors as you've already found, so I modified the __repr__ function of FixedFileInfo to manually convert tuple arguments to strings.

The Windows cmd.exe has a Windows version resource embedded, here's the output from GrabVersion.py which you would save to a file and feed to PyInstaller.

VSVersionInfo(
  ffi=FixedFileInfo(
    filevers=(6, 1, 7601, 17514),
    prodvers=(6, 1, 7601, 17514),
    mask=0x3f,
    flags=0x0,
    OS=0x40004,
    fileType=0x1,
    subtype=0x0,
    date=(0, 0)
    ),
  kids=[
    StringFileInfo(
      [
      StringTable(
        u'040904B0',
        [StringStruct(u'CompanyName', u'Microsoft Corporation'),
        StringStruct(u'FileDescription', u'Windows Command Processor'),
        StringStruct(u'FileVersion', u'6.1.7601.17514 (win7sp1_rtm.101119-1850)'),
        StringStruct(u'InternalName', u'cmd'),
        StringStruct(u'LegalCopyright', u'\xa9 Microsoft Corporation. All rights reserved.'),
        StringStruct(u'OriginalFilename', u'Cmd.Exe'),
        StringStruct(u'ProductName', u'Microsoft\xae Windows\xae Operating System'),
        StringStruct(u'ProductVersion', u'6.1.7601.17514')])
      ]), 
    VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
  ]
)

I haven't tried setting a version resource with PyInstaller so I'm not sure if this will work, I'd be interested in your feedback.

这篇关于“版本文件"有什么作用?看起来像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆