Эх сурвалжийг харах

Z991239-5709 #comment 公共库ShellExecute新增windows实现;增加拷贝完成后depver.txt写入

oilyang 11 сар өмнө
parent
commit
f3b4931dfc

+ 42 - 6
Module/include/CommEntityUtil.hpp

@@ -566,18 +566,54 @@ static std::string formatTime(const SYSTEMTIME& time)
 
 static bool ShellExecute(const std::string& cmd, std::string& succResult, std::string& errResult)
 {
+	succResult = errResult = "";
+	char ps[1024] = { 0 };
+	strcpy(ps, cmd.c_str());
 #if defined(_MSC_VER)
-    ///*TODO(80374374@3/7/2023):  */
-    return false;
+	STARTUPINFO si;
+	PROCESS_INFORMATION pi;
+
+	ZeroMemory(&si, sizeof(si));
+	si.cb = sizeof(si);
+	// 设置STARTUPINFO的wShowWindow成员为SW_HIDE,以隐藏窗口
+	si.wShowWindow = SW_HIDE;
+	ZeroMemory(&pi, sizeof(pi));
+
+	// 使用CreateProcess启动程序
+	if (!CreateProcess(NULL,   // 不使用模块名
+		ps, // 命令行
+		NULL,           // 不继承进程句柄
+		NULL,           // 不继承线程句柄
+		FALSE,          // 不继承句柄
+		0,              // 没有创建标志
+		NULL,           // 使用父进程的环境块
+		NULL,           // 使用父进程的当前目录
+		&si,            // 指向STARTUPINFO的指针
+		&pi)            // 指向PROCESS_INFORMATION的指针
+		) {
+		errResult = errResult + "CreateProcess failed with error:" + strerror(GetLastError());
+		return false;
+	}
+
+	// 等待程序结束,并获取其退出状态
+	WaitForSingleObject(pi.hProcess, INFINITE);
+	DWORD exitCode;
+	if (!GetExitCodeProcess(pi.hProcess, &exitCode)) {
+		errResult = errResult + "GetExitCodeProcess failed with error code " + strerror(GetLastError());
+		return false;
+	}
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("The program exited with code:%d", exitCode);
+
+	// 关闭进程和线程句柄
+	CloseHandle(pi.hProcess);
+	CloseHandle(pi.hThread);
+
+	return true;
 #else
 	char buf_ps[1024];
-	char ps[1024] = { 0 };
 	char result[2049] = { 0 };
 	FILE* ptr;
 
-	strcpy(ps, cmd.c_str());
-	succResult = errResult = "";
-
 	if ((ptr = popen(ps, "r")) != NULL) {
 		while (fgets(buf_ps, 1024, ptr) != NULL) {
 			if (strlen(result) + strlen(buf_ps) > 2048)

+ 24 - 15
Module/mod_vtmloader/VtmLoaderFSM.cpp

@@ -1781,13 +1781,13 @@ bool CVtmLoaderFSM::GetConfig()
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[DepBak]%s,%s", SpStrError(ec), csDepPath.GetData());
 		} while (false);
 
-		do
-		{
-			//更新适配器版本号文件内容
-			CSimpleStringA csVersion("0.0.0.2");
-			ec1 = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RewriteDepVersion(csVersion, true);
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[RewriteDepVersion] %s,%s", SpStrError(ec1), csVersion.GetData());
-		} while (false);
+		//do
+		//{
+		//	//更新适配器版本号文件内容
+		//	CSimpleStringA csVersion("0.0.0.2");
+		//	ec1 = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RewriteDepVersion(csVersion, true);
+		//	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[RewriteDepVersion] %s,%s", SpStrError(ec1), csVersion.GetData());
+		//} while (false);
 
 
 		do 
@@ -2970,11 +2970,12 @@ bool CVtmLoaderFSM::CheckIfNeedCopyDepFiles()
 #else
 	if (access(csPath.GetData(), F_OK) == 0) {
 #endif
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("depver.txt(%s) exist, no need to do dep copy.", csPath.GetData());
 		return false;
 	}
 	else
 	{
-		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("depver.txt(%s) is not exist.", csPath.GetData());
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("depver.txt(%s) is not exist.", csPath.GetData());
 		return true;
 	}
 }
@@ -3008,15 +3009,23 @@ void CVtmLoaderFSM::CopyDepFilesToNewDepPath()
 	}
 	//xcopy C:\sourceDir C:\destDir /E /I /Y
 	//cp -r /path/to/source /path/to/destination
-#if defined(RVC_OS_WIN)
-	CSimpleStringA csCmd;
-	csCmd = CSimpleStringA::Format("xcopy %s %s /E /I /Y", csDepBakPath.GetData(), csPath.GetData());
-	WinExec((LPCSTR)csCmd, SW_HIDE);
-
-#else
 	std::string sucContent, failedContent;
 	CSimpleStringA strCmd;
+#if defined(RVC_OS_WIN)
+	strCmd = CSimpleStringA::Format("xcopy %s %s /E /I /Y", csDepBakPath.GetData(), csPath.GetData());
+#else
 	strCmd = CSimpleStringA::Format("cp -r %s %s", csDepBakPath.GetData(), csPath.GetData());
-	bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
 #endif //RVC_OS_WIN
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to execute:%s", strCmd.GetData());
+	ULONGLONG ullCopyBeginTick = SP::Module::Comm::RVCGetTickCount();
+	bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
+	ULONGLONG ullCopyEndTick = SP::Module::Comm::RVCGetTickCount();
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ret:%d, sucContent:%s, failedContent:%s, costtime(ms):%d", ret, sucContent.c_str(), failedContent.c_str(), ullCopyEndTick - ullCopyBeginTick);
+	if (ret)
+	{
+		//更新适配器版本号文件内容
+		CSimpleStringA csVersion("0.0.0.1");
+		eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RewriteDepVersion(csVersion, true);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[RewriteDepVersion] %s,%s", SpStrError(eErr), csVersion.GetData());
+	}
 }