Преглед изворни кода

#IQRV #comment [ResouceWatcher] 判断输入法版本接口优化&调整删除终端版本的逻辑

gifur пре 2 година
родитељ
комит
f7de058425

+ 82 - 240
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -2584,33 +2584,44 @@ int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int
 
 BOOL ResourceWatcherFSM::DeleteVersionPackage()
 {
-#ifdef RVC_OS_LINUX
     BOOL bRet = FALSE;
     ErrorCodeEnum erroCode = Error_Succeed;
     CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
     CSmartPointer<IConfigInfo> spConfigRun;
+    CSmartPointer<IConfigInfo> spConfig;
     CSystemStaticInfo info;
     if (pFunc->GetSystemStaticInfo(info) != Error_Succeed) {
         LogError(Severity_Middle, erroCode, 0, "Get system static info error");
         return FALSE;
     }
-    Dbg("Current version: %s", (LPCTSTR)info.InstallVersion.ToString());
+    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Current version: %s", (LPCTSTR)info.InstallVersion.ToString());
 
+    //判断是否需要被清理
     int nLastTaskTime = 0;
     int nLstFlag = 0;
+    int nDelCount = 0;
     UINT64 utVersion = 0;
+
+    int verSaved = DEFAULT_VERSION_SAVED_COUNT;
+    int tmpSaved = 0;
+    pFunc->OpenConfig(Config_CenterSetting, spConfig);
+    spConfig->ReadConfigValueInt("VersionSaved", "default", tmpSaved);
+    if (tmpSaved > DEFAULT_VERSION_SAVED_COUNT) {
+        verSaved = tmpSaved;
+    }
+
     pFunc->OpenConfig(Config_Run, spConfigRun);
     spConfigRun->ReadConfigValueHexInt("VersionClear", "OptVer", utVersion);
-    spConfigRun->ReadConfigValueInt("VersionClear", "LastCondi", nLstFlag); //last times is failed or not? failed:true
+    spConfigRun->ReadConfigValueInt("VersionClear", "DelVerCnt", nDelCount);
+    spConfigRun->ReadConfigValueInt("VersionClear", "LastCondi", nLstFlag);
     spConfigRun->ReadConfigValueInt("VersionClear", "LastTime", nLastTaskTime);
 
     CVersion optVer(utVersion);
     SYSTEMTIME stTaskTime = CSmallDateTime(nLastTaskTime).ToSystemTime();
-    Dbg("LastTime<%04d-%02d-%02d %02d:%02d:%02d>: OptVer: %s, LastCondi: %d",
-        stTaskTime.wYear, stTaskTime.wMonth, stTaskTime.wDay,
-        stTaskTime.wHour, stTaskTime.wMinute, stTaskTime.wSecond,
-        (LPCTSTR)optVer.ToString(), nLstFlag);
-
+    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("LastTime<%04d-%02d-%02d %02d:%02d:%02d>: OptVer: %s, LastCondi: %d",
+                                                  stTaskTime.wYear, stTaskTime.wMonth, stTaskTime.wDay,
+                                                  stTaskTime.wHour, stTaskTime.wMinute, stTaskTime.wSecond,
+                                                  (LPCTSTR)optVer.ToString(), nLstFlag);
     //判断是否需要被清理
     if (optVer.IsValid() && optVer == info.InstallVersion && !nLstFlag) {
         Dbg("VersionPackage cleaning has been done before.");
@@ -2619,17 +2630,15 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
 
     CSimpleStringA strRunInfo, strStartTime;
     if (m_pEntity->GetFunction()->GetPath("RunInfo", strRunInfo) == Error_Succeed) {
-        strStartTime = strRunInfo + "/runcfg/starttime.dat";
+        strStartTime = strRunInfo + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "starttime.dat";
         if (!ExistsFileA(strStartTime.GetData())) {
-            Dbg("upgrade porcess done, try to delete version files.");//完成升级过程,通过
-        }
-        else {
-            Dbg("upgrade process is not end ,should not delete version files.");
+            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("upgrade prpcess done, try to delete version files.");//完成升级过程,通过
+        } else {
+            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("upgrade process is not end ,should not delete version files.");
             return FALSE;//升级未完成,不进行删除
         }
-    }
-    else {
-        Dbg("upgrade process is not end ,get runinfo path is error, should not delete version files.");
+    } else {
+        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("upgrade process is not end ,get runinfo path is error, should not delete version files.");
         return FALSE;//失败,继续等待
     }
 
@@ -2637,25 +2646,28 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
     CSimpleStringA csPath;
     ErrorCodeEnum Error = m_pEntity->GetFunction()->GetPath("RootVer", csPath);   //获取当前版本路劲 例如:C:\Run
     if (Error_Succeed == Error) {
-        if (csPath.IsNullOrEmpty())
-        {
-            Dbg("get currVer path is null");
+        if (csPath.IsNullOrEmpty()) {
+            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get currVer path is null");
             return FALSE;
+        } else {
+            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CUR VERSION PATH = %s.", csPath.GetData());
         }
-        else
-        {
-            /*csPath.Append("/version");*/
-            Dbg("CUR VERSION PATH = %s.", csPath.GetData());
-        }
-    }
-    else {
-        Dbg("get upgradeVer path is error");
+    } else {
+        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get Ver path error");
         return FALSE;
     }
 
-    //vector<CInstallInfoEx> intallInfoVects;
     vector<CVersion> intallInfoVects;
     vector<string> files;
+
+    CSimpleStringA upPath;
+    ErrorCodeEnum upError = pFunc->GetPath("Upgraded", upPath);
+    if (Error_Succeed != upError) {
+        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get Upgraded path error");
+        return FALSE;
+    }
+
+#ifdef RVC_OS_LINUX
     DIR* dp;
     struct dirent* dirp;
 
@@ -2667,31 +2679,24 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
             int n = sscanf(dirp->d_name, "%d.%d.%d.%d", &dwMajor, &dwMinor, &dwRevision, &dwBuild);
             if (n != 4)
             {
-                Dbg("Not version file.[%s]", dirp->d_name);
+                DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not version file.[%s]", dirp->d_name);
                 continue;
             }
             else {
                 CVersion verName(dwMajor, dwMinor, dwRevision, dwBuild);
                 if (verName.IsValid() && verName < info.InstallVersion)   //对高于自身版本的文件不予删除
                 {
-                    //verInfo.InstallVersion = verName;
                     intallInfoVects.push_back(verName);
                 }
                 else {
-                    Dbg("Not version file.[%s]", dirp->d_name);
+                    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not version file.[%s]", dirp->d_name);
                 }
             }
         }
         closedir(dp);
     }
 
-    CSimpleStringA upPath;
-    ErrorCodeEnum upError = m_pEntity->GetFunction()->GetPath("Upgraded", upPath);
-    if (Error_Succeed != upError) {
-        Dbg("get Upgraded path error");
-        return FALSE;
-    }
-
+    //删除rvc/Upgraded目录下的文件
     DIR* updp;
     struct dirent* updirp;
     if ((updp = opendir(upPath.GetData())) != NULL) {
@@ -2699,156 +2704,19 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
             char szPath[MAX_VERSION_PATH] = { 0 };
             strcat(szPath, upPath.GetData());
             CSimpleStringA tmpDirPath = szPath;
-            strcat(szPath, "/");
+            strcat(szPath, SPLIT_SLASH_STR);
             strcat(szPath, updirp->d_name);
-            Dbg("operating Upgrade path: [%s][%s]", (LPCTSTR)tmpDirPath, szPath);
+            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("operating Upgrade path: [%s][%s]", (LPCTSTR)tmpDirPath, szPath);
             RemoveFileA(szPath);
         }
         closedir(updp);
     }
 
