- Fix a bug which broke build
[reactos.git] / reactos / dll / win32 / shell32 / shfldr_fs.c
index a67907e..381293d 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "config.h"
-#include "wine/port.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdio.h>
-
-#define COBJMACROS
-#define NONAMELESSUNION
-#define NONAMELESSSTRUCT
-
-#include "winerror.h"
-#include "windef.h"
-#include "winbase.h"
-#include "winreg.h"
-#include "wingdi.h"
-#include "winuser.h"
-
-#include "ole2.h"
-#include "shlguid.h"
-
-#include "enumidlist.h"
-#include "pidl.h"
-#include "undocshell.h"
-#include "shell32_main.h"
-#include "shresdef.h"
-#include "shlwapi.h"
-#include "shellfolder.h"
-#include "wine/debug.h"
-#include "debughlp.h"
-#include "shfldr.h"
+#include <precomp.h>
 
 WINE_DEFAULT_DEBUG_CHANNEL (shell);
 
@@ -78,7 +47,7 @@ typedef struct {
 
     UINT cfShellIDList;    /* clipboardformat for IDropTarget */
     BOOL fAcceptFmt;       /* flag for pending Drop */
-} IGenericSFImpl;
+} IGenericSFImpl, *LPIGenericSFImpl;
 
 static const IUnknownVtbl unkvt;
 static const IShellFolder2Vtbl sfvt;
@@ -86,24 +55,24 @@ static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3; /* IPersistFolder3 fo
 static const IDropTargetVtbl dtvt;
 static const ISFHelperVtbl shvt;
 
-static inline IGenericSFImpl *impl_from_IShellFolder2( IShellFolder2 *iface )
+static LPIGenericSFImpl __inline impl_from_IShellFolder2( IShellFolder2 *iface )
 {
-    return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblShellFolder));
+    return (LPIGenericSFImpl)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblShellFolder));
 }
 
-static inline IGenericSFImpl *impl_from_IPersistFolder3( IPersistFolder3 *iface )
+static LPIGenericSFImpl __inline impl_from_IPersistFolder3( IPersistFolder3 *iface )
 {
-    return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblPersistFolder3));
+    return (LPIGenericSFImpl)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblPersistFolder3));
 }
 
-static inline IGenericSFImpl *impl_from_IDropTarget( IDropTarget *iface )
+static LPIGenericSFImpl __inline impl_from_IDropTarget( IDropTarget *iface )
 {
-    return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblDropTarget));
+    return (LPIGenericSFImpl)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblDropTarget));
 }
 
-static inline IGenericSFImpl *impl_from_ISFHelper( ISFHelper *iface )
+static LPIGenericSFImpl __inline impl_from_ISFHelper( ISFHelper *iface )
 {
-    return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblSFHelper));
+    return (LPIGenericSFImpl)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblSFHelper));
 }
 
 
@@ -405,7 +374,7 @@ IShellFolder_fnParseDisplayName (IShellFolder2 * iface,
         /* build the full pathname to the element */
         lstrcpynW(szPath, This->sPathTarget, MAX_PATH - 1);
         PathAddBackslashW(szPath);
-        len = lstrlenW(szPath);
+        len = wcslen(szPath);
         lstrcpynW(szPath + len, szElement, MAX_PATH - len);
 
         /* get the pidl */
@@ -808,7 +777,7 @@ IShellFolder_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
         {
             lstrcpynW(pszPath, This->sPathTarget, MAX_PATH);
             PathAddBackslashW(pszPath);
-            len = lstrlenW(pszPath);
+            len = wcslen(pszPath);
         }
         _ILSimpleGetTextW(pidl, pszPath + len, MAX_PATH + 1 - len);
         if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
@@ -880,7 +849,7 @@ static HRESULT WINAPI IShellFolder_fnSetNameOf (IShellFolder2 * iface,
     if(!(dwFlags & SHGDN_FORPARSING) && SHELL_FS_HideExtension(szSrc)) {
         WCHAR *ext = PathFindExtensionW(szSrc);
         if(*ext != '\0') {
-            INT len = strlenW(szDest);
+            INT len = wcslen(szDest);
             lstrcpynW(szDest + len, ext, MAX_PATH - len);
         }
     }
@@ -1120,7 +1089,7 @@ next:
          dwFetched) {
             _ILSimpleGetTextW (pidl, wszText, MAX_PATH);
             if (0 == lstrcmpiW (wszText, pwszName)) {
-                snprintfW (pwszName, uLen, wszFormat, wszNewFolder, i++);
+                _snwprintf (pwszName, uLen, wszFormat, wszNewFolder, i++);
                 if (i > 99) {
                     hr = E_FAIL;
                     break;
@@ -1174,7 +1143,7 @@ ISFHelper_fnAddFolder (ISFHelper * iface, HWND hwnd, LPCWSTR pwszName,
          sizeof (wszTempText));
         LoadStringW (shell32_hInstance, IDS_CREATEFOLDER_CAPTION, wszCaption,
          sizeof (wszCaption));
-        sprintfW (wszText, wszTempText, wszNewDir);
+        swprintf (wszText, wszTempText, wszNewDir);
         MessageBoxW (hwnd, wszText, wszCaption, MB_OK | MB_ICONEXCLAMATION);
     }
 
@@ -1194,7 +1163,7 @@ WCHAR *build_paths_list(LPCWSTR wszBasePath, int cidl, LPCITEMIDLIST *pidls)
     int iPathLen;
     int i;
 
-    iPathLen = lstrlenW(wszBasePath);
+    iPathLen = wcslen(wszBasePath);
     wszPathsList = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR)*cidl+1);
     wszListPos = wszPathsList;
 
