https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5f149287633cd36287d49…
commit 5f149287633cd36287d494e668b6a861e36fdd66
Author: Stanislav Motylkov <x86corez(a)gmail.com>
AuthorDate: Thu Oct 20 04:10:04 2022 +0300
Commit: Stanislav Motylkov <x86corez(a)gmail.com>
CommitDate: Thu Oct 20 04:10:04 2022 +0300
[DESK] Refactor the work with registry parameters
Use SHGet/Set functions instead of talking directly to registry.
This makes the code a lot more simple and readable.
CORE-3567
---
dll/cpl/desk/desktop.c | 132 +++++++++++--------------------------------------
1 file changed, 28 insertions(+), 104 deletions(-)
diff --git a/dll/cpl/desk/desktop.c b/dll/cpl/desk/desktop.c
index 8655a013174..351eea1ee85 100644
--- a/dll/cpl/desk/desktop.c
+++ b/dll/cpl/desk/desktop.c
@@ -26,7 +26,7 @@
*/
#define IDS_PERSONAL 9227
-static const TCHAR szHideDesktopIcons[] =
TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons");
+static const TCHAR szHideDesktopIcons[] =
TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\");
static const TCHAR szClassicStartMenu[] = TEXT("ClassicStartMenu");
static const TCHAR szNewStartPanel[] = TEXT("NewStartPanel");
@@ -62,75 +62,38 @@ struct
VOID
InitDesktopSettings(PDESKTOP_DATA pData)
{
- HKEY regKey, iconKey1, iconKey2;
UINT i;
- DWORD dwType, cbData;
-
- /* Default values */
- for (i = 0; i < _countof(pData->optIcons); i++)
- {
- // pData->optIcons[i].bHideClassic is FALSE by default
- pData->optIcons[i].bHideNewStart = TRUE;
- }
+ TCHAR regPath[MAX_PATH];
/* Load desktop icon settings from the registry */
- if (RegOpenKeyEx(HKEY_CURRENT_USER, szHideDesktopIcons,
- 0, KEY_QUERY_VALUE, ®Key) != ERROR_SUCCESS)
+ StringCchCopy(regPath, _countof(regPath), szHideDesktopIcons);
+ StringCchCat(regPath, _countof(regPath), szClassicStartMenu);
+
+ for (i = 0; i < _countof(pData->optIcons); i++)
{
- goto LoadIcons;
+ pData->optIcons[i].bHideClassic = SHRegGetBoolUSValue(regPath,
DesktopIcons[i].CLSID, FALSE, FALSE);
}
- if (RegOpenKeyEx(regKey, szClassicStartMenu, 0, KEY_QUERY_VALUE, &iconKey1) !=
ERROR_SUCCESS)
- iconKey1 = NULL;
-
- if (RegOpenKeyEx(regKey, szNewStartPanel, 0, KEY_QUERY_VALUE, &iconKey2) !=
ERROR_SUCCESS)
- iconKey2 = NULL;
+ StringCchCopy(regPath, _countof(regPath), szHideDesktopIcons);
+ StringCchCat(regPath, _countof(regPath), szNewStartPanel);
for (i = 0; i < _countof(pData->optIcons); i++)
{
- LSTATUS res;
- DWORD dwData;
-
- if (iconKey1)
- {
- cbData = sizeof(dwData);
- res = RegQueryValueEx(iconKey1, DesktopIcons[i].CLSID, NULL, &dwType,
(LPBYTE)&dwData, &cbData);
-
- if (res == ERROR_SUCCESS && dwType == REG_DWORD && cbData ==
sizeof(dwData))
- pData->optIcons[i].bHideClassic = !!dwData;
- }
-
- if (iconKey2)
- {
- cbData = sizeof(dwData);
- res = RegQueryValueEx(iconKey2, DesktopIcons[i].CLSID, NULL, &dwType,
(LPBYTE)&dwData, &cbData);
-
- if (res == ERROR_SUCCESS && dwType == REG_DWORD && cbData ==
sizeof(dwData))
- pData->optIcons[i].bHideNewStart = !!dwData;
- }
+ pData->optIcons[i].bHideNewStart = SHRegGetBoolUSValue(regPath,
DesktopIcons[i].CLSID, FALSE, TRUE);
}
- if (iconKey1)
- RegCloseKey(iconKey1);
-
- if (iconKey2)
- RegCloseKey(iconKey2);
-
- RegCloseKey(regKey);
-
-LoadIcons:
for (i = 0; i < _countof(IconChange); i++)
{
- TCHAR iconPath[MAX_PATH];
+ DWORD cbData, dwType;
TCHAR szData[MAX_PATH];
/* Current icons */
- StringCchCopy(iconPath, _countof(iconPath), szUserClass);
- StringCchCat(iconPath, _countof(iconPath), IconChange[i].CLSID);
- StringCchCat(iconPath, _countof(iconPath), szDefaultIcon);
+ StringCchCopy(regPath, _countof(regPath), szUserClass);
+ StringCchCat(regPath, _countof(regPath), IconChange[i].CLSID);
+ StringCchCat(regPath, _countof(regPath), szDefaultIcon);
cbData = sizeof(szData);
- if (SHGetValue(HKEY_CURRENT_USER, iconPath, IconChange[i].IconName, &dwType,
+ if (SHGetValue(HKEY_CURRENT_USER, regPath, IconChange[i].IconName, &dwType,
&szData, &cbData) == ERROR_SUCCESS &&
(dwType == REG_SZ || dwType == REG_EXPAND_SZ))
{
@@ -139,12 +102,12 @@ LoadIcons:
/* Default icons */
/* FIXME: Get default icons from theme data, fallback to CLSID data on error. */
- StringCchCopy(iconPath, _countof(iconPath), szSysClass);
- StringCchCat(iconPath, _countof(iconPath), IconChange[i].CLSID);
- StringCchCat(iconPath, _countof(iconPath), szDefaultIcon);
+ StringCchCopy(regPath, _countof(regPath), szSysClass);
+ StringCchCat(regPath, _countof(regPath), IconChange[i].CLSID);
+ StringCchCat(regPath, _countof(regPath), szDefaultIcon);
cbData = sizeof(szData);
- if (SHGetValue(HKEY_CLASSES_ROOT, iconPath, IconChange[i].IconName, &dwType,
+ if (SHGetValue(HKEY_CLASSES_ROOT, regPath, IconChange[i].IconName, &dwType,
&szData, &cbData) == ERROR_SUCCESS &&
(dwType == REG_SZ || dwType == REG_EXPAND_SZ))
{
@@ -194,63 +157,24 @@ SaveDesktopSettings(PDESKTOP_DATA pData)
static BOOL
GetCurrentValue(UINT i, BOOL bNewStart)
{
- HKEY regKey, iconKey;
- LSTATUS res;
- DWORD dwType, cbData;
- BOOL bRet;
-
- /* Set default value */
- bRet = bNewStart;
+ TCHAR regPath[MAX_PATH];
- if (RegOpenKeyEx(HKEY_CURRENT_USER, szHideDesktopIcons,
- 0, KEY_QUERY_VALUE, ®Key) != ERROR_SUCCESS)
- {
- return bRet;
- }
-
- if (RegOpenKeyEx(regKey, (bNewStart ? szNewStartPanel : szClassicStartMenu),
- 0, KEY_QUERY_VALUE, &iconKey) != ERROR_SUCCESS)
- {
- RegCloseKey(regKey);
- return bRet;
- }
+ StringCchCopy(regPath, _countof(regPath), szHideDesktopIcons);
+ StringCchCat(regPath, _countof(regPath), bNewStart ? szNewStartPanel :
szClassicStartMenu);
- cbData = sizeof(bRet);
- res = RegQueryValueEx(iconKey, DesktopIcons[i].CLSID, NULL, &dwType,
(LPBYTE)&bRet, &cbData);
-
- if (res != ERROR_SUCCESS || dwType != REG_DWORD || cbData != sizeof(bRet))
- bRet = bNewStart;
-
- RegCloseKey(iconKey);
- RegCloseKey(regKey);
-
- return bRet;
+ return SHRegGetBoolUSValue(regPath, DesktopIcons[i].CLSID, FALSE, bNewStart);
}
static VOID
SetCurrentValue(UINT i, BOOL bNewStart, BOOL bValue)
{
- HKEY regKey, iconKey;
-
- if (RegCreateKeyEx(HKEY_CURRENT_USER, szHideDesktopIcons,
- 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE,
- NULL, ®Key, NULL) != ERROR_SUCCESS)
- {
- return;
- }
-
- if (RegCreateKeyEx(regKey, (bNewStart ? szNewStartPanel : szClassicStartMenu),
- 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE,
- NULL, &iconKey, NULL) != ERROR_SUCCESS)
- {
- RegCloseKey(regKey);
- return;
- }
+ TCHAR regPath[MAX_PATH];
- RegSetValueEx(iconKey, DesktopIcons[i].CLSID, 0, REG_DWORD, (LPBYTE)&bValue,
sizeof(bValue));
+ StringCchCopy(regPath, _countof(regPath), szHideDesktopIcons);
+ StringCchCat(regPath, _countof(regPath), bNewStart ? szNewStartPanel :
szClassicStartMenu);
- RegCloseKey(iconKey);
- RegCloseKey(regKey);
+ SHSetValue(HKEY_CURRENT_USER, regPath, DesktopIcons[i].CLSID, REG_DWORD,
+ (LPBYTE)&bValue, sizeof(bValue));
}
VOID