-    int verSaved = DEFAULT_VERSION_SAVED_COUNT;
-    int tmpSaved = 0;
-    CSmartPointer<IEntityFunction> spFunction = this->GetEntityBase()->GetFunction();
-    CSmartPointer<IConfigInfo> spConfig;
-    spFunction->OpenConfig(Config_Software, spConfig);
-    spConfig->ReadConfigValueInt("VersionSaved", "default", tmpSaved);
-    if (tmpSaved > DEFAULT_VERSION_SAVED_COUNT)
-    {
-        verSaved = tmpSaved;
-    }
-
-    int nPackCount = intallInfoVects.size();
-    Dbg("Install Package's count: %d", nPackCount);
-    bool bFailFlag = false;
-    int nDelVersionCnt = 0;
-    if (nPackCount != 0) {
-        int nSavedCount = 0;
-        sort(intallInfoVects.begin(), intallInfoVects.end());
-        //vector<CInstallInfoEx>::iterator iter = intallInfoVects.begin();
-        vector<CVersion>::reverse_iterator riter = intallInfoVects.rbegin();
-        while (riter != intallInfoVects.rend()) {
-            //Dbg("InstallPackage Info: %s, SwithOverDate: %s", (LPCTSTR)iter->InstallVersion.ToString(), (LPCTSTR)iter->tmSwithOverDate.ToTimeString());
-            Dbg("InstallPackage Info: %s", (LPCTSTR)(*riter).ToString());
-            if (++nSavedCount <= verSaved) {
-                Dbg("Save above version");
-                riter++;
-                continue;
-            }
-            //if (!DeleteSpecificeVersionDir(iter->InstallVersion))
-            if (!DeleteSpecificeVersionDir(*riter))
-                bFailFlag = true;
-            else
-                nDelVersionCnt++;
-
-            riter++;
-        }
-    }
-
-    nLstFlag = bFailFlag ? 1 : 0;
-    spConfigRun->WriteConfigValueHexInt("VersionClear", "OptVer", info.InstallVersion.GetVersion64());
-    spConfigRun->WriteConfigValueInt("VersionClear", "LastCondi", nLstFlag);
-    spConfigRun->WriteConfigValue("VersionClear", "LastTime",
-        (LPCTSTR)CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
-
-    string warn = "Delete Version files count : " + to_string(nDelVersionCnt);
-    LogWarn(Severity_Low, Error_Debug, LOG_WARN_VER_DELETE, CSimpleStringA::Format("%s", warn.c_str()));
-
-    return TRUE;
 #else
-    BOOL bRet = FALSE;
-	ErrorCodeEnum erroCode = Error_Succeed;
-	CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
-	CSmartPointer<IConfigInfo> spConfigRun;
-	CSystemStaticInfo& info = m_RvcSysinfo;
-	erroCode = pFunc->GetSystemStaticInfo(info);
-	if (erroCode != Error_Succeed)
-	{
-		LogWarn(Severity_Middle, erroCode, 0, "Get system static info error");
-		return FALSE;
-	}
-
-	//判断是否需要被清理
-	erroCode = pFunc->OpenConfig(Config_Run, spConfigRun);
-	if (erroCode != Error_Succeed)
-	{
-		LogWarn(Severity_Middle, erroCode, 0, "Open Run Config failed");
-		return FALSE;
-	}
-
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Current version: %s", (LPCTSTR)info.InstallVersion.ToString());
-
-	int nLastTaskTime = 0;
-	int nLstFlag = 0;
-	int nDelCount = 0;
-	UINT64 utVersion = 0;
-
-	spConfigRun->ReadConfigValueHexInt("VersionClear", "OptVer", utVersion);
-	spConfigRun->ReadConfigValueInt("VersionClear", "DelVerCnt", nDelCount);
-	spConfigRun->ReadConfigValueInt("VersionClear", "LastCondi", nLstFlag);
-	spConfigRun->ReadConfigValueInt("VersionClear", "LastTime", nLastTaskTime);
-
-	CVersion optVer(utVersion);
-	SYSTEMTIME stTaskTime = CSmallDateTime(nLastTaskTime).ToSystemTime();
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("LastTime<%04d-%02d-%02d %02d:%02d:%02d>: OptVer: %s, LastCondi: %d",
-		stTaskTime.wYear, stTaskTime.wMonth, stTaskTime.wDay,
-		stTaskTime.wHour, stTaskTime.wMinute, stTaskTime.wSecond,
-		(LPCTSTR)optVer.ToString(), nLstFlag);
-	SYSTEMTIME stNow = {};
-	GetLocalTime(&stNow);
-	if (optVer.IsValid() && optVer == info.InstallVersion && !nLstFlag)
-	{
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("VersionPackage cleaning has been done before.");
-		return TRUE;
-	}
-
-	CSimpleStringA strRunInfo, strStartTime;
-	if (m_pEntity->GetFunction()->GetPath("RunInfo", strRunInfo) == Error_Succeed) {
-		strStartTime = strRunInfo + "\\runcfg\\starttime.dat";
-		if (!ExistsFileA(strStartTime.GetData())) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("upgrade prpcess done, try to delete version files.");//完成升级过程,通过
-		}
-		else {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("upgrade process is not end ,should not delete version files.");
-			return FALSE;//升级未完成,不进行删除
-		}
-	}
-	else {
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("upgrade process is not end ,get runinfo path is error, should not delete version files.");
-		return FALSE;//失败,继续等待
-	}
-
-	//获取当前目录下的文件夹名称, 将符合命名规则的终端版本名称push_back
-	CSimpleStringA csPath;
-	ErrorCodeEnum Error = m_pEntity->GetFunction()->GetPath("RootVer", csPath);   //获取当前版本路劲 例如:C:\Run
-	if (Error_Succeed == Error) {
-		if (csPath.IsNullOrEmpty())
-		{
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get currVer path is null");
-			return FALSE;
-		}
-		else
-		{
-			//csPath.Append("\\version");
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CUR VERSION PATH = %s.", csPath.GetData());
-		}
-	}
-	else {
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get Ver path error");
-		return FALSE;
-	}
-
-	//vector<CInstallInfoEx> intallInfoVects;
-	vector<CVersion> intallInfoVects;
-	vector<string> files;
 	long hFile = 0;
 	struct _finddata_t fileinfo;//文件信息读取结构
 	string p;
 