@@ -1205,7 +1174,7 @@ WCHAR *build_paths_list(LPCWSTR wszBasePath, int cidl, LPCITEMIDLIST *pidls)
         lstrcpynW(wszListPos, wszBasePath, MAX_PATH);
         /* FIXME: abort if path too long */
         _ILSimpleGetTextW(pidls[i], wszListPos+iPathLen, MAX_PATH-iPathLen);
-        wszListPos += lstrlenW(wszListPos)+1;
+        wszListPos += wcslen(wszListPos)+1;
     }
     *wszListPos=0;
     return wszPathsList;
@@ -1271,7 +1240,7 @@ ISFHelper_fnDeleteItems (ISFHelper * iface, UINT cidl, LPCITEMIDLIST * apidl)
             SHFree(pidl);
         }
 
-        wszCurrentPath += lstrlenW(wszCurrentPath)+1;
+        wszCurrentPath += wcslen(wszCurrentPath)+1;
     }
     HeapFree(GetProcessHeap(), 0, wszPathsList);
     return ret;
@@ -1291,16 +1260,17 @@ ISFHelper_fnCopyItems (ISFHelper * iface, IShellFolder * pSFFrom, UINT cidl,
     WCHAR szTargetPath[MAX_PATH];
     SHFILEOPSTRUCTW op;
     LPITEMIDLIST pidl;
-    LPWSTR pszSrc, pszTarget, pszSrcList, pszTargetList;
-    int res;
+    LPWSTR pszSrc, pszTarget, pszSrcList, pszTargetList, pszFileName;
+    int res, length;
+    HRESULT hr;
     STRRET strRet;
 
     IGenericSFImpl *This = impl_from_ISFHelper(iface);
 
     TRACE ("(%p)->(%p,%u,%p)\n", This, pSFFrom, cidl, apidl);
 
-    IShellFolder_QueryInterface (pSFFrom, &IID_IPersistFolder2, (LPVOID *) & ppf2);
-    if (ppf2) 
+    hr = IShellFolder_QueryInterface (pSFFrom, &IID_IPersistFolder2, (LPVOID *) & ppf2);
+    if (SUCCEEDED(hr))
     {
         if (FAILED(IPersistFolder2_GetCurFolder (ppf2, &pidl)))
         {
@@ -1380,8 +1350,26 @@ ISFHelper_fnCopyItems (ISFHelper * iface, IShellFolder * pSFFrom, UINT cidl,
 
         res = SHFileOperationW(&op);
 
-        HeapFree(GetProcessHeap(), 0, pszSrc);
-        HeapFree(GetProcessHeap(), 0, pszTarget);
+        if (res == DE_SAMEFILE)
+        {
+            length = wcslen(szTargetPath);
+
+            pszFileName = wcsrchr(pszSrcList, '\\');
+            pszFileName++;
+
+            if (LoadStringW(shell32_hInstance, IDS_COPY_OF, pszTarget, MAX_PATH - length))
+            {
+                wcscat(szTargetPath, L" ");
+            }
+
+            wcscat(szTargetPath, pszFileName);
+            op.pTo = szTargetPath;
+
+            res = SHFileOperationW(&op);
+        }
+
+        HeapFree(GetProcessHeap(), 0, pszSrcList);
+        HeapFree(GetProcessHeap(), 0, pszTargetList);
 
         if (res)
             return E_FAIL;
@@ -1485,7 +1473,7 @@ IFSFldr_PersistFolder3_Initialize (IPersistFolder3 * iface, LPCITEMIDLIST pidl)
 
     /* set my path */
     if (SHGetPathFromIDListW (pidl, wszTemp)) {
-        int len = strlenW(wszTemp);
+        int len = wcslen(wszTemp);
         This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
         if (!This->sPathTarget)
             return E_OUTOFMEMORY;
@@ -1555,14 +1543,14 @@ IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3 * iface,
         if (ppfti->csidl != -1) {
             if (SHGetSpecialFolderPathW (0, wszTemp, ppfti->csidl,
              ppfti->csidl & CSIDL_FLAG_CREATE)) {
-                int len = strlenW(wszTemp);
+                int len = wcslen(wszTemp);
                 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
                 if (!This->sPathTarget)
                     return E_OUTOFMEMORY;
                 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
             }
         } else if (ppfti->szTargetParsingName[0]) {
-            int len = strlenW(ppfti->szTargetParsingName);
+            int len = wcslen(ppfti->szTargetParsingName);
             This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
             if (!This->sPathTarget)
                 return E_OUTOFMEMORY;
@@ -1570,7 +1558,7 @@ IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3 * iface,
                    (len + 1) * sizeof(WCHAR));
         } else if (ppfti->pidlTargetFolder) {
             if (SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTemp)) {
-                int len = strlenW(wszTemp);
+                int len = wcslen(wszTemp);
                 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
                 if (!This->sPathTarget)
                     return E_OUTOFMEMORY;