source: trunk/src/shell32/shlfileop.c@ 9901

Last change on this file since 9901 was 9833, checked in by sandervl, 23 years ago

DT: Shell file operation updates

File size: 32.0 KB
Line 
1/*
2 * SHFileOperation
3 *
4 * Copyright 2000 Juergen Schmied
5 * Copyright 2002 Andriy Palamarchuk
6 * Copyright 2002 Dietrich Teickner (from Odin)
7 * Copyright 2002 Rolf Kalbermatter
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include "config.h"
25#include "wine/port.h"
26
27#include <string.h>
28#include <ctype.h>
29
30#include "winreg.h"
31#include "shellapi.h"
32#include "shlobj.h"
33#include "shresdef.h"
34#include "shell32_main.h"
35#include "undocshell.h"
36#include "shlwapi.h"
37#include "wine/debug.h"
38
39#define IsAttribFile(x) (!(x == -1) && !(x & FILE_ATTRIBUTE_DIRECTORY))
40#define IsAttribDir(x) (!(x == -1) && (x & FILE_ATTRIBUTE_DIRECTORY))
41
42#define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
43
44WINE_DEFAULT_DEBUG_CHANNEL(shell);
45
46CHAR aWildcardFile[] = {'*','.','*',0};
47WCHAR wWildcardFile[] = {'*','.','*',0};
48WCHAR wWildcardChars[] = {'*','?',0};
49WCHAR wBackslash[] = {'\\',0};
50
51static BOOL SHNotifyCreateDirectoryA(LPCSTR path, LPSECURITY_ATTRIBUTES sec);
52static BOOL SHNotifyCreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sec);
53static BOOL SHNotifyRemoveDirectoryA(LPCSTR path);
54static BOOL SHNotifyRemoveDirectoryW(LPCWSTR path);
55static BOOL SHNotifyDeleteFileA(LPCSTR path);
56static BOOL SHNotifyDeleteFileW(LPCWSTR path);
57
58typedef struct
59{
60 UINT caption_resource_id, text_resource_id;
61} SHELL_ConfirmIDstruc;
62
63static BOOL SHELL_ConfirmIDs(int nKindOfDialog, SHELL_ConfirmIDstruc *ids)
64{
65 switch (nKindOfDialog) {
66 case ASK_DELETE_FILE:
67 ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
68 ids->text_resource_id = IDS_DELETEITEM_TEXT;
69 return TRUE;
70 case ASK_DELETE_FOLDER:
71 ids->caption_resource_id = IDS_DELETEFOLDER_CAPTION;
72 ids->text_resource_id = IDS_DELETEITEM_TEXT;
73 return TRUE;
74 case ASK_DELETE_MULTIPLE_ITEM:
75 ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
76 ids->text_resource_id = IDS_DELETEMULTIPLE_TEXT;
77 return TRUE;
78 case ASK_OVERWRITE_FILE:
79 ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION;
80 ids->text_resource_id = IDS_OVERWRITEFILE_TEXT;
81 return TRUE;
82 default:
83 FIXME(" Unhandled nKindOfDialog %d stub\n", nKindOfDialog);
84 }
85 return FALSE;
86}
87
88BOOL SHELL_ConfirmDialog(int nKindOfDialog, LPCSTR szDir)
89{
90 CHAR szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
91 SHELL_ConfirmIDstruc ids;
92
93 if (!SHELL_ConfirmIDs(nKindOfDialog, &ids))
94 return FALSE;
95
96 LoadStringA(shell32_hInstance, ids.caption_resource_id, szCaption, sizeof(szCaption));
97 LoadStringA(shell32_hInstance, ids.text_resource_id, szText, sizeof(szText));
98
99 FormatMessageA(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
100 szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)&szDir);
101
102 return (IDOK == MessageBoxA(GetActiveWindow(), szBuffer, szCaption, MB_OKCANCEL | MB_ICONEXCLAMATION));
103}
104
105BOOL SHELL_ConfirmDialogW(int nKindOfDialog, LPCWSTR szDir)
106{
107 WCHAR szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
108 SHELL_ConfirmIDstruc ids;
109
110 if (!SHELL_ConfirmIDs(nKindOfDialog, &ids))
111 return FALSE;
112
113 LoadStringW(shell32_hInstance, ids.caption_resource_id, szCaption, sizeof(szCaption));
114 LoadStringW(shell32_hInstance, ids.text_resource_id, szText, sizeof(szText));
115
116 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
117 szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)&szDir);
118
119 return (IDOK == MessageBoxW(GetActiveWindow(), szBuffer, szCaption, MB_OKCANCEL | MB_ICONEXCLAMATION));
120}
121
122/**************************************************************************
123 * SHELL_DeleteDirectoryA()
124 *
125 * like rm -r
126 */
127BOOL SHELL_DeleteDirectoryA(LPCSTR pszDir, BOOL bShowUI)
128{
129 BOOL ret = TRUE;
130 HANDLE hFind;
131 WIN32_FIND_DATAA wfd;
132 char szTemp[MAX_PATH];
133
134 /* Make sure the directory exists before eventually prompting the user */
135 PathCombineA(szTemp, pszDir, aWildcardFile);
136 hFind = FindFirstFileA(szTemp, &wfd);
137 if (hFind == INVALID_HANDLE_VALUE)
138 return FALSE;
139
140 if (!bShowUI || SHELL_ConfirmDialog(ASK_DELETE_FOLDER, pszDir))
141 {
142 do
143 {
144 LPSTR lp = wfd.cAlternateFileName;
145 if (!lp[0])
146 lp = wfd.cFileName;
147 if (IsDotDir(lp))
148 continue;
149 PathCombineA(szTemp, pszDir, lp);
150 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
151 ret = SHELL_DeleteDirectoryA(szTemp, FALSE);
152 else
153 ret = SHNotifyDeleteFileA(szTemp);
154 } while (ret && FindNextFileA(hFind, &wfd));
155 }
156 FindClose(hFind);
157 if (ret)
158 ret = SHNotifyRemoveDirectoryA(pszDir);
159 return ret;
160}
161
162BOOL SHELL_DeleteDirectoryW(LPCWSTR pszDir, BOOL bShowUI)
163{
164 BOOL ret = TRUE;
165 HANDLE hFind;
166 WIN32_FIND_DATAW wfd;
167 WCHAR szTemp[MAX_PATH];
168
169 /* Make sure the directory exists before eventually prompting the user */
170 PathCombineW(szTemp, pszDir, wWildcardFile);
171 hFind = FindFirstFileW(szTemp, &wfd);
172 if (hFind == INVALID_HANDLE_VALUE)
173 return FALSE;
174
175 if (!bShowUI || SHELL_ConfirmDialogW(ASK_DELETE_FOLDER, pszDir))
176 {
177 do
178 {
179 LPWSTR lp = wfd.cAlternateFileName;
180 if (!lp[0])
181 lp = wfd.cFileName;
182 if (IsDotDir(lp))
183 continue;
184 PathCombineW(szTemp, pszDir, lp);
185 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
186 ret = SHELL_DeleteDirectoryW(szTemp, FALSE);
187 else
188 ret = SHNotifyDeleteFileW(szTemp);
189 } while (ret && FindNextFileW(hFind, &wfd));
190 }
191 FindClose(hFind);
192 if (ret)
193 ret = SHNotifyRemoveDirectoryW(pszDir);
194 return ret;
195}
196
197/**************************************************************************
198 * SHELL_DeleteFileA()
199 */
200BOOL SHELL_DeleteFileA(LPCSTR pszFile, BOOL bShowUI)
201{
202 if (bShowUI && !SHELL_ConfirmDialog(ASK_DELETE_FILE, pszFile))
203 return FALSE;
204
205 return SHNotifyDeleteFileA(pszFile);
206}
207
208BOOL SHELL_DeleteFileW(LPCWSTR pszFile, BOOL bShowUI)
209{
210 if (bShowUI && !SHELL_ConfirmDialogW(ASK_DELETE_FILE, pszFile))
211 return FALSE;
212
213 return SHNotifyDeleteFileW(pszFile);
214}
215
216/**************************************************************************
217 * Win32CreateDirectory (SHELL32_93) [SHELL32.93]
218 *
219 * Creates a directory. Also triggers a change notify if one exists.
220 */
221static BOOL SHNotifyCreateDirectoryA(LPCSTR path, LPSECURITY_ATTRIBUTES sec)
222{
223 BOOL ret;
224 TRACE("(%s, %p)\n", debugstr_a(path), sec);
225
226 ret = CreateDirectoryA(path, sec);
227 if (ret)
228 {
229 SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHA, path, NULL);
230 }
231 return ret;
232}
233
234static BOOL SHNotifyCreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
235{
236 BOOL ret;
237 TRACE("(%s, %p)\n", debugstr_w(path), sec);
238
239 ret = CreateDirectoryW(path, sec);
240 if (ret)
241 {
242 SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHW, path, NULL);
243 }
244 return ret;
245}
246
247BOOL WINAPI Win32CreateDirectoryAW(LPCVOID path, LPSECURITY_ATTRIBUTES sec)
248{
249 if (SHELL_OsIsUnicode())
250 return SHNotifyCreateDirectoryW(path, sec);
251 return SHNotifyCreateDirectoryA(path, sec);
252}
253
254/************************************************************************
255 * Win32RemoveDirectory (SHELL32_94) [SHELL32.94]
256 *
257 * Deletes a directory. Also triggers a change notify if one exists.
258 */
259static BOOL SHNotifyRemoveDirectoryA(LPCSTR path)
260{
261 BOOL ret;
262 TRACE("(%s)\n", debugstr_a(path));
263
264 ret = RemoveDirectoryA(path);
265 if (!ret)
266 {
267 /* Directory may be write protected */
268 DWORD dwAttr = GetFileAttributesA(path);
269 if (dwAttr != -1 && dwAttr & FILE_ATTRIBUTE_READONLY)
270 if (SetFileAttributesA(path, dwAttr & ~FILE_ATTRIBUTE_READONLY))
271 ret = RemoveDirectoryA(path);
272 }
273 if (ret)
274 SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHA, path, NULL);
275 return ret;
276}
277
278static BOOL SHNotifyRemoveDirectoryW(LPCWSTR path)
279{
280 BOOL ret;
281 TRACE("(%s)\n", debugstr_w(path));
282
283 ret = RemoveDirectoryW(path);
284 if (!ret)
285 {
286 /* Directory may be write protected */
287 DWORD dwAttr = GetFileAttributesW(path);
288 if (dwAttr != -1 && dwAttr & FILE_ATTRIBUTE_READONLY)
289 if (SetFileAttributesW(path, dwAttr & ~FILE_ATTRIBUTE_READONLY))
290 ret = RemoveDirectoryW(path);
291 }
292 if (ret)
293 SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHW, path, NULL);
294 return ret;
295}
296
297BOOL WINAPI Win32RemoveDirectoryAW(LPCVOID path)
298{
299 if (SHELL_OsIsUnicode())
300 return SHNotifyRemoveDirectoryW(path);
301 return SHNotifyRemoveDirectoryA(path);
302}
303
304/************************************************************************
305 * Win32DeleteFile (SHELL32_164) [SHELL32.164]
306 *
307 * Deletes a file. Also triggers a change notify if one exists.
308 *
309 * NOTES:
310 * Verified on Win98 / IE 5 (SHELL32 4.72, March 1999 build) to be ANSI.
311 * This is Unicode on NT/2000
312 */
313static BOOL SHNotifyDeleteFileA(LPCSTR path)
314{
315 BOOL ret;
316
317 TRACE("(%s)\n", debugstr_a(path));
318
319 ret = DeleteFileA(path);
320 if (!ret)
321 {
322 /* File may be write protected or a system file */
323 DWORD dwAttr = GetFileAttributesA(path);
324 if ((dwAttr != -1) && (dwAttr & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
325 if (SetFileAttributesA(path, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
326 ret = DeleteFileA(path);
327 }
328 if (ret)
329 SHChangeNotify(SHCNE_DELETE, SHCNF_PATHA, path, NULL);
330 return ret;
331}
332
333static BOOL SHNotifyDeleteFileW(LPCWSTR path)
334{
335 BOOL ret;
336
337 TRACE("(%s)\n", debugstr_w(path));
338
339 ret = DeleteFileW(path);
340 if (!ret)
341 {
342 /* File may be write protected or a system file */
343 DWORD dwAttr = GetFileAttributesW(path);
344 if ((dwAttr != -1) && (dwAttr & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
345 if (SetFileAttributesW(path, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
346 ret = DeleteFileW(path);
347 }
348 if (ret)
349 SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, path, NULL);
350 return ret;
351}
352
353DWORD WINAPI Win32DeleteFileAW(LPCVOID path)
354{
355 if (SHELL_OsIsUnicode())
356 return SHNotifyDeleteFileW(path);
357 return SHNotifyDeleteFileA(path);
358}
359
360/*************************************************************************
361 * SHCreateDirectory [SHELL32.165]
362 *
363 * NOTES
364 * exported by ordinal
365 * WinNT/2000 exports Unicode
366 */
367DWORD WINAPI SHCreateDirectory(HWND hWnd, LPCVOID path)
368{
369 if (SHELL_OsIsUnicode())
370 return SHCreateDirectoryExW(hWnd, path, NULL);
371 return SHCreateDirectoryExA(hWnd, path, NULL);
372}
373
374/*************************************************************************
375 * SHCreateDirectoryExA [SHELL32.@]
376 */
377DWORD WINAPI SHCreateDirectoryExA(HWND hWnd, LPCSTR path, LPSECURITY_ATTRIBUTES sec)
378{
379 WCHAR wPath[MAX_PATH];
380 TRACE("(%p, %s, %p)\n",hWnd, debugstr_a(path), sec);
381
382 MultiByteToWideChar(CP_ACP, 0, path, -1, wPath, MAX_PATH);
383 return SHCreateDirectoryExW(hWnd, wPath, sec);
384}
385
386/*************************************************************************
387 * SHCreateDirectoryExW [SHELL32.@]
388 */
389DWORD WINAPI SHCreateDirectoryExW(HWND hWnd, LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
390{
391 DWORD ret = ERROR_SUCCESS;
392 TRACE("(%p, %s, %p)\n",hWnd, debugstr_w(path), sec);
393
394 if (PathIsRelativeW(path))
395 {
396 ret = ERROR_BAD_PATHNAME;
397 SetLastError(ERROR_BAD_PATHNAME);
398 }
399 else
400 {
401 if (!SHNotifyCreateDirectoryW(path, sec))
402 {
403 ret = GetLastError();
404 if (ret != ERROR_FILE_EXISTS &&
405 ret != ERROR_ALREADY_EXISTS &&
406 ret != ERROR_FILENAME_EXCED_RANGE)
407 {
408 /*lstrcpynW(pathName, path, MAX_PATH);
409 lpStr = PathAddBackslashW(pathName);*/
410 FIXME("Semi-stub, non zero hWnd should be used somehow?");
411 }
412 }
413 }
414 return ret;
415}
416
417/*************************************************************************
418 *
419 * SHFileStrICmp HelperFunction for SHFileOperationW
420 *
421 */
422BOOL SHFileStrICmpW(LPWSTR p1, LPWSTR p2, LPWSTR p1End, LPWSTR p2End)
423{
424 WCHAR C1 = '\0';
425 WCHAR C2 = '\0';
426 int i_Temp = -1;
427 int i_len1 = lstrlenW(p1);
428 int i_len2 = lstrlenW(p2);
429
430 if (p1End && (&p1[i_len1] >= p1End) && ('\\' == p1End[0]))
431 {
432 C1 = p1End[0];
433 p1End[0] = '\0';
434 i_len1 = lstrlenW(p1);
435 }
436 if (p2End)
437 {
438 if ((&p2[i_len2] >= p2End) && ('\\' == p2End[0]))
439 {
440 C2 = p2End[0];
441 if (C2)
442 p2End[0] = '\0';
443 }
444 }
445 else
446 {
447 if ((i_len1 <= i_len2) && ('\\' == p2[i_len1]))
448 {
449 C2 = p2[i_len1];
450 if (C2)
451 p2[i_len1] = '\0';
452 }
453 }
454 i_len2 = lstrlenW(p2);
455 if (i_len1 == i_len2)
456 i_Temp = lstrcmpiW(p1,p2);
457 if (C1)
458 p1[i_len1] = C1;
459 if (C2)
460 p2[i_len2] = C2;
461 return !(i_Temp);
462}
463
464/*************************************************************************
465 *
466 * SHFileStrCpyCat HelperFunction for SHFileOperationW
467 *
468 */
469LPWSTR SHFileStrCpyCatW(LPWSTR pTo, LPCWSTR pFrom, LPCWSTR pCatStr)
470{
471 LPWSTR pToFile = NULL;
472 int i_len;
473 if (pTo)
474 {
475 if (pFrom)
476 lstrcpyW(pTo, pFrom);
477 if (pCatStr)
478 {
479 i_len = lstrlenW(pTo);
480 if ((i_len) && (pTo[--i_len] != '\\'))
481 i_len++;
482 pTo[i_len] = '\\';
483 if (pCatStr[0] == '\\')
484 pCatStr++; \
485 lstrcpyW(&pTo[i_len+1], pCatStr);
486 }
487 pToFile = StrRChrW(pTo,NULL,'\\');
488/* !! termination of the new string-group */
489 pTo[(lstrlenW(pTo)) + 1] = '\0';
490 }
491 return pToFile;
492}
493
494/*************************************************************************
495 *
496 * SHName(s)Translate HelperFunction for SHFileOperationA
497 *
498 */
499DWORD SHNameTranslate(LPWSTR* wString, LPCWSTR* pWToFrom, BOOL more)
500{
501 DWORD retSize = 0, size;
502 LPCSTR aString = (LPSTR)pWToFrom[0];
503 if (pWToFrom[0])
504 {
505 if (wString[0]) /* only in the second loop */
506 pWToFrom[0] = wString[0];
507 do
508 {
509 size = lstrlenA(aString) + 1;
510 if (wString[0]) /* only in the second loop */
511 {
512 MultiByteToWideChar(CP_ACP, 0, aString, size, wString[0], size);
513 wString[0] += size;
514 }
515 aString += size;
516 retSize += size;
517 } while ((size != 1) & more);
518 retSize = ((retSize+0x7) & -8);
519 }
520return retSize;
521}
522/*************************************************************************
523 * SHFileOperationA [SHELL32.@]
524 *
525 * NOTES
526 * exported by name
527 */
528DWORD WINAPI SHFileOperationA(LPSHFILEOPSTRUCTA lpFileOp)
529{
530 SHFILEOPSTRUCTW nFileOp = *((LPSHFILEOPSTRUCTW)lpFileOp);
531 DWORD retCode = 0, size = 0;
532 LPWSTR wString = NULL; /* we change this in SHNameTranlate */
533 LPWSTR ForFree = NULL;
534
535 TRACE("SHFileOperationA");
536 if (FO_DELETE == (nFileOp.wFunc & 0xf))
537 nFileOp.pTo = NULL; /* we need a NULL or a valid pointer for translation */
538 if (!(nFileOp.fFlags & FOF_SIMPLEPROGRESS))
539 nFileOp.lpszProgressTitle = NULL; /* we need a NULL or a valid pointer for translation */
540 do
541 {
542 if (size)
543 {
544 ForFree = wString = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
545 if (!wString)
546 {
547 retCode = ERROR_OUTOFMEMORY;
548 goto shfileop_error;
549 }
550 }
551 size = SHNameTranslate(&wString, &nFileOp.lpszProgressTitle, FALSE); /* no loop */
552 size += SHNameTranslate(&wString, &nFileOp.pFrom, TRUE); /* internal loop */
553 size += SHNameTranslate(&wString, &nFileOp.pTo, TRUE); /* internal loop */
554 /* first loop only for calculate size, no translation, we hav a NULL-pointer */
555 } while (!ForFree); /* second loop calculate size, also translation. We have a valid pointer */
556
557 retCode = SHFileOperationW(&nFileOp);
558
559shfileop_error:
560 if (ForFree)
561 HeapFree(GetProcessHeap(), 0, ForFree);
562
563 if (retCode)
564 {
565 nFileOp.fAnyOperationsAborted = TRUE;
566 SetLastError(retCode);
567 }
568 lpFileOp->hNameMappings = nFileOp.hNameMappings;
569 lpFileOp->fAnyOperationsAborted = nFileOp.fAnyOperationsAborted;
570 return retCode;
571}
572
573/*************************************************************************
574 * SHFileOperationW [SHELL32.@]
575 *
576 * NOTES
577 * exported by name
578 */
579DWORD WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
580{
581 SHFILEOPSTRUCTW nFileOp = *(lpFileOp);
582
583 LPCWSTR pNextFrom = nFileOp.pFrom;
584 LPCWSTR pNextTo = nFileOp.pTo;
585 LPCWSTR pFrom = pNextFrom;
586 LPCWSTR pTo = NULL;
587 HANDLE hFind = INVALID_HANDLE_VALUE;
588 WIN32_FIND_DATAW wfd;
589 LPWSTR pTempFrom = NULL;
590 LPWSTR pTempTo = NULL;
591 LPWSTR pFromFile;
592 LPWSTR pToFile;
593 LPWSTR lpFileName;
594 long retCode = 0;
595 DWORD ToAttr;
596 DWORD ToPathAttr;
597 FILEOP_FLAGS OFl = ((FILEOP_FLAGS)lpFileOp->fFlags & 0x7ff);
598
599 BOOL b_Multi = (nFileOp.fFlags & FOF_MULTIDESTFILES);
600
601 BOOL b_MultiTo = (FO_DELETE != (lpFileOp->wFunc & 0xf));
602 BOOL b_MultiFrom = FALSE;
603 BOOL not_overwrite;
604 BOOL ask_overwrite;
605 BOOL b_SameRoot;
606 BOOL b_SameTailName;
607 BOOL b_ToInvalidTail;
608 BOOL b_ToValid; /* for W98-Bug for FO_MOVE with source and taget in same rootdrive */
609 BOOL b_Mask; /* wird als Schalter benutzt, vieleicht finde ich die richtige bitposition */
610 BOOL b_ToTailSlash;
611 LPCSTR cFO_Name [] = {"FO_????","FO_MOVE","FO_COPY","FO_DELETE","FO_RENAME"};
612
613 long FuncSwitch = (nFileOp.wFunc & 0xf);
614 long level= nFileOp.wFunc>>4;
615
616/* default no error */
617 nFileOp.fAnyOperationsAborted = FALSE;
618
619 if ((FuncSwitch < FO_MOVE) || (FuncSwitch > FO_RENAME))
620 goto shfileop_normal; /* no valid FunctionCode */
621
622 cFO_Name[0] = cFO_Name [FuncSwitch];
623 if (level == 0)
624 TRACE("%s: flags (0x%04x) : %s%s%s%s%s%s%s%s%s%s%s%s \n",cFO_Name[0], nFileOp.fFlags,
625 nFileOp.fFlags & FOF_MULTIDESTFILES ? "FOF_MULTIDESTFILES " : "",
626 nFileOp.fFlags & FOF_CONFIRMMOUSE ? "FOF_CONFIRMMOUSE " : "",
627 nFileOp.fFlags & FOF_SILENT ? "FOF_SILENT " : "",
628 nFileOp.fFlags & FOF_RENAMEONCOLLISION ? "FOF_RENAMEONCOLLISION " : "",
629 nFileOp.fFlags & FOF_NOCONFIRMATION ? "FOF_NOCONFIRMATION " : "",
630 nFileOp.fFlags & FOF_WANTMAPPINGHANDLE ? "FOF_WANTMAPPINGHANDLE " : "",
631 nFileOp.fFlags & FOF_ALLOWUNDO ? "FOF_ALLOWUNDO " : "",
632 nFileOp.fFlags & FOF_FILESONLY ? "FOF_FILESONLY " : "",
633 nFileOp.fFlags & FOF_SIMPLEPROGRESS ? "FOF_SIMPLEPROGRESS " : "",
634 nFileOp.fFlags & FOF_NOCONFIRMMKDIR ? "FOF_NOCONFIRMMKDIR " : "",
635 nFileOp.fFlags & FOF_NOERRORUI ? "FOF_NOERRORUI " : "",
636 nFileOp.fFlags & 0xf800 ? "MORE-UNKNOWN-Flags" : "");
637 ;
638 {
639 /* establish when pTo is interpreted as the name of the destination file
640 * or the directory where the Fromfile should be copied to.
641 * This depends on:
642 * (1) pTo points to the name of an existing directory;
643 * (2) the flag FOF_MULTIDESTFILES is present;
644 * (3) whether pFrom point to multiple filenames.
645 *
646 * Some experiments:
647 *
648 * destisdir 1 1 1 1 0 0 0 0
649 * FOF_MULTIDESTFILES 1 1 0 0 1 1 0 0
650 * multiple from filenames 1 0 1 0 1 0 1 0
651 * ---------------
652 * copy files to dir 1 0 1 1 0 0 1 0
653 * create dir 0 0 0 0 0 0 1 0
654 */
655/*
656 * FOF_MULTIDESTFILES, FOF_NOCONFIRMATION, FOF_FILESONLY are implemented
657 * FOF_CONFIRMMOUSE, FOF_SILENT, FOF_NOCONFIRMMKDIR, FOF_SIMPLEPROGRESS are not implemented and ignored
658 * FOF_RENAMEONCOLLISION are implemented partially and breaks if file exist
659 * FOF_ALLOWUNDO, FOF_WANTMAPPINGHANDLE are not implemented and breaks
660 * if any other flag set, an error occurs
661 */
662 TRACE(" %s level=%d nFileOp.fFlags=0x%x\n", cFO_Name[0], level, lpFileOp->fFlags);
663
664/* OFl &= (-1 - (FOF_MULTIDESTFILES | FOF_FILESONLY)); */
665/* OFl ^= (FOF_SILENT | FOF_NOCONFIRMATION | FOF_SIMPLEPROGRESS | FOF_NOCONFIRMMKDIR); */
666 OFl &= (~(FOF_MULTIDESTFILES | FOF_NOCONFIRMATION | FOF_FILESONLY)); /* implemented */
667 OFl ^= (FOF_SILENT | FOF_NOCONFIRMMKDIR); /* ignored, if one */
668 OFl &= (~FOF_SIMPLEPROGRESS); /* ignored, only with FOF_SILENT */
669 if (OFl)
670 {
671 if (OFl & ( ~ (FOF_CONFIRMMOUSE | FOF_SILENT | FOF_RENAMEONCOLLISION | FOF_NOCONFIRMMKDIR)))
672 {
673 TRACE("%s level=%d lpFileOp->fFlags=0x%x not implemented, Aborted=TRUE, stub\n", cFO_Name[0], level, OFl);
674 retCode = 0x403; /* 1027, we need a extension of shlfileop */
675 goto shfileop_error;
676 }
677 else
678 {
679 TRACE("%s level=%d lpFileOp->fFlags=0x%x not full implemented ,stub\n", cFO_Name[0], level, OFl);
680 } /* endif */
681 } /* endif */
682
683 if ((pNextFrom) && (!(b_MultiTo) || (pNextTo)))
684 {
685 nFileOp.pFrom = pTempFrom = HeapAlloc(GetProcessHeap(), 0, ((1 + 2 * (b_MultiTo)) * MAX_PATH + 6) * sizeof(WCHAR));
686 if (b_MultiTo)
687 pTempTo = &pTempFrom[MAX_PATH + 4];
688 nFileOp.pTo = pTempTo;
689 ask_overwrite = (!(nFileOp.fFlags & FOF_NOCONFIRMATION) && !(nFileOp.fFlags & FOF_RENAMEONCOLLISION));
690 not_overwrite = (!(nFileOp.fFlags & FOF_NOCONFIRMATION) || (nFileOp.fFlags & FOF_RENAMEONCOLLISION));
691 }
692 else
693 {
694 retCode = 0x402; /* 1026 */
695 goto shfileop_error;
696 }
697/* need break at error before change sourcepointer */
698 while(!nFileOp.fAnyOperationsAborted && (pNextFrom[0]))
699 {
700 nFileOp.wFunc = ((level + 1) << 4) + FuncSwitch;
701 nFileOp.fFlags = lpFileOp->fFlags;
702
703 if (b_MultiTo)
704 {
705 pTo = pNextTo;
706 pNextTo = &pNextTo[lstrlenW(pTo)+1];
707 b_MultiTo = (b_Multi && pNextTo[0]);
708 }
709
710 pFrom = pNextFrom;
711 pNextFrom = &pNextFrom[lstrlenW(pNextFrom)+1];
712 if (!b_MultiFrom && !b_MultiTo)
713 b_MultiFrom = (pNextFrom[0]);
714
715 pFromFile = SHFileStrCpyCatW(pTempFrom, pFrom, NULL);
716
717 if (pTo)
718 {
719 pToFile = SHFileStrCpyCatW(pTempTo, pTo, NULL);
720 }
721 if (!(pFromFile) || !(pFromFile[1]) || ((pTo) && !(pToFile)))
722 {
723 retCode = 0x402; /* 1026 */
724 goto shfileop_error;
725 }
726 if (pTo)
727 {
728 b_ToTailSlash = (!pToFile[1]);
729 if (b_ToTailSlash)
730 {
731 pToFile[0] = '\0';
732 if (StrChrW(pTempTo,'\\'))
733 {
734 pToFile = SHFileStrCpyCatW(pTempTo, NULL, NULL);
735 }
736 }
737 b_ToInvalidTail = (NULL != StrPBrkW(&pToFile[1], wWildcardChars));
738 }
739
740 /* for all */
741 b_Mask = (NULL != StrPBrkW(&pFromFile[1], wWildcardChars));
742 if (FO_RENAME == FuncSwitch)
743 {
744 /* temporary only for FO_RENAME */
745/* ??? b_Mask = (NULL != strrbrk(pFrom,"*?")); */
746 if (b_MultiTo || b_MultiFrom || (b_Mask && !b_ToInvalidTail))
747 {
748 /* no work, only RC=0 */
749/* ??? nFileOp.fAnyOperationsAborted = TRUE; */
750 goto shfileop_normal;
751 }
752 }
753
754 hFind = FindFirstFileW(pFrom, &wfd);
755 if (INVALID_HANDLE_VALUE == hFind)
756 {
757 /* root (without mask) is also not allowed as source, tested in W98 */
758 retCode = 0x402; /* 1026 */
759 goto shfileop_error;
760 } /* endif */
761
762/* for all */
763#define HIGH_ADR (LPWSTR)0xffffffff
764
765/* ??? b_Mask = (!SHFileStrICmpA(&pFromFile[1], &wfd.cFileName[0], HIGH_ADR, HIGH_ADR)); */
766
767 if (!pTo) /* FO_DELETE */
768 {
769 do
770 {
771 lpFileName = wfd.cAlternateFileName;
772 if (!lpFileName[0])
773 lpFileName = wfd.cFileName;
774 if (IsDotDir(lpFileName))
775 continue;
776 SHFileStrCpyCatW(&pFromFile[1], lpFileName, NULL);
777 /* TODO: Check the SHELL_DeleteFileOrDirectoryW() function in shell32.dll */
778 if (IsAttribFile(wfd.dwFileAttributes))
779 {
780 nFileOp.fAnyOperationsAborted = (!SHNotifyDeleteFileW(pTempFrom));
781 retCode = 0x78; /* value unknown */
782 }
783 else
784 {
785 nFileOp.fAnyOperationsAborted = (!SHELL_DeleteDirectoryW(pTempFrom, (!(nFileOp.fFlags & FOF_NOCONFIRMATION))));
786 retCode = 0x79; /* value unknown */
787 }
788 } while (!nFileOp.fAnyOperationsAborted && FindNextFileW(hFind, &wfd));
789 FindClose(hFind);
790 hFind = INVALID_HANDLE_VALUE;
791 if (nFileOp.fAnyOperationsAborted)
792 {
793 goto shfileop_error;
794 }
795 continue;
796 } /* FO_DELETE ends, pTo must be always valid from here */
797
798 b_SameRoot = (towupper(pTempFrom[0]) == towupper(pTempTo[0]));
799 b_SameTailName = SHFileStrICmpW(pToFile, pFromFile, NULL, NULL);
800
801 ToPathAttr = ToAttr = GetFileAttributesW(pTempTo);
802 if (!b_Mask && (ToAttr -1) && (pToFile))
803 {
804 pToFile[0] = '\0';
805 ToPathAttr = GetFileAttributesW(pTempTo);
806 pToFile[0] = '\\';
807 }
808
809 if (FO_RENAME == FuncSwitch)
810 {
811 if (!b_SameRoot || b_Mask /* FO_RENAME works not with Mask */
812 || !SHFileStrICmpW(pTempFrom, pTempTo, pFromFile, NULL)
813 || (SHFileStrICmpW(pTempFrom, pTempTo, pFromFile, HIGH_ADR) && !b_ToTailSlash))
814 {
815 retCode = 0x73;
816 goto shfileop_error;
817 }
818 if (b_ToInvalidTail)
819 {
820 retCode=0x2;
821 goto shfileop_error;
822 }
823 if (-1 == ToPathAttr)
824 {
825 retCode = 0x75;
826 goto shfileop_error;
827 }
828 if (IsAttribDir(wfd.dwFileAttributes) && IsAttribDir(ToAttr))
829 {
830 retCode = (b_ToTailSlash) ? 0xb7 : 0x7b;
831 goto shfileop_error;
832 } /* endif */
833 /* TODO: use SHNotifyMoveFile() instead ?? */
834 if (!MoveFileW(pTempFrom, pTempTo))
835 {
836 /* we need still the value for the returncode, we use the mostly assumed */
837 retCode = 0xb7;
838 goto shfileop_error;
839 }
840 goto shfileop_normal;
841 }
842
843 /* W98 Bug with FO_MOVE different to FO_COPY, better the same as FO_COPY */
844 b_ToValid = ((b_SameTailName && b_SameRoot && (FO_COPY == FuncSwitch)) ||
845 (b_SameTailName && !b_SameRoot) || (b_ToInvalidTail));
846
847 /* handle mask in source */
848 if (b_Mask)
849 {
850 if (!IsAttribDir(ToAttr))
851 {
852 retCode = (b_ToInvalidTail &&/* b_SameTailName &&*/ (FO_MOVE == FuncSwitch)) \
853 ? 0x2 : 0x75;
854 goto shfileop_error;
855 }
856 pToFile = SHFileStrCpyCatW(pTempTo, NULL, wBackslash);
857 nFileOp.fFlags = (nFileOp.fFlags | FOF_MULTIDESTFILES);
858 do
859 {
860 lpFileName = wfd.cAlternateFileName;
861 if (!lpFileName[0])
862 lpFileName = wfd.cFileName;
863 if (IsDotDir(lpFileName) ||
864 (IsAttribDir(wfd.dwFileAttributes) && (nFileOp.fFlags & FOF_FILESONLY)))
865 continue; /* next name in pTempFrom(dir) */
866 SHFileStrCpyCatW(&pToFile[1], lpFileName, NULL);
867 SHFileStrCpyCatW(&pFromFile[1], lpFileName, NULL);
868 retCode = SHFileOperationW (&nFileOp);
869 } while(!nFileOp.fAnyOperationsAborted && FindNextFileW(hFind, &wfd));
870 }
871 FindClose(hFind);
872 hFind = INVALID_HANDLE_VALUE;
873 /* FO_COPY/FO_MOVE with mask, FO_DELETE and FO_RENAME are solved */
874 if (b_Mask)
875 continue;
876
877 /* only FO_COPY/FO_MOVE without mask, all others are (must be) solved */
878 if (IsAttribDir(wfd.dwFileAttributes) && (ToAttr -1))
879 {
880 if (pToFile)
881 {
882 pToFile[0] = '\0';
883 ToPathAttr = GetFileAttributesW(pTempTo);
884 if ((ToPathAttr == -1) && b_ToValid)
885 {
886 /* create dir must be here, sample target D:\y\ *.* create with RC=10003 */
887 if (SHCreateDirectoryExW(NULL, pTempTo, NULL))
888 {
889 retCode = 0x73;/* value unknown */
890 goto shfileop_error;
891 }
892 ToPathAttr = GetFileAttributesW(pTempTo);
893 }
894 pToFile[0] = '\\';
895 if (b_ToInvalidTail)
896 {
897 retCode = 0x10003;
898 goto shfileop_error;
899 }
900 }
901 }
902
903 /* trailing BackSlash is ever removed and pToFile points to BackSlash before */
904 if (!b_MultiTo && (b_MultiFrom || (!(b_Multi) && IsAttribDir(ToAttr))))
905 {
906 if ((FO_MOVE == FuncSwitch) && IsAttribDir(ToAttr) && IsAttribDir(wfd.dwFileAttributes))
907 {
908 if (b_Multi)
909 {
910 retCode = 0x73; /* !b_Multi = 0x8 ?? */
911 goto shfileop_error;
912 }
913 }
914 pToFile = SHFileStrCpyCatW(pTempTo, NULL, wfd.cFileName);
915 ToAttr = GetFileAttributesW(pTempTo);
916 }
917
918 if (IsAttribDir(ToAttr))
919 {
920 if (IsAttribFile(wfd.dwFileAttributes))
921 {
922 retCode = (FO_COPY == FuncSwitch) ? 0x75 : 0xb7;
923 goto shfileop_error;
924 }
925 }
926 else
927 {
928 pToFile[0] = '\0';
929 ToPathAttr = GetFileAttributesW(pTempTo);
930 pToFile[0] = '\\';
931 if (IsAttribFile(ToPathAttr))
932 {
933 /* error, is this tested ? */
934 retCode = 0x777402;
935 goto shfileop_error;
936 } /* endif */
937 }
938
939 /* singlesource + no mask */
940 if (-1 == (ToAttr & ToPathAttr))
941 {
942 /* Target-dir does not exist, and cannot be created */
943 retCode=0x75;
944 goto shfileop_error;
945 }
946
947 switch(FuncSwitch)
948 {
949 case FO_MOVE:
950 pToFile = NULL;
951 if ((ToAttr == -1) && SHFileStrICmpW(pTempFrom, pTempTo, pFromFile, NULL))
952 {
953 nFileOp.wFunc = ((level+1)<<4) + FO_RENAME;
954 }
955 else
956 {
957 if (b_SameRoot && IsAttribDir(ToAttr) && IsAttribDir(wfd.dwFileAttributes))
958 {
959 /* we need pToFile for FO_DELETE after FO_MOVE contence */
960 pToFile = SHFileStrCpyCatW(pTempFrom, NULL, wWildcardFile);
961 }
962 else
963 {
964 nFileOp.wFunc = ((level+1)<<4) + FO_COPY;
965 }
966 }
967 retCode = SHFileOperationW(&nFileOp);
968 if (pToFile)
969 ((DWORD*)pToFile)[0] = '\0';
970 if (!nFileOp.fAnyOperationsAborted && (FO_RENAME != (nFileOp.wFunc & 0xf)))
971 {
972 nFileOp.wFunc = ((level+1)<<4) + FO_DELETE;
973 retCode = SHFileOperationW(&nFileOp);
974 }
975 continue;
976 case FO_COPY:
977 if (SHFileStrICmpW(pTempFrom, pTempTo, NULL, NULL))
978 { /* target is the same as source ? */
979 /* we still need the value for the returncode, we assume 0x71 */
980 retCode = 0x71;
981 goto shfileop_error;
982 } /* endif */
983 if (IsAttribDir((ToAttr & wfd.dwFileAttributes)))
984 {
985 if (IsAttribDir(ToAttr) || !SHCreateDirectoryExW(NULL,pTempTo, NULL))
986 {
987/* ??? nFileOp.fFlags = (nFileOp.fFlags | FOF_MULTIDESTFILES); */
988 SHFileStrCpyCatW(pTempFrom, NULL, wWildcardFile);
989 retCode = SHFileOperationW(&nFileOp);
990 }
991 else
992 {
993 retCode = 0x750;/* value unknown */
994 goto shfileop_error;
995 }
996 }
997 else
998 {
999 if (!(ask_overwrite && SHELL_ConfirmDialogW(ASK_OVERWRITE_FILE, pTempTo))
1000 && (not_overwrite))
1001 {
1002 /* we still need the value for the returncode, we use the mostly assumed */
1003 retCode = 0x73;
1004 goto shfileop_error;
1005 }
1006 /* TODO: use SHNotifyCopyFile() */
1007 if (!(CopyFileW(pTempFrom, pTempTo, FALSE)))
1008 {
1009 retCode = 0x77; /* value unknown */
1010 goto shfileop_error;
1011 }
1012 }
1013 } /* end-switch */
1014 } /* end-while */
1015 }
1016shfileop_normal:
1017 if (!(nFileOp.fAnyOperationsAborted))
1018 retCode = 0;
1019shfileop_error:
1020 if (hFind != INVALID_HANDLE_VALUE)
1021 FindClose(hFind);
1022 hFind = INVALID_HANDLE_VALUE;
1023 if (pTempFrom)
1024 HeapFree(GetProcessHeap(), 0, pTempFrom);
1025 if (retCode)
1026 {
1027 nFileOp.fAnyOperationsAborted = TRUE;
1028 SetLastError(retCode);
1029 }
1030 TRACE("%s level=%d AnyOpsAborted=%s ret=0x%x, with %s%s%s\n",
1031 cFO_Name[0], level, nFileOp.fAnyOperationsAborted ? "TRUE":"FALSE",
1032 retCode, debugstr_w(pFrom), pTo ? " -> ":"", debugstr_w(pTo));
1033
1034 lpFileOp->fAnyOperationsAborted = nFileOp.fAnyOperationsAborted;
1035 return retCode;
1036}
1037
1038/*************************************************************************
1039 * SHFileOperation [SHELL32.@]
1040 *
1041 */
1042DWORD WINAPI SHFileOperationAW(LPVOID lpFileOp)
1043{
1044 if (SHELL_OsIsUnicode())
1045 return SHFileOperationW(lpFileOp);
1046 return SHFileOperationA(lpFileOp);
1047}
1048
1049/*************************************************************************
1050 * SheGetDirW [SHELL32.281]
1051 *
1052 */
1053HRESULT WINAPI SheGetDirW(LPWSTR u, LPWSTR v)
1054{ FIXME("%p %p stub\n",u,v);
1055 return 0;
1056}
1057
1058/*************************************************************************
1059 * SheChangeDirW [SHELL32.274]
1060 *
1061 */
1062HRESULT WINAPI SheChangeDirW(LPWSTR u)
1063{ FIXME("(%s),stub\n",debugstr_w(u));
1064 return 0;
1065}
1066
1067/*************************************************************************
1068 * IsNetDrive [SHELL32.66]
1069 */
1070BOOL WINAPI IsNetDrive(DWORD drive)
1071{
1072 char root[4];
1073 strcpy(root, "A:\\");
1074 root[0] += (char)drive;
1075 return (GetDriveTypeA(root) == DRIVE_REMOTE);
1076}
1077
1078
1079
1080
Note: See TracBrowser for help on using the repository browser.