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
27 #include "shell32_main.h"
28 #include "undocshell.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(shell);
34 BOOL SHELL_WarnItemDelete (int nKindOfDialog, LPCSTR szDir)
36 char szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
38 if(nKindOfDialog == ASK_DELETE_FILE)
40 LoadStringA(shell32_hInstance, IDS_DELETEITEM_TEXT, szText,
42 LoadStringA(shell32_hInstance, IDS_DELETEITEM_CAPTION,
43 szCaption, sizeof(szCaption));
45 else if(nKindOfDialog == ASK_DELETE_FOLDER)
47 LoadStringA(shell32_hInstance, IDS_DELETEITEM_TEXT, szText,
49 LoadStringA(shell32_hInstance, IDS_DELETEFOLDER_CAPTION,
50 szCaption, sizeof(szCaption));
52 else if(nKindOfDialog == ASK_DELETE_MULTIPLE_ITEM)
54 LoadStringA(shell32_hInstance, IDS_DELETEMULTIPLE_TEXT, szText,
56 LoadStringA(shell32_hInstance, IDS_DELETEITEM_CAPTION,
57 szCaption, sizeof(szCaption));
60 FIXME("Called without a valid nKindOfDialog specified!\n");
61 LoadStringA(shell32_hInstance, IDS_DELETEITEM_TEXT, szText,
63 LoadStringA(shell32_hInstance, IDS_DELETEITEM_CAPTION,
64 szCaption, sizeof(szCaption));
67 FormatMessageA(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
68 szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)&szDir);
70 return (IDOK == MessageBoxA(GetActiveWindow(), szBuffer, szCaption, MB_OKCANCEL | MB_ICONEXCLAMATION));
73 /**************************************************************************
74 * SHELL_DeleteDirectoryA()
79 BOOL SHELL_DeleteDirectoryA(LPCSTR pszDir, BOOL bShowUI)
84 char szTemp[MAX_PATH];
86 strcpy(szTemp, pszDir);
87 PathAddBackslashA(szTemp);
88 strcat(szTemp, "*.*");
90 if (bShowUI && !SHELL_WarnItemDelete(ASK_DELETE_FOLDER, pszDir))
93 if(INVALID_HANDLE_VALUE != (hFind = FindFirstFileA(szTemp, &wfd)))
97 if(strcasecmp(wfd.cFileName, ".") && strcasecmp(wfd.cFileName, ".."))
99 strcpy(szTemp, pszDir);
100 PathAddBackslashA(szTemp);
101 strcat(szTemp, wfd.cFileName);
103 if(FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
104 SHELL_DeleteDirectoryA(szTemp, FALSE);
108 } while(FindNextFileA(hFind, &wfd));
111 ret = RemoveDirectoryA(pszDir);
117 /**************************************************************************
118 * SHELL_DeleteFileA()
121 BOOL SHELL_DeleteFileA(LPCSTR pszFile, BOOL bShowUI)
123 if (bShowUI && !SHELL_WarnItemDelete(ASK_DELETE_FILE, pszFile))
126 return DeleteFileA(pszFile);
129 /*************************************************************************
130 * SHCreateDirectory [SHELL32.165]
133 * exported by ordinal
134 * not sure about LPSECURITY_ATTRIBUTES
136 DWORD WINAPI SHCreateDirectory(LPSECURITY_ATTRIBUTES sec,LPCSTR path)
139 TRACE("(%p,%s)\n",sec,path);
140 if ((ret = CreateDirectoryA(path,sec)))
142 SHChangeNotifyA(SHCNE_MKDIR, SHCNF_PATHA, path, NULL);
147 /************************************************************************
148 * Win32DeleteFile [SHELL32.164]
150 * Deletes a file. Also triggers a change notify if one exists.
153 * Verified on Win98 / IE 5 (SHELL32 4.72, March 1999 build) to be
154 * ANSI. Is this Unicode on NT?
158 BOOL WINAPI Win32DeleteFile(LPSTR fName)
160 TRACE("%p(%s)\n", fName, fName);
163 SHChangeNotifyA(SHCNE_DELETE, SHCNF_PATHA, fName, NULL);
167 /**************************************************************************
168 * SHELL_FileNamesMatch()
170 * Accepts two \0 delimited lists of the file names. Checks whether number of
171 * files in the both lists is the same.
173 BOOL SHELL_FileNamesMatch(LPCSTR pszFiles1, LPCSTR pszFiles2)
175 while ((pszFiles1[strlen(pszFiles1) + 1] != '\0') &&
176 (pszFiles2[strlen(pszFiles2) + 1] != '\0'))
178 pszFiles1 += strlen(pszFiles1) + 1;
179 pszFiles2 += strlen(pszFiles2) + 1;
183 ((pszFiles1[strlen(pszFiles1) + 1] == '\0') &&
184 (pszFiles2[strlen(pszFiles2) + 1] == '\0')) ||
185 ((pszFiles1[strlen(pszFiles1) + 1] != '\0') &&
186 (pszFiles2[strlen(pszFiles2) + 1] != '\0'));
189 /*************************************************************************
190 * SHFileOperationA [SHELL32.@]
195 DWORD WINAPI SHFileOperationA (LPSHFILEOPSTRUCTA lpFileOp)
197 LPSTR pFrom = (LPSTR)lpFileOp->pFrom;
198 LPSTR pTo = (LPSTR)lpFileOp->pTo;
200 TRACE("flags (0x%04x) : %s%s%s%s%s%s%s%s%s%s%s%s \n", lpFileOp->fFlags,
201 lpFileOp->fFlags & FOF_MULTIDESTFILES ? "FOF_MULTIDESTFILES " : "",
202 lpFileOp->fFlags & FOF_CONFIRMMOUSE ? "FOF_CONFIRMMOUSE " : "",
203 lpFileOp->fFlags & FOF_SILENT ? "FOF_SILENT " : "",
204 lpFileOp->fFlags & FOF_RENAMEONCOLLISION ? "FOF_RENAMEONCOLLISION " : "",
205 lpFileOp->fFlags & FOF_NOCONFIRMATION ? "FOF_NOCONFIRMATION " : "",
206 lpFileOp->fFlags & FOF_WANTMAPPINGHANDLE ? "FOF_WANTMAPPINGHANDLE " : "",
207 lpFileOp->fFlags & FOF_ALLOWUNDO ? "FOF_ALLOWUNDO " : "",
208 lpFileOp->fFlags & FOF_FILESONLY ? "FOF_FILESONLY " : "",
209 lpFileOp->fFlags & FOF_SIMPLEPROGRESS ? "FOF_SIMPLEPROGRESS " : "",
210 lpFileOp->fFlags & FOF_NOCONFIRMMKDIR ? "FOF_NOCONFIRMMKDIR " : "",
211 lpFileOp->fFlags & FOF_NOERRORUI ? "FOF_NOERRORUI " : "",
212 lpFileOp->fFlags & 0xf800 ? "MORE-UNKNOWN-Flags" : "");
213 switch(lpFileOp->wFunc) {
217 /* establish when pTo is interpreted as the name of the destination file
218 * or the directory where the Fromfile should be copied to.
220 * (1) pTo points to the name of an existing directory;
221 * (2) the flag FOF_MULTIDESTFILES is present;
222 * (3) whether pFrom point to multiple filenames.
226 * destisdir 1 1 1 1 0 0 0 0
227 * FOF_MULTIDESTFILES 1 1 0 0 1 1 0 0
228 * multiple from filenames 1 0 1 0 1 0 1 0
230 * copy files to dir 1 0 1 1 0 0 1 0
231 * create dir 0 0 0 0 0 0 1 0
233 int multifrom = pFrom[strlen(pFrom) + 1] != '\0';
234 int destisdir = PathIsDirectoryA( pTo );
237 if (lpFileOp->wFunc == FO_COPY)
238 TRACE("File Copy:\n");
240 TRACE("File Move:\n");
243 if ( !((lpFileOp->fFlags & FOF_MULTIDESTFILES) && !multifrom))
246 if ( !(lpFileOp->fFlags & FOF_MULTIDESTFILES) && multifrom)
250 if ((pTo[strlen(pTo) + 1] != '\0') &&
251 !(lpFileOp->fFlags & FOF_MULTIDESTFILES))
253 WARN("Attempt to use multiple file names as a destination "
254 "without specifying FOF_MULTIDESTFILES\n");
258 if ((lpFileOp->fFlags & FOF_MULTIDESTFILES) &&
259 !SHELL_FileNamesMatch(pTo, pFrom))
261 WARN("Attempt to use multiple file names as a destination "
262 "with mismatching number of files in the source and "
263 "destination lists\n");
268 char szTempFrom[MAX_PATH];
272 TRACE(" creating directory %s\n",pTo);
273 SHCreateDirectory(NULL,pTo);
275 lenPTo = strlen(pTo);
278 WIN32_FIND_DATAA wfd;
281 TRACE(" From Pattern='%s'\n", pFrom);
282 if(INVALID_HANDLE_VALUE != (hFind = FindFirstFileA(pFrom, &wfd)))
286 if(strcasecmp(wfd.cFileName, ".") && strcasecmp(wfd.cFileName, ".."))
288 strcpy(szTempFrom, pFrom);
290 pTempTo = HeapAlloc(GetProcessHeap(), 0,
291 lenPTo + strlen(wfd.cFileName) + 5);
294 PathAddBackslashA(pTempTo);
295 strcat(pTempTo,wfd.cFileName);
297 fromfile = PathFindFileNameA(szTempFrom);
299 PathAddBackslashA(szTempFrom);
300 strcat(szTempFrom, wfd.cFileName);
301 TRACE(" From='%s' To='%s'\n", szTempFrom, pTempTo);
302 if(lpFileOp->wFunc == FO_COPY)
304 if(FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
306 /* copy recursively */
307 if(!(lpFileOp->fFlags & FOF_FILESONLY))
309 SHFILEOPSTRUCTA shfo;
311 SHCreateDirectory(NULL,pTempTo);
312 PathAddBackslashA(szTempFrom);
313 strcat(szTempFrom, "*.*");
314 szTempFrom[strlen(szTempFrom) + 1] = '\0';
315 pTempTo[strlen(pTempTo) + 1] = '\0';
316 memcpy(&shfo, lpFileOp, sizeof(shfo));
317 shfo.pFrom = szTempFrom;
319 SHFileOperationA(&shfo);
321 szTempFrom[strlen(szTempFrom) - 4] = '\0';
325 CopyFileA(szTempFrom, pTempTo, FALSE);
329 /* move file/directory */
330 MoveFileA(szTempFrom, pTempTo);
332 HeapFree(GetProcessHeap(), 0, pTempTo);
335 } while(FindNextFileA(hFind, &wfd));
340 /* can't find file with specified name */
343 pFrom += strlen(pFrom) + 1;
349 TRACE(" From='%s' To='%s'\n", pFrom, pTo);
351 pTempTo = HeapAlloc(GetProcessHeap(), 0, strlen(pTo)+1);
354 strcpy( pTempTo, pTo );
355 PathRemoveFileSpecA(pTempTo);
356 TRACE(" Creating Directory '%s'\n", pTempTo);
357 SHCreateDirectory(NULL,pTempTo);
358 HeapFree(GetProcessHeap(), 0, pTempTo);
360 if (lpFileOp->wFunc == FO_COPY)
361 CopyFileA(pFrom, pTo, FALSE);
363 MoveFileA(pFrom, pTo);
365 pFrom += strlen(pFrom) + 1;
366 pTo += strlen(pTo) + 1;
369 TRACE("Setting AnyOpsAborted=FALSE\n");
370 lpFileOp->fAnyOperationsAborted=FALSE;
377 WIN32_FIND_DATAA wfd;
378 char szTemp[MAX_PATH];
381 TRACE("File Delete:\n");
384 TRACE(" Pattern='%s'\n", pFrom);
385 if(INVALID_HANDLE_VALUE != (hFind = FindFirstFileA(pFrom, &wfd)))
389 if(strcasecmp(wfd.cFileName, ".") && strcasecmp(wfd.cFileName, ".."))
391 strcpy(szTemp, pFrom);
392 file_name = PathFindFileNameA(szTemp);
394 PathAddBackslashA(szTemp);
395 strcat(szTemp, wfd.cFileName);
397 TRACE(" File='%s'\n", szTemp);
398 if(FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
400 if(!(lpFileOp->fFlags & FOF_FILESONLY))
401 SHELL_DeleteDirectoryA(szTemp, FALSE);
406 } while(FindNextFileA(hFind, &wfd));
410 pFrom += strlen(pFrom) + 1;
412 TRACE("Setting AnyOpsAborted=FALSE\n");
413 lpFileOp->fAnyOperationsAborted=FALSE;
418 TRACE("File Rename:\n");
419 if (pFrom[strlen(pFrom) + 1] != '\0')
421 WARN("Attempt to rename more than one file\n");
424 lpFileOp->fAnyOperationsAborted = FALSE;
425 TRACE("From %s, To %s\n", pFrom, pTo);
426 return !MoveFileA(pFrom, pTo);
429 FIXME("Unhandled shell file operation %d\n", lpFileOp->wFunc);
435 /*************************************************************************
436 * SHFileOperationW [SHELL32.@]
441 DWORD WINAPI SHFileOperationW (LPSHFILEOPSTRUCTW lpFileOp)
443 FIXME("(%p):stub.\n", lpFileOp);
447 /*************************************************************************
448 * SHFileOperation [SHELL32.@]
451 DWORD WINAPI SHFileOperationAW(LPVOID lpFileOp)
453 if (SHELL_OsIsUnicode())
454 return SHFileOperationW(lpFileOp);
455 return SHFileOperationA(lpFileOp);
458 /*************************************************************************
459 * SheGetDirW [SHELL32.281]
462 HRESULT WINAPI SheGetDirW(LPWSTR u, LPWSTR v)
463 { FIXME("%p %p stub\n",u,v);
467 /*************************************************************************
468 * SheChangeDirW [SHELL32.274]
471 HRESULT WINAPI SheChangeDirW(LPWSTR u)
472 { FIXME("(%s),stub\n",debugstr_w(u));
476 /*************************************************************************
477 * IsNetDrive [SHELL32.66]
479 BOOL WINAPI IsNetDrive(DWORD drive)
482 strcpy(root, "A:\\");
484 return (GetDriveTypeA(root) == DRIVE_REMOTE);