Răsfoiți Sursa

#IQRV #comment 清空系统桌面图标功能实现

80374374 1 an în urmă
părinte
comite
3553d6c665

+ 89 - 2
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -396,10 +396,13 @@ void ResourceWatcherFSM::AfterInit()
     if (m_bFirstRunAfterBoot) {
 		DetectAutoStartupCover();
         DetectWallpaperAndWarn();
-        ClearDesktopFileTask* task = new ClearDesktopFileTask(this);
+		ClearDesktopFileTask* task = new ClearDesktopFileTask(this);
 		GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
     }
 	DetectVersionHasChangedAndWarnCover();
+    //todo test
+	ClearDesktopFileTask* task = new ClearDesktopFileTask(this);
+	GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
 #else
     if (m_bFirstRunAfterBoot) {
         //获取系统激活状态
@@ -1660,7 +1663,7 @@ int ResourceWatcherFSM::DetectAutoStartupType()
         DWORD dwSize = MAX_PATH * sizeof(TCHAR);
         TCHAR szValue[MAX_PATH + 1] = { 0 };
         memset(szValue, '\0', MAX_PATH + 1);
-        lResult = RegQueryValueEx(hKey, "Shell", NULL, &dwType, (LPBYTE)szValue, &dwSize);
+        lResult = RegQueryValueExA(hKey, "Shell", NULL, &dwType, (LPBYTE)szValue, &dwSize);
         if (lResult == ERROR_SUCCESS) {
             std::string strValue(szValue);
             regeditValue = szValue;
@@ -2036,6 +2039,81 @@ void ResourceWatcherFSM::DetectDestopFileAndWarn(bool bClear, CSimpleStringA& st
     }
 }
 
+bool ResourceWatcherFSM::SetDesktopSysIcon2Registry(const std::string& key, bool toDisplay)
+{
+    bool result(true);
+	DWORD dwFlag = KEY_READ | KEY_WRITE | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS;
+	if (Is32R64Platform() != 0) {
+		dwFlag |= KEY_WOW64_64KEY;
+	}
+	HKEY hKey4Panel;
+	HKEY hKey4StartMenu;
+    DWORD dwCurValue4Panel = (DWORD)-1;
+	DWORD dwCurValue4StartMenu = (DWORD)-1;
+
+	LONG lResult = RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\NewStartPanel", 0, dwFlag, &hKey4Panel);
+    if (lResult == ERROR_SUCCESS) {
+		DWORD dwType = REG_DWORD;
+		DWORD dwValue = 0;
+		DWORD dwSize = sizeof(DWORD);
+        lResult = RegQueryValueExA(hKey4Panel, key.c_str(), NULL, &dwType, (LPBYTE)&dwValue, &dwSize);
+		if (lResult == ERROR_SUCCESS) {
+            dwCurValue4Panel = dwValue;
+            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("NewStartPanel Value of %s: %d", key.c_str(), dwCurValue4Panel);
+		}
+		else {
+            result = false;
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RegQueryValueEx for \"%s\" in NewStartPanel error, result=%ld.", key.c_str(), lResult);
+		}
+    }
+
+	lResult = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\ClassicStartMenu", 0, dwFlag, &hKey4StartMenu);
+	if (lResult == ERROR_SUCCESS) {
+		DWORD dwType = REG_DWORD;
+		DWORD dwValue = 0;
+		DWORD dwSize = sizeof(DWORD);
+		lResult = RegQueryValueExA(hKey4StartMenu, key.c_str(), NULL, &dwType, (LPBYTE)&dwValue, &dwSize);
+		if (lResult == ERROR_SUCCESS) {
+            dwCurValue4StartMenu = dwValue;
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ClassicStartMenu Value of %s: %d", key.c_str(), dwCurValue4StartMenu);
+		}
+		else {
+            result = false;
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RegQueryValueEx for \"%s\" in ClassicStartMenu error, result=%ld.", key.c_str(), lResult);
+		}
+	}
+    const DWORD dwAimValue = toDisplay ? 0 : 1;
+    if (dwCurValue4Panel != (DWORD)(-1) && dwCurValue4Panel != dwAimValue) {
+		DWORD dwType = REG_DWORD;
+		DWORD dwValue = dwAimValue;
+		DWORD dwSize = sizeof(DWORD);
+        lResult = RegSetValueExA(hKey4Panel, key.c_str(), 0, dwType, (BYTE*)&dwValue, dwSize);
+		if (lResult == ERROR_SUCCESS) {
+            DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Set Value with %d for %s in NewStartPanel succ.", dwValue, key.c_str());
+		}
+		else {
+            result = false;
+            DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Set Value with %d for %s  in NewStartPanel error, result=%ld.", key.c_str(), lResult);
+		}
+    }
+	if (dwCurValue4StartMenu != (DWORD)(-1) && dwCurValue4StartMenu != dwAimValue) {
+		DWORD dwType = REG_DWORD;
+		DWORD dwValue = dwAimValue;
+		DWORD dwSize = sizeof(DWORD);
+		lResult = RegSetValueExA(hKey4StartMenu, key.c_str(), 0, dwType, (BYTE*)&dwValue, dwSize);
+		if (lResult == ERROR_SUCCESS) {
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Set Value with %d for %s in ClassicStartMenu succ.", dwValue, key.c_str());
+		}
+		else {
+            result = false;
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Set Value with %d for %s  in ClassicStartMenu error, result=%ld.", key.c_str(), lResult);
+		}
+	}
+    RegCloseKey(hKey4Panel);
+	RegCloseKey(hKey4StartMenu);
+    return result;
+}
+
 void ResourceWatcherFSM::DetectAutoStartFileAndWarn()
 {
     const DWORD INFO_BUFFER_SIZE = 2048;
@@ -2430,6 +2508,7 @@ void ResourceWatcherFSM::VerifySignature(const CSimpleStringA& filePath)
 
 void ResourceWatcherFSM::DetectAndClearDesktopFile()
 {
+    LOG_FUNCTION();
 #if defined(RVC_OS_WIN)
 	CSmartPointer<IConfigInfo> spCtSettingConfig;
 	GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
@@ -2445,6 +2524,14 @@ void ResourceWatcherFSM::DetectAndClearDesktopFile()
 		}
 	}
 	DetectDestopFileAndWarn(!!clearDesktopFlag, strFileWhiteSheet);
