Explorar el Código

#IQRV #comment 针对自定义自启动文件的处理

80374374 hace 1 año
padre
commit
ea9f8ea747

+ 218 - 92
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -192,7 +192,7 @@ private:
 ResourceWatcherFSM::ResourceWatcherFSM(void)
     :m_strTerminalNo(true),
     m_bFirstRunAfterBoot(FALSE),
-    m_cpuTop(0)
+    m_cpuTop(0), flag4DeleteKeyAutoStartFile(false)
 {
 #ifdef RVC_OS_WIN
     m_forceStartupWithExeFlag = 0;
@@ -209,7 +209,6 @@ ResourceWatcherFSM::~ResourceWatcherFSM(void)
 
 void ResourceWatcherFSM::s0_on_entry()
 {
-    LOG_FUNCTION();
 #if defined(RVC_OS_WIN)
     this->PostEventFIFO(new RunEvent());
     BOOL fInstallBySetup(FALSE);
@@ -219,7 +218,6 @@ void ResourceWatcherFSM::s0_on_entry()
 
 unsigned int ResourceWatcherFSM::s0_on_event(FSMEvent* e)
 {
-    LOG_FUNCTION();
     unsigned int unRes = 0;
     switch (e->iEvt)
     {
@@ -244,12 +242,10 @@ void ResourceWatcherFSM::s0_on_exit()
 
 void ResourceWatcherFSM::s1_on_entry()
 {
-    LOG_FUNCTION();
 }
 
 unsigned int ResourceWatcherFSM::s1_on_event(FSMEvent* e)
 {
-    LOG_FUNCTION();
     unsigned int unRes = 0;
     e->SetHandled();
     return unRes;
@@ -261,12 +257,10 @@ void ResourceWatcherFSM::s1_on_exit()
 
 void ResourceWatcherFSM::s2_on_entry()
 {
-    LOG_FUNCTION();
 }
 
 unsigned int ResourceWatcherFSM::s2_on_event(FSMEvent* e)
 {
-    LOG_FUNCTION();
     unsigned int unRes = 0;
     switch (e->iEvt)
     {
@@ -285,7 +279,6 @@ void ResourceWatcherFSM::s2_on_exit()
 
 void ResourceWatcherFSM::s3_on_entry()
 {
-    LOG_FUNCTION();
 }
 
 unsigned int ResourceWatcherFSM::s3_on_event(FSMEvent* e)
@@ -464,45 +457,49 @@ ErrorCodeEnum ResourceWatcherFSM::OnExit()
 void ResourceWatcherFSM::AfterInit()
 {
 #if defined(RVC_OS_WIN)
-	do
-	{
-		CSmartPointer<IConfigInfo> spCtSettingConfig;
-		GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
-		CSimpleStringA strFileInterestSheet(true);
-		spCtSettingConfig->ReadConfigValue(GetEntityBase()->GetEntityName(), "AutoStartUserFileSheet", strFileInterestSheet);
-		if (!strFileInterestSheet.IsNullOrEmpty()) {
-			auto fileNames = strFileInterestSheet.Split('|');
-			if (fileNames.GetCount() > 0) {
-				for (int i = 0; i < fileNames.GetCount(); ++i) {
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AutoStartUserFileSheet[%s]", fileNames[i].GetData());
-					keyUserlist.push_back(fileNames[i].GetData());
+
+    if (m_bFirstRunAfterBoot) {
+        DetectWallpaperAndWarn();
+		do
+		{
+			CSmartPointer<IConfigInfo> spCtSettingConfig;
+			GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
+			CSimpleStringA strFileInterestSheet(true);
+			spCtSettingConfig->ReadConfigValue(GetEntityBase()->GetEntityName(), "AutoStartUserFileSheet", strFileInterestSheet);
+			if (!strFileInterestSheet.IsNullOrEmpty()) {
+				auto fileNames = strFileInterestSheet.Split('|');
+				if (fileNames.GetCount() > 0) {
+					for (int i = 0; i < fileNames.GetCount(); ++i) {
+						DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AutoStartUserFileSheet[%s]", fileNames[i].GetData());
+						keyUserlist.push_back(fileNames[i].GetData());
+					}
 				}
 			}
-		}
-		strFileInterestSheet.Clear();
-		spCtSettingConfig->ReadConfigValue(GetEntityBase()->GetEntityName(), "AutoStartPubFileSheet", strFileInterestSheet);
-		if (!strFileInterestSheet.IsNullOrEmpty()) {
-			auto fileNames = strFileInterestSheet.Split('|');
-			if (fileNames.GetCount() > 0) {
-				for (int i = 0; i < fileNames.GetCount(); ++i) {
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AutoStartPubFileSheet[%s]", fileNames[i].GetData());
-					keyPublist.push_back(fileNames[i].GetData());
+			strFileInterestSheet.Clear();
+			spCtSettingConfig->ReadConfigValue(GetEntityBase()->GetEntityName(), "AutoStartPubFileSheet", strFileInterestSheet);
+			if (!strFileInterestSheet.IsNullOrEmpty()) {
+				auto fileNames = strFileInterestSheet.Split('|');
+				if (fileNames.GetCount() > 0) {
+					for (int i = 0; i < fileNames.GetCount(); ++i) {
+						DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AutoStartPubFileSheet[%s]", fileNames[i].GetData());
+						keyPublist.push_back(fileNames[i].GetData());
+					}
 				}
 			}
-		}
-	} while (false);
 
-    if (m_bFirstRunAfterBoot) {
+			//int value(0);
+			//spConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "DeleteCustomAutoStartFile", value);
+	  //      if (!!value) { 
+	  //          DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get DeleteCustomAutoStartFile execute flag from CenterSettings");
+	  //          flag4DeleteKeyAutoStartFile = !!value;
+	  //      }
+		} while (false);
 		DetectAutoStartupCover();
-        DetectWallpaperAndWarn();
 		ClearDesktopFileTask* task = new ClearDesktopFileTask(this);
 		GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
     }
 	DetectVersionHasChangedAndWarnCover();
 
-    DetectAutoStartupCover();
-	ClearDesktopFileTask* task = new ClearDesktopFileTask(this);
-	GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
 #else
     if (m_bFirstRunAfterBoot) {
         //获取系统激活状态
@@ -1402,14 +1399,12 @@ ErrorCodeEnum ResourceWatcherFSM::CheckNetType(
 ErrorCodeEnum ResourceWatcherFSM::GetBizLinks(
     SpReqAnsContext<ResourceWatcherService_GetBizLinks_Req, ResourceWatcherService_GetBizLinks_Ans>::Pointer ctx)
 {
-    LOG_FUNCTION();
     ErrorCodeEnum ec = Error_Succeed;
 
     int filter = ctx->Req.filter;  //后续过滤使用
     CAutoArray<CSimpleStringA> bizLinks;
     CAutoArray<CSimpleStringA> bizNames;
 
-
     CSmartPointer<IConfigInfo> spCtSettingConfig;
     GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
 
@@ -1538,12 +1533,12 @@ bool ResourceWatcherFSM::CreateLinkFile(const CSimpleStringA& szStartAppPath, co
     return bRet;
 }
 
-void ResourceWatcherFSM::CreateLink(const CSimpleStringA& exePath, const CSimpleStringA& csVersion)
+bool ResourceWatcherFSM::CreateLink(int nType, const CSimpleStringA& exePath)
 {
-
+    bool result(false);
 	CSimpleStringA icoPath;
-	ErrorCodeEnum Error = GetEntityBase()->GetFunction()->GetPath("RootVer", icoPath);
-	icoPath = icoPath + "\\" + csVersion.GetData() + "\\bin\\VTM.ico";
+	ErrorCodeEnum Error = GetEntityBase()->GetFunction()->GetPath("Bin", icoPath);
+	icoPath = icoPath + "\\" + "VTM.ico";
 	CSimpleStringA strRvc(true);
 	GetEntityBase()->GetFunction()->GetPath("rvc", strRvc);
 	if (!strRvc.IsNullOrEmpty()) {
@@ -1559,45 +1554,89 @@ void ResourceWatcherFSM::CreateLink(const CSimpleStringA& exePath, const CSimple
 			icoPath = strRvc.GetData();
 		}
 	}
+	if (!ExistsFileA(icoPath)) {
+        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("%s is not exist", icoPath.GetData());
+        return result;
+	}
 
     LPITEMIDLIST lp;
-    SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, &lp);
-    CHAR lstr[100] = "";
-    SHGetPathFromIDList(lp, lstr);
-    CSimpleStringA s = lstr;
-    s += "\\可视柜台.lnk";
-	if (!CreateLinkFile(exePath, "", s, icoPath))
-	{
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("CreateLinkFile DESKTOP fail");
-	}
+	CHAR lstr[MAX_PATH] = "";
+    if (nType == 0) {
+		SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, &lp);
+        memset(lstr, 0, strlen(lstr));
+		SHGetPathFromIDList(lp, lstr);
+		CSimpleStringA s = lstr;
+		s += "\\可视柜台.lnk";
+		if (!(result = CreateLinkFile(exePath, "", s, icoPath))) {
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Create link file for DESKTOP fail");
+        }
+    }
+    else if (nType == 1) {
+		SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &lp);
+		memset(lstr, 0, strlen(lstr));
+		SHGetPathFromIDList(lp, lstr);
+        CSimpleStringA s = lstr;
+		s += "\\可视柜台.lnk";
+		if (!(result = CreateLinkFile(exePath, "", s, icoPath)))
+		{
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Create link file for PROGRAMS fail");
+		}
+    }
+    else if (nType == 2) {
+		SHGetSpecialFolderLocation(0, CSIDL_STARTUP /*CSIDL_COMMON_STARTUP*/, &lp);
+		memset(lstr, 0, strlen(lstr));
+		SHGetPathFromIDList(lp, lstr);
+        CSimpleStringA s = lstr;
+        s += "\\";
+        s += STRATUP_FILENAME_FROM_SCRIPTS;
+		if (!(result = CreateLinkFile(exePath, "", s, icoPath)))
+		{
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Create link file for STARTUP fail");
+		}
+    }
+    else {
+        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("cannot support link create type: %d", nType);
+    }
+    return result;
+}
 
-	SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &lp);
-	memset(lstr, 0, strlen(lstr));
-	SHGetPathFromIDList(lp, lstr);
-	s = lstr;
-	s += "\\可视柜台.lnk";
-	if (!CreateLinkFile(exePath, "", s, icoPath))
-	{
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("CreateLinkFile CSIDL_PROGRAMS fail");
+
+bool ResourceWatcherFSM::GetVTMExePath(CSimpleStringA& strValue, bool FailIfNotExist)
+{
+    bool result(false);
+	CSimpleStringA exePath(true);
+    strValue = "";
+	ErrorCodeEnum rc = GetEntityBase()->GetFunction()->GetPath("RootVer", exePath);
+	if (exePath.IsNullOrEmpty() || rc != Error_Succeed) {
+        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Get RootVer path failed: %s", SpStrError(rc));
+	}
+	else {
+		exePath.Append("\\VTM.exe");
+		if (FailIfNotExist && !ExistsFileA(exePath)) {
+            DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("[% s] is not existed!", exePath.GetData());
+        }
+        else {
+			result = true;
+        }
+		strValue = exePath;
 	}
+    return result;
 }
 
-bool ResourceWatcherFSM::CopyExeToRoot(const CSimpleStringA& csVersion)
+bool ResourceWatcherFSM::CopyExeToRoot(const CSimpleStringA& csVersion, const CSimpleStringA& aimExePath)
 {
-    CSimpleStringA rootVerPath, exePath;
+    CSimpleStringA rootVerPath(true), exePath(true);
     ErrorCodeEnum rc = GetEntityBase()->GetFunction()->GetPath("RootVer", rootVerPath);
-    exePath = rootVerPath + "\\VTM.exe";
-    DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("exePath:%s", exePath.GetData());
     if (rc == Error_Succeed)
     {
         CSimpleStringA srcExePath, csPath = rootVerPath;
 		srcExePath = rootVerPath + "\\" + csVersion.GetData() + "\\bin\\VTM.exe";
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("srcExePath:%s exePath:%s", srcExePath.GetData(), exePath.GetData());
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("srcExePath:%s exePath:%s", srcExePath.GetData());
         if (!ExistsFileA(srcExePath)) {
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("%s is not exist!", srcExePath.GetData());
 			return false;
         }
-		if (!CopyFileA(srcExePath.GetData(), exePath.GetData(), FALSE))
+		if (!CopyFileA(srcExePath.GetData(), aimExePath.GetData(), FALSE))
 		{
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("CopyFileA Fail error :%d ", GetLastError());
 			return false;
@@ -1661,11 +1700,12 @@ bool ResourceWatcherFSM::GetRegValue(HKEY hKey, LPCTSTR lpcszParam,
 /** 方案设计见:https://processon.paas.cmbchina.com/home/view/link/66d12df48139570821109ecf#WIN端应用开机自启动方式优化(实体实现)  [Gifur@2024830]*/
 void ResourceWatcherFSM::DetectAutoStartupCover()
 {
-    const int nStartupType = DetectAutoStartupType();
+    CSimpleStringA strStartupPath(true);
+    const int nStartupType = DetectAutoStartupType(strStartupPath);
     ErrorCodeEnum rc = Error_InvalidState;
     const int setType = InitialAutoStartupSetType();
     /** 是否去移除开始自启动菜单中对应的文件  [Gifur@2024830]*/
-    bool toCheckAndDelteAutostartFile(false);
+    bool toDeleteAutoStartFile(false);
     DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("current startup type:%d, aim start type:%d", nStartupType, setType);
     switch (setType)
     {
@@ -1678,15 +1718,16 @@ void ResourceWatcherFSM::DetectAutoStartupCover()
 		if (nStartupType == 1 || nStartupType == 0 || nStartupType == 3) {
 			rc = ChangeAutoStartupWithExe();
 			if (rc == Error_Succeed && nStartupType == 3) {
-                toCheckAndDelteAutostartFile = true;
+                toDeleteAutoStartFile = true;
 			}
         }
         break;
 	case 5: //设置使用EXE注册表自启动(涵盖所有类型)
-		if (nStartupType == 1 || nStartupType == 0 || nStartupType == 3 || nStartupType == 4) {
+		if (nStartupType == 1 || nStartupType == 0 || nStartupType == 3 || nStartupType == 4 || nStartupType == 5) {
 			rc = ChangeAutoStartupWithExe();
-			if (rc == Error_Succeed && (nStartupType == 3 || nStartupType == 4)) {
-				toCheckAndDelteAutostartFile = true;
+			if (rc == Error_Succeed && (nStartupType == 3 || nStartupType == 4 || nStartupType == 5)) {
+				toDeleteAutoStartFile = true;
+                //这里不做DeleteDuplicateAutoStartFile清理,因为以前也没有问题
 			}
 		}
 		break;
@@ -1694,8 +1735,9 @@ void ResourceWatcherFSM::DetectAutoStartupCover()
 		if (nStartupType == 1 || nStartupType == 2) {
 			rc = ChangeAutoStartupWithExe(false, true);
         }
-        else if (nStartupType == 3 || nStartupType == 4) {
-            toCheckAndDelteAutostartFile = true;
+        else if (nStartupType == 3 || nStartupType == 4 || nStartupType == 5) {
+            toDeleteAutoStartFile = true;
+            //这里不做DeleteDuplicateAutoStartFile清理,因为可以自动的一个一个删除
         }
         break;
     case 4: //恢复VBS启动(防止EXE启动失败),几乎不会用到
@@ -1703,20 +1745,58 @@ void ResourceWatcherFSM::DetectAutoStartupCover()
 			rc = ChangeAutoStartupWithExe(true);
 		}
         break;
+	case 6: //设置为开机后开始菜单自启动(涵盖所有类型)
+    {
+        CSimpleStringA exePath(true);
+        if (GetVTMExePath(exePath, true)) {
+			if (nStartupType == 1 || nStartupType == 2) {
+                //TODO: 如果出现修改注册表成功但是设置自启动图标失败的情况  [Gifur@202492]
+				rc = ChangeAutoStartupWithExe(false, true);
+                if (rc == Error_Succeed) {
+                    rc = CreateLink(2, exePath) ? Error_Succeed : Error_Unexpect;
+                    if (rc != Error_Succeed) {
+						LogWarn(Severity_Middle, Error_InvalidState, LOG_WARN_CREATE_EXELINK_FROMAUTOSTART_FAILED, 
+                            CSimpleStringA::Format("Create autostart lnk failed, old start type: %d", nStartupType));
+                    }
+                    else {
+                        LogWarn(Severity_Low, Error_Debug, LOG_WARN_CREATE_EXELINK_FROMAUTOSTART_SUCC, 
+                            CSimpleStringA::Format("Create autostart lnk succ, old start type: %d", nStartupType));
+                        DeleteDuplicateAutoStartFile(true);
+                    }
+                }
+			}
+			else if (nStartupType == 3 || nStartupType == 5) {
+				rc = CreateLink(2, exePath) ? Error_Succeed : Error_Unexpect;
+				if (rc != Error_Succeed) {
+					LogWarn(Severity_Middle, Error_InvalidState, LOG_WARN_CREATE_EXELINK_FROMAUTOSTART_FAILED, 
+                        CSimpleStringA::Format("Create autostart lnk failed, old start type: %d", nStartupType));
+				}
+				else {
+					LogWarn(Severity_Low, Error_Debug, LOG_WARN_CREATE_EXELINK_FROMAUTOSTART_SUCC, 
+                        CSimpleStringA::Format("Create autostart lnk succ, old start type: %d", nStartupType));
+                    toDeleteAutoStartFile = true;
+                    DeleteDuplicateAutoStartFile(true);
+				}
+			}
+        }
+        else {
+            LogWarn(Severity_Middle, Error_InvalidState, LOG_WARN_CREATE_EXELINK_FROMAUTOSTART_FAILED, 
+                CSimpleStringA::Format("[%s] is not exist", exePath.GetData()));
+        }
+    }
+		break;
     default:
         break;
     }
 
-    if (toCheckAndDelteAutostartFile) {
-		CSimpleStringA strLnkPath(true);
-        int nType;
-		if (IsHasSetAutoStartupByFolder(strLnkPath, nType) && !strLnkPath.IsNullOrEmpty()) {
-			BOOL rmRet = RemoveFileA(strLnkPath);
-            if (!rmRet && ExistsFileA(strLnkPath)) {
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("remove auto start lnk file failed: %s, GLE=%u", strLnkPath.GetData(), GetLastError());
+    if (toDeleteAutoStartFile) {
+		if (!strStartupPath.IsNullOrEmpty() && ExistsFileA(strStartupPath)) {
+			BOOL rmRet = RemoveFileA(strStartupPath);
+            if (!rmRet && ExistsFileA(strStartupPath)) {
+				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("remove auto start lnk file failed: %s, GLE=%u", strStartupPath.GetData(), GetLastError());
             }
             else {
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("remove auto start lnk file: %s", strLnkPath.GetData());
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("remove auto start lnk file: %s", strStartupPath.GetData());
             }
 		}
     }
@@ -1744,7 +1824,7 @@ static int Is32R64Platform()
     return isWow64;
 }
 
-int ResourceWatcherFSM::DetectAutoStartupType()
+int ResourceWatcherFSM::DetectAutoStartupType(CSimpleStringA& strValue)
 {
     LOG_FUNCTION();
 
@@ -1814,11 +1894,13 @@ int ResourceWatcherFSM::DetectAutoStartupType()
 				LogWarn(Severity_Low, Error_Debug, LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU_FROMCUSTOM, strLnkPath);
                 vbsType = 5;
             }
+            regeditValue = strLnkPath;
         }
         else if (vbsType == 0 && explorerSet) {
 			LogWarn(Severity_Low, Error_Debug, LOG_WARN_NOT_AUTO_STARTUP_FROM_REGIST, regeditValue);
         }
     }
+    strValue = regeditValue;
     return vbsType;
 }
 
@@ -1900,6 +1982,53 @@ int ResourceWatcherFSM::InitialAutoStartupSetType()
     return ret;
 }
 
+void ResourceWatcherFSM::DeleteDuplicateAutoStartFile(bool forceDelete)
+{
+	std::vector<std::string> userlist;
+	std::vector<std::string> publist;
+	std::string userPath(""), pubPath("");
+    bool toDelete = forceDelete;
+    if (!toDelete) {
+        toDelete = flag4DeleteKeyAutoStartFile;
+    }
+    if (!toDelete) {
+        DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("do not delete interest auto start file");
+        return;
+    }
+
+	GetAutoStartFile(userPath, userlist, pubPath, publist);
+	if (!keyPublist.empty() || !keyUserlist.empty()) {
+		for (auto it = userlist.cbegin(); keyUserlist.size() > 0 && it != userlist.cend(); ++it) {
+			for (auto kt = keyUserlist.cbegin(); kt != keyUserlist.cend(); ++kt) {
+				CSimpleStringA strfilename(it->c_str());
+				if (strfilename.Compare(kt->c_str()) == 0) {
+					CSimpleStringA fullStartFileNameFromScripts(userPath.c_str());
+					fullStartFileNameFromScripts += "\\";
+					fullStartFileNameFromScripts += strfilename;
+					if (ExistsFileA(fullStartFileNameFromScripts)) {
+                        const auto r = DeleteFileA(fullStartFileNameFromScripts);
+                        DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete AutoStart File:[%s]", fullStartFileNameFromScripts);
+					}
+				}
+			}
+		}
+		for (auto it = publist.cbegin(); keyPublist.size() > 0 && it != publist.cend(); ++it) {
+			for (auto kt = keyPublist.cbegin(); kt != keyPublist.cend(); ++kt) {
+				CSimpleStringA strfilename(it->c_str());
+				if (strfilename.Compare(kt->c_str()) == 0) {
+					CSimpleStringA fullStartFileNameFromScripts(pubPath.c_str());
+					fullStartFileNameFromScripts += "\\";
+					fullStartFileNameFromScripts += strfilename;
+					if (ExistsFileA(fullStartFileNameFromScripts)) {
+						const auto r = DeleteFileA(fullStartFileNameFromScripts);
+						DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete AutoStart File:[%s]", fullStartFileNameFromScripts);
+					}
+				}
+			}
+		}
+	}
+}
+
 BOOL ResourceWatcherFSM::IsHasSetAutoStartupByFolder(CSimpleStringA& strPath, int& setType)
 {
     BOOL result(FALSE);
@@ -1951,7 +2080,7 @@ BOOL ResourceWatcherFSM::IsHasSetAutoStartupByFolder(CSimpleStringA& strPath, in
 	}
     
     if (!result && (!keyPublist.empty() || !keyUserlist.empty())) {
-        //检查是否由用户自定义
+        //检查是否由用户自定义的开机自启动快捷键
 		for (auto it = userlist.cbegin(); !result && keyUserlist.size() > 0 && it != userlist.cend(); ++it) {
 			for (auto kt = keyUserlist.cbegin(); kt != keyUserlist.cend(); ++kt) {
 				CSimpleStringA strfilename(it->c_str());
@@ -2276,8 +2405,8 @@ void ResourceWatcherFSM::DetectAutoStartFileAndWarn()
 
     if (pubAutoCnt + userAutoCnt > 1) {
 		LogWarn(Severity_Low, Error_Debug, LOG_INFO_AUTOSTART_INTEREST_FILESTATUS
-			, CSimpleStringA::Format("{\"subject\":\"duplicate_autostart_file\", \"file_count\":%d, \"user\":\"%s\",\"public\":\"%s\"}"
-				, pubAutoCnt + userAutoCnt, strUserAutoList.c_str(), strPubAutoList.c_str()));
+			, CSimpleStringA::Format("{\"subject\":\"duplicate_vtm_autostart_file\", \"user_count\":%d, \"pub_count\":%d, \"user\":\"%s\",\"public\":\"%s\"}"
+				, userAutoCnt, pubAutoCnt, strUserAutoList.c_str(), strPubAutoList.c_str()));
     }
 }
 
@@ -2400,7 +2529,7 @@ bool ResourceWatcherFSM::RegWtVtmPath(const CSimpleStringA& vtmExtPath, const CS
     }
     else
     {
-        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Get path of VTM.exe failed.");
+        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Vtm.exe path is failed");
     }
 	if (bRet)
 	{
@@ -2413,7 +2542,7 @@ bool ResourceWatcherFSM::RegWtVtmPath(const CSimpleStringA& vtmExtPath, const CS
 	}
 	else
 	{
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Get path of VTM.exe failed.");
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Set path for %s failed", rootPath.GetData());
 	}
     ::RegCloseKey(key);
     return bRet;
@@ -2480,13 +2609,10 @@ bool ResourceWatcherFSM::RegOperation4LnkFile()
     CSimpleStringA  csVersion(true), VtmRegPath(true), VtmRegVersion(true), VtmRegVerPath(true);
     bool bGetActive = GetVtmVersionFromActiveTxt(csVersion);
     bool bRegRead = RegRdVtmVersion(VtmRegPath, VtmRegVersion, VtmRegVerPath);
-
     CSimpleStringA rootVerPath(true), exePath(true);
     ErrorCodeEnum rc = GetEntityBase()->GetFunction()->GetPath("RootVer", rootVerPath);
-    exePath = rootVerPath + "\\VTM.exe";
-
     DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("csVersion :%s ,VtmRegVersion:%s, %d", csVersion.GetData(), VtmRegVersion.GetData(), bRegRead);
-	if (!ExistsFileA(exePath) && !CopyExeToRoot(csVersion))
+	if (GetVTMExePath(exePath, false) && !ExistsFileA(exePath) && !CopyExeToRoot(csVersion, exePath))
 	{
 		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Copy VTM.exe to version root fail.");
 		bRet = false;
@@ -2507,7 +2633,7 @@ bool ResourceWatcherFSM::RegOperation4LnkFile()
     GetUserDesktopDire(s);
 	s += "\\可视柜台.lnk";
     if (bRet && !ExistsFileA(s)) {
-        CreateLink(exePath, csVersion);
+        bRet = CreateLink(0, exePath);
     }
     return bRet;
 }

+ 7 - 4
Module/mod_ResourceWatcher/ResourceWatcherFSM.h

@@ -257,6 +257,7 @@ private:
 
 	std::vector<std::string> keyUserlist;
 	std::vector<std::string> keyPublist;
+	BOOL flag4DeleteKeyAutoStartFile;
 
 public:
 	void CheckDiskFileSpace();
@@ -317,12 +318,14 @@ public:
 	/** 自己摸索,统信说需要操作系统定制方能解决 [Gifur@202198]*/
 	void ConfirmNotificationCenterDisable();
 #else
-	bool CopyExeToRoot(const CSimpleStringA& csVersion);
+	bool GetVTMExePath(CSimpleStringA& strValue, bool FailIfNotExist);
+	bool CopyExeToRoot(const CSimpleStringA& csVersion, const CSimpleStringA& aimExePath);
 	bool RegOperation4LnkFile();
 	bool RegRdVtmVersion(CSimpleStringA& VTMpath, CSimpleStringA& vtmVersion, CSimpleStringA& verPath);
 	bool RegWtVtmPath(const CSimpleStringA& vtmExtPath, const CSimpleStringA& rootPath);
 	bool RegWtVtmVersion(const CSimpleStringA& vtmVer);
-	void CreateLink(const CSimpleStringA& exePath, const CSimpleStringA& csVersion);
+	//nType: 0 桌面,1 开始菜单,2 启动列表
+	bool CreateLink(int nType, const CSimpleStringA& exePath);
 	bool CreateLinkFile(const CSimpleStringA& szStartAppPath, const CSimpleStringA& szAddCmdLine,
 		const CSimpleStringA& szDestLnkPath, const CSimpleStringA& szIconPath);
 	bool GetVtmVersionFromActiveTxt(CSimpleStringA& csVersion);
@@ -337,10 +340,10 @@ public:
 	//4:startmenu lnk from install scripts
 	//5:startmenu lnk from user customization
 	//-1:failed
-	int DetectAutoStartupType();
+	int DetectAutoStartupType(CSimpleStringA& strValue);
 	ErrorCodeEnum ChangeAutoStartupWithExe(bool resetVBS = false, bool resetExplorer = false);
 	int InitialAutoStartupSetType();
-
+	void DeleteDuplicateAutoStartFile(bool forceDelete = false);
 	//0:startmenu lnk from RVCTermimalApplicationSetup
 	//1:startmenu lnk from install scripts
 	//2:startmenu lnk from user customization

+ 9 - 3
Module/mod_ResourceWatcher/ResourceWatcher_UserCode.h

@@ -60,12 +60,18 @@
 #define LOG_WARN_NOT_AUTO_STARTUP_FROM_REGIST 0x50A00042 //注册表未注册自启动(默认是explorer.exe)
 #define LOG_WARN_CHECK_AUTO_STARTUP_FROM_REGIST_FAILED 0x50A00043
 #define LOG_WARN_CHECK_AUTO_STARTUP_WITH_EXE 0x50A00044//注册VTM.exe自启动
-#define LOG_WARN_UPDATE_AUTO_STARTUP_WITH_EXE_SUCC 0x50A00045
-#define LOG_WARN_UPDATE_AUTO_STARTUP_WITH_EXE_FAILED 0x50A00046
+#define LOG_WARN_UPDATE_AUTO_STARTUP_WITH_EXE_SUCC 0x50A00045 //切换设置注册表成功
+#define LOG_WARN_UPDATE_AUTO_STARTUP_WITH_EXE_FAILED 0x50A00046 //切换设置注册表失败
 #define LOG_WARN_CHECK_AUTO_STARTUP_UNKNOWN 0x50A00047 //注册表未知内容
 #define LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU_FROMSETUP 0x50A00048 //开始菜单里设置开机自启动(通过安装程序RVCTerminalApplicationSetup)
 #define LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU_FROMSCRIPT 0x50A00049 //开始菜单里设置开机自启动(通过安装脚本)
-#define LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU_FROMCUSTOM 0x50A0004A //开始菜单里设置开机自启动(厂商或分行捣鼓)
+#define LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU_FROMCUSTOM 0x50A0004A //开始菜单里设置开机自启动(厂商或分行捣鼓的启动快捷方式文件)
+
+#define LOG_WARN_CREATE_EXELINK_FROMDESKTOP_SUCC 0x50A0004B //设置桌面图标成功
+#define LOG_WARN_CREATE_EXELINK_FROMDESKTOP_FAILED 0x50A0004C //设置桌面图标失败
+#define LOG_WARN_CREATE_EXELINK_FROMAUTOSTART_SUCC 0x50A0004D //设置自启动应用图标成功
+#define LOG_WARN_CREATE_EXELINK_FROMAUTOSTART_FAILED 0x50A0004E //设置自启动应用图标失败
+
 
 
 #define LOG_WARN_GET_FILE_CONTENT 0x50A00050

+ 0 - 1
Module/mod_ResourceWatcher/mod_ResourceWatcher.h

@@ -65,7 +65,6 @@ public:
 
 	virtual CServerSessionBase* OnNewSession(const char*, const char*)
 	{
-		LOG_FUNCTION();
 		return new ResourceWatcherServiceSession(this);
 	}