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
);
133 SetBkMode(hdc
, TRANSPARENT
);
135 GetClientRect(GetDlgItem(hDlg
, IDC_YESTOALL_MESSAGE
), &r
);
136 /* this will remap the rect to dialog coords */
137 MapWindowPoints(GetDlgItem(hDlg
, IDC_YESTOALL_MESSAGE
), hDlg
, (LPPOINT
)&r
, 2);
138 hOldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)SendDlgItemMessageW(hDlg
, IDC_YESTOALL_MESSAGE
, WM_GETFONT
, 0, 0));
139 DrawTextW(hdc
, (LPWSTR
)GetPropW(hDlg
, CONFIRM_MSG_PROP
), -1, &r
, DT_NOPREFIX
| DT_PATH_ELLIPSIS
| DT_WORDBREAK
);
140 SelectObject(hdc
, hOldFont
);
146 static INT_PTR
ConfirmMsgBox_Init(HWND hDlg
, LPARAM lParam
)
148 struct confirm_msg_info
*info
= (struct confirm_msg_info
*)lParam
;
155 SetWindowTextW(hDlg
, info
->lpszCaption
);
156 ShowWindow(GetDlgItem(hDlg
, IDC_YESTOALL_MESSAGE
), SW_HIDE
);
157 SetPropW(hDlg
, CONFIRM_MSG_PROP
, info
->lpszText
);
158 SendDlgItemMessageW(hDlg
, IDC_YESTOALL_ICON
, STM_SETICON
, (WPARAM
)info
->hIcon
, 0);
160 /* compute the text height and resize the dialog */
161 GetClientRect(GetDlgItem(hDlg
, IDC_YESTOALL_MESSAGE
), &r
);
164 hOldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)SendDlgItemMessageW(hDlg
, IDC_YESTOALL_MESSAGE
, WM_GETFONT
, 0, 0));
165 DrawTextW(hdc
, info
->lpszText
, -1, &r
, DT_NOPREFIX
| DT_PATH_ELLIPSIS
| DT_WORDBREAK
| DT_CALCRECT
);
166 SelectObject(hdc
, hOldFont
);
168 yOffset
= min(yOffset
, 35); /* don't make the dialog too small */
169 ReleaseDC(hDlg
, hdc
);
171 GetClientRect(hDlg
, &r
);
173 GetWindowRect(hDlg
, &r
);
174 width
= r
.right
- r
.left
;
175 height
= r
.bottom
- r
.top
- yOffset
;
176 MoveWindow(hDlg
, (GetSystemMetrics(SM_CXSCREEN
) - width
)/2,
177 (GetSystemMetrics(SM_CYSCREEN
) - height
)/2, width
, height
, FALSE
);
179 confirm_msg_move_button(hDlg
, IDCANCEL
, &xPos
, yOffset
, info
->bYesToAll
);
180 confirm_msg_move_button(hDlg
, IDNO
, &xPos
, yOffset
, TRUE
);
181 confirm_msg_move_button(hDlg
, IDC_YESTOALL
, &xPos
, yOffset
, info
->bYesToAll
);
182 confirm_msg_move_button(hDlg
, IDYES
, &xPos
, yOffset
, TRUE
);
187 static INT_PTR CALLBACK
ConfirmMsgBoxProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
192 return ConfirmMsgBox_Init(hDlg
, lParam
);
194 return ConfirmMsgBox_Paint(hDlg
);
196 EndDialog(hDlg
, wParam
);
199 EndDialog(hDlg
, IDCANCEL
);
205 int SHELL_ConfirmMsgBox(HWND hWnd
, LPWSTR lpszText
, LPWSTR lpszCaption
, HICON hIcon
, BOOL bYesToAll
)
207 struct confirm_msg_info info
;
209 info
.lpszText
= lpszText
;
210 info
.lpszCaption
= lpszCaption
;
212 info
.bYesToAll
= bYesToAll
;
213 return DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_YESTOALL_MSGBOX
), hWnd
, ConfirmMsgBoxProc
, (LPARAM
)&info
);
216 /* confirmation dialogs content */
219 HINSTANCE hIconInstance
;
220 UINT icon_resource_id
;
221 UINT caption_resource_id
, text_resource_id
;
222 } SHELL_ConfirmIDstruc
;
224 static BOOL
SHELL_ConfirmIDs(int nKindOfDialog
, SHELL_ConfirmIDstruc
*ids
)
226 ids
->hIconInstance
= shell32_hInstance
;
227 switch (nKindOfDialog
)
229 case ASK_DELETE_FILE
:
230 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
231 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
232 ids
->text_resource_id
= IDS_DELETEITEM_TEXT
;
235 case ASK_DELETE_FOLDER
:
236 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
237 ids
->caption_resource_id
= IDS_DELETEFOLDER_CAPTION
;
238 ids
->text_resource_id
= IDS_DELETEITEM_TEXT
;
241 case ASK_DELETE_MULTIPLE_ITEM
:
242 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
243 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
244 ids
->text_resource_id
= IDS_DELETEMULTIPLE_TEXT
;
248 ids
->icon_resource_id
= IDI_SHELL_TRASH_FILE
;
249 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
250 ids
->text_resource_id
= IDS_TRASHITEM_TEXT
;
253 case ASK_TRASH_FOLDER
:
254 ids
->icon_resource_id
= IDI_SHELL_TRASH_FILE
;
255 ids
->caption_resource_id
= IDS_DELETEFOLDER_CAPTION
;
256 ids
->text_resource_id
= IDS_TRASHFOLDER_TEXT
;
259 case ASK_TRASH_MULTIPLE_ITEM
:
260 ids
->icon_resource_id
= IDI_SHELL_TRASH_FILE
;
261 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
262 ids
->text_resource_id
= IDS_TRASHMULTIPLE_TEXT
;
265 case ASK_CANT_TRASH_ITEM
:
266 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
267 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
268 ids
->text_resource_id
= IDS_CANTTRASH_TEXT
;
271 case ASK_DELETE_SELECTED
:
272 ids
->icon_resource_id
= IDI_SHELL_CONFIRM_DELETE
;
273 ids
->caption_resource_id
= IDS_DELETEITEM_CAPTION
;
274 ids
->text_resource_id
= IDS_DELETESELECTED_TEXT
;
277 case ASK_OVERWRITE_FILE
:
278 ids
->icon_resource_id
= IDI_SHELL_FOLDER_MOVE2
;
279 ids
->caption_resource_id
= IDS_OVERWRITEFILE_CAPTION
;
280 ids
->text_resource_id
= IDS_OVERWRITEFILE_TEXT
;
283 case ASK_OVERWRITE_FOLDER
:
284 ids
->icon_resource_id
= IDI_SHELL_FOLDER_MOVE2
;
285 ids
->caption_resource_id
= IDS_OVERWRITEFILE_CAPTION
;
286 ids
->text_resource_id
= IDS_OVERWRITEFOLDER_TEXT
;
290 FIXME(" Unhandled nKindOfDialog %d stub\n", nKindOfDialog
);
295 static BOOL
SHELL_ConfirmDialogW(HWND hWnd
, int nKindOfDialog
, LPCWSTR szDir
, FILE_OPERATION
*op
)
297 WCHAR szCaption
[255], szText
[255], szBuffer
[MAX_PATH
+ 256];
298 SHELL_ConfirmIDstruc ids
;
303 assert(nKindOfDialog
>= 0 && nKindOfDialog
< 32);
304 if (op
&& (op
->dwYesToAllMask
& (1 << nKindOfDialog
)))
307 if (!SHELL_ConfirmIDs(nKindOfDialog
, &ids
)) return FALSE
;
309 LoadStringW(shell32_hInstance
, ids
.caption_resource_id
, szCaption
, sizeof(szCaption
)/sizeof(WCHAR
));
310 LoadStringW(shell32_hInstance
, ids
.text_resource_id
, szText
, sizeof(szText
)/sizeof(WCHAR
));
312 args
[0] = (DWORD_PTR
)szDir
;
313 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
314 szText
, 0, 0, szBuffer
, sizeof(szBuffer
), (va_list*)args
);
315 hIcon
= LoadIconW(ids
.hIconInstance
, (LPWSTR
)MAKEINTRESOURCE(ids
.icon_resource_id
));
317 ret
= SHELL_ConfirmMsgBox(hWnd
, szBuffer
, szCaption
, hIcon
, op
&& op
->bManyItems
);
320 if (ret
== IDC_YESTOALL
)
322 op
->dwYesToAllMask
|= (1 << nKindOfDialog
);
326 op
->bCancelled
= TRUE
;
328 op
->req
->fAnyOperationsAborted
= TRUE
;
333 BOOL
SHELL_ConfirmYesNoW(HWND hWnd
, int nKindOfDialog
, LPCWSTR szDir
)
335 return SHELL_ConfirmDialogW(hWnd
, nKindOfDialog
, szDir
, NULL
);
338 static DWORD
SHELL32_AnsiToUnicodeBuf(LPCSTR aPath
, LPWSTR
*wPath
, DWORD minChars
)
340 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, aPath
, -1, NULL
, 0);
345 *wPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
348 MultiByteToWideChar(CP_ACP
, 0, aPath
, -1, *wPath
, len
);
351 return E_OUTOFMEMORY
;
354 static void SHELL32_FreeUnicodeBuf(LPWSTR wPath
)
356 HeapFree(GetProcessHeap(), 0, wPath
);
359 EXTERN_C HRESULT WINAPI
SHIsFileAvailableOffline(LPCWSTR path
, LPDWORD status
)
361 FIXME("(%s, %p) stub\n", debugstr_w(path
), status
);
365 /**************************************************************************
366 * SHELL_DeleteDirectory() [internal]
368 * Asks for confirmation when bShowUI is true and deletes the directory and
369 * all its subdirectories and files if necessary.
371 BOOL
SHELL_DeleteDirectoryW(FILE_OPERATION
*op
, LPCWSTR pszDir
, BOOL bShowUI
)
375 WIN32_FIND_DATAW wfd
;
376 WCHAR szTemp
[MAX_PATH
];
378 /* Make sure the directory exists before eventually prompting the user */
379 PathCombineW(szTemp
, pszDir
, wWildcardFile
);
380 hFind
= FindFirstFileW(szTemp
, &wfd
);
381 if (hFind
== INVALID_HANDLE_VALUE
)
384 if (!bShowUI
|| (ret
= SHELL_ConfirmDialogW(op
->req
->hwnd
, ASK_DELETE_FOLDER
, pszDir
, NULL
)))
388 if (IsDotDir(wfd
.cFileName
))
390 PathCombineW(szTemp
, pszDir
, wfd
.cFileName
);
391 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
392 ret
= SHELL_DeleteDirectoryW(op
, szTemp
, FALSE
);
394 ret
= (SHNotifyDeleteFileW(op
, szTemp
) == ERROR_SUCCESS
);
396 if (op
->progress
!= NULL
)
397 op
->bCancelled
|= op
->progress
->HasUserCancelled();
398 } while (ret
&& FindNextFileW(hFind
, &wfd
) && !op
->bCancelled
);
402 ret
= (SHNotifyRemoveDirectoryW(pszDir
) == ERROR_SUCCESS
);
406 /**************************************************************************
407 * Win32CreateDirectory [SHELL32.93]
409 * Creates a directory. Also triggers a change notify if one exists.
412 * path [I] path to directory to create
415 * TRUE if successful, FALSE otherwise
418 static DWORD
SHNotifyCreateDirectoryW(LPCWSTR path
, LPSECURITY_ATTRIBUTES sec
)
420 TRACE("(%s, %p)\n", debugstr_w(path
), sec
);
422 if (CreateDirectoryW(path
, sec
))
424 SHChangeNotify(SHCNE_MKDIR
, SHCNF_PATHW
, path
, NULL
);
425 return ERROR_SUCCESS
;
427 return GetLastError();
430 /**********************************************************************/
432 EXTERN_C BOOL WINAPI
Win32CreateDirectoryW(LPCWSTR path
, LPSECURITY_ATTRIBUTES sec
)
434 return (SHNotifyCreateDirectoryW(path
, sec
) == ERROR_SUCCESS
);
437 /************************************************************************
438 * Win32RemoveDirectory [SHELL32.94]
440 * Deletes a directory. Also triggers a change notify if one exists.
443 * path [I] path to directory to delete
446 * TRUE if successful, FALSE otherwise
448 static DWORD
SHNotifyRemoveDirectoryW(LPCWSTR path
)
451 TRACE("(%s)\n", debugstr_w(path
));
453 ret
= RemoveDirectoryW(path
);
456 /* Directory may be write protected */
457 DWORD dwAttr
= GetFileAttributesW(path
);
458 if (IsAttrib(dwAttr
, FILE_ATTRIBUTE_READONLY
))
459 if (SetFileAttributesW(path
, dwAttr
& ~FILE_ATTRIBUTE_READONLY
))
460 ret
= RemoveDirectoryW(path
);
464 SHChangeNotify(SHCNE_RMDIR
, SHCNF_PATHW
, path
, NULL
);
465 return ERROR_SUCCESS
;
467 return GetLastError();
470 /***********************************************************************/
472 EXTERN_C BOOL WINAPI
Win32RemoveDirectoryW(LPCWSTR path
)
474 return (SHNotifyRemoveDirectoryW(path
) == ERROR_SUCCESS
);
477 static void _SetOperationTitle(FILE_OPERATION
*op
) {
478 if (op
->progress
== NULL
)
480 WCHAR szTitle
[50], szPreflight
[50];
481 UINT animation_id
= NULL
;
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
));
488 animation_id
= IDA_SHELL_COPY
;
491 LoadStringW(shell32_hInstance
, IDS_FILEOOP_DELETING
, szTitle
, sizeof(szTitle
)/sizeof(WCHAR
));
492 LoadStringW(shell32_hInstance
, IDS_FILEOOP_FROM
, op
->szBuilderString
, sizeof( op
->szBuilderString
)/sizeof(WCHAR
));
493 animation_id
= IDA_SHELL_DELETE
;
496 LoadStringW(shell32_hInstance
, IDS_FILEOOP_MOVING
, szTitle
, sizeof(szTitle
)/sizeof(WCHAR
));
497 LoadStringW(shell32_hInstance
, IDS_FILEOOP_FROM_TO
, op
->szBuilderString
, sizeof( op
->szBuilderString
)/sizeof(WCHAR
));
498 animation_id
= IDA_SHELL_COPY
;
503 LoadStringW(shell32_hInstance
, IDS_FILEOOP_PREFLIGHT
, szPreflight
, sizeof(szPreflight
)/sizeof(WCHAR
));
505 op
->progress
->SetTitle(szTitle
);
506 op
->progress
->SetLine(1, szPreflight
, false, NULL
);
507 op
->progress
->SetAnimation(shell32_hInstance
, animation_id
);
510 static void _SetOperationTexts(FILE_OPERATION
*op
, LPCWSTR src
, LPCWSTR dest
) {
511 if (op
->progress
== NULL
|| src
== NULL
)
513 LPWSTR fileSpecS
, pathSpecS
, fileSpecD
, pathSpecD
;
514 WCHAR szFolderS
[50], szFolderD
[50], szFinalString
[260];
518 fileSpecS
= (pathSpecS
= (LPWSTR
) src
);
519 fileSpecD
= (pathSpecD
= (LPWSTR
) dest
);
521 // March across the string to get the file path and it's parent dir.
522 for (LPWSTR ptr
= (LPWSTR
) src
; *ptr
; ptr
++) {
524 pathSpecS
= fileSpecS
;
528 lstrcpynW(szFolderS
, pathSpecS
, min(50, fileSpecS
- pathSpecS
));
529 args
[0] = (DWORD_PTR
) szFolderS
;
531 switch (op
->req
->wFunc
)
537 for (LPWSTR ptr
= (LPWSTR
) dest
; *ptr
; ptr
++) {
539 pathSpecD
= fileSpecD
;
543 lstrcpynW(szFolderD
, pathSpecD
, min(50, fileSpecD
- pathSpecD
));
544 args
[1] = (DWORD_PTR
) szFolderD
;
552 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
553 op
->szBuilderString
, 0, 0, szFinalString
, sizeof(szFinalString
), (va_list*)args
);
555 op
->progress
->SetLine(1, fileSpecS
, false, NULL
);
556 op
->progress
->SetLine(2, szFinalString
, false, NULL
);
560 DWORD CALLBACK
SHCopyProgressRoutine(
561 LARGE_INTEGER TotalFileSize
,
562 LARGE_INTEGER TotalBytesTransferred
,
563 LARGE_INTEGER StreamSize
,
564 LARGE_INTEGER StreamBytesTransferred
,
565 DWORD dwStreamNumber
,
566 DWORD dwCallbackReason
,
568 HANDLE hDestinationFile
,
571 FILE_OPERATION
*op
= (FILE_OPERATION
*) lpData
;
575 * This is called at the start of each file. To keop less state,
576 * I'm adding the file to the completed size here, and the re-subtracting
577 * it when drawing the progress bar.
579 if (dwCallbackReason
& CALLBACK_STREAM_SWITCH
)
580 op
->completedSize
.QuadPart
+= TotalFileSize
.QuadPart
;
582 op
->progress
->SetProgress64(op
->completedSize
.QuadPart
-
583 TotalFileSize
.QuadPart
+
584 TotalBytesTransferred
.QuadPart
585 , op
->totalSize
.QuadPart
);
588 op
->bCancelled
= op
->progress
->HasUserCancelled();
595 /************************************************************************
596 * SHNotifyDeleteFileW [internal]
598 * Deletes a file. Also triggers a change notify if one exists.
601 * op [I] File Operation context
602 * path [I] path to source file to move
605 * ERORR_SUCCESS if successful
607 static DWORD
SHNotifyDeleteFileW(FILE_OPERATION
*op
, LPCWSTR path
)
611 TRACE("(%s)\n", debugstr_w(path
));
613 _SetOperationTexts(op
, path
, NULL
);
615 LARGE_INTEGER FileSize
;
616 FileSize
.QuadPart
= 0;
618 WIN32_FIND_DATAW wfd
;
619 HANDLE hFile
= FindFirstFileW(path
, &wfd
);
620 if (hFile
!= INVALID_HANDLE_VALUE
&& IsAttribFile(wfd
.dwFileAttributes
)) {
622 tmp
.u
.LowPart
= wfd
.nFileSizeLow
;
623 tmp
.u
.HighPart
= wfd
.nFileSizeHigh
;
624 FileSize
.QuadPart
= tmp
.QuadPart
;
628 ret
= DeleteFileW(path
);
631 /* File may be write protected or a system file */
632 DWORD dwAttr
= GetFileAttributesW(path
);
633 if (IsAttrib(dwAttr
, FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_SYSTEM
))
634 if (SetFileAttributesW(path
, dwAttr
& ~(FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_SYSTEM
)))
635 ret
= DeleteFileW(path
);
639 // Bit of a hack to make the progress bar move. We don't have progress inside the file, so inform when done.
640 SHCopyProgressRoutine(FileSize
, FileSize
, FileSize
, FileSize
, 0, CALLBACK_STREAM_SWITCH
, NULL
, NULL
, op
);
641 SHChangeNotify(SHCNE_DELETE
, SHCNF_PATHW
, path
, NULL
);
642 return ERROR_SUCCESS
;
644 return GetLastError();
647 /************************************************************************
648 * Win32DeleteFile [SHELL32.164]
650 * Deletes a file. Also triggers a change notify if one exists.
653 * path [I] path to file to delete
656 * TRUE if successful, FALSE otherwise
658 EXTERN_C DWORD WINAPI
Win32DeleteFileW(LPCWSTR path
)
660 return (SHNotifyDeleteFileW(NULL
, path
) == ERROR_SUCCESS
);
663 /************************************************************************
664 * SHNotifyMoveFile [internal]
666 * Moves a file. Also triggers a change notify if one exists.
669 * op [I] File Operation context
670 * src [I] path to source file to move
671 * dest [I] path to target file to move to
674 * ERROR_SUCCESS if successful
676 static DWORD
SHNotifyMoveFileW(FILE_OPERATION
*op
, LPCWSTR src
, LPCWSTR dest
, BOOL isdir
)
680 TRACE("(%s %s)\n", debugstr_w(src
), debugstr_w(dest
));
682 _SetOperationTexts(op
, src
, dest
);
684 ret
= MoveFileWithProgressW(src
, dest
, SHCopyProgressRoutine
, op
, MOVEFILE_REPLACE_EXISTING
);
686 /* MOVEFILE_REPLACE_EXISTING fails with dirs, so try MoveFile */
688 ret
= MoveFileW(src
, dest
);
694 dwAttr
= SHFindAttrW(dest
, FALSE
);
695 if (INVALID_FILE_ATTRIBUTES
== dwAttr
)
697 /* Source file may be write protected or a system file */
698 dwAttr
= GetFileAttributesW(src
);
699 if (IsAttrib(dwAttr
, FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_SYSTEM
))
700 if (SetFileAttributesW(src
, dwAttr
& ~(FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_SYSTEM
)))
701 ret
= MoveFileW(src
, dest
);
706 SHChangeNotify(isdir
? SHCNE_MKDIR
: SHCNE_CREATE
, SHCNF_PATHW
, dest
, NULL
);
707 SHChangeNotify(isdir
? SHCNE_RMDIR
: SHCNE_DELETE
, SHCNF_PATHW
, src
, NULL
);
708 return ERROR_SUCCESS
;
710 return GetLastError();
713 /************************************************************************
714 * SHNotifyCopyFile [internal]
716 * Copies a file. Also triggers a change notify if one exists.
719 * src [I] path to source file to move
720 * dest [I] path to target file to move to
721 * bFailIfExists [I] if TRUE, the target file will not be overwritten if
722 * a file with this name already exists
725 * ERROR_SUCCESS if successful
727 static DWORD
SHNotifyCopyFileW(FILE_OPERATION
*op
, LPCWSTR src
, LPCWSTR dest
, BOOL bFailIfExists
)
732 TRACE("(%s %s %s)\n", debugstr_w(src
), debugstr_w(dest
), bFailIfExists
? "failIfExists" : "");
734 _SetOperationTexts(op
, src
, dest
);
736 /* Destination file may already exist with read only attribute */
737 attribs
= GetFileAttributesW(dest
);
738 if (IsAttrib(attribs
, FILE_ATTRIBUTE_READONLY
))
739 SetFileAttributesW(dest
, attribs
& ~FILE_ATTRIBUTE_READONLY
);
741 if (GetFileAttributesW(dest
) & FILE_ATTRIBUTE_READONLY
)
743 SetFileAttributesW(dest
, attribs
& ~FILE_ATTRIBUTE_READONLY
);
744 if (GetFileAttributesW(dest
) & FILE_ATTRIBUTE_READONLY
)
746 TRACE("[shell32, SHNotifyCopyFileW] STILL SHIT\n");
750 ret
= CopyFileExW(src
, dest
, SHCopyProgressRoutine
, op
, &op
->bCancelled
, bFailIfExists
);
753 SHChangeNotify(SHCNE_CREATE
, SHCNF_PATHW
, dest
, NULL
);
754 return ERROR_SUCCESS
;
757 return GetLastError();
760 /*************************************************************************
761 * SHCreateDirectory [SHELL32.165]
763 * This function creates a file system folder whose fully qualified path is
764 * given by path. If one or more of the intermediate folders do not exist,
765 * they will be created as well.
769 * path [I] path of directory to create
772 * ERROR_SUCCESS or one of the following values:
773 * ERROR_BAD_PATHNAME if the path is relative
774 * ERROR_FILE_EXISTS when a file with that name exists
775 * ERROR_PATH_NOT_FOUND can't find the path, probably invalid
776 * ERROR_INVALID_NAME if the path contains invalid chars
777 * ERROR_ALREADY_EXISTS when the directory already exists
778 * ERROR_FILENAME_EXCED_RANGE if the filename was to long to process
781 * exported by ordinal
783 * WinNT/2000 exports Unicode
785 int WINAPI
SHCreateDirectory(HWND hWnd
, LPCWSTR path
)
787 return SHCreateDirectoryExW(hWnd
, path
, NULL
);
790 /*************************************************************************
791 * SHCreateDirectoryExA [SHELL32.@]
793 * This function creates a file system folder whose fully qualified path is
794 * given by path. If one or more of the intermediate folders do not exist,
795 * they will be created as well.
799 * path [I] path of directory to create
800 * sec [I] security attributes to use or NULL
803 * ERROR_SUCCESS or one of the following values:
804 * ERROR_BAD_PATHNAME or ERROR_PATH_NOT_FOUND if the path is relative
805 * ERROR_INVALID_NAME if the path contains invalid chars
806 * ERROR_FILE_EXISTS when a file with that name exists
807 * ERROR_ALREADY_EXISTS when the directory already exists
808 * ERROR_FILENAME_EXCED_RANGE if the filename was too long to process
810 * FIXME: Not implemented yet;
811 * SHCreateDirectoryEx also verifies that the files in the directory will be visible
812 * if the path is a network path to deal with network drivers which might have a limited
813 * but unknown maximum path length. If not:
815 * If hWnd is set to a valid window handle, a message box is displayed warning
816 * the user that the files may not be accessible. If the user chooses not to
817 * proceed, the function returns ERROR_CANCELLED.
819 * If hWnd is set to NULL, no user interface is displayed and the function
820 * returns ERROR_CANCELLED.
822 int WINAPI
SHCreateDirectoryExA(HWND hWnd
, LPCSTR path
, LPSECURITY_ATTRIBUTES sec
)
827 TRACE("(%s, %p)\n", debugstr_a(path
), sec
);
829 retCode
= SHELL32_AnsiToUnicodeBuf(path
, &wPath
, 0);
832 retCode
= SHCreateDirectoryExW(hWnd
, wPath
, sec
);
833 SHELL32_FreeUnicodeBuf(wPath
);
838 /*************************************************************************
839 * SHCreateDirectoryExW [SHELL32.@]
841 * See SHCreateDirectoryExA.
843 int WINAPI
SHCreateDirectoryExW(HWND hWnd
, LPCWSTR path
, LPSECURITY_ATTRIBUTES sec
)
845 int ret
= ERROR_BAD_PATHNAME
;
846 TRACE("(%p, %s, %p)\n", hWnd
, debugstr_w(path
), sec
);
848 if (PathIsRelativeW(path
))
854 ret
= SHNotifyCreateDirectoryW(path
, sec
);
855 /* Refuse to work on certain error codes before trying to create directories recursively */
856 if (ret
!= ERROR_SUCCESS
&&
857 ret
!= ERROR_FILE_EXISTS
&&
858 ret
!= ERROR_ALREADY_EXISTS
&&
859 ret
!= ERROR_FILENAME_EXCED_RANGE
)
861 WCHAR
*pEnd
, *pSlash
, szTemp
[MAX_PATH
+ 1]; /* extra for PathAddBackslash() */
863 lstrcpynW(szTemp
, path
, MAX_PATH
);
864 pEnd
= PathAddBackslashW(szTemp
);
869 while (*pSlash
&& *pSlash
!= '\\') pSlash
++;
872 *pSlash
= 0; /* terminate path at separator */
874 ret
= SHNotifyCreateDirectoryW(szTemp
, pSlash
+ 1 == pEnd
? sec
: NULL
);
876 *pSlash
++ = '\\'; /* put the separator back */
880 if (ret
&& hWnd
&& (ERROR_CANCELLED
!= ret
))
882 ShellMessageBoxW(shell32_hInstance
, hWnd
, MAKEINTRESOURCEW(IDS_CREATEFOLDER_DENIED
), MAKEINTRESOURCEW(IDS_CREATEFOLDER_CAPTION
),
883 MB_ICONEXCLAMATION
| MB_OK
, path
);
884 ret
= ERROR_CANCELLED
;
891 /*************************************************************************
892 * SHFindAttrW [internal]
894 * Get the Attributes for a file or directory. The difference to GetAttributes()
895 * is that this function will also work for paths containing wildcard characters
899 * path [I] path of directory or file to check
900 * fileOnly [I] TRUE if only files should be found
903 * INVALID_FILE_ATTRIBUTES if the path does not exist, the actual attributes of
904 * the first file or directory found otherwise
906 static DWORD
SHFindAttrW(LPCWSTR pName
, BOOL fileOnly
)
908 WIN32_FIND_DATAW wfd
;
909 BOOL b_FileMask
= fileOnly
&& (NULL
!= StrPBrkW(pName
, wWildcardChars
));
910 DWORD dwAttr
= INVALID_FILE_ATTRIBUTES
;
911 HANDLE hFind
= FindFirstFileW(pName
, &wfd
);
913 TRACE("%s %d\n", debugstr_w(pName
), fileOnly
);
914 if (INVALID_HANDLE_VALUE
!= hFind
)
918 if (b_FileMask
&& IsAttribDir(wfd
.dwFileAttributes
))
920 dwAttr
= wfd
.dwFileAttributes
;
922 } while (FindNextFileW(hFind
, &wfd
));
929 /*************************************************************************
931 * _ConvertAtoW helper function for SHFileOperationA
933 * Converts a string or string-list to unicode.
935 static DWORD
_ConvertAtoW(PCSTR strSrc
, PCWSTR
* pStrDest
, BOOL isList
)
939 // If the input is null, nothing to convert.
943 // Measure the total size, depending on if it's a zero-terminated list.
947 PCSTR tmpSrc
= strSrc
;
951 size
= lstrlenA(tmpSrc
) + 1;
958 sizeA
= lstrlenA(strSrc
) + 1;
961 // Measure the needed allocation size.
962 int sizeW
= MultiByteToWideChar(CP_ACP
, 0, strSrc
, sizeA
, NULL
, 0);
964 return GetLastError();
966 PWSTR strDest
= (PWSTR
) HeapAlloc(GetProcessHeap(), 0, sizeW
* sizeof(WCHAR
));
968 return ERROR_OUTOFMEMORY
;
970 int err
= MultiByteToWideChar(CP_ACP
, 0, strSrc
, sizeA
, strDest
, sizeW
);
973 HeapFree(GetProcessHeap(), 0, strDest
);
974 return GetLastError();
981 /*************************************************************************
982 * SHFileOperationA [SHELL32.@]
984 * Function to copy, move, delete and create one or more files with optional
988 * lpFileOp [I/O] pointer to a structure containing all the necessary information
991 * Success: ERROR_SUCCESS.
992 * Failure: ERROR_CANCELLED.
997 int WINAPI
SHFileOperationA(LPSHFILEOPSTRUCTA lpFileOp
)
999 int errCode
, retCode
;
1000 SHFILEOPSTRUCTW nFileOp
= { 0 };
1002 // Convert A information to W
1003 nFileOp
.hwnd
= lpFileOp
->hwnd
;
1004 nFileOp
.wFunc
= lpFileOp
->wFunc
;
1005 nFileOp
.fFlags
= lpFileOp
->fFlags
;
1007 errCode
= _ConvertAtoW(lpFileOp
->pFrom
, &nFileOp
.pFrom
, TRUE
);
1011 if (FO_DELETE
!= (nFileOp
.wFunc
& FO_MASK
))
1013 errCode
= _ConvertAtoW(lpFileOp
->pTo
, &nFileOp
.pTo
, TRUE
);
1018 if (nFileOp
.fFlags
& FOF_SIMPLEPROGRESS
)
1020 errCode
= _ConvertAtoW(lpFileOp
->lpszProgressTitle
, &nFileOp
.lpszProgressTitle
, FALSE
);
1025 // Call the actual function
1026 retCode
= SHFileOperationW(&nFileOp
);
1031 HeapFree(GetProcessHeap(), 0, (PVOID
) nFileOp
.pFrom
);
1033 HeapFree(GetProcessHeap(), 0, (PVOID
) nFileOp
.pTo
);
1034 if (nFileOp
.lpszProgressTitle
)
1035 HeapFree(GetProcessHeap(), 0, (PVOID
) nFileOp
.lpszProgressTitle
);
1039 lpFileOp
->fAnyOperationsAborted
= TRUE
;
1040 SetLastError(errCode
);
1045 // Thankfully, starting with NT4 the name mappings are always unicode, so no need to convert.
1046 lpFileOp
->hNameMappings
= nFileOp
.hNameMappings
;
1047 lpFileOp
->fAnyOperationsAborted
= nFileOp
.fAnyOperationsAborted
;
1051 static void __inline
grow_list(FILE_LIST
*list
)
1053 FILE_ENTRY
*newx
= (FILE_ENTRY
*)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, list
->feFiles
,
1054 list
->num_alloc
* 2 * sizeof(*newx
) );
1055 list
->feFiles
= newx
;
1056 list
->num_alloc
*= 2;
1059 /* adds a file to the FILE_ENTRY struct
1061 static void add_file_to_entry(FILE_ENTRY
*feFile
, LPCWSTR szFile
)
1063 DWORD dwLen
= lstrlenW(szFile
) + 1;
1066 feFile
->szFullPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwLen
* sizeof(WCHAR
));
1067 lstrcpyW(feFile
->szFullPath
, szFile
);
1069 ptr
= StrRChrW(szFile
, NULL
, '\\');
1072 dwLen
= ptr
- szFile
+ 1;
1073 feFile
->szDirectory
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwLen
* sizeof(WCHAR
));
1074 lstrcpynW(feFile
->szDirectory
, szFile
, dwLen
);
1076 dwLen
= lstrlenW(feFile
->szFullPath
) - dwLen
+ 1;
1077 feFile
->szFilename
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwLen
* sizeof(WCHAR
));
1078 lstrcpyW(feFile
->szFilename
, ptr
+ 1); /* skip over backslash */
1080 feFile
->bFromWildcard
= FALSE
;
1083 static LPWSTR
wildcard_to_file(LPCWSTR szWildCard
, LPCWSTR szFileName
)
1087 DWORD dwDirLen
, dwFullLen
;
1089 ptr
= StrRChrW(szWildCard
, NULL
, '\\');
1090 dwDirLen
= ptr
- szWildCard
+ 1;
1092 dwFullLen
= dwDirLen
+ lstrlenW(szFileName
) + 1;
1093 szFullPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwFullLen
* sizeof(WCHAR
));
1095 lstrcpynW(szFullPath
, szWildCard
, dwDirLen
+ 1);
1096 lstrcatW(szFullPath
, szFileName
);
1101 static void parse_wildcard_files(FILE_LIST
*flList
, LPCWSTR szFile
, LPDWORD pdwListIndex
)
1103 WIN32_FIND_DATAW wfd
;
1104 HANDLE hFile
= FindFirstFileW(szFile
, &wfd
);
1109 if (hFile
== INVALID_HANDLE_VALUE
) return;
1111 for (res
= TRUE
; res
; res
= FindNextFileW(hFile
, &wfd
))
1113 if (IsDotDir(wfd
.cFileName
))
1116 if (*pdwListIndex
>= flList
->num_alloc
)
1117 grow_list( flList
);
1119 szFullPath
= wildcard_to_file(szFile
, wfd
.cFileName
);
1120 file
= &flList
->feFiles
[(*pdwListIndex
)++];
1121 add_file_to_entry(file
, szFullPath
);
1122 file
->bFromWildcard
= TRUE
;
1123 file
->attributes
= wfd
.dwFileAttributes
;
1125 if (IsAttribDir(file
->attributes
))
1126 flList
->bAnyDirectories
= TRUE
;
1128 HeapFree(GetProcessHeap(), 0, szFullPath
);
1134 /* takes the null-separated file list and fills out the FILE_LIST */
1135 static HRESULT
parse_file_list(FILE_LIST
*flList
, LPCWSTR szFiles
)
1137 LPCWSTR ptr
= szFiles
;
1138 WCHAR szCurFile
[MAX_PATH
];
1142 return ERROR_INVALID_PARAMETER
;
1144 flList
->bAnyFromWildcard
= FALSE
;
1145 flList
->bAnyDirectories
= FALSE
;
1146 flList
->bAnyDontExist
= FALSE
;
1147 flList
->num_alloc
= 32;
1148 flList
->dwNumFiles
= 0;
1152 return ERROR_ACCESS_DENIED
;
1154 flList
->feFiles
= (FILE_ENTRY
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1155 flList
->num_alloc
* sizeof(FILE_ENTRY
));
1159 if (i
>= flList
->num_alloc
) grow_list( flList
);
1161 /* change relative to absolute path */
1162 if (PathIsRelativeW(ptr
))
1164 GetCurrentDirectoryW(MAX_PATH
, szCurFile
);
1165 PathCombineW(szCurFile
, szCurFile
, ptr
);
1166 flList
->feFiles
[i
].bFromRelative
= TRUE
;
1170 lstrcpyW(szCurFile
, ptr
);
1171 flList
->feFiles
[i
].bFromRelative
= FALSE
;
1174 /* parse wildcard files if they are in the filename */
1175 if (StrPBrkW(szCurFile
, wWildcardChars
))
1177 parse_wildcard_files(flList
, szCurFile
, &i
);
1178 flList
->bAnyFromWildcard
= TRUE
;
1183 FILE_ENTRY
*file
= &flList
->feFiles
[i
];
1184 add_file_to_entry(file
, szCurFile
);
1185 file
->attributes
= GetFileAttributesW( file
->szFullPath
);
1186 file
->bExists
= (file
->attributes
!= INVALID_FILE_ATTRIBUTES
);
1189 flList
->bAnyDontExist
= TRUE
;
1191 if (IsAttribDir(file
->attributes
))
1192 flList
->bAnyDirectories
= TRUE
;
1195 /* advance to the next string */
1196 ptr
+= lstrlenW(ptr
) + 1;
1199 flList
->dwNumFiles
= i
;
1204 /* free the FILE_LIST */
1205 static void destroy_file_list(FILE_LIST
*flList
)
1209 if (!flList
|| !flList
->feFiles
)
1212 for (i
= 0; i
< flList
->dwNumFiles
; i
++)
1214 HeapFree(GetProcessHeap(), 0, flList
->feFiles
[i
].szDirectory
);
1215 HeapFree(GetProcessHeap(), 0, flList
->feFiles
[i
].szFilename
);
1216 HeapFree(GetProcessHeap(), 0, flList
->feFiles
[i
].szFullPath
);
1219 HeapFree(GetProcessHeap(), 0, flList
->feFiles
);
1222 static void copy_dir_to_dir(FILE_OPERATION
*op
, const FILE_ENTRY
*feFrom
, LPCWSTR szDestPath
)
1224 WCHAR szFrom
[MAX_PATH
], szTo
[MAX_PATH
];
1225 FILE_LIST flFromNew
, flToNew
;
1227 static const WCHAR wildCardFiles
[] = {'*','.','*',0};
1229 if (IsDotDir(feFrom
->szFilename
))
1232 if (PathFileExistsW(szDestPath
))
1233 PathCombineW(szTo
, szDestPath
, feFrom
->szFilename
);
1235 lstrcpyW(szTo
, szDestPath
);
1237 if (!(op
->req
->fFlags
& FOF_NOCONFIRMATION
) && PathFileExistsW(szTo
))
1239 if (!SHELL_ConfirmDialogW(op
->req
->hwnd
, ASK_OVERWRITE_FOLDER
, feFrom
->szFilename
, op
))
1241 /* Vista returns an ERROR_CANCELLED even if user pressed "No" */
1242 if (!op
->bManyItems
)
1243 op
->bCancelled
= TRUE
;
1248 szTo
[lstrlenW(szTo
) + 1] = '\0';
1249 SHNotifyCreateDirectoryW(szTo
, NULL
);
1251 PathCombineW(szFrom
, feFrom
->szFullPath
, wildCardFiles
);
1252 szFrom
[lstrlenW(szFrom
) + 1] = '\0';
1254 ZeroMemory(&flFromNew
, sizeof(FILE_LIST
));
1255 ZeroMemory(&flToNew
, sizeof(FILE_LIST
));
1256 parse_file_list(&flFromNew
, szFrom
);
1257 parse_file_list(&flToNew
, szTo
);
1259 copy_files(op
, FALSE
, &flFromNew
, &flToNew
);
1261 destroy_file_list(&flFromNew
);
1262 destroy_file_list(&flToNew
);
1265 static BOOL
copy_file_to_file(FILE_OPERATION
*op
, const WCHAR
*szFrom
, const WCHAR
*szTo
)
1267 if (!(op
->req
->fFlags
& FOF_NOCONFIRMATION
) && PathFileExistsW(szTo
))
1269 if (!SHELL_ConfirmDialogW(op
->req
->hwnd
, ASK_OVERWRITE_FILE
, PathFindFileNameW(szTo
), op
))
1273 return SHNotifyCopyFileW(op
, szFrom
, szTo
, FALSE
) == 0;
1276 /* copy a file or directory to another directory */
1277 static void copy_to_dir(FILE_OPERATION
*op
, const FILE_ENTRY
*feFrom
, const FILE_ENTRY
*feTo
)
1279 if (!PathFileExistsW(feTo
->szFullPath
))
1280 SHNotifyCreateDirectoryW(feTo
->szFullPath
, NULL
);
1282 if (IsAttribFile(feFrom
->attributes
))
1284 WCHAR szDestPath
[MAX_PATH
];
1286 PathCombineW(szDestPath
, feTo
->szFullPath
, feFrom
->szFilename
);
1287 copy_file_to_file(op
, feFrom
->szFullPath
, szDestPath
);
1289 else if (!(op
->req
->fFlags
& FOF_FILESONLY
&& feFrom
->bFromWildcard
))
1290 copy_dir_to_dir(op
, feFrom
, feTo
->szFullPath
);
1293 static void create_dest_dirs(LPCWSTR szDestDir
)
1295 WCHAR dir
[MAX_PATH
];
1296 LPCWSTR ptr
= StrChrW(szDestDir
, '\\');
1298 /* make sure all directories up to last one are created */
1299 while (ptr
&& (ptr
= StrChrW(ptr
+ 1, '\\')))
1301 lstrcpynW(dir
, szDestDir
, ptr
- szDestDir
+ 1);
1303 if (!PathFileExistsW(dir
))
1304 SHNotifyCreateDirectoryW(dir
, NULL
);
1307 /* create last directory */
1308 if (!PathFileExistsW(szDestDir
))
1309 SHNotifyCreateDirectoryW(szDestDir
, NULL
);
1312 /* the FO_COPY operation */
1313 static HRESULT
copy_files(FILE_OPERATION
*op
, BOOL multiDest
, const FILE_LIST
*flFrom
, FILE_LIST
*flTo
)
1316 const FILE_ENTRY
*entryToCopy
;
1317 const FILE_ENTRY
*fileDest
= &flTo
->feFiles
[0];
1319 if (flFrom
->bAnyDontExist
)
1320 return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND
;
1322 if (flTo
->dwNumFiles
== 0)
1324 /* If the destination is empty, SHFileOperation should use the current directory */
1325 WCHAR curdir
[MAX_PATH
+1];
1327 GetCurrentDirectoryW(MAX_PATH
, curdir
);
1328 curdir
[lstrlenW(curdir
)+1] = 0;
1330 destroy_file_list(flTo
);
1331 ZeroMemory(flTo
, sizeof(FILE_LIST
));
1332 parse_file_list(flTo
, curdir
);
1333 fileDest
= &flTo
->feFiles
[0];
1338 if (flFrom
->bAnyFromWildcard
)
1339 return ERROR_CANCELLED
;
1341 if (flFrom
->dwNumFiles
!= flTo
->dwNumFiles
)
1343 if (flFrom
->dwNumFiles
!= 1 && !IsAttribDir(fileDest
->attributes
))
1344 return ERROR_CANCELLED
;
1346 /* Free all but the first entry. */
1347 for (i
= 1; i
< flTo
->dwNumFiles
; i
++)
1349 HeapFree(GetProcessHeap(), 0, flTo
->feFiles
[i
].szDirectory
);
1350 HeapFree(GetProcessHeap(), 0, flTo
->feFiles
[i
].szFilename
);
1351 HeapFree(GetProcessHeap(), 0, flTo
->feFiles
[i
].szFullPath
);
1354 flTo
->dwNumFiles
= 1;
1356 else if (IsAttribDir(fileDest
->attributes
))
1358 for (i
= 1; i
< flTo
->dwNumFiles
; i
++)
1359 if (!IsAttribDir(flTo
->feFiles
[i
].attributes
) ||
1360 !IsAttribDir(flFrom
->feFiles
[i
].attributes
))
1362 return ERROR_CANCELLED
;
1366 else if (flFrom
->dwNumFiles
!= 1)
1368 if (flTo
->dwNumFiles
!= 1 && !IsAttribDir(fileDest
->attributes
))
1369 return ERROR_CANCELLED
;
1371 if (PathFileExistsW(fileDest
->szFullPath
) &&
1372 IsAttribFile(fileDest
->attributes
))
1374 return ERROR_CANCELLED
;
1377 if (flTo
->dwNumFiles
== 1 && fileDest
->bFromRelative
&&
1378 !PathFileExistsW(fileDest
->szFullPath
))
1380 return ERROR_CANCELLED
;
1384 for (i
= 0; i
< flFrom
->dwNumFiles
; i
++)
1386 entryToCopy
= &flFrom
->feFiles
[i
];
1389 flTo
->dwNumFiles
> 1)
1391 fileDest
= &flTo
->feFiles
[i
];
1394 if (IsAttribDir(entryToCopy
->attributes
) &&
1395 !lstrcmpiW(entryToCopy
->szFullPath
, fileDest
->szDirectory
))
1397 return ERROR_SUCCESS
;
1400 create_dest_dirs(fileDest
->szDirectory
);
1402 if (!lstrcmpiW(entryToCopy
->szFullPath
, fileDest
->szFullPath
))
1404 if (IsAttribFile(entryToCopy
->attributes
))
1405 return ERROR_NO_MORE_SEARCH_HANDLES
;
1407 return ERROR_SUCCESS
;
1410 if ((flFrom
->dwNumFiles
> 1 && flTo
->dwNumFiles
== 1) ||
1411 IsAttribDir(fileDest
->attributes
))
1413 copy_to_dir(op
, entryToCopy
, fileDest
);
1415 else if (IsAttribDir(entryToCopy
->attributes
))
1417 copy_dir_to_dir(op
, entryToCopy
, fileDest
->szFullPath
);
1421 if (!copy_file_to_file(op
, entryToCopy
->szFullPath
, fileDest
->szFullPath
))
1423 op
->req
->fAnyOperationsAborted
= TRUE
;
1424 return ERROR_CANCELLED
;
1428 if (op
->progress
!= NULL
)
1429 op
->bCancelled
|= op
->progress
->HasUserCancelled();
1430 /* Vista return code. XP would return e.g. ERROR_FILE_NOT_FOUND, ERROR_ALREADY_EXISTS */
1432 return ERROR_CANCELLED
;
1435 /* Vista return code. On XP if the used pressed "No" for the last item,
1436 * ERROR_ARENA_TRASHED would be returned */
1437 return ERROR_SUCCESS
;
1440 static BOOL
confirm_delete_list(HWND hWnd
, DWORD fFlags
, BOOL fTrash
, const FILE_LIST
*flFrom
)
1442 if (flFrom
->dwNumFiles
> 1)
1445 const WCHAR format
[] = {'%','d',0};
1447 wnsprintfW(tmp
, sizeof(tmp
)/sizeof(tmp
[0]), format
, flFrom
->dwNumFiles
);
1448 return SHELL_ConfirmDialogW(hWnd
, (fTrash
?ASK_TRASH_MULTIPLE_ITEM
:ASK_DELETE_MULTIPLE_ITEM
), tmp
, NULL
);
1452 const FILE_ENTRY
*fileEntry
= &flFrom
->feFiles
[0];
1454 if (IsAttribFile(fileEntry
->attributes
))
1455 return SHELL_ConfirmDialogW(hWnd
, (fTrash
?ASK_TRASH_FILE
:ASK_DELETE_FILE
), fileEntry
->szFullPath
, NULL
);
1456 else if (!(fFlags
& FOF_FILESONLY
&& fileEntry
->bFromWildcard
))
1457 return SHELL_ConfirmDialogW(hWnd
, (fTrash
?ASK_TRASH_FOLDER
:ASK_DELETE_FOLDER
), fileEntry
->szFullPath
, NULL
);
1462 /* the FO_DELETE operation */
1463 static HRESULT
delete_files(FILE_OPERATION
*op
, const FILE_LIST
*flFrom
)
1465 const FILE_ENTRY
*fileEntry
;
1470 if (!flFrom
->dwNumFiles
)
1471 return ERROR_SUCCESS
;
1473 /* Windows also checks only the first item */
1474 bTrash
= (op
->req
->fFlags
& FOF_ALLOWUNDO
)
1475 && TRASH_CanTrashFile(flFrom
->feFiles
[0].szFullPath
);
1477 if (!(op
->req
->fFlags
& FOF_NOCONFIRMATION
) || (!bTrash
&& op
->req
->fFlags
& FOF_WANTNUKEWARNING
))
1478 if (!confirm_delete_list(op
->req
->hwnd
, op
->req
->fFlags
, bTrash
, flFrom
))
1480 op
->req
->fAnyOperationsAborted
= TRUE
;
1484 /* Check files. Do not delete one if one file does not exists */
1485 for (i
= 0; i
< flFrom
->dwNumFiles
; i
++)
1487 fileEntry
= &flFrom
->feFiles
[i
];
1489 if ((HANDLE
)fileEntry
->attributes
== INVALID_HANDLE_VALUE
)
1491 // This is a windows 2003 server specific value which has been removed.
1492 // Later versions of windows return ERROR_FILE_NOT_FOUND.
1493 return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND
;
1497 for (i
= 0; i
< flFrom
->dwNumFiles
; i
++)
1500 fileEntry
= &flFrom
->feFiles
[i
];
1502 if (!IsAttribFile(fileEntry
->attributes
) &&
1503 (op
->req
->fFlags
& FOF_FILESONLY
&& fileEntry
->bFromWildcard
))
1509 if (TRASH_TrashFile(fileEntry
->szFullPath
))
1511 SHChangeNotify(SHCNE_DELETE
, SHCNF_PATHW
, fileEntry
->szFullPath
, NULL
);
1515 /* Note: Windows silently deletes the file in such a situation, we show a dialog */
1516 if (!(op
->req
->fFlags
& FOF_NOCONFIRMATION
) || (op
->req
->fFlags
& FOF_WANTNUKEWARNING
))
1517 bDelete
= SHELL_ConfirmDialogW(op
->req
->hwnd
, ASK_CANT_TRASH_ITEM
, fileEntry
->szFullPath
, NULL
);
1523 op
->req
->fAnyOperationsAborted
= TRUE
;
1528 /* delete the file or directory */
1529 if (IsAttribFile(fileEntry
->attributes
))
1531 bPathExists
= (ERROR_SUCCESS
== SHNotifyDeleteFileW(op
, fileEntry
->szFullPath
));
1534 bPathExists
= SHELL_DeleteDirectoryW(op
, fileEntry
->szFullPath
, FALSE
);
1538 DWORD err
= GetLastError();
1540 if (ERROR_FILE_NOT_FOUND
== err
)
1542 // This is a windows 2003 server specific value which ahs been removed.
1543 // Later versions of windows return ERROR_FILE_NOT_FOUND.
1544 return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND
;
1552 if (op
->progress
!= NULL
)
1553 op
->bCancelled
|= op
->progress
->HasUserCancelled();
1554 /* Should fire on progress dialog only */
1556 return ERROR_CANCELLED
;
1559 return ERROR_SUCCESS
;
1562 static void move_dir_to_dir(FILE_OPERATION
*op
, const FILE_ENTRY
*feFrom
, LPCWSTR szDestPath
)
1564 WCHAR szFrom
[MAX_PATH
], szTo
[MAX_PATH
];
1565 FILE_LIST flFromNew
, flToNew
;
1567 static const WCHAR wildCardFiles
[] = {'*','.','*',0};
1569 if (IsDotDir(feFrom
->szFilename
))
1572 SHNotifyCreateDirectoryW(szDestPath
, NULL
);
1574 PathCombineW(szFrom
, feFrom
->szFullPath
, wildCardFiles
);
1575 szFrom
[lstrlenW(szFrom
) + 1] = '\0';
1577 lstrcpyW(szTo
, szDestPath
);
1578 szTo
[lstrlenW(szDestPath
) + 1] = '\0';
1580 ZeroMemory(&flFromNew
, sizeof(FILE_LIST
));
1581 ZeroMemory(&flToNew
, sizeof(FILE_LIST
));
1582 parse_file_list(&flFromNew
, szFrom
);
1583 parse_file_list(&flToNew
, szTo
);
1585 move_files(op
, FALSE
, &flFromNew
, &flToNew
);
1587 destroy_file_list(&flFromNew
);
1588 destroy_file_list(&flToNew
);
1591 /* moves a file or directory to another directory */
1592 static void move_to_dir(FILE_OPERATION
*op
, const FILE_ENTRY
*feFrom
, const FILE_ENTRY
*feTo
)
1594 WCHAR szDestPath
[MAX_PATH
];
1596 PathCombineW(szDestPath
, feTo
->szFullPath
, feFrom
->szFilename
);
1598 if (IsAttribFile(feFrom
->attributes
))
1599 SHNotifyMoveFileW(op
, feFrom
->szFullPath
, szDestPath
, FALSE
);
1600 else if (!(op
->req
->fFlags
& FOF_FILESONLY
&& feFrom
->bFromWildcard
))
1601 move_dir_to_dir(op
, feFrom
, szDestPath
);
1604 /* the FO_MOVE operation */
1605 static DWORD
move_files(FILE_OPERATION
*op
, BOOL multiDest
, const FILE_LIST
*flFrom
, const FILE_LIST
*flTo
)
1610 const FILE_ENTRY
*entryToMove
;
1611 const FILE_ENTRY
*fileDest
;
1613 if (!flFrom
->dwNumFiles
)
1614 return ERROR_SUCCESS
;
1616 if (!flTo
->dwNumFiles
)
1617 return ERROR_FILE_NOT_FOUND
;
1620 flTo
->dwNumFiles
> 1 && flFrom
->dwNumFiles
> 1)
1622 return ERROR_CANCELLED
;
1626 !flFrom
->bAnyDirectories
&&
1627 flFrom
->dwNumFiles
> flTo
->dwNumFiles
)
1629 return ERROR_CANCELLED
;
1632 if (!PathFileExistsW(flTo
->feFiles
[0].szDirectory
))
1633 return ERROR_CANCELLED
;
1636 mismatched
= flFrom
->dwNumFiles
- flTo
->dwNumFiles
;
1638 fileDest
= &flTo
->feFiles
[0];
1639 for (i
= 0; i
< flFrom
->dwNumFiles
; i
++)
1641 entryToMove
= &flFrom
->feFiles
[i
];
1643 if (!PathFileExistsW(fileDest
->szDirectory
))
1644 return ERROR_CANCELLED
;
1648 if (i
>= flTo
->dwNumFiles
)
1650 fileDest
= &flTo
->feFiles
[i
];
1651 if (mismatched
&& !fileDest
->bExists
)
1653 create_dest_dirs(flTo
->feFiles
[i
].szFullPath
);
1654 flTo
->feFiles
[i
].bExists
= TRUE
;
1655 flTo
->feFiles
[i
].attributes
= FILE_ATTRIBUTE_DIRECTORY
;
1659 if (fileDest
->bExists
&& IsAttribDir(fileDest
->attributes
))
1660 move_to_dir(op
, entryToMove
, fileDest
);
1662 SHNotifyMoveFileW(op
, entryToMove
->szFullPath
, fileDest
->szFullPath
, IsAttribDir(entryToMove
->attributes
));
1664 if (op
->progress
!= NULL
)
1665 op
->bCancelled
|= op
->progress
->HasUserCancelled();
1666 /* Should fire on progress dialog only */
1668 return ERROR_CANCELLED
;
1674 if (flFrom
->bAnyDirectories
)
1675 return DE_DESTSAMETREE
;
1680 return ERROR_SUCCESS
;
1683 /* the FO_RENAME files */
1684 static HRESULT
rename_files(FILE_OPERATION
*op
, const FILE_LIST
*flFrom
, const FILE_LIST
*flTo
)
1686 const FILE_ENTRY
*feFrom
;
1687 const FILE_ENTRY
*feTo
;
1689 if (flFrom
->dwNumFiles
!= 1)
1690 return ERROR_GEN_FAILURE
;
1692 if (flTo
->dwNumFiles
!= 1)
1693 return ERROR_CANCELLED
;
1695 feFrom
= &flFrom
->feFiles
[0];
1696 feTo
= &flTo
->feFiles
[0];
1698 /* fail if destination doesn't exist */
1699 if (!feFrom
->bExists
)
1700 return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND
;
1702 /* fail if destination already exists */
1704 return ERROR_ALREADY_EXISTS
;
1706 return SHNotifyMoveFileW(op
, feFrom
->szFullPath
, feTo
->szFullPath
, IsAttribDir(feFrom
->attributes
));
1709 /* alert the user if an unsupported flag is used */
1710 static void check_flags(FILEOP_FLAGS fFlags
)
1712 WORD wUnsupportedFlags
= FOF_NO_CONNECTED_ELEMENTS
|
1713 FOF_NOCOPYSECURITYATTRIBS
| FOF_NORECURSEREPARSE
|
1714 FOF_RENAMEONCOLLISION
| FOF_WANTMAPPINGHANDLE
;
1716 if (fFlags
& wUnsupportedFlags
)
1717 FIXME("Unsupported flags: %04x\n", fFlags
);
1720 /*************************************************************************
1721 * SHFileOperationW [SHELL32.@]
1723 * See SHFileOperationA
1725 int WINAPI
SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp
)
1728 FILE_LIST flFrom
, flTo
;
1732 return ERROR_INVALID_PARAMETER
;
1734 ret
= CoInitialize(NULL
);
1738 check_flags(lpFileOp
->fFlags
);
1740 ZeroMemory(&flFrom
, sizeof(FILE_LIST
));
1741 ZeroMemory(&flTo
, sizeof(FILE_LIST
));
1743 if ((ret
= parse_file_list(&flFrom
, lpFileOp
->pFrom
)))
1746 if (lpFileOp
->wFunc
!= FO_DELETE
)
1747 parse_file_list(&flTo
, lpFileOp
->pTo
);
1749 ZeroMemory(&op
, sizeof(op
));
1751 op
.totalSize
.QuadPart
= 0ull;
1752 op
.completedSize
.QuadPart
= 0ull;
1753 op
.bManyItems
= (flFrom
.dwNumFiles
> 1);
1755 if (lpFileOp
->wFunc
!= FO_RENAME
&& !(lpFileOp
->fFlags
& FOF_SILENT
)) {
1756 ret
= CoCreateInstance(CLSID_ProgressDialog
,
1758 CLSCTX_INPROC_SERVER
,
1759 IID_PPV_ARG(IProgressDialog
, &op
.progress
));
1763 op
.progress
->StartProgressDialog(op
.req
->hwnd
, NULL
, PROGDLG_NORMAL
& PROGDLG_AUTOTIME
, NULL
);
1764 _SetOperationTitle(&op
);
1765 _FileOpCountManager(&op
, &flFrom
);
1768 switch (lpFileOp
->wFunc
)
1771 ret
= copy_files(&op
, op
.req
->fFlags
& FOF_MULTIDESTFILES
, &flFrom
, &flTo
);
1774 ret
= delete_files(&op
, &flFrom
);
1777 ret
= move_files(&op
, op
.req
->fFlags
& FOF_MULTIDESTFILES
, &flFrom
, &flTo
);
1780 ret
= rename_files(&op
, &flFrom
, &flTo
);
1783 ret
= ERROR_INVALID_PARAMETER
;
1788 op
.progress
->StopProgressDialog();
1789 op
.progress
->Release();
1793 destroy_file_list(&flFrom
);
1795 if (lpFileOp
->wFunc
!= FO_DELETE
)
1796 destroy_file_list(&flTo
);
1798 if (ret
== ERROR_CANCELLED
)
1799 lpFileOp
->fAnyOperationsAborted
= TRUE
;
1806 // Used by SHFreeNameMappings
1807 static int CALLBACK
_DestroyCallback(void *p
, void *pData
)
1809 LPSHNAMEMAPPINGW lp
= (SHNAMEMAPPINGW
*)p
;
1811 SHFree(lp
->pszOldPath
);
1812 SHFree(lp
->pszNewPath
);
1817 /*************************************************************************
1818 * SHFreeNameMappings [shell32.246]
1820 * Free the mapping handle returned by SHFileOperation if FOF_WANTSMAPPINGHANDLE
1824 * hNameMapping [I] handle to the name mappings used during renaming of files
1829 void WINAPI
SHFreeNameMappings(HANDLE hNameMapping
)
1833 DSA_DestroyCallback((HDSA
) hNameMapping
, _DestroyCallback
, NULL
);
1837 /*************************************************************************
1838 * SheGetDirA [SHELL32.@]
1840 * drive = 0: returns the current directory path
1841 * drive > 0: returns the current directory path of the specified drive
1842 * drive=1 -> A: drive=2 -> B: ...
1843 * returns 0 if successful
1845 EXTERN_C DWORD WINAPI
SheGetDirA(DWORD drive
, LPSTR buffer
)
1847 WCHAR org_path
[MAX_PATH
];
1851 /* change current directory to the specified drive */
1853 strcpy(drv_path
, "A:");
1854 drv_path
[0] += (char)drive
-1;
1856 GetCurrentDirectoryW(MAX_PATH
, org_path
);
1858 SetCurrentDirectoryA(drv_path
);
1861 /* query current directory path of the specified drive */
1862 ret
= GetCurrentDirectoryA(MAX_PATH
, buffer
);
1864 /* back to the original drive */
1866 SetCurrentDirectoryW(org_path
);
1869 return GetLastError();
1874 /*************************************************************************
1875 * SheGetDirW [SHELL32.@]
1877 * drive = 0: returns the current directory path
1878 * drive > 0: returns the current directory path of the specified drive
1879 * drive=1 -> A: drive=2 -> B: ...
1880 * returns 0 if successful
1882 EXTERN_C DWORD WINAPI
SheGetDirW(DWORD drive
, LPWSTR buffer
)
1884 WCHAR org_path
[MAX_PATH
];
1888 /* change current directory to the specified drive */
1891 strcpy(drv_path
, "A:");
1892 drv_path
[0] += (char)drive
-1;
1894 GetCurrentDirectoryW(MAX_PATH
, org_path
);
1896 SetCurrentDirectoryA(drv_path
);
1899 /* query current directory path of the specified drive */
1900 ret
= GetCurrentDirectoryW(MAX_PATH
, buffer
);
1902 /* back to the original drive */
1904 SetCurrentDirectoryW(org_path
);
1907 return GetLastError();
1912 /*************************************************************************
1913 * SheChangeDirA [SHELL32.@]
1915 * changes the current directory to the specified path
1916 * and returns 0 if successful
1918 EXTERN_C DWORD WINAPI
SheChangeDirA(LPSTR path
)
1920 if (SetCurrentDirectoryA(path
))
1923 return GetLastError();
1926 /*************************************************************************
1927 * SheChangeDirW [SHELL32.@]
1929 * changes the current directory to the specified path
1930 * and returns 0 if successful
1932 EXTERN_C DWORD WINAPI
SheChangeDirW(LPWSTR path
)
1934 if (SetCurrentDirectoryW(path
))
1937 return GetLastError();
1940 /*************************************************************************
1941 * IsNetDrive [SHELL32.66]
1943 EXTERN_C
int WINAPI
IsNetDrive(int drive
)
1946 strcpy(root
, "A:\\");
1947 root
[0] += (char)drive
;
1948 return (GetDriveTypeA(root
) == DRIVE_REMOTE
);
1952 /*************************************************************************
1953 * RealDriveType [SHELL32.524]
1955 EXTERN_C INT WINAPI
RealDriveType(INT drive
, BOOL bQueryNet
)
1957 char root
[] = "A:\\";
1958 root
[0] += (char)drive
;
1959 return GetDriveTypeA(root
);
1962 /***********************************************************************
1963 * SHPathPrepareForWriteW (SHELL32.@)
1965 EXTERN_C HRESULT WINAPI
SHPathPrepareForWriteW(HWND hwnd
, IUnknown
*modless
, LPCWSTR path
, DWORD flags
)
1972 WCHAR
* temppath
=NULL
;
1974 TRACE("%p %p %s 0x%08x\n", hwnd
, modless
, debugstr_w(path
), flags
);
1976 if (flags
& ~(SHPPFW_DIRCREATE
|SHPPFW_ASKDIRCREATE
|SHPPFW_IGNOREFILENAME
))
1977 FIXME("unimplemented flags 0x%08x\n", flags
);
1979 /* cut off filename if necessary */
1980 if (flags
& SHPPFW_IGNOREFILENAME
)
1982 last_slash
= StrRChrW(path
, NULL
, '\\');
1983 if (last_slash
== NULL
)
1986 len
= last_slash
- path
+ 1;
1987 temppath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1989 return E_OUTOFMEMORY
;
1990 StrCpyNW(temppath
, path
, len
);
1991 realpath
= temppath
;
1998 /* try to create the directory if asked to */
1999 if (flags
& (SHPPFW_DIRCREATE
|SHPPFW_ASKDIRCREATE
))
2001 if (flags
& SHPPFW_ASKDIRCREATE
)
2002 FIXME("treating SHPPFW_ASKDIRCREATE as SHPPFW_DIRCREATE\n");
2004 SHCreateDirectoryExW(0, realpath
, NULL
);
2007 /* check if we can access the directory */
2008 res
= GetFileAttributesW(realpath
);
2010 HeapFree(GetProcessHeap(), 0, temppath
);
2012 if (res
== INVALID_FILE_ATTRIBUTES
)
2014 err
= GetLastError();
2015 if (err
== ERROR_FILE_NOT_FOUND
)
2016 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
2017 return HRESULT_FROM_WIN32(err
);
2019 else if (res
& FILE_ATTRIBUTE_DIRECTORY
)
2022 return HRESULT_FROM_WIN32(ERROR_DIRECTORY
);
2025 /***********************************************************************
2026 * SHPathPrepareForWriteA (SHELL32.@)
2028 EXTERN_C HRESULT WINAPI
SHPathPrepareForWriteA(HWND hwnd
, IUnknown
*modless
, LPCSTR path
, DWORD flags
)
2030 WCHAR wpath
[MAX_PATH
];
2031 MultiByteToWideChar( CP_ACP
, 0, path
, -1, wpath
, MAX_PATH
);
2032 return SHPathPrepareForWriteW(hwnd
, modless
, wpath
, flags
);
2037 * The two following background operations were modified from filedefext.cpp
2038 * They use an inordinate amount of mutable state across the string functions,
2039 * so are not easy to follow and care is required when modifying.
2043 _FileOpCountManager(FILE_OPERATION
*op
, const FILE_LIST
*from
)
2045 DWORD ticks
= GetTickCount();
2046 FILE_ENTRY
*entryToCount
;
2048 for (UINT i
= 0; i
< from
->dwNumFiles
; i
++)
2050 entryToCount
= &from
->feFiles
[i
];
2052 WCHAR theFileName
[MAX_PATH
];
2053 StringCchCopyW(theFileName
, MAX_PATH
, entryToCount
->szFullPath
);
2054 _FileOpCount(op
, theFileName
, IsAttribDir(entryToCount
->attributes
), &ticks
);
2059 // All path manipulations, even when this function is nested, occur on the one buffer.
2061 _FileOpCount(FILE_OPERATION
*op
, LPWSTR pwszBuf
, BOOL bFolder
, DWORD
*ticks
)
2063 /* Find filename position */
2064 UINT cchBuf
= wcslen(pwszBuf
);
2065 WCHAR
*pwszFilename
= pwszBuf
+ cchBuf
;
2066 size_t cchFilenameMax
= MAX_PATH
- cchBuf
;
2067 if (!cchFilenameMax
)
2071 *(pwszFilename
++) = '\\';
2073 /* Find all files, FIXME: shouldn't be "*"? */
2074 StringCchCopyW(pwszFilename
, cchFilenameMax
, L
"*");
2077 WIN32_FIND_DATAW wfd
;
2078 HANDLE hFind
= FindFirstFileW(pwszBuf
, &wfd
);
2079 if (hFind
== INVALID_HANDLE_VALUE
)
2081 ERR("FindFirstFileW %ls failed\n", pwszBuf
);
2087 if (wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
2089 /* Don't process "." and ".." items */
2090 if (!wcscmp(wfd
.cFileName
, L
".") || !wcscmp(wfd
.cFileName
, L
".."))
2093 StringCchCopyW(pwszFilename
, cchFilenameMax
, wfd
.cFileName
);
2094 _FileOpCount(op
, pwszBuf
, TRUE
, ticks
);
2098 ULARGE_INTEGER FileSize
;
2099 FileSize
.u
.LowPart
= wfd
.nFileSizeLow
;
2100 FileSize
.u
.HighPart
= wfd
.nFileSizeHigh
;
2101 op
->totalSize
.QuadPart
+= FileSize
.QuadPart
;
2103 if (GetTickCount() - *ticks
> (DWORD
) 500)
2105 // Check if the dialog has ended. If it has, we'll spin down.
2106 if (op
->progress
!= NULL
)
2107 op
->bCancelled
= op
->progress
->HasUserCancelled();
2111 *ticks
= GetTickCount();
2113 } while(FindNextFileW(hFind
, &wfd
));