https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a5a30fc249e24108317a37...
commit a5a30fc249e24108317a37fd430b119e49e38f10 Author: Kyle Katarn contact@kcsoftwares.com AuthorDate: Fri Sep 18 21:19:55 2020 +0200 Commit: GitHub noreply@github.com CommitDate: Fri Sep 18 21:19:55 2020 +0200
[SHELL32][SHELLEXT] Fix use of SHFileOperation results and improve log on failure / fix log spam (#3198) --- dll/shellext/mydocs/CMyDocsDropHandler.cpp | 7 ++++- dll/win32/shell32/CCopyToMenu.cpp | 8 +++++- dll/win32/shell32/CMoveToMenu.cpp | 8 +++++- dll/win32/shell32/droptargets/CFSDropTarget.cpp | 33 ++++++++++++++-------- .../shell32/droptargets/CRecyclerDropTarget.cpp | 5 ++-- dll/win32/shell32/shellrecyclebin/recyclebin_v5.c | 6 ++-- dll/win32/shell32/shlfileop.cpp | 4 +++ 7 files changed, 53 insertions(+), 18 deletions(-)
diff --git a/dll/shellext/mydocs/CMyDocsDropHandler.cpp b/dll/shellext/mydocs/CMyDocsDropHandler.cpp index cd74af6d016..477ca4b1d7f 100644 --- a/dll/shellext/mydocs/CMyDocsDropHandler.cpp +++ b/dll/shellext/mydocs/CMyDocsDropHandler.cpp @@ -157,7 +157,12 @@ CMyDocsDropHandler::Drop(IDataObject *pDataObject, DWORD dwKeyState, fileop.pFrom = pszzSrcList; fileop.pTo = szzDir; fileop.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY | FOF_MULTIDESTFILES | FOF_NOCONFIRMMKDIR; - SHFileOperationW(&fileop); + int res = SHFileOperationW(&fileop); + if (res) + { + ERR("SHFileOperationW failed with 0x%x\n", res); + hr = E_FAIL; + }
// unlock buffer strSrcList.ReleaseBuffer(); diff --git a/dll/win32/shell32/CCopyToMenu.cpp b/dll/win32/shell32/CCopyToMenu.cpp index 47da3b11f44..de2e2921ecd 100644 --- a/dll/win32/shell32/CCopyToMenu.cpp +++ b/dll/win32/shell32/CCopyToMenu.cpp @@ -211,7 +211,13 @@ HRESULT CCopyToMenu::DoRealCopy(LPCMINVOKECOMMANDINFO lpici, LPCITEMIDLIST pidl) op.pFrom = strFiles; op.pTo = szPath; op.fFlags = FOF_ALLOWUNDO; - return ((SHFileOperation(&op) == 0) ? S_OK : E_FAIL); + int res = SHFileOperationW(&op); + if (res) + { + ERR("SHFileOperationW failed with 0x%x\n", res); + return E_FAIL; + } + return S_OK; }
CStringW CCopyToMenu::DoGetFileTitle() diff --git a/dll/win32/shell32/CMoveToMenu.cpp b/dll/win32/shell32/CMoveToMenu.cpp index 7e74473e143..be90f97201a 100644 --- a/dll/win32/shell32/CMoveToMenu.cpp +++ b/dll/win32/shell32/CMoveToMenu.cpp @@ -178,7 +178,13 @@ HRESULT CMoveToMenu::DoRealMove(LPCMINVOKECOMMANDINFO lpici, LPCITEMIDLIST pidl) op.pFrom = strFiles; op.pTo = szPath; op.fFlags = FOF_ALLOWUNDO; - return ((SHFileOperation(&op) == 0) ? S_OK : E_FAIL); + int res = SHFileOperationW(&op); + if (res) + { + ERR("SHFileOperationW failed with 0x%x\n", res); + return E_FAIL; + } + return S_OK; }
CStringW CMoveToMenu::DoGetFileTitle() diff --git a/dll/win32/shell32/droptargets/CFSDropTarget.cpp b/dll/win32/shell32/droptargets/CFSDropTarget.cpp index b8e67fd9adf..4fb1657da78 100644 --- a/dll/win32/shell32/droptargets/CFSDropTarget.cpp +++ b/dll/win32/shell32/droptargets/CFSDropTarget.cpp @@ -75,7 +75,7 @@ HRESULT CFSDropTarget::_CopyItems(IShellFolder * pSFFrom, UINT cidl, return hr;
pszSrcList = BuildPathsList(strretFrom.pOleStr, cidl, apidl); - ERR("Source file (just the first) = %s, target path = %s, bCopy: %d\n", debugstr_w(pszSrcList), debugstr_w(m_sPathTarget), bCopy); + TRACE("Source file (just the first) = %s, target path = %s, bCopy: %d\n", debugstr_w(pszSrcList), debugstr_w(m_sPathTarget), bCopy); CoTaskMemFree(strretFrom.pOleStr); if (!pszSrcList) return E_OUTOFMEMORY; @@ -92,9 +92,11 @@ HRESULT CFSDropTarget::_CopyItems(IShellFolder * pSFFrom, UINT cidl, HeapFree(GetProcessHeap(), 0, pszSrcList);
if (res) + { + ERR("SHFileOperationW failed with 0x%x\n", res); return E_FAIL; - else - return S_OK; + } + return S_OK; }
CFSDropTarget::CFSDropTarget(): @@ -489,7 +491,10 @@ HRESULT CFSDropTarget::_DoDrop(IDataObject *pDataObject, { hr = pDataObject->GetData(&fmt, &medium); TRACE("CFSTR_SHELLIDLIST.\n"); - + if (FAILED(hr)) + { + ERR("CFSTR_SHELLIDLIST failed\n"); + } /* lock the handle */ LPIDA lpcida = (LPIDA)GlobalLock(medium.hGlobal); if (!lpcida) @@ -597,9 +602,9 @@ HRESULT CFSDropTarget::_DoDrop(IDataObject *pDataObject, }
hr = ppf->Save(wszTarget, FALSE); - if (FAILED(hr)) - break; - SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, wszTarget, NULL); + if (FAILED(hr)) + break; + SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, wszTarget, NULL); } else { @@ -636,9 +641,9 @@ HRESULT CFSDropTarget::_DoDrop(IDataObject *pDataObject, break;
hr = ppf->Save(wszTarget, TRUE); - if (FAILED(hr)) - break; - SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, wszTarget, NULL); + if (FAILED(hr)) + break; + SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, wszTarget, NULL); } } } @@ -680,7 +685,13 @@ HRESULT CFSDropTarget::_DoDrop(IDataObject *pDataObject, op.hwnd = m_hwndSite; op.wFunc = bCopy ? FO_COPY : FO_MOVE; op.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMMKDIR; - hr = SHFileOperationW(&op); + int res = SHFileOperationW(&op); + if (res) + { + ERR("SHFileOperationW failed with 0x%x\n", res); + hr = E_FAIL; + } + return hr; } ERR("Error calling GetData\n"); diff --git a/dll/win32/shell32/droptargets/CRecyclerDropTarget.cpp b/dll/win32/shell32/droptargets/CRecyclerDropTarget.cpp index fa2b5ff1bcb..efd446d5cfa 100644 --- a/dll/win32/shell32/droptargets/CRecyclerDropTarget.cpp +++ b/dll/win32/shell32/droptargets/CRecyclerDropTarget.cpp @@ -58,9 +58,10 @@ class CRecyclerDropTarget : FileOp.fFlags = FOF_ALLOWUNDO; TRACE("Deleting file (just the first) = %s, allowundo: %d\n", debugstr_w(FileOp.pFrom), (FileOp.fFlags == FOF_ALLOWUNDO));
- if (SHFileOperationW(&FileOp) != 0) + int res = SHFileOperationW(&FileOp); + if (res) { - ERR("SHFileOperation failed with 0x%x\n", GetLastError()); + ERR("SHFileOperation failed with 0x%x\n", res); hr = E_FAIL; }
diff --git a/dll/win32/shell32/shellrecyclebin/recyclebin_v5.c b/dll/win32/shell32/shellrecyclebin/recyclebin_v5.c index 518cd0f216e..4e333da9f27 100644 --- a/dll/win32/shell32/shellrecyclebin/recyclebin_v5.c +++ b/dll/win32/shell32/shellrecyclebin/recyclebin_v5.c @@ -503,10 +503,12 @@ RecycleBin5_RecycleBin5_Restore( op.pFrom = pDeletedFileName; op.pTo = pDeletedFile->FileNameW;
- if (!SHFileOperationW(&op)) + int res = SHFileOperationW(&op); + if (res) { + ERR("SHFileOperationW failed with 0x%x\n", res); UnmapViewOfFile(pHeader); - return HRESULT_FROM_WIN32(GetLastError()); + return E_FAIL; }
/* Clear last entry in the file */ diff --git a/dll/win32/shell32/shlfileop.cpp b/dll/win32/shell32/shlfileop.cpp index c9e7400bed2..204feceaafe 100644 --- a/dll/win32/shell32/shlfileop.cpp +++ b/dll/win32/shell32/shlfileop.cpp @@ -1027,6 +1027,10 @@ int WINAPI SHFileOperationA(LPSHFILEOPSTRUCTA lpFileOp)
// Call the actual function retCode = SHFileOperationW(&nFileOp); + if (retCode) + { + ERR("SHFileOperationW failed with 0x%x\n", retCode); + }
// Cleanup cleanup: