* Create a IDataObject when cidl == 0 (click on TreeView)
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Tue, 19 Aug 2008 13:03:16 +0000 (13:03 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Tue, 19 Aug 2008 13:03:16 +0000 (13:03 +0000)
* Handle directories in ISFHelper_fnCopyItems
* Should make copying directories work

svn path=/trunk/; revision=35450

reactos/dll/win32/shell32/shfldr_fs.c

index b7ac4de..cc94009 100644 (file)
@@ -653,10 +653,17 @@ IShellFolder_fnGetUIObjectOf (IShellFolder2 * iface,
 
         if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
             hr = CDefFolderMenu_Create2(This->pidlRoot, hwndOwner, cidl, apidl, (IShellFolder*)iface, NULL, 0, NULL, (IContextMenu**)&pObj);
-        } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
+        } else if (IsEqualIID (riid, &IID_IDataObject)){
+                       if (cidl >= 1) {
             pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
              This->pidlRoot, apidl, cidl);
             hr = S_OK;
+                       }
+                       else
+                       {
+                pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, (LPCITEMIDLIST*)&This->pidlRoot, 1);
+                hr = S_OK;
+                       }
         } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
             pidl = ILCombine (This->pidlRoot, apidl[0]);
             pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
@@ -1274,9 +1281,9 @@ ISFHelper_fnCopyItems (ISFHelper * iface, IShellFolder * pSFFrom, UINT cidl,
     WCHAR szTargetPath[MAX_PATH];
     SHFILEOPSTRUCTW op;
     LPITEMIDLIST pidl;
-    LPWSTR pszSrc, pszTarget;
+    LPWSTR pszSrc, pszTarget, pszSrcList, pszTargetList;
     int res;
-
+    STRRET strRet;
 
     IGenericSFImpl *This = impl_from_ISFHelper(iface);
 
@@ -1290,48 +1297,82 @@ ISFHelper_fnCopyItems (ISFHelper * iface, IShellFolder * pSFFrom, UINT cidl,
             IPersistFolder2_Release(ppf2);
             return E_FAIL;
         }
+        IPersistFolder2_Release(ppf2);
 
-        if (!SHGetPathFromIDListW (pidl, szSrcPath))
+        if (FAILED(IShellFolder_GetDisplayNameOf(pSFFrom, pidl, SHGDN_FORPARSING, &strRet)))
+        {
+            SHFree (pidl);
+            return E_FAIL;
+        }
+
+        if (FAILED(StrRetToBufW(&strRet, pidl, szSrcPath, MAX_PATH)))
         {
             SHFree (pidl);
-            IPersistFolder2_Release (ppf2);
             return E_FAIL;
         }
+        SHFree (pidl);
+
         pszSrc = PathAddBackslashW (szSrcPath);
+
         wcscpy(szTargetPath, This->sPathTarget);
         pszTarget = PathAddBackslashW (szTargetPath);
 
-        pszSrc = build_paths_list(szSrcPath, cidl, apidl);
-        pszTarget = build_paths_list(szTargetPath, cidl, apidl);
+        pszSrcList = build_paths_list(szSrcPath, cidl, apidl);
+        pszTargetList = build_paths_list(szTargetPath, cidl, apidl);
 
-        if (!pszSrc || !pszTarget)
+        if (!pszSrcList || !pszTargetList)
         {
-            if (pszSrc)
-                HeapFree(GetProcessHeap(), 0, pszSrc);
+            if (pszSrcList)
+                HeapFree(GetProcessHeap(), 0, pszSrcList);
 
-            if (pszTarget)
-                HeapFree(GetProcessHeap(), 0, pszTarget);
+            if (pszTargetList)
+                HeapFree(GetProcessHeap(), 0, pszTargetList);
 
             SHFree (pidl);
             IPersistFolder2_Release (ppf2);
             return E_OUTOFMEMORY;
         }
-
         ZeroMemory(&op, sizeof(op));
+        if (!pszSrcList[0])
+        {
+            /* remove trailing backslash */
+            pszSrc--;
+            pszSrc[0] = L'\0';
+            op.pFrom = szSrcPath;
+        }
+        else
+        {
+            op.pFrom = pszSrcList;
+        }
+
+        if (!pszTargetList[0])
+        {
+            /* remove trailing backslash */
+            if (pszTarget - szTargetPath > 3)
+            {
+                pszTarget--;
+                pszTarget[0] = L'\0';
+            }
+            else
+            {
+                pszTarget[1] = L'\0';
+            }
+
+            op.pTo = szTargetPath;
+        }
+        else
+        {
+            op.pTo = pszTargetList;
+        }
         op.hwnd = GetActiveWindow();
         op.wFunc = FO_COPY;
-        op.pFrom = pszSrc;
-        op.pTo = pszTarget;
-        op.fFlags = FOF_ALLOWUNDO;
+        op.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMMKDIR;
 
         res = SHFileOperationW(&op);
 
         HeapFree(GetProcessHeap(), 0, pszSrc);
         HeapFree(GetProcessHeap(), 0, pszTarget);
 
-        SHFree (pidl);
-        IPersistFolder2_Release (ppf2);
-
         if (res)
             return E_FAIL;
         else