فهرست منبع

添加SetCurrentDirectory设置,因为调用者程序不与自身在同一目录,导致git命令无效.

Jeff Wang 3 سال پیش
والد
کامیت
c4c49bb3d8
1فایلهای تغییر یافته به همراه13 افزوده شده و 3 حذف شده
  1. 13 3
      gitver/gitver/gitver.cpp

+ 13 - 3
gitver/gitver/gitver.cpp

@@ -43,6 +43,9 @@ void GetDirInfo()
 		strVal = strVal.Right(strVal.GetLength() - nPos -1);
 		_stprintf_s(g_szFolderName, _T("%s"), strVal.GetString());
 	}
+
+    // 必须要设置为当前路径为程序路径,因为外部调用者目录不同;
+    SetCurrentDirectory(g_szCurModuleDir);
 }
 
 BOOL ReplaceFileContent(LPCTSTR lpFile, std::vector<std::string> &vtOldContent, std::vector<std::string> &vtNewContent)
@@ -158,6 +161,8 @@ CString StartProcess(LPCTSTR program, LPTSTR args, LPCTSTR lpCurrentDirectory )
     CloseHandle(hPipeRead);
     CloseHandle(hPipeWrite);
 
+    printf(_T("程序:%s \n参数:%s \n运行目录:%s \n运行结果:%s\n"), program == NULL ? "None" : program , args == NULL ? "None":args, lpCurrentDirectory == NULL ? "None" : lpCurrentDirectory, strValue.GetString());
+
     return strValue;
 }
 
@@ -183,7 +188,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
             nCodeType = _tstoi(argv[1]);
         
 #ifdef _DEBUG
-        CString strValue = StartProcess(NULL, "cmd /c git rev-parse --short HEAD", _T("E:\\CFG\\Moka_CShare_FactoryTool\\FactoryTool_CShare"));
+        CString strValue = StartProcess(NULL, "cmd /c git rev-parse --short HEAD", _T("F:\\cfg\\Moka_CShare_FactoryTool\\FactoryTool_CShare"));
 #else
 		CString strValue = StartProcess(NULL, "cmd /c git rev-parse --short HEAD", NULL);
 #endif
@@ -204,7 +209,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 			// 问题:当commitid长度超过4位数字时,FileVersion放不下这么多字符;
 			_stprintf_s(szResFile, _T("%s\\%s.rc"), g_szCurModuleDir, g_szFolderName);
             // 先checkout 资源文件;
-            _stprintf_s(szValue, _T("cmd /c git checkout %s.rc"), g_szFolderName);
+            _stprintf_s(szValue, _T("cmd /c git checkout .\\%s.rc"), g_szFolderName);
             StartProcess(NULL, szValue, NULL);
 
 #if 0
@@ -233,9 +238,14 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 		else if ( nCodeType == 2 )
 		{
             
+#ifdef _DEBUG
+            SetCurrentDirectory(_T("F:\\cfg\\Moka_CShare_FactoryTool\\FactoryTool_CShare"));
+            _stprintf_s(szResFile, _T("%s\\Properties\\AssemblyInfo.cs"), _T("F:\\cfg\\Moka_CShare_FactoryTool\\FactoryTool_CShare"));
+#else
 			_stprintf_s(szResFile, _T("%s\\Properties\\AssemblyInfo.cs"), g_szCurModuleDir);
+#endif
             // 先checkout 资源文件;
-            _stprintf_s(szValue, _T("cmd /c git checkout %s"), _T("Properties\\AssemblyInfo.cs"));
+            _stprintf_s(szValue, _T("cmd /c git checkout %s"), _T(".\\Properties\\AssemblyInfo.cs"));
             StartProcess(NULL, szValue, NULL);
 
 #if 0