2000-02-20 19:39:11 +01:00
|
|
|
/*
|
|
|
|
* SHFileOperation
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* Copyright 2000 Juergen Schmied
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-02-20 19:39:11 +01:00
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-11-06 23:31:19 +01:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "shellapi.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"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "shell32_main.h"
|
2001-08-16 20:49:56 +02:00
|
|
|
#include "undocshell.h"
|
2001-01-07 22:50:52 +01:00
|
|
|
#include "shlwapi.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.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
|
|
|
|
2001-02-21 05:01:20 +01:00
|
|
|
BOOL SHELL_WarnItemDelete (int nKindOfDialog, LPCSTR szDir)
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
{
|
2000-08-11 02:38:44 +02:00
|
|
|
char szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
|
2001-02-21 05:01:20 +01:00
|
|
|
if(nKindOfDialog == ASK_DELETE_FILE)
|
|
|
|
{
|
|
|
|
LoadStringA(shell32_hInstance, IDS_DELETEITEM_TEXT, szText,
|
|
|
|
sizeof(szText));
|
|
|
|
LoadStringA(shell32_hInstance, IDS_DELETEITEM_CAPTION,
|
|
|
|
szCaption, sizeof(szCaption));
|
|
|
|
}
|
|
|
|
else if(nKindOfDialog == ASK_DELETE_FOLDER)
|
|
|
|
{
|
|
|
|
LoadStringA(shell32_hInstance, IDS_DELETEITEM_TEXT, szText,
|
|
|
|
sizeof(szText));
|
|
|
|
LoadStringA(shell32_hInstance, IDS_DELETEFOLDER_CAPTION,
|
|
|
|
szCaption, sizeof(szCaption));
|
|
|
|
}
|
|
|
|
else if(nKindOfDialog == ASK_DELETE_MULTIPLE_ITEM)
|
|
|
|
{
|
|
|
|
LoadStringA(shell32_hInstance, IDS_DELETEMULTIPLE_TEXT, szText,
|
|
|
|
sizeof(szText));
|
|
|
|
LoadStringA(shell32_hInstance, IDS_DELETEITEM_CAPTION,
|
|
|
|
szCaption, sizeof(szCaption));
|
|
|
|
}
|
|
|
|
else {
|
2001-05-09 19:31:31 +02:00
|
|
|
FIXME("Called without a valid nKindOfDialog specified!\n");
|
2001-02-21 05:01:20 +01:00
|
|
|
LoadStringA(shell32_hInstance, IDS_DELETEITEM_TEXT, szText,
|
|
|
|
sizeof(szText));
|
|
|
|
LoadStringA(shell32_hInstance, IDS_DELETEITEM_CAPTION,
|
|
|
|
szCaption, sizeof(szCaption));
|
|
|
|
}
|
|
|
|
|
2000-08-11 02:38:44 +02:00
|
|
|
FormatMessageA(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
2000-10-15 02:31:23 +02:00
|
|
|
szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)&szDir);
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
|
2000-08-11 02:38:44 +02:00
|
|
|
return (IDOK == MessageBoxA(GetActiveWindow(), szBuffer, szCaption, MB_OKCANCEL | MB_ICONEXCLAMATION));
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
}
|
|
|
|
|
2000-02-26 19:48:16 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* SHELL_DeleteDirectoryA()
|
|
|
|
*
|
|
|
|
* like rm -r
|
|
|
|
*/
|
|
|
|
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
BOOL SHELL_DeleteDirectoryA(LPCSTR pszDir, BOOL bShowUI)
|
2000-02-26 19:48:16 +01:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
HANDLE hFind;
|
|
|
|
WIN32_FIND_DATAA wfd;
|
|
|
|
char szTemp[MAX_PATH];
|
|
|
|
|
|
|
|
strcpy(szTemp, pszDir);
|
|
|
|
PathAddBackslashA(szTemp);
|
|
|
|
strcat(szTemp, "*.*");
|
|
|
|
|
2001-02-21 05:01:20 +01:00
|
|
|
if (bShowUI && !SHELL_WarnItemDelete(ASK_DELETE_FOLDER, pszDir))
|
|
|
|
return FALSE;
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
|
2000-02-26 19:48:16 +01:00
|
|
|
if(INVALID_HANDLE_VALUE != (hFind = FindFirstFileA(szTemp, &wfd)))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(strcasecmp(wfd.cFileName, ".") && strcasecmp(wfd.cFileName, ".."))
|
|
|
|
{
|
|
|
|
strcpy(szTemp, pszDir);
|
|
|
|
PathAddBackslashA(szTemp);
|
|
|
|
strcat(szTemp, wfd.cFileName);
|
|
|
|
|
|
|
|
if(FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
SHELL_DeleteDirectoryA(szTemp, FALSE);
|
2000-02-26 19:48:16 +01:00
|
|
|
else
|
|
|
|
DeleteFileA(szTemp);
|
|
|
|
}
|
|
|
|
} while(FindNextFileA(hFind, &wfd));
|
|
|
|
|
|
|
|
FindClose(hFind);
|
|
|
|
ret = RemoveDirectoryA(pszDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-02-21 05:01:20 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* SHELL_DeleteFileA()
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL SHELL_DeleteFileA(LPCSTR pszFile, BOOL bShowUI)
|
|
|
|
{
|
|
|
|
if (bShowUI && !SHELL_WarnItemDelete(ASK_DELETE_FILE, pszFile))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return DeleteFileA(pszFile);
|
|
|
|
}
|
|
|
|
|
2000-02-26 19:48:16 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateDirectory [SHELL32.165]
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* exported by ordinal
|
|
|
|
* not sure about LPSECURITY_ATTRIBUTES
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SHCreateDirectory(LPSECURITY_ATTRIBUTES sec,LPCSTR path)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
TRACE("(%p,%s)\n",sec,path);
|
|
|
|
if ((ret = CreateDirectoryA(path,sec)))
|
|
|
|
{
|
|
|
|
SHChangeNotifyA(SHCNE_MKDIR, SHCNF_PATHA, path, NULL);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Win32DeleteFile [SHELL32.164]
|
|
|
|
*
|
|
|
|
* Deletes a file. Also triggers a change notify if one exists.
|
|
|
|
*
|
|
|
|
* FIXME:
|
|
|
|
* Verified on Win98 / IE 5 (SHELL32 4.72, March 1999 build) to be
|
|
|
|
* ANSI. Is this Unicode on NT?
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL WINAPI Win32DeleteFile(LPSTR fName)
|
|
|
|
{
|
|
|
|
TRACE("%p(%s)\n", fName, fName);
|
|
|
|
|
|
|
|
DeleteFileA(fName);
|
|
|
|
SHChangeNotifyA(SHCNE_DELETE, SHCNF_PATHA, fName, NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-02-20 19:39:11 +01:00
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SHFileOperationA [SHELL32.@]
|
2000-02-20 19:39:11 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* exported by name
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SHFileOperationA (LPSHFILEOPSTRUCTA lpFileOp)
|
|
|
|
{
|
2001-02-26 23:31:38 +01:00
|
|
|
LPSTR pFrom = (LPSTR)lpFileOp->pFrom;
|
|
|
|
LPSTR pTo = (LPSTR)lpFileOp->pTo;
|
|
|
|
LPSTR pTempTo;
|
2002-02-15 19:20:18 +01:00
|
|
|
TRACE("flags (0x%04x) : %s%s%s%s%s%s%s%s%s%s%s%s \n", lpFileOp->fFlags,
|
|
|
|
lpFileOp->fFlags & FOF_MULTIDESTFILES ? "FOF_MULTIDESTFILES " : "",
|
|
|
|
lpFileOp->fFlags & FOF_CONFIRMMOUSE ? "FOF_CONFIRMMOUSE " : "",
|
|
|
|
lpFileOp->fFlags & FOF_SILENT ? "FOF_SILENT " : "",
|
|
|
|
lpFileOp->fFlags & FOF_RENAMEONCOLLISION ? "FOF_RENAMEONCOLLISION " : "",
|
|
|
|
lpFileOp->fFlags & FOF_NOCONFIRMATION ? "FOF_NOCONFIRMATION " : "",
|
|
|
|
lpFileOp->fFlags & FOF_WANTMAPPINGHANDLE ? "FOF_WANTMAPPINGHANDLE " : "",
|
|
|
|
lpFileOp->fFlags & FOF_ALLOWUNDO ? "FOF_ALLOWUNDO " : "",
|
|
|
|
lpFileOp->fFlags & FOF_FILESONLY ? "FOF_FILESONLY " : "",
|
|
|
|
lpFileOp->fFlags & FOF_SIMPLEPROGRESS ? "FOF_SIMPLEPROGRESS " : "",
|
|
|
|
lpFileOp->fFlags & FOF_NOCONFIRMMKDIR ? "FOF_NOCONFIRMMKDIR " : "",
|
|
|
|
lpFileOp->fFlags & FOF_NOERRORUI ? "FOF_NOERRORUI " : "",
|
|
|
|
lpFileOp->fFlags & 0xf800 ? "MORE-UNKNOWN-Flags" : "");
|
2001-02-26 23:31:38 +01:00
|
|
|
switch(lpFileOp->wFunc) {
|
2002-02-15 19:20:18 +01:00
|
|
|
case FO_COPY: {
|
|
|
|
/* establish when pTo is interpreted as the name of the destination file
|
|
|
|
* or the directory where the Fromfile should be copied to.
|
|
|
|
* This depends on:
|
|
|
|
* (1) pTo points to the name of an existing directory;
|
|
|
|
* (2) the flag FOF_MULTIDESTFILES is present;
|
|
|
|
* (3) whether pFrom point to multiple filenames.
|
|
|
|
*
|
|
|
|
* Some experiments:
|
|
|
|
*
|
|
|
|
* destisdir 1 1 1 1 0 0 0 0
|
|
|
|
* FOF_MULTIDESTFILES 1 1 0 0 1 1 0 0
|
|
|
|
* multiple from filenames 1 0 1 0 1 0 1 0
|
|
|
|
* ---------------
|
|
|
|
* copy files to dir 1 0 1 1 0 0 1 0
|
|
|
|
* create dir 0 0 0 0 0 0 1 0
|
|
|
|
*/
|
|
|
|
int multifrom = pFrom[strlen(pFrom) + 1] != '\0';
|
|
|
|
int destisdir = PathIsDirectoryA( pTo );
|
|
|
|
int copytodir = 0;
|
2001-02-26 23:31:38 +01:00
|
|
|
TRACE("File Copy:\n");
|
2002-02-15 19:20:18 +01:00
|
|
|
if( destisdir ) {
|
|
|
|
if ( !((lpFileOp->fFlags & FOF_MULTIDESTFILES) && !multifrom))
|
|
|
|
copytodir = 1;
|
|
|
|
} else {
|
|
|
|
if ( !(lpFileOp->fFlags & FOF_MULTIDESTFILES) && multifrom)
|
|
|
|
copytodir = 1;
|
|
|
|
}
|
|
|
|
if ( copytodir ) {
|
|
|
|
char *fromfile;
|
|
|
|
int lenPTo;
|
|
|
|
if ( ! destisdir) {
|
|
|
|
TRACE(" creating directory %s\n",pTo);
|
|
|
|
SHCreateDirectory(NULL,pTo);
|
|
|
|
}
|
|
|
|
lenPTo = strlen(pTo);
|
|
|
|
while(1) {
|
|
|
|
if(!pFrom[0]) break;
|
|
|
|
fromfile = PathFindFileNameA( pFrom);
|
|
|
|
pTempTo = HeapAlloc(GetProcessHeap(), 0, lenPTo + strlen(fromfile) + 2);
|
|
|
|
if (pTempTo) {
|
|
|
|
strcpy(pTempTo,pTo);
|
|
|
|
if(lenPTo && pTo[lenPTo] != '\\')
|
|
|
|
strcat(pTempTo,"\\");
|
|
|
|
strcat(pTempTo,fromfile);
|
|
|
|
TRACE(" From='%s' To='%s'\n", pFrom, pTempTo);
|
|
|
|
CopyFileA(pFrom, pTempTo, FALSE);
|
2001-02-26 23:31:38 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pTempTo);
|
|
|
|
}
|
2002-02-15 19:20:18 +01:00
|
|
|
pFrom += strlen(pFrom) + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while(1) {
|
|
|
|
if(!pFrom[0]) break;
|
|
|
|
if(!pTo[0]) break;
|
|
|
|
TRACE(" From='%s' To='%s'\n", pFrom, pTo);
|
2001-02-26 23:31:38 +01:00
|
|
|
|
2002-02-15 19:20:18 +01:00
|
|
|
pTempTo = HeapAlloc(GetProcessHeap(), 0, strlen(pTo)+1);
|
|
|
|
if (pTempTo)
|
|
|
|
{
|
|
|
|
strcpy( pTempTo, pTo );
|
|
|
|
PathRemoveFileSpecA(pTempTo);
|
|
|
|
TRACE(" Creating Directory '%s'\n", pTempTo);
|
|
|
|
SHCreateDirectory(NULL,pTempTo);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pTempTo);
|
|
|
|
}
|
|
|
|
CopyFileA(pFrom, pTo, FALSE);
|
|
|
|
|
|
|
|
pFrom += strlen(pFrom) + 1;
|
|
|
|
pTo += strlen(pTo) + 1;
|
|
|
|
}
|
|
|
|
}
|
2001-02-26 23:31:38 +01:00
|
|
|
TRACE("Setting AnyOpsAborted=FALSE\n");
|
|
|
|
lpFileOp->fAnyOperationsAborted=FALSE;
|
|
|
|
return 0;
|
2002-02-15 19:20:18 +01:00
|
|
|
}
|
2001-02-26 23:31:38 +01:00
|
|
|
|
|
|
|
case FO_DELETE:
|
|
|
|
TRACE("File Delete:\n");
|
|
|
|
while(1) {
|
|
|
|
if(!pFrom[0]) break;
|
|
|
|
TRACE(" File='%s'\n", pFrom);
|
|
|
|
DeleteFileA(pFrom);
|
|
|
|
pFrom += strlen(pFrom) + 1;
|
|
|
|
}
|
|
|
|
TRACE("Setting AnyOpsAborted=FALSE\n");
|
|
|
|
lpFileOp->fAnyOperationsAborted=FALSE;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled shell file operation %d\n", lpFileOp->wFunc);
|
|
|
|
}
|
|
|
|
|
2000-02-20 19:39:11 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SHFileOperationW [SHELL32.@]
|
2000-02-20 19:39:11 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* exported by name
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SHFileOperationW (LPSHFILEOPSTRUCTW lpFileOp)
|
|
|
|
{
|
|
|
|
FIXME("(%p):stub.\n", lpFileOp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SHFileOperation [SHELL32.@]
|
2000-02-20 19:39:11 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SHFileOperationAW(LPVOID lpFileOp)
|
|
|
|
{
|
2000-08-14 16:35:01 +02:00
|
|
|
if (SHELL_OsIsUnicode())
|
2000-02-20 19:39:11 +01:00
|
|
|
return SHFileOperationW(lpFileOp);
|
|
|
|
return SHFileOperationA(lpFileOp);
|
|
|
|
}
|
Complete cleanup, bugfixes.
New: PathStripPath, PathMakeUniqueName, PathStripToRoot,
PathGetShortPath, PathParseIconLocation, PathRemoveExtension,
PathRemoveArgs, PathAppend, PathBuildRoot, PathCanonicalize,
PathFindNextComponent, PathRemoveFileSpec.
2000-04-28 22:23:46 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SheGetDirW [SHELL32.281]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SheGetDirW(LPWSTR u, LPWSTR v)
|
|
|
|
{ FIXME("%p %p stub\n",u,v);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SheChangeDirW [SHELL32.274]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
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:\\");
|
|
|
|
root[0] += drive;
|
|
|
|
return (GetDriveTypeA(root) == DRIVE_REMOTE);
|
|
|
|
}
|