https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8a3080151668efc99be9e…
commit 8a3080151668efc99be9e7a2fb22a24392c85ea3
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Jul 7 15:57:01 2019 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Jul 7 17:56:51 2019 +0200
[SHELL32] Recycle-Bin: Minor code enhancements.
- Use _countof() and ZeroMemory().
- Fix case of 'BitBucket' registry key (Windows-compatible).
- Simplify code.
- Minor code formatting.
---
boot/bootdata/hivesft.inf | 4 +-
dll/win32/shell32/dialogs/recycler_prop.cpp | 67 +++++++++++------------------
dll/win32/shell32/folders/CRecycleBin.cpp | 24 +++++------
3 files changed, 40 insertions(+), 55 deletions(-)
diff --git a/boot/bootdata/hivesft.inf b/boot/bootdata/hivesft.inf
index 330101a29db..818d26745a4 100644
--- a/boot/bootdata/hivesft.inf
+++ b/boot/bootdata/hivesft.inf
@@ -456,8 +456,8 @@
HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce","InstallRoot.NET",0x000
HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons",,0x00000012
HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu",,0x00000012
HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu","{208D2C60-3AEA-1069-A2D7-08002B30309D}",0x00010001,0x00000000
-HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Bitbucket",,0x00000012
-HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Bitbucket\Volume",,0x00000012
+HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\BitBucket",,0x00000012
+HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume",,0x00000012
; CMD Settings
HKLM,"SOFTWARE\Microsoft\Command
Processor","AutoRun",0x00020000,""
diff --git a/dll/win32/shell32/dialogs/recycler_prop.cpp
b/dll/win32/shell32/dialogs/recycler_prop.cpp
index 95840be7699..f6efad5e4ad 100644
--- a/dll/win32/shell32/dialogs/recycler_prop.cpp
+++ b/dll/win32/shell32/dialogs/recycler_prop.cpp
@@ -25,9 +25,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(CRecycleBin);
typedef struct
{
- DWORD dwNukeOnDelete;
DWORD dwSerial;
DWORD dwMaxCapacity;
+ DWORD dwNukeOnDelete;
} DRIVE_ITEM_CONTEXT, *PDRIVE_ITEM_CONTEXT;
static void toggleNukeOnDeleteOption(HWND hwndDlg, BOOL bEnable)
@@ -46,11 +46,9 @@ static void toggleNukeOnDeleteOption(HWND hwndDlg, BOOL bEnable)
}
}
-
static VOID
InitializeRecycleBinDlg(HWND hwndDlg, WCHAR DefaultDrive)
{
- WCHAR CurDrive = L'A';
WCHAR szDrive[] = L"A:\\";
DWORD dwDrives;
WCHAR szName[100];
@@ -70,12 +68,12 @@ InitializeRecycleBinDlg(HWND hwndDlg, WCHAR DefaultDrive)
hDlgCtrl = GetDlgItem(hwndDlg, 14000);
- if (!LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_LOCATION, szVolume,
sizeof(szVolume) / sizeof(WCHAR)))
+ if (!LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_LOCATION, szVolume,
_countof(szVolume)))
szVolume[0] = 0;
GetClientRect(hDlgCtrl, &rect);
- memset(&lc, 0, sizeof(LV_COLUMN) );
+ ZeroMemory(&lc, sizeof(lc));
lc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT;
columnSize = 140; //FIXME
@@ -86,7 +84,7 @@ InitializeRecycleBinDlg(HWND hwndDlg, WCHAR DefaultDrive)
lc.pszText = szVolume;
(void)SendMessageW(hDlgCtrl, LVM_INSERTCOLUMNW, 0, (LPARAM)&lc);
- if (!LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_DISKSPACE, szVolume,
sizeof(szVolume) / sizeof(WCHAR)))
+ if (!LoadStringW(shell32_hInstance, IDS_RECYCLEBIN_DISKSPACE, szVolume,
_countof(szVolume)))
szVolume[0] = 0;
lc.iSubItem = 1;
@@ -99,33 +97,32 @@ InitializeRecycleBinDlg(HWND hwndDlg, WCHAR DefaultDrive)
itemCount = 0;
do
{
- if ((dwDrives & 0x1))
+ if (dwDrives & 0x1)
{
UINT Type = GetDriveTypeW(szDrive);
if (Type == DRIVE_FIXED) //FIXME
{
- if (!GetVolumeInformationW(szDrive, szName, sizeof(szName) /
sizeof(WCHAR), &dwSerial, &MaxComponent, &Flags, NULL, 0))
+ if (!GetVolumeInformationW(szDrive, szName, _countof(szName),
&dwSerial, &MaxComponent, &Flags, NULL, 0))
{
szName[0] = 0;
dwSerial = -1;
}
swprintf(szVolume, L"%s (%c:)", szName, szDrive[0]);
- memset(&li, 0x0, sizeof(LVITEMW));
+ ZeroMemory(&li, sizeof(li));
li.mask = LVIF_TEXT | LVIF_PARAM;
li.iSubItem = 0;
li.pszText = szVolume;
li.iItem = itemCount;
SendMessageW(hDlgCtrl, LVM_INSERTITEMW, 0, (LPARAM)&li);
- if (GetDiskFreeSpaceExW(szDrive, &FreeBytesAvailable ,
&TotalNumberOfBytes, &TotalNumberOfFreeBytes))
+ if (GetDiskFreeSpaceExW(szDrive, &FreeBytesAvailable,
&TotalNumberOfBytes, &TotalNumberOfFreeBytes))
{
- if (StrFormatByteSizeW(TotalNumberOfFreeBytes.QuadPart, szVolume,
sizeof(szVolume) / sizeof(WCHAR)))
+ if (StrFormatByteSizeW(TotalNumberOfFreeBytes.QuadPart, szVolume,
_countof(szVolume)))
{
-
pItem = (DRIVE_ITEM_CONTEXT *)HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, sizeof(DRIVE_ITEM_CONTEXT));
if (pItem)
{
- swprintf(szName,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Bitbucket\\Volume\\%04X-%04X",
LOWORD(dwSerial), HIWORD(dwSerial));
+ swprintf(szName,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\BitBucket\\Volume\\%04X-%04X",
LOWORD(dwSerial), HIWORD(dwSerial));
dwSize = sizeof(DWORD);
RegGetValueW(HKEY_CURRENT_USER, szName,
L"MaxCapacity", RRF_RT_DWORD, NULL, &pItem->dwMaxCapacity, &dwSize);
dwSize = sizeof(DWORD);
@@ -134,7 +131,7 @@ InitializeRecycleBinDlg(HWND hwndDlg, WCHAR DefaultDrive)
li.mask = LVIF_PARAM;
li.lParam = (LPARAM)pItem;
(void)SendMessageW(hDlgCtrl, LVM_SETITEMW, 0,
(LPARAM)&li);
- if (CurDrive == DefaultDrive)
+ if (szDrive[0] == DefaultDrive)
{
defIndex = itemCount;
pDefault = pItem;
@@ -153,10 +150,9 @@ InitializeRecycleBinDlg(HWND hwndDlg, WCHAR DefaultDrive)
itemCount++;
}
}
- CurDrive++;
- szDrive[0] = CurDrive;
+ szDrive[0]++;
dwDrives = (dwDrives >> 1);
- } while(dwDrives);
+ } while (dwDrives);
if (!pDefault)
pDefault = pFirst;
@@ -171,7 +167,6 @@ InitializeRecycleBinDlg(HWND hwndDlg, WCHAR DefaultDrive)
li.state = LVIS_FOCUSED | LVIS_SELECTED;
li.iItem = defIndex;
(void)SendMessageW(hDlgCtrl, LVM_SETITEMW, 0, (LPARAM)&li);
-
}
static BOOL StoreDriveSettings(HWND hwndDlg)
@@ -184,8 +179,7 @@ static BOOL StoreDriveSettings(HWND hwndDlg)
WCHAR szSerial[20];
DWORD dwSize;
-
- if (RegCreateKeyExW(HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Bitbucket\\Volume", 0,
NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
+ if (RegCreateKeyExW(HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\BitBucket\\Volume", 0,
NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
return FALSE;
iCount = ListView_GetItemCount(hDlgCtrl);
@@ -193,7 +187,7 @@ static BOOL StoreDriveSettings(HWND hwndDlg)
ZeroMemory(&li, sizeof(li));
li.mask = LVIF_PARAM;
- for(iIndex = 0; iIndex < iCount; iIndex++)
+ for (iIndex = 0; iIndex < iCount; iIndex++)
{
li.iItem = iIndex;
if (SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
@@ -202,17 +196,16 @@ static BOOL StoreDriveSettings(HWND hwndDlg)
swprintf(szSerial, L"%04X-%04X", LOWORD(pItem->dwSerial),
HIWORD(pItem->dwSerial));
if (RegCreateKeyExW(hKey, szSerial, 0, NULL, 0, KEY_WRITE, NULL,
&hSubKey, NULL) == ERROR_SUCCESS)
{
- dwSize = sizeof(DWORD);
- RegSetValueExW(hSubKey, L"NukeOnDelete", 0, REG_DWORD,
(LPBYTE)&pItem->dwNukeOnDelete, dwSize);
dwSize = sizeof(DWORD);
RegSetValueExW(hSubKey, L"MaxCapacity", 0, REG_DWORD,
(LPBYTE)&pItem->dwMaxCapacity, dwSize);
+ dwSize = sizeof(DWORD);
+ RegSetValueExW(hSubKey, L"NukeOnDelete", 0, REG_DWORD,
(LPBYTE)&pItem->dwNukeOnDelete, dwSize);
RegCloseKey(hSubKey);
}
}
}
RegCloseKey(hKey);
return TRUE;
-
}
static VOID FreeDriveItemContext(HWND hwndDlg)
@@ -226,18 +219,18 @@ static VOID FreeDriveItemContext(HWND hwndDlg)
ZeroMemory(&li, sizeof(li));
li.mask = LVIF_PARAM;
- for(iIndex = 0; iIndex < iCount; iIndex++)
+ for (iIndex = 0; iIndex < iCount; iIndex++)
{
li.iItem = iIndex;
if (SendMessageW(hDlgCtrl, LVM_GETITEMW, 0, (LPARAM)&li))
{
- HeapFree(GetProcessHeap(), 0, (LPVOID)li.lParam);
+ HeapFree(GetProcessHeap(), 0, (PVOID)li.lParam);
}
}
}
static INT
-GetDefaultItem(HWND hwndDlg, LVITEMW * li)
+GetDefaultItem(HWND hwndDlg, LVITEMW* li)
{
HWND hDlgCtrl;
UINT iItemCount, iIndex;
@@ -252,7 +245,7 @@ GetDefaultItem(HWND hwndDlg, LVITEMW * li)
ZeroMemory(li, sizeof(LVITEMW));
li->mask = LVIF_PARAM | LVIF_STATE;
- li->stateMask = (UINT) - 1;
+ li->stateMask = (UINT)-1;
for (iIndex = 0; iIndex < iItemCount; iIndex++)
{
li->iItem = iIndex;
@@ -263,7 +256,6 @@ GetDefaultItem(HWND hwndDlg, LVITEMW * li)
}
}
return -1;
-
}
static INT_PTR CALLBACK
@@ -271,8 +263,7 @@ RecycleBinDlg(
HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
- LPARAM lParam
-)
+ LPARAM lParam)
{
LPPSHNOTIFY lppsn;
LPNMLISTVIEW lppl;
@@ -387,12 +378,10 @@ BOOL SH_ShowRecycleBinProperties(WCHAR sDrive)
HPROPSHEETPAGE hpsp[1];
PROPSHEETHEADERW psh;
HPROPSHEETPAGE hprop;
+ INT_PTR ret;
- BOOL ret;
-
-
- ZeroMemory(&psh, sizeof(PROPSHEETHEADERW));
- psh.dwSize = sizeof(PROPSHEETHEADERW);
+ ZeroMemory(&psh, sizeof(psh));
+ psh.dwSize = sizeof(psh);
psh.dwFlags = PSP_DEFAULT | PSH_PROPTITLE;
psh.pszCaption = MAKEINTRESOURCEW(IDS_RECYCLEBIN_FOLDER_NAME);
psh.hwndParent = NULL;
@@ -408,10 +397,6 @@ BOOL SH_ShowRecycleBinProperties(WCHAR sDrive)
hpsp[psh.nPages] = hprop;
psh.nPages++;
-
ret = PropertySheetW(&psh);
- if (ret < 0)
- return FALSE;
- else
- return TRUE;
+ return (ret >= 0);
}
diff --git a/dll/win32/shell32/folders/CRecycleBin.cpp
b/dll/win32/shell32/folders/CRecycleBin.cpp
index ad80c9dbc73..e2198897fdc 100644
--- a/dll/win32/shell32/folders/CRecycleBin.cpp
+++ b/dll/win32/shell32/folders/CRecycleBin.cpp
@@ -320,30 +320,30 @@ HRESULT WINAPI CRecycleBinItemContextMenu::QueryContextMenu(HMENU
hMenu, UINT in
TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x
)\n", this, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
- if (LoadStringW(shell32_hInstance, IDS_RESTORE, szBuffer, sizeof(szBuffer) /
sizeof(WCHAR)))
+ if (LoadStringW(shell32_hInstance, IDS_RESTORE, szBuffer, _countof(szBuffer)))
{
- szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
+ szBuffer[_countof(szBuffer)-1] = L'\0';
_InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count, MFT_STRING,
szBuffer, MFS_ENABLED);
Count++;
}
- if (LoadStringW(shell32_hInstance, IDS_CUT, szBuffer, sizeof(szBuffer) /
sizeof(WCHAR)))
+ if (LoadStringW(shell32_hInstance, IDS_CUT, szBuffer, _countof(szBuffer)))
{
_InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_SEPARATOR,
NULL, MFS_ENABLED);
- szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
+ szBuffer[_countof(szBuffer)-1] = L'\0';
_InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_STRING,
szBuffer, MFS_ENABLED);
}
- if (LoadStringW(shell32_hInstance, IDS_DELETE, szBuffer, sizeof(szBuffer) /
sizeof(WCHAR)))
+ if (LoadStringW(shell32_hInstance, IDS_DELETE, szBuffer, _countof(szBuffer)))
{
- szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
+ szBuffer[_countof(szBuffer)-1] = L'\0';
_InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_SEPARATOR,
NULL, MFS_ENABLED);
_InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_STRING,
szBuffer, MFS_ENABLED);
}
- if (LoadStringW(shell32_hInstance, IDS_PROPERTIES, szBuffer, sizeof(szBuffer) /
sizeof(WCHAR)))
+ if (LoadStringW(shell32_hInstance, IDS_PROPERTIES, szBuffer, _countof(szBuffer)))
{
- szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
+ szBuffer[_countof(szBuffer)-1] = L'\0';
_InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count++, MFT_SEPARATOR,
NULL, MFS_ENABLED);
_InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count, MFT_STRING,
szBuffer, MFS_DEFAULT);
}
@@ -791,12 +791,12 @@ HRESULT WINAPI CRecycleBin::QueryContextMenu(HMENU hMenu, UINT
indexMenu, UINT i
if (!hMenu)
return E_INVALIDARG;
- memset(&mii, 0, sizeof(mii));
+ ZeroMemory(&mii, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
mii.fState = RecycleBinIsEmpty() ? MFS_DISABLED : MFS_ENABLED;
szBuffer[0] = L'\0';
- LoadStringW(shell32_hInstance, IDS_EMPTY_BITBUCKET, szBuffer, sizeof(szBuffer) /
sizeof(WCHAR));
+ LoadStringW(shell32_hInstance, IDS_EMPTY_BITBUCKET, szBuffer, _countof(szBuffer));
mii.dwTypeData = szBuffer;
mii.cch = wcslen(mii.dwTypeData);
mii.wID = idCmdFirst + id++;
@@ -881,7 +881,7 @@ TRASH_CanTrashFile(LPCWSTR wszPath)
DWORD FileSystemFlags, dwSize, dwDisposition;
HKEY hKey;
WCHAR szBuffer[10];
- WCHAR szKey[150] =
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Bitbucket\\Volume\\";
+ WCHAR szKey[150] =
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\BitBucket\\Volume\\";
if (wszPath[1] != L':')
{
@@ -1116,7 +1116,7 @@ HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath,
DWORD dwFlags)
if (dwType != REG_EXPAND_SZ) /* type dismatch */
return S_OK;
- szPath[(sizeof(szPath)/sizeof(WCHAR))-1] = L'\0';
+ szPath[_countof(szPath)-1] = L'\0';
PlaySoundW(szPath, NULL, SND_FILENAME);
}
return S_OK;