diff --git a/GitVer/GitVer.cpp b/GitVer/GitVer.cpp index afb3a65..d5f5d45 100644 --- a/GitVer/GitVer.cpp +++ b/GitVer/GitVer.cpp @@ -33,11 +33,6 @@ extern TCHAR g_szFolderName[MAX_PATH] = { 0 }; const UINT DEFAULT_MAJOR_WHEN_NO_TAG = 1; const UINT DEFAULT_MINOR_WHEN_NO_TAG = 0; -#ifdef DEBUG -#define RC_DIR _T("F:\\Code\\HS\\SHWS_dev\\SHWS\\") -#define RC_NAME _T("SHWS") -#endif - int HandleSetVerCommand(int argc, TCHAR* argv[]); /// @@ -555,10 +550,6 @@ void GetDirInfo() _stprintf_s(g_szFolderName, _T("%s"), strVal.GetString()); } -#ifdef _DEBUG - _stprintf_s(g_szFolderName, RC_NAME); - _stprintf_s(g_szCurModuleDir, RC_DIR); -#endif SetCurrentDirectory(g_szCurModuleDir); } @@ -639,7 +630,7 @@ int HandleSetVerCommand(int argc, TCHAR* argv[]) if (nSetupType >= 0) { // -setup=N 存在:不回写版本信息到项目文件,只修改安装脚本并编译 - if (!ExecuteSetupBuild(nSetupType, strProductVersion)) + if (!ExecuteSetupBuild(nSetupType, strProductVersion, strFileVersion)) { return 38; } @@ -777,11 +768,7 @@ int HandleRewriteCommand(int argc, TCHAR* argv[]) _tprintf(_T("项目类型: %s\n"), GetProjectCodeTypeName(nCodeType)); -#ifdef _DEBUG - CString strValue = StartProcess(NULL, _T("cmd /c git rev-parse --short HEAD"), RC_DIR); -#else CString strValue = StartProcess(NULL, _T("cmd /c git rev-parse --short HEAD"), NULL); -#endif strValue.Replace(_T("\n"), _T("")); strValue.Replace(_T("\r"), _T("")); strValue.Trim(); diff --git a/GitVer/GitVer_setup.cpp b/GitVer/GitVer_setup.cpp index 3b0f3dc..66d7b46 100644 --- a/GitVer/GitVer_setup.cpp +++ b/GitVer/GitVer_setup.cpp @@ -106,7 +106,7 @@ static BOOL FindSetupScript(int nSetupType, CString& strScriptPath) /// /// 修改 .iss 脚本中的 AppVersion= 行。 /// -static BOOL ModifyIssScript(const CString& strScriptPath, const CString& strProductVersion) +static BOOL ModifyIssScript(const CString& strScriptPath, const CString& strFileVersion) { std::string strContent; std::string strBomPrefix; @@ -116,17 +116,17 @@ static BOOL ModifyIssScript(const CString& strScriptPath, const CString& strProd return FALSE; } - const std::string strToken = "AppVersion="; + const std::string strToken = "#define MyAppVersion "; if (strContent.find(strToken) == std::string::npos) { - _tprintf(_T("错误: .iss 文件中未找到 AppVersion= 行: %s\n"), strScriptPath.GetString()); + _tprintf(_T("错误: .iss 文件中未找到 #define MyAppVersion 行: %s\n"), strScriptPath.GetString()); return FALSE; } - std::string strNewLine = "AppVersion=" + ToAnsiString(strProductVersion.GetString()); + std::string strNewLine = "#define MyAppVersion \"" + ToAnsiString(strFileVersion.GetString()) + "\""; if (!ReplaceLineByToken(strContent, strToken, strNewLine)) { - _tprintf(_T("错误: 替换 .iss AppVersion= 行失败。\n")); + _tprintf(_T("错误: 替换 .iss #define MyAppVersion 行失败。\n")); return FALSE; } @@ -136,7 +136,7 @@ static BOOL ModifyIssScript(const CString& strScriptPath, const CString& strProd return FALSE; } - _tprintf(_T("成功: 已更新 .iss AppVersion=%s\n"), strProductVersion.GetString()); + _tprintf(_T("成功: 已更新 .iss #define MyAppVersion \"%s\"\n"), strFileVersion.GetString()); return TRUE; } @@ -147,7 +147,7 @@ static BOOL ModifyIssScript(const CString& strScriptPath, const CString& strProd /// /// 修改 .nsh 脚本中的 !define PRODUCT_VERSION 行。 /// -static BOOL ModifyNshScript(const CString& strScriptPath, const CString& strProductVersion) +static BOOL ModifyNshScript(const CString& strScriptPath, const CString& strFileVersion) { std::string strContent; std::string strBomPrefix; @@ -164,7 +164,7 @@ static BOOL ModifyNshScript(const CString& strScriptPath, const CString& strProd return FALSE; } - std::string strNewLine = "!define PRODUCT_VERSION \"" + ToAnsiString(strProductVersion.GetString()) + "\""; + std::string strNewLine = "!define PRODUCT_VERSION \"" + ToAnsiString(strFileVersion.GetString()) + "\""; if (!ReplaceLineByToken(strContent, strToken, strNewLine)) { _tprintf(_T("错误: 替换 .nsh PRODUCT_VERSION 行失败。\n")); @@ -177,7 +177,7 @@ static BOOL ModifyNshScript(const CString& strScriptPath, const CString& strProd return FALSE; } - _tprintf(_T("成功: 已更新 .nsh PRODUCT_VERSION=%s\n"), strProductVersion.GetString()); + _tprintf(_T("成功: 已更新 .nsh PRODUCT_VERSION=%s\n"), strFileVersion.GetString()); return TRUE; } @@ -250,8 +250,11 @@ static CString FindNsisCompiler() // 不回写版本信息到项目文件,只修改安装脚本并调用编译器打包。 // ───────────────────────────────────────────── -BOOL ExecuteSetupBuild(int nSetupType, const CString& strProductVersion) +BOOL ExecuteSetupBuild(int nSetupType, const CString& strProductVersion, const CString& strFileVersion) { +#ifdef _DEBUG + Sleep(1500); +#endif // 查找安装脚本 CString strScriptPath; if (!FindSetupScript(nSetupType, strScriptPath)) @@ -264,8 +267,8 @@ BOOL ExecuteSetupBuild(int nSetupType, const CString& strProductVersion) // 修改脚本中的版本号(不写回 .rc / AssemblyInfo.cs) BOOL bModifyOk = (nSetupType == 0) - ? ModifyIssScript(strScriptPath, strProductVersion) - : ModifyNshScript(strScriptPath, strProductVersion); + ? ModifyIssScript(strScriptPath, strFileVersion) + : ModifyNshScript(strScriptPath, strFileVersion); if (!bModifyOk) { @@ -320,6 +323,9 @@ BOOL ExecuteSetupBuild(int nSetupType, const CString& strProductVersion) int HandleSetupCommand(int argc, TCHAR* argv[]) { +#ifdef _DEBUG + Sleep(15000); +#endif // 解析 -setup=n 中的 n CString strSetupArg = argv[1]; CString strN = strSetupArg.Mid(7); // 跳过 "-setup=" @@ -355,8 +361,8 @@ int HandleSetupCommand(int argc, TCHAR* argv[]) return nRepoArgRet; } - CString strProductVersion; CString strFileVersion; + CString strProductVersion; VersionBuildErrorCodes errorCodes = { 5, 6, 9 }; int nVersionRet = BuildVersionsFromRepo( lpRepoPath, @@ -366,6 +372,7 @@ int HandleSetupCommand(int argc, TCHAR* argv[]) strFileVersion, DEFAULT_MAJOR_WHEN_NO_TAG_FOR_SETUP, DEFAULT_MINOR_WHEN_NO_TAG_FOR_SETUP); + if (nVersionRet != 0) { return nVersionRet; @@ -382,10 +389,11 @@ int HandleSetupCommand(int argc, TCHAR* argv[]) _tprintf(_T("[测试版本] 已将 major/minor 置零: ProductVersion=%s\n"), strProductVersion.GetString()); } + _tprintf(_T("FileVersion=%s\n"), strFileVersion.GetString()); _tprintf(_T("ProductVersion=%s\n"), strProductVersion.GetString()); // 不回写版本信息到项目文件,直接修改安装脚本并编译打包 - if (!ExecuteSetupBuild((int)nSetupType, strProductVersion)) + if (!ExecuteSetupBuild((int)nSetupType, strProductVersion, strFileVersion)) { return 38; } diff --git a/GitVer/GitVer_setup.h b/GitVer/GitVer_setup.h index 0d2dd5c..c0b3cf2 100644 --- a/GitVer/GitVer_setup.h +++ b/GitVer/GitVer_setup.h @@ -6,7 +6,7 @@ /// 涓嶅啓鍥為」鐩増鏈枃浠讹紙.rc / AssemblyInfo.cs锛夈 /// /// TRUE 鎴愬姛锛汧ALSE 澶辫触锛堥敊璇凡鎵撳嵃锛夈 -BOOL ExecuteSetupBuild(int nSetupType, const CString& strProductVersion); +BOOL ExecuteSetupBuild(int nSetupType, const CString& strProductVersion, const CString& strFileVersion); /// /// 澶勭悊鐙珛鐨 -setup=n 鍛戒护琛屽叆鍙c