4 * Copyright 2000 Juergen Schmied
5 * Copyright 2002 Andriy Palamarchuk
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
31 #include "shell32_main.h"
32 #include "undocshell.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shell);
38 BOOL SHELL_ConfirmDialog (int nKindOfDialog, LPCSTR szDir)
40 char szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
41 UINT caption_resource_id, text_resource_id;
43 switch(nKindOfDialog) {
46 caption_resource_id = IDS_DELETEITEM_CAPTION;
47 text_resource_id = IDS_DELETEITEM_TEXT;
49 case ASK_DELETE_FOLDER:
50 caption_resource_id = IDS_DELETEFOLDER_CAPTION;
51 text_resource_id = IDS_DELETEITEM_TEXT;
53 case ASK_DELETE_MULTIPLE_ITEM:
54 caption_resource_id = IDS_DELETEITEM_CAPTION;
55 text_resource_id = IDS_DELETEMULTIPLE_TEXT;
57 case ASK_OVERWRITE_FILE:
58 caption_resource_id = IDS_OVERWRITEFILE_CAPTION;
59 text_resource_id = IDS_OVERWRITEFILE_TEXT;
62 FIXME(" Unhandled nKindOfDialog %d stub\n", nKindOfDialog);
66 LoadStringA(shell32_hInstance, caption_resource_id, szCaption, sizeof(szCaption));
67 LoadStringA(shell32_hInstance, text_resource_id, szText, sizeof(szText));
69 FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
70 szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)&szDir);
72 return (IDOK == MessageBoxA(GetActiveWindow(), szBuffer, szCaption, MB_OKCANCEL | MB_ICONEXCLAMATION));
75 /**************************************************************************
76 * SHELL_DeleteDirectoryA()
81 BOOL SHELL_DeleteDirectoryA(LPCSTR pszDir, BOOL bShowUI)
86 char szTemp[MAX_PATH];
88 strcpy(szTemp, pszDir);
89 PathAddBackslashA(szTemp);
90 strcat(szTemp, "*.*");
92 if (bShowUI && !SHELL_ConfirmDialog(ASK_DELETE_FOLDER, pszDir))
95 if(INVALID_HANDLE_VALUE != (hFind = FindFirstFileA(szTemp, &wfd)))
99 if(strcasecmp(wfd.cFileName, ".") && strcasecmp(wfd.cFileName, ".."))
101 strcpy(szTemp, pszDir);
102 PathAddBackslashA(szTemp);
103 strcat(szTemp, wfd.cFileName);
105 if(FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
106 SHELL_DeleteDirectoryA(szTemp, FALSE);
110 } while(FindNextFileA(hFind, &wfd));
113 ret = RemoveDirectoryA(pszDir);
119 /**************************************************************************
120 * SHELL_DeleteFileA()
123 BOOL SHELL_DeleteFileA(LPCSTR pszFile, BOOL bShowUI)
125 if (bShowUI && !SHELL_ConfirmDialog(ASK_DELETE_FILE, pszFile))
128 return DeleteFileA(pszFile);
131 /*************************************************************************
132 * SHCreateDirectory [SHELL32.165]
135 * exported by ordinal
136 * WinNT/2000 exports Unicode
138 DWORD WINAPI SHCreateDirectory(HWND hWnd, LPCVOID path)
140 if (SHELL_OsIsUnicode())
141 return SHCreateDirectoryExW(hWnd, path, NULL);
142 return SHCreateDirectoryExA(hWnd, path, NULL);
145 /*************************************************************************
146 * SHCreateDirectoryExA [SHELL32.@]
148 DWORD WINAPI SHCreateDirectoryExA(HWND hWnd, LPCSTR path, LPSECURITY_ATTRIBUTES sec)
151 TRACE("(%p, %s, %p)\n",hWnd, path, sec);
152 if ((ret = CreateDirectoryA(path, sec)))
154 SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHA, path, NULL);
157 FIXME("Semi-stub, non zero hWnd should be used as parent for error dialog!");
161 /*************************************************************************
162 * SHCreateDirectoryExW [SHELL32.@]
164 DWORD WINAPI SHCreateDirectoryExW(HWND hWnd, LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
167 TRACE("(%p, %s, %p)\n",hWnd, debugstr_w(path), sec);
168 if ((ret = CreateDirectoryW(path, sec)))
170 SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHW, path, NULL);
173 FIXME("Semi-stub, non zero hWnd should be used as parent for error dialog!");
177 /************************************************************************
178 * Win32DeleteFile [SHELL32.164]
180 * Deletes a file. Also triggers a change notify if one exists.
183 * Verified on Win98 / IE 5 (SHELL32 4.72, March 1999 build) to be ANSI.
184 * This is Unicode on NT/2000
186 static BOOL Win32DeleteFileA(LPCSTR fName)
188 TRACE("%p(%s)\n", fName, fName);
191 SHChangeNotify(SHCNE_DELETE, SHCNF_PATHA, fName, NULL);
195 static BOOL Win32DeleteFileW(LPCWSTR fName)
197 TRACE("%p(%s)\n", fName, debugstr_w(fName));
200 SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, fName, NULL);
204 DWORD WINAPI Win32DeleteFileAW(LPCVOID fName)
206 if (SHELL_OsIsUnicode())
207 return Win32DeleteFileW(fName);
208 return Win32DeleteFileA(fName);
211 /**************************************************************************
212 * SHELL_FileNamesMatch()
214 * Accepts two \0 delimited lists of the file names. Checks whether number of
215 * files in the both lists is the same.
217 BOOL SHELL_FileNamesMatch(LPCSTR pszFiles1, LPCSTR pszFiles2)
219 while ((pszFiles1[strlen(pszFiles1) + 1] != '\0') &&
220 (pszFiles2[strlen(pszFiles2) + 1] != '\0'))
222 pszFiles1 += strlen(pszFiles1) + 1;
223 pszFiles2 += strlen(pszFiles2) + 1;
227 ((pszFiles1[strlen(pszFiles1) + 1] == '\0') &&
228 (pszFiles2[strlen(pszFiles2) + 1] == '\0')) ||
229 ((pszFiles1[strlen(pszFiles1) + 1] != '\0') &&
230 (pszFiles2[strlen(pszFiles2) + 1] != '\0'));
233 /*************************************************************************
234 * SHFileOperationA [SHELL32.@]
239 DWORD WINAPI SHFileOperationA (LPSHFILEOPSTRUCTA lpFileOp)
241 LPSTR pFrom = (LPSTR)lpFileOp->pFrom;
242 LPSTR pTo = (LPSTR)lpFileOp->pTo;
244 TRACE("flags (0x%04x) : %s%s%s%s%s%s%s%s%s%s%s%s \n", lpFileOp->fFlags,
245 lpFileOp->fFlags & FOF_MULTIDESTFILES ? "FOF_MULTIDESTFILES " : "",
246 lpFileOp->fFlags & FOF_CONFIRMMOUSE ? "FOF_CONFIRMMOUSE " : "",
247 lpFileOp->fFlags & FOF_SILENT ? "FOF_SILENT " : "",
248 lpFileOp->fFlags & FOF_RENAMEONCOLLISION ? "FOF_RENAMEONCOLLISION " : "",
249 lpFileOp->fFlags & FOF_NOCONFIRMATION ? "FOF_NOCONFIRMATION " : "",
250 lpFileOp->fFlags & FOF_WANTMAPPINGHANDLE ? "FOF_WANTMAPPINGHANDLE " : "",
251 lpFileOp->fFlags & FOF_ALLOWUNDO ? "FOF_ALLOWUNDO " : "",
252 lpFileOp->fFlags & FOF_FILESONLY ? "FOF_FILESONLY " : "",
253 lpFileOp->fFlags & FOF_SIMPLEPROGRESS ? "FOF_SIMPLEPROGRESS " : "",
254 lpFileOp->fFlags & FOF_NOCONFIRMMKDIR ? "FOF_NOCONFIRMMKDIR " : "",
255 lpFileOp->fFlags & FOF_NOERRORUI ? "FOF_NOERRORUI " : "",
256 lpFileOp->fFlags & 0xf800 ? "MORE-UNKNOWN-Flags" : "");
257 switch(lpFileOp->wFunc) {
261 /* establish when pTo is interpreted as the name of the destination file
262 * or the directory where the Fromfile should be copied to.
264 * (1) pTo points to the name of an existing directory;
265 * (2) the flag FOF_MULTIDESTFILES is present;
266 * (3) whether pFrom point to multiple filenames.
270 * destisdir 1 1 1 1 0 0 0 0
271 * FOF_MULTIDESTFILES 1 1 0 0 1 1 0 0
272 * multiple from filenames 1 0 1 0 1 0 1 0
274 * copy files to dir 1 0 1 1 0 0 1 0
275 * create dir 0 0 0 0 0 0 1 0
277 int multifrom = pFrom[strlen(pFrom) + 1] != '\0';
278 int destisdir = PathIsDirectoryA( pTo );
281 if (lpFileOp->wFunc == FO_COPY)
282 TRACE("File Copy:\n");
284 TRACE("File Move:\n");
287 if ( !((lpFileOp->fFlags & FOF_MULTIDESTFILES) && !multifrom))
290 if ( !(lpFileOp->fFlags & FOF_MULTIDESTFILES) && multifrom)
294 if ((pTo[strlen(pTo) + 1] != '\0') &&
295 !(lpFileOp->fFlags & FOF_MULTIDESTFILES))
297 WARN("Attempt to use multiple file names as a destination "
298 "without specifying FOF_MULTIDESTFILES\n");
302 if ((lpFileOp->fFlags & FOF_MULTIDESTFILES) &&
303 !SHELL_FileNamesMatch(pTo, pFrom))
305 WARN("Attempt to use multiple file names as a destination "
306 "with mismatching number of files in the source and "
307 "destination lists\n");
312 char szTempFrom[MAX_PATH];
316 TRACE(" creating directory %s\n",pTo);
317 SHCreateDirectoryExA(NULL, pTo, NULL);
319 lenPTo = strlen(pTo);
322 WIN32_FIND_DATAA wfd;
325 TRACE(" From Pattern='%s'\n", pFrom);
326 if(INVALID_HANDLE_VALUE != (hFind = FindFirstFileA(pFrom, &wfd)))
330 if(strcasecmp(wfd.cFileName, ".") && strcasecmp(wfd.cFileName, ".."))
332 strcpy(szTempFrom, pFrom);
334 pTempTo = HeapAlloc(GetProcessHeap(), 0,
335 lenPTo + strlen(wfd.cFileName) + 5);
338 PathAddBackslashA(pTempTo);
339 strcat(pTempTo,wfd.cFileName);
341 fromfile = PathFindFileNameA(szTempFrom);
343 PathAddBackslashA(szTempFrom);
344 strcat(szTempFrom, wfd.cFileName);
345 TRACE(" From='%s' To='%s'\n", szTempFrom, pTempTo);
346 if(lpFileOp->wFunc == FO_COPY)
348 if(FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
350 /* copy recursively */
351 if(!(lpFileOp->fFlags & FOF_FILESONLY))
353 SHFILEOPSTRUCTA shfo;
355 SHCreateDirectoryExA(NULL, pTempTo, NULL);
356 PathAddBackslashA(szTempFrom);
357 strcat(szTempFrom, "*.*");
358 szTempFrom[strlen(szTempFrom) + 1] = '\0';
359 pTempTo[strlen(pTempTo) + 1] = '\0';
360 memcpy(&shfo, lpFileOp, sizeof(shfo));
361 shfo.pFrom = szTempFrom;
363 SHFileOperationA(&shfo);
365 szTempFrom[strlen(szTempFrom) - 4] = '\0';
369 CopyFileA(szTempFrom, pTempTo, FALSE);
373 /* move file/directory */
374 MoveFileA(szTempFrom, pTempTo);
376 HeapFree(GetProcessHeap(), 0, pTempTo);
379 } while(FindNextFileA(hFind, &wfd));
384 /* can't find file with specified name */
387 pFrom += strlen(pFrom) + 1;
393 TRACE(" From='%s' To='%s'\n", pFrom, pTo);
395 pTempTo = HeapAlloc(GetProcessHeap(), 0, strlen(pTo)+1);
398 strcpy( pTempTo, pTo );
399 PathRemoveFileSpecA(pTempTo);
400 TRACE(" Creating Directory '%s'\n", pTempTo);
401 SHCreateDirectoryExA(NULL, pTempTo, NULL);
402 HeapFree(GetProcessHeap(), 0, pTempTo);
404 if (lpFileOp->wFunc == FO_COPY)
405 CopyFileA(pFrom, pTo, FALSE);
407 MoveFileA(pFrom, pTo);
409 pFrom += strlen(pFrom) + 1;
410 pTo += strlen(pTo) + 1;
413 TRACE("Setting AnyOpsAborted=FALSE\n");
414 lpFileOp->fAnyOperationsAborted=FALSE;
421 WIN32_FIND_DATAA wfd;
422 char szTemp[MAX_PATH];
425 TRACE("File Delete:\n");
428 TRACE(" Pattern='%s'\n", pFrom);
429 if(INVALID_HANDLE_VALUE != (hFind = FindFirstFileA(pFrom, &wfd)))
433 if(strcasecmp(wfd.cFileName, ".") && strcasecmp(wfd.cFileName, ".."))
435 strcpy(szTemp, pFrom);
436 file_name = PathFindFileNameA(szTemp);
438 PathAddBackslashA(szTemp);
439 strcat(szTemp, wfd.cFileName);
441 TRACE(" File='%s'\n", szTemp);
442 if(FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
444 if(!(lpFileOp->fFlags & FOF_FILESONLY))
445 SHELL_DeleteDirectoryA(szTemp, FALSE);
450 } while(FindNextFileA(hFind, &wfd));
454 pFrom += strlen(pFrom) + 1;
456 TRACE("Setting AnyOpsAborted=FALSE\n");
457 lpFileOp->fAnyOperationsAborted=FALSE;
462 TRACE("File Rename:\n");
463 if (pFrom[strlen(pFrom) + 1] != '\0')
465 WARN("Attempt to rename more than one file\n");
468 lpFileOp->fAnyOperationsAborted = FALSE;
469 TRACE("From %s, To %s\n", pFrom, pTo);
470 return !MoveFileA(pFrom, pTo);
473 FIXME("Unhandled shell file operation %d\n", lpFileOp->wFunc);
479 /*************************************************************************
480 * SHFileOperationW [SHELL32.@]
485 DWORD WINAPI SHFileOperationW (LPSHFILEOPSTRUCTW lpFileOp)
487 FIXME("(%p):stub.\n", lpFileOp);
491 /*************************************************************************
492 * SHFileOperation [SHELL32.@]
495 DWORD WINAPI SHFileOperationAW(LPVOID lpFileOp)
497 if (SHELL_OsIsUnicode())
498 return SHFileOperationW(lpFileOp);
499 return SHFileOperationA(lpFileOp);
502 /*************************************************************************
503 * SheGetDirW [SHELL32.281]
506 HRESULT WINAPI SheGetDirW(LPWSTR u, LPWSTR v)
507 { FIXME("%p %p stub\n",u,v);
511 /*************************************************************************
512 * SheChangeDirW [SHELL32.274]
515 HRESULT WINAPI SheChangeDirW(LPWSTR u)
516 { FIXME("(%s),stub\n",debugstr_w(u));
520 /*************************************************************************
521 * IsNetDrive [SHELL32.66]
523 BOOL WINAPI IsNetDrive(DWORD drive)
526 strcpy(root, "A:\\");
527 root[0] += (char)drive;
528 return (GetDriveTypeA(root) == DRIVE_REMOTE);