[SHELL32] Recycle-Bin: Minor code enhancements.

- Use _countof() and ZeroMemory().
- Fix case of 'BitBucket' registry key (Windows-compatible).
- Simplify code.
- Minor code formatting.
This commit is contained in:
Hermès Bélusca-Maïto 2019-07-07 15:57:01 +02:00
parent 36e9a6f8dd
commit 8a30801516
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 40 additions and 55 deletions

View file

@ -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,""

View file

@ -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);
}

View file

@ -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;