4 * Copyright 2000 Juergen Schmied
5 * Copyright 2002 Andriy Palamarchuk
6 * Copyright 2004 Dietrich Teickner (from Odin)
7 * Copyright 2004 Rolf Kalbermatter
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
28 #define IsAttrib(x, y) ((INVALID_FILE_ATTRIBUTES != (x)) && ((x) & (y)))
29 #define IsAttribFile(x) (!((x) & FILE_ATTRIBUTE_DIRECTORY))
30 #define IsAttribDir(x) IsAttrib(x, FILE_ATTRIBUTE_DIRECTORY)
31 #define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
35 static const WCHAR wWildcardFile
[] = {'*',0};
36 static const WCHAR wWildcardChars
[] = {'*','?',0};
44 IProgressDialog
*progress
;
45 ULARGE_INTEGER completedSize
;
46 ULARGE_INTEGER totalSize
;
47 WCHAR szBuilderString
[50];
50 #define ERROR_SHELL_INTERNAL_FILE_NOT_FOUND 1026
68 BOOL bAnyFromWildcard
;
73 static DWORD
SHNotifyCreateDirectoryW(LPCWSTR path
, LPSECURITY_ATTRIBUTES sec
);
74 static DWORD
SHNotifyRemoveDirectoryW(LPCWSTR path
);
75 static DWORD
SHNotifyDeleteFileW(FILE_OPERATION
*op
, LPCWSTR path
);
76 static DWORD
SHNotifyMoveFileW(FILE_OPERATION
*op
, LPCWSTR src
, LPCWSTR dest
, BOOL isdir
);
77 static DWORD
SHNotifyCopyFileW(FILE_OPERATION
*op
, LPCWSTR src
, LPCWSTR dest
, BOOL bFailIfExists
);
78 static DWORD
SHFindAttrW(LPCWSTR pName
, BOOL fileOnly
);
79 static HRESULT
copy_files(FILE_OPERATION
*op
, BOOL multiDest
, const FILE_LIST
*flFrom
, FILE_LIST
*flTo
);
80 static DWORD
move_files(FILE_OPERATION
*op
, BOOL multiDest
, const FILE_LIST
*flFrom
, const FILE_LIST
*flTo
);
82 DWORD WINAPI
_FileOpCountManager(FILE_OPERATION
*op
, const FILE_LIST
*flFrom
);
83 static BOOL
_FileOpCount(FILE_OPERATION
*op
, LPWSTR pwszBuf
, BOOL bFolder
, DWORD
*ticks
);
85 /* Confirm dialogs with an optional "Yes To All" as used in file operations confirmations
87 static const WCHAR CONFIRM_MSG_PROP
[] = {'W','I','N','E','_','C','O','N','F','I','R','M',0};
89 struct confirm_msg_info
97 /* as some buttons may be hidden and the dialog height may change we may need
98 * to move the controls */
99 static void confirm_msg_move_button(HWND hDlg
, INT iId
, INT
*xPos
, INT yOffset
, BOOL bShow
)
101 HWND hButton
= GetDlgItem(hDlg
, iId
);
109 GetWindowRect(hButton
, &r
);
110 width
= r
.right
- r
.left
;
113 ScreenToClient(hDlg
, &pt
);
114 MoveWindow(hButton
, *xPos
- width
, pt
.y
- yOffset
, width
, r
.bottom
- r
.top
, FALSE
);
118 ShowWindow(hButton
, SW_HIDE
);
121 /* Note: we paint the text manually and don't use the static control to make
122 * sure the text has the same height as the one computed in WM_INITDIALOG
124 static INT_PTR
ConfirmMsgBox_Paint(HWND hDlg
)
131 BeginPaint(hDlg
, &ps
);
134 GetClientRect(GetDlgItem(hDlg
, IDC_YESTOALL_MESSAGE
), &r
);
135 /* this will remap the rect to dialog coords */
136 MapWindowPoints(GetDlgItem(hDlg
, IDC_YESTOALL_MESSAGE
), hDlg
, (LPPOINT
)&r
, 2);
137 hOldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)SendDlgItemMessageW(hDlg
, IDC_YESTOALL_MESSAGE
, WM_GETFONT
, 0, 0));
138 DrawTextW(hdc
, (LPWSTR
)GetPropW(hDlg
, CONFIRM_MSG_PROP
), -1, &r
, DT_NOPREFIX
| DT_PATH_ELLIPSIS
| DT_WORDBREAK
);
139 SelectObject(hdc
, hOldFont
);
145 static INT_PTR
ConfirmMsgBox_Init(HWND hDlg
, LPARAM lParam
)
147 struct confirm_msg_info
*info
= (struct confirm_msg_info
*)lParam
;
154 SetWindowTextW(hDlg
, info
->lpszCaption
);
155 ShowWindow(GetDlgItem(hDlg
, IDC_YESTOALL_MESSAGE
), SW_HIDE
);
156 SetPropW(hDlg
, CONFIRM_MSG_PROP
, info
->lpszText
);
157 SendDlgItemMessageW(hDlg
, IDC_YESTOALL_ICON
, STM_SETICON
, (WPARAM
)info
->hIcon
, 0);
159 /* compute the text height and resize the dialog */
160 GetClientRect(GetDlgItem(hDlg
, IDC_YESTOALL_MESSAGE
), &r
);
163 hOldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)SendDlgItemMessageW(hDlg
, IDC_YESTOALL_MESSAGE
, WM_GETFONT
, 0, 0));
164 DrawTextW(hdc
, info
->lpszText
, -1, &r
, DT_NOPREFIX
| DT_PATH_ELLIPSIS
| DT_WORDBREAK
| DT_CALCRECT
);
165 SelectObject(hdc
, hOldFont
);
167 yOffset
= min(yOffset
, 35); /* don't make the dialog too small */
168 ReleaseDC(hDlg
, hdc
);
170 GetClientRect(hDlg
, &r
);
172 GetWindowRect(hDlg
, &r
);
173 width
= r
.right
- r
.left
;
174 height
= r
.bottom
- r
.top
- yOffset
;
175 MoveWindow(hDlg
, (GetSystemMetrics(SM_CXSCREEN
) - width
)/2,
176 (GetSystemMetrics(SM_CYSCREEN
) - height
)/2, width
, height
, FALSE
);
178 confirm_msg_move_button(hDlg
, IDCANCEL
, &xPos
, yOffset
, info
->bYesToAll
);
179 confirm_msg_move_button(hDlg
, IDNO
, &xPos
, yOffset
, TRUE
);
180 confirm_msg_move_button(hDlg
, IDC_YESTOALL
, &xPos
, yOffset
, info
->bYesToAll
);
181 confirm_msg_move_button(hDlg
, IDYES
, &xPos
, yOffset
, TRUE
);
186 static INT_PTR CALLBACK
ConfirmMsgBoxProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
191 return ConfirmMsgBox_Init(hDlg
, lParam
);
193 return ConfirmMsgBox_Paint(hDlg
);
195 EndDialog(hDlg
, wParam
);
198 EndDialog(hDlg
, IDCANCEL
);
204 int SHELL_ConfirmMsgBox(HWND hWnd
, LPWSTR lpszText
, LPWSTR lpszCaption
, HICON hIcon
, BOOL bYesToAll
)
206 struct confirm_msg_info info
;
208 info
.lpszText
= lpszText
;
209 info
.lpszCaption
= lpszCaption
;
211 info
.bYesToAll
= bYesToAll
;
212 return DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_YESTOALL_MSGBOX
), hWnd
, ConfirmMsgBoxProc
, (LPARAM
)&info
);
215 /* confirmation dialogs content */
218 HINSTANCE hIconInstance
;
219 UINT icon_resource_id
;
220 UINT caption_resource_id
, text_resource_id
;
221 } SHELL_ConfirmIDstruc
;
223 static BOOL
SHELL_ConfirmIDs(int nKindOfDialog
, SHELL_ConfirmIDstruc
*ids
)
225 ids
->hIconInstance
= shell32_hInstance
;
226 switch (nKindOfDialog
)
228 case ASK_DELETE_FILE
:
229 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
230 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
231 ids
->text_resource_id
= IDS_DELETEITEM_TEXT
;
234 case ASK_DELETE_FOLDER
:
235 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
236 ids
->caption_resource_id
= IDS_DELETEFOLDER_CAPTION
;
237 ids
->text_resource_id
= IDS_DELETEITEM_TEXT
;
240 case ASK_DELETE_MULTIPLE_ITEM
:
241 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
242 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
243 ids
->text_resource_id
= IDS_DELETEMULTIPLE_TEXT
;
247 ids
->icon_resource_id
= IDI_SHELL_TRASH_FILE
;
248 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
249 ids
->text_resource_id
= IDS_TRASHITEM_TEXT
;
252 case ASK_TRASH_FOLDER
:
253 ids
->icon_resource_id
= IDI_SHELL_TRASH_FILE
;
254 ids
->caption_resource_id
= IDS_DELETEFOLDER_CAPTION
;
255 ids
->text_resource_id
= IDS_TRASHFOLDER_TEXT
;
258 case ASK_TRASH_MULTIPLE_ITEM
:
259 ids
->icon_resource_id
= IDI_SHELL_TRASH_FILE
;
260 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
261 ids
->text_resource_id
= IDS_TRASHMULTIPLE_TEXT
;
264 case ASK_CANT_TRASH_ITEM
:
265 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
266 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
267 ids
->text_resource_id
= IDS_CANTTRASH_TEXT
;
270 case ASK_DELETE_SELECTED
:
271 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
272 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
273 ids
->text_resource_id
= IDS_DELETESELECTED_TEXT
;
276 case ASK_OVERWRITE_FILE
:
277 ids
->hIconInstance
= NULL
;
278 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
279 ids
->caption_resource_id
= IDS_OVERWRITEFILE_CAPTION
;
280 ids
->text_resource_id
= IDS_OVERWRITEFILE_TEXT
;
283 case ASK_OVERWRITE_FOLDER
:
284 ids
->hIconInstance
= NULL
;
285 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
286 ids
->caption_resource_id
= IDS_OVERWRITEFILE_CAPTION
;
287 ids
->text_resource_id
= IDS_OVERWRITEFOLDER_TEXT
;
291 FIXME(" Unhandled nKindOfDialog %d stub\n", nKindOfDialog
);
296 static BOOL
SHELL_ConfirmDialogW(HWND hWnd
, int nKindOfDialog
, LPCWSTR szDir
, FILE_OPERATION
*op
)
298 WCHAR szCaption
[255], szText
[255], szBuffer
[MAX_PATH
+ 256];
299 SHELL_ConfirmIDstruc ids
;
304 assert(nKindOfDialog
>= 0 && nKindOfDialog
< 32);
305 if (op
&& (op
->dwYesToAllMask
& (1 << nKindOfDialog
)))
308 if (!SHELL_ConfirmIDs(nKindOfDialog
, &ids
)) return FALSE
;
310 LoadStringW(shell32_hInstance
, ids
.caption_resource_id
, szCaption
, sizeof(szCaption
)/sizeof(WCHAR
));
311 LoadStringW(shell32_hInstance
, ids
.text_resource_id
, szText
, sizeof(szText
)/sizeof(WCHAR
));
313 args
[0] = (DWORD_PTR
)szDir
;
314 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
315 szText
, 0, 0, szBuffer
, sizeof(szBuffer
), (va_list*)args
);
316 hIcon
= LoadIconW(ids
.hIconInstance
, (LPWSTR
)MAKEINTRESOURCE(ids
.icon_resource_id
));
318 ret
= SHELL_ConfirmMsgBox(hWnd
, szBuffer
, szCaption
, hIcon
, op
&& op
->bManyItems
);
321 if (ret
== IDC_YESTOALL
)
323 op
->dwYesToAllMask
|= (1 << nKindOfDialog
);
327 op
->bCancelled
= TRUE
;
329 op
->req
->fAnyOperationsAborted
= TRUE
;
334 BOOL
SHELL_ConfirmYesNoW(HWND hWnd
, int nKindOfDialog
, LPCWSTR szDir
)
336 return SHELL_ConfirmDialogW(hWnd
, nKindOfDialog
, szDir
, NULL
);
339 static DWORD
SHELL32_AnsiToUnicodeBuf(LPCSTR aPath
, LPWSTR
*wPath
, DWORD minChars
)
341 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, aPath
, -1, NULL
, 0);
346 *wPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
349 MultiByteToWideChar(CP_ACP
, 0, aPath
, -1, *wPath
, len
);
352 return E_OUTOFMEMORY
;
355 static void SHELL32_FreeUnicodeBuf(LPWSTR wPath
)
357 HeapFree(GetProcessHeap(), 0, wPath
);
360 EXTERN_C HRESULT WINAPI
SHIsFileAvailableOffline(LPCWSTR path
, LPDWORD status
)
362 FIXME("(%s, %p) stub\n", debugstr_w(path
), status
);
366 /**************************************************************************
367 * SHELL_DeleteDirectory() [internal]
369 * Asks for confirmation when bShowUI is true and deletes the directory and
370 * all its subdirectories and files if necessary.
372 BOOL
SHELL_DeleteDirectoryW(FILE_OPERATION
*op
, LPCWSTR pszDir
, BOOL bShowUI
)
376 WIN32_FIND_DATAW wfd
;
377 WCHAR szTemp
[MAX_PATH
];
379 /* Make sure the directory exists before eventually prompting the user */
380 PathCombineW(szTemp
, pszDir
, wWildcardFile
);
381 hFind
= FindFirstFileW(szTemp
, &wfd
);
382 if (hFind
== INVALID_HANDLE_VALUE
)
385 if (!bShowUI
|| (ret
= SHELL_ConfirmDialogW(op
->req
->hwnd
, ASK_DELETE_FOLDER
, pszDir
, NULL
)))
389 if (IsDotDir(wfd
.cFileName
))
391 PathCombineW(szTemp
, pszDir
, wfd
.cFileName
);
392 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
393 ret
= SHELL_DeleteDirectoryW(op
, szTemp
, FALSE
);
395 ret
= (SHNotifyDeleteFileW(op
, szTemp
) == ERROR_SUCCESS
);
397 if (op
->progress
!= NULL
)
398 op
->bCancelled
|= op
->progress
->HasUserCancelled();
399 } while (ret
&& FindNextFileW(hFind
, &wfd
) && !op
->bCancelled
);
403 ret
= (SHNotifyRemoveDirectoryW(pszDir
) == ERROR_SUCCESS
);
407 /**************************************************************************
408 * Win32CreateDirectory [SHELL32.93]
410 * Creates a directory. Also triggers a change notify if one exists.
413 * path [I] path to directory to create
416 * TRUE if successful, FALSE otherwise
419 static DWORD
SHNotifyCreateDirectoryW(LPCWSTR path
, LPSECURITY_ATTRIBUTES sec
)
421 TRACE("(%s, %p)\n", debugstr_w(path
), sec
);
423 if (CreateDirectoryW(path
, sec
))
425 SHChangeNotify(SHCNE_MKDIR
, SHCNF_PATHW
, path
, NULL
);
426 return ERROR_SUCCESS
;
428 return GetLastError();
431 /**********************************************************************/
433 EXTERN_C BOOL WINAPI
Win32CreateDirectoryW(LPCWSTR path
, LPSECURITY_ATTRIBUTES sec
)
435 return (SHNotifyCreateDirectoryW(path
, sec
) == ERROR_SUCCESS
);
438 /************************************************************************
439 * Win32RemoveDirectory [SHELL32.94]
441 * Deletes a directory. Also triggers a change notify if one exists.
444 * path [I] path to directory to delete
447 * TRUE if successful, FALSE otherwise
449 static DWORD
SHNotifyRemoveDirectoryW(LPCWSTR path
)
452 TRACE("(%s)\n", debugstr_w(path
));
454 ret
= RemoveDirectoryW(path
);
457 /* Directory may be write protected */
458 DWORD dwAttr
= GetFileAttributesW(path
);
459 if (IsAttrib(dwAttr
, FILE_ATTRIBUTE_READONLY
))
460 if (SetFileAttributesW(path
, dwAttr
& ~FILE_ATTRIBUTE_READONLY
))
461 ret
= RemoveDirectoryW(path
);
465 SHChangeNotify(SHCNE_RMDIR
, SHCNF_PATHW
, path
, NULL
);
466 return ERROR_SUCCESS
;
468 return GetLastError();
471 /***********************************************************************/
473 EXTERN_C BOOL WINAPI
Win32RemoveDirectoryW(LPCWSTR path
)
475 return (SHNotifyRemoveDirectoryW(path
) == ERROR_SUCCESS
);
478 static void _SetOperationTitle(FILE_OPERATION
*op
) {
479 if (op
->progress
== NULL
)
481 WCHAR szTitle
[50], szPreflight
[50];
483 switch (op
->req
->wFunc
)
486 LoadStringW(shell32_hInstance
, IDS_FILEOOP_COPYING
, szTitle
, sizeof(szTitle
)/sizeof(WCHAR
));
487 LoadStringW(shell32_hInstance
, IDS_FILEOOP_FROM_TO
, op
->szBuilderString
, sizeof( op
->szBuilderString
)/sizeof(WCHAR
));
490 LoadStringW(shell32_hInstance
, IDS_FILEOOP_DELETING
, szTitle
, sizeof(szTitle
)/sizeof(WCHAR
));
491 LoadStringW(shell32_hInstance
, IDS_FILEOOP_FROM
, op
->szBuilderString
, sizeof( op
->szBuilderString
)/sizeof(WCHAR
));
494 LoadStringW(shell32_hInstance
, IDS_FILEOOP_MOVING
, szTitle
, sizeof(szTitle
)/sizeof(WCHAR
));
495 LoadStringW(shell32_hInstance
, IDS_FILEOOP_FROM_TO
, op
->szBuilderString
, sizeof( op
->szBuilderString
)/sizeof(WCHAR
));
500 LoadStringW(shell32_hInstance
, IDS_FILEOOP_PREFLIGHT
, szPreflight
, sizeof(szPreflight
)/sizeof(WCHAR
));
502 op
->progress
->SetTitle(szTitle
);
503 op
->progress
->SetLine(1, szPreflight
, false, NULL
);
506 static void _SetOperationTexts(FILE_OPERATION
*op
, LPCWSTR src
, LPCWSTR dest
) {
507 if (op
->progress
== NULL
|| src
== NULL
)
509 LPWSTR fileSpecS
, pathSpecS
, fileSpecD
, pathSpecD
;
510 WCHAR szFolderS
[50], szFolderD
[50], szFinalString
[260];
514 fileSpecS
= (pathSpecS
= (LPWSTR
) src
);
515 fileSpecD
= (pathSpecD
= (LPWSTR
) dest
);
517 // March across the string to get the file path and it's parent dir.
518 for (LPWSTR ptr
= (LPWSTR
) src
; *ptr
; ptr
++) {
520 pathSpecS
= fileSpecS
;
524 lstrcpynW(szFolderS
, pathSpecS
, min(50, fileSpecS
- pathSpecS
));
525 args
[0] = (DWORD_PTR
) szFolderS
;
527 switch (op
->req
->wFunc
)
533 for (LPWSTR ptr
= (LPWSTR
) dest
; *ptr
; ptr
++) {
535 pathSpecD
= fileSpecD
;
539 lstrcpynW(szFolderD
, pathSpecD
, min(50, fileSpecD
- pathSpecD
));
540 args
[1] = (DWORD_PTR
) szFolderD
;
548 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
549 op
->szBuilderString
, 0, 0, szFinalString
, sizeof(szFinalString
), (va_list*)args
);
551 op
->progress
->SetLine(1, fileSpecS
, false, NULL
);
552 op
->progress
->SetLine(2, szFinalString
, false, NULL
);
556 DWORD CALLBACK
SHCopyProgressRoutine(
557 LARGE_INTEGER TotalFileSize
,
558 LARGE_INTEGER TotalBytesTransferred
,
559 LARGE_INTEGER StreamSize
,
560 LARGE_INTEGER StreamBytesTransferred
,
561 DWORD dwStreamNumber
,
562 DWORD dwCallbackReason
,
564 HANDLE hDestinationFile
,
567 FILE_OPERATION
*op
= (FILE_OPERATION
*) lpData
;
571 * This is called at the start of each file. To keop less state,
572 * I'm adding the file to the completed size here, and the re-subtracting
573 * it when drawing the progress bar.
575 if (dwCallbackReason
& CALLBACK_STREAM_SWITCH
)
576 op
->completedSize
.QuadPart
+= TotalFileSize
.QuadPart
;
578 op
->progress
->SetProgress64(op
->completedSize
.QuadPart
-
579 TotalFileSize
.QuadPart
+
580 TotalBytesTransferred
.QuadPart
581 , op
->totalSize
.QuadPart
);
584 op
->bCancelled
= op
->progress
->HasUserCancelled();
591 /************************************************************************
592 * SHNotifyDeleteFileW [internal]
594 * Deletes a file. Also triggers a change notify if one exists.
597 * op [I] File Operation context
598 * path [I] path to source file to move
601 * ERORR_SUCCESS if successful
603 static DWORD
SHNotifyDeleteFileW(FILE_OPERATION
*op
, LPCWSTR path
)
607 TRACE("(%s)\n", debugstr_w(path
));
609 _SetOperationTexts(op
, path
, NULL
);
611 LARGE_INTEGER FileSize
;
612 FileSize
.QuadPart
= 0;
614 WIN32_FIND_DATAW wfd
;
615 HANDLE hFile
= FindFirstFileW(path
, &wfd
);
616 if (hFile
!= INVALID_HANDLE_VALUE
&& IsAttribFile(wfd
.dwFileAttributes
)) {
618 tmp
.u
.LowPart
= wfd
.nFileSizeLow
;
619 tmp
.u
.HighPart
= wfd
.nFileSizeHigh
;
620 FileSize
.QuadPart
= tmp
.QuadPart
;
624 ret
= DeleteFileW(path
);
627 /* File may be write protected or a system file */
628 DWORD dwAttr
= GetFileAttributesW(path
);
629 if (IsAttrib(dwAttr
, FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_SYSTEM
))
630 if (SetFileAttributesW(path
, dwAttr
& ~(FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_SYSTEM
)))
631 ret
= DeleteFileW(path
);
635 // Bit of a hack to make the progress bar move. We don't have progress inside the file, so inform when done.
636 SHCopyProgressRoutine(FileSize
, FileSize
, FileSize
, FileSize
, 0, CALLBACK_STREAM_SWITCH
, NULL
, NULL
, op
);
637 SHChangeNotify(SHCNE_DELETE
, SHCNF_PATHW
, path
, NULL
);
638 return ERROR_SUCCESS
;
640 return GetLastError();
643 /************************************************************************
644 * Win32DeleteFile [SHELL32.164]
646 * Deletes a file. Also triggers a change notify if one exists.
649 * path [I] path to file to delete
652 * TRUE if successful, FALSE otherwise
654 EXTERN_C DWORD WINAPI
Win32DeleteFileW(LPCWSTR path
)
656 return (SHNotifyDeleteFileW(NULL
, path
) == ERROR_SUCCESS
);
659 /************************************************************************
660 * SHNotifyMoveFile [internal]
662 * Moves a file. Also triggers a change notify if one exists.
665 * op [I] File Operation context
666 * src [I] path to source file to move
667 * dest [I] path to target file to move to
670 * ERORR_SUCCESS if successful
672 static DWORD
SHNotifyMoveFileW(FILE_OPERATION
*op
, LPCWSTR src
, LPCWSTR dest
, BOOL isdir
)
676 TRACE("(%s %s)\n", debugstr_w(src
), debugstr_w(dest
));
678 _SetOperationTexts(op
, src
, dest
);
680 ret
= MoveFileWithProgressW(src
, dest
, SHCopyProgressRoutine
, op
, MOVEFILE_REPLACE_EXISTING
);
682 /* MOVEFILE_REPLACE_EXISTING fails with dirs, so try MoveFile */
684 ret
= MoveFileW(src
, dest
);
690 dwAttr
= SHFindAttrW(dest
, FALSE
);
691 if (INVALID_FILE_ATTRIBUTES
== dwAttr
)
693 /* Source file may be write protected or a system file */
694 dwAttr
= GetFileAttributesW(src
);
695 if (IsAttrib(dwAttr
, FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_SYSTEM
))
696 if (SetFileAttributesW(src
, dwAttr
& ~(FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_SYSTEM
)))
697 ret
= MoveFileW(src
, dest
);
702 SHChangeNotify(isdir
? SHCNE_MKDIR
: SHCNE_CREATE
, SHCNF_PATHW
, dest
, NULL
);
703 SHChangeNotify(isdir
? SHCNE_RMDIR
: SHCNE_DELETE
, SHCNF_PATHW
, src
, NULL
);
704 return ERROR_SUCCESS
;
706 return GetLastError();
709 /************************************************************************
710 * SHNotifyCopyFile [internal]
712 * Copies a file. Also triggers a change notify if one exists.
715 * src [I] path to source file to move
716 * dest [I] path to target file to move to
717 * bFailIfExists [I] if TRUE, the target file will not be overwritten if
718 * a file with this name already exists
721 * ERROR_SUCCESS if successful
723 static DWORD
SHNotifyCopyFileW(FILE_OPERATION
*op
, LPCWSTR src
, LPCWSTR dest
, BOOL bFailIfExists
)
728 TRACE("(%s %s %s)\n", debugstr_w(src
), debugstr_w(dest
), bFailIfExists
? "failIfExists" : "");
730 _SetOperationTexts(op
, src
, dest
);
732 /* Destination file may already exist with read only attribute */
733 attribs
= GetFileAttributesW(dest
);
734 if (IsAttrib(attribs
, FILE_ATTRIBUTE_READONLY
))
735 SetFileAttributesW(dest
, attribs
& ~FILE_ATTRIBUTE_READONLY
);
737 if (GetFileAttributesW(dest
) & FILE_ATTRIBUTE_READONLY
)
739 SetFileAttributesW(dest
, attribs
& ~FILE_ATTRIBUTE_READONLY
);
740 if (GetFileAttributesW(dest
) & FILE_ATTRIBUTE_READONLY
)
742 TRACE("[shell32, SHNotifyCopyFileW] STILL SHIT\n");
746 ret
= CopyFileExW(src
, dest
, SHCopyProgressRoutine
, op
, &op
->bCancelled
, bFailIfExists
);
749 SHChangeNotify(SHCNE_CREATE
, SHCNF_PATHW
, dest
, NULL
);
750 return ERROR_SUCCESS
;
753 return GetLastError();
756 /*************************************************************************
757 * SHCreateDirectory [SHELL32.165]
759 * This function creates a file system folder whose fully qualified path is
760 * given by path. If one or more of the intermediate folders do not exist,
761 * they will be created as well.
765 * path [I] path of directory to create
768 * ERROR_SUCCESS or one of the following values:
769 * ERROR_BAD_PATHNAME if the path is relative
770 * ERROR_FILE_EXISTS when a file with that name exists
771 * ERROR_PATH_NOT_FOUND can't find the path, probably invalid
772 * ERROR_INVALID_NAME if the path contains invalid chars
773 * ERROR_ALREADY_EXISTS when the directory already exists
774 * ERROR_FILENAME_EXCED_RANGE if the filename was to long to process
777 * exported by ordinal
779 * WinNT/2000 exports Unicode
781 int WINAPI
SHCreateDirectory(HWND hWnd
, LPCWSTR path
)
783 return SHCreateDirectoryExW(hWnd
, path
, NULL
);
786 /*************************************************************************
787 * SHCreateDirectoryExA [SHELL32.@]
789 * This function creates a file system folder whose fully qualified path is
790 * given by path. If one or more of the intermediate folders do not exist,
791 * they will be created as well.
795 * path [I] path of directory to create
796 * sec [I] security attributes to use or NULL
799 * ERROR_SUCCESS or one of the following values:
800 * ERROR_BAD_PATHNAME or ERROR_PATH_NOT_FOUND if the path is relative
801 * ERROR_INVALID_NAME if the path contains invalid chars
802 * ERROR_FILE_EXISTS when a file with that name exists
803 * ERROR_ALREADY_EXISTS when the directory already exists
804 * ERROR_FILENAME_EXCED_RANGE if the filename was to long to process
806 * FIXME: Not implemented yet;
807 * SHCreateDirectoryEx also verifies that the files in the directory will be visible
808 * if the path is a network path to deal with network drivers which might have a limited
809 * but unknown maximum path length. If not:
811 * If hWnd is set to a valid window handle, a message box is displayed warning
812 * the user that the files may not be accessible. If the user chooses not to
813 * proceed, the function returns ERROR_CANCELLED.
815 * If hWnd is set to NULL, no user interface is displayed and the function
816 * returns ERROR_CANCELLED.
818 int WINAPI
SHCreateDirectoryExA(HWND hWnd
, LPCSTR path
, LPSECURITY_ATTRIBUTES sec
)
823 TRACE("(%s, %p)\n", debugstr_a(path
), sec
);
825 retCode
= SHELL32_AnsiToUnicodeBuf(path
, &wPath
, 0);
828 retCode
= SHCreateDirectoryExW(hWnd
, wPath
, sec
);
829 SHELL32_FreeUnicodeBuf(wPath
);
834 /*************************************************************************
835 * SHCreateDirectoryExW [SHELL32.@]
837 * See SHCreateDirectoryExA.
839 int WINAPI
SHCreateDirectoryExW(HWND hWnd
, LPCWSTR path
, LPSECURITY_ATTRIBUTES sec
)
841 int ret
= ERROR_BAD_PATHNAME
;
842 TRACE("(%p, %s, %p)\n", hWnd
, debugstr_w(path
), sec
);
844 if (PathIsRelativeW(path
))
850 ret
= SHNotifyCreateDirectoryW(path
, sec
);
851 /* Refuse to work on certain error codes before trying to create directories recursively */
852 if (ret
!= ERROR_SUCCESS
&&
853 ret
!= ERROR_FILE_EXISTS
&&
854 ret
!= ERROR_ALREADY_EXISTS
&&
855 ret
!= ERROR_FILENAME_EXCED_RANGE
)
857 WCHAR
*pEnd
, *pSlash
, szTemp
[MAX_PATH
+ 1]; /* extra for PathAddBackslash() */
859 lstrcpynW(szTemp
, path
, MAX_PATH
);
860 pEnd
= PathAddBackslashW(szTemp
);
865 while (*pSlash
&& *pSlash
!= '\\') pSlash
++;
868 *pSlash
= 0; /* terminate path at separator */
870 ret
= SHNotifyCreateDirectoryW(szTemp
, pSlash
+ 1 == pEnd
? sec
: NULL
);
872 *pSlash
++ = '\\'; /* put the separator back */
876 if (ret
&& hWnd
&& (ERROR_CANCELLED
!= ret
))
878 /* We failed and should show a dialog box */
879 FIXME("Show system error message, creating path %s, failed with error %d\n", debugstr_w(path
), ret
);
880 ret
= ERROR_CANCELLED
; /* Error has been already presented to user (not really yet!) */
887 /*************************************************************************
888 * SHFindAttrW [internal]
890 * Get the Attributes for a file or directory. The difference to GetAttributes()
891 * is that this function will also work for paths containing wildcard characters
895 * path [I] path of directory or file to check
896 * fileOnly [I] TRUE if only files should be found
899 * INVALID_FILE_ATTRIBUTES if the path does not exist, the actual attributes of
900 * the first file or directory found otherwise
902 static DWORD
SHFindAttrW(LPCWSTR pName
, BOOL fileOnly
)
904 WIN32_FIND_DATAW wfd
;
905 BOOL b_FileMask
= fileOnly
&& (NULL
!= StrPBrkW(pName
, wWildcardChars
));
906 DWORD dwAttr
= INVALID_FILE_ATTRIBUTES
;
907 HANDLE hFind
= FindFirstFileW(pName
, &wfd
);
909 TRACE("%s %d\n", debugstr_w(pName
), fileOnly
);
910 if (INVALID_HANDLE_VALUE
!= hFind
)
914 if (b_FileMask
&& IsAttribDir(wfd
.dwFileAttributes
))
916 dwAttr
= wfd
.dwFileAttributes
;
918 } while (FindNextFileW(hFind
, &wfd
));
925 /*************************************************************************
927 * _ConvertAtoW helper function for SHFileOperationA
929 * Converts a string or string-list to unicode.
931 static DWORD
_ConvertAtoW(PCSTR strSrc
, PCWSTR
* pStrDest
, BOOL isList
)
935 // If the input is null, nothing to convert.
939 // Measure the total size, depending on if it's a zero-terminated list.
943 PCSTR tmpSrc
= strSrc
;
947 size
= lstrlenA(tmpSrc
) + 1;
954 sizeA
= lstrlenA(strSrc
) + 1;
957 // Measure the needed allocation size.
958 int sizeW
= MultiByteToWideChar(CP_ACP
, 0, strSrc
, sizeA
, NULL
, 0);
960 return GetLastError();
962 PWSTR strDest
= (PWSTR
) HeapAlloc(GetProcessHeap(), 0, sizeW
* sizeof(WCHAR
));
964 return ERROR_OUTOFMEMORY
;
966 int err
= MultiByteToWideChar(CP_ACP
, 0, strSrc
, sizeA
, strDest
, sizeW
);
969 HeapFree(GetProcessHeap(), 0, strDest
);
970 return GetLastError();
977 /*************************************************************************
978 * SHFileOperationA [SHELL32.@]
980 * Function to copy, move, delete and create one or more files with optional
984 * lpFileOp [I/O] pointer to a structure containing all the necessary information
987 * Success: ERROR_SUCCESS.
988 * Failure: ERROR_CANCELLED.
993 int WINAPI
SHFileOperationA(LPSHFILEOPSTRUCTA lpFileOp
)
995 int errCode
, retCode
;
996 SHFILEOPSTRUCTW nFileOp
= { 0 };
998 // Convert A information to W
999 nFileOp
.hwnd
= lpFileOp
->hwnd
;
1000 nFileOp
.wFunc
= lpFileOp
->wFunc
;
1001 nFileOp
.fFlags
= lpFileOp
->fFlags
;
1003 errCode
= _ConvertAtoW(lpFileOp
->pFrom
, &nFileOp
.pFrom
, TRUE
);
1007 if (FO_DELETE
!= (nFileOp
.wFunc
& FO_MASK
))
1009 errCode
= _ConvertAtoW(lpFileOp
->pTo
, &nFileOp
.pTo
, TRUE
);
1014 if (nFileOp
.fFlags
& FOF_SIMPLEPROGRESS
)
1016 errCode
= _ConvertAtoW(lpFileOp
->lpszProgressTitle
, &nFileOp
.lpszProgressTitle
, FALSE
);
1021 // Call the actual function
1022 retCode
= SHFileOperationW(&nFileOp
);
1027 HeapFree(GetProcessHeap(), 0, (PVOID
) nFileOp
.pFrom
);
1029 HeapFree(GetProcessHeap(), 0, (PVOID
) nFileOp
.pTo
);
1030 if (nFileOp
.lpszProgressTitle
)
1031 HeapFree(GetProcessHeap(), 0, (PVOID
) nFileOp
.lpszProgressTitle
);
1035 lpFileOp
->fAnyOperationsAborted
= TRUE
;
1036 SetLastError(errCode
);
1041 // Thankfully, starting with NT4 the name mappings are always unicode, so no need to convert.
1042 lpFileOp
->hNameMappings
= nFileOp
.hNameMappings
;
1043 lpFileOp
->fAnyOperationsAborted
= nFileOp
.fAnyOperationsAborted
;
1047 static void __inline
grow_list(FILE_LIST
*list
)
1049 FILE_ENTRY
*newx
= (FILE_ENTRY
*)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, list
->feFiles
,
1050 list
->num_alloc
* 2 * sizeof(*newx
) );
1051 list
->feFiles
= newx
;
1052 list
->num_alloc
*= 2;
1055 /* adds a file to the FILE_ENTRY struct
1057 static void add_file_to_entry(FILE_ENTRY
*feFile
, LPCWSTR szFile
)
1059 DWORD dwLen
= lstrlenW(szFile
) + 1;
1062 feFile
->szFullPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwLen
* sizeof(WCHAR
));
1063 lstrcpyW(feFile
->szFullPath
, szFile
);
1065 ptr
= StrRChrW(szFile
, NULL
, '\\');
1068 dwLen
= ptr
- szFile
+ 1;
1069 feFile
->szDirectory
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwLen
* sizeof(WCHAR
));
1070 lstrcpynW(feFile
->szDirectory
, szFile
, dwLen
);
1072 dwLen
= lstrlenW(feFile
->szFullPath
) - dwLen
+ 1;
1073 feFile
->szFilename
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwLen
* sizeof(WCHAR
));
1074 lstrcpyW(feFile
->szFilename
, ptr
+ 1); /* skip over backslash */
1076 feFile
->bFromWildcard
= FALSE
;
1079 static LPWSTR
wildcard_to_file(LPCWSTR szWildCard
, LPCWSTR szFileName
)
1083 DWORD dwDirLen
, dwFullLen
;
1085 ptr
= StrRChrW(szWildCard
, NULL
, '\\');
1086 dwDirLen
= ptr
- szWildCard
+ 1;
1088 dwFullLen
= dwDirLen
+ lstrlenW(szFileName
) + 1;
1089 szFullPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwFullLen
* sizeof(WCHAR
));
1091 lstrcpynW(szFullPath
, szWildCard
, dwDirLen
+ 1);
1092 lstrcatW(szFullPath
, szFileName
);
1097 static void parse_wildcard_files(FILE_LIST
*flList
, LPCWSTR szFile
, LPDWORD pdwListIndex
)
1099 WIN32_FIND_DATAW wfd
;
1100 HANDLE hFile
= FindFirstFileW(szFile
, &wfd
);
1105 if (hFile
== INVALID_HANDLE_VALUE
) return;
1107 for (res
= TRUE
; res
; res
= FindNextFileW(hFile
, &wfd
))
1109 if (IsDotDir(wfd
.cFileName
))
1112 if (*pdwListIndex
>= flList
->num_alloc
)
1113 grow_list( flList
);
1115 szFullPath
= wildcard_to_file(szFile
, wfd
.cFileName
);
1116 file
= &flList
->feFiles
[(*pdwListIndex
)++];
1117 add_file_to_entry(file
, szFullPath
);
1118 file
->bFromWildcard
= TRUE
;
1119 file
->attributes
= wfd
.dwFileAttributes
;
1121 if (IsAttribDir(file
->attributes
))
1122 flList
->bAnyDirectories
= TRUE
;
1124 HeapFree(GetProcessHeap(), 0, szFullPath
);
1130 /* takes the null-separated file list and fills out the FILE_LIST */
1131 static HRESULT
parse_file_list(FILE_LIST
*flList
, LPCWSTR szFiles
)
1133 LPCWSTR ptr
= szFiles
;
1134 WCHAR szCurFile
[MAX_PATH
];
1138 return ERROR_INVALID_PARAMETER
;
1140 flList
->bAnyFromWildcard
= FALSE
;
1141 flList
->bAnyDirectories
= FALSE
;
1142 flList
->bAnyDontExist
= FALSE
;
1143 flList
->num_alloc
= 32;
1144 flList
->dwNumFiles
= 0;
1148 return ERROR_ACCESS_DENIED
;
1150 flList
->feFiles
= (FILE_ENTRY
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1151 flList
->num_alloc
* sizeof(FILE_ENTRY
));
1155 if (i
>= flList
->num_alloc
) grow_list( flList
);
1157 /* change relative to absolute path */
1158 if (PathIsRelativeW(ptr
))
1160 GetCurrentDirectoryW(MAX_PATH
, szCurFile
);
1161 PathCombineW(szCurFile
, szCurFile
, ptr
);
1162 flList
->feFiles
[i
].bFromRelative
= TRUE
;
1166 lstrcpyW(szCurFile
, ptr
);
1167 flList
->feFiles
[i
].bFromRelative
= FALSE
;
1170 /* parse wildcard files if they are in the filename */
1171 if (StrPBrkW(szCurFile
, wWildcardChars
))
1173 parse_wildcard_files(flList
, szCurFile
, &i
);
1174 flList
->bAnyFromWildcard
= TRUE
;
1179 FILE_ENTRY
*file
= &flList
->feFiles
[i
];
1180 add_file_to_entry(file
, szCurFile
);
1181 file
->attributes
= GetFileAttributesW( file
->szFullPath
);
1182 file
->bExists
= (file
->attributes
!= INVALID_FILE_ATTRIBUTES
);
1185 flList
->bAnyDontExist
= TRUE
;
1187 if (IsAttribDir(file
->attributes
))
1188 flList
->bAnyDirectories
= TRUE
;
1191 /* advance to the next string */
1192 ptr
+= lstrlenW(ptr
) + 1;
1195 flList
->dwNumFiles
= i
;
1200 /* free the FILE_LIST */
1201 static void destroy_file_list(FILE_LIST
*flList
)
1205 if (!flList
|| !flList
->feFiles
)
1208 for (i
= 0; i
< flList
->dwNumFiles
; i
++)
1210 HeapFree(GetProcessHeap(), 0, flList
->feFiles
[i
].szDirectory
);
1211 HeapFree(GetProcessHeap(), 0, flList
->feFiles
[i
].szFilename
);
1212 HeapFree(GetProcessHeap(), 0, flList
->feFiles
[i
].szFullPath
);
1215 HeapFree(GetProcessHeap(), 0, flList
->feFiles
);
1218 static void copy_dir_to_dir(FILE_OPERATION
*op
, const FILE_ENTRY
*feFrom
, LPCWSTR szDestPath
)
1220 WCHAR szFrom
[MAX_PATH
], szTo
[MAX_PATH
];
1221 FILE_LIST flFromNew
, flToNew
;
1223 static const WCHAR wildCardFiles
[] = {'*','.','*',0};
1225 if (IsDotDir(feFrom
->szFilename
))
1228 if (PathFileExistsW(szDestPath
))
1229 PathCombineW(szTo
, szDestPath
, feFrom
->szFilename
);
1231 lstrcpyW(szTo
, szDestPath
);
1233 if (!(op
->req
->fFlags
& FOF_NOCONFIRMATION
) && PathFileExistsW(szTo
))
1235 if (!SHELL_ConfirmDialogW(op
->req
->hwnd
, ASK_OVERWRITE_FOLDER
, feFrom
->szFilename
, op
))
1237 /* Vista returns an ERROR_CANCELLED even if user pressed "No" */
1238 if (!op
->bManyItems
)
1239 op
->bCancelled
= TRUE
;
1244 szTo
[lstrlenW(szTo
) + 1] = '\0';
1245 SHNotifyCreateDirectoryW(szTo
, NULL
);
1247 PathCombineW(szFrom
, feFrom
->szFullPath
, wildCardFiles
);
1248 szFrom
[lstrlenW(szFrom
) + 1] = '\0';
1250 ZeroMemory(&flFromNew
, sizeof(FILE_LIST
));
1251 ZeroMemory(&flToNew
, sizeof(FILE_LIST
));
1252 parse_file_list(&flFromNew
, szFrom
);
1253 parse_file_list(&flToNew
, szTo
);
1255 copy_files(op
, FALSE
, &flFromNew
, &flToNew
);
1257 destroy_file_list(&flFromNew
);
1258 destroy_file_list(&flToNew
);
1261 static BOOL
copy_file_to_file(FILE_OPERATION
*op
, const WCHAR
*szFrom
, const WCHAR
*szTo
)
1263 if (!(op
->req
->fFlags
& FOF_NOCONFIRMATION
) && PathFileExistsW(szTo
))
1265 if (!SHELL_ConfirmDialogW(op
->req
->hwnd
, ASK_OVERWRITE_FILE
, PathFindFileNameW(szTo
), op
))
1269 return SHNotifyCopyFileW(op
, szFrom
, szTo
, FALSE
) == 0;
1272 /* copy a file or directory to another directory */
1273 static void copy_to_dir(FILE_OPERATION
*op
, const FILE_ENTRY
*feFrom
, const FILE_ENTRY
*feTo
)
1275 if (!PathFileExistsW(feTo
->szFullPath
))
1276 SHNotifyCreateDirectoryW(feTo
->szFullPath
, NULL
);
1278 if (IsAttribFile(feFrom
->attributes
))
1280 WCHAR szDestPath
[MAX_PATH
];
1282 PathCombineW(szDestPath
, feTo
->szFullPath
, feFrom
->szFilename
);
1283 copy_file_to_file(op
, feFrom
->szFullPath
, szDestPath
);
1285 else if (!(op
->req
->fFlags
& FOF_FILESONLY
&& feFrom
->bFromWildcard
))
1286 copy_dir_to_dir(op
, feFrom
, feTo
->szFullPath
);
1289 static void create_dest_dirs(LPCWSTR szDestDir
)
1291 WCHAR dir
[MAX_PATH
];
1292 LPCWSTR ptr
= StrChrW(szDestDir
, '\\');
1294 /* make sure all directories up to last one are created */
1295 while (ptr
&& (ptr
= StrChrW(ptr
+ 1, '\\')))
1297 lstrcpynW(dir
, szDestDir
, ptr
- szDestDir
+ 1);
1299 if (!PathFileExistsW(dir
))
1300 SHNotifyCreateDirectoryW(dir
, NULL
);
1303 /* create last directory */
1304 if (!PathFileExistsW(szDestDir
))
1305 SHNotifyCreateDirectoryW(szDestDir
, NULL
);
1308 /* the FO_COPY operation */
1309 static HRESULT
copy_files(FILE_OPERATION
*op
, BOOL multiDest
, const FILE_LIST
*flFrom
, FILE_LIST
*flTo
)
1312 const FILE_ENTRY
*entryToCopy
;
1313 const FILE_ENTRY
*fileDest
= &flTo
->feFiles
[0];
1315 if (flFrom
->bAnyDontExist
)
1316 return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND
;
1318 if (flTo
->dwNumFiles
== 0)
1320 /* If the destination is empty, SHFileOperation should use the current directory */
1321 WCHAR curdir
[MAX_PATH
+1];
1323 GetCurrentDirectoryW(MAX_PATH
, curdir
);
1324 curdir
[lstrlenW(curdir
)+1] = 0;
1326 destroy_file_list(flTo
);
1327 ZeroMemory(flTo
, sizeof(FILE_LIST
));
1328 parse_file_list(flTo
, curdir
);
1329 fileDest
= &flTo
->feFiles
[0];
1334 if (flFrom
->bAnyFromWildcard
)
1335 return ERROR_CANCELLED
;
1337 if (flFrom
->dwNumFiles
!= flTo
->dwNumFiles
)
1339 if (flFrom
->dwNumFiles
!= 1 && !IsAttribDir(fileDest
->attributes
))
1340 return ERROR_CANCELLED
;
1342 /* Free all but the first entry. */
1343 for (i
= 1; i
< flTo
->dwNumFiles
; i
++)
1345 HeapFree(GetProcessHeap(), 0, flTo
->feFiles
[i
].szDirectory
);
1346 HeapFree(GetProcessHeap(), 0, flTo
->feFiles
[i
].szFilename
);
1347 HeapFree(GetProcessHeap(), 0, flTo
->feFiles
[i
].szFullPath
);
1350 flTo
->dwNumFiles
= 1;
1352 else if (IsAttribDir(fileDest
->attributes
))
1354 for (i
= 1; i
< flTo
->dwNumFiles
; i
++)
1355 if (!IsAttribDir(flTo
->feFiles
[i
].attributes
) ||
1356 !IsAttribDir(flFrom
->feFiles
[i
].attributes
))
1358 return ERROR_CANCELLED
;
1362 else if (flFrom
->dwNumFiles
!= 1)
1364 if (flTo
->dwNumFiles
!= 1 && !IsAttribDir(fileDest
->attributes
))
1365 return ERROR_CANCELLED
;
1367 if (PathFileExistsW(fileDest
->szFullPath
) &&
1368 IsAttribFile(fileDest
->attributes
))
1370 return ERROR_CANCELLED
;
1373 if (flTo
->dwNumFiles
== 1 && fileDest
->bFromRelative
&&
1374 !PathFileExistsW(fileDest
->szFullPath
))
1376 return ERROR_CANCELLED
;
1380 for (i
= 0; i
< flFrom
->dwNumFiles
; i
++)
1382 entryToCopy
= &flFrom
->feFiles
[i
];
1385 flTo
->dwNumFiles
> 1)
1387 fileDest
= &flTo
->feFiles
[i
];
1390 if (IsAttribDir(entryToCopy
->attributes
) &&
1391 !lstrcmpiW(entryToCopy
->szFullPath
, fileDest
->szDirectory
))
1393 return ERROR_SUCCESS
;
1396 create_dest_dirs(fileDest
->szDirectory
);
1398 if (!lstrcmpiW(entryToCopy
->szFullPath
, fileDest
->szFullPath
))
1400 if (IsAttribFile(entryToCopy
->attributes
))
1401 return ERROR_NO_MORE_SEARCH_HANDLES
;
1403 return ERROR_SUCCESS
;
1406 if ((flFrom
->dwNumFiles
> 1 && flTo
->dwNumFiles
== 1) ||
1407 IsAttribDir(fileDest
->attributes
))
1409 copy_to_dir(op
, entryToCopy
, fileDest
);
1411 else if (IsAttribDir(entryToCopy
->attributes
))
1413 copy_dir_to_dir(op
, entryToCopy
, fileDest
->szFullPath
);
1417 if (!copy_file_to_file(op
, entryToCopy
->szFullPath
, fileDest
->szFullPath
))
1419 op
->req
->fAnyOperationsAborted
= TRUE
;
1420 return ERROR_CANCELLED
;
1424 if (op
->progress
!= NULL
)
1425 op
->bCancelled
|= op
->progress
->HasUserCancelled();
1426 /* Vista return code. XP would return e.g. ERROR_FILE_NOT_FOUND, ERROR_ALREADY_EXISTS */
1428 return ERROR_CANCELLED
;
1431 /* Vista return code. On XP if the used pressed "No" for the last item,
1432 * ERROR_ARENA_TRASHED would be returned */
1433 return ERROR_SUCCESS
;
1436 static BOOL
confirm_delete_list(HWND hWnd
, DWORD fFlags
, BOOL fTrash
, const FILE_LIST
*flFrom
)
1438 if (flFrom
->dwNumFiles
> 1)
1441 const WCHAR format
[] = {'%','d',0};
1443 wnsprintfW(tmp
, sizeof(tmp
)/sizeof(tmp
[0]), format
, flFrom
->dwNumFiles
);
1444 return SHELL_ConfirmDialogW(hWnd
, (fTrash
?ASK_TRASH_MULTIPLE_ITEM
:ASK_DELETE_MULTIPLE_ITEM
), tmp
, NULL
);
1448 const FILE_ENTRY
*fileEntry
= &flFrom
->feFiles
[0];
1450 if (IsAttribFile(fileEntry
->attributes
))
1451 return SHELL_ConfirmDialogW(hWnd
, (fTrash
?ASK_TRASH_FILE
:ASK_DELETE_FILE
), fileEntry
->szFullPath
, NULL
);
1452 else if (!(fFlags
& FOF_FILESONLY
&& fileEntry
->bFromWildcard
))
1453 return SHELL_ConfirmDialogW(hWnd
, (fTrash
?ASK_TRASH_FOLDER
:ASK_DELETE_FOLDER
), fileEntry
->szFullPath
, NULL
);
1458 /* the FO_DELETE operation */
1459 static HRESULT
delete_files(FILE_OPERATION
*op
, const FILE_LIST
*flFrom
)
1461 const FILE_ENTRY
*fileEntry
;
1466 if (!flFrom
->dwNumFiles
)
1467 return ERROR_SUCCESS
;
1469 /* Windows also checks only the first item */
1470 bTrash
= (op
->req
->fFlags
& FOF_ALLOWUNDO
)
1471 && TRASH_CanTrashFile(flFrom
->feFiles
[0].szFullPath
);
1473 if (!(op
->req
->fFlags
& FOF_NOCONFIRMATION
) || (!bTrash
&& op
->req
->fFlags
& FOF_WANTNUKEWARNING
))
1474 if (!confirm_delete_list(op
->req
->hwnd
, op
->req
->fFlags
, bTrash
, flFrom
))
1476 op
->req
->fAnyOperationsAborted
= TRUE
;
1480 for (i
= 0; i
< flFrom
->dwNumFiles
; i
++)
1483 fileEntry
= &flFrom
->feFiles
[i
];
1485 if (!IsAttribFile(fileEntry
->attributes
) &&
1486 (op
->req
->fFlags
& FOF_FILESONLY
&& fileEntry
->bFromWildcard
))
1492 if (TRASH_TrashFile(fileEntry
->szFullPath
))
1494 SHChangeNotify(SHCNE_DELETE
, SHCNF_PATHW
, fileEntry
->szFullPath
, NULL
);
1498 /* Note: Windows silently deletes the file in such a situation, we show a dialog */
1499 if (!(op
->req
->fFlags
& FOF_NOCONFIRMATION
) || (op
->req
->fFlags
& FOF_WANTNUKEWARNING
))
1500 bDelete
= SHELL_ConfirmDialogW(op
->req
->hwnd
, ASK_CANT_TRASH_ITEM
, fileEntry
->szFullPath
, NULL
);
1506 op
->req
->fAnyOperationsAborted
= TRUE
;
1511 /* delete the file or directory */
1512 if (IsAttribFile(fileEntry
->attributes
))
1514 bPathExists
= (ERROR_SUCCESS
== SHNotifyDeleteFileW(op
, fileEntry
->szFullPath
));
1517 bPathExists
= SHELL_DeleteDirectoryW(op
, fileEntry
->szFullPath
, FALSE
);
1521 DWORD err
= GetLastError();
1523 if (ERROR_FILE_NOT_FOUND
== err
)
1525 // This is a windows 2003 server specific value which ahs been removed.
1526 // Later versions of windows return ERROR_FILE_NOT_FOUND.
1535 if (op
->progress
!= NULL
)
1536 op
->bCancelled
|= op
->progress
->HasUserCancelled();
1537 /* Should fire on progress dialog only */
1539 return ERROR_CANCELLED
;
1542 return ERROR_SUCCESS
;
1545 static void move_dir_to_dir(FILE_OPERATION
*op
, const FILE_ENTRY
*feFrom
, LPCWSTR szDestPath
)
1547 WCHAR szFrom
[MAX_PATH
], szTo
[MAX_PATH
];
1548 FILE_LIST flFromNew
, flToNew
;
1550 static const WCHAR wildCardFiles
[] = {'*','.','*',0};
1552 if (IsDotDir(feFrom
->szFilename
))
1555 SHNotifyCreateDirectoryW(szDestPath
, NULL
);
1557 PathCombineW(szFrom
, feFrom
->szFullPath
, wildCardFiles
);
1558 szFrom
[lstrlenW(szFrom
) + 1] = '\0';
1560 lstrcpyW(szTo
, szDestPath
);
1561 szTo
[lstrlenW(szDestPath
) + 1] = '\0';
1563 ZeroMemory(&flFromNew
, sizeof(FILE_LIST
));
1564 ZeroMemory(&flToNew
, sizeof(FILE_LIST
));
1565 parse_file_list(&flFromNew
, szFrom
);
1566 parse_file_list(&flToNew
, szTo
);
1568 move_files(op
, FALSE
, &flFromNew
, &flToNew
);
1570 destroy_file_list(&flFromNew
);
1571 destroy_file_list(&flToNew
);
1574 /* moves a file or directory to another directory */
1575 static void move_to_dir(FILE_OPERATION
*op
, const FILE_ENTRY
*feFrom
, const FILE_ENTRY
*feTo
)
1577 WCHAR szDestPath
[MAX_PATH
];
1579 PathCombineW(szDestPath
, feTo
->szFullPath
, feFrom
->szFilename
);
1581 if (IsAttribFile(feFrom
->attributes
))
1582 SHNotifyMoveFileW(op
, feFrom
->szFullPath
, szDestPath
, FALSE
);
1583 else if (!(op
->req
->fFlags
& FOF_FILESONLY
&& feFrom
->bFromWildcard
))
1584 move_dir_to_dir(op
, feFrom
, szDestPath
);
1587 /* the FO_MOVE operation */
1588 static DWORD
move_files(FILE_OPERATION
*op
, BOOL multiDest
, const FILE_LIST
*flFrom
, const FILE_LIST
*flTo
)
1593 const FILE_ENTRY
*entryToMove
;
1594 const FILE_ENTRY
*fileDest
;
1596 if (!flFrom
->dwNumFiles
)
1597 return ERROR_SUCCESS
;
1599 if (!flTo
->dwNumFiles
)
1600 return ERROR_FILE_NOT_FOUND
;
1603 flTo
->dwNumFiles
> 1 && flFrom
->dwNumFiles
> 1)
1605 return ERROR_CANCELLED
;
1609 !flFrom
->bAnyDirectories
&&
1610 flFrom
->dwNumFiles
> flTo
->dwNumFiles
)
1612 return ERROR_CANCELLED
;
1615 if (!PathFileExistsW(flTo
->feFiles
[0].szDirectory
))
1616 return ERROR_CANCELLED
;
1619 mismatched
= flFrom
->dwNumFiles
- flTo
->dwNumFiles
;
1621 fileDest
= &flTo
->feFiles
[0];
1622 for (i
= 0; i
< flFrom
->dwNumFiles
; i
++)
1624 entryToMove
= &flFrom
->feFiles
[i
];
1626 if (!PathFileExistsW(fileDest
->szDirectory
))
1627 return ERROR_CANCELLED
;
1631 if (i
>= flTo
->dwNumFiles
)
1633 fileDest
= &flTo
->feFiles
[i
];
1634 if (mismatched
&& !fileDest
->bExists
)
1636 create_dest_dirs(flTo
->feFiles
[i
].szFullPath
);
1637 flTo
->feFiles
[i
].bExists
= TRUE
;
1638 flTo
->feFiles
[i
].attributes
= FILE_ATTRIBUTE_DIRECTORY
;
1642 if (fileDest
->bExists
&& IsAttribDir(fileDest
->attributes
))
1643 move_to_dir(op
, entryToMove
, fileDest
);
1645 SHNotifyMoveFileW(op
, entryToMove
->szFullPath
, fileDest
->szFullPath
, IsAttribDir(entryToMove
->attributes
));
1647 if (op
->progress
!= NULL
)
1648 op
->bCancelled
|= op
->progress
->HasUserCancelled();
1649 /* Should fire on progress dialog only */
1651 return ERROR_CANCELLED
;
1657 if (flFrom
->bAnyDirectories
)
1658 return DE_DESTSAMETREE
;
1663 return ERROR_SUCCESS
;
1666 /* the FO_RENAME files */
1667 static HRESULT
rename_files(FILE_OPERATION
*op
, const FILE_LIST
*flFrom
, const FILE_LIST
*flTo
)
1669 const FILE_ENTRY
*feFrom
;
1670 const FILE_ENTRY
*feTo
;
1672 if (flFrom
->dwNumFiles
!= 1)
1673 return ERROR_GEN_FAILURE
;
1675 if (flTo
->dwNumFiles
!= 1)
1676 return ERROR_CANCELLED
;
1678 feFrom
= &flFrom
->feFiles
[0];
1679 feTo
= &flTo
->feFiles
[0];
1681 /* fail if destination doesn't exist */
1682 if (!feFrom
->bExists
)
1683 return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND
;
1685 /* fail if destination already exists */
1687 return ERROR_ALREADY_EXISTS
;
1689 return SHNotifyMoveFileW(op
, feFrom
->szFullPath
, feTo
->szFullPath
, IsAttribDir(feFrom
->attributes
));
1692 /* alert the user if an unsupported flag is used */
1693 static void check_flags(FILEOP_FLAGS fFlags
)
1695 WORD wUnsupportedFlags
= FOF_NO_CONNECTED_ELEMENTS
|
1696 FOF_NOCOPYSECURITYATTRIBS
| FOF_NORECURSEREPARSE
|
1697 FOF_RENAMEONCOLLISION
| FOF_WANTMAPPINGHANDLE
;
1699 if (fFlags
& wUnsupportedFlags
)
1700 FIXME("Unsupported flags: %04x\n", fFlags
);
1703 /*************************************************************************
1704 * SHFileOperationW [SHELL32.@]
1706 * See SHFileOperationA
1708 int WINAPI
SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp
)
1711 FILE_LIST flFrom
, flTo
;
1715 return ERROR_INVALID_PARAMETER
;
1717 ret
= CoInitialize(NULL
);
1721 check_flags(lpFileOp
->fFlags
);
1723 ZeroMemory(&flFrom
, sizeof(FILE_LIST
));
1724 ZeroMemory(&flTo
, sizeof(FILE_LIST
));
1726 if ((ret
= parse_file_list(&flFrom
, lpFileOp
->pFrom
)))
1729 if (lpFileOp
->wFunc
!= FO_DELETE
)
1730 parse_file_list(&flTo
, lpFileOp
->pTo
);
1732 ZeroMemory(&op
, sizeof(op
));
1734 op
.totalSize
.QuadPart
= 0ull;
1735 op
.completedSize
.QuadPart
= 0ull;
1736 op
.bManyItems
= (flFrom
.dwNumFiles
> 1);
1738 if (lpFileOp
->wFunc
!= FO_RENAME
&& !(lpFileOp
->fFlags
& FOF_SILENT
)) {
1739 ret
= CoCreateInstance(CLSID_ProgressDialog
,
1741 CLSCTX_INPROC_SERVER
,
1742 IID_PPV_ARG(IProgressDialog
, &op
.progress
));
1746 op
.progress
->StartProgressDialog(op
.req
->hwnd
, NULL
, PROGDLG_NORMAL
& PROGDLG_AUTOTIME
, NULL
);
1747 _SetOperationTitle(&op
);
1748 _FileOpCountManager(&op
, &flFrom
);
1751 switch (lpFileOp
->wFunc
)
1754 ret
= copy_files(&op
, op
.req
->fFlags
& FOF_MULTIDESTFILES
, &flFrom
, &flTo
);
1757 ret
= delete_files(&op
, &flFrom
);
1760 ret
= move_files(&op
, op
.req
->fFlags
& FOF_MULTIDESTFILES
, &flFrom
, &flTo
);
1763 ret
= rename_files(&op
, &flFrom
, &flTo
);
1766 ret
= ERROR_INVALID_PARAMETER
;
1771 op
.progress
->StopProgressDialog();
1772 op
.progress
->Release();
1776 destroy_file_list(&flFrom
);
1778 if (lpFileOp
->wFunc
!= FO_DELETE
)
1779 destroy_file_list(&flTo
);
1781 if (ret
== ERROR_CANCELLED
)
1782 lpFileOp
->fAnyOperationsAborted
= TRUE
;
1789 // Used by SHFreeNameMappings
1790 static int CALLBACK
_DestroyCallback(void *p
, void *pData
)
1792 LPSHNAMEMAPPINGW lp
= (SHNAMEMAPPINGW
*)p
;
1794 SHFree(lp
->pszOldPath
);
1795 SHFree(lp
->pszNewPath
);
1800 /*************************************************************************
1801 * SHFreeNameMappings [shell32.246]
1803 * Free the mapping handle returned by SHFileOperation if FOF_WANTSMAPPINGHANDLE
1807 * hNameMapping [I] handle to the name mappings used during renaming of files
1812 void WINAPI
SHFreeNameMappings(HANDLE hNameMapping
)
1816 DSA_DestroyCallback((HDSA
) hNameMapping
, _DestroyCallback
, NULL
);
1820 /*************************************************************************
1821 * SheGetDirA [SHELL32.@]
1823 * drive = 0: returns the current directory path
1824 * drive > 0: returns the current directory path of the specified drive
1825 * drive=1 -> A: drive=2 -> B: ...
1826 * returns 0 if successful
1828 EXTERN_C DWORD WINAPI
SheGetDirA(DWORD drive
, LPSTR buffer
)
1830 WCHAR org_path
[MAX_PATH
];
1834 /* change current directory to the specified drive */
1836 strcpy(drv_path
, "A:");
1837 drv_path
[0] += (char)drive
-1;
1839 GetCurrentDirectoryW(MAX_PATH
, org_path
);
1841 SetCurrentDirectoryA(drv_path
);
1844 /* query current directory path of the specified drive */
1845 ret
= GetCurrentDirectoryA(MAX_PATH
, buffer
);
1847 /* back to the original drive */
1849 SetCurrentDirectoryW(org_path
);
1852 return GetLastError();
1857 /*************************************************************************
1858 * SheGetDirW [SHELL32.@]
1860 * drive = 0: returns the current directory path
1861 * drive > 0: returns the current directory path of the specified drive
1862 * drive=1 -> A: drive=2 -> B: ...
1863 * returns 0 if successful
1865 EXTERN_C DWORD WINAPI
SheGetDirW(DWORD drive
, LPWSTR buffer
)
1867 WCHAR org_path
[MAX_PATH
];
1871 /* change current directory to the specified drive */
1874 strcpy(drv_path
, "A:");
1875 drv_path
[0] += (char)drive
-1;
1877 GetCurrentDirectoryW(MAX_PATH
, org_path
);
1879 SetCurrentDirectoryA(drv_path
);
1882 /* query current directory path of the specified drive */
1883 ret
= GetCurrentDirectoryW(MAX_PATH
, buffer
);
1885 /* back to the original drive */
1887 SetCurrentDirectoryW(org_path
);
1890 return GetLastError();
1895 /*************************************************************************
1896 * SheChangeDirA [SHELL32.@]
1898 * changes the current directory to the specified path
1899 * and returns 0 if successful
1901 EXTERN_C DWORD WINAPI
SheChangeDirA(LPSTR path
)
1903 if (SetCurrentDirectoryA(path
))
1906 return GetLastError();
1909 /*************************************************************************
1910 * SheChangeDirW [SHELL32.@]
1912 * changes the current directory to the specified path
1913 * and returns 0 if successful
1915 EXTERN_C DWORD WINAPI
SheChangeDirW(LPWSTR path
)
1917 if (SetCurrentDirectoryW(path
))
1920 return GetLastError();
1923 /*************************************************************************
1924 * IsNetDrive [SHELL32.66]
1926 EXTERN_C
int WINAPI
IsNetDrive(int drive
)
1929 strcpy(root
, "A:\\");
1930 root
[0] += (char)drive
;
1931 return (GetDriveTypeA(root
) == DRIVE_REMOTE
);
1935 /*************************************************************************
1936 * RealDriveType [SHELL32.524]
1938 EXTERN_C INT WINAPI
RealDriveType(INT drive
, BOOL bQueryNet
)
1940 char root
[] = "A:\\";
1941 root
[0] += (char)drive
;
1942 return GetDriveTypeA(root
);
1945 /***********************************************************************
1946 * SHPathPrepareForWriteW (SHELL32.@)
1948 EXTERN_C HRESULT WINAPI
SHPathPrepareForWriteW(HWND hwnd
, IUnknown
*modless
, LPCWSTR path
, DWORD flags
)
1955 WCHAR
* temppath
=NULL
;
1957 TRACE("%p %p %s 0x%80x\n", hwnd
, modless
, debugstr_w(path
), flags
);
1959 if (flags
& ~(SHPPFW_DIRCREATE
|SHPPFW_ASKDIRCREATE
|SHPPFW_IGNOREFILENAME
))
1960 FIXME("unimplemented flags 0x%08x\n", flags
);
1962 /* cut off filename if necessary */
1963 if (flags
& SHPPFW_IGNOREFILENAME
)
1965 last_slash
= StrRChrW(path
, NULL
, '\\');
1966 if (last_slash
== NULL
)
1969 len
= last_slash
- path
+ 1;
1970 temppath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1972 return E_OUTOFMEMORY
;
1973 StrCpyNW(temppath
, path
, len
);
1974 realpath
= temppath
;
1981 /* try to create the directory if asked to */
1982 if (flags
& (SHPPFW_DIRCREATE
|SHPPFW_ASKDIRCREATE
))
1984 if (flags
& SHPPFW_ASKDIRCREATE
)
1985 FIXME("treating SHPPFW_ASKDIRCREATE as SHPPFW_DIRCREATE\n");
1987 SHCreateDirectoryExW(0, realpath
, NULL
);
1990 /* check if we can access the directory */
1991 res
= GetFileAttributesW(realpath
);
1993 HeapFree(GetProcessHeap(), 0, temppath
);
1995 if (res
== INVALID_FILE_ATTRIBUTES
)
1997 err
= GetLastError();
1998 if (err
== ERROR_FILE_NOT_FOUND
)
1999 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
2000 return HRESULT_FROM_WIN32(err
);
2002 else if (res
& FILE_ATTRIBUTE_DIRECTORY
)
2005 return HRESULT_FROM_WIN32(ERROR_DIRECTORY
);
2008 /***********************************************************************
2009 * SHPathPrepareForWriteA (SHELL32.@)
2011 EXTERN_C HRESULT WINAPI
SHPathPrepareForWriteA(HWND hwnd
, IUnknown
*modless
, LPCSTR path
, DWORD flags
)
2013 WCHAR wpath
[MAX_PATH
];
2014 MultiByteToWideChar( CP_ACP
, 0, path
, -1, wpath
, MAX_PATH
);
2015 return SHPathPrepareForWriteW(hwnd
, modless
, wpath
, flags
);
2020 * The two following background operations were modified from filedefext.cpp
2021 * They use an inordinate amount of mutable state across the string functions,
2022 * so are not easy to follow and care is required when modifying.
2026 _FileOpCountManager(FILE_OPERATION
*op
, const FILE_LIST
*from
)
2028 DWORD ticks
= GetTickCount();
2029 FILE_ENTRY
*entryToCount
;
2031 for (UINT i
= 0; i
< from
->dwNumFiles
; i
++)
2033 entryToCount
= &from
->feFiles
[i
];
2035 WCHAR theFileName
[MAX_PATH
];
2036 StringCchCopyW(theFileName
, MAX_PATH
, entryToCount
->szFullPath
);
2037 _FileOpCount(op
, theFileName
, IsAttribDir(entryToCount
->attributes
), &ticks
);
2042 // All path manipulations, even when this function is nested, occur on the one buffer.
2044 _FileOpCount(FILE_OPERATION
*op
, LPWSTR pwszBuf
, BOOL bFolder
, DWORD
*ticks
)
2046 /* Find filename position */
2047 UINT cchBuf
= wcslen(pwszBuf
);
2048 WCHAR
*pwszFilename
= pwszBuf
+ cchBuf
;
2049 size_t cchFilenameMax
= MAX_PATH
- cchBuf
;
2050 if (!cchFilenameMax
)
2054 *(pwszFilename
++) = '\\';
2056 /* Find all files, FIXME: shouldn't be "*"? */
2057 StringCchCopyW(pwszFilename
, cchFilenameMax
, L
"*");
2060 WIN32_FIND_DATAW wfd
;
2061 HANDLE hFind
= FindFirstFileW(pwszBuf
, &wfd
);
2062 if (hFind
== INVALID_HANDLE_VALUE
)
2064 ERR("FindFirstFileW %ls failed\n", pwszBuf
);
2070 if (wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2072 /* Don't process "." and ".." items */
2073 if (!wcscmp(wfd
.cFileName
, L
".") || !wcscmp(wfd
.cFileName
, L
".."))
2076 StringCchCopyW(pwszFilename
, cchFilenameMax
, wfd
.cFileName
);
2077 _FileOpCount(op
, pwszBuf
, TRUE
, ticks
);
2081 ULARGE_INTEGER FileSize
;
2082 FileSize
.u
.LowPart
= wfd
.nFileSizeLow
;
2083 FileSize
.u
.HighPart
= wfd
.nFileSizeHigh
;
2084 op
->totalSize
.QuadPart
+= FileSize
.QuadPart
;
2086 if (GetTickCount() - *ticks
> (DWORD
) 500)
2088 // Check if the dialog has ended. If it has, we'll spin down.
2089 if (op
->progress
!= NULL
)
2090 op
->bCancelled
= op
->progress
->HasUserCancelled();
2094 *ticks
= GetTickCount();
2096 } while(FindNextFileW(hFind
, &wfd
));