修复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'";
auto p = s.find(key);
if (p != std::string::npos) {
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);
}
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 字符串值
{
const std::string key = "u'ProductVersion', u'";
auto p = s.find(key);
if (p != std::string::npos) {
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);
}
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;
@@ -547,7 +573,7 @@ int HandlePyinstallerBuildCommand(int argc, TCHAR* argv[])
_tprintf(_T("FileVersion=%s\n"), strFileVersion.GetString());
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);
strCmd.ReleaseBuffer();