+    /** 如果白名单中有{SysIcon}则不清理桌面系统图标  [Gifur@2024830]*/
+    if (!!clearDesktopFlag && (strFileWhiteSheet.IsNullOrEmpty() || strFileWhiteSheet.IndexOf("{sysicon}") == -1)) {
+		SetDesktopSysIcon2Registry("{20D04FE0-3AEA-1069-A2D8-08002B30309D}", false); //此电脑 图标
+		SetDesktopSysIcon2Registry("{645FF040-5081-101B-9F08-00AA002F954E}", false); //回收站 图标
+		SetDesktopSysIcon2Registry("{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}", false); //网络 图标
+		SetDesktopSysIcon2Registry("{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}", false); //控制面板 图标
+		SetDesktopSysIcon2Registry("{59031a47-3f72-44a7-89c5-5595fe6b30ee}", false); //用户的文件 图标
+    }
 #endif //RVC_OS_WIN
 }
 

+ 1 - 0
Module/mod_ResourceWatcher/ResourceWatcherFSM.h

@@ -339,6 +339,7 @@ public:
 	BOOL IsHasSetAutoStartupByFolder(CSimpleStringA& strPath, bool& scriptsType);
 	void DetectVersionHasChangedAndWarn();
 	void DetectDestopFileAndWarn(bool bClear, CSimpleStringA& strFileSaveList);
+	bool SetDesktopSysIcon2Registry(const std::string& key, bool toDisplay);
 	void DetectAutoStartFileAndWarn();
 
 	ErrorCodeEnum DetectVTMInstalledBySetup(BOOL& fYes);