修复inno setup中脚本的版本修改失败问题。

This commit is contained in:
2026-06-03 18:33:18 +08:00
parent 171fa4448d
commit a1f4ebd45a

View File

@@ -30,9 +30,7 @@ static const UINT DEFAULT_MINOR_WHEN_NO_TAG_FOR_SETUP = 0;
/// 在字符串内容中查找首个包含 strToken 的整行, /// 在字符串内容中查找首个包含 strToken 的整行,
/// 用 strNewLine 替换该行(不含行尾换行符)。 /// 用 strNewLine 替换该行(不含行尾换行符)。
/// </summary> /// </summary>
static BOOL ReplaceLineByToken(std::string& strContent, static BOOL ReplaceLineByToken(std::string& strContent, const std::string& strToken, const std::string& strNewLine)
const std::string& strToken,
const std::string& strNewLine)
{ {
std::string::size_type nPos = strContent.find(strToken); std::string::size_type nPos = strContent.find(strToken);
if (nPos == std::string::npos) if (nPos == std::string::npos)
@@ -119,17 +117,17 @@ static BOOL ModifyIssScript(const CString& strScriptPath, const CString& strFile
return FALSE; return FALSE;
} }
const std::string strToken = "#define MyAppVersion "; const std::string strToken = "#define MyAppVersion ";
if (strContent.find(strToken) == std::string::npos) if (strContent.find(strToken) == std::string::npos)
{ {
_tprintf(_T("错误: .iss 文件中未找到 #define MyAppVersion 行: %s\n"), strScriptPath.GetString()); _tprintf(_T("错误: .iss 文件中未找到 #define MyAppVersion 行: %s\n"), strScriptPath.GetString());
return FALSE; return FALSE;
} }
std::string strNewLine = "#define MyAppVersion \"" + ToAnsiString(strFileVersion.GetString()) + "\""; std::string strNewLine = "#define MyAppVersion \"" + ToAnsiString(strFileVersion.GetString()) + "\"";
if (!ReplaceLineByToken(strContent, strToken, strNewLine)) if (!ReplaceLineByToken(strContent, strToken, strNewLine))
{ {
_tprintf(_T("错误: 替换 .iss #define MyAppVersion 行失败。\n")); _tprintf(_T("错误: 替换 .iss #define MyAppVersion 行失败。\n"));
return FALSE; return FALSE;
} }
@@ -139,7 +137,7 @@ static BOOL ModifyIssScript(const CString& strScriptPath, const CString& strFile
return FALSE; return FALSE;
} }
_tprintf(_T("成功: 已更新 .iss #define MyAppVersion \"%s\"\n"), strFileVersion.GetString()); _tprintf(_T("成功: 已更新 .iss #define MyAppVersion \"%s\"\n"), strFileVersion.GetString());
return TRUE; return TRUE;
} }