https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7ca2710d64179a4b48eb3…
commit 7ca2710d64179a4b48eb3b2fbd4d212949717cb0
Author: Thamatip Chitpong <tangaming123456(a)outlook.com>
AuthorDate: Sat Dec 10 03:14:09 2022 +0700
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Dec 9 23:14:09 2022 +0300
[SHELL32] Improve "Empty Recycle Bin" sound code (#4927)
Split off from PR #4755. This change doesn't require WINMM fixes (#4635).
- Remove `MAX_PATH` limit
- Use ATL classes
- Play the sound asynchronously
---
dll/win32/shell32/folders/CRecycleBin.cpp | 72 +++++++++++++++++++++++--------
1 file changed, 54 insertions(+), 18 deletions(-)
diff --git a/dll/win32/shell32/folders/CRecycleBin.cpp
b/dll/win32/shell32/folders/CRecycleBin.cpp
index ee6c6d60754..bb44ca3cd6a 100644
--- a/dll/win32/shell32/folders/CRecycleBin.cpp
+++ b/dll/win32/shell32/folders/CRecycleBin.cpp
@@ -1018,6 +1018,57 @@ TRASH_TrashFile(LPCWSTR wszPath)
return DeleteFileToRecycleBin(wszPath);
}
+static void TRASH_PlayEmptyRecycleBinSound()
+{
+ CRegKey regKey;
+ CHeapPtr<WCHAR> pszValue;
+ CHeapPtr<WCHAR> pszSndPath;
+ DWORD dwType, dwSize;
+ LONG lError;
+
+ lError = regKey.Open(HKEY_CURRENT_USER,
+
L"AppEvents\\Schemes\\Apps\\Explorer\\EmptyRecycleBin\\.Current",
+ KEY_READ);
+ if (lError != ERROR_SUCCESS)
+ return;
+
+ lError = regKey.QueryValue(NULL, &dwType, NULL, &dwSize);
+ if (lError != ERROR_SUCCESS)
+ return;
+
+ if (!pszValue.AllocateBytes(dwSize))
+ return;
+
+ lError = regKey.QueryValue(NULL, &dwType, pszValue, &dwSize);
+ if (lError != ERROR_SUCCESS)
+ return;
+
+ if (dwType == REG_EXPAND_SZ)
+ {
+ dwSize = ExpandEnvironmentStringsW(pszValue, NULL, 0);
+ if (dwSize == 0)
+ return;
+
+ if (!pszSndPath.Allocate(dwSize))
+ return;
+
+ if (ExpandEnvironmentStringsW(pszValue, pszSndPath, dwSize) == 0)
+ return;
+ }
+ else if (dwType == REG_SZ)
+ {
+ /* The type is REG_SZ, no need to expand */
+ pszSndPath.Attach(pszValue.Detach());
+ }
+ else
+ {
+ /* Invalid type */
+ return;
+ }
+
+ PlaySoundW(pszSndPath, NULL, SND_FILENAME | SND_ASYNC | SND_NODEFAULT);
+}
+
/*************************************************************************
* SHUpdateCRecycleBinIcon [SHELL32.@]
*
@@ -1064,8 +1115,8 @@ HRESULT WINAPI SHEmptyRecycleBinA(HWND hwnd, LPCSTR pszRootPath,
DWORD dwFlags)
HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath, DWORD dwFlags)
{
- WCHAR szPath[MAX_PATH] = {0}, szBuffer[MAX_PATH];
- DWORD dwSize, dwType, count;
+ WCHAR szBuffer[MAX_PATH];
+ DWORD count;
LONG ret;
IShellFolder *pDesktop, *pRecycleBin;
PIDLIST_ABSOLUTE pidlRecycleBin;
@@ -1157,22 +1208,7 @@ HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath,
DWORD dwFlags)
if (!(dwFlags & SHERB_NOSOUND))
{
- dwSize = sizeof(szPath);
- ret = RegGetValueW(HKEY_CURRENT_USER,
-
L"AppEvents\\Schemes\\Apps\\Explorer\\EmptyRecycleBin\\.Current",
- NULL,
- RRF_RT_REG_SZ,
- &dwType,
- (PVOID)szPath,
- &dwSize);
- if (ret != ERROR_SUCCESS)
- return S_OK;
-
- if (dwType != REG_EXPAND_SZ) /* type dismatch */
- return S_OK;
-
- szPath[_countof(szPath)-1] = L'\0';
- PlaySoundW(szPath, NULL, SND_FILENAME);
+ TRASH_PlayEmptyRecycleBinSound();
}
return S_OK;
}