-	/*CSimpleStringA uiState;
-	m_pEntity->GetFunction()->GetSysVar("UIState", uiState);*/
-
-
 	if ((hFile = _findfirst(p.assign(string(csPath.GetData())).append("\\*").c_str(), &fileinfo)) != -1) {
 		do {
 			CInstallInfo verInfo = {};
@@ -2863,7 +2731,6 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
 				CVersion verName(dwMajor, dwMinor, dwRevision, dwBuild);
 				if (verName.IsValid() && verName < info.InstallVersion)
 				{
-					//verInfo.InstallVersion = verName;
 					intallInfoVects.push_back(verName);
 				}
 				else {
@@ -2874,14 +2741,6 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
 		_findclose(hFile);
 	}
 
-
-	CSimpleStringA upPath;
-	ErrorCodeEnum upError = m_pEntity->GetFunction()->GetPath("Upgraded", upPath);
-	if (Error_Succeed != upError) {
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get Upgraded path error");
-		return FALSE;
-	}
-
 	//删除rvc/Upgraded目录下的文件
 	struct _finddata_t upfileinfo;
 	long upFile = 0;
@@ -2891,7 +2750,7 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
 			char szPath[MAX_VERSION_PATH] = { 0 };
 			strcat_s(szPath, upPath.GetData());
 			CSimpleStringA tmpDirPath = szPath;
-			strcat_s(szPath, "\\");
+			strcat_s(szPath, SPLIT_SLASH_STR);
 			strcat_s(szPath, upfileinfo.name);
 			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("operating Upgrade path: [%s][%s]", (LPCTSTR)tmpDirPath, szPath);
 			RemoveFileA(szPath);
@@ -2899,64 +2758,47 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
 		_findclose(upFile);
 	}
 
-	int verSaved = DEFAULT_VERSION_SAVED_COUNT;
-	int tmpSaved = 0;
-	CSmartPointer<IEntityFunction> spFunction = this->GetEntityBase()->GetFunction();
-	CSmartPointer<IConfigInfo> spConfig;
-	spFunction->OpenConfig(Config_CenterSetting, spConfig); //迁移至集中配置下
-	spConfig->ReadConfigValueInt("ResourceWatcher", "VersionSaved", tmpSaved);
-
-	if (tmpSaved > DEFAULT_VERSION_SAVED_COUNT)
-	{
-		verSaved = tmpSaved;
-	}
+#endif // RVC_OS_LINUX
 
-	int nPackCount = intallInfoVects.size();
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Install Package's count: %d", nPackCount);
-	bool bFailFlag = false;
-	int nDelVersionCnt = 0;
-	std::string tInfo("");
+    int nPackCount = intallInfoVects.size();
+    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Install Package's count: %d", nPackCount);
+    bool bFailFlag = false;
+    int nDelVersionCnt = 0;
+    std::string tInfo("");
 
-	if (nPackCount != 0)
-	{
-		int nSavedCount = 0;
-		sort(intallInfoVects.begin(), intallInfoVects.end());
-		//vector<CInstallInfoEx>::iterator iter = intallInfoVects.begin();
-		vector<CVersion>::reverse_iterator riter = intallInfoVects.rbegin();
-		while (riter != intallInfoVects.rend())
-		{
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("InstallPackage Info: %s", (LPCTSTR)(*riter).ToString());
-			if (++nSavedCount <= verSaved)
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Save above version");
-				riter++;
-				continue;
-			}
-			if (!DeleteSpecificeVersionDir(*riter)) bFailFlag = true;
-			else
-			{
-				nDelVersionCnt++;
-				tInfo = tInfo + "|" + std::string((*riter).ToString().GetData());
-			}
-			riter++;
-		}
-	}
+    if (nPackCount != 0) {
+        int nSavedCount = 0;
+        sort(intallInfoVects.begin(), intallInfoVects.end());
+        vector<CVersion>::reverse_iterator riter = intallInfoVects.rbegin();
+        while (riter != intallInfoVects.rend()) {
+            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("InstallPackage Info: %s", (LPCTSTR)(*riter).ToString());
+            if (++nSavedCount <= verSaved) {
+                DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Save above version");
+                riter++;
+                continue;
+            }
+            if (!DeleteSpecificeVersionDir(*riter)) bFailFlag = true;
+            else {
+                nDelVersionCnt++;
+                tInfo = tInfo + "|" + std::string((*riter).ToString().GetData());
+            }
+            riter++;
+        }
+    }
 
