修复pyinstaller打包后,版本信息不对的问题。

This commit is contained in:
2026-05-20 20:16:27 +08:00
parent 150486a29b
commit 84d67d9709
2 changed files with 36 additions and 10 deletions

View File

@@ -411,23 +411,49 @@ static BOOL UpdateVersionInfoFile(LPCTSTR lpPath, LPCTSTR lpProductVersion, LPCT
{ {
const std::string key = "u'FileVersion', u'"; const std::string key = "u'FileVersion', u'";
auto p = s.find(key); auto p = s.find(key);
if (p != std::string::npos) { if (p != std::string::npos)
{
auto pValStart = p + key.size(); auto pValStart = p + key.size();
auto pValEnd = s.find('\'', pValStart); auto pValEnd = s.find('\'', pValStart);
if (pValEnd != std::string::npos) if (pValEnd != std::string::npos)
s.replace(pValStart, pValEnd - pValStart, szFileVer); s.replace(pValStart, pValEnd - pValStart, szFileVer);
} }
else
{// 可能不带u
const std::string key = "'FileVersion', '";
auto p = s.find(key);
if (p != std::string::npos)
{
auto pValStart = p + key.size();
auto pValEnd = s.find('\'', pValStart);
if (pValEnd != std::string::npos)
s.replace(pValStart, pValEnd - pValStart, szFileVer);
}
}
} }
// 更新 ProductVersion 字符串值 // 更新 ProductVersion 字符串值
{ {
const std::string key = "u'ProductVersion', u'"; const std::string key = "u'ProductVersion', u'";
auto p = s.find(key); auto p = s.find(key);
if (p != std::string::npos) { if (p != std::string::npos)
{
auto pValStart = p + key.size(); auto pValStart = p + key.size();
auto pValEnd = s.find('\'', pValStart); auto pValEnd = s.find('\'', pValStart);
if (pValEnd != std::string::npos) if (pValEnd != std::string::npos)
s.replace(pValStart, pValEnd - pValStart, szProdVer); s.replace(pValStart, pValEnd - pValStart, szProdVer);
} }
else
{//可能不带u
const std::string key = "'ProductVersion', '";
auto p = s.find(key);
if (p != std::string::npos)
{
auto pValStart = p + key.size();
auto pValEnd = s.find('\'', pValStart);
if (pValEnd != std::string::npos)
s.replace(pValStart, pValEnd - pValStart, szProdVer);
}
}
} }
if (!myFile.Open(lpPath, CFile::modeCreate | CFile::modeWrite, &fileEx)) return FALSE; if (!myFile.Open(lpPath, CFile::modeCreate | CFile::modeWrite, &fileEx)) return FALSE;
@@ -547,7 +573,7 @@ int HandlePyinstallerBuildCommand(int argc, TCHAR* argv[])
_tprintf(_T("FileVersion=%s\n"), strFileVersion.GetString()); _tprintf(_T("FileVersion=%s\n"), strFileVersion.GetString());
CString strCmd; CString strCmd;
strCmd.Format(_T("cmd /c python -m PyInstaller %s"),strExtraArgs.GetString()); strCmd.Format(_T("cmd /c python -m PyInstaller %s"), strExtraArgs.GetString());
CString strBuildResult = StartProcess(NULL, strCmd.GetBuffer(), lpRepoPath); CString strBuildResult = StartProcess(NULL, strCmd.GetBuffer(), lpRepoPath);
strCmd.ReleaseBuffer(); strCmd.ReleaseBuffer();

View File

@@ -443,14 +443,14 @@ VSVersionInfo(
StringTable( StringTable(
'040904B0', # 语言 0409=英语, 04B0=Unicode '040904B0', # 语言 0409=英语, 04B0=Unicode
[ [
StringStruct('CompanyName', 'MyCompany'), StringStruct('CompanyName', 'MyCompany'),
StringStruct('FileDescription', 'MyApp Application'), StringStruct('FileDescription', 'MyApp Application'),
StringStruct('FileVersion', '5.0.1920.11'), StringStruct('FileVersion', '5.0.1920.11'),
StringStruct('InternalName', 'MyApp'), StringStruct('InternalName', 'MyApp'),
StringStruct('LegalCopyright', 'Copyright (C) 2026 MyCompany'), StringStruct('LegalCopyright', 'Copyright (C) 2026 MyCompany'),
StringStruct('OriginalFilename', 'MyApp.exe'), StringStruct('OriginalFilename', 'MyApp.exe'),
StringStruct('ProductName', 'MyApp'), StringStruct('ProductName', 'MyApp'),
StringStruct('ProductVersion', '5.0.1920.11'), StringStruct('ProductVersion', '5.0.1920.11'),
] ]
) )
]), ]),