From b2b508f52099255dbb6ada883e62d2efd74daebe Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 19 May 2026 15:38:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=8D=8F=E5=AD=97=E7=AC=A6=E7=BC=96?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GitVer/GitVer.cpp | 228 +++++++++++++++++++------------------- GitVer/GitVer_setup.cpp | 136 +++++++++++------------ GitVer/GitVer_version.cpp | 40 +++---- 3 files changed, 202 insertions(+), 202 deletions(-) diff --git a/GitVer/GitVer.cpp b/GitVer/GitVer.cpp index de96d68..ba1a453 100644 --- a/GitVer/GitVer.cpp +++ b/GitVer/GitVer.cpp @@ -1,4 +1,4 @@ -// GitVer.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// GitVer.cpp : ļ "main" ִнڴ˴ʼ // #include "pch.h" @@ -18,7 +18,7 @@ #define new DEBUG_NEW #endif -// 唯一的应用程序对象 +// ΨһӦó CWinApp theApp; @@ -41,10 +41,10 @@ const UINT DEFAULT_MINOR_WHEN_NO_TAG = 0; int HandleSetVerCommand(int argc, TCHAR* argv[]); /// -/// 将宽字符字符串转换为ANSI字符串。 +/// ַַתΪANSIַ /// -/// 要转换的宽字符字符串。 -/// 转换后的ANSI字符串。 +/// ҪתĿַַ +/// תANSIַ std::string ToAnsiString(LPCTSTR lpText) { if (lpText == NULL) @@ -69,11 +69,11 @@ std::string ToAnsiString(LPCTSTR lpText) } /// -/// 检查指定目录下是否存在与模式匹配的文件。 +/// ָĿ¼Ƿģʽƥļ /// -/// 要搜索的基目录。 -/// 要匹配的文件模式。 -/// 如果存在匹配的文件,则返回TRUE;否则返回FALSE。 +/// ҪĻĿ¼ +/// Ҫƥļģʽ +/// ƥļ򷵻TRUE򷵻FALSE BOOL HasMatchingFile(LPCTSTR lpBaseDir, LPCTSTR lpPattern) { CString strSearchPath; @@ -91,12 +91,12 @@ BOOL HasMatchingFile(LPCTSTR lpBaseDir, LPCTSTR lpPattern) } /// -/// 递归查找与模式匹配的第一个文件。 +/// ݹģʽƥĵһļ /// -/// 要搜索的基目录。 -/// 要匹配的文件模式。 -/// 找到的文件的完整路径。 -/// 如果找到匹配的文件,则返回TRUE;否则返回FALSE。 +/// ҪĻĿ¼ +/// Ҫƥļģʽ +/// ҵļ· +/// ҵƥļ򷵻TRUE򷵻FALSE BOOL FindFirstFileByPatternRecursive(LPCTSTR lpBaseDir, LPCTSTR lpPattern, CString& strFoundPath) { strFoundPath.Empty(); @@ -155,12 +155,12 @@ BOOL FindFirstFileByPatternRecursive(LPCTSTR lpBaseDir, LPCTSTR lpPattern, CStri } /// -/// 构建相对于仓库的路径。 +/// ڲֿ· /// -/// 基目录。 -/// 完整路径。 -/// 相对路径。 -/// 如果成功构建相对路径,则返回TRUE;否则返回FALSE。 +/// Ŀ¼ +/// · +/// · +/// ɹ·򷵻TRUE򷵻FALSE BOOL BuildRepoRelativePath(LPCTSTR lpBaseDir, LPCTSTR lpFullPath, CString& strRelativePath) { strRelativePath.Empty(); @@ -196,10 +196,10 @@ BOOL BuildRepoRelativePath(LPCTSTR lpBaseDir, LPCTSTR lpFullPath, CString& strRe } /// -/// 获取文件名(不包含扩展名)。 +/// ȡļչ /// -/// 文件路径。 -/// 不包含扩展名的文件名。 +/// ļ· +/// չļ CString GetFileNameWithoutExtension(LPCTSTR lpFilePath) { if (lpFilePath == NULL) @@ -218,11 +218,11 @@ CString GetFileNameWithoutExtension(LPCTSTR lpFilePath) } /// -/// 查找首选的C++资源文件(.rc)。 +/// ѡC++Դļ.rc /// -/// 要搜索的基目录。 -/// 找到的资源文件的完整路径。 -/// 如果找到首选的资源文件,则返回TRUE;否则返回FALSE。 +/// ҪĻĿ¼ +/// ҵԴļ· +/// ҵѡԴļ򷵻TRUE򷵻FALSE BOOL FindPreferredCppRcFileAt(LPCTSTR lpBaseDir, CString& strResFile) { strResFile.Empty(); @@ -260,11 +260,11 @@ BOOL FindPreferredCppRcFileAt(LPCTSTR lpBaseDir, CString& strResFile) } /// -/// 查找首选的AssemblyInfo.cs文件。 +/// ѡAssemblyInfo.csļ /// -/// 要搜索的基目录。 -/// 找到的AssemblyInfo.cs文件的完整路径。 -/// 如果找到首选的AssemblyInfo.cs文件,则返回TRUE;否则返回FALSE。 +/// ҪĻĿ¼ +/// ҵAssemblyInfo.csļ· +/// ҵѡAssemblyInfo.csļ򷵻TRUE򷵻FALSE BOOL FindPreferredAssemblyInfoFileAt(LPCTSTR lpBaseDir, CString& strResFile) { strResFile.Empty(); @@ -290,13 +290,13 @@ BOOL FindPreferredAssemblyInfoFileAt(LPCTSTR lpBaseDir, CString& strResFile) } /// -/// 检测项目的源码类型。 +/// ĿԴ͡ /// -/// 要检测的基目录。 -/// 返回项目的源码类型枚举值。 +/// ҪĻĿ¼ +/// ĿԴöֵ int DetectProjectCodeType(LPCTSTR lpBaseDir) { - _tprintf(_T("检测项目源码类型:%s\n"), lpBaseDir); + _tprintf(_T("ĿԴͣ%s\n"), lpBaseDir); if (PathFileExists(CString(lpBaseDir) + _T("\\Properties\\AssemblyInfo.cs")) || HasMatchingFile(lpBaseDir, _T("*.csproj")) || HasMatchingFile(lpBaseDir, _T("*.cs"))) @@ -326,10 +326,10 @@ int DetectProjectCodeType(LPCTSTR lpBaseDir) } /// -/// 获取项目源码类型的名称。 +/// ȡĿԴ͵ơ /// -/// 项目源码类型枚举值。 -/// 项目源码类型的名称。 +/// ĿԴöֵ +/// ĿԴ͵ơ LPCTSTR GetProjectCodeTypeName(int nCodeType) { switch (nCodeType) @@ -346,21 +346,21 @@ LPCTSTR GetProjectCodeTypeName(int nCodeType) } /// -/// 打印完整的使用示例。 +/// ӡʹʾ /// void PrintFullUsageExamples() { LPCTSTR lpUsageText = - _T("用法:\n") - _T(" gitver (显示帮助后进入当前分支创建 tag 流程)\n") - _T(" gitver rewrite [PEType可选] [-f可选]\n") - _T(" gitver setver= [repodir=可选] [-test可选]\n") - _T(" gitver nuitkabuild= [repodir=可选] [-test可选] [params=\"\"可选]\n") - _T(" gitver nuitkapydbuild= [repodir=可选] [-test可选] [params=\"\"可选]\n") - _T(" gitver -setup=0|1 [pid] [repodir=可选] [-test可选]\n") - _T(" -setup=0: 使用 Inno Setup 脚本 (setup.iss)\n") - _T(" -setup=1: 使用 NSIS 脚本 (setup.nsh)\n") - _T("\n示例:\n") + _T("÷\n") + _T(" gitver ʾ뵱ǰ֧ tag ̣\n") + _T(" gitver rewrite [PETypeѡ] [-fѡ]\n") + _T(" gitver setver= [repodir=ѡ] [-testѡ]\n") + _T(" gitver nuitkabuild= [repodir=ѡ] [-testѡ] [params=\"\"ѡ]\n") + _T(" gitver nuitkapydbuild= [repodir=ѡ] [-testѡ] [params=\"\"ѡ]\n") + _T(" gitver -setup=0|1 [pid] [repodir=ѡ] [-testѡ]\n") + _T(" -setup=0: ʹ Inno Setup ű (setup.iss)\n") + _T(" -setup=1: ʹ NSIS ű (setup.nsh)\n") + _T("\nʾ\n") _T(" gitver\n") _T(" gitver rewrite\n") _T(" gitver rewrite 2\n") @@ -376,48 +376,48 @@ void PrintFullUsageExamples() _T(" gitver nuitkapydbuild=5 src\\core.py repodir=E:\\Code\\MyPyProj params=\"--output-dir=dist\"\n") _T(" gitver -setup=0 5\n") _T(" gitver -setup=1 5 repodir=E:\\Code\\MyProj\n") - _T("params: 传递给 Nuitka 的额外参数,用双引号括起来,如 params=\"--standalone --output-dir=dist\"。\n") - _T("-test: 将产品版本号的 major 和 minor 都置为 0(用于测试版本构建)。\n") - _T("无参数时会读取当前分支最近三次 tag,并提示选择 major 加 1 或 minor 加 1,然后创建新 tag。\n") - _T("未找到当前分支 tag 时自动使用默认版本 1.0。\n"); + _T("params: ݸ Nuitka Ķ˫ params=\"--standalone --output-dir=dist\"\n") + _T("-test: Ʒ汾ŵ major minor Ϊ 0ڲ԰汾\n") + _T("޲ʱȡǰ֧ tagʾѡ major 1 minor 1Ȼ󴴽 tag\n") + _T("δҵǰ֧ tag ʱԶʹĬϰ汾 1.0\n"); _tprintf(_T("%s"), lpUsageText); } /// -/// 打印命令简要用法(用于未知命令等场景)。 +/// ӡҪ÷δ֪ȳ /// void PrintShortCommandUsage() { - _tprintf(_T("请使用:gitver rewrite [PE类型可选]\n")); - _tprintf(_T("请使用:gitver setver= [repodir=可选]\n")); - _tprintf(_T("或:gitver nuitkabuild= [repodir=可选] [params=\"\"可选]\n")); - _tprintf(_T("或:gitver nuitkapydbuild= [repodir=可选] [params=\"\"可选]\n")); + _tprintf(_T("ʹãgitver rewrite [PEͿѡ]\n")); + _tprintf(_T("ʹãgitver setver= [repodir=ѡ]\n")); + _tprintf(_T("gitver nuitkabuild= [repodir=ѡ] [params=\"\"ѡ]\n")); + _tprintf(_T("gitver nuitkapydbuild= [repodir=ѡ] [params=\"\"ѡ]\n")); } /// -/// 打印命令参数不足时的标准用法与示例。 +/// ӡʱı׼÷ʾ /// -/// 命令名称。 -/// 必选参数占位文本。 -/// 示例中的必选参数。 +/// ơ +/// ѡռλı +/// ʾеıѡ void PrintCommandUsageAndExamples(LPCTSTR lpCommandName, LPCTSTR lpRequiredArgs, LPCTSTR lpExampleRequiredArgs) { - _tprintf(_T("用法:gitver %s %s [repodir=可选]\n"), lpCommandName, lpRequiredArgs); + _tprintf(_T("÷gitver %s %s [repodir=ѡ]\n"), lpCommandName, lpRequiredArgs); if (lpExampleRequiredArgs != NULL && _tcslen(lpExampleRequiredArgs) > 0) { - _tprintf(_T("示例:gitver %s 5 %s repodir=E:\\Code\\OTH\\gitver\n"), lpCommandName, lpExampleRequiredArgs); - _tprintf(_T("示例:gitver %s 5 %s\n"), lpCommandName, lpExampleRequiredArgs); + _tprintf(_T("ʾgitver %s 5 %s repodir=E:\\Code\\OTH\\gitver\n"), lpCommandName, lpExampleRequiredArgs); + _tprintf(_T("ʾgitver %s 5 %s\n"), lpCommandName, lpExampleRequiredArgs); } else { - _tprintf(_T("示例:gitver %s 5 repodir=E:\\Code\\OTH\\gitver\n"), lpCommandName); - _tprintf(_T("示例:gitver %s 5\n"), lpCommandName); + _tprintf(_T("ʾgitver %s 5 repodir=E:\\Code\\OTH\\gitver\n"), lpCommandName); + _tprintf(_T("ʾgitver %s 5\n"), lpCommandName); } } /// -/// 获取退出码的简要说明。 +/// ȡ˳ļҪ˵ /// LPCTSTR GetExitCodeHint(int nRetCode) { @@ -493,7 +493,7 @@ LPCTSTR GetExitCodeHint(int nRetCode) } /// -/// 在命令执行返回非零时输出统一错误日志。 +/// ִзطʱͳһ־ /// void PrintCommandFailedWithCode(LPCTSTR lpCommandName, int nRetCode) { @@ -512,18 +512,18 @@ void PrintCommandFailedWithCode(LPCTSTR lpCommandName, int nRetCode) } /// -/// 输出命令执行结束日志(含耗时和退出码)。 +/// ִн־ʱ˳룩 /// void LogCommandEnd(LPCTSTR lpCommandName, DWORD dwStartTick, int nRetCode) { DWORD dwElapsed = GetTickCount() - dwStartTick; - _tprintf(_T("命令结束: %s,耗时 %u ms,退出码 %d\n"), lpCommandName, dwElapsed, nRetCode); + _tprintf(_T(": %sʱ %u ms˳ %d\n"), lpCommandName, dwElapsed, nRetCode); } /// -/// 获取当前模块的目录信息。 +/// ȡǰģĿ¼Ϣ /// -/// 返回值。 +/// ֵ void GetDirInfo() { TCHAR szDrive[_MAX_DRIVE] = { 0 }; @@ -563,19 +563,19 @@ void GetDirInfo() } /// -/// 处理设置版本命令。 +/// ð汾 /// -/// 参数个数。 -/// 参数数组。 -/// 返回值。 +/// +/// 顣 +/// ֵ int HandleSetVerCommand(int argc, TCHAR* argv[]) { - // 解析 "setver=N" 中的 pid - CString strPid = CString(argv[1]).Mid(7); // 跳过 "setver=" + // "setver=N" е pid + CString strPid = CString(argv[1]).Mid(7); // "setver=" UINT nPid = 0; if (strPid.IsEmpty() || !TryParseUInt16(strPid, nPid)) { - _tprintf(_T("错误: setver= 后的 pid 无效:%s,应为 0-65535 范围的整数。\n"), strPid.GetString()); + _tprintf(_T(": setver= pid Ч%sӦΪ 0-65535 Χ\n"), strPid.GetString()); return 4; } @@ -611,13 +611,13 @@ int HandleSetVerCommand(int argc, TCHAR* argv[]) { strProductVersion = strProductVersion.Left(nDot2 + 1) + _T("0.0"); } - _tprintf(_T("[test] 已将 major/minor 置零: ProductVersion=%s\n"), strProductVersion.GetString()); + _tprintf(_T("[test] ѽ major/minor : ProductVersion=%s\n"), strProductVersion.GetString()); } _tprintf(_T("ProductVersion=%s\n"), strProductVersion.GetString()); _tprintf(_T("FileVersion=%s\n"), strFileVersion.GetString()); - // 检查是否附带了 -setup=N 标志 + // Ƿ񸽴 -setup=N ־ int nSetupType = -1; for (int i = 2; i < argc; ++i) { @@ -627,7 +627,7 @@ int HandleSetVerCommand(int argc, TCHAR* argv[]) UINT nVal = 0; if (!TryParseUInt16(strArg.Mid(7), nVal) || (nVal != 0 && nVal != 1)) { - _tprintf(_T("错误: -setup 参数值 \"%s\" 不支持,仅支持 0(Inno Setup)或 1(NSIS)。\n"), + _tprintf(_T(": -setup ֵ \"%s\" ֧֣֧ 0Inno Setup 1NSIS\n"), strArg.Mid(7).GetString()); return 36; } @@ -638,7 +638,7 @@ int HandleSetVerCommand(int argc, TCHAR* argv[]) if (nSetupType >= 0) { - // -setup=N 存在:不回写版本信息到项目文件,只修改安装脚本并编译 + // -setup=N ڣд汾ϢĿļֻ޸İװű if (!ExecuteSetupBuild(nSetupType, strProductVersion)) { return 38; @@ -651,13 +651,13 @@ int HandleSetVerCommand(int argc, TCHAR* argv[]) /// /// -/// 准备C++重写内容。 +/// ׼C++дݡ /// -/// 提交ID。 -/// PE类型。 -/// 资源文件路径。 -/// 旧内容向量。 -/// 新内容向量。 +/// ύID +/// PE͡ +/// Դļ· +/// +/// /// void PrepareCppRewriteContent(const CString& strCommitId, int nPEType, CString& strResFile, std::vector& vtOldContent, std::vector& vtNewContent) { @@ -665,7 +665,7 @@ void PrepareCppRewriteContent(const CString& strCommitId, int nPEType, CString& if (!FindPreferredCppRcFileAt(g_szCurModuleDir, strResFile)) { - _tprintf(_T("错误: 未找到C++ .rc资源文件。\n")); + _tprintf(_T(": δҵC++ .rcԴļ\n")); return; } @@ -704,7 +704,7 @@ void PrepareCppRewriteContent(const CString& strCommitId, int nPEType, CString& vtNewContent.push_back(ToAnsiString(szValue)); _tprintf(_T("Rewrite new token: %s\n"), szValue); #if 0 - _stprintf_s(szValue, "VALUE \"FileDescription\", \"TODO: <文件说明>\""); + _stprintf_s(szValue, "VALUE \"FileDescription\", \"TODO: <ļ˵>\""); vtOldContent.push_back(szValue); _stprintf_s(szValue, "VALUE \"FileDescription\", \"%s\"", strCommitId.GetString()); @@ -714,18 +714,18 @@ void PrepareCppRewriteContent(const CString& strCommitId, int nPEType, CString& } /// -/// 准备C#重写内容。 +/// ׼C#дݡ /// -/// 提交ID。 -/// 资源文件路径。 -/// 旧内容向量。 -/// 新内容向量。 +/// ύID +/// Դļ· +/// +/// void PrepareCSharpRewriteContent(const CString& strCommitId, CString& strResFile, std::vector& vtOldContent, std::vector& vtNewContent) { TCHAR szValue[MAX_PATH] = { 0 }; if (!FindPreferredAssemblyInfoFileAt(g_szCurModuleDir, strResFile)) { - _tprintf(_T("错误: 未找到首选的 AssemblyInfo 文件。\n")); + _tprintf(_T(": δҵѡ AssemblyInfo ļ\n")); return; } @@ -752,11 +752,11 @@ void PrepareCSharpRewriteContent(const CString& strCommitId, CString& strResFile } /// -/// 处理重写命令。 +/// д /// -/// 参数个数。 -/// 参数数组。 -/// 返回值。 +/// +/// 顣 +/// ֵ int HandleRewriteCommand(int argc, TCHAR* argv[]) { int nCodeType = DetectProjectCodeType(g_szCurModuleDir); @@ -771,11 +771,11 @@ int HandleRewriteCommand(int argc, TCHAR* argv[]) if (nCodeType == PROJECT_UNKNOWN) { - _tprintf(_T("错误: 未知项目类型。\n")); + _tprintf(_T(": δ֪Ŀ͡\n")); return 15; } - _tprintf(_T("项目类型: %s\n"), GetProjectCodeTypeName(nCodeType)); + _tprintf(_T("Ŀ: %s\n"), GetProjectCodeTypeName(nCodeType)); #ifdef _DEBUG CString strValue = StartProcess(NULL, _T("cmd /c git rev-parse --short HEAD"), RC_DIR); @@ -787,7 +787,7 @@ int HandleRewriteCommand(int argc, TCHAR* argv[]) strValue.Trim(); if (strValue.IsEmpty()) { - _tprintf(_T("错误: 获取提交ID失败。\n")); + _tprintf(_T(": ȡύIDʧܡ\n")); return 2; } @@ -805,7 +805,7 @@ int HandleRewriteCommand(int argc, TCHAR* argv[]) } else if (nCodeType == PROJECT_PYTHON) { - _tprintf(_T("错误: 不支持的项目类型: Python。\n")); + _tprintf(_T(": ֵ֧Ŀ: Python\n")); return 16; } @@ -813,11 +813,11 @@ int HandleRewriteCommand(int argc, TCHAR* argv[]) { if (bForceRewrite) { - _tprintf(_T("警告: 资源文件路径为空,已按 -f 忽略本次重写失败。\n")); + _tprintf(_T(": Դļ·ΪգѰ -f Աдʧܡ\n")); return 0; } - _tprintf(_T("错误: 资源文件路径为空。\n")); + _tprintf(_T(": Դļ·Ϊա\n")); return 35; } @@ -825,7 +825,7 @@ int HandleRewriteCommand(int argc, TCHAR* argv[]) { if (bForceRewrite) { - _tprintf(_T("警告: 替换文件内容失败,已按 -f 忽略本次重写失败。\n")); + _tprintf(_T(": 滻ļʧܣѰ -f Աдʧܡ\n")); return 0; } @@ -839,7 +839,7 @@ int main(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; - // 添加图标; + // ͼ; HWND hwnd = GetForegroundWindow(); SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON_APP))); HMODULE hModule = ::GetModuleHandle(NULL); @@ -847,23 +847,23 @@ int main(int argc, TCHAR* argv[], TCHAR* envp[]) GetDirInfo(); if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { - _tprintf(_T("错误:MFC 初始化失败。\n")); + _tprintf(_T("MFC ʼʧܡ\n")); nRetCode = 1; } else { CString strArgs = BuildArgsForLog(argc, argv); - _tprintf(_T("命令参数: %s\n"), strArgs.GetString()); + _tprintf(_T(": %s\n"), strArgs.GetString()); if (argc <= 1) { - _tprintf(_T("进入交互式标签创建模式。\n")); + _tprintf(_T("뽻ʽǩģʽ\n")); PrintFullUsageExamples(); DWORD dwStartTick = LogCommandStart(_T("interactive")); int nCmdRet = HandleCreateTagInteractive(); LogCommandEnd(_T("interactive"), dwStartTick, nCmdRet); PrintCommandFailedWithCode(_T("interactive"), nCmdRet); - // 暂停,便于查看输出日志(Windows 控制台) + // ͣڲ鿴־Windows ̨ system("pause"); return nCmdRet; } @@ -913,7 +913,7 @@ int main(int argc, TCHAR* argv[], TCHAR* envp[]) return nCmdRet; } - _tprintf(_T("错误:未知命令:%s\n"), argv[1]); + _tprintf(_T("δ֪%s\n"), argv[1]); PrintShortCommandUsage(); return 3; diff --git a/GitVer/GitVer_setup.cpp b/GitVer/GitVer_setup.cpp index db689da..f8d3b75 100644 --- a/GitVer/GitVer_setup.cpp +++ b/GitVer/GitVer_setup.cpp @@ -8,7 +8,7 @@ extern TCHAR g_szCurModuleDir[MAX_PATH]; -// 来自 gitver_rewrite.cpp / GitVer.cpp 的跨单元函数声明 +// gitver_rewrite.cpp / GitVer.cpp Ŀ絥Ԫ std::string ToAnsiString(LPCTSTR lpText); BOOL ReadTextFileAsAnsi(LPCTSTR lpFile, std::string& strContent, std::string& strBomPrefix); BOOL WriteTextFileAsAnsi(LPCTSTR lpFile, const std::string& strContent, const std::string& strBomPrefix); @@ -19,13 +19,13 @@ int ParseSetVerOptions(int argc, TCHAR* argv[], int nStartIndex, LPCTSTR& lpRepo static const UINT DEFAULT_MAJOR_WHEN_NO_TAG_FOR_SETUP = 1; static const UINT DEFAULT_MINOR_WHEN_NO_TAG_FOR_SETUP = 0; -// ───────────────────────────────────────────── -// 内部工具:行级文本替换 -// ───────────────────────────────────────────── +// +// ڲߣмı滻 +// /// -/// 在字符串内容中查找首个包含 strToken 的整行, -/// 用 strNewLine 替换该行(不含行尾换行符)。 +/// ַв׸ strToken У +/// strNewLine 滻Уβз /// static BOOL ReplaceLineByToken(std::string& strContent, const std::string& strToken, @@ -46,7 +46,7 @@ static BOOL ReplaceLineByToken(std::string& strContent, nLineEnd = strContent.size(); } - // 去掉可能存在的 \r + // ȥܴڵ \r std::string::size_type nReplEnd = nLineEnd; if (nReplEnd > nLineStart && strContent[nReplEnd - 1] == '\r') { @@ -57,13 +57,13 @@ static BOOL ReplaceLineByToken(std::string& strContent, return TRUE; } -// ───────────────────────────────────────────── -// 查找安装脚本 -// ───────────────────────────────────────────── +// +// Ұװű +// /// -/// 在 exe 所在目录及其上级目录中查找安装脚本。 -/// nSetupType=0 查找 setup.iss,nSetupType=1 查找 setup.nsi。 +/// exe Ŀ¼ϼĿ¼вҰװű +/// nSetupType=0 setup.issnSetupType=1 setup.nsi /// static BOOL FindSetupScript(int nSetupType, CString& strScriptPath) { @@ -71,10 +71,10 @@ static BOOL FindSetupScript(int nSetupType, CString& strScriptPath) LPCTSTR lpFileName = (nSetupType == 0) ? _T("setup.iss") : _T("setup.nsi"); - // 当前 exe 目录(无末尾反斜杠) + // ǰ exe Ŀ¼ĩβбܣ CString strExeDir = g_szCurModuleDir; - // 尝试 exe 目录 + // exe Ŀ¼ CString strCandidate; strCandidate.Format(_T("%s\\%s"), strExeDir.GetString(), lpFileName); if (PathFileExists(strCandidate)) @@ -83,7 +83,7 @@ static BOOL FindSetupScript(int nSetupType, CString& strScriptPath) return TRUE; } - // 尝试上级目录 + // ϼĿ¼ int nSlash = strExeDir.ReverseFind(_T('\\')); if (nSlash > 0) { @@ -99,12 +99,12 @@ static BOOL FindSetupScript(int nSetupType, CString& strScriptPath) return FALSE; } -// ───────────────────────────────────────────── -// 修改 Inno Setup 脚本 -// ───────────────────────────────────────────── +// +// ޸ Inno Setup ű +// /// -/// 修改 .iss 脚本中的 AppVersion= 行。 +/// ޸ .iss űе AppVersion= С /// static BOOL ModifyIssScript(const CString& strScriptPath, const CString& strProductVersion) { @@ -112,40 +112,40 @@ static BOOL ModifyIssScript(const CString& strScriptPath, const CString& strProd std::string strBomPrefix; if (!ReadTextFileAsAnsi(strScriptPath, strContent, strBomPrefix)) { - _tprintf(_T("错误: 读取 .iss 文件失败: %s\n"), strScriptPath.GetString()); + _tprintf(_T(": ȡ .iss ļʧ: %s\n"), strScriptPath.GetString()); return FALSE; } const std::string strToken = "AppVersion="; if (strContent.find(strToken) == std::string::npos) { - _tprintf(_T("错误: .iss 文件中未找到 AppVersion= 行: %s\n"), strScriptPath.GetString()); + _tprintf(_T(": .iss ļδҵ AppVersion= : %s\n"), strScriptPath.GetString()); return FALSE; } std::string strNewLine = "AppVersion=" + ToAnsiString(strProductVersion.GetString()); if (!ReplaceLineByToken(strContent, strToken, strNewLine)) { - _tprintf(_T("错误: 替换 .iss AppVersion= 行失败。\n")); + _tprintf(_T(": 滻 .iss AppVersion= ʧܡ\n")); return FALSE; } if (!WriteTextFileAsAnsi(strScriptPath, strContent, strBomPrefix)) { - _tprintf(_T("错误: 写入 .iss 文件失败: %s\n"), strScriptPath.GetString()); + _tprintf(_T(": д .iss ļʧ: %s\n"), strScriptPath.GetString()); return FALSE; } - _tprintf(_T("成功: 已更新 .iss AppVersion=%s\n"), strProductVersion.GetString()); + _tprintf(_T("ɹ: Ѹ .iss AppVersion=%s\n"), strProductVersion.GetString()); return TRUE; } -// ───────────────────────────────────────────── -// 修改 NSIS 脚本 -// ───────────────────────────────────────────── +// +// ޸ NSIS ű +// /// -/// 修改 .nsh 脚本中的 !define PRODUCT_VERSION 行。 +/// ޸ .nsh űе !define PRODUCT_VERSION С /// static BOOL ModifyNshScript(const CString& strScriptPath, const CString& strProductVersion) { @@ -153,41 +153,41 @@ static BOOL ModifyNshScript(const CString& strScriptPath, const CString& strProd std::string strBomPrefix; if (!ReadTextFileAsAnsi(strScriptPath, strContent, strBomPrefix)) { - _tprintf(_T("错误: 读取 .nsh 文件失败: %s\n"), strScriptPath.GetString()); + _tprintf(_T(": ȡ .nsh ļʧ: %s\n"), strScriptPath.GetString()); return FALSE; } const std::string strToken = "!define PRODUCT_VERSION"; if (strContent.find(strToken) == std::string::npos) { - _tprintf(_T("错误: .nsh 文件中未找到 !define PRODUCT_VERSION 行: %s\n"), strScriptPath.GetString()); + _tprintf(_T(": .nsh ļδҵ !define PRODUCT_VERSION : %s\n"), strScriptPath.GetString()); return FALSE; } std::string strNewLine = "!define PRODUCT_VERSION \"" + ToAnsiString(strProductVersion.GetString()) + "\""; if (!ReplaceLineByToken(strContent, strToken, strNewLine)) { - _tprintf(_T("错误: 替换 .nsh PRODUCT_VERSION 行失败。\n")); + _tprintf(_T(": 滻 .nsh PRODUCT_VERSION ʧܡ\n")); return FALSE; } if (!WriteTextFileAsAnsi(strScriptPath, strContent, strBomPrefix)) { - _tprintf(_T("错误: 写入 .nsh 文件失败: %s\n"), strScriptPath.GetString()); + _tprintf(_T(": д .nsh ļʧ: %s\n"), strScriptPath.GetString()); return FALSE; } - _tprintf(_T("成功: 已更新 .nsh PRODUCT_VERSION=%s\n"), strProductVersion.GetString()); + _tprintf(_T("ɹ: Ѹ .nsh PRODUCT_VERSION=%s\n"), strProductVersion.GetString()); return TRUE; } -// ───────────────────────────────────────────── -// 查找编译器 -// ───────────────────────────────────────────── +// +// ұ +// /// -/// 查找 Inno Setup 编译器 (ISCC.exe)。 -/// 先查 PATH,再尝试常见安装路径。 +/// Inno Setup (ISCC.exe) +/// Ȳ PATHٳԳװ· /// static CString FindInnoSetupCompiler() { @@ -217,8 +217,8 @@ static CString FindInnoSetupCompiler() } /// -/// 查找 NSIS 编译器 (makensis.exe)。 -/// 先查 PATH,再尝试常见安装路径。 +/// NSIS (makensis.exe) +/// Ȳ PATHٳԳװ· /// static CString FindNsisCompiler() { @@ -245,35 +245,35 @@ static CString FindNsisCompiler() return CString(); } -// ───────────────────────────────────────────── -// 公共执行函数(供 HandleSetupCommand 和 setver -setup=N 共用) -// 不回写版本信息到项目文件,只修改安装脚本并调用编译器打包。 -// ───────────────────────────────────────────── +// +// ִк HandleSetupCommand setver -setup=N ã +// д汾ϢĿļֻ޸İװűñ +// BOOL ExecuteSetupBuild(int nSetupType, const CString& strProductVersion) { - // 查找安装脚本 + // Ұװű CString strScriptPath; if (!FindSetupScript(nSetupType, strScriptPath)) { LPCTSTR lpScriptName = (nSetupType == 0) ? _T("setup.iss") : _T("setup.nsi"); - _tprintf(_T("错误: 未在 exe 目录或上级目录中找到 %s。\n"), lpScriptName); + _tprintf(_T(": δ exe Ŀ¼ϼĿ¼ҵ %s\n"), lpScriptName); return FALSE; } - _tprintf(_T("找到安装脚本: %s\n"), strScriptPath.GetString()); + _tprintf(_T("ҵװű: %s\n"), strScriptPath.GetString()); - // 修改脚本中的版本号(不写回 .rc / AssemblyInfo.cs) + // ޸Ľűеİ汾ţд .rc / AssemblyInfo.cs BOOL bModifyOk = (nSetupType == 0) ? ModifyIssScript(strScriptPath, strProductVersion) : ModifyNshScript(strScriptPath, strProductVersion); if (!bModifyOk) { - _tprintf(_T("错误: 修改安装脚本版本信息失败。\n")); + _tprintf(_T(": ޸İװű汾Ϣʧܡ\n")); return FALSE; } - // 查找编译器 + // ұ CString strCompiler = (nSetupType == 0) ? FindInnoSetupCompiler() : FindNsisCompiler(); @@ -283,12 +283,12 @@ BOOL ExecuteSetupBuild(int nSetupType, const CString& strProductVersion) LPCTSTR lpCompilerName = (nSetupType == 0) ? _T("ISCC.exe (Inno Setup)") : _T("makensis.exe (NSIS)"); - _tprintf(_T("错误: 未找到安装包编译器 %s,请确认已安装并加入 PATH。\n"), lpCompilerName); + _tprintf(_T(": δҵװ %sȷѰװ PATH\n"), lpCompilerName); return FALSE; } - _tprintf(_T("找到编译器: %s\n"), strCompiler.GetString()); + _tprintf(_T("ҵ: %s\n"), strCompiler.GetString()); - // 取脚本所在目录作为工作目录 + // ȡűĿ¼ΪĿ¼ CString strScriptDir = strScriptPath; int nSlash = strScriptDir.ReverseFind(_T('\\')); if (nSlash >= 0) @@ -296,47 +296,47 @@ BOOL ExecuteSetupBuild(int nSetupType, const CString& strProductVersion) strScriptDir = strScriptDir.Left(nSlash); } - // 构建并执行编译命令 + // ִб CString strCmd; strCmd.Format(_T("cmd /c %s %s"), QuoteCmdArg(strCompiler).GetString(), QuoteCmdArg(strScriptPath).GetString()); - _tprintf(_T("执行编译: %s\n"), strCmd.GetString()); + _tprintf(_T("ִб: %s\n"), strCmd.GetString()); CString strOutput = StartProcess(NULL, strCmd.GetBuffer(), strScriptDir.GetString()); strCmd.ReleaseBuffer(); if (strOutput.IsEmpty()) { - _tprintf(_T("警告: 编译器无输出,可能执行失败。\n")); + _tprintf(_T(": ִʧܡ\n")); } return TRUE; } -// ───────────────────────────────────────────── -// 独立命令入口(argv[1] 形如 "-setup=0") -// ───────────────────────────────────────────── +// +// ڣargv[1] "-setup=0" +// int HandleSetupCommand(int argc, TCHAR* argv[]) { - // 解析 -setup=n 中的 n + // -setup=n е n CString strSetupArg = argv[1]; - CString strN = strSetupArg.Mid(7); // 跳过 "-setup=" + CString strN = strSetupArg.Mid(7); // "-setup=" UINT nSetupType = UINT(-1); if (!TryParseUInt16(strN, nSetupType) || (nSetupType != 0 && nSetupType != 1)) { - _tprintf(_T("错误: -setup 参数值 \"%s\" 不支持,仅支持 0(Inno Setup)或 1(NSIS)。\n"), + _tprintf(_T(": -setup ֵ \"%s\" ֧֣֧ 0Inno Setup 1NSIS\n"), strN.GetString()); return 36; } if (argc < 3) { - _tprintf(_T("错误: 参数不足。\n")); - _tprintf(_T("用法:gitver -setup=0|1 [pid] [repodir=可选]\n")); - _tprintf(_T("示例:gitver -setup=0 5\n")); - _tprintf(_T("示例:gitver -setup=1 5 repodir=E:\\Code\\MyProj\n")); + _tprintf(_T(": 㡣\n")); + _tprintf(_T("÷gitver -setup=0|1 [pid] [repodir=ѡ]\n")); + _tprintf(_T("ʾgitver -setup=0 5\n")); + _tprintf(_T("ʾgitver -setup=1 5 repodir=E:\\Code\\MyProj\n")); return 3; } @@ -379,12 +379,12 @@ int HandleSetupCommand(int argc, TCHAR* argv[]) { strProductVersion = strProductVersion.Left(nDot2 + 1) + _T("0.0"); } - _tprintf(_T("[test] 已将 major/minor 置零: ProductVersion=%s\n"), strProductVersion.GetString()); + _tprintf(_T("[test] ѽ major/minor : ProductVersion=%s\n"), strProductVersion.GetString()); } _tprintf(_T("ProductVersion=%s\n"), strProductVersion.GetString()); - // 不回写版本信息到项目文件,直接修改安装脚本并编译打包 + // д汾ϢĿļֱ޸İװű if (!ExecuteSetupBuild((int)nSetupType, strProductVersion)) { return 38; diff --git a/GitVer/GitVer_version.cpp b/GitVer/GitVer_version.cpp index ce235d3..db0fc0c 100644 --- a/GitVer/GitVer_version.cpp +++ b/GitVer/GitVer_version.cpp @@ -6,7 +6,7 @@ BOOL TryGetCurrentBranch(LPCTSTR lpRepoPath, CString& strBranch) { - _tprintf(_T("��ȡ��ǰ��֧���ƣ�\n")); + _tprintf(_T("ȡǰ֧: \n")); strBranch = StartProcess(NULL, _T("cmd /c git rev-parse --abbrev-ref HEAD"), lpRepoPath); strBranch.Replace(_T("\r"), _T("")); strBranch.Replace(_T("\n"), _T("")); @@ -92,7 +92,7 @@ BOOL GetLastMajorMinorTag(LPCTSTR lpRepoPath, const CString& strBranch, CString& CString strTagList = StartProcess(NULL, _T("cmd /c git tag --list --sort=v:refname"), lpRepoPath); if (strTagList.IsEmpty()) { - _tprintf(_T("����: ��ȡ��ǩ�б�ʧ��\n")); + _tprintf(_T(": ȡǩбʧ\n")); return FALSE; } @@ -103,7 +103,7 @@ BOOL GetLastMajorMinorTag(LPCTSTR lpRepoPath, const CString& strBranch, CString& strLine.Trim(); if (strLine.Left(6).CompareNoCase(_T("fatal:")) == 0) { - _tprintf(_T("����: ��ȡ��ǩ�б�ʧ�� %s\n"), strLine.GetString()); + _tprintf(_T(": ȡǩбʧ %s\n"), strLine.GetString()); return FALSE; } @@ -125,7 +125,7 @@ BOOL GetLastMajorMinorTag(LPCTSTR lpRepoPath, const CString& strBranch, CString& void GetFileVersionDateFromSystemTime(const SYSTEMTIME& stLocal, UINT& nYY, UINT& nMMDD) { nYY = stLocal.wYear % 100; - // Ϊ���ð汾�Ŷ���4λ���·ݴ�1-12ӳ�䵽11-22; + // Ϊ汾ļ汾ţ·ӳ䵽1-12ӳ䵽11-22; nMMDD = (stLocal.wMonth + 10) * 100 + stLocal.wDay; } @@ -221,32 +221,32 @@ BOOL ResolveFileVersionDateAndCommitCount(LPCTSTR lpRepoPath, const CString& str UINT nTodayCommitCount = 0; if (!TryGetBranchCommitCountByDate(lpRepoPath, strBranch, stTargetDate, nTodayCommitCount)) { - _tprintf(_T("����: ��ȡ�����ύ����ʧ��\n")); + _tprintf(_T(": ȡύʧ\n")); return FALSE; } if (nTodayCommitCount == 0) { - _tprintf(_T("�����ύ����Ϊ0������ȡ���һ���ύ����\n")); + _tprintf(_T(": ύΪ0Իȡһύ\n")); if (!TryGetLastBranchCommitDate(lpRepoPath, strBranch, stTargetDate)) { - _tprintf(_T("����: ��ȡ���һ���ύ����ʧ��\n")); + _tprintf(_T(": ȡһύʧ\n")); return FALSE; } if (!TryGetBranchCommitCountByDate(lpRepoPath, strBranch, stTargetDate, nTodayCommitCount)) { - _tprintf(_T("����: ��ȡ[%s]�ύ����ʧ��\n"), strBranch.GetString()); + _tprintf(_T(": ȡ [%s] ύʧ\n"), strBranch.GetString()); return FALSE; } - _tprintf(_T("��ȡ�����һ���ύ����: %04u-%02u-%02u, �ύ����: %u\n"), + _tprintf(_T("ȡύϢɹ: %04u-%02u-%02u, ύ: %u\n"), stTargetDate.wYear, stTargetDate.wMonth, stTargetDate.wDay, nTodayCommitCount); } else { - _tprintf(_T("��ȡ�������ύ����: %u\n"), nTodayCommitCount); + _tprintf(_T("ȡύɹ: %u\n"), nTodayCommitCount); } GetFileVersionDateFromSystemTime(stTargetDate, nYY, nMMDD); @@ -263,7 +263,7 @@ int BuildVersionsFromRepo( UINT nDefaultMajor, UINT nDefaultMinor) { - _tprintf(_T("\xBF\xAA\xCA\xBC\xB9\xB9\xBD\xA8\xB0\xE6\xB1\xBE: \xB2\xD6\xBF\xE2\xC2\xB7\xBE\xB6=%s pid=%u default=%u.%u\n"), + _tprintf(_T("ʼ汾: ֿ·=%s pid=%u ĬTag(%u.%u)\n"), lpRepoPath == NULL ? _T("") : lpRepoPath, nPid, nDefaultMajor, @@ -273,17 +273,17 @@ int BuildVersionsFromRepo( CString strBranch; if (!TryGetCurrentBranch(lpRepoPath, strBranch)) { - _tprintf(_T("����: ��ȡ��ǰ��֧ʧ�ܡ�\n")); + _tprintf(_T(": ȡǰ֧ʧ\n")); return errorCodes.nBidErrorCode; } - _tprintf(_T("��ǰ��֧: %s\n"), strBranch.GetString()); + _tprintf(_T("ǰ֧: %s\n"), strBranch.GetString()); if (!TryGetBidFromBranch(strBranch, nBid)) { - _tprintf(_T("����: ��ȡ��֧ bid ʧ��\n")); + _tprintf(_T(": ȡ֧ bid ʧ\n")); return errorCodes.nBidErrorCode; } - _tprintf(_T("��֧ bid: %u\n"), nBid); + _tprintf(_T("֧ bid: %u\n"), nBid); CString strLastTag; UINT nMajor = 0; @@ -292,11 +292,11 @@ int BuildVersionsFromRepo( { nMajor = nDefaultMajor; nMinor = nDefaultMinor; - _tprintf(_T("ʹ��Ĭ�ϱ�ǩ %u %u\n"), nMajor, nMinor); + _tprintf(_T("ʹĬϱǩ %u %u\n"), nMajor, nMinor); } else { - _tprintf(_T("��ȡ���ı�ǩ: %s (major=%u minor=%u)\n"), strLastTag.GetString(), nMajor, nMinor); + _tprintf(_T("ǩ: %s (major=%u minor=%u)\n"), strLastTag.GetString(), nMajor, nMinor); } UINT nYY = 0; @@ -304,13 +304,13 @@ int BuildVersionsFromRepo( UINT nId = 0; if (!ResolveFileVersionDateAndCommitCount(lpRepoPath, strBranch, nYY, nMMDD, nId)) { - _tprintf(_T("����: ��ȡ��֧�ύ��Ϣʧ��\n")); + _tprintf(_T(": ȡ֧ύϢʧ\n")); return errorCodes.nCommitErrorCode; } - _tprintf(_T("��֧�ύ��Ϣ: yy=%u mmdd=%u id=%u\n"), nYY, nMMDD, nId); + _tprintf(_T("֧ύϢ: yy=%u mmdd=%u id=%u\n"), nYY, nMMDD, nId); strProductVersion.Format(_T("%u.%u.%u.%u"), nPid, nBid, nMajor, nMinor); strFileVersion.Format(_T("%u.%u.%u.%u"), nPid, nYY, nMMDD, nId); - _tprintf(_T("�ļ��汾��Ϣ: ProductVersion=%s FileVersion=%s\n"), strProductVersion.GetString(), strFileVersion.GetString()); + _tprintf(_T("ļ汾Ϣ: ProductVersion=%s FileVersion=%s\n"), strProductVersion.GetString(), strFileVersion.GetString()); return 0; } \ No newline at end of file