-	nLstFlag = bFailFlag ? 1 : 0;
-	spConfigRun->WriteConfigValueHexInt("VersionClear", "OptVer", info.InstallVersion.GetVersion64());
-	spConfigRun->WriteConfigValueInt("VersionClear", "DelVerCnt", nDelCount + nDelVersionCnt);
-	spConfigRun->WriteConfigValueInt("VersionClear", "LastCondi", nLstFlag);
-	spConfigRun->WriteConfigValue("VersionClear", "LastTime",
-		(LPCTSTR)CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
+    nLstFlag = bFailFlag ? 1 : 0;
+    spConfigRun->WriteConfigValueHexInt("VersionClear", "OptVer", info.InstallVersion.GetVersion64());
+    spConfigRun->WriteConfigValueInt("VersionClear", "DelVerCnt", nDelCount + nDelVersionCnt);
+    spConfigRun->WriteConfigValueInt("VersionClear", "LastCondi", nLstFlag);
+    spConfigRun->WriteConfigValue("VersionClear", "LastTime",
+                                  (LPCTSTR)CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
 
-	if (nDelVersionCnt > 0)
-	{
-		std::string warn = "Delete Vesion file count : " + std::to_string((long long)nDelVersionCnt) + ".  ----- " + tInfo + ".";
-		LogWarn(Severity_Low, Error_Debug, LOG_WARN_VER_DELETE, CSimpleStringA::Format("%s", warn.c_str()));
-	}
+    if (nDelVersionCnt > 0) {
+        std::string warn = "Delete Vesion file count : " + std::to_string((long long)nDelVersionCnt) + ".  ----- " + tInfo + ".";
+        LogWarn(Severity_Low, Error_Debug, LOG_WARN_VER_DELETE, CSimpleStringA::Format("%s", warn.c_str()));
+    }
 
-	return TRUE;
-#endif // RVC_OS_LINUX
+    return TRUE;
 }
 
 BOOL ResourceWatcherFSM::DeleteSpecificeVersionDir(CVersion version)

+ 45 - 47
Module/mod_ResourceWatcher/mod_ResourceWatcher.cpp

@@ -163,6 +163,26 @@ struct SogouRunVersionInfo
         }
         return result;
     }
