[SHELL32][SHELLEXT] Fix use of SHFileOperation results and improve log on failure...
authorKyle Katarn <contact@kcsoftwares.com>
Fri, 18 Sep 2020 19:19:55 +0000 (21:19 +0200)
committerGitHub <noreply@github.com>
Fri, 18 Sep 2020 19:19:55 +0000 (21:19 +0200)
dll/shellext/mydocs/CMyDocsDropHandler.cpp
dll/win32/shell32/CCopyToMenu.cpp
dll/win32/shell32/CMoveToMenu.cpp
dll/win32/shell32/droptargets/CFSDropTarget.cpp
dll/win32/shell32/droptargets/CRecyclerDropTarget.cpp
dll/win32/shell32/shellrecyclebin/recyclebin_v5.c
dll/win32/shell32/shlfileop.cpp

index cd74af6..477ca4b 100644 (file)
@@ -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();
index 47da3b1..de2e292 100644 (file)
@@ -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()
index 7e74473..be90f97 100644 (file)
@@ -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()
index b8e67fd..4fb1657 100644 (file)
@@ -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");
index fa2b5ff..efd446d 100644 (file)
@@ -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;
             }
 
index 518cd0f..4e333da 100644 (file)
@@ -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 */
index c9e7400..204fece 100644 (file)
@@ -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: