static HRESULT erase_items(HWND parent,const LPCITEMIDLIST * apidl, UINT cidl, BOOL confirm) { UINT i=0; HRESULT ret = S_OK; LPITEMIDLIST recyclebin; if(confirm) { WCHAR arg[MAX_PATH]; WCHAR message[100]; WCHAR caption[50]; switch(cidl) { case 0: return S_OK; case 1: { WIN32_FIND_DATAW data; TRASH_UnpackItemID(&((*apidl)->mkid),&data); lstrcpynW(arg,data.cFileName,MAX_PATH); LoadStringW(shell32_hInstance,IDS_RECYCLEBIN_ERASEITEM,message, sizeof(message)/sizeof(WCHAR)); break; } default: { static const WCHAR format[]={'%','u','\0'}; LoadStringW(shell32_hInstance,IDS_RECYCLEBIN_ERASEMULTIPLE, message,sizeof(message)/sizeof(WCHAR)); sprintfW(arg,format,cidl); break; } } LoadStringW(shell32_hInstance,IDS_RECYCLEBIN_ERASE_CAPTION,caption, sizeof(caption)/sizeof(WCHAR)); if(ShellMessageBoxW(shell32_hInstance,parent,message,caption, MB_YESNO|MB_ICONEXCLAMATION,arg)!=IDYES) return ret; } SHGetFolderLocation(parent,CSIDL_BITBUCKET,0,0,&recyclebin); for (; i<cidl; i++) { if(SUCCEEDED(TRASH_EraseItem(apidl[i]))) SHChangeNotify(SHCNE_DELETE,SHCNF_IDLIST, ILCombine(recyclebin,apidl[i]),0); } ILFree(recyclebin); return S_OK; }
static void DoRestore(RecycleBinMenu *This) { /*TODO add prompts*/ UINT i; for(i=0;i<This->cidl;i++) { WIN32_FIND_DATAW data; TRASH_UnpackItemID(&((This->apidl[i])->mkid),&data); if(PathFileExistsW(data.cFileName)) { PIDLIST_ABSOLUTE dest_pidl = ILCreateFromPathW(data.cFileName); WCHAR message[100]; WCHAR caption[50]; if(_ILIsFolder(ILFindLastID(dest_pidl))) LoadStringW(shell32_hInstance,IDS_RECYCLEBIN_OVERWRITEFOLDER, message,sizeof(message)/sizeof(WCHAR)); else LoadStringW(shell32_hInstance,IDS_RECYCLEBIN_OVERWRITEFILE, message,sizeof(message)/sizeof(WCHAR)); LoadStringW(shell32_hInstance,IDS_RECYCLEBIN_OVERWRITE_CAPTION, caption,sizeof(caption)/sizeof(WCHAR)); if(ShellMessageBoxW(shell32_hInstance,GetActiveWindow(),message, caption,MB_YESNO|MB_ICONEXCLAMATION, data.cFileName)!=IDYES) continue; } if(SUCCEEDED(TRASH_RestoreItem(This->apidl[i]))) { IPersistFolder2 *persist; LPITEMIDLIST root_pidl; PIDLIST_ABSOLUTE dest_pidl = ILCreateFromPathW(data.cFileName); BOOL is_folder = _ILIsFolder(ILFindLastID(dest_pidl)); IShellFolder2_QueryInterface(This->folder,&IID_IPersistFolder2, (void**)&persist); IPersistFolder2_GetCurFolder(persist,&root_pidl); SHChangeNotify(is_folder ? SHCNE_RMDIR : SHCNE_DELETE, SHCNF_IDLIST,ILCombine(root_pidl,This->apidl[i]),0); SHChangeNotify(is_folder ? SHCNE_MKDIR : SHCNE_CREATE, SHCNF_IDLIST,dest_pidl,0); ILFree(dest_pidl); ILFree(root_pidl); } } }
/* Dialog procedure for RunFileDlg */ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { RUNFILEDLGPARAMS *prfdp = (RUNFILEDLGPARAMS *)GetWindowLongPtrW(hwnd, DWLP_USER); switch (message) { case WM_INITDIALOG: prfdp = (RUNFILEDLGPARAMS *)lParam ; SetWindowLongPtrW(hwnd, DWLP_USER, (LONG_PTR)prfdp); if (prfdp->lpstrTitle) SetWindowTextW(hwnd, prfdp->lpstrTitle); if (prfdp->lpstrDescription) SetWindowTextW(GetDlgItem(hwnd, IDC_RUNDLG_DESCRIPTION), prfdp->lpstrDescription); if (prfdp->uFlags & RFF_NOBROWSE) { HWND browse = GetDlgItem(hwnd, IDC_RUNDLG_BROWSE); ShowWindow(browse, SW_HIDE); EnableWindow(browse, FALSE); } if (prfdp->uFlags & RFF_NOLABEL) ShowWindow(GetDlgItem(hwnd, IDC_RUNDLG_LABEL), SW_HIDE); if (prfdp->uFlags & RFF_CALCDIRECTORY) FIXME("RFF_CALCDIRECTORY not supported\n"); if (prfdp->hIcon == NULL) prfdp->hIcon = LoadIconW(NULL, (LPCWSTR)IDI_WINLOGO); SendMessageW(hwnd, WM_SETICON, ICON_BIG, (LPARAM)prfdp->hIcon); SendMessageW(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)prfdp->hIcon); SendMessageW(GetDlgItem(hwnd, IDC_RUNDLG_ICON), STM_SETICON, (WPARAM)prfdp->hIcon, 0); FillList (GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH), NULL, (prfdp->uFlags & RFF_NODEFAULT) == 0); SetFocus (GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH)); return TRUE; case WM_COMMAND: switch (LOWORD (wParam)) { case IDOK: { int ic; HWND htxt = GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH); if ((ic = GetWindowTextLengthW (htxt))) { WCHAR *psz, *parent = NULL; SHELLEXECUTEINFOW sei; ZeroMemory (&sei, sizeof(sei)); sei.cbSize = sizeof(sei); psz = (WCHAR *)HeapAlloc(GetProcessHeap(), 0, (ic + 1)*sizeof(WCHAR)); if (psz) { GetWindowTextW(htxt, psz, ic + 1); /* according to http://www.codeproject.com/KB/shell/runfiledlg.aspx we should send a * WM_NOTIFY before execution */ sei.hwnd = hwnd; sei.nShow = SW_SHOWNORMAL; sei.lpFile = psz; if (prfdp->lpstrDirectory) sei.lpDirectory = prfdp->lpstrDirectory; else sei.lpDirectory = parent = RunDlg_GetParentDir(sei.lpFile); if (!ShellExecuteExW(&sei)) { HeapFree(GetProcessHeap(), 0, psz); HeapFree(GetProcessHeap(), 0, parent); SendMessageA (htxt, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)); return TRUE; } /* FillList is still ANSI */ GetWindowTextA (htxt, (LPSTR)psz, ic + 1); FillList (htxt, (LPSTR)psz, FALSE); HeapFree(GetProcessHeap(), 0, psz); HeapFree(GetProcessHeap(), 0, parent); EndDialog (hwnd, 0); } } } case IDCANCEL: EndDialog (hwnd, 0); return TRUE; case IDC_RUNDLG_BROWSE: { HMODULE hComdlg = NULL; LPFNOFN ofnProc = NULL; static const WCHAR comdlg32W[] = L"comdlg32"; WCHAR szFName[1024] = {0}; WCHAR filter[MAX_PATH], szCaption[MAX_PATH]; OPENFILENAMEW ofn; LoadStringW(shell32_hInstance, IDS_RUNDLG_BROWSE_FILTER, filter, MAX_PATH); LoadStringW(shell32_hInstance, IDS_RUNDLG_BROWSE_CAPTION, szCaption, MAX_PATH); ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(OPENFILENAMEW); ofn.hwndOwner = hwnd; ofn.lpstrFilter = filter; ofn.lpstrFile = szFName; ofn.nMaxFile = 1023; ofn.lpstrTitle = szCaption; ofn.Flags = OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST; ofn.lpstrInitialDir = prfdp->lpstrDirectory; if (NULL == (hComdlg = LoadLibraryExW (comdlg32W, NULL, 0)) || NULL == (ofnProc = (LPFNOFN)GetProcAddress (hComdlg, "GetOpenFileNameW"))) { ERR("Couldn't get GetOpenFileName function entry (lib=%p, proc=%p)\n", hComdlg, ofnProc); ShellMessageBoxW(shell32_hInstance, hwnd, MAKEINTRESOURCEW(IDS_RUNDLG_BROWSE_ERROR), NULL, MB_OK | MB_ICONERROR); return TRUE; } if (ofnProc(&ofn)) { SetFocus (GetDlgItem (hwnd, IDOK)); SetWindowTextW (GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH), szFName); SendMessageW (GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH), CB_SETEDITSEL, 0, MAKELPARAM (0, -1)); SetFocus (GetDlgItem (hwnd, IDOK)); } FreeLibrary (hComdlg); return TRUE; } } return TRUE; } return FALSE; }
HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath, DWORD dwFlags) { WCHAR szPath[MAX_PATH] = {0}, szBuffer[MAX_PATH]; DWORD dwSize, dwType, count; LONG ret; IShellFolder *pDesktop, *pRecycleBin; PIDLIST_ABSOLUTE pidlRecycleBin; PITEMID_CHILD pidl; HRESULT hr = S_OK; LPENUMIDLIST penumFiles; STRRET StrRet; TRACE("%p, %s, 0x%08x\n", hwnd, debugstr_w(pszRootPath), dwFlags); if (!(dwFlags & SHERB_NOCONFIRMATION)) { hr = SHGetDesktopFolder(&pDesktop); if (FAILED(hr)) return hr; hr = SHGetFolderLocation(NULL, CSIDL_BITBUCKET, NULL, 0, &pidlRecycleBin); if (FAILED(hr)) { pDesktop->Release(); return hr; } hr = pDesktop->BindToObject(pidlRecycleBin, NULL, IID_PPV_ARG(IShellFolder, &pRecycleBin)); CoTaskMemFree(pidlRecycleBin); pDesktop->Release(); if (FAILED(hr)) return hr; hr = pRecycleBin->EnumObjects(hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &penumFiles); if (FAILED(hr)) { pRecycleBin->Release(); return hr; } count = 0; if (hr != S_FALSE) { while (penumFiles->Next(1, &pidl, NULL) == S_OK) { count++; pRecycleBin->GetDisplayNameOf(pidl, SHGDN_NORMAL, &StrRet); StrRetToBuf(&StrRet, pidl, szBuffer, _countof(szBuffer)); CoTaskMemFree(pidl); } penumFiles->Release(); } pRecycleBin->Release(); switch (count) { case 0: /* no files, don't need confirmation */ break; case 1: /* we have only one item inside the bin, so show a message box with its name */ if (ShellMessageBoxW(shell32_hInstance, hwnd, MAKEINTRESOURCEW(IDS_DELETEITEM_TEXT), MAKEINTRESOURCEW(IDS_EMPTY_BITBUCKET), MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, szBuffer) == IDNO) { return S_OK; } break; default: /* we have more than one item, so show a message box with the count of the items */ StringCbPrintfW(szBuffer, sizeof(szBuffer), L"%u", count); if (ShellMessageBoxW(shell32_hInstance, hwnd, MAKEINTRESOURCEW(IDS_DELETEMULTIPLE_TEXT), MAKEINTRESOURCEW(IDS_EMPTY_BITBUCKET), MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, szBuffer) == IDNO) { return S_OK; } break; } } if (dwFlags & SHERB_NOPROGRESSUI) { ret = EmptyRecycleBinW(pszRootPath); } else { /* FIXME * show a progress dialog */ ret = EmptyRecycleBinW(pszRootPath); } if (!ret) return HRESULT_FROM_WIN32(GetLastError()); if (!(dwFlags & SHERB_NOSOUND)) { dwSize = sizeof(szPath); ret = RegGetValueW(HKEY_CURRENT_USER, L"AppEvents\\Schemes\\Apps\\Explorer\\EmptyRecycleBin\\.Current", NULL, RRF_RT_REG_SZ, &dwType, (PVOID)szPath, &dwSize); if (ret != ERROR_SUCCESS) return S_OK; if (dwType != REG_EXPAND_SZ) /* type dismatch */ return S_OK; szPath[(sizeof(szPath)/sizeof(WCHAR))-1] = L'\0'; PlaySoundW(szPath, NULL, SND_FILENAME); } return S_OK; }