+
+    CVersion ConvertVersion()
+    {
+        CVersion installVer;
+        DWORD dwMajor(0), dwMinor(0), dwRevision(0), dwBuild(0);
+        int n = sscanf(strVersion.GetData(), "%d.%d.%d.%d", &dwMajor, &dwMinor, &dwRevision, &dwBuild);
+        if (n != 4) {
+            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not sogou version.[%s]", strVersion.GetData());
+        } else {
+            installVer = CVersion(dwMajor, dwMinor, dwRevision, dwBuild);
+        }
+        return installVer;
+    }
+
+    //true: 普通调用版本输入法,false: SDK版本输入法
+    bool IsTSFVersion()
+    {
+        CVersion standardVer = CVersion(2, 6, 4, 355); //对比版本为2.4.6.355
+        return (ConvertVersion() >= standardVer);
+    }
 };
 
 struct SogouInstallStateInfo
@@ -1158,7 +1178,8 @@ void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWat
     ErrorCodeEnum tmpResult(Error_Succeed);
     CSimpleStringA tmpMsg(true);
 
-    LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHE_RESTART_THIRDPARTYPROGRAM, CSimpleStringA::Format("RestartThirdPartyProgram: ctx-req context: %d, %d, %d", ctx->Req.type, ctx->Req.reserved1, ctx->Req.reserved2));
+    LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHE_RESTART_THIRDPARTYPROGRAM, 
+            CSimpleStringA::Format("RestartThirdPartyProgram: ctx-req context: %d, %d, %d", ctx->Req.type, ctx->Req.reserved1, ctx->Req.reserved2));
 
     if (ctx->Req.type == 1) 
     {
@@ -1167,21 +1188,11 @@ void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWat
         info.state.strInstallDate = Sogou_GetInstallTime();
         info.program.strInstallDir = Sogou_GetInstallPath();
         info.program.strVersion = Sogou_GetVersion();
-
-        CVersion installVer;
-        DWORD dwMajor(0), dwMinor(0), dwRevision(0), dwBuild(0);
-        int n = sscanf(info.program.strVersion.GetData(), "%d.%d.%d.%d", &dwMajor, &dwMinor, &dwRevision, &dwBuild);
-        if (n != 4)
-        {
-            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not sogou version.[%s]", info.program.strVersion.GetData());
-        }
-        else
-        {
-            installVer = CVersion(dwMajor, dwMinor, dwRevision, dwBuild);
+        if (info.program.strVersion.IsNullOrEmpty()) {
+            info.program.strVersion = TryToGetSogouVersionEx().c_str();
         }
-        CVersion standardVer = CVersion(2, 6, 4, 355); //对比版本为2.4.6.355
 
-        if (installVer < standardVer)
+        if (!info.program.IsTSFVersion())
         {
             //重启搜狗输入法
             static int old_process_id[2] = { -1, -1 };
@@ -1196,8 +1207,7 @@ void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWat
             CAutoArray<CSimpleStringA> msgs(array_size(relate_processes));
             int cnt(0);
 
-            for (int i = 0; i < array_size(relate_processes); ++i)
-            {
+            for (int i = 0; i < array_size(relate_processes); ++i) {
                 int k = -1;
                 for (int j = 0; j < count; ++j) {
                     if (strcmp(processes[j].name, relate_processes[i]) == 0) {
@@ -1205,15 +1215,13 @@ void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWat
                         break;
                     }
                 }
-                if (k != -1)
-                {
+                if (k != -1) {
                     cnt++;
                     old_process_id[k] = processes[k].pid;
-
                     std::string sucContent, failedContent;
                     CSimpleStringA strCmd = CSimpleStringA::Format("kill -9 %d", old_process_id[k]);
                     bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
-                    Dbg("{%s}:{%s}{%s}", strCmd.GetData(), sucContent.c_str(), failedContent.c_str());
+                    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("{%s}:{%s}{%s}", strCmd.GetData(), sucContent.c_str(), failedContent.c_str());
                 }
             }
 
@@ -1229,8 +1237,7 @@ void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWat
                 alive_process_info newProcesses[3];
                 memset(newProcesses, 0, sizeof(newProcesses));
                 osutil_detect_unique_app(relate_processes, array_size(relate_processes), &newCount, newProcesses);
-                for (int i = 0; i < array_size(relate_processes); ++i)
-                {
+                for (int i = 0; i < array_size(relate_processes); ++i) {
                     int k = -1;
                     for (int j = 0; j < count; ++j) {
                         if (strcmp(newProcesses[j].name, relate_processes[i]) == 0 && newProcesses[j].pid > 0) {
@@ -1238,18 +1245,14 @@ void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWat
                             break;
                         }
                     }
-                    if (k != -1)
-                    {
+                    if (k != -1) {
                         cnt2++;
-                        if (newProcesses[k].pid != old_process_id[k])
-                        {
+                        if (newProcesses[k].pid != old_process_id[k]) {
                             notSame++;
-                        }
-                        else
-                        {
+                        } else {
                             tmpResult = Error_Unexpect;
                             CSimpleStringA tmsg = CSimpleStringA::Format("{杀死当前搜狗进程[%s]失败,pid[%d]。}",
-                                newProcesses[k].name, newProcesses[k].pid);
+                                                                         newProcesses[k].name, newProcesses[k].pid);
                             tKillmsg.push_back(tmsg);
                         }
                     }
@@ -1260,17 +1263,12 @@ void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWat
                     tmpMsg = "已杀死搜狗进程。但重启搜狗进程失败,请确认守护进程正常运行。";
                     tmpResult = Error_Unexpect;
                 }
-                else
-                {
-                    if (tKillmsg.size() != 0)
-                    {
-                        for (int i = 0; i < tKillmsg.size(); ++i)
-                        {
+                else {
+                    if (tKillmsg.size() != 0) {
+                        for (int i = 0; i < tKillmsg.size(); ++i) {
                             tmpMsg += tKillmsg[i];
                         }
-                    }
-                    else
-                    {
+                    } else {
                         tmpMsg = "已成功重启搜狗输入法进程。";
                     }
                 }
@@ -1283,13 +1281,13 @@ void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWat
         }
         else
         {
-            tmpResult = Error_Unexpect;
+            tmpResult = Error_NotSupport;
 			tmpMsg = CSimpleStringA::Format("新搜狗版本,不支持重启功能。");
         }
     }
     else
     {
-        tmpResult = Error_NotSupport;
+        tmpResult = Error_Param;
         tmpMsg = CSimpleStringA::Format("接口调用参数错误。");
     }
 
@@ -1317,7 +1315,7 @@ void ResourceWatcherEntity::ProcessDetectThirdPartyProgram(SpReqAnsContext<Resou
         if (res.length() == 0)
         {
             tmpResult = Error_Failed;
-            tmpMsg = "Can't find Sogou Process.";
+            tmpMsg = "当前系统无搜狗进程";
         }
         else
         {
@@ -1325,14 +1323,13 @@ void ResourceWatcherEntity::ProcessDetectThirdPartyProgram(SpReqAnsContext<Resou
         }
     }
 
-
     ctx->Ans.result = tmpResult;
     ctx->Ans.msg = tmpMsg;
-
     ctx->Answer(result);
     return;
 }
 
+
 void ResourceWatcherEntity::CheckProcessStatus()
 {
     vector<string> msg;
@@ -1792,6 +1789,7 @@ ErrorCodeEnum ResourceWatcherEntity::GetSogouPkgDirPath(CSimpleStringA& strPkgPa
     return Error_Succeed;
 }
 
+///**TODO(Gifur@8/11/2023): 合并单屏版本,去除bin目录的干扰 */
 ErrorCodeEnum ResourceWatcherEntity::RunShellScript(LPCTSTR cmdline)
 {
     char app[MAX_PATH] = { '\0' };
@@ -1803,11 +1801,11 @@ ErrorCodeEnum ResourceWatcherEntity::RunShellScript(LPCTSTR cmdline)
     option.params = (char*)cmdline;
     const int res = process_spawn(&option, &process);
     if (0 == res) {
-        Dbg("execute {%s}, pid: %d", cmdline, process->pid);
+        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute {%s}, pid: %d", cmdline, process->pid);
         FREE(process);
         return Error_Succeed;
     } else {
-        Dbg("execute {%s} failed: %d", cmdline, res);
+        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("execute {%s} failed: %d", cmdline, res);
         return Error_Unexpect;
     }
 }
@@ -1817,11 +1815,11 @@ void ResourceWatcherEntity::OnSysVarEvent(const char* pszKey, const char* pszVal
     Dbg("OnSysVarEvent pszKey = %s, pszValue = %s", pszKey, pszValue);
     if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0)) {
         if (_strnicmp(pszValue, "M", strlen("M")) == 0) {
+            ///**TODO(Gifur@8/11/2023): 不要每一次进入首页都进行版本清理,没必要 */
             ClearVersionTask* task = new ClearVersionTask(&m_fsm);
             GetFunction()->PostThreadPoolTask(task);
         }
     }
-
 }
 
 std::string ResourceWatcherEntity::DoCheckCertainProcessStatus(const CAutoArray<CSimpleStringA>& pName)

+ 4 - 0
Module/mod_ResourceWatcher/mod_ResourceWatcher.h

@@ -366,6 +366,10 @@ private:
 		ErrorCodeEnum ConfigMonitorSetting(const UOS::MonitorInfo& config);
 		std::vector<std::string> GetUserNameList(bool bExcludeRoot = false);
 		ErrorCodeEnum RunShellScript(LPCTSTR cmdline);
+
+		/// <summary>
+		/// 通过集中配置检测指定进程是否存在
+		/// </summary>
 		void CheckProcessStatus();