2000-02-20 19:39:11 +01:00
|
|
|
/*
|
|
|
|
* SHFileOperation
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* Copyright 2000 Juergen Schmied
|
2002-09-04 20:46:29 +02:00
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
2004-10-22 00:29:42 +02:00
|
|
|
* Copyright 2004 Dietrich Teickner (from Odin)
|
|
|
|
* Copyright 2004 Rolf Kalbermatter
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-02-20 19:39:11 +01:00
|
|
|
*/
|
2002-12-16 23:40:34 +01:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-02-20 19:39:11 +01:00
|
|
|
#include <string.h>
|
2003-03-21 22:23:33 +01:00
|
|
|
#include <ctype.h>
|
2007-02-09 17:13:25 +01:00
|
|
|
#include <assert.h>
|
2000-02-20 19:39:11 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2001-11-06 23:31:19 +01:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "shellapi.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2000-02-26 19:48:16 +01:00
|
|
|
#include "shlobj.h"
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
#include "shresdef.h"
|
2003-04-19 22:09:09 +02:00
|
|
|
#define NO_SHLWAPI_STREAM
|
|
|
|
#include "shlwapi.h"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "shell32_main.h"
|
2001-08-16 20:49:56 +02:00
|
|
|
#include "undocshell.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2006-07-19 18:37:02 +02:00
|
|
|
#include "xdg.h"
|
2000-02-26 19:48:16 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
2000-02-20 19:39:11 +01:00
|
|
|
|
2004-10-18 23:45:16 +02:00
|
|
|
#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)
|
2003-03-21 22:23:33 +01:00
|
|
|
#define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
|
|
|
|
|
2003-04-19 22:09:09 +02:00
|
|
|
#define FO_MASK 0xF
|
|
|
|
|
2004-10-18 23:45:16 +02:00
|
|
|
static const WCHAR wWildcardFile[] = {'*',0};
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wWildcardChars[] = {'*','?',0};
|
2003-03-21 22:23:33 +01:00
|
|
|
|
2003-09-02 20:12:44 +02:00
|
|
|
static DWORD SHNotifyCreateDirectoryA(LPCSTR path, LPSECURITY_ATTRIBUTES sec);
|
|
|
|
static DWORD SHNotifyCreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sec);
|
|
|
|
static DWORD SHNotifyRemoveDirectoryA(LPCSTR path);
|
|
|
|
static DWORD SHNotifyRemoveDirectoryW(LPCWSTR path);
|
|
|
|
static DWORD SHNotifyDeleteFileA(LPCSTR path);
|
|
|
|
static DWORD SHNotifyDeleteFileW(LPCWSTR path);
|
2004-10-22 00:29:42 +02:00
|
|
|
static DWORD SHNotifyMoveFileW(LPCWSTR src, LPCWSTR dest);
|
|
|
|
static DWORD SHNotifyCopyFileW(LPCWSTR src, LPCWSTR dest, BOOL bFailIfExists);
|
|
|
|
static DWORD SHFindAttrW(LPCWSTR pName, BOOL fileOnly);
|
2003-03-21 22:23:33 +01:00
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
SHFILEOPSTRUCTW *req;
|
|
|
|
DWORD dwYesToAllMask;
|
|
|
|
BOOL bManyItems;
|
|
|
|
BOOL bCancelled;
|
|
|
|
} FILE_OPERATION;
|
|
|
|
|
2007-02-09 16:59:43 +01: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;
|
|
|
|
|
|
|
|
if (bShow) {
|
|
|
|
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 CALLBACK ConfirmMsgBox_Paint(HWND hDlg)
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HFONT hOldFont;
|
|
|
|
RECT r;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
BeginPaint(hDlg, &ps);
|
|
|
|
hdc = ps.hdc;
|
|
|
|
|
|
|
|
GetClientRect(GetDlgItem(hDlg, IDD_MESSAGE), &r);
|
|
|
|
/* this will remap the rect to dialog coords */
|
|
|
|
MapWindowPoints(GetDlgItem(hDlg, IDD_MESSAGE), hDlg, (LPPOINT)&r, 2);
|
|
|
|
hOldFont = SelectObject(hdc, (HFONT)SendDlgItemMessageW(hDlg, IDD_MESSAGE, WM_GETFONT, 0, 0));
|
|
|
|
DrawTextW(hdc, (LPWSTR)GetPropW(hDlg, CONFIRM_MSG_PROP), -1, &r, DT_NOPREFIX | DT_PATH_ELLIPSIS | DT_WORDBREAK);
|
|
|
|
SelectObject(hdc, hOldFont);
|
|
|
|
EndPaint(hDlg, &ps);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK 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);
|
|
|
|
ShowWindow(GetDlgItem(hDlg, IDD_MESSAGE), SW_HIDE);
|
|
|
|
SetPropW(hDlg, CONFIRM_MSG_PROP, (HANDLE)info->lpszText);
|
|
|
|
SendDlgItemMessageW(hDlg, IDD_ICON, STM_SETICON, (WPARAM)info->hIcon, 0);
|
|
|
|
|
|
|
|
/* compute the text height and resize the dialog */
|
|
|
|
GetClientRect(GetDlgItem(hDlg, IDD_MESSAGE), &r);
|
|
|
|
hdc = GetDC(hDlg);
|
|
|
|
yOffset = r.bottom;
|
|
|
|
hOldFont = SelectObject(hdc, (HFONT)SendDlgItemMessageW(hDlg, IDD_MESSAGE, WM_GETFONT, 0, 0));
|
|
|
|
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);
|
|
|
|
confirm_msg_move_button(hDlg, IDD_YESTOALL, &xPos, yOffset, info->bYesToAll);
|
|
|
|
confirm_msg_move_button(hDlg, IDYES, &xPos, yOffset, TRUE);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SHELL_ConfirmMsgBox(HWND hWnd, LPWSTR lpszText, LPWSTR lpszCaption, HICON hIcon, BOOL bYesToAll)
|
|
|
|
{
|
|
|
|
static const WCHAR wszTemplate[] = {'S','H','E','L','L','_','Y','E','S','T','O','A','L','L','_','M','S','G','B','O','X',0};
|
|
|
|
struct confirm_msg_info info;
|
|
|
|
|
|
|
|
info.lpszText = lpszText;
|
|
|
|
info.lpszCaption = lpszCaption;
|
|
|
|
info.hIcon = hIcon;
|
|
|
|
info.bYesToAll = bYesToAll;
|
|
|
|
return DialogBoxParamW(shell32_hInstance, wszTemplate, hWnd, ConfirmMsgBoxProc, (LPARAM)&info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* confirmation dialogs content */
|
2003-03-21 22:23:33 +01:00
|
|
|
typedef struct
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
{
|
2006-06-30 22:47:12 +02:00
|
|
|
HINSTANCE hIconInstance;
|
|
|
|
UINT icon_resource_id;
|
2002-12-19 05:11:22 +01:00
|
|
|
UINT caption_resource_id, text_resource_id;
|
2003-03-21 22:23:33 +01:00
|
|
|
} SHELL_ConfirmIDstruc;
|
2002-12-19 05:11:22 +01:00
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
static BOOL SHELL_ConfirmIDs(int nKindOfDialog, SHELL_ConfirmIDstruc *ids)
|
|
|
|
{
|
2006-06-30 22:50:28 +02:00
|
|
|
ids->hIconInstance = shell32_hInstance;
|
2003-03-21 22:23:33 +01:00
|
|
|
switch (nKindOfDialog) {
|
|
|
|
case ASK_DELETE_FILE:
|
2006-06-30 22:50:28 +02:00
|
|
|
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
|
2003-03-21 22:23:33 +01:00
|
|
|
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_DELETEITEM_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
case ASK_DELETE_FOLDER:
|
2006-06-30 22:50:28 +02:00
|
|
|
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
|
2003-03-21 22:23:33 +01:00
|
|
|
ids->caption_resource_id = IDS_DELETEFOLDER_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_DELETEITEM_TEXT;
|
|
|
|
return TRUE;
|
|
|
|
case ASK_DELETE_MULTIPLE_ITEM:
|
2006-06-30 22:50:28 +02:00
|
|
|
ids->icon_resource_id = IDI_SHELL_CONFIRM_DELETE;
|
2003-03-21 22:23:33 +01:00
|
|
|
ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_DELETEMULTIPLE_TEXT;
|
|
|
|
return TRUE;
|
2006-07-19 18:36:22 +02:00
|
|
|
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;
|
2006-07-19 18:37:02 +02:00
|
|
|
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;
|
2006-07-06 20:46:21 +02:00
|
|
|
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;
|
2003-03-21 22:23:33 +01:00
|
|
|
case ASK_OVERWRITE_FILE:
|
2006-06-30 22:50:28 +02:00
|
|
|
ids->hIconInstance = NULL;
|
|
|
|
ids->icon_resource_id = IDI_WARNING;
|
2003-03-21 22:23:33 +01:00
|
|
|
ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_OVERWRITEFILE_TEXT;
|
2007-02-09 17:13:25 +01:00
|
|
|
return TRUE;
|
|
|
|
case ASK_OVERWRITE_FOLDER:
|
|
|
|
ids->hIconInstance = NULL;
|
|
|
|
ids->icon_resource_id = IDI_WARNING;
|
|
|
|
ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION;
|
|
|
|
ids->text_resource_id = IDS_OVERWRITEFOLDER_TEXT;
|
|
|
|
return TRUE;
|
2003-03-21 22:23:33 +01:00
|
|
|
default:
|
|
|
|
FIXME(" Unhandled nKindOfDialog %d stub\n", nKindOfDialog);
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2003-03-21 22:23:33 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
static BOOL SHELL_ConfirmDialogW(HWND hWnd, int nKindOfDialog, LPCWSTR szDir, FILE_OPERATION *op)
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
|
|
|
WCHAR szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
|
|
|
|
SHELL_ConfirmIDstruc ids;
|
2006-10-01 01:04:02 +02:00
|
|
|
DWORD_PTR args[1];
|
2007-02-09 16:59:43 +01:00
|
|
|
HICON hIcon;
|
2007-02-09 17:13:25 +01:00
|
|
|
int ret;
|
2003-03-21 22:23:33 +01:00
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
assert(nKindOfDialog >= 0 && nKindOfDialog < 32);
|
|
|
|
if (op && (op->dwYesToAllMask & (1 << nKindOfDialog)))
|
2007-02-14 14:43:50 +01:00
|
|
|
return TRUE;
|
2007-02-09 17:13:25 +01:00
|
|
|
|
2007-02-14 14:43:50 +01:00
|
|
|
if (!SHELL_ConfirmIDs(nKindOfDialog, &ids)) return FALSE;
|
2003-03-21 22:23:33 +01:00
|
|
|
|
2006-06-20 21:58:20 +02: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));
|
2003-03-21 22:23:33 +01:00
|
|
|
|
2006-10-01 01:04:02 +02:00
|
|
|
args[0] = (DWORD_PTR)szDir;
|
2003-03-21 22:23:33 +01:00
|
|
|
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
2006-10-01 01:04:02 +02:00
|
|
|
szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)args);
|
2007-02-09 16:59:43 +01:00
|
|
|
hIcon = LoadIconW(ids.hIconInstance, (LPWSTR)MAKEINTRESOURCE(ids.icon_resource_id));
|
2003-03-21 22:23:33 +01:00
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
ret = SHELL_ConfirmMsgBox(hWnd, szBuffer, szCaption, hIcon, op && op->bManyItems);
|
|
|
|
if (op) {
|
|
|
|
if (ret == IDD_YESTOALL) {
|
|
|
|
op->dwYesToAllMask |= (1 << nKindOfDialog);
|
|
|
|
ret = IDYES;
|
|
|
|
}
|
|
|
|
if (ret == IDCANCEL)
|
|
|
|
op->bCancelled = TRUE;
|
|
|
|
if (ret != IDYES)
|
|
|
|
op->req->fAnyOperationsAborted = TRUE;
|
|
|
|
}
|
|
|
|
return ret == IDYES;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL SHELL_ConfirmYesNoW(HWND hWnd, int nKindOfDialog, LPCWSTR szDir)
|
|
|
|
{
|
|
|
|
return SHELL_ConfirmDialogW(hWnd, nKindOfDialog, szDir, NULL);
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
|
2004-10-27 23:18:35 +02:00
|
|
|
static DWORD SHELL32_AnsiToUnicodeBuf(LPCSTR aPath, LPWSTR *wPath, DWORD minChars)
|
2004-10-18 23:45:16 +02:00
|
|
|
{
|
|
|
|
DWORD len = MultiByteToWideChar(CP_ACP, 0, aPath, -1, NULL, 0);
|
|
|
|
|
2004-10-27 23:18:35 +02:00
|
|
|
if (len < minChars)
|
|
|
|
len = minChars;
|
2004-10-18 23:45:16 +02:00
|
|
|
|
2004-10-27 23:18:35 +02:00
|
|
|
*wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
2004-10-18 23:45:16 +02:00
|
|
|
if (*wPath)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, aPath, -1, *wPath, len);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SHELL32_FreeUnicodeBuf(LPWSTR wPath)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, wPath);
|
|
|
|
}
|
|
|
|
|
2006-07-07 14:38:18 +02:00
|
|
|
HRESULT WINAPI SHIsFileAvailableOffline(LPCWSTR path, LPDWORD status)
|
|
|
|
{
|
|
|
|
FIXME("(%s, %p) stub\n", debugstr_w(path), status);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2000-02-26 19:48:16 +01:00
|
|
|
/**************************************************************************
|
2004-10-22 00:29:42 +02:00
|
|
|
* SHELL_DeleteDirectory() [internal]
|
2000-02-26 19:48:16 +01:00
|
|
|
*
|
2004-10-22 00:29:42 +02:00
|
|
|
* Asks for confirmation when bShowUI is true and deletes the directory and
|
|
|
|
* all its subdirectories and files if necessary.
|
2000-02-26 19:48:16 +01:00
|
|
|
*/
|
2006-06-30 22:43:12 +02:00
|
|
|
BOOL SHELL_DeleteDirectoryW(HWND hwnd, LPCWSTR pszDir, BOOL bShowUI)
|
2003-03-21 22:23:33 +01: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;
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
if (!bShowUI || (ret = SHELL_ConfirmDialogW(hwnd, ASK_DELETE_FOLDER, pszDir, NULL)))
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2006-11-14 12:00:23 +01:00
|
|
|
if (IsDotDir(wfd.cFileName))
|
2003-03-21 22:23:33 +01:00
|
|
|
continue;
|
2006-11-14 12:00:23 +01:00
|
|
|
PathCombineW(szTemp, pszDir, wfd.cFileName);
|
2003-03-21 22:23:33 +01:00
|
|
|
if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
|
2006-06-30 22:43:12 +02:00
|
|
|
ret = SHELL_DeleteDirectoryW(hwnd, szTemp, FALSE);
|
2003-03-21 22:23:33 +01:00
|
|
|
else
|
2003-09-02 20:12:44 +02:00
|
|
|
ret = (SHNotifyDeleteFileW(szTemp) == ERROR_SUCCESS);
|
2003-03-21 22:23:33 +01:00
|
|
|
} while (ret && FindNextFileW(hFind, &wfd));
|
|
|
|
}
|
|
|
|
FindClose(hFind);
|
|
|
|
if (ret)
|
2003-09-02 20:12:44 +02:00
|
|
|
ret = (SHNotifyRemoveDirectoryW(pszDir) == ERROR_SUCCESS);
|
2000-02-26 19:48:16 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* Win32CreateDirectory [SHELL32.93]
|
2000-02-26 19:48:16 +01:00
|
|
|
*
|
2003-03-21 22:23:33 +01:00
|
|
|
* 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
|
|
|
|
*
|
2005-11-10 12:15:22 +01:00
|
|
|
* NOTES
|
2003-03-21 22:23:33 +01:00
|
|
|
* Verified on Win98 / IE 5 (SHELL32 4.72, March 1999 build) to be ANSI.
|
|
|
|
* This is Unicode on NT/2000
|
2000-02-26 19:48:16 +01:00
|
|
|
*/
|
2003-09-02 20:12:44 +02:00
|
|
|
static DWORD SHNotifyCreateDirectoryA(LPCSTR path, LPSECURITY_ATTRIBUTES sec)
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
2004-10-18 23:45:16 +02:00
|
|
|
LPWSTR wPath;
|
|
|
|
DWORD retCode;
|
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
TRACE("(%s, %p)\n", debugstr_a(path), sec);
|
|
|
|
|
2004-10-18 23:45:16 +02:00
|
|
|
retCode = SHELL32_AnsiToUnicodeBuf(path, &wPath, 0);
|
|
|
|
if (!retCode)
|
|
|
|
{
|
|
|
|
retCode = SHNotifyCreateDirectoryW(wPath, sec);
|
|
|
|
SHELL32_FreeUnicodeBuf(wPath);
|
|
|
|
}
|
|
|
|
return retCode;
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
|
2004-02-20 21:19:23 +01:00
|
|
|
/**********************************************************************/
|
|
|
|
|
2003-09-02 20:12:44 +02:00
|
|
|
static DWORD SHNotifyCreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
|
|
|
TRACE("(%s, %p)\n", debugstr_w(path), sec);
|
|
|
|
|
2003-09-02 20:12:44 +02:00
|
|
|
if (CreateDirectoryW(path, sec))
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
|
|
|
SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHW, path, NULL);
|
2003-09-02 20:12:44 +02:00
|
|
|
return ERROR_SUCCESS;
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
2003-09-02 20:12:44 +02:00
|
|
|
return GetLastError();
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
|
2004-02-20 21:19:23 +01:00
|
|
|
/**********************************************************************/
|
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
BOOL WINAPI Win32CreateDirectoryAW(LPCVOID path, LPSECURITY_ATTRIBUTES sec)
|
2003-02-01 01:41:30 +01:00
|
|
|
{
|
|
|
|
if (SHELL_OsIsUnicode())
|
2003-09-02 20:12:44 +02:00
|
|
|
return (SHNotifyCreateDirectoryW(path, sec) == ERROR_SUCCESS);
|
|
|
|
return (SHNotifyCreateDirectoryA(path, sec) == ERROR_SUCCESS);
|
2003-02-01 01:41:30 +01:00
|
|
|
}
|
|
|
|
|
2003-03-21 22:23:33 +01: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
|
|
|
|
*
|
2005-11-10 12:15:22 +01:00
|
|
|
* NOTES
|
2003-03-21 22:23:33 +01:00
|
|
|
* Verified on Win98 / IE 5 (SHELL32 4.72, March 1999 build) to be ANSI.
|
|
|
|
* This is Unicode on NT/2000
|
2003-02-01 01:41:30 +01:00
|
|
|
*/
|
2003-09-02 20:12:44 +02:00
|
|
|
static DWORD SHNotifyRemoveDirectoryA(LPCSTR path)
|
2000-02-26 19:48:16 +01:00
|
|
|
{
|
2004-10-18 23:45:16 +02:00
|
|
|
LPWSTR wPath;
|
|
|
|
DWORD retCode;
|
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(path));
|
|
|
|
|
2004-10-18 23:45:16 +02:00
|
|
|
retCode = SHELL32_AnsiToUnicodeBuf(path, &wPath, 0);
|
|
|
|
if (!retCode)
|
|
|
|
{
|
|
|
|
retCode = SHNotifyRemoveDirectoryW(wPath);
|
|
|
|
SHELL32_FreeUnicodeBuf(wPath);
|
|
|
|
}
|
|
|
|
return retCode;
|
2003-02-01 01:41:30 +01:00
|
|
|
}
|
|
|
|
|
2003-08-08 23:07:23 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
|
2003-09-02 20:12:44 +02:00
|
|
|
static DWORD SHNotifyRemoveDirectoryW(LPCWSTR path)
|
2003-02-01 01:41:30 +01:00
|
|
|
{
|
2003-03-21 22:23:33 +01:00
|
|
|
BOOL ret;
|
|
|
|
TRACE("(%s)\n", debugstr_w(path));
|
|
|
|
|
|
|
|
ret = RemoveDirectoryW(path);
|
|
|
|
if (!ret)
|
2003-02-01 01:41:30 +01:00
|
|
|
{
|
2003-03-21 22:23:33 +01:00
|
|
|
/* Directory may be write protected */
|
|
|
|
DWORD dwAttr = GetFileAttributesW(path);
|
2004-10-18 23:45:16 +02:00
|
|
|
if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY))
|
2003-03-21 22:23:33 +01:00
|
|
|
if (SetFileAttributesW(path, dwAttr & ~FILE_ATTRIBUTE_READONLY))
|
|
|
|
ret = RemoveDirectoryW(path);
|
2003-02-01 01:41:30 +01:00
|
|
|
}
|
2003-03-21 22:23:33 +01:00
|
|
|
if (ret)
|
2003-09-02 20:12:44 +02:00
|
|
|
{
|
2003-03-21 22:23:33 +01:00
|
|
|
SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHW, path, NULL);
|
2003-09-02 20:12:44 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return GetLastError();
|
2000-02-26 19:48:16 +01:00
|
|
|
}
|
|
|
|
|
2003-08-08 23:07:23 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
BOOL WINAPI Win32RemoveDirectoryAW(LPCVOID path)
|
|
|
|
{
|
|
|
|
if (SHELL_OsIsUnicode())
|
2003-09-02 20:12:44 +02:00
|
|
|
return (SHNotifyRemoveDirectoryW(path) == ERROR_SUCCESS);
|
|
|
|
return (SHNotifyRemoveDirectoryA(path) == ERROR_SUCCESS);
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
|
2000-02-26 19:48:16 +01:00
|
|
|
/************************************************************************
|
2003-03-21 22:23:33 +01:00
|
|
|
* Win32DeleteFile [SHELL32.164]
|
2000-02-26 19:48:16 +01:00
|
|
|
*
|
2003-02-01 01:41:30 +01:00
|
|
|
* Deletes a file. Also triggers a change notify if one exists.
|
2000-02-26 19:48:16 +01:00
|
|
|
*
|
2003-03-21 22:23:33 +01:00
|
|
|
* PARAMS
|
|
|
|
* path [I] path to file to delete
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful, FALSE otherwise
|
|
|
|
*
|
2005-11-10 12:15:22 +01:00
|
|
|
* NOTES
|
2003-02-01 01:41:30 +01:00
|
|
|
* Verified on Win98 / IE 5 (SHELL32 4.72, March 1999 build) to be ANSI.
|
|
|
|
* This is Unicode on NT/2000
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2003-09-02 20:12:44 +02:00
|
|
|
static DWORD SHNotifyDeleteFileA(LPCSTR path)
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
2004-10-18 23:45:16 +02:00
|
|
|
LPWSTR wPath;
|
|
|
|
DWORD retCode;
|
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(path));
|
|
|
|
|
2004-10-18 23:45:16 +02:00
|
|
|
retCode = SHELL32_AnsiToUnicodeBuf(path, &wPath, 0);
|
|
|
|
if (!retCode)
|
|
|
|
{
|
|
|
|
retCode = SHNotifyDeleteFileW(wPath);
|
|
|
|
SHELL32_FreeUnicodeBuf(wPath);
|
|
|
|
}
|
|
|
|
return retCode;
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
|
2003-08-08 23:07:23 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
|
2003-09-02 20:12:44 +02:00
|
|
|
static DWORD SHNotifyDeleteFileW(LPCWSTR path)
|
2000-02-26 19:48:16 +01:00
|
|
|
{
|
2003-03-21 22:23:33 +01:00
|
|
|
BOOL ret;
|
2000-02-26 19:48:16 +01:00
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(path));
|
|
|
|
|
|
|
|
ret = DeleteFileW(path);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
/* File may be write protected or a system file */
|
|
|
|
DWORD dwAttr = GetFileAttributesW(path);
|
2004-10-18 23:45:16 +02:00
|
|
|
if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
|
2003-03-21 22:23:33 +01:00
|
|
|
if (SetFileAttributesW(path, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
|
|
|
|
ret = DeleteFileW(path);
|
|
|
|
}
|
|
|
|
if (ret)
|
2003-09-02 20:12:44 +02:00
|
|
|
{
|
2003-03-21 22:23:33 +01:00
|
|
|
SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, path, NULL);
|
2003-09-02 20:12:44 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return GetLastError();
|
2000-02-26 19:48:16 +01:00
|
|
|
}
|
|
|
|
|
2003-08-08 23:07:23 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
DWORD WINAPI Win32DeleteFileAW(LPCVOID path)
|
|
|
|
{
|
|
|
|
if (SHELL_OsIsUnicode())
|
2003-09-02 20:12:44 +02:00
|
|
|
return (SHNotifyDeleteFileW(path) == ERROR_SUCCESS);
|
|
|
|
return (SHNotifyDeleteFileA(path) == ERROR_SUCCESS);
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* SHNotifyMoveFile [internal]
|
|
|
|
*
|
|
|
|
* Moves 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
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-09-02 20:12:44 +02:00
|
|
|
* ERORR_SUCCESS if successful
|
2003-03-21 22:23:33 +01:00
|
|
|
*/
|
2004-10-22 00:29:42 +02:00
|
|
|
static DWORD SHNotifyMoveFileW(LPCWSTR src, LPCWSTR dest)
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
2004-10-22 00:29:42 +02:00
|
|
|
TRACE("(%s %s)\n", debugstr_w(src), debugstr_w(dest));
|
2003-03-21 22:23:33 +01:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
ret = MoveFileExW(src, dest, MOVEFILE_REPLACE_EXISTING);
|
|
|
|
|
|
|
|
/* MOVEFILE_REPLACE_EXISTING fails with dirs, so try MoveFile */
|
|
|
|
if (!ret)
|
|
|
|
ret = MoveFileW(src, dest);
|
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
if (!ret)
|
|
|
|
{
|
2004-10-22 00:29:42 +02:00
|
|
|
DWORD dwAttr;
|
2003-09-02 20:12:44 +02:00
|
|
|
|
2004-10-22 00:29:42 +02:00
|
|
|
dwAttr = SHFindAttrW(dest, FALSE);
|
|
|
|
if (INVALID_FILE_ATTRIBUTES == dwAttr)
|
2003-09-02 20:12:44 +02:00
|
|
|
{
|
2004-10-22 00:29:42 +02:00
|
|
|
/* 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);
|
2003-09-02 20:12:44 +02:00
|
|
|
}
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
if (ret)
|
2003-09-02 20:12:44 +02:00
|
|
|
{
|
2003-03-21 22:23:33 +01:00
|
|
|
SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_PATHW, src, dest);
|
2003-09-02 20:12:44 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return GetLastError();
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* SHNotifyCopyFile [internal]
|
|
|
|
*
|
|
|
|
* Copies a file. Also triggers a change notify if one exists.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-10-22 00:29:42 +02:00
|
|
|
* 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
|
2003-03-21 22:23:33 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2003-09-02 20:12:44 +02:00
|
|
|
* ERROR_SUCCESS if successful
|
2003-03-21 22:23:33 +01:00
|
|
|
*/
|
2004-10-22 00:29:42 +02:00
|
|
|
static DWORD SHNotifyCopyFileW(LPCWSTR src, LPCWSTR dest, BOOL bFailIfExists)
|
2003-02-01 01:41:30 +01:00
|
|
|
{
|
2003-03-21 22:23:33 +01:00
|
|
|
BOOL ret;
|
2003-02-01 01:41:30 +01:00
|
|
|
|
2004-10-22 00:29:42 +02:00
|
|
|
TRACE("(%s %s %s)\n", debugstr_w(src), debugstr_w(dest), bFailIfExists ? "failIfExists" : "");
|
2003-03-21 22:23:33 +01:00
|
|
|
|
2004-10-22 00:29:42 +02:00
|
|
|
ret = CopyFileW(src, dest, bFailIfExists);
|
2003-03-21 22:23:33 +01:00
|
|
|
if (ret)
|
2003-09-02 20:12:44 +02:00
|
|
|
{
|
2003-03-21 22:23:33 +01:00
|
|
|
SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, dest, NULL);
|
2003-09-02 20:12:44 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2006-01-23 11:22:59 +01:00
|
|
|
|
2003-09-02 20:12:44 +02:00
|
|
|
return GetLastError();
|
2003-02-01 01:41:30 +01:00
|
|
|
}
|
|
|
|
|
2003-03-21 22:23:33 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateDirectory [SHELL32.165]
|
|
|
|
*
|
2004-10-18 23:45:16 +02:00
|
|
|
* 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.
|
2003-03-21 22:23:33 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2003-04-19 22:09:09 +02:00
|
|
|
* hWnd [I]
|
|
|
|
* path [I] path of directory to create
|
2003-03-21 22:23:33 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* ERRROR_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
|
2004-10-18 23:45:16 +02:00
|
|
|
* ERROR_PATH_NOT_FOUND can't find the path, probably invalid
|
|
|
|
* ERROR_INVLID_NAME if the path contains invalid chars
|
2003-03-21 22:23:33 +01:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SHCreateDirectory(HWND hWnd, LPCVOID path)
|
2003-02-01 01:41:30 +01:00
|
|
|
{
|
|
|
|
if (SHELL_OsIsUnicode())
|
2003-03-21 22:23:33 +01:00
|
|
|
return SHCreateDirectoryExW(hWnd, path, NULL);
|
|
|
|
return SHCreateDirectoryExA(hWnd, path, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateDirectoryExA [SHELL32.@]
|
|
|
|
*
|
2004-10-18 23:45:16 +02:00
|
|
|
* 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.
|
2003-03-21 22:23:33 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2004-10-18 23:45:16 +02:00
|
|
|
* hWnd [I]
|
|
|
|
* path [I] path of directory to create
|
2003-03-21 22:23:33 +01:00
|
|
|
* sec [I] security attributes to use or NULL
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* ERRROR_SUCCESS or one of the following values:
|
2004-10-18 23:45:16 +02:00
|
|
|
* ERROR_BAD_PATHNAME or ERROR_PATH_NOT_FOUND if the path is relative
|
|
|
|
* ERROR_INVLID_NAME if the path contains invalid chars
|
2003-03-21 22:23:33 +01:00
|
|
|
* ERROR_FILE_EXISTS when a file with that name exists
|
|
|
|
* ERROR_ALREADY_EXISTS when the directory already exists
|
|
|
|
* ERROR_FILENAME_EXCED_RANGE if the filename was to long to process
|
2004-10-18 23:45:16 +02:00
|
|
|
*
|
|
|
|
* FIXME: Not implemented yet;
|
2004-10-22 00:29:42 +02:00
|
|
|
* 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:
|
2004-10-18 23:45:16 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2003-03-21 22:23:33 +01:00
|
|
|
*/
|
2004-06-28 22:32:53 +02:00
|
|
|
int WINAPI SHCreateDirectoryExA(HWND hWnd, LPCSTR path, LPSECURITY_ATTRIBUTES sec)
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
2004-10-18 23:45:16 +02:00
|
|
|
LPWSTR wPath;
|
|
|
|
DWORD retCode;
|
|
|
|
|
|
|
|
TRACE("(%s, %p)\n", debugstr_a(path), sec);
|
2003-03-21 22:23:33 +01:00
|
|
|
|
2004-10-18 23:45:16 +02:00
|
|
|
retCode = SHELL32_AnsiToUnicodeBuf(path, &wPath, 0);
|
|
|
|
if (!retCode)
|
|
|
|
{
|
|
|
|
retCode = SHCreateDirectoryExW(hWnd, wPath, sec);
|
|
|
|
SHELL32_FreeUnicodeBuf(wPath);
|
|
|
|
}
|
|
|
|
return retCode;
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateDirectoryExW [SHELL32.@]
|
2005-11-10 12:15:22 +01:00
|
|
|
*
|
|
|
|
* See SHCreateDirectoryExA.
|
2003-03-21 22:23:33 +01:00
|
|
|
*/
|
2004-06-28 22:32:53 +02:00
|
|
|
int WINAPI SHCreateDirectoryExW(HWND hWnd, LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
2004-06-28 22:32:53 +02:00
|
|
|
int ret = ERROR_BAD_PATHNAME;
|
2004-10-18 23:45:16 +02:00
|
|
|
TRACE("(%p, %s, %p)\n", hWnd, debugstr_w(path), sec);
|
2003-03-21 22:23:33 +01:00
|
|
|
|
|
|
|
if (PathIsRelativeW(path))
|
|
|
|
{
|
2003-09-02 20:12:44 +02:00
|
|
|
SetLastError(ret);
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-09-02 20:12:44 +02:00
|
|
|
ret = SHNotifyCreateDirectoryW(path, sec);
|
2004-10-18 23:45:16 +02:00
|
|
|
/* Refuse to work on certain error codes before trying to create directories recursively */
|
2006-06-07 21:08:38 +02:00
|
|
|
if (ret != ERROR_SUCCESS &&
|
|
|
|
ret != ERROR_FILE_EXISTS &&
|
2003-09-02 20:12:44 +02:00
|
|
|
ret != ERROR_ALREADY_EXISTS &&
|
|
|
|
ret != ERROR_FILENAME_EXCED_RANGE)
|
2003-03-21 22:23:33 +01:00
|
|
|
{
|
2004-10-22 00:29:42 +02:00
|
|
|
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 = CharNextW(pSlash);
|
|
|
|
|
|
|
|
if (*pSlash)
|
|
|
|
{
|
2004-10-23 00:27:51 +02:00
|
|
|
*pSlash = 0; /* terminate path at separator */
|
2004-10-22 00:29:42 +02:00
|
|
|
|
|
|
|
ret = SHNotifyCreateDirectoryW(szTemp, pSlash + 1 == pEnd ? sec : NULL);
|
|
|
|
}
|
2004-10-23 00:27:51 +02:00
|
|
|
*pSlash++ = '\\'; /* put the separator back */
|
2004-10-22 00:29:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret && hWnd && (ERROR_CANCELLED != ret))
|
|
|
|
{
|
|
|
|
/* We failed and should show a dialog box */
|
|
|
|
FIXME("Show system error message, creating path %s, failed with error %d\n", debugstr_w(path), ret);
|
|
|
|
ret = ERROR_CANCELLED; /* Error has been already presented to user (not really yet!) */
|
2003-03-21 22:23:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2003-02-01 01:41:30 +01:00
|
|
|
}
|
|
|
|
|
2004-10-22 00:29:42 +02: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)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
FindClose(hFind);
|
|
|
|
}
|
|
|
|
return dwAttr;
|
|
|
|
}
|
|
|
|
|
2000-02-20 19:39:11 +01:00
|
|
|
/*************************************************************************
|
2003-04-19 22:09:09 +02:00
|
|
|
*
|
2003-04-26 04:05:39 +02:00
|
|
|
* SHNameTranslate HelperFunction for SHFileOperationA
|
2003-04-19 22:09:09 +02:00
|
|
|
*
|
2003-04-26 04:05:39 +02:00
|
|
|
* Translates a list of 0 terminated ASCII strings into Unicode. If *wString
|
2003-04-19 22:09:09 +02:00
|
|
|
* is NULL, only the necessary size of the string is determined and returned,
|
|
|
|
* otherwise the ASCII strings are copied into it and the buffer is increased
|
|
|
|
* to point to the location after the final 0 termination char.
|
|
|
|
*/
|
2007-02-06 23:05:44 +01:00
|
|
|
static DWORD SHNameTranslate(LPWSTR* wString, LPCWSTR* pWToFrom, BOOL more)
|
2003-04-19 22:09:09 +02:00
|
|
|
{
|
|
|
|
DWORD size = 0, aSize = 0;
|
|
|
|
LPCSTR aString = (LPCSTR)*pWToFrom;
|
|
|
|
|
|
|
|
if (aString)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
size = lstrlenA(aString) + 1;
|
|
|
|
aSize += size;
|
|
|
|
aString += size;
|
|
|
|
} while ((size != 1) && more);
|
|
|
|
/* The two sizes might be different in the case of multibyte chars */
|
|
|
|
size = MultiByteToWideChar(CP_ACP, 0, aString, aSize, *wString, 0);
|
|
|
|
if (*wString) /* only in the second loop */
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*pWToFrom, aSize, *wString, size);
|
|
|
|
*pWToFrom = *wString;
|
|
|
|
*wString += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
/*************************************************************************
|
|
|
|
* 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
|
2000-02-20 19:39:11 +01:00
|
|
|
*
|
2005-11-10 12:15:22 +01:00
|
|
|
* RETURNS
|
2006-01-23 11:22:59 +01:00
|
|
|
* Success: ERROR_SUCCESS.
|
|
|
|
* Failure: ERROR_CANCELLED.
|
2005-11-10 12:15:22 +01:00
|
|
|
*
|
2000-02-20 19:39:11 +01:00
|
|
|
* NOTES
|
2003-04-19 22:09:09 +02:00
|
|
|
* exported by name
|
|
|
|
*/
|
2004-01-05 22:13:37 +01:00
|
|
|
int WINAPI SHFileOperationA(LPSHFILEOPSTRUCTA lpFileOp)
|
2003-04-19 22:09:09 +02:00
|
|
|
{
|
|
|
|
SHFILEOPSTRUCTW nFileOp = *((LPSHFILEOPSTRUCTW)lpFileOp);
|
2004-01-05 22:13:37 +01:00
|
|
|
int retCode = 0;
|
|
|
|
DWORD size;
|
2003-04-26 04:05:39 +02:00
|
|
|
LPWSTR ForFree = NULL, /* we change wString in SHNameTranslate and can't use it for freeing */
|
|
|
|
wString = NULL; /* we change this in SHNameTranslate */
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2003-05-11 05:31:08 +02:00
|
|
|
TRACE("\n");
|
2003-04-19 22:09:09 +02:00
|
|
|
if (FO_DELETE == (nFileOp.wFunc & FO_MASK))
|
|
|
|
nFileOp.pTo = NULL; /* we need a NULL or a valid pointer for translation */
|
|
|
|
if (!(nFileOp.fFlags & FOF_SIMPLEPROGRESS))
|
|
|
|
nFileOp.lpszProgressTitle = NULL; /* we need a NULL or a valid pointer for translation */
|
2003-04-26 04:05:39 +02:00
|
|
|
while (1) /* every loop calculate size, second translate also, if we have storage for this */
|
2003-04-19 22:09:09 +02:00
|
|
|
{
|
|
|
|
size = SHNameTranslate(&wString, &nFileOp.lpszProgressTitle, FALSE); /* no loop */
|
|
|
|
size += SHNameTranslate(&wString, &nFileOp.pFrom, TRUE); /* internal loop */
|
|
|
|
size += SHNameTranslate(&wString, &nFileOp.pTo, TRUE); /* internal loop */
|
|
|
|
|
2003-04-26 04:05:39 +02:00
|
|
|
if (ForFree)
|
|
|
|
{
|
|
|
|
retCode = SHFileOperationW(&nFileOp);
|
2005-05-06 17:44:31 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ForFree); /* we cannot use wString, it was changed */
|
2003-04-26 04:05:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wString = ForFree = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
if (ForFree) continue;
|
|
|
|
retCode = ERROR_OUTOFMEMORY;
|
|
|
|
nFileOp.fAnyOperationsAborted = TRUE;
|
|
|
|
SetLastError(retCode);
|
|
|
|
return retCode;
|
|
|
|
}
|
2003-04-19 22:09:09 +02:00
|
|
|
}
|
2003-04-26 04:05:39 +02:00
|
|
|
|
2003-04-19 22:09:09 +02:00
|
|
|
lpFileOp->hNameMappings = nFileOp.hNameMappings;
|
|
|
|
lpFileOp->fAnyOperationsAborted = nFileOp.fAnyOperationsAborted;
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
#define ERROR_SHELL_INTERNAL_FILE_NOT_FOUND 1026
|
2003-05-11 05:31:08 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
typedef struct
|
2003-05-11 05:31:08 +02:00
|
|
|
{
|
2006-03-06 16:44:31 +01:00
|
|
|
DWORD attributes;
|
2006-01-23 11:22:59 +01:00
|
|
|
LPWSTR szDirectory;
|
|
|
|
LPWSTR szFilename;
|
|
|
|
LPWSTR szFullPath;
|
|
|
|
BOOL bFromWildcard;
|
|
|
|
BOOL bFromRelative;
|
|
|
|
BOOL bExists;
|
|
|
|
} FILE_ENTRY;
|
2003-05-11 05:31:08 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
FILE_ENTRY *feFiles;
|
2006-03-06 17:47:57 +01:00
|
|
|
DWORD num_alloc;
|
2006-01-23 11:22:59 +01:00
|
|
|
DWORD dwNumFiles;
|
|
|
|
BOOL bAnyFromWildcard;
|
|
|
|
BOOL bAnyDirectories;
|
|
|
|
BOOL bAnyDontExist;
|
|
|
|
} FILE_LIST;
|
|
|
|
|
2005-01-14 17:51:14 +01:00
|
|
|
|
2006-03-06 17:47:57 +01:00
|
|
|
static inline void grow_list(FILE_LIST *list)
|
2005-01-14 17:51:14 +01:00
|
|
|
{
|
2006-03-06 17:47:57 +01:00
|
|
|
FILE_ENTRY *new = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, list->feFiles,
|
|
|
|
list->num_alloc * 2 * sizeof(*new) );
|
|
|
|
list->feFiles = new;
|
|
|
|
list->num_alloc *= 2;
|
2005-01-14 17:51:14 +01:00
|
|
|
}
|
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
/* adds a file to the FILE_ENTRY struct
|
2005-01-14 17:51:14 +01:00
|
|
|
*/
|
2006-03-06 16:44:31 +01:00
|
|
|
static void add_file_to_entry(FILE_ENTRY *feFile, LPWSTR szFile)
|
2006-01-23 11:22:59 +01:00
|
|
|
{
|
2006-08-24 12:16:26 +02:00
|
|
|
DWORD dwLen = lstrlenW(szFile) + 1;
|
2006-01-23 11:22:59 +01:00
|
|
|
LPWSTR ptr;
|
|
|
|
|
|
|
|
feFile->szFullPath = HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR));
|
2006-08-24 12:16:26 +02:00
|
|
|
lstrcpyW(feFile->szFullPath, szFile);
|
2006-01-23 11:22:59 +01:00
|
|
|
|
|
|
|
ptr = StrRChrW(szFile, NULL, '\\');
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
dwLen = ptr - szFile + 1;
|
|
|
|
feFile->szDirectory = HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR));
|
|
|
|
lstrcpynW(feFile->szDirectory, szFile, dwLen);
|
|
|
|
|
2006-08-24 12:16:26 +02:00
|
|
|
dwLen = lstrlenW(feFile->szFullPath) - dwLen + 1;
|
2006-01-23 11:22:59 +01:00
|
|
|
feFile->szFilename = HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR));
|
2006-08-24 12:16:26 +02:00
|
|
|
lstrcpyW(feFile->szFilename, ptr + 1); /* skip over backslash */
|
2006-01-23 11:22:59 +01:00
|
|
|
}
|
2006-03-06 16:44:31 +01:00
|
|
|
feFile->bFromWildcard = FALSE;
|
2006-01-23 11:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR wildcard_to_file(LPWSTR szWildCard, LPWSTR szFileName)
|
|
|
|
{
|
|
|
|
LPWSTR szFullPath, ptr;
|
|
|
|
DWORD dwDirLen, dwFullLen;
|
|
|
|
|
|
|
|
ptr = StrRChrW(szWildCard, NULL, '\\');
|
|
|
|
dwDirLen = ptr - szWildCard + 1;
|
|
|
|
|
2006-08-24 12:16:26 +02:00
|
|
|
dwFullLen = dwDirLen + lstrlenW(szFileName) + 1;
|
2006-01-23 11:22:59 +01:00
|
|
|
szFullPath = HeapAlloc(GetProcessHeap(), 0, dwFullLen * sizeof(WCHAR));
|
|
|
|
|
|
|
|
lstrcpynW(szFullPath, szWildCard, dwDirLen + 1);
|
2006-08-24 12:16:26 +02:00
|
|
|
lstrcatW(szFullPath, szFileName);
|
2006-01-23 11:22:59 +01:00
|
|
|
|
|
|
|
return szFullPath;
|
|
|
|
}
|
2005-01-14 17:51:14 +01:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
static void parse_wildcard_files(FILE_LIST *flList, LPWSTR szFile, LPDWORD pdwListIndex)
|
2005-01-14 17:51:14 +01:00
|
|
|
{
|
2006-01-23 11:22:59 +01:00
|
|
|
WIN32_FIND_DATAW wfd;
|
|
|
|
HANDLE hFile = FindFirstFileW(szFile, &wfd);
|
2006-03-06 16:44:31 +01:00
|
|
|
FILE_ENTRY *file;
|
2006-01-23 11:22:59 +01:00
|
|
|
LPWSTR szFullPath;
|
2006-03-03 17:08:32 +01:00
|
|
|
BOOL res;
|
|
|
|
|
2006-12-11 15:37:35 +01:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
2006-03-03 17:08:32 +01:00
|
|
|
for (res = TRUE; res; res = FindNextFileW(hFile, &wfd))
|
2005-01-14 17:51:14 +01:00
|
|
|
{
|
2006-03-03 17:08:32 +01:00
|
|
|
if (IsDotDir(wfd.cFileName)) continue;
|
2006-03-06 17:47:57 +01:00
|
|
|
if (*pdwListIndex >= flList->num_alloc) grow_list( flList );
|
2006-01-23 11:22:59 +01:00
|
|
|
szFullPath = wildcard_to_file(szFile, wfd.cFileName);
|
2006-03-06 16:44:31 +01:00
|
|
|
file = &flList->feFiles[(*pdwListIndex)++];
|
|
|
|
add_file_to_entry(file, szFullPath);
|
|
|
|
file->bFromWildcard = TRUE;
|
|
|
|
file->attributes = wfd.dwFileAttributes;
|
|
|
|
if (IsAttribDir(file->attributes)) flList->bAnyDirectories = TRUE;
|
2006-03-03 17:08:32 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, szFullPath);
|
2006-01-23 11:22:59 +01:00
|
|
|
}
|
|
|
|
|
2006-01-27 15:48:29 +01:00
|
|
|
FindClose(hFile);
|
2006-01-23 11:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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];
|
2006-03-06 17:47:57 +01:00
|
|
|
DWORD i = 0, dwDirLen;
|
2006-01-23 11:22:59 +01:00
|
|
|
|
|
|
|
if (!szFiles)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
flList->bAnyFromWildcard = FALSE;
|
|
|
|
flList->bAnyDirectories = FALSE;
|
|
|
|
flList->bAnyDontExist = FALSE;
|
2006-03-06 17:47:57 +01:00
|
|
|
flList->num_alloc = 32;
|
|
|
|
flList->dwNumFiles = 0;
|
2006-01-23 11:22:59 +01:00
|
|
|
|
|
|
|
/* empty list */
|
2006-03-06 17:47:57 +01:00
|
|
|
if (!szFiles[0])
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_ACCESS_DENIED;
|
|
|
|
|
|
|
|
flList->feFiles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2006-03-06 17:47:57 +01:00
|
|
|
flList->num_alloc * sizeof(FILE_ENTRY));
|
2006-01-23 11:22:59 +01:00
|
|
|
|
2006-03-06 17:47:57 +01:00
|
|
|
while (*ptr)
|
2006-01-23 11:22:59 +01:00
|
|
|
{
|
2006-03-06 17:47:57 +01:00
|
|
|
if (i >= flList->num_alloc) grow_list( flList );
|
2006-01-23 11:22:59 +01:00
|
|
|
|
|
|
|
/* change relative to absolute path */
|
|
|
|
if (PathIsRelativeW(ptr))
|
2005-01-14 17:51:14 +01:00
|
|
|
{
|
2006-01-23 11:22:59 +01:00
|
|
|
dwDirLen = GetCurrentDirectoryW(MAX_PATH, szCurFile) + 1;
|
|
|
|
PathCombineW(szCurFile, szCurFile, ptr);
|
|
|
|
flList->feFiles[i].bFromRelative = TRUE;
|
2005-01-14 17:51:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-24 12:16:26 +02:00
|
|
|
lstrcpyW(szCurFile, ptr);
|
2006-01-23 11:22:59 +01:00
|
|
|
flList->feFiles[i].bFromRelative = FALSE;
|
|
|
|
}
|
2005-01-14 17:51:14 +01:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
/* parse wildcard files if they are in the filename */
|
|
|
|
if (StrPBrkW(szCurFile, wWildcardChars))
|
|
|
|
{
|
|
|
|
parse_wildcard_files(flList, szCurFile, &i);
|
|
|
|
flList->bAnyFromWildcard = TRUE;
|
|
|
|
i--;
|
|
|
|
}
|
2006-03-06 16:44:31 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE_ENTRY *file = &flList->feFiles[i];
|
|
|
|
add_file_to_entry(file, szCurFile);
|
|
|
|
file->attributes = GetFileAttributesW( file->szFullPath );
|
2006-03-06 17:47:57 +01:00
|
|
|
file->bExists = (file->attributes != INVALID_FILE_ATTRIBUTES);
|
|
|
|
if (!file->bExists) flList->bAnyDontExist = TRUE;
|
2006-03-06 16:44:31 +01:00
|
|
|
if (IsAttribDir(file->attributes)) flList->bAnyDirectories = TRUE;
|
|
|
|
}
|
2006-01-23 11:22:59 +01:00
|
|
|
|
|
|
|
/* advance to the next string */
|
2006-08-24 12:16:26 +02:00
|
|
|
ptr += lstrlenW(ptr) + 1;
|
2006-03-06 17:47:57 +01:00
|
|
|
i++;
|
2006-01-23 11:22:59 +01:00
|
|
|
}
|
2006-03-06 17:47:57 +01:00
|
|
|
flList->dwNumFiles = i;
|
2006-01-23 11:22:59 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2005-02-17 12:50:25 +01:00
|
|
|
}
|
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
/* free the FILE_LIST */
|
|
|
|
static void destroy_file_list(FILE_LIST *flList)
|
2005-02-17 12:50:25 +01:00
|
|
|
{
|
2006-01-23 11:22:59 +01:00
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if (!flList || !flList->feFiles)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < flList->dwNumFiles; i++)
|
2005-02-17 12:50:25 +01:00
|
|
|
{
|
2006-01-23 11:22:59 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, flList->feFiles[i].szDirectory);
|
|
|
|
HeapFree(GetProcessHeap(), 0, flList->feFiles[i].szFilename);
|
|
|
|
HeapFree(GetProcessHeap(), 0, flList->feFiles[i].szFullPath);
|
2005-02-17 12:50:25 +01:00
|
|
|
}
|
2006-01-23 11:22:59 +01:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, flList->feFiles);
|
2005-02-17 12:50:25 +01:00
|
|
|
}
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
static void copy_dir_to_dir(FILE_OPERATION *op, FILE_ENTRY *feFrom, LPWSTR szDestPath)
|
2005-02-17 12:50:25 +01:00
|
|
|
{
|
2006-01-23 11:22:59 +01:00
|
|
|
WCHAR szFrom[MAX_PATH], szTo[MAX_PATH];
|
|
|
|
SHFILEOPSTRUCTW fileOp;
|
|
|
|
|
|
|
|
static const WCHAR wildCardFiles[] = {'*','.','*',0};
|
|
|
|
|
|
|
|
if (IsDotDir(feFrom->szFilename))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (PathFileExistsW(szDestPath))
|
|
|
|
PathCombineW(szTo, szDestPath, feFrom->szFilename);
|
|
|
|
else
|
2006-08-24 12:16:26 +02:00
|
|
|
lstrcpyW(szTo, szDestPath);
|
2006-01-23 11:22:59 +01:00
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
if (!(op->req->fFlags & FOF_NOCONFIRMATION) && PathFileExistsW(szTo)) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-24 12:16:26 +02:00
|
|
|
szTo[lstrlenW(szTo) + 1] = '\0';
|
2006-01-23 11:22:59 +01:00
|
|
|
SHNotifyCreateDirectoryW(szTo, NULL);
|
|
|
|
|
|
|
|
PathCombineW(szFrom, feFrom->szFullPath, wildCardFiles);
|
2006-08-24 12:16:26 +02:00
|
|
|
szFrom[lstrlenW(szFrom) + 1] = '\0';
|
2006-01-23 11:22:59 +01:00
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
memcpy(&fileOp, op->req, sizeof(fileOp));
|
2006-01-23 11:22:59 +01:00
|
|
|
fileOp.pFrom = szFrom;
|
|
|
|
fileOp.pTo = szTo;
|
|
|
|
fileOp.fFlags &= ~FOF_MULTIDESTFILES; /* we know we're copying to one dir */
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
/* Don't ask the user about overwriting files when he accepted to overwrite the
|
|
|
|
folder. FIXME: this is not exactly what Windows does - e.g. there would be
|
|
|
|
an additional confirmation for a nested folder */
|
|
|
|
fileOp.fFlags |= FOF_NOCONFIRMATION;
|
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
SHFileOperationW(&fileOp);
|
2005-02-17 12:50:25 +01:00
|
|
|
}
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
static BOOL copy_file_to_file(FILE_OPERATION *op, WCHAR *szFrom, WCHAR *szTo)
|
|
|
|
{
|
|
|
|
if (!(op->req->fFlags & FOF_NOCONFIRMATION) && PathFileExistsW(szTo))
|
|
|
|
{
|
|
|
|
if (!SHELL_ConfirmDialogW(op->req->hwnd, ASK_OVERWRITE_FILE, PathFindFileNameW(szTo), op))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SHNotifyCopyFileW(szFrom, szTo, FALSE) == 0;
|
|
|
|
}
|
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
/* copy a file or directory to another directory */
|
2007-02-09 17:13:25 +01:00
|
|
|
static void copy_to_dir(FILE_OPERATION *op, FILE_ENTRY *feFrom, FILE_ENTRY *feTo)
|
2000-02-20 19:39:11 +01:00
|
|
|
{
|
2006-01-23 11:22:59 +01:00
|
|
|
if (!PathFileExistsW(feTo->szFullPath))
|
|
|
|
SHNotifyCreateDirectoryW(feTo->szFullPath, NULL);
|
|
|
|
|
2006-03-06 16:44:31 +01:00
|
|
|
if (IsAttribFile(feFrom->attributes))
|
2006-08-22 07:16:46 +02:00
|
|
|
{
|
|
|
|
WCHAR szDestPath[MAX_PATH];
|
|
|
|
|
|
|
|
PathCombineW(szDestPath, feTo->szFullPath, feFrom->szFilename);
|
2007-02-09 17:13:25 +01:00
|
|
|
copy_file_to_file(op, feFrom->szFullPath, szDestPath);
|
2006-08-22 07:16:46 +02:00
|
|
|
}
|
2007-02-09 17:13:25 +01:00
|
|
|
else if (!(op->req->fFlags & FOF_FILESONLY && feFrom->bFromWildcard))
|
|
|
|
copy_dir_to_dir(op, feFrom, feTo->szFullPath);
|
2006-01-23 11:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void create_dest_dirs(LPWSTR szDestDir)
|
|
|
|
{
|
|
|
|
WCHAR dir[MAX_PATH];
|
|
|
|
LPWSTR 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 */
|
2007-02-09 17:13:25 +01:00
|
|
|
static HRESULT copy_files(FILE_OPERATION *op, FILE_LIST *flFrom, FILE_LIST *flTo)
|
2006-01-23 11:22:59 +01:00
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
FILE_ENTRY *entryToCopy;
|
|
|
|
FILE_ENTRY *fileDest = &flTo->feFiles[0];
|
|
|
|
BOOL bCancelIfAnyDirectories = FALSE;
|
|
|
|
|
|
|
|
if (flFrom->bAnyDontExist)
|
|
|
|
return ERROR_SHELL_INTERNAL_FILE_NOT_FOUND;
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
if (op->req->fFlags & FOF_MULTIDESTFILES && flFrom->bAnyFromWildcard)
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
if (!(op->req->fFlags & FOF_MULTIDESTFILES) && flTo->dwNumFiles != 1)
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
if (op->req->fFlags & FOF_MULTIDESTFILES && flFrom->dwNumFiles != 1 &&
|
2006-01-23 11:22:59 +01:00
|
|
|
flFrom->dwNumFiles != flTo->dwNumFiles)
|
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flFrom->dwNumFiles > 1 && flTo->dwNumFiles == 1 &&
|
|
|
|
!PathFileExistsW(flTo->feFiles[0].szFullPath) &&
|
2006-03-06 16:44:31 +01:00
|
|
|
IsAttribFile(fileDest->attributes))
|
2006-01-23 11:22:59 +01:00
|
|
|
{
|
|
|
|
bCancelIfAnyDirectories = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flFrom->dwNumFiles > 1 && flTo->dwNumFiles == 1 && fileDest->bFromRelative &&
|
|
|
|
!PathFileExistsW(fileDest->szFullPath))
|
|
|
|
{
|
2007-02-09 17:13:25 +01:00
|
|
|
op->req->fAnyOperationsAborted = TRUE;
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
if (!(op->req->fFlags & FOF_MULTIDESTFILES) && flFrom->dwNumFiles != 1 &&
|
2006-01-23 11:22:59 +01:00
|
|
|
PathFileExistsW(fileDest->szFullPath) &&
|
2006-03-06 16:44:31 +01:00
|
|
|
IsAttribFile(fileDest->attributes))
|
2006-01-23 11:22:59 +01:00
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < flFrom->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
entryToCopy = &flFrom->feFiles[i];
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
if (op->req->fFlags & FOF_MULTIDESTFILES)
|
2006-01-23 11:22:59 +01:00
|
|
|
fileDest = &flTo->feFiles[i];
|
|
|
|
|
2006-03-06 16:44:31 +01:00
|
|
|
if (IsAttribDir(entryToCopy->attributes) &&
|
2006-08-08 11:47:02 +02:00
|
|
|
!lstrcmpiW(entryToCopy->szFullPath, fileDest->szDirectory))
|
2003-04-19 22:09:09 +02:00
|
|
|
{
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_SUCCESS;
|
2003-04-19 22:09:09 +02:00
|
|
|
}
|
2006-01-23 11:22:59 +01:00
|
|
|
|
2006-03-06 16:44:31 +01:00
|
|
|
if (IsAttribDir(entryToCopy->attributes) && bCancelIfAnyDirectories)
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
|
|
|
create_dest_dirs(fileDest->szDirectory);
|
|
|
|
|
2006-08-08 11:47:02 +02:00
|
|
|
if (!lstrcmpiW(entryToCopy->szFullPath, fileDest->szFullPath))
|
2003-04-19 22:09:09 +02:00
|
|
|
{
|
2006-03-06 16:44:31 +01:00
|
|
|
if (IsAttribFile(entryToCopy->attributes))
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_NO_MORE_SEARCH_HANDLES;
|
|
|
|
else
|
|
|
|
return ERROR_SUCCESS;
|
2003-04-19 22:09:09 +02:00
|
|
|
}
|
2006-01-23 11:22:59 +01:00
|
|
|
|
|
|
|
if ((flFrom->dwNumFiles > 1 && flTo->dwNumFiles == 1) ||
|
2006-03-06 16:44:31 +01:00
|
|
|
(flFrom->dwNumFiles == 1 && IsAttribDir(fileDest->attributes)))
|
2006-01-23 11:22:59 +01:00
|
|
|
{
|
2007-02-09 17:13:25 +01:00
|
|
|
copy_to_dir(op, entryToCopy, fileDest);
|
2006-01-23 11:22:59 +01:00
|
|
|
}
|
2006-03-06 16:44:31 +01:00
|
|
|
else if (IsAttribDir(entryToCopy->attributes))
|
2006-01-23 11:22:59 +01:00
|
|
|
{
|
2007-02-09 17:13:25 +01:00
|
|
|
copy_dir_to_dir(op, entryToCopy, fileDest->szFullPath);
|
2006-01-23 11:22:59 +01:00
|
|
|
}
|
|
|
|
else
|
2003-04-19 22:09:09 +02:00
|
|
|
{
|
2007-02-09 17:13:25 +01:00
|
|
|
if (!copy_file_to_file(op, entryToCopy->szFullPath, fileDest->szFullPath))
|
2006-01-23 11:22:59 +01:00
|
|
|
{
|
2007-02-09 17:13:25 +01:00
|
|
|
op->req->fAnyOperationsAborted = TRUE;
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
2007-02-09 17:13:25 +01:00
|
|
|
|
|
|
|
/* Vista return code. XP would return e.g. ERROR_FILE_NOT_FOUND, ERROR_ALREADY_EXISTS */
|
|
|
|
if (op->bCancelled)
|
|
|
|
return ERROR_CANCELLED;
|
2006-01-23 11:22:59 +01:00
|
|
|
}
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
/* Vista return code. On XP if the used pressed "No" for the last item,
|
|
|
|
* ERROR_ARENA_TRASHED would be returned */
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2002-09-04 20:46:29 +02:00
|
|
|
|
2006-07-19 18:36:22 +02:00
|
|
|
static BOOL confirm_delete_list(HWND hWnd, DWORD fFlags, BOOL fTrash, FILE_LIST *flFrom)
|
2006-06-27 21:51:35 +02:00
|
|
|
{
|
|
|
|
if (flFrom->dwNumFiles > 1)
|
|
|
|
{
|
|
|
|
WCHAR tmp[8];
|
|
|
|
const WCHAR format[] = {'%','d',0};
|
|
|
|
|
|
|
|
wnsprintfW(tmp, sizeof(tmp)/sizeof(tmp[0]), format, flFrom->dwNumFiles);
|
2007-02-09 17:13:25 +01:00
|
|
|
return SHELL_ConfirmDialogW(hWnd, (fTrash?ASK_TRASH_MULTIPLE_ITEM:ASK_DELETE_MULTIPLE_ITEM), tmp, NULL);
|
2006-06-27 21:51:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE_ENTRY *fileEntry = &flFrom->feFiles[0];
|
|
|
|
|
|
|
|
if (IsAttribFile(fileEntry->attributes))
|
2007-02-09 17:13:25 +01:00
|
|
|
return SHELL_ConfirmDialogW(hWnd, (fTrash?ASK_TRASH_FILE:ASK_DELETE_FILE), fileEntry->szFullPath, NULL);
|
2006-06-27 21:51:35 +02:00
|
|
|
else if (!(fFlags & FOF_FILESONLY && fileEntry->bFromWildcard))
|
2007-02-09 17:13:25 +01:00
|
|
|
return SHELL_ConfirmDialogW(hWnd, (fTrash?ASK_TRASH_FOLDER:ASK_DELETE_FOLDER), fileEntry->szFullPath, NULL);
|
2006-06-27 21:51:35 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
/* the FO_DELETE operation */
|
|
|
|
static HRESULT delete_files(LPSHFILEOPSTRUCTW lpFileOp, FILE_LIST *flFrom)
|
|
|
|
{
|
|
|
|
FILE_ENTRY *fileEntry;
|
|
|
|
DWORD i;
|
|
|
|
BOOL bPathExists;
|
2006-07-19 18:37:02 +02:00
|
|
|
BOOL bTrash;
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
if (!flFrom->dwNumFiles)
|
|
|
|
return ERROR_SUCCESS;
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-07-19 18:37:02 +02:00
|
|
|
/* Windows also checks only the first item */
|
|
|
|
bTrash = (lpFileOp->fFlags & FOF_ALLOWUNDO)
|
|
|
|
&& TRASH_CanTrashFile(flFrom->feFiles[0].szFullPath);
|
|
|
|
|
|
|
|
if (!(lpFileOp->fFlags & FOF_NOCONFIRMATION) || (!bTrash && lpFileOp->fFlags & FOF_WANTNUKEWARNING))
|
|
|
|
if (!confirm_delete_list(lpFileOp->hwnd, lpFileOp->fFlags, bTrash, flFrom))
|
2006-06-27 21:51:35 +02:00
|
|
|
{
|
|
|
|
lpFileOp->fAnyOperationsAborted = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
for (i = 0; i < flFrom->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
bPathExists = TRUE;
|
|
|
|
fileEntry = &flFrom->feFiles[i];
|
2002-09-04 20:46:29 +02:00
|
|
|
|
2006-07-19 18:37:02 +02:00
|
|
|
if (!IsAttribFile(fileEntry->attributes) &&
|
|
|
|
(lpFileOp->fFlags & FOF_FILESONLY && fileEntry->bFromWildcard))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (bTrash)
|
|
|
|
{
|
|
|
|
BOOL bDelete;
|
|
|
|
if (TRASH_TrashFile(fileEntry->szFullPath))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Note: Windows silently deletes the file in such a situation, we show a dialog */
|
|
|
|
if (!(lpFileOp->fFlags & FOF_NOCONFIRMATION) || (lpFileOp->fFlags & FOF_WANTNUKEWARNING))
|
2007-02-09 17:13:25 +01:00
|
|
|
bDelete = SHELL_ConfirmDialogW(lpFileOp->hwnd, ASK_CANT_TRASH_ITEM, fileEntry->szFullPath, NULL);
|
2006-07-19 18:37:02 +02:00
|
|
|
else
|
|
|
|
bDelete = TRUE;
|
|
|
|
|
|
|
|
if (!bDelete)
|
|
|
|
{
|
|
|
|
lpFileOp->fAnyOperationsAborted = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
/* delete the file or directory */
|
2006-03-06 16:44:31 +01:00
|
|
|
if (IsAttribFile(fileEntry->attributes))
|
2006-01-23 11:22:59 +01:00
|
|
|
bPathExists = DeleteFileW(fileEntry->szFullPath);
|
2006-07-19 18:37:02 +02:00
|
|
|
else
|
2006-06-30 22:43:12 +02:00
|
|
|
bPathExists = SHELL_DeleteDirectoryW(lpFileOp->hwnd, fileEntry->szFullPath, FALSE);
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
if (!bPathExists)
|
|
|
|
return ERROR_PATH_NOT_FOUND;
|
|
|
|
}
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
static void move_dir_to_dir(LPSHFILEOPSTRUCTW lpFileOp, FILE_ENTRY *feFrom, LPWSTR szDestPath)
|
|
|
|
{
|
|
|
|
WCHAR szFrom[MAX_PATH], szTo[MAX_PATH];
|
|
|
|
SHFILEOPSTRUCTW fileOp;
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
static const WCHAR wildCardFiles[] = {'*','.','*',0};
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
if (IsDotDir(feFrom->szFilename))
|
|
|
|
return;
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
SHNotifyCreateDirectoryW(szDestPath, NULL);
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
PathCombineW(szFrom, feFrom->szFullPath, wildCardFiles);
|
2006-08-24 12:16:26 +02:00
|
|
|
szFrom[lstrlenW(szFrom) + 1] = '\0';
|
2001-02-26 23:31:38 +01:00
|
|
|
|
2006-08-24 12:16:26 +02:00
|
|
|
lstrcpyW(szTo, szDestPath);
|
|
|
|
szTo[lstrlenW(szDestPath) + 1] = '\0';
|
2002-08-27 03:34:33 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
memcpy(&fileOp, lpFileOp, sizeof(fileOp));
|
|
|
|
fileOp.pFrom = szFrom;
|
|
|
|
fileOp.pTo = szTo;
|
2001-02-26 23:31:38 +01:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
SHFileOperationW(&fileOp);
|
|
|
|
}
|
2000-02-20 19:39:11 +01:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
/* moves a file or directory to another directory */
|
|
|
|
static void move_to_dir(LPSHFILEOPSTRUCTW lpFileOp, FILE_ENTRY *feFrom, FILE_ENTRY *feTo)
|
|
|
|
{
|
|
|
|
WCHAR szDestPath[MAX_PATH];
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
PathCombineW(szDestPath, feTo->szFullPath, feFrom->szFilename);
|
2003-04-19 22:09:09 +02:00
|
|
|
|
2006-03-06 16:44:31 +01:00
|
|
|
if (IsAttribFile(feFrom->attributes))
|
2006-01-23 11:22:59 +01:00
|
|
|
SHNotifyMoveFileW(feFrom->szFullPath, szDestPath);
|
|
|
|
else if (!(lpFileOp->fFlags & FOF_FILESONLY && feFrom->bFromWildcard))
|
|
|
|
move_dir_to_dir(lpFileOp, feFrom, szDestPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the FO_MOVE operation */
|
|
|
|
static HRESULT move_files(LPSHFILEOPSTRUCTW lpFileOp, FILE_LIST *flFrom, FILE_LIST *flTo)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
FILE_ENTRY *entryToMove;
|
|
|
|
FILE_ENTRY *fileDest;
|
|
|
|
|
|
|
|
if (!flFrom->dwNumFiles || !flTo->dwNumFiles)
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
|
|
|
if (!(lpFileOp->fFlags & FOF_MULTIDESTFILES) &&
|
|
|
|
flTo->dwNumFiles > 1 && flFrom->dwNumFiles > 1)
|
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(lpFileOp->fFlags & FOF_MULTIDESTFILES) &&
|
|
|
|
!flFrom->bAnyDirectories &&
|
|
|
|
flFrom->dwNumFiles > flTo->dwNumFiles)
|
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PathFileExistsW(flTo->feFiles[0].szDirectory))
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
|
|
|
if ((lpFileOp->fFlags & FOF_MULTIDESTFILES) &&
|
|
|
|
flFrom->dwNumFiles != flTo->dwNumFiles)
|
|
|
|
{
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileDest = &flTo->feFiles[0];
|
|
|
|
for (i = 0; i < flFrom->dwNumFiles; i++)
|
|
|
|
{
|
|
|
|
entryToMove = &flFrom->feFiles[i];
|
|
|
|
|
|
|
|
if (lpFileOp->fFlags & FOF_MULTIDESTFILES)
|
|
|
|
fileDest = &flTo->feFiles[i];
|
|
|
|
|
|
|
|
if (!PathFileExistsW(fileDest->szDirectory))
|
|
|
|
return ERROR_CANCELLED;
|
|
|
|
|
2006-03-06 16:44:31 +01:00
|
|
|
if (fileDest->bExists && IsAttribDir(fileDest->attributes))
|
2006-01-23 11:22:59 +01:00
|
|
|
move_to_dir(lpFileOp, entryToMove, fileDest);
|
|
|
|
else
|
|
|
|
SHNotifyMoveFileW(entryToMove->szFullPath, fileDest->szFullPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the FO_RENAME files */
|
|
|
|
static HRESULT rename_files(LPSHFILEOPSTRUCTW lpFileOp, FILE_LIST *flFrom, FILE_LIST *flTo)
|
|
|
|
{
|
|
|
|
FILE_ENTRY *feFrom;
|
|
|
|
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;
|
|
|
|
|
|
|
|
return SHNotifyMoveFileW(feFrom->szFullPath, feTo->szFullPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* alert the user if an unsupported flag is used */
|
|
|
|
static void check_flags(FILEOP_FLAGS fFlags)
|
|
|
|
{
|
2006-07-19 18:37:02 +02:00
|
|
|
WORD wUnsupportedFlags = FOF_NO_CONNECTED_ELEMENTS |
|
2006-06-27 21:51:35 +02:00
|
|
|
FOF_NOCOPYSECURITYATTRIBS | FOF_NORECURSEREPARSE |
|
2006-01-23 11:22:59 +01:00
|
|
|
FOF_RENAMEONCOLLISION | FOF_WANTMAPPINGHANDLE;
|
|
|
|
|
|
|
|
if (fFlags & wUnsupportedFlags)
|
|
|
|
FIXME("Unsupported flags: %04x\n", fFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHFileOperationW [SHELL32.@]
|
|
|
|
*
|
|
|
|
* See SHFileOperationA
|
|
|
|
*/
|
|
|
|
int WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
|
|
|
|
{
|
2007-02-09 17:13:25 +01:00
|
|
|
FILE_OPERATION op;
|
2006-01-23 11:22:59 +01:00
|
|
|
FILE_LIST flFrom, flTo;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!lpFileOp)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
ZeroMemory(&op, sizeof(op));
|
|
|
|
op.req = lpFileOp;
|
|
|
|
op.bManyItems = (flFrom.dwNumFiles > 1);
|
|
|
|
|
2006-01-23 11:22:59 +01:00
|
|
|
switch (lpFileOp->wFunc)
|
|
|
|
{
|
|
|
|
case FO_COPY:
|
2007-02-09 17:13:25 +01:00
|
|
|
ret = copy_files(&op, &flFrom, &flTo);
|
2006-01-23 11:22:59 +01:00
|
|
|
break;
|
|
|
|
case FO_DELETE:
|
|
|
|
ret = delete_files(lpFileOp, &flFrom);
|
|
|
|
break;
|
|
|
|
case FO_MOVE:
|
|
|
|
ret = move_files(lpFileOp, &flFrom, &flTo);
|
|
|
|
break;
|
|
|
|
case FO_RENAME:
|
|
|
|
ret = rename_files(lpFileOp, &flFrom, &flTo);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy_file_list(&flFrom);
|
|
|
|
|
|
|
|
if (lpFileOp->wFunc != FO_DELETE)
|
|
|
|
destroy_file_list(&flTo);
|
|
|
|
|
|
|
|
if (ret == ERROR_CANCELLED)
|
|
|
|
lpFileOp->fAnyOperationsAborted = TRUE;
|
|
|
|
|
|
|
|
return ret;
|
2000-02-20 19:39:11 +01:00
|
|
|
}
|
|
|
|
|
2004-10-18 21:33:45 +02:00
|
|
|
#define SHDSA_GetItemCount(hdsa) (*(int*)(hdsa))
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* 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
|
|
|
|
*
|
2005-11-10 12:15:22 +01:00
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
2004-10-18 21:33:45 +02:00
|
|
|
*/
|
|
|
|
void WINAPI SHFreeNameMappings(HANDLE hNameMapping)
|
|
|
|
{
|
|
|
|
if (hNameMapping)
|
|
|
|
{
|
|
|
|
int i = SHDSA_GetItemCount((HDSA)hNameMapping) - 1;
|
|
|
|
|
|
|
|
for (; i>= 0; i--)
|
|
|
|
{
|
|
|
|
LPSHNAMEMAPPINGW lp = DSA_GetItemPtr((HDSA)hNameMapping, i);
|
|
|
|
|
|
|
|
SHFree(lp->pszOldPath);
|
|
|
|
SHFree(lp->pszNewPath);
|
|
|
|
}
|
|
|
|
DSA_Destroy((HDSA)hNameMapping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
/*************************************************************************
|
- Revert wrong -noname markup for Drag*, DoEnvironmentSubst and
SHGetNewLinkInfo{A,W}.
- Also mark stub exports -noname when they are exported by ordinal
only on win98/2k.
- Implementation level stubs for SheChangeDirA, SheGetDirA,
SHHelpShortcuts_RunDLL{A,W}.
- New spec file stubs for Control_RunDLLAsUserW,
FixupOptionalComponents, OCInstall, SHChangeNotifySuspendResume,
SHCreateProcessAsUserW, SHExtractIconsW,
SHInvokePrinterCommand{A,W}, SHIsFileAvailableOffline,
SHLoadNonloadedIconOverlayIdentifiers, SHPathPrepareForWrite{A,W},
ShellExec_RunDLL{,A,W}, SHGetIconOverlayIndex{A,W}.
2005-02-21 19:37:33 +01:00
|
|
|
* SheGetDirA [SHELL32.@]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SheGetDirA(LPSTR u, LPSTR v)
|
|
|
|
{ FIXME("%p %p stub\n",u,v);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SheGetDirW [SHELL32.@]
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SheGetDirW(LPWSTR u, LPWSTR v)
|
|
|
|
{ FIXME("%p %p stub\n",u,v);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
- Revert wrong -noname markup for Drag*, DoEnvironmentSubst and
SHGetNewLinkInfo{A,W}.
- Also mark stub exports -noname when they are exported by ordinal
only on win98/2k.
- Implementation level stubs for SheChangeDirA, SheGetDirA,
SHHelpShortcuts_RunDLL{A,W}.
- New spec file stubs for Control_RunDLLAsUserW,
FixupOptionalComponents, OCInstall, SHChangeNotifySuspendResume,
SHCreateProcessAsUserW, SHExtractIconsW,
SHInvokePrinterCommand{A,W}, SHIsFileAvailableOffline,
SHLoadNonloadedIconOverlayIdentifiers, SHPathPrepareForWrite{A,W},
ShellExec_RunDLL{,A,W}, SHGetIconOverlayIndex{A,W}.
2005-02-21 19:37:33 +01:00
|
|
|
* SheChangeDirA [SHELL32.@]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SheChangeDirA(LPSTR u)
|
|
|
|
{ FIXME("(%s),stub\n",debugstr_a(u));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SheChangeDirW [SHELL32.@]
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SheChangeDirW(LPWSTR u)
|
|
|
|
{ FIXME("(%s),stub\n",debugstr_w(u));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:04:19 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* IsNetDrive [SHELL32.66]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsNetDrive(DWORD drive)
|
|
|
|
{
|
|
|
|
char root[4];
|
|
|
|
strcpy(root, "A:\\");
|
2003-02-01 01:41:30 +01:00
|
|
|
root[0] += (char)drive;
|
2001-01-19 00:04:19 +01:00
|
|
|
return (GetDriveTypeA(root) == DRIVE_REMOTE);
|
|
|
|
}
|
2004-06-14 18:56:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* RealDriveType [SHELL32.524]
|
|
|
|
*/
|
|
|
|
INT WINAPI RealDriveType(INT drive, BOOL bQueryNet)
|
|
|
|
{
|
|
|
|
char root[] = "A:\\";
|
|
|
|
root[0] += (char)drive;
|
|
|
|
return GetDriveTypeA(root);
|
|
|
|
}
|