Moved file functions to shlfileop.c

New SHELL_DeleteDirectoryA
Use shell notifications.
Enabled file manipulation functions.
This commit is contained in:
Juergen Schmied 2000-02-26 18:48:16 +00:00 committed by Alexandre Julliard
parent d52e04781b
commit 93e99127f5
8 changed files with 265 additions and 70 deletions

View File

@ -7,8 +7,11 @@
* The contents of a pidl should never used from a application
* directly.
*
* This stuff is used from SHGetFileAttributes, ShellFolder
* EnumIDList and ShellView.
* Undocumented:
* MS says: the abID of SHITEMID should be treated as binary data and not
* be interpreted by applications. Applies to everyone but MS itself.
* Word95 interprets the contents of abID (Filesize/Date) so we have to go
* for binary compatibility here.
*/
#ifndef __WINE_PIDL_H

View File

@ -7,8 +7,89 @@
#include "shell32_main.h"
#include "winversion.h"
#include "shlobj.h"
DEFAULT_DEBUG_CHANNEL(shell);
/**************************************************************************
* SHELL_DeleteDirectoryA()
*
* like rm -r
*/
BOOL SHELL_DeleteDirectoryA(LPCSTR pszDir)
{
BOOL ret = FALSE;
HANDLE hFind;
WIN32_FIND_DATAA wfd;
char szTemp[MAX_PATH];
strcpy(szTemp, pszDir);
PathAddBackslashA(szTemp);
strcat(szTemp, "*.*");
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)
SHELL_DeleteDirectoryA(szTemp);
else
DeleteFileA(szTemp);
}
} while(FindNextFileA(hFind, &wfd));
FindClose(hFind);
ret = RemoveDirectoryA(pszDir);
}
return ret;
}
/*************************************************************************
* 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;
}
/*************************************************************************
* SHFileOperationA [SHELL32.243]
*
@ -43,4 +124,3 @@ DWORD WINAPI SHFileOperationAW(LPVOID lpFileOp)
return SHFileOperationW(lpFileOp);
return SHFileOperationA(lpFileOp);
}

View File

@ -1090,10 +1090,12 @@ static HRESULT WINAPI IShellFolder_fnSetNameOf(
_ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface)
char szSrc[MAX_PATH], szDest[MAX_PATH];
int len;
BOOL bIsFolder = _ILIsFolder(ILFindLastID(pidl));
TRACE("(%p)->(%u,pidl=%p,%s,%lu,%p),stub!\n",
This,hwndOwner,pidl,debugstr_w(lpName),dwFlags,pPidlOut);
TRACE("(%p)->(%u,pidl=%p,%s,%lu,%p)\n",
This,hwndOwner,pidl,debugstr_w(lpName),dwFlags,pPidlOut);
/* build source path */
if (dwFlags & SHGDN_INFOLDER)
{
strcpy(szSrc, This->sMyPath);
@ -1105,15 +1107,18 @@ static HRESULT WINAPI IShellFolder_fnSetNameOf(
{
SHGetPathFromIDListA(pidl, szSrc);
}
/* build destination path */
strcpy(szDest, This->sMyPath);
PathAddBackslashA(szDest);
len = strlen (szDest);
lstrcpynWtoA(szDest+len, lpName, MAX_PATH-len);
TRACE("src=%s dest=%s\n", szSrc, szDest);
if (MoveFileA(szSrc, szDest))
if ( MoveFileA(szSrc, szDest) )
{
if (pPidlOut) *pPidlOut = SHSimpleIDListFromPathA(szDest);
SHChangeNotifyA( bIsFolder?SHCNE_RENAMEFOLDER:SHCNE_RENAMEITEM, SHCNF_PATHA, szSrc, szDest);
return S_OK;
}
return E_FAIL;
@ -1430,8 +1435,8 @@ static HRESULT WINAPI ISFHelper_fnDeleteItems(
{
LPITEMIDLIST pidl;
/* if (! RemoveDirectoryA(szPath)) return E_FAIL; */
MESSAGE("would delete %s\n", szPath);
MESSAGE("delete %s\n", szPath);
if (! RemoveDirectoryA(szPath)) return E_FAIL;
pidl = ILCombine(This->absPidl, apidl[i]);
SHChangeNotifyA(SHCNE_RMDIR, SHCNF_IDLIST, pidl, NULL);
SHFree(pidl);
@ -1440,8 +1445,8 @@ static HRESULT WINAPI ISFHelper_fnDeleteItems(
{
LPITEMIDLIST pidl;
/* if (! DeleteFileA(szPath)) return E_FAIL; */
MESSAGE("would delete %s\n", szPath);
MESSAGE("delete %s\n", szPath);
if (! DeleteFileA(szPath)) return E_FAIL;
pidl = ILCombine(This->absPidl, apidl[i]);
SHChangeNotifyA(SHCNE_DELETE, SHCNF_IDLIST, pidl, NULL);
SHFree(pidl);

View File

@ -163,7 +163,7 @@ static int FM_InitMenuPopup(HMENU hmenu, LPITEMIDLIST pAlternatePidl)
if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf, 1, &pidlTemp, &ulItemAttr)))
{
ILGetDisplayName( pidlTemp, sTemp);
if (! (PidlToSicIndex(lpsf, pidlTemp, FALSE, &iIcon)))
if (! (PidlToSicIndex(lpsf, pidlTemp, FALSE, 0, &iIcon)))
iIcon = FM_BLANK_ICON;
if ( SFGAO_FOLDER & ulItemAttr)
{

View File

@ -69,8 +69,8 @@ typedef struct
IShellFolder2* pSF2Parent;
IShellBrowser* pShellBrowser;
ICommDlgBrowser* pCommDlgBrowser;
HWND hWnd;
HWND hWndList;
HWND hWnd; /* SHELLDLL_DefView */
HWND hWndList; /* ListView control */
HWND hWndParent;
FOLDERSETTINGS FolderSettings;
HMENU hMenu;
@ -78,6 +78,8 @@ typedef struct
UINT cidl;
LPITEMIDLIST *apidl;
LISTVIEW_SORT_INFO ListViewSortInfo;
HANDLE hNotify; /* change notification handle */
HANDLE hAccel;
} IShellViewImpl;
static struct ICOM_VTABLE(IShellView) svvt;
@ -112,6 +114,8 @@ static struct ICOM_VTABLE(IViewObject) vovt;
#define ID_LISTVIEW 2000
#define SHV_CHANGE_NOTIFY WM_USER + 0x1111
#define TOOLBAR_ID (L"SHELLDLL_DefView")
/*windowsx.h */
#define GET_WM_COMMAND_ID(wp, lp) LOWORD(wp)
@ -462,6 +466,87 @@ static INT CALLBACK ShellView_ListViewCompareItems(LPVOID lParam1, LPVOID lParam
}
/**********************************************************
* LV_FindItemByPidl()
*/
static int LV_FindItemByPidl(
IShellViewImpl * This,
LPITEMIDLIST pidl)
{
LVITEMA lvItem;
ZeroMemory(&lvItem, sizeof(LVITEMA));
lvItem.mask = LVIF_PARAM;
for(lvItem.iItem = 0; ListView_GetItemA(This->hWndList, &lvItem); lvItem.iItem++)
{
LPITEMIDLIST currentpidl = (LPITEMIDLIST) lvItem.lParam;
HRESULT hr = IShellFolder_CompareIDs(This->pSFParent, 0, pidl, currentpidl);
if(SUCCEEDED(hr) && !HRESULT_CODE(hr))
{
return lvItem.iItem;
}
}
return -1;
}
/**********************************************************
* LV_AddItem()
*/
static BOOLEAN LV_AddItem(IShellViewImpl * This, LPITEMIDLIST pidl)
{
LVITEMA lvItem;
FIXME("(%p)(pidl=%p)\n", This, pidl);
ZeroMemory(&lvItem, sizeof(lvItem)); /* create the listview item*/
lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; /*set the mask*/
lvItem.iItem = ListView_GetItemCount(This->hWndList); /*add the item to the end of the list*/
lvItem.lParam = (LPARAM) ILClone(ILFindLastID(pidl)); /*set the item's data*/
lvItem.pszText = LPSTR_TEXTCALLBACKA; /*get text on a callback basis*/
lvItem.iImage = I_IMAGECALLBACK; /*get the image on a callback basis*/
return (-1==ListView_InsertItemA(This->hWndList, &lvItem))? FALSE: TRUE;
}
/**********************************************************
* LV_DeleteItem()
*/
static BOOLEAN LV_DeleteItem(IShellViewImpl * This, LPITEMIDLIST pidl)
{
int nIndex;
FIXME("(%p)(pidl=%p)\n", This, pidl);
nIndex = LV_FindItemByPidl(This, ILFindLastID(pidl));
return (-1==ListView_DeleteItem(This->hWndList, nIndex))? FALSE: TRUE;
}
/**********************************************************
* LV_RenameItem()
*/
static BOOLEAN LV_RenameItem(IShellViewImpl * This, LPITEMIDLIST pidlOld, LPITEMIDLIST pidlNew )
{
int nItem;
LVITEMA lvItem;
FIXME("(%p)(pidlold=%p pidlnew=%p)\n", This, pidlOld, pidlNew);
nItem = LV_FindItemByPidl(This, ILFindLastID(pidlOld));
if ( -1 != nItem )
{
ZeroMemory(&lvItem, sizeof(lvItem)); /* create the listview item*/
lvItem.mask = LVIF_PARAM; /* only the pidl */
lvItem.iItem = nItem;
ListView_GetItemA(This->hWndList, &lvItem);
SHFree((LPITEMIDLIST)lvItem.lParam);
lvItem.mask = LVIF_PARAM;
lvItem.iItem = nItem;
lvItem.lParam = (LPARAM) ILClone(ILFindLastID(pidlNew)); /* set the item's data */
ListView_SetItemA(This->hWndList, &lvItem);
ListView_Update(This->hWndList, nItem);
return TRUE; /* fixme: better handling */
}
return FALSE;
}
/**********************************************************
* ShellView_FillList()
*
@ -476,7 +561,6 @@ static HRESULT ShellView_FillList(IShellViewImpl * This)
LPITEMIDLIST pidl;
DWORD dwFetched;
UINT i;
LVITEMA lvItem;
HRESULT hRes;
HDPA hdpa;
@ -516,18 +600,16 @@ static HRESULT ShellView_FillList(IShellViewImpl * This)
for (i=0; i < DPA_GetPtrCount(hdpa); ++i) /* DPA_GetPtrCount is a macro*/
{
pidl = (LPITEMIDLIST)DPA_GetPtr(hdpa, i);
if (IncludeObject(This, pidl) == S_OK) /* in a commdlg This works as a filemask*/
/* in a commdlg This works as a filemask*/
if ( IncludeObject(This, pidl)==S_OK )
{
ZeroMemory(&lvItem, sizeof(lvItem)); /* create the listviewitem*/
lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; /*set the mask*/
lvItem.iItem = ListView_GetItemCount(This->hWndList); /*add the item to the end of the list*/
lvItem.lParam = (LPARAM) pidl; /*set the item's data*/
lvItem.pszText = LPSTR_TEXTCALLBACKA; /*get text on a callback basis*/
lvItem.iImage = I_IMAGECALLBACK; /*get the image on a callback basis*/
ListView_InsertItemA(This->hWndList, &lvItem);
if(! LV_AddItem(This, pidl)) SHFree(pidl); /* insert failed: PIDL not owned by the LV */
}
else
SHFree(pidl); /* the listview has the COPY*/
{
SHFree(pidl); /* not inserted */
}
}
/*turn the listview's redrawing back on and force it to draw*/
@ -539,34 +621,15 @@ static HRESULT ShellView_FillList(IShellViewImpl * This)
return S_OK;
}
/**********************************************************
* FindItemByPidl()
*/
static int FindItemByPidl(
IShellViewImpl * This,
LPITEMIDLIST pidl)
{
LVITEMA lvItem;
ZeroMemory(&lvItem, sizeof(LVITEMA));
lvItem.mask = LVIF_PARAM;
for(lvItem.iItem = 0; ListView_GetItemA(This->hWndList, &lvItem); lvItem.iItem++)
{
LPITEMIDLIST currentpidl = (LPITEMIDLIST) lvItem.lParam;
HRESULT hr = IShellFolder_CompareIDs(This->pSFParent, 0, pidl, currentpidl);
if(SUCCEEDED(hr) && !HRESULT_CODE(hr))
{
return lvItem.iItem;
}
}
return -1;
}
/**********************************************************
* ShellView_OnCreate()
*/
static LRESULT ShellView_OnCreate(IShellViewImpl * This)
{
IDropTarget* pdt;
NOTIFYREGISTER ntreg;
IPersistFolder2 * ppf2 = NULL;
TRACE("%p\n",This);
if(ShellView_CreateList(This))
@ -585,6 +648,20 @@ static LRESULT ShellView_OnCreate(IShellViewImpl * This)
IDropTarget_Release(pdt);
}
}
/* register for receiving notifications */
IShellFolder_QueryInterface(This->pSFParent, &IID_IPersistFolder2, (LPVOID*)&ppf2);
if (ppf2)
{
IPersistFolder2_GetCurFolder(ppf2, &ntreg.pidlPath);
ntreg.bWatchSubtree = FALSE;
This->hNotify = SHChangeNotifyRegister(This->hWnd, SHCNF_IDLIST, SHCNE_ALLEVENTS, SHV_CHANGE_NOTIFY, 1, &ntreg);
SHFree(ntreg.pidlPath);
IPersistFolder2_Release(ppf2);
}
This->hAccel = LoadAcceleratorsA(shell32_hInstance, "shv_accel");
return S_OK;
}
@ -1196,6 +1273,21 @@ static LRESULT ShellView_OnNotify(IShellViewImpl * This, UINT CtlID, LPNMHDR lpn
}
break;
case LVN_KEYDOWN:
{
/* MSG msg;
msg.hwnd = This->hWnd;
msg.message = WM_KEYDOWN;
msg.wParam = plvKeyDown->wVKey;
msg.lParam = 0;
msg.time = 0;
msg.pt = 0;*/
LPNMLVKEYDOWN plvKeyDown = (LPNMLVKEYDOWN) lpnmh;
// TranslateAccelerator(This->hWnd, This->hAccel, &msg)
FIXME("LVN_KEYDOWN key=0x%08x\n",plvKeyDown->wVKey);
}
break;
default:
TRACE("-- %p WM_COMMAND %s unhandled\n", This, SPY_GetMsgName(lpnmh->code));
break;;
@ -1203,6 +1295,33 @@ static LRESULT ShellView_OnNotify(IShellViewImpl * This, UINT CtlID, LPNMHDR lpn
return 0;
}
/**********************************************************
* ShellView_OnChange()
*/
static LRESULT ShellView_OnChange(IShellViewImpl * This, LPITEMIDLIST * Pidls, LONG wEventId)
{
TRACE("(%p)(%p,%p,0x%08lx)\n", This, Pidls[0], Pidls[1], wEventId);
switch(wEventId)
{
case SHCNE_MKDIR:
case SHCNE_CREATE:
LV_AddItem(This, Pidls[0]);
break;
case SHCNE_RMDIR:
case SHCNE_DELETE:
LV_DeleteItem(This, Pidls[0]);
break;
case SHCNE_RENAMEFOLDER:
case SHCNE_RENAMEITEM:
LV_RenameItem(This, Pidls[0], Pidls[1]);
break;
case SHCNE_UPDATEITEM:
break;
}
return TRUE;
}
/**********************************************************
* ShellView_WndProc
*/
@ -1233,6 +1352,7 @@ static LRESULT CALLBACK ShellView_WndProc(HWND hWnd, UINT uMessage, WPARAM wPara
GET_WM_COMMAND_ID(wParam, lParam),
GET_WM_COMMAND_CMD(wParam, lParam),
GET_WM_COMMAND_HWND(wParam, lParam));
case SHV_CHANGE_NOTIFY: return ShellView_OnChange(pThis, (LPITEMIDLIST*)wParam, (LONG)lParam);
case WM_CONTEXTMENU: ShellView_DoContextMenu(pThis, LOWORD(lParam), HIWORD(lParam), FALSE);
return 0;
@ -1246,6 +1366,7 @@ static LRESULT CALLBACK ShellView_WndProc(HWND hWnd, UINT uMessage, WPARAM wPara
{
pRevokeDragDrop(pThis->hWnd);
}
SHChangeNotifyDeregister(pThis->hNotify);
break;
}
@ -1523,8 +1644,7 @@ static HRESULT WINAPI IShellView_fnCreateViewWindow(
CheckToolbar(This);
if(!*phWnd)
return E_FAIL;
if(!*phWnd) return E_FAIL;
return S_OK;
}
@ -1590,7 +1710,7 @@ static HRESULT WINAPI IShellView_fnSelectItem(
TRACE("(%p)->(pidl=%p, 0x%08x) stub\n",This, pidl, uFlags);
i = FindItemByPidl(This, pidl);
i = LV_FindItemByPidl(This, pidl);
if (i != -1)
{
@ -1667,7 +1787,7 @@ static HRESULT WINAPI IShellView_fnEditItem(
TRACE("(%p)->(pidl=%p)\n",This, pidl);
i = FindItemByPidl(This, pidl);
i = LV_FindItemByPidl(This, pidl);
if (i != -1)
{
SetFocus(This->hWndList);

View File

@ -272,8 +272,8 @@ type win32
@ stub SHCreateShellPalette
@ stub SHDeleteEmptyKeyA
@ stub SHDeleteEmptyKeyW
@ stub SHDeleteKeyA
@ stub SHDeleteKeyW
@ stdcall SHDeleteKeyA(long str)SHRegDeleteKeyA
@ stdcall SHDeleteKeyW(long str)SHRegDeleteKeyW
@ stub SHDeleteOrphanKeyA
@ stub SHDeleteOrphanKeyW
@ stub SHDeleteValueA
@ -348,10 +348,10 @@ type win32
@ stub StrNCatW
@ stub StrPBrkA
@ stub StrPBrkW
@ stdcall StrRChrA (str str long) StrRChrA
@ stdcall StrRChrA (str str long) lstrrchr
@ stub StrRChrIA
@ stub StrRChrIW
@ stdcall StrRChrW (wstr wstr long) StrRChrW
@ stdcall StrRChrW (wstr wstr long) lstrrchrw
@ stub StrRStrIA
@ stub StrRStrIW
@ stub StrSpnA

View File

@ -171,7 +171,6 @@ static void DoNewFolder(
if(psv)
{
/* if we are in a shellview do labeledit */
IShellView_Refresh(psv); /* fixme: so long we dont have SHChangeNotify */
IShellView_SelectItem(psv,
pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
|SVSI_FOCUSED|SVSI_SELECT));

View File

@ -309,7 +309,8 @@ static void DoRename(
if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
{
TRACE("(sv=%p)\n",lpSV);
IShellView_EditItem(lpSV, This->apidl[0]);
IShellView_SelectItem(lpSV, This->apidl[0],
SVSI_DESELECTOTHERS|SVSI_EDIT|SVSI_ENSUREVISIBLE|SVSI_FOCUSED|SVSI_SELECT);
IShellView_Release(lpSV);
}
}
@ -320,9 +321,7 @@ static void DoRename(
*
* deletes the currently selected items
*/
static void DoDelete(
IContextMenu *iface,
IShellView *psv)
static void DoDelete(IContextMenu *iface)
{
ICOM_THIS(ItemCmImpl, iface);
ISFHelper * psfhlp;
@ -331,8 +330,6 @@ static void DoDelete(
if (psfhlp)
{
ISFHelper_DeleteItems(psfhlp, This->cidl, This->apidl);
if(psv)
IShellView_Refresh(psv); /* fixme: so long we dont have SHChangeNotify */
ISFHelper_Release(psfhlp);
}
}
@ -421,17 +418,8 @@ static HRESULT WINAPI ISvItemCm_fnInvokeCommand(
{
ICOM_THIS(ItemCmImpl, iface);
LPSHELLBROWSER lpSB;
LPSHELLVIEW lpSV = NULL;
TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
/* get the active IShellView */
lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0);
/* we are not in a ShellView every time */
if (lpSB) IShellBrowser_QueryActiveShellView(lpSB, &lpSV);
if(LOWORD(lpcmi->lpVerb) > FCIDM_SHVIEWLAST) return E_INVALIDARG;
switch(LOWORD(lpcmi->lpVerb))
@ -446,7 +434,7 @@ static HRESULT WINAPI ISvItemCm_fnInvokeCommand(
DoRename(iface, lpcmi->hwnd);
break;
case FCIDM_SHVIEW_DELETE:
DoDelete(iface, lpSV);
DoDelete(iface);
break;
case FCIDM_SHVIEW_COPY:
DoCopyOrCut(iface, lpcmi->hwnd, FALSE);