2011-05-15 15:55:49 +00:00
|
|
|
/*
|
|
|
|
* SHFileOperation
|
|
|
|
*
|
|
|
|
* Copyright 2000 Juergen Schmied
|
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
|
|
|
* Copyright 2004 Dietrich Teickner (from Odin)
|
|
|
|
* Copyright 2004 Rolf Kalbermatter
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "precomp.h"
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
|
|
|
|
|
|
|
#define IsAttrib(x, y) ((INVALID_FILE_ATTRIBUTES != (x)) && ((x) & (y)))
|
|
|
|
#define IsAttribFile(x) (!((x) & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
#define IsAttribDir(x) IsAttrib(x, FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
#define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
|
|
|
|
|
|
|
|
#define FO_MASK 0xF
|
|
|
|
|
|
|
|
static const WCHAR wWildcardFile[] = {'*',0};
|
|
|
|
static const WCHAR wWildcardChars[] = {'*','?',0};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
SHFILEOPSTRUCTW *req;
|
|
|
|
DWORD dwYesToAllMask;
|
|
|
|
BOOL bManyItems;
|
|
|
|
BOOL bCancelled;
|
2015-02-21 12:52:58 +00:00
|
|
|
IProgressDialog *progress;
|
|
|
|
ULARGE_INTEGER completedSize;
|
|
|
|
ULARGE_INTEGER totalSize;
|
|
|
|
WCHAR szBuilderString[50];
|
2011-05-15 15:55:49 +00:00
|
|
|
} FILE_OPERATION;
|
|
|
|
|
|
|
|
#define ERROR_SHELL_INTERNAL_FILE_NOT_FOUND 1026
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DWORD attributes;
|
|
|
|
LPWSTR szDirectory;
|
|
|
|
LPWSTR szFilename;
|
|
|
|
LPWSTR szFullPath;
|
|
|
|
BOOL bFromWildcard;
|
|
|
|
BOOL bFromRelative;
|
|
|
|
BOOL bExists;
|
|
|
|
} FILE_ENTRY;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
FILE_ENTRY *feFiles;
|
|
|
|
DWORD num_alloc;
|
|
|
|
DWORD dwNumFiles;
|
|
|
|
BOOL bAnyFromWildcard;
|
|
|
|
BOOL bAnyDirectories;
|
|
|
|
BOOL bAnyDontExist;
|
|
|
|
} FILE_LIST;
|
|
|
|
|
2015-02-21 12:59:42 +00:00
|
|
|
static DWORD SHNotifyCreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sec);
|
|
|
|
static DWORD SHNotifyRemoveDirectoryW(LPCWSTR path);
|
|
|
|
static DWORD SHNotifyDeleteFileW(FILE_OPERATION *op, LPCWSTR path);
|
|
|
|
static DWORD SHNotifyMoveFileW(FILE_OPERATION *op, LPCWSTR src, LPCWSTR dest, BOOL isdir);
|
|
|
|
static DWORD SHNotifyCopyFileW(FILE_OPERATION *op, LPCWSTR src, LPCWSTR dest, BOOL bFailIfExists);
|
|
|
|
static DWORD SHFindAttrW(LPCWSTR pName, BOOL fileOnly);
|
|
|
|
static HRESULT copy_files(FILE_OPERATION *op, BOOL multiDest, const FILE_LIST *flFrom, FILE_LIST *flTo);
|
|
|
|
static DWORD move_files(FILE_OPERATION *op, BOOL multiDest, const FILE_LIST *flFrom, const FILE_LIST *flTo);
|
|
|
|
|
|
|
|
DWORD WINAPI _FileOpCountManager(FILE_OPERATION *op, const FILE_LIST *flFrom);
|
|
|
|
static BOOL _FileOpCount(FILE_OPERATION *op, LPWSTR pwszBuf, BOOL bFolder, DWORD *ticks);
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/* Confirm dialogs with an optional "Yes To All" as used in file operations confirmations
|
|
|
|
*/
|
|
|
|
static const WCHAR CONFIRM_MSG_PROP[] = {'W','I','N','E','_','C','O','N','F','I','R','M',0};
|
|
|
|
|
|
|
|
struct confirm_msg_info
|
|
|
|
{
|
|
|
|
LPWSTR lpszText;
|
|
|
|
LPWSTR lpszCaption;
|
|
|
|
HICON hIcon;
|
|
|
|
BOOL bYesToAll;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* as some buttons may be hidden and the dialog height may change we may need
|
|
|
|
* to move the controls */
|
|
|
|
static void confirm_msg_move_button(HWND hDlg, INT iId, INT *xPos, INT yOffset, BOOL bShow)
|
|
|
|
{
|
|
|
|
HWND hButton = GetDlgItem(hDlg, iId);
|
|
|
|
RECT r;
|
|
|
|
|
2011-09-03 00:08:11 +00:00
|
|
|
if (bShow)
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
POINT pt;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
GetWindowRect(hButton, &r);
|
|
|
|
width = r.right - r.left;
|
|
|
|
pt.x = r.left;
|
|
|
|
pt.y = r.top;
|
|
|
|
ScreenToClient(hDlg, &pt);
|
|
|
|
MoveWindow(hButton, *xPos - width, pt.y - yOffset, width, r.bottom - r.top, FALSE);
|
|
|
|
*xPos -= width + 5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ShowWindow(hButton, SW_HIDE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: we paint the text manually and don't use the static control to make
|
|
|
|
* sure the text has the same height as the one computed in WM_INITDIALOG
|
|
|
|
*/
|
|
|
|
static INT_PTR ConfirmMsgBox_Paint(HWND hDlg)
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HFONT hOldFont;
|
|
|
|
RECT r;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
BeginPaint(hDlg, &ps);
|
|
|
|
hdc = ps.hdc;
|
2017-09-06 05:33:35 +00:00
|
|
|
SetBkMode(hdc, TRANSPARENT);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2012-01-17 21:28:17 +00:00
|
|
|
GetClientRect(GetDlgItem(hDlg, IDC_YESTOALL_MESSAGE), &r);
|
2011-05-15 15:55:49 +00:00
|
|
|
/* this will remap the rect to dialog coords */
|
2012-01-17 21:28:17 +00:00
|
|
|
MapWindowPoints(GetDlgItem(hDlg, IDC_YESTOALL_MESSAGE), hDlg, (LPPOINT)&r, 2);
|
|
|
|
hOldFont = (HFONT)SelectObject(hdc, (HFONT)SendDlgItemMessageW(hDlg, IDC_YESTOALL_MESSAGE, WM_GETFONT, 0, 0));
|
2011-05-15 15:55:49 +00:00
|
|
|
DrawTextW(hdc, (LPWSTR)GetPropW(hDlg, CONFIRM_MSG_PROP), -1, &r, DT_NOPREFIX | DT_PATH_ELLIPSIS | DT_WORDBREAK);
|
|
|
|
SelectObject(hdc, hOldFont);
|
|
|
|
EndPaint(hDlg, &ps);
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
return TRUE;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR ConfirmMsgBox_Init(HWND hDlg, LPARAM lParam)
|
|
|
|
{
|
|
|
|
struct confirm_msg_info *info = (struct confirm_msg_info *)lParam;
|
|
|
|
INT xPos, yOffset;
|
|
|
|
int width, height;
|
|
|
|
HFONT hOldFont;
|
|
|
|
HDC hdc;
|
|
|
|
RECT r;
|
|
|
|
|
|
|
|
SetWindowTextW(hDlg, info->lpszCaption);
|
2012-01-17 21:28:17 +00:00
|
|
|
ShowWindow(GetDlgItem(hDlg, IDC_YESTOALL_MESSAGE), SW_HIDE);
|
2011-05-15 15:55:49 +00:00
|
|
|
SetPropW(hDlg, CONFIRM_MSG_PROP, info->lpszText);
|
2012-01-17 21:28:17 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_YESTOALL_ICON, STM_SETICON, (WPARAM)info->hIcon, 0);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/* compute the text height and resize the dialog */
|
2012-01-17 21:28:17 +00:00
|
|
|
GetClientRect(GetDlgItem(hDlg, IDC_YESTOALL_MESSAGE), &r);
|
2011-05-15 15:55:49 +00:00
|
|
|
hdc = GetDC(hDlg);
|
|
|
|
yOffset = r.bottom;
|
2012-01-17 21:28:17 +00:00
|
|
|
hOldFont = (HFONT)SelectObject(hdc, (HFONT)SendDlgItemMessageW(hDlg, IDC_YESTOALL_MESSAGE, WM_GETFONT, 0, 0));
|
2011-05-15 15:55:49 +00:00
|
|
|
DrawTextW(hdc, info->lpszText, -1, &r, DT_NOPREFIX | DT_PATH_ELLIPSIS | DT_WORDBREAK | DT_CALCRECT);
|
|
|
|
SelectObject(hdc, hOldFont);
|
|
|
|
yOffset -= r.bottom;
|
|
|
|
yOffset = min(yOffset, 35); /* don't make the dialog too small */
|
|
|
|
ReleaseDC(hDlg, hdc);
|
|
|
|
|
|
|
|
GetClientRect(hDlg, &r);
|
|
|
|
xPos = r.right - 7;
|
|
|
|
GetWindowRect(hDlg, &r);
|
|
|
|
width = r.right - r.left;
|
|
|
|
height = r.bottom - r.top - yOffset;
|
|
|
|
MoveWindow(hDlg, (GetSystemMetrics(SM_CXSCREEN) - width)/2,
|
|
|
|
(GetSystemMetrics(SM_CYSCREEN) - height)/2, width, height, FALSE);
|
|
|
|
|
|
|
|
confirm_msg_move_button(hDlg, IDCANCEL, &xPos, yOffset, info->bYesToAll);
|
|
|
|
confirm_msg_move_button(hDlg, IDNO, &xPos, yOffset, TRUE);
|
2012-01-17 21:28:17 +00:00
|
|
|
confirm_msg_move_button(hDlg, IDC_YESTOALL, &xPos, yOffset, info->bYesToAll);
|
2011-05-15 15:55:49 +00:00
|
|
|
confirm_msg_move_button(hDlg, IDYES, &xPos, yOffset, TRUE);
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK ConfirmMsgBoxProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
return ConfirmMsgBox_Init(hDlg, lParam);
|
|
|
|
case WM_PAINT:
|
|
|
|
return ConfirmMsgBox_Paint(hDlg);
|
|
|
|
case WM_COMMAND:
|
|
|
|
EndDialog(hDlg, wParam);
|
|
|
|
break;
|
|
|
|
case WM_CLOSE:
|
|
|
|
EndDialog(hDlg, IDCANCEL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SHELL_ConfirmMsgBox(HWND hWnd, LPWSTR lpszText, LPWSTR lpszCaption, HICON hIcon, BOOL bYesToAll)
|
|
|
|
{
|
|
|
|
struct confirm_msg_info info;
|
|
|
|
|
|
|
|
info.lpszText = lpszText;
|
|
|
|
info.lpszCaption = lpszCaption;
|
|
|
|
info.hIcon = hIcon;
|
|
|
|
info.bYesToAll = bYesToAll;
|
2012-01-17 21:28:17 +00:00
|
|
|
return DialogBoxParamW(shell32_hInstance, MAKEINTRESOURCEW(IDD_YESTOALL_MSGBOX), hWnd, ConfirmMsgBoxProc, (LPARAM)&info);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* confirmation dialogs content */
|
|
|
|
typedef struct
|
|
|
|
{
|
2011-09-03 00:08:11 +00:00
|
|
|
HINSTANCE hIconInstance;
|
|
|
|
UINT icon_resource_id;
|
2011-09-03 00:13:22 +00:00
|
|
|
UINT caption_resource_id, text_resource_id;
|
2011-05-15 15:55:49 +00:00
|
|
|
} SHELL_ConfirmIDstruc;
|
|
|
|
|
|
|
|
static BOOL SHELL_ConfirmIDs(int nKindOfDialog, SHELL_ConfirmIDstruc *ids)
|
|
|
|
{
|
2011-09-03 00:08:11 +00:00
|
|
|
ids->hIconInstance = shell32_hInstance;
|
2011-09-03 00:13:22 +00:00
|
|
|
switch (nKindOfDialog)
|
2011-09-03 00:08:11 +00:00
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
case ASK_DELETE_FILE:
|
|
|
|
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
|
|
|
|
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_DELETEITEM_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case ASK_DELETE_FOLDER:
|
|
|
|
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
|
|
|
|
ids->caption_resource_id = IDS_DELETEFOLDER_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_DELETEITEM_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case ASK_DELETE_MULTIPLE_ITEM:
|
|
|
|
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
|
|
|
|
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_DELETEMULTIPLE_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case ASK_TRASH_FILE:
|
|
|
|
ids->icon_resource_id = IDI_SHELL_TRASH_FILE;
|
|
|
|
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_TRASHITEM_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case ASK_TRASH_FOLDER:
|
|
|
|
ids->icon_resource_id = IDI_SHELL_TRASH_FILE;
|
|
|
|
ids->caption_resource_id = IDS_DELETEFOLDER_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_TRASHFOLDER_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case ASK_TRASH_MULTIPLE_ITEM:
|
|
|
|
ids->icon_resource_id = IDI_SHELL_TRASH_FILE;
|
|
|
|
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_TRASHMULTIPLE_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case ASK_CANT_TRASH_ITEM:
|
|
|
|
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
|
|
|
|
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_CANTTRASH_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case ASK_DELETE_SELECTED:
|
|
|
|
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
|
|
|
|
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_DELETESELECTED_TEXT;
|
|
|
|
return TRUE;
|
2011-09-03 00:08:11 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
case ASK_OVERWRITE_FILE:
|
2016-02-23 16:06:27 +00:00
|
|
|
ids->icon_resource_id = IDI_SHELL_FOLDER_MOVE2;
|
2011-09-03 00:13:22 +00:00
|
|
|
ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_OVERWRITEFILE_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case ASK_OVERWRITE_FOLDER:
|
2016-02-23 16:06:27 +00:00
|
|
|
ids->icon_resource_id = IDI_SHELL_FOLDER_MOVE2;
|
2011-09-03 00:13:22 +00:00
|
|
|
ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_OVERWRITEFOLDER_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME(" Unhandled nKindOfDialog %d stub\n", nKindOfDialog);
|
|
|
|
}
|
|
|
|
return FALSE;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL SHELL_ConfirmDialogW(HWND hWnd, int nKindOfDialog, LPCWSTR szDir, FILE_OPERATION *op)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
WCHAR szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
|
|
|
|
SHELL_ConfirmIDstruc ids;
|
|
|
|
DWORD_PTR args[1];
|
|
|
|
HICON hIcon;
|
|
|
|
int ret;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 00:08:11 +00:00
|
|
|
assert(nKindOfDialog >= 0 && nKindOfDialog < 32);
|
|
|
|
if (op && (op->dwYesToAllMask & (1 << nKindOfDialog)))
|
|
|
|
return TRUE;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 00:08:11 +00:00
|
|
|
if (!SHELL_ConfirmIDs(nKindOfDialog, &ids)) return FALSE;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
LoadStringW(shell32_hInstance, ids.caption_resource_id, szCaption, sizeof(szCaption)/sizeof(WCHAR));
|
|
|
|
LoadStringW(shell32_hInstance, ids.text_resource_id, szText, sizeof(szText)/sizeof(WCHAR));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
args[0] = (DWORD_PTR)szDir;
|
|
|
|
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
|
|
|
szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)args);
|
2011-09-03 00:08:11 +00:00
|
|
|
hIcon = LoadIconW(ids.hIconInstance, (LPWSTR)MAKEINTRESOURCE(ids.icon_resource_id));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 00:08:11 +00:00
|
|
|
ret = SHELL_ConfirmMsgBox(hWnd, szBuffer, szCaption, hIcon, op && op->bManyItems);
|
|
|
|
if (op)
|
|
|
|
{
|
2012-01-17 21:28:17 +00:00
|
|
|
if (ret == IDC_YESTOALL)
|
2011-09-03 00:08:11 +00:00
|
|
|
{
|
|
|
|
op->dwYesToAllMask |= (1 << nKindOfDialog);
|
|
|
|
ret = IDYES;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2011-09-03 00:08:11 +00:00
|
|
|
if (ret == IDCANCEL)
|
|
|
|
op->bCancelled = TRUE;
|
|
|
|
if (ret != IDYES)
|
|
|
|
op->req->fAnyOperationsAborted = TRUE;
|
|
|
|
}
|
|
|
|
return ret == IDYES;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL SHELL_ConfirmYesNoW(HWND hWnd, int nKindOfDialog, LPCWSTR szDir)
|
|
|
|
{
|
|
|
|
return SHELL_ConfirmDialogW(hWnd, nKindOfDialog, szDir, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD SHELL32_AnsiToUnicodeBuf(LPCSTR aPath, LPWSTR *wPath, DWORD minChars)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
DWORD len = MultiByteToWideChar(CP_ACP, 0, aPath, -1, NULL, 0);
|
|
|
|
|
|
|
|
if (len < minChars)
|
|
|
|
len = minChars;
|
|
|
|
|
|
|
|
*wPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (*wPath)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, aPath, -1, *wPath, len);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
return E_OUTOFMEMORY;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SHELL32_FreeUnicodeBuf(LPWSTR wPath)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, wPath);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXTERN_C HRESULT WINAPI SHIsFileAvailableOffline(LPCWSTR path, LPDWORD status)
|
|
|
|
{
|
|
|
|
FIXME("(%s, %p) stub\n", debugstr_w(path), status);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* SHELL_DeleteDirectory() [internal]
|
|
|
|
*
|
|
|
|
* Asks for confirmation when bShowUI is true and deletes the directory and
|
|
|
|
* all its subdirectories and files if necessary.
|
|
|
|
*/
|
2015-02-21 12:52:58 +00:00
|
|
|
BOOL SHELL_DeleteDirectoryW(FILE_OPERATION *op, LPCWSTR pszDir, BOOL bShowUI)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
HANDLE hFind;
|
|
|
|
WIN32_FIND_DATAW wfd;
|
|
|
|
WCHAR szTemp[MAX_PATH];
|
|
|
|
|
|
|
|
/* Make sure the directory exists before eventually prompting the user */
|
|
|
|
PathCombineW(szTemp, pszDir, wWildcardFile);
|
|
|
|
hFind = FindFirstFileW(szTemp, &wfd);
|
|
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if (!bShowUI || (ret = SHELL_ConfirmDialogW(op->req->hwnd, ASK_DELETE_FOLDER, pszDir, NULL)))
|
2011-09-03 00:13:22 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (IsDotDir(wfd.cFileName))
|
|
|
|
continue;
|
|
|
|
PathCombineW(szTemp, pszDir, wfd.cFileName);
|
|
|
|
if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
|
2015-02-21 12:52:58 +00:00
|
|
|
ret = SHELL_DeleteDirectoryW(op, szTemp, FALSE);
|
2011-09-03 00:13:22 +00:00
|
|
|
else
|
2015-02-21 12:52:58 +00:00
|
|
|
ret = (SHNotifyDeleteFileW(op, szTemp) == ERROR_SUCCESS);
|
|
|
|
|
|
|
|
if (op->progress != NULL)
|
|
|
|
op->bCancelled |= op->progress->HasUserCancelled();
|
|
|
|
} while (ret && FindNextFileW(hFind, &wfd) && !op->bCancelled);
|
2011-09-03 00:13:22 +00:00
|
|
|
}
|
|
|
|
FindClose(hFind);
|
|
|
|
if (ret)
|
|
|
|
ret = (SHNotifyRemoveDirectoryW(pszDir) == ERROR_SUCCESS);
|
|
|
|
return ret;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Win32CreateDirectory [SHELL32.93]
|
|
|
|
*
|
|
|
|
* Creates a directory. Also triggers a change notify if one exists.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* path [I] path to directory to create
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful, FALSE otherwise
|
|
|
|
*/
|
|
|
|
|
|
|
|
static DWORD SHNotifyCreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
TRACE("(%s, %p)\n", debugstr_w(path), sec);
|
|
|
|
|
|
|
|
if (CreateDirectoryW(path, sec))
|
|
|
|
{
|
|
|
|
SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHW, path, NULL);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return GetLastError();
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
EXTERN_C BOOL WINAPI Win32CreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
return (SHNotifyCreateDirectoryW(path, sec) == ERROR_SUCCESS);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Win32RemoveDirectory [SHELL32.94]
|
|
|
|
*
|
|
|
|
* Deletes a directory. Also triggers a change notify if one exists.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* path [I] path to directory to delete
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful, FALSE otherwise
|
|
|
|
*/
|
|
|
|
static DWORD SHNotifyRemoveDirectoryW(LPCWSTR path)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
BOOL ret;
|
|
|
|
TRACE("(%s)\n", debugstr_w(path));
|
|
|
|
|
|
|
|
ret = RemoveDirectoryW(path);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
/* Directory may be write protected */
|
|
|
|
DWORD dwAttr = GetFileAttributesW(path);
|
|
|
|
if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY))
|
|
|
|
if (SetFileAttributesW(path, dwAttr & ~FILE_ATTRIBUTE_READONLY))
|
|
|
|
ret = RemoveDirectoryW(path);
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHW, path, NULL);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return GetLastError();
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
EXTERN_C BOOL WINAPI Win32RemoveDirectoryW(LPCWSTR path)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
return (SHNotifyRemoveDirectoryW(path) == ERROR_SUCCESS);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
static void _SetOperationTitle(FILE_OPERATION *op) {
|
|
|
|
if (op->progress == NULL)
|
|
|
|
return;
|
|
|
|
WCHAR szTitle[50], szPreflight[50];
|
2015-04-23 22:35:23 +00:00
|
|
|
UINT animation_id = NULL;
|
2015-02-21 12:52:58 +00:00
|
|
|
|
|
|
|
switch (op->req->wFunc)
|
|
|
|
{
|
|
|
|
case FO_COPY:
|
|
|
|
LoadStringW(shell32_hInstance, IDS_FILEOOP_COPYING, szTitle, sizeof(szTitle)/sizeof(WCHAR));
|
|
|
|
LoadStringW(shell32_hInstance, IDS_FILEOOP_FROM_TO, op->szBuilderString, sizeof( op->szBuilderString)/sizeof(WCHAR));
|
2015-04-23 22:35:23 +00:00
|
|
|
animation_id = IDA_SHELL_COPY;
|
2015-02-21 12:52:58 +00:00
|
|
|
break;
|
|
|
|
case FO_DELETE:
|
|
|
|
LoadStringW(shell32_hInstance, IDS_FILEOOP_DELETING, szTitle, sizeof(szTitle)/sizeof(WCHAR));
|
|
|
|
LoadStringW(shell32_hInstance, IDS_FILEOOP_FROM, op->szBuilderString, sizeof( op->szBuilderString)/sizeof(WCHAR));
|
2015-04-23 22:35:23 +00:00
|
|
|
animation_id = IDA_SHELL_DELETE;
|
2015-02-21 12:52:58 +00:00
|
|
|
break;
|
|
|
|
case FO_MOVE:
|
|
|
|
LoadStringW(shell32_hInstance, IDS_FILEOOP_MOVING, szTitle, sizeof(szTitle)/sizeof(WCHAR));
|
|
|
|
LoadStringW(shell32_hInstance, IDS_FILEOOP_FROM_TO, op->szBuilderString, sizeof( op->szBuilderString)/sizeof(WCHAR));
|
2015-04-23 22:35:23 +00:00
|
|
|
animation_id = IDA_SHELL_COPY;
|
2015-02-21 12:52:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LoadStringW(shell32_hInstance, IDS_FILEOOP_PREFLIGHT, szPreflight, sizeof(szPreflight)/sizeof(WCHAR));
|
|
|
|
|
|
|
|
op->progress->SetTitle(szTitle);
|
|
|
|
op->progress->SetLine(1, szPreflight, false, NULL);
|
2015-04-23 22:35:23 +00:00
|
|
|
op->progress->SetAnimation(shell32_hInstance, animation_id);
|
2015-02-21 12:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _SetOperationTexts(FILE_OPERATION *op, LPCWSTR src, LPCWSTR dest) {
|
|
|
|
if (op->progress == NULL || src == NULL)
|
|
|
|
return;
|
|
|
|
LPWSTR fileSpecS, pathSpecS, fileSpecD, pathSpecD;
|
|
|
|
WCHAR szFolderS[50], szFolderD[50], szFinalString[260];
|
|
|
|
|
|
|
|
DWORD_PTR args[2];
|
|
|
|
|
|
|
|
fileSpecS = (pathSpecS = (LPWSTR) src);
|
|
|
|
fileSpecD = (pathSpecD = (LPWSTR) dest);
|
|
|
|
|
|
|
|
// March across the string to get the file path and it's parent dir.
|
|
|
|
for (LPWSTR ptr = (LPWSTR) src; *ptr; ptr++) {
|
|
|
|
if (*ptr == '\\') {
|
|
|
|
pathSpecS = fileSpecS;
|
|
|
|
fileSpecS = ptr+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lstrcpynW(szFolderS, pathSpecS, min(50, fileSpecS - pathSpecS));
|
|
|
|
args[0] = (DWORD_PTR) szFolderS;
|
|
|
|
|
|
|
|
switch (op->req->wFunc)
|
|
|
|
{
|
|
|
|
case FO_COPY:
|
|
|
|
case FO_MOVE:
|
|
|
|
if (dest == NULL)
|
|
|
|
return;
|
|
|
|
for (LPWSTR ptr = (LPWSTR) dest; *ptr; ptr++) {
|
|
|
|
if (*ptr == '\\') {
|
|
|
|
pathSpecD = fileSpecD;
|
|
|
|
fileSpecD = ptr + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lstrcpynW(szFolderD, pathSpecD, min(50, fileSpecD - pathSpecD));
|
|
|
|
args[1] = (DWORD_PTR) szFolderD;
|
|
|
|
break;
|
|
|
|
case FO_DELETE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
|
|
|
op->szBuilderString, 0, 0, szFinalString, sizeof(szFinalString), (va_list*)args);
|
|
|
|
|
|
|
|
op->progress->SetLine(1, fileSpecS, false, NULL);
|
|
|
|
op->progress->SetLine(2, szFinalString, false, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DWORD CALLBACK SHCopyProgressRoutine(
|
|
|
|
LARGE_INTEGER TotalFileSize,
|
|
|
|
LARGE_INTEGER TotalBytesTransferred,
|
|
|
|
LARGE_INTEGER StreamSize,
|
|
|
|
LARGE_INTEGER StreamBytesTransferred,
|
|
|
|
DWORD dwStreamNumber,
|
|
|
|
DWORD dwCallbackReason,
|
|
|
|
HANDLE hSourceFile,
|
|
|
|
HANDLE hDestinationFile,
|
|
|
|
LPVOID lpData
|
|
|
|
) {
|
|
|
|
FILE_OPERATION *op = (FILE_OPERATION *) lpData;
|
|
|
|
|
|
|
|
if (op->progress) {
|
|
|
|
/*
|
|
|
|
* This is called at the start of each file. To keop less state,
|
|
|
|
* I'm adding the file to the completed size here, and the re-subtracting
|
|
|
|
* it when drawing the progress bar.
|
|
|
|
*/
|
|
|
|
if (dwCallbackReason & CALLBACK_STREAM_SWITCH)
|
|
|
|
op->completedSize.QuadPart += TotalFileSize.QuadPart;
|
|
|
|
|
|
|
|
op->progress->SetProgress64(op->completedSize.QuadPart -
|
|
|
|
TotalFileSize.QuadPart +
|
|
|
|
TotalBytesTransferred.QuadPart
|
|
|
|
, op->totalSize.QuadPart);
|
|
|
|
|
|
|
|
|
|
|
|
op->bCancelled = op->progress->HasUserCancelled();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/************************************************************************
|
2015-02-21 12:52:58 +00:00
|
|
|
* SHNotifyDeleteFileW [internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* Deletes a file. Also triggers a change notify if one exists.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2015-02-21 12:52:58 +00:00
|
|
|
* op [I] File Operation context
|
|
|
|
* path [I] path to source file to move
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* RETURNS
|
2015-02-21 12:52:58 +00:00
|
|
|
* ERORR_SUCCESS if successful
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
2015-02-21 12:52:58 +00:00
|
|
|
static DWORD SHNotifyDeleteFileW(FILE_OPERATION *op, LPCWSTR path)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(path));
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
_SetOperationTexts(op, path, NULL);
|
|
|
|
|
|
|
|
LARGE_INTEGER FileSize;
|
|
|
|
FileSize.QuadPart = 0;
|
|
|
|
|
|
|
|
WIN32_FIND_DATAW wfd;
|
|
|
|
HANDLE hFile = FindFirstFileW(path, &wfd);
|
|
|
|
if (hFile != INVALID_HANDLE_VALUE && IsAttribFile(wfd.dwFileAttributes)) {
|
|
|
|
ULARGE_INTEGER tmp;
|
|
|
|
tmp.u.LowPart = wfd.nFileSizeLow;
|
|
|
|
tmp.u.HighPart = wfd.nFileSizeHigh;
|
|
|
|
FileSize.QuadPart = tmp.QuadPart;
|
|
|
|
}
|
|
|
|
FindClose(hFile);
|
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
ret = DeleteFileW(path);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
/* File may be write protected or a system file */
|
|
|
|
DWORD dwAttr = GetFileAttributesW(path);
|
|
|
|
if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
|
|
|
|
if (SetFileAttributesW(path, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
|
|
|
|
ret = DeleteFileW(path);
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
2015-02-21 12:52:58 +00:00
|
|
|
// Bit of a hack to make the progress bar move. We don't have progress inside the file, so inform when done.
|
|
|
|
SHCopyProgressRoutine(FileSize, FileSize, FileSize, FileSize, 0, CALLBACK_STREAM_SWITCH, NULL, NULL, op);
|
2011-09-03 00:13:22 +00:00
|
|
|
SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, path, NULL);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return GetLastError();
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
/************************************************************************
|
|
|
|
* Win32DeleteFile [SHELL32.164]
|
|
|
|
*
|
|
|
|
* Deletes a file. Also triggers a change notify if one exists.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* path [I] path to file to delete
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful, FALSE otherwise
|
|
|
|
*/
|
2011-05-15 15:55:49 +00:00
|
|
|
EXTERN_C DWORD WINAPI Win32DeleteFileW(LPCWSTR path)
|
|
|
|
{
|
2015-02-21 12:52:58 +00:00
|
|
|
return (SHNotifyDeleteFileW(NULL, path) == ERROR_SUCCESS);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* SHNotifyMoveFile [internal]
|
|
|
|
*
|
|
|
|
* Moves a file. Also triggers a change notify if one exists.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2015-02-21 12:52:58 +00:00
|
|
|
* op [I] File Operation context
|
2011-05-15 15:55:49 +00:00
|
|
|
* src [I] path to source file to move
|
|
|
|
* dest [I] path to target file to move to
|
|
|
|
*
|
|
|
|
* RETURNS
|
2016-09-05 07:52:52 +00:00
|
|
|
* ERROR_SUCCESS if successful
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
2015-02-21 12:52:58 +00:00
|
|
|
static DWORD SHNotifyMoveFileW(FILE_OPERATION *op, LPCWSTR src, LPCWSTR dest, BOOL isdir)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
BOOL ret;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
TRACE("(%s %s)\n", debugstr_w(src), debugstr_w(dest));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
_SetOperationTexts(op, src, dest);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
ret = MoveFileWithProgressW(src, dest, SHCopyProgressRoutine, op, MOVEFILE_REPLACE_EXISTING);
|
|
|
|
|
|
|
|
/* MOVEFILE_REPLACE_EXISTING fails with dirs, so try MoveFile */
|
|
|
|
if (!ret)
|
|
|
|
ret = MoveFileW(src, dest);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
DWORD dwAttr;
|
|
|
|
|
|
|
|
dwAttr = SHFindAttrW(dest, FALSE);
|
|
|
|
if (INVALID_FILE_ATTRIBUTES == dwAttr)
|
|
|
|
{
|
|
|
|
/* Source file may be write protected or a system file */
|
|
|
|
dwAttr = GetFileAttributesW(src);
|
|
|
|
if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
|
|
|
|
if (SetFileAttributesW(src, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
|
|
|
|
ret = MoveFileW(src, dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
2014-03-15 13:59:22 +00:00
|
|
|
SHChangeNotify(isdir ? SHCNE_MKDIR : SHCNE_CREATE, SHCNF_PATHW, dest, NULL);
|
|
|
|
SHChangeNotify(isdir ? SHCNE_RMDIR : SHCNE_DELETE, SHCNF_PATHW, src, NULL);
|
2011-09-03 00:13:22 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return GetLastError();
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* SHNotifyCopyFile [internal]
|
|
|
|
*
|
|
|
|
* Copies a file. Also triggers a change notify if one exists.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* src [I] path to source file to move
|
|
|
|
* dest [I] path to target file to move to
|
|
|
|
* bFailIfExists [I] if TRUE, the target file will not be overwritten if
|
|
|
|
* a file with this name already exists
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* ERROR_SUCCESS if successful
|
|
|
|
*/
|
2015-02-21 12:52:58 +00:00
|
|
|
static DWORD SHNotifyCopyFileW(FILE_OPERATION *op, LPCWSTR src, LPCWSTR dest, BOOL bFailIfExists)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
BOOL ret;
|
|
|
|
DWORD attribs;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
TRACE("(%s %s %s)\n", debugstr_w(src), debugstr_w(dest), bFailIfExists ? "failIfExists" : "");
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
_SetOperationTexts(op, src, dest);
|
|
|
|
|
2011-09-03 00:08:11 +00:00
|
|
|
/* Destination file may already exist with read only attribute */
|
|
|
|
attribs = GetFileAttributesW(dest);
|
|
|
|
if (IsAttrib(attribs, FILE_ATTRIBUTE_READONLY))
|
|
|
|
SetFileAttributesW(dest, attribs & ~FILE_ATTRIBUTE_READONLY);
|
|
|
|
|
|
|
|
if (GetFileAttributesW(dest) & FILE_ATTRIBUTE_READONLY)
|
|
|
|
{
|
|
|
|
SetFileAttributesW(dest, attribs & ~FILE_ATTRIBUTE_READONLY);
|
|
|
|
if (GetFileAttributesW(dest) & FILE_ATTRIBUTE_READONLY)
|
|
|
|
{
|
2011-09-09 10:55:09 +00:00
|
|
|
TRACE("[shell32, SHNotifyCopyFileW] STILL SHIT\n");
|
2011-09-03 00:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
ret = CopyFileExW(src, dest, SHCopyProgressRoutine, op, &op->bCancelled, bFailIfExists);
|
2011-09-03 00:13:22 +00:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, dest, NULL);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
return GetLastError();
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateDirectory [SHELL32.165]
|
|
|
|
*
|
|
|
|
* This function creates a file system folder whose fully qualified path is
|
|
|
|
* given by path. If one or more of the intermediate folders do not exist,
|
|
|
|
* they will be created as well.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hWnd [I]
|
|
|
|
* path [I] path of directory to create
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* ERROR_SUCCESS or one of the following values:
|
|
|
|
* ERROR_BAD_PATHNAME if the path is relative
|
|
|
|
* ERROR_FILE_EXISTS when a file with that name exists
|
|
|
|
* ERROR_PATH_NOT_FOUND can't find the path, probably invalid
|
|
|
|
* ERROR_INVALID_NAME if the path contains invalid chars
|
|
|
|
* ERROR_ALREADY_EXISTS when the directory already exists
|
|
|
|
* ERROR_FILENAME_EXCED_RANGE if the filename was to long to process
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* exported by ordinal
|
|
|
|
* Win9x exports ANSI
|
|
|
|
* WinNT/2000 exports Unicode
|
|
|
|
*/
|
|
|
|
int WINAPI SHCreateDirectory(HWND hWnd, LPCWSTR path)
|
|
|
|
{
|
|
|
|
return SHCreateDirectoryExW(hWnd, path, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateDirectoryExA [SHELL32.@]
|
|
|
|
*
|
|
|
|
* This function creates a file system folder whose fully qualified path is
|
|
|
|
* given by path. If one or more of the intermediate folders do not exist,
|
|
|
|
* they will be created as well.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hWnd [I]
|
|
|
|
* path [I] path of directory to create
|
|
|
|
* sec [I] security attributes to use or NULL
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* ERROR_SUCCESS or one of the following values:
|
|
|
|
* ERROR_BAD_PATHNAME or ERROR_PATH_NOT_FOUND if the path is relative
|
|
|
|
* ERROR_INVALID_NAME if the path contains invalid chars
|
|
|
|
* ERROR_FILE_EXISTS when a file with that name exists
|
|
|
|
* ERROR_ALREADY_EXISTS when the directory already exists
|
2016-09-05 07:52:52 +00:00
|
|
|
* ERROR_FILENAME_EXCED_RANGE if the filename was too long to process
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* FIXME: Not implemented yet;
|
|
|
|
* SHCreateDirectoryEx also verifies that the files in the directory will be visible
|
|
|
|
* if the path is a network path to deal with network drivers which might have a limited
|
|
|
|
* but unknown maximum path length. If not:
|
|
|
|
*
|
|
|
|
* If hWnd is set to a valid window handle, a message box is displayed warning
|
|
|
|
* the user that the files may not be accessible. If the user chooses not to
|
|
|
|
* proceed, the function returns ERROR_CANCELLED.
|
|
|
|
*
|
|
|
|
* If hWnd is set to NULL, no user interface is displayed and the function
|
|
|
|
* returns ERROR_CANCELLED.
|
|
|
|
*/
|
|
|
|
int WINAPI SHCreateDirectoryExA(HWND hWnd, LPCSTR path, LPSECURITY_ATTRIBUTES sec)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
LPWSTR wPath;
|
|
|
|
DWORD retCode;
|
|
|
|
|
|
|
|
TRACE("(%s, %p)\n", debugstr_a(path), sec);
|
|
|
|
|
|
|
|
retCode = SHELL32_AnsiToUnicodeBuf(path, &wPath, 0);
|
|
|
|
if (!retCode)
|
|
|
|
{
|
|
|
|
retCode = SHCreateDirectoryExW(hWnd, wPath, sec);
|
|
|
|
SHELL32_FreeUnicodeBuf(wPath);
|
|
|
|
}
|
|
|
|
return retCode;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateDirectoryExW [SHELL32.@]
|
|
|
|
*
|
|
|
|
* See SHCreateDirectoryExA.
|
|
|
|
*/
|
|
|
|
int WINAPI SHCreateDirectoryExW(HWND hWnd, LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
int ret = ERROR_BAD_PATHNAME;
|
|
|
|
TRACE("(%p, %s, %p)\n", hWnd, debugstr_w(path), sec);
|
|
|
|
|
|
|
|
if (PathIsRelativeW(path))
|
|
|
|
{
|
|
|
|
SetLastError(ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = SHNotifyCreateDirectoryW(path, sec);
|
|
|
|
/* Refuse to work on certain error codes before trying to create directories recursively */
|
|
|
|
if (ret != ERROR_SUCCESS &&
|
|
|
|
ret != ERROR_FILE_EXISTS &&
|
|
|
|
ret != ERROR_ALREADY_EXISTS &&
|
|
|
|
ret != ERROR_FILENAME_EXCED_RANGE)
|
|
|
|
{
|
|
|
|
WCHAR *pEnd, *pSlash, szTemp[MAX_PATH + 1]; /* extra for PathAddBackslash() */
|
|
|
|
|
|
|
|
lstrcpynW(szTemp, path, MAX_PATH);
|
|
|
|
pEnd = PathAddBackslashW(szTemp);
|
|
|
|
pSlash = szTemp + 3;
|
|
|
|
|
|
|
|
while (*pSlash)
|
|
|
|
{
|
|
|
|
while (*pSlash && *pSlash != '\\') pSlash++;
|
|
|
|
if (*pSlash)
|
|
|
|
{
|
|
|
|
*pSlash = 0; /* terminate path at separator */
|
|
|
|
|
|
|
|
ret = SHNotifyCreateDirectoryW(szTemp, pSlash + 1 == pEnd ? sec : NULL);
|
|
|
|
}
|
|
|
|
*pSlash++ = '\\'; /* put the separator back */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret && hWnd && (ERROR_CANCELLED != ret))
|
|
|
|
{
|
2016-08-20 09:34:25 +00:00
|
|
|
ShellMessageBoxW(shell32_hInstance, hWnd, MAKEINTRESOURCEW(IDS_CREATEFOLDER_DENIED), MAKEINTRESOURCEW(IDS_CREATEFOLDER_CAPTION),
|
|
|
|
MB_ICONEXCLAMATION | MB_OK, path);
|
|
|
|
ret = ERROR_CANCELLED;
|
2011-09-03 00:13:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHFindAttrW [internal]
|
|
|
|
*
|
|
|
|
* Get the Attributes for a file or directory. The difference to GetAttributes()
|
|
|
|
* is that this function will also work for paths containing wildcard characters
|
|
|
|
* in its filename.
|
|
|
|
|
|
|
|
* PARAMS
|
|
|
|
* path [I] path of directory or file to check
|
|
|
|
* fileOnly [I] TRUE if only files should be found
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* INVALID_FILE_ATTRIBUTES if the path does not exist, the actual attributes of
|
|
|
|
* the first file or directory found otherwise
|
|
|
|
*/
|
|
|
|
static DWORD SHFindAttrW(LPCWSTR pName, BOOL fileOnly)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
WIN32_FIND_DATAW wfd;
|
|
|
|
BOOL b_FileMask = fileOnly && (NULL != StrPBrkW(pName, wWildcardChars));
|
|
|
|
DWORD dwAttr = INVALID_FILE_ATTRIBUTES;
|
|
|
|
HANDLE hFind = FindFirstFileW(pName, &wfd);
|
|
|
|
|
|
|
|
TRACE("%s %d\n", debugstr_w(pName), fileOnly);
|
|
|
|
if (INVALID_HANDLE_VALUE != hFind)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (b_FileMask && IsAttribDir(wfd.dwFileAttributes))
|
|
|
|
continue;
|
|
|
|
dwAttr = wfd.dwFileAttributes;
|
|
|
|
break;
|
|
|
|
} while (FindNextFileW(hFind, &wfd));
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
FindClose(hFind);
|
|
|
|
}
|
|
|
|
return dwAttr;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
*
|
2014-10-09 00:10:20 +00:00
|
|
|
* _ConvertAtoW helper function for SHFileOperationA
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
2014-10-09 00:10:20 +00:00
|
|
|
* Converts a string or string-list to unicode.
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
2014-10-09 00:10:20 +00:00
|
|
|
static DWORD _ConvertAtoW(PCSTR strSrc, PCWSTR* pStrDest, BOOL isList)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-10-09 00:10:20 +00:00
|
|
|
*pStrDest = NULL;
|
2011-09-03 00:13:22 +00:00
|
|
|
|
2014-10-09 00:10:20 +00:00
|
|
|
// If the input is null, nothing to convert.
|
|
|
|
if (!strSrc)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Measure the total size, depending on if it's a zero-terminated list.
|
|
|
|
int sizeA = 0;
|
|
|
|
if (isList)
|
2011-09-03 00:13:22 +00:00
|
|
|
{
|
2014-10-09 00:10:20 +00:00
|
|
|
PCSTR tmpSrc = strSrc;
|
|
|
|
int size;
|
2011-09-03 00:13:22 +00:00
|
|
|
do
|
|
|
|
{
|
2014-10-09 00:10:20 +00:00
|
|
|
size = lstrlenA(tmpSrc) + 1;
|
|
|
|
sizeA += size;
|
|
|
|
tmpSrc += size;
|
|
|
|
} while (size != 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sizeA = lstrlenA(strSrc) + 1;
|
2011-09-03 00:13:22 +00:00
|
|
|
}
|
2014-10-09 00:10:20 +00:00
|
|
|
|
2014-10-09 12:54:29 +00:00
|
|
|
// Measure the needed allocation size.
|
2014-10-09 00:10:20 +00:00
|
|
|
int sizeW = MultiByteToWideChar(CP_ACP, 0, strSrc, sizeA, NULL, 0);
|
|
|
|
if (!sizeW)
|
|
|
|
return GetLastError();
|
|
|
|
|
2014-10-09 12:54:29 +00:00
|
|
|
PWSTR strDest = (PWSTR) HeapAlloc(GetProcessHeap(), 0, sizeW * sizeof(WCHAR));
|
2014-10-09 00:10:20 +00:00
|
|
|
if (!strDest)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
int err = MultiByteToWideChar(CP_ACP, 0, strSrc, sizeA, strDest, sizeW);
|
|
|
|
if (!err)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, strDest);
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
*pStrDest = strDest;
|
|
|
|
return 0;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2014-10-09 00:10:20 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* SHFileOperationA [SHELL32.@]
|
|
|
|
*
|
|
|
|
* Function to copy, move, delete and create one or more files with optional
|
|
|
|
* user prompts.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpFileOp [I/O] pointer to a structure containing all the necessary information
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: ERROR_SUCCESS.
|
|
|
|
* Failure: ERROR_CANCELLED.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* exported by name
|
|
|
|
*/
|
|
|
|
int WINAPI SHFileOperationA(LPSHFILEOPSTRUCTA lpFileOp)
|
|
|
|
{
|
2014-10-09 00:10:20 +00:00
|
|
|
int errCode, retCode;
|
|
|
|
SHFILEOPSTRUCTW nFileOp = { 0 };
|
|
|
|
|
|
|
|
// Convert A information to W
|
|
|
|
nFileOp.hwnd = lpFileOp->hwnd;
|
|
|
|
nFileOp.wFunc = lpFileOp->wFunc;
|
|
|
|
nFileOp.fFlags = lpFileOp->fFlags;
|
|
|
|
|
|
|
|
errCode = _ConvertAtoW(lpFileOp->pFrom, &nFileOp.pFrom, TRUE);
|
|
|
|
if (errCode != 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (FO_DELETE != (nFileOp.wFunc & FO_MASK))
|
2011-09-03 00:13:22 +00:00
|
|
|
{
|
2014-10-09 00:10:20 +00:00
|
|
|
errCode = _ConvertAtoW(lpFileOp->pTo, &nFileOp.pTo, TRUE);
|
|
|
|
if (errCode != 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-09-03 00:13:22 +00:00
|
|
|
|
2014-10-09 00:10:20 +00:00
|
|
|
if (nFileOp.fFlags & FOF_SIMPLEPROGRESS)
|
|
|
|
{
|
|
|
|
errCode = _ConvertAtoW(lpFileOp->lpszProgressTitle, &nFileOp.lpszProgressTitle, FALSE);
|
|
|
|
if (errCode != 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call the actual function
|
|
|
|
retCode = SHFileOperationW(&nFileOp);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
cleanup:
|
|
|
|
if (nFileOp.pFrom)
|
|
|
|
HeapFree(GetProcessHeap(), 0, (PVOID) nFileOp.pFrom);
|
|
|
|
if (nFileOp.pTo)
|
|
|
|
HeapFree(GetProcessHeap(), 0, (PVOID) nFileOp.pTo);
|
|
|
|
if (nFileOp.lpszProgressTitle)
|
|
|
|
HeapFree(GetProcessHeap(), 0, (PVOID) nFileOp.lpszProgressTitle);
|
|
|
|
|
|
|
|
if (errCode != 0)
|
|
|
|
{
|
|
|
|
lpFileOp->fAnyOperationsAborted = TRUE;
|
|
|
|
SetLastError(errCode);
|
|
|
|
|
|
|
|
return errCode;
|
2011-09-03 00:13:22 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 00:13:05 +00:00
|
|
|
// Thankfully, starting with NT4 the name mappings are always unicode, so no need to convert.
|
2011-09-03 00:13:22 +00:00
|
|
|
lpFileOp->hNameMappings = nFileOp.hNameMappings;
|
|
|
|
lpFileOp->fAnyOperationsAborted = nFileOp.fAnyOperationsAborted;
|
|
|
|
return retCode;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __inline grow_list(FILE_LIST *list)
|
|
|
|
{
|
|
|
|
FILE_ENTRY *newx = (FILE_ENTRY *)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, list->feFiles,
|
|
|
|
list->num_alloc * 2 * sizeof(*newx) );
|
|
|
|
list->feFiles = newx;
|
|
|
|
list->num_alloc *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adds a file to the FILE_ENTRY struct
|
|
|
|
*/
|
|
|
|
static void add_file_to_entry(FILE_ENTRY *feFile, LPCWSTR szFile)
|
|
|
|
{
|
|
|
|
DWORD dwLen = lstrlenW(szFile) + 1;
|
|
|
|
LPCWSTR ptr;
|
|
|
|
|
|
|
|
feFile->szFullPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR));
|
|
|
|
lstrcpyW(feFile->szFullPath, szFile);
|
|
|
|
|
|
|
|
ptr = StrRChrW(szFile, NULL, '\\');
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
dwLen = ptr - szFile + 1;
|
|
|
|
feFile->szDirectory = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR));
|
|
|
|
lstrcpynW(feFile->szDirectory, szFile, dwLen);
|
|
|
|
|
|
|
|
dwLen = lstrlenW(feFile->szFullPath) - dwLen + 1;
|
|
|
|
feFile->szFilename = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR));
|
|
|
|
lstrcpyW(feFile->szFilename, ptr + 1); /* skip over backslash */
|
|
|
|
}
|
|
|
|
feFile->bFromWildcard = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR wildcard_to_file(LPCWSTR szWildCard, LPCWSTR szFileName)
|
|
|
|
{
|
|
|
|
LPCWSTR ptr;
|
|
|
|
LPWSTR szFullPath;
|
|
|
|
DWORD dwDirLen, dwFullLen;
|
|
|
|
|
|
|
|
ptr = StrRChrW(szWildCard, NULL, '\\');
|
|
|
|
dwDirLen = ptr - szWildCard + 1;
|
|
|
|
|
|
|
|
dwFullLen = dwDirLen + lstrlenW(szFileName) + 1;
|
|
|
|
szFullPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwFullLen * sizeof(WCHAR));
|
|
|
|
|
|
|
|
lstrcpynW(szFullPath, szWildCard, dwDirLen + 1);
|
|
|
|
lstrcatW(szFullPath, szFileName);
|
|
|
|
|
|
|
|
return szFullPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_wildcard_files(FILE_LIST *flList, LPCWSTR szFile, LPDWORD pdwListIndex)
|
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW wfd;
|
|
|
|
HANDLE hFile = FindFirstFileW(szFile, &wfd);
|
|
|
|
FILE_ENTRY *file;
|
|
|
|
LPWSTR szFullPath;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
|
|
|
for (res = TRUE; res; res = FindNextFileW(hFile, &wfd))
|
|
|
|
{
|
2011-09-03 00:08:11 +00:00
|
|
|
if (IsDotDir(wfd.cFileName))
|
2011-09-03 00:13:22 +00:00
|
|
|
continue;
|
2011-09-03 00:08:11 +00:00
|
|
|
|
|
|
|
if (*pdwListIndex >= flList->num_alloc)
|
2011-09-03 00:13:22 +00:00
|
|
|
grow_list( flList );
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
szFullPath = wildcard_to_file(szFile, wfd.cFileName);
|
2011-05-15 15:55:49 +00:00
|
|
|
file = &flList->feFiles[(*pdwListIndex)++];
|
|
|
|
add_file_to_entry(file, szFullPath);
|
|
|
|
file->bFromWildcard = TRUE;
|
|
|
|
file->attributes = wfd.dwFileAttributes;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
if (IsAttribDir(file->attributes))
|
|
|
|
flList->bAnyDirectories = TRUE;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-09-03 00:13:22 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, szFullPath);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FindClose(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* takes the null-separated file list and fills out the FILE_LIST */
|
|
|
|
static HRESULT parse_file_list(FILE_LIST *flList, LPCWSTR szFiles)
|
|
|
|
{
|
|
|
|
LPCWSTR ptr = szFiles;
|
|
|
|
WCHAR szCurFile[MAX_PATH];
|
|
|
|
DWORD i = 0;
|
|
|
|
|
|
|
|
if (!szFiles)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
flList->bAnyFromWildcard = FALSE;
|
|
|
|
flList->bAnyDirectories = FALSE;
|
|
|
|
flList->bAnyDontExist = FALSE;
|
|
|
|
flList->num_alloc = 32;
|
|
|
|
flList->dwNumFiles = 0;
|
|
|
|
|
|
|
|
/* empty list */
|
|
|
|
if (!szFiles[0])
|
|
|
|
return ERROR_ACCESS_DENIED;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
flList->feFiles = (FILE_ENTRY *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
flList->num_alloc * sizeof(FILE_ENTRY));
|
|
|
|
|
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
if (i >= flList->num_alloc) grow_list( flList );
|
|
|
|
|
|
|
|
/* change relative to absolute path */
|
|
|
|
if (PathIsRelativeW(ptr))
|
|
|
|
{
|
|
|
|
GetCurrentDirectoryW(MAX_PATH, szCurFile);
|
|
|
|
PathCombineW(szCurFile, szCurFile, ptr);
|
|
|
|
flList->feFiles[i].bFromRelative = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lstrcpyW(szCurFile, ptr);
|
|
|
|
flList->feFiles[i].bFromRelative = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse wildcard files if they are in the filename */
|
|
|
|
if (StrPBrkW(szCurFile, wWildcardChars))
|
|
|
|
{
|
|
|
|
parse_wildcard_files(flList, szCurFile, &i);
|
|
|
|
flList->bAnyFromWildcard = TRUE;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE_ENTRY *file = &flList->feFiles[i];
|
|
|
|
add_file_to_entry(file, szCurFile);
|
|
|
|
file->attributes = GetFileAttributesW( file->szFullPath );
|
|
|
|
file->bExists = (file->attributes != INVALID_FILE_ATTRIBUTES);
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-08-22 16:32:16 +00:00
|
|
|
if (!file->bExists)
|
|
|
|
flList->bAnyDontExist = TRUE;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-08-22 16:32:16 +00:00
|
|
|
if (IsAttribDir(file->attributes))
|
|
|
|
flList->bAnyDirectories = TRUE;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* advance to the next string */
|
|
|
|
ptr += lstrlenW(ptr) + 1;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
flList->dwNumFiles = i;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free the FILE_LIST */
|
|
|
|
static void destroy_file_list(FILE_LIST *flList)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if (!flList || !flList->feFiles)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < flList->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, flList->feFiles[i].szDirectory);
|
|
|
|
HeapFree(GetProcessHeap(), 0, flList->feFiles[i].szFilename);
|
|
|
|
HeapFree(GetProcessHeap(), 0, flList->feFiles[i].szFullPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, flList->feFiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void copy_dir_to_dir(FILE_OPERATION *op, const FILE_ENTRY *feFrom, LPCWSTR szDestPath)
|
|
|
|
{
|
|
|
|
WCHAR szFrom[MAX_PATH], szTo[MAX_PATH];
|
2015-02-21 12:52:58 +00:00
|
|
|
FILE_LIST flFromNew, flToNew;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
static const WCHAR wildCardFiles[] = {'*','.','*',0};
|
|
|
|
|
|
|
|
if (IsDotDir(feFrom->szFilename))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (PathFileExistsW(szDestPath))
|
|
|
|
PathCombineW(szTo, szDestPath, feFrom->szFilename);
|
|
|
|
else
|
|
|
|
lstrcpyW(szTo, szDestPath);
|
|
|
|
|
2011-09-03 00:08:11 +00:00
|
|
|
if (!(op->req->fFlags & FOF_NOCONFIRMATION) && PathFileExistsW(szTo))
|
2011-09-03 00:13:22 +00:00
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
if (!SHELL_ConfirmDialogW(op->req->hwnd, ASK_OVERWRITE_FOLDER, feFrom->szFilename, op))
|
|
|
|
{
|
|
|
|
/* Vista returns an ERROR_CANCELLED even if user pressed "No" */
|
|
|
|
if (!op->bManyItems)
|
|
|
|
op->bCancelled = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
szTo[lstrlenW(szTo) + 1] = '\0';
|
|
|
|
SHNotifyCreateDirectoryW(szTo, NULL);
|
|
|
|
|
|
|
|
PathCombineW(szFrom, feFrom->szFullPath, wildCardFiles);
|
|
|
|
szFrom[lstrlenW(szFrom) + 1] = '\0';
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
ZeroMemory(&flFromNew, sizeof(FILE_LIST));
|
|
|
|
ZeroMemory(&flToNew, sizeof(FILE_LIST));
|
|
|
|
parse_file_list(&flFromNew, szFrom);
|
|
|
|
parse_file_list(&flToNew, szTo);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
copy_files(op, FALSE, &flFromNew, &flToNew);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
destroy_file_list(&flFromNew);
|
|
|
|
destroy_file_list(&flToNew);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL copy_file_to_file(FILE_OPERATION *op, const WCHAR *szFrom, const WCHAR *szTo)
|
|
|
|
{
|
|
|
|
if (!(op->req->fFlags & FOF_NOCONFIRMATION) && PathFileExistsW(szTo))
|
|
|
|
{
|
|
|
|
if (!SHELL_ConfirmDialogW(op->req->hwnd, ASK_OVERWRITE_FILE, PathFindFileNameW(szTo), op))
|
2016-09-05 07:52:52 +00:00
|
|
|
return FALSE;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
return SHNotifyCopyFileW(op, szFrom, szTo, FALSE) == 0;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy a file or directory to another directory */
|
|
|
|
static void copy_to_dir(FILE_OPERATION *op, const FILE_ENTRY *feFrom, const FILE_ENTRY *feTo)
|
|
|
|
{
|
|
|
|
if (!PathFileExistsW(feTo->szFullPath))
|
|
|
|
SHNotifyCreateDirectoryW(feTo->szFullPath, NULL);
|
|
|
|
|
|
|
|
if (IsAttribFile(feFrom->attributes))
|
|
|
|
{
|
|
|
|
WCHAR szDestPath[MAX_PATH];
|
|
|
|
|
|
|
|
PathCombineW(szDestPath, feTo->szFullPath, feFrom->szFilename);
|
|
|
|
copy_file_to_file(op, feFrom->szFullPath, szDestPath);
|
|
|
|
}
|
|
|
|
else if (!(op->req->fFlags & FOF_FILESONLY && feFrom->bFromWildcard))
|
|
|
|
copy_dir_to_dir(op, feFrom, feTo->szFullPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_dest_dirs(LPCWSTR szDestDir)
|
|
|
|
{
|
|
|
|
WCHAR dir[MAX_PATH];
|
|
|
|
LPCWSTR ptr = StrChrW(szDestDir, '\\');
|
|
|
|
|
|
|
|
/* make sure all directories up to last one are created */
|
|
|
|
while (ptr && (ptr = StrChrW(ptr + 1, '\\')))
|
|
|
|
{
|
|
|
|
lstrcpynW(dir, szDestDir, ptr - szDestDir + 1);
|
|
|
|
|
|
|
|
if (!PathFileExistsW(dir))
|
|
|
|
SHNotifyCreateDirectoryW(dir, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create last directory */
|
|
|
|
if (!PathFileExistsW(szDestDir))
|
|
|
|
SHNotifyCreateDirectoryW(szDestDir, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the FO_COPY operation */
|
2015-02-21 12:52:58 +00:00
|
|
|
static HRESULT copy_files(FILE_OPERATION *op, BOOL multiDest, const FILE_LIST *flFrom, FILE_LIST *flTo)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
const FILE_ENTRY *entryToCopy;
|
|
|
|
const FILE_ENTRY *fileDest = &flTo->feFiles[0];
|
|
|
|
|
|
|
|
if (flFrom->bAnyDontExist)
|
|
|
|
return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
if (flTo->dwNumFiles == 0)
|
|
|
|
{
|
|
|
|
/* If the destination is empty, SHFileOperation should use the current directory */
|
|
|
|
WCHAR curdir[MAX_PATH+1];
|
|
|
|
|
|
|
|
GetCurrentDirectoryW(MAX_PATH, curdir);
|
|
|
|
curdir[lstrlenW(curdir)+1] = 0;
|
|
|
|
|
|
|
|
destroy_file_list(flTo);
|
|
|
|
ZeroMemory(flTo, sizeof(FILE_LIST));
|
|
|
|
parse_file_list(flTo, curdir);
|
|
|
|
fileDest = &flTo->feFiles[0];
|
|
|
|
}
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if (multiDest)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
if (flFrom->bAnyFromWildcard)
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
|
|
|
if (flFrom->dwNumFiles != flTo->dwNumFiles)
|
|
|
|
{
|
|
|
|
if (flFrom->dwNumFiles != 1 && !IsAttribDir(fileDest->attributes))
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
|
|
|
/* Free all but the first entry. */
|
|
|
|
for (i = 1; i < flTo->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, flTo->feFiles[i].szDirectory);
|
|
|
|
HeapFree(GetProcessHeap(), 0, flTo->feFiles[i].szFilename);
|
|
|
|
HeapFree(GetProcessHeap(), 0, flTo->feFiles[i].szFullPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
flTo->dwNumFiles = 1;
|
|
|
|
}
|
|
|
|
else if (IsAttribDir(fileDest->attributes))
|
|
|
|
{
|
|
|
|
for (i = 1; i < flTo->dwNumFiles; i++)
|
|
|
|
if (!IsAttribDir(flTo->feFiles[i].attributes) ||
|
|
|
|
!IsAttribDir(flFrom->feFiles[i].attributes))
|
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (flFrom->dwNumFiles != 1)
|
|
|
|
{
|
|
|
|
if (flTo->dwNumFiles != 1 && !IsAttribDir(fileDest->attributes))
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
|
|
|
if (PathFileExistsW(fileDest->szFullPath) &&
|
|
|
|
IsAttribFile(fileDest->attributes))
|
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flTo->dwNumFiles == 1 && fileDest->bFromRelative &&
|
|
|
|
!PathFileExistsW(fileDest->szFullPath))
|
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < flFrom->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
entryToCopy = &flFrom->feFiles[i];
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if ((multiDest) &&
|
2011-05-15 15:55:49 +00:00
|
|
|
flTo->dwNumFiles > 1)
|
|
|
|
{
|
|
|
|
fileDest = &flTo->feFiles[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsAttribDir(entryToCopy->attributes) &&
|
|
|
|
!lstrcmpiW(entryToCopy->szFullPath, fileDest->szDirectory))
|
|
|
|
{
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
create_dest_dirs(fileDest->szDirectory);
|
|
|
|
|
|
|
|
if (!lstrcmpiW(entryToCopy->szFullPath, fileDest->szFullPath))
|
|
|
|
{
|
|
|
|
if (IsAttribFile(entryToCopy->attributes))
|
|
|
|
return ERROR_NO_MORE_SEARCH_HANDLES;
|
|
|
|
else
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flFrom->dwNumFiles > 1 && flTo->dwNumFiles == 1) ||
|
|
|
|
IsAttribDir(fileDest->attributes))
|
|
|
|
{
|
|
|
|
copy_to_dir(op, entryToCopy, fileDest);
|
|
|
|
}
|
|
|
|
else if (IsAttribDir(entryToCopy->attributes))
|
|
|
|
{
|
|
|
|
copy_dir_to_dir(op, entryToCopy, fileDest->szFullPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!copy_file_to_file(op, entryToCopy->szFullPath, fileDest->szFullPath))
|
|
|
|
{
|
|
|
|
op->req->fAnyOperationsAborted = TRUE;
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
2015-02-21 12:52:58 +00:00
|
|
|
|
|
|
|
if (op->progress != NULL)
|
|
|
|
op->bCancelled |= op->progress->HasUserCancelled();
|
2011-05-15 15:55:49 +00:00
|
|
|
/* Vista return code. XP would return e.g. ERROR_FILE_NOT_FOUND, ERROR_ALREADY_EXISTS */
|
|
|
|
if (op->bCancelled)
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Vista return code. On XP if the used pressed "No" for the last item,
|
|
|
|
* ERROR_ARENA_TRASHED would be returned */
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL confirm_delete_list(HWND hWnd, DWORD fFlags, BOOL fTrash, const FILE_LIST *flFrom)
|
|
|
|
{
|
|
|
|
if (flFrom->dwNumFiles > 1)
|
|
|
|
{
|
|
|
|
WCHAR tmp[8];
|
|
|
|
const WCHAR format[] = {'%','d',0};
|
|
|
|
|
|
|
|
wnsprintfW(tmp, sizeof(tmp)/sizeof(tmp[0]), format, flFrom->dwNumFiles);
|
|
|
|
return SHELL_ConfirmDialogW(hWnd, (fTrash?ASK_TRASH_MULTIPLE_ITEM:ASK_DELETE_MULTIPLE_ITEM), tmp, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const FILE_ENTRY *fileEntry = &flFrom->feFiles[0];
|
|
|
|
|
|
|
|
if (IsAttribFile(fileEntry->attributes))
|
|
|
|
return SHELL_ConfirmDialogW(hWnd, (fTrash?ASK_TRASH_FILE:ASK_DELETE_FILE), fileEntry->szFullPath, NULL);
|
|
|
|
else if (!(fFlags & FOF_FILESONLY && fileEntry->bFromWildcard))
|
|
|
|
return SHELL_ConfirmDialogW(hWnd, (fTrash?ASK_TRASH_FOLDER:ASK_DELETE_FOLDER), fileEntry->szFullPath, NULL);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the FO_DELETE operation */
|
2015-02-21 12:52:58 +00:00
|
|
|
static HRESULT delete_files(FILE_OPERATION *op, const FILE_LIST *flFrom)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
const FILE_ENTRY *fileEntry;
|
|
|
|
DWORD i;
|
|
|
|
BOOL bPathExists;
|
|
|
|
BOOL bTrash;
|
|
|
|
|
|
|
|
if (!flFrom->dwNumFiles)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
/* Windows also checks only the first item */
|
2015-02-21 12:52:58 +00:00
|
|
|
bTrash = (op->req->fFlags & FOF_ALLOWUNDO)
|
2011-05-15 15:55:49 +00:00
|
|
|
&& TRASH_CanTrashFile(flFrom->feFiles[0].szFullPath);
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if (!(op->req->fFlags & FOF_NOCONFIRMATION) || (!bTrash && op->req->fFlags & FOF_WANTNUKEWARNING))
|
|
|
|
if (!confirm_delete_list(op->req->hwnd, op->req->fFlags, bTrash, flFrom))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2015-02-21 12:52:58 +00:00
|
|
|
op->req->fAnyOperationsAborted = TRUE;
|
2011-05-15 15:55:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-20 09:43:09 +00:00
|
|
|
/* Check files. Do not delete one if one file does not exists */
|
|
|
|
for (i = 0; i < flFrom->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
fileEntry = &flFrom->feFiles[i];
|
|
|
|
|
|
|
|
if ((HANDLE)fileEntry->attributes == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
// This is a windows 2003 server specific value which has been removed.
|
|
|
|
// Later versions of windows return ERROR_FILE_NOT_FOUND.
|
|
|
|
return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
for (i = 0; i < flFrom->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
bPathExists = TRUE;
|
|
|
|
fileEntry = &flFrom->feFiles[i];
|
|
|
|
|
|
|
|
if (!IsAttribFile(fileEntry->attributes) &&
|
2015-02-21 12:52:58 +00:00
|
|
|
(op->req->fFlags & FOF_FILESONLY && fileEntry->bFromWildcard))
|
2011-05-15 15:55:49 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (bTrash)
|
|
|
|
{
|
|
|
|
BOOL bDelete;
|
|
|
|
if (TRASH_TrashFile(fileEntry->szFullPath))
|
2014-03-15 13:59:22 +00:00
|
|
|
{
|
|
|
|
SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, fileEntry->szFullPath, NULL);
|
2011-05-15 15:55:49 +00:00
|
|
|
continue;
|
2014-03-15 13:59:22 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/* Note: Windows silently deletes the file in such a situation, we show a dialog */
|
2015-02-21 12:52:58 +00:00
|
|
|
if (!(op->req->fFlags & FOF_NOCONFIRMATION) || (op->req->fFlags & FOF_WANTNUKEWARNING))
|
|
|
|
bDelete = SHELL_ConfirmDialogW(op->req->hwnd, ASK_CANT_TRASH_ITEM, fileEntry->szFullPath, NULL);
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
|
|
|
bDelete = TRUE;
|
|
|
|
|
|
|
|
if (!bDelete)
|
|
|
|
{
|
2015-02-21 12:52:58 +00:00
|
|
|
op->req->fAnyOperationsAborted = TRUE;
|
2011-05-15 15:55:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete the file or directory */
|
|
|
|
if (IsAttribFile(fileEntry->attributes))
|
2014-03-15 13:59:22 +00:00
|
|
|
{
|
2015-02-21 12:52:58 +00:00
|
|
|
bPathExists = (ERROR_SUCCESS == SHNotifyDeleteFileW(op, fileEntry->szFullPath));
|
2014-03-15 13:59:22 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
2015-02-21 12:52:58 +00:00
|
|
|
bPathExists = SHELL_DeleteDirectoryW(op, fileEntry->szFullPath, FALSE);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (!bPathExists)
|
2011-09-03 14:20:03 +00:00
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
|
|
|
|
if (ERROR_FILE_NOT_FOUND == err)
|
|
|
|
{
|
|
|
|
// This is a windows 2003 server specific value which ahs been removed.
|
|
|
|
// Later versions of windows return ERROR_FILE_NOT_FOUND.
|
2016-08-20 09:43:09 +00:00
|
|
|
return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND;
|
2011-09-03 14:20:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
2015-02-21 12:52:58 +00:00
|
|
|
|
|
|
|
if (op->progress != NULL)
|
|
|
|
op->bCancelled |= op->progress->HasUserCancelled();
|
|
|
|
/* Should fire on progress dialog only */
|
|
|
|
if (op->bCancelled)
|
|
|
|
return ERROR_CANCELLED;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
static void move_dir_to_dir(FILE_OPERATION *op, const FILE_ENTRY *feFrom, LPCWSTR szDestPath)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
WCHAR szFrom[MAX_PATH], szTo[MAX_PATH];
|
2015-02-21 12:52:58 +00:00
|
|
|
FILE_LIST flFromNew, flToNew;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
static const WCHAR wildCardFiles[] = {'*','.','*',0};
|
|
|
|
|
|
|
|
if (IsDotDir(feFrom->szFilename))
|
|
|
|
return;
|
|
|
|
|
|
|
|
SHNotifyCreateDirectoryW(szDestPath, NULL);
|
|
|
|
|
|
|
|
PathCombineW(szFrom, feFrom->szFullPath, wildCardFiles);
|
|
|
|
szFrom[lstrlenW(szFrom) + 1] = '\0';
|
|
|
|
|
|
|
|
lstrcpyW(szTo, szDestPath);
|
|
|
|
szTo[lstrlenW(szDestPath) + 1] = '\0';
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
ZeroMemory(&flFromNew, sizeof(FILE_LIST));
|
|
|
|
ZeroMemory(&flToNew, sizeof(FILE_LIST));
|
|
|
|
parse_file_list(&flFromNew, szFrom);
|
|
|
|
parse_file_list(&flToNew, szTo);
|
|
|
|
|
|
|
|
move_files(op, FALSE, &flFromNew, &flToNew);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
destroy_file_list(&flFromNew);
|
|
|
|
destroy_file_list(&flToNew);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* moves a file or directory to another directory */
|
2015-02-21 12:52:58 +00:00
|
|
|
static void move_to_dir(FILE_OPERATION *op, const FILE_ENTRY *feFrom, const FILE_ENTRY *feTo)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
WCHAR szDestPath[MAX_PATH];
|
|
|
|
|
|
|
|
PathCombineW(szDestPath, feTo->szFullPath, feFrom->szFilename);
|
|
|
|
|
|
|
|
if (IsAttribFile(feFrom->attributes))
|
2015-02-21 12:52:58 +00:00
|
|
|
SHNotifyMoveFileW(op, feFrom->szFullPath, szDestPath, FALSE);
|
|
|
|
else if (!(op->req->fFlags & FOF_FILESONLY && feFrom->bFromWildcard))
|
|
|
|
move_dir_to_dir(op, feFrom, szDestPath);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the FO_MOVE operation */
|
2015-02-21 12:52:58 +00:00
|
|
|
static DWORD move_files(FILE_OPERATION *op, BOOL multiDest, const FILE_LIST *flFrom, const FILE_LIST *flTo)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
DWORD i;
|
2014-11-02 16:12:38 +00:00
|
|
|
INT mismatched = 0;
|
2015-02-21 12:52:58 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
const FILE_ENTRY *entryToMove;
|
|
|
|
const FILE_ENTRY *fileDest;
|
|
|
|
|
2014-11-02 16:12:38 +00:00
|
|
|
if (!flFrom->dwNumFiles)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
if (!flTo->dwNumFiles)
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if (!(multiDest) &&
|
2011-05-15 15:55:49 +00:00
|
|
|
flTo->dwNumFiles > 1 && flFrom->dwNumFiles > 1)
|
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if (!(multiDest) &&
|
2011-05-15 15:55:49 +00:00
|
|
|
!flFrom->bAnyDirectories &&
|
|
|
|
flFrom->dwNumFiles > flTo->dwNumFiles)
|
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PathFileExistsW(flTo->feFiles[0].szDirectory))
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if (multiDest)
|
2014-11-02 16:12:38 +00:00
|
|
|
mismatched = flFrom->dwNumFiles - flTo->dwNumFiles;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
fileDest = &flTo->feFiles[0];
|
|
|
|
for (i = 0; i < flFrom->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
entryToMove = &flFrom->feFiles[i];
|
|
|
|
|
|
|
|
if (!PathFileExistsW(fileDest->szDirectory))
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if (multiDest)
|
2014-11-02 16:12:38 +00:00
|
|
|
{
|
|
|
|
if (i >= flTo->dwNumFiles)
|
|
|
|
break;
|
|
|
|
fileDest = &flTo->feFiles[i];
|
|
|
|
if (mismatched && !fileDest->bExists)
|
|
|
|
{
|
|
|
|
create_dest_dirs(flTo->feFiles[i].szFullPath);
|
|
|
|
flTo->feFiles[i].bExists = TRUE;
|
|
|
|
flTo->feFiles[i].attributes = FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
if (fileDest->bExists && IsAttribDir(fileDest->attributes))
|
2015-02-21 12:52:58 +00:00
|
|
|
move_to_dir(op, entryToMove, fileDest);
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
2015-02-21 12:52:58 +00:00
|
|
|
SHNotifyMoveFileW(op, entryToMove->szFullPath, fileDest->szFullPath, IsAttribDir(entryToMove->attributes));
|
|
|
|
|
|
|
|
if (op->progress != NULL)
|
|
|
|
op->bCancelled |= op->progress->HasUserCancelled();
|
|
|
|
/* Should fire on progress dialog only */
|
|
|
|
if (op->bCancelled)
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2014-11-02 16:12:38 +00:00
|
|
|
if (mismatched > 0)
|
|
|
|
{
|
|
|
|
if (flFrom->bAnyDirectories)
|
|
|
|
return DE_DESTSAMETREE;
|
|
|
|
else
|
|
|
|
return DE_SAMEFILE;
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the FO_RENAME files */
|
2015-02-21 12:52:58 +00:00
|
|
|
static HRESULT rename_files(FILE_OPERATION *op, const FILE_LIST *flFrom, const FILE_LIST *flTo)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
const FILE_ENTRY *feFrom;
|
|
|
|
const FILE_ENTRY *feTo;
|
|
|
|
|
|
|
|
if (flFrom->dwNumFiles != 1)
|
|
|
|
return ERROR_GEN_FAILURE;
|
|
|
|
|
|
|
|
if (flTo->dwNumFiles != 1)
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
|
|
|
feFrom = &flFrom->feFiles[0];
|
|
|
|
feTo= &flTo->feFiles[0];
|
|
|
|
|
|
|
|
/* fail if destination doesn't exist */
|
|
|
|
if (!feFrom->bExists)
|
|
|
|
return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
/* fail if destination already exists */
|
|
|
|
if (feTo->bExists)
|
|
|
|
return ERROR_ALREADY_EXISTS;
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
return SHNotifyMoveFileW(op, feFrom->szFullPath, feTo->szFullPath, IsAttribDir(feFrom->attributes));
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* alert the user if an unsupported flag is used */
|
|
|
|
static void check_flags(FILEOP_FLAGS fFlags)
|
|
|
|
{
|
|
|
|
WORD wUnsupportedFlags = FOF_NO_CONNECTED_ELEMENTS |
|
|
|
|
FOF_NOCOPYSECURITYATTRIBS | FOF_NORECURSEREPARSE |
|
|
|
|
FOF_RENAMEONCOLLISION | FOF_WANTMAPPINGHANDLE;
|
|
|
|
|
|
|
|
if (fFlags & wUnsupportedFlags)
|
|
|
|
FIXME("Unsupported flags: %04x\n", fFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHFileOperationW [SHELL32.@]
|
|
|
|
*
|
|
|
|
* See SHFileOperationA
|
|
|
|
*/
|
|
|
|
int WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
|
|
|
|
{
|
|
|
|
FILE_OPERATION op;
|
|
|
|
FILE_LIST flFrom, flTo;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!lpFileOp)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2015-02-21 14:36:22 +00:00
|
|
|
ret = CoInitialize(NULL);
|
|
|
|
if (FAILED(ret))
|
|
|
|
return ret;
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
check_flags(lpFileOp->fFlags);
|
|
|
|
|
|
|
|
ZeroMemory(&flFrom, sizeof(FILE_LIST));
|
|
|
|
ZeroMemory(&flTo, sizeof(FILE_LIST));
|
|
|
|
|
|
|
|
if ((ret = parse_file_list(&flFrom, lpFileOp->pFrom)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (lpFileOp->wFunc != FO_DELETE)
|
|
|
|
parse_file_list(&flTo, lpFileOp->pTo);
|
|
|
|
|
|
|
|
ZeroMemory(&op, sizeof(op));
|
|
|
|
op.req = lpFileOp;
|
2015-02-21 12:52:58 +00:00
|
|
|
op.totalSize.QuadPart = 0ull;
|
|
|
|
op.completedSize.QuadPart = 0ull;
|
2011-05-15 15:55:49 +00:00
|
|
|
op.bManyItems = (flFrom.dwNumFiles > 1);
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if (lpFileOp->wFunc != FO_RENAME && !(lpFileOp->fFlags & FOF_SILENT)) {
|
2015-02-21 14:36:22 +00:00
|
|
|
ret = CoCreateInstance(CLSID_ProgressDialog,
|
|
|
|
NULL,
|
|
|
|
CLSCTX_INPROC_SERVER,
|
|
|
|
IID_PPV_ARG(IProgressDialog, &op.progress));
|
|
|
|
if (FAILED(ret))
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
op.progress->StartProgressDialog(op.req->hwnd, NULL, PROGDLG_NORMAL & PROGDLG_AUTOTIME, NULL);
|
|
|
|
_SetOperationTitle(&op);
|
|
|
|
_FileOpCountManager(&op, &flFrom);
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
switch (lpFileOp->wFunc)
|
|
|
|
{
|
|
|
|
case FO_COPY:
|
2015-02-21 12:52:58 +00:00
|
|
|
ret = copy_files(&op, op.req->fFlags & FOF_MULTIDESTFILES, &flFrom, &flTo);
|
2011-05-15 15:55:49 +00:00
|
|
|
break;
|
|
|
|
case FO_DELETE:
|
2015-02-21 12:52:58 +00:00
|
|
|
ret = delete_files(&op, &flFrom);
|
2011-05-15 15:55:49 +00:00
|
|
|
break;
|
|
|
|
case FO_MOVE:
|
2015-02-21 12:52:58 +00:00
|
|
|
ret = move_files(&op, op.req->fFlags & FOF_MULTIDESTFILES, &flFrom, &flTo);
|
2011-05-15 15:55:49 +00:00
|
|
|
break;
|
|
|
|
case FO_RENAME:
|
2015-02-21 12:52:58 +00:00
|
|
|
ret = rename_files(&op, &flFrom, &flTo);
|
2011-05-15 15:55:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-02-21 12:52:58 +00:00
|
|
|
if (op.progress) {
|
|
|
|
op.progress->StopProgressDialog();
|
|
|
|
op.progress->Release();
|
|
|
|
}
|
|
|
|
|
2015-02-21 14:36:22 +00:00
|
|
|
cleanup:
|
2011-05-15 15:55:49 +00:00
|
|
|
destroy_file_list(&flFrom);
|
|
|
|
|
|
|
|
if (lpFileOp->wFunc != FO_DELETE)
|
|
|
|
destroy_file_list(&flTo);
|
|
|
|
|
|
|
|
if (ret == ERROR_CANCELLED)
|
|
|
|
lpFileOp->fAnyOperationsAborted = TRUE;
|
|
|
|
|
2015-02-21 14:36:22 +00:00
|
|
|
CoUninitialize();
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-09 12:54:29 +00:00
|
|
|
// Used by SHFreeNameMappings
|
|
|
|
static int CALLBACK _DestroyCallback(void *p, void *pData)
|
|
|
|
{
|
|
|
|
LPSHNAMEMAPPINGW lp = (SHNAMEMAPPINGW *)p;
|
|
|
|
|
|
|
|
SHFree(lp->pszOldPath);
|
|
|
|
SHFree(lp->pszNewPath);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHFreeNameMappings [shell32.246]
|
|
|
|
*
|
|
|
|
* Free the mapping handle returned by SHFileOperation if FOF_WANTSMAPPINGHANDLE
|
|
|
|
* was specified.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hNameMapping [I] handle to the name mappings used during renaming of files
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*/
|
|
|
|
void WINAPI SHFreeNameMappings(HANDLE hNameMapping)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
if (hNameMapping)
|
|
|
|
{
|
2014-10-09 12:54:29 +00:00
|
|
|
DSA_DestroyCallback((HDSA) hNameMapping, _DestroyCallback, NULL);
|
2011-09-03 00:13:22 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SheGetDirA [SHELL32.@]
|
|
|
|
*
|
|
|
|
* drive = 0: returns the current directory path
|
|
|
|
* drive > 0: returns the current directory path of the specified drive
|
|
|
|
* drive=1 -> A: drive=2 -> B: ...
|
|
|
|
* returns 0 if successful
|
|
|
|
*/
|
|
|
|
EXTERN_C DWORD WINAPI SheGetDirA(DWORD drive, LPSTR buffer)
|
|
|
|
{
|
|
|
|
WCHAR org_path[MAX_PATH];
|
|
|
|
DWORD ret;
|
|
|
|
char drv_path[3];
|
|
|
|
|
|
|
|
/* change current directory to the specified drive */
|
|
|
|
if (drive) {
|
|
|
|
strcpy(drv_path, "A:");
|
|
|
|
drv_path[0] += (char)drive-1;
|
|
|
|
|
|
|
|
GetCurrentDirectoryW(MAX_PATH, org_path);
|
|
|
|
|
|
|
|
SetCurrentDirectoryA(drv_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* query current directory path of the specified drive */
|
|
|
|
ret = GetCurrentDirectoryA(MAX_PATH, buffer);
|
|
|
|
|
|
|
|
/* back to the original drive */
|
|
|
|
if (drive)
|
|
|
|
SetCurrentDirectoryW(org_path);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return GetLastError();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SheGetDirW [SHELL32.@]
|
|
|
|
*
|
|
|
|
* drive = 0: returns the current directory path
|
|
|
|
* drive > 0: returns the current directory path of the specified drive
|
|
|
|
* drive=1 -> A: drive=2 -> B: ...
|
|
|
|
* returns 0 if successful
|
|
|
|
*/
|
|
|
|
EXTERN_C DWORD WINAPI SheGetDirW(DWORD drive, LPWSTR buffer)
|
|
|
|
{
|
|
|
|
WCHAR org_path[MAX_PATH];
|
|
|
|
DWORD ret;
|
|
|
|
char drv_path[3];
|
|
|
|
|
|
|
|
/* change current directory to the specified drive */
|
2011-09-03 00:08:11 +00:00
|
|
|
if (drive)
|
2011-09-03 00:13:22 +00:00
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
strcpy(drv_path, "A:");
|
|
|
|
drv_path[0] += (char)drive-1;
|
|
|
|
|
|
|
|
GetCurrentDirectoryW(MAX_PATH, org_path);
|
|
|
|
|
|
|
|
SetCurrentDirectoryA(drv_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* query current directory path of the specified drive */
|
|
|
|
ret = GetCurrentDirectoryW(MAX_PATH, buffer);
|
|
|
|
|
|
|
|
/* back to the original drive */
|
|
|
|
if (drive)
|
|
|
|
SetCurrentDirectoryW(org_path);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return GetLastError();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SheChangeDirA [SHELL32.@]
|
|
|
|
*
|
|
|
|
* changes the current directory to the specified path
|
|
|
|
* and returns 0 if successful
|
|
|
|
*/
|
|
|
|
EXTERN_C DWORD WINAPI SheChangeDirA(LPSTR path)
|
|
|
|
{
|
|
|
|
if (SetCurrentDirectoryA(path))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SheChangeDirW [SHELL32.@]
|
|
|
|
*
|
|
|
|
* changes the current directory to the specified path
|
|
|
|
* and returns 0 if successful
|
|
|
|
*/
|
|
|
|
EXTERN_C DWORD WINAPI SheChangeDirW(LPWSTR path)
|
|
|
|
{
|
|
|
|
if (SetCurrentDirectoryW(path))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 00:13:22 +00:00
|
|
|
* IsNetDrive [SHELL32.66]
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
|
|
|
EXTERN_C int WINAPI IsNetDrive(int drive)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
char root[4];
|
|
|
|
strcpy(root, "A:\\");
|
|
|
|
root[0] += (char)drive;
|
|
|
|
return (GetDriveTypeA(root) == DRIVE_REMOTE);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* RealDriveType [SHELL32.524]
|
|
|
|
*/
|
|
|
|
EXTERN_C INT WINAPI RealDriveType(INT drive, BOOL bQueryNet)
|
|
|
|
{
|
|
|
|
char root[] = "A:\\";
|
|
|
|
root[0] += (char)drive;
|
|
|
|
return GetDriveTypeA(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SHPathPrepareForWriteW (SHELL32.@)
|
|
|
|
*/
|
|
|
|
EXTERN_C HRESULT WINAPI SHPathPrepareForWriteW(HWND hwnd, IUnknown *modless, LPCWSTR path, DWORD flags)
|
|
|
|
{
|
2011-09-03 00:13:22 +00:00
|
|
|
DWORD res;
|
2011-05-15 15:55:49 +00:00
|
|
|
DWORD err;
|
|
|
|
LPCWSTR realpath;
|
|
|
|
int len;
|
|
|
|
WCHAR* last_slash;
|
|
|
|
WCHAR* temppath=NULL;
|
|
|
|
|
2016-09-05 07:52:52 +00:00
|
|
|
TRACE("%p %p %s 0x%08x\n", hwnd, modless, debugstr_w(path), flags);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (flags & ~(SHPPFW_DIRCREATE|SHPPFW_ASKDIRCREATE|SHPPFW_IGNOREFILENAME))
|
|
|
|
FIXME("unimplemented flags 0x%08x\n", flags);
|
|
|
|
|
|
|
|
/* cut off filename if necessary */
|
|
|
|
if (flags & SHPPFW_IGNOREFILENAME)
|
|
|
|
{
|
|
|
|
last_slash = StrRChrW(path, NULL, '\\');
|
|
|
|
if (last_slash == NULL)
|
|
|
|
len = 1;
|
|
|
|
else
|
|
|
|
len = last_slash - path + 1;
|
|
|
|
temppath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!temppath)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
StrCpyNW(temppath, path, len);
|
|
|
|
realpath = temppath;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
realpath = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to create the directory if asked to */
|
|
|
|
if (flags & (SHPPFW_DIRCREATE|SHPPFW_ASKDIRCREATE))
|
|
|
|
{
|
|
|
|
if (flags & SHPPFW_ASKDIRCREATE)
|
|
|
|
FIXME("treating SHPPFW_ASKDIRCREATE as SHPPFW_DIRCREATE\n");
|
|
|
|
|
|
|
|
SHCreateDirectoryExW(0, realpath, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we can access the directory */
|
|
|
|
res = GetFileAttributesW(realpath);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, temppath);
|
|
|
|
|
|
|
|
if (res == INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
err = GetLastError();
|
|
|
|
if (err == ERROR_FILE_NOT_FOUND)
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
|
|
|
|
return HRESULT_FROM_WIN32(err);
|
|
|
|
}
|
|
|
|
else if (res & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
return S_OK;
|
|
|
|
else
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_DIRECTORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SHPathPrepareForWriteA (SHELL32.@)
|
|
|
|
*/
|
|
|
|
EXTERN_C HRESULT WINAPI SHPathPrepareForWriteA(HWND hwnd, IUnknown *modless, LPCSTR path, DWORD flags)
|
|
|
|
{
|
|
|
|
WCHAR wpath[MAX_PATH];
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, path, -1, wpath, MAX_PATH);
|
|
|
|
return SHPathPrepareForWriteW(hwnd, modless, wpath, flags);
|
|
|
|
}
|
2015-02-21 12:52:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The two following background operations were modified from filedefext.cpp
|
|
|
|
* They use an inordinate amount of mutable state across the string functions,
|
|
|
|
* so are not easy to follow and care is required when modifying.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
_FileOpCountManager(FILE_OPERATION *op, const FILE_LIST *from)
|
|
|
|
{
|
|
|
|
DWORD ticks = GetTickCount();
|
|
|
|
FILE_ENTRY *entryToCount;
|
|
|
|
|
|
|
|
for (UINT i = 0; i < from->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
entryToCount = &from->feFiles[i];
|
|
|
|
|
|
|
|
WCHAR theFileName[MAX_PATH];
|
|
|
|
StringCchCopyW(theFileName, MAX_PATH, entryToCount->szFullPath);
|
|
|
|
_FileOpCount(op, theFileName, IsAttribDir(entryToCount->attributes), &ticks);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All path manipulations, even when this function is nested, occur on the one buffer.
|
|
|
|
static BOOL
|
|
|
|
_FileOpCount(FILE_OPERATION *op, LPWSTR pwszBuf, BOOL bFolder, DWORD *ticks)
|
|
|
|
{
|
|
|
|
/* Find filename position */
|
|
|
|
UINT cchBuf = wcslen(pwszBuf);
|
|
|
|
WCHAR *pwszFilename = pwszBuf + cchBuf;
|
|
|
|
size_t cchFilenameMax = MAX_PATH - cchBuf;
|
|
|
|
if (!cchFilenameMax)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (bFolder) {
|
|
|
|
*(pwszFilename++) = '\\';
|
|
|
|
--cchFilenameMax;
|
|
|
|
/* Find all files, FIXME: shouldn't be "*"? */
|
|
|
|
StringCchCopyW(pwszFilename, cchFilenameMax, L"*");
|
|
|
|
}
|
|
|
|
|
|
|
|
WIN32_FIND_DATAW wfd;
|
|
|
|
HANDLE hFind = FindFirstFileW(pwszBuf, &wfd);
|
|
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ERR("FindFirstFileW %ls failed\n", pwszBuf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
|
|
|
/* Don't process "." and ".." items */
|
|
|
|
if (!wcscmp(wfd.cFileName, L".") || !wcscmp(wfd.cFileName, L".."))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
StringCchCopyW(pwszFilename, cchFilenameMax, wfd.cFileName);
|
|
|
|
_FileOpCount(op, pwszBuf, TRUE, ticks);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER FileSize;
|
|
|
|
FileSize.u.LowPart = wfd.nFileSizeLow;
|
|
|
|
FileSize.u.HighPart = wfd.nFileSizeHigh;
|
|
|
|
op->totalSize.QuadPart += FileSize.QuadPart;
|
|
|
|
}
|
|
|
|
if (GetTickCount() - *ticks > (DWORD) 500)
|
|
|
|
{
|
|
|
|
// Check if the dialog has ended. If it has, we'll spin down.
|
|
|
|
if (op->progress != NULL)
|
|
|
|
op->bCancelled = op->progress->HasUserCancelled();
|
|
|
|
|
|
|
|
if (op->bCancelled)
|
|
|
|
break;
|
|
|
|
*ticks = GetTickCount();
|
|
|
|
}
|
|
|
|
} while(FindNextFileW(hFind, &wfd));
|
|
|
|
|
|
|
|
FindClose(hFind);
|
|
|
|
return TRUE;
|
|
|
|
}
|