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); } } }
/************************************************************************** * CDesktopFolder::GetAttributesOf */ HRESULT WINAPI CDesktopFolder::GetAttributesOf( UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut) { HRESULT hr = S_OK; TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", this, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0); if (cidl && !apidl) return E_INVALIDARG; if (*rgfInOut == 0) *rgfInOut = ~0; if(cidl == 0) *rgfInOut &= dwDesktopAttributes; else { /* TODO: always add SFGAO_CANLINK */ for (UINT i = 0; i < cidl; ++i) { pdump(*apidl); if (_ILIsDesktop(*apidl)) *rgfInOut &= dwDesktopAttributes; else if (_ILIsMyComputer(apidl[i])) *rgfInOut &= dwMyComputerAttributes; else if (_ILIsNetHood(apidl[i])) *rgfInOut &= dwMyNetPlacesAttributes; else if (_ILIsSpecialFolder(apidl[i])) SHELL32_GetGuidItemAttributes(this, apidl[i], rgfInOut); else if (_ILIsFolder(apidl[i]) || _ILIsValue(apidl[i])) { CComPtr<IShellFolder2> psf; HRESULT hr = _GetSFFromPidl(apidl[i], &psf); if (FAILED_UNEXPECTEDLY(hr)) continue; psf->GetAttributesOf(1, &apidl[i], rgfInOut); } else ERR("Got an unknown pidl type!!!\n"); } } /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */ *rgfInOut &= ~SFGAO_VALIDATE; TRACE("-- result=0x%08x\n", *rgfInOut); return hr; }
/*********************************************************************** * SHELL32_CoCreateInitSF * * Creates a shell folder and initializes it with a pidl and a root folder * via IPersistFolder3 or IPersistFolder. * * NOTES * pathRoot can be NULL for Folders being a drive. * In this case the absolute path is built from pidlChild (eg. C:) */ static HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot, LPCITEMIDLIST pidlChild, REFCLSID clsid, LPVOID * ppvOut) { HRESULT hr; TRACE ("(%p %s %p %s %p)\n", pidlRoot, debugstr_w(pathRoot), pidlChild, debugstr_guid(clsid), ppvOut); hr = SHCoCreateInstance(NULL, clsid, NULL, &IID_IShellFolder, ppvOut); if (SUCCEEDED (hr)) { LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild); IPersistFolder *pPF; IPersistFolder3 *ppf; if (_ILIsFolder(pidlChild) && SUCCEEDED (IUnknown_QueryInterface ((IUnknown *) * ppvOut, &IID_IPersistFolder3, (LPVOID *) & ppf))) { PERSIST_FOLDER_TARGET_INFO ppfti; ZeroMemory (&ppfti, sizeof (ppfti)); /* fill the PERSIST_FOLDER_TARGET_INFO */ ppfti.dwAttributes = -1; ppfti.csidl = -1; /* build path */ if (pathRoot) { lstrcpynW (ppfti.szTargetParsingName, pathRoot, MAX_PATH - 1); PathAddBackslashW(ppfti.szTargetParsingName); /* FIXME: why have drives a backslash here ? */ } if (pidlChild) { int len = lstrlenW(ppfti.szTargetParsingName); if (!_ILSimpleGetTextW(pidlChild, ppfti.szTargetParsingName + len, MAX_PATH - len)) hr = E_INVALIDARG; } IPersistFolder3_InitializeEx (ppf, NULL, pidlAbsolute, &ppfti); IPersistFolder3_Release (ppf); } else if (SUCCEEDED ((hr = IUnknown_QueryInterface ((IUnknown *) * ppvOut, &IID_IPersistFolder, (LPVOID *) & pPF)))) { IPersistFolder_Initialize (pPF, pidlAbsolute); IPersistFolder_Release (pPF); } ILFree (pidlAbsolute); } TRACE ("-- (%p) ret=0x%08x\n", *ppvOut, hr); return hr; }
/*********************************************************************** * SHELL32_BindToFS [Internal] * * Common code for IShellFolder_BindToObject. * * PARAMS * pidlRoot [I] The parent shell folder's absolute pidl. * pathRoot [I] Absolute dos path of the parent shell folder. * pidlComplete [I] PIDL of the child. Relative to pidlRoot. * riid [I] GUID of the interface, which ppvOut shall be bound to. * ppvOut [O] A reference to the child's interface (riid). * * NOTES * pidlComplete has to contain at least one non empty SHITEMID. * This function makes special assumptions on the shell namespace, which * means you probably can't use it for your IShellFolder implementation. */ HRESULT SHELL32_BindToFS (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot, LPCITEMIDLIST pidlComplete, REFIID riid, LPVOID * ppvOut) { CComPtr<IShellFolder> pSF; HRESULT hr; LPCITEMIDLIST pidlChild; if (!pidlRoot || !ppvOut || !pidlComplete || !pidlComplete->mkid.cb) return E_INVALIDARG; if (_ILIsValue(pidlComplete)) { ERR("Binding to file is unimplemented\n"); return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); } if (!_ILIsFolder(pidlComplete) && !_ILIsDrive(pidlComplete)) { ERR("Got an unknown type of pidl!\n"); return E_FAIL; } *ppvOut = NULL; pidlChild = (_ILIsPidlSimple (pidlComplete)) ? pidlComplete : ILCloneFirst (pidlComplete); CLSID clsidFolder = CLSID_ShellFSFolder; DWORD attributes = _ILGetFileAttributes(ILFindLastID(pidlChild), NULL, 0); if ((attributes & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)) != 0) SHELL32_GetCLSIDForDirectory(pathRoot, pidlChild, &clsidFolder); hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild, clsidFolder, &pSF); if (pidlChild != pidlComplete) ILFree ((LPITEMIDLIST)pidlChild); if (SUCCEEDED (hr)) { if (_ILIsPidlSimple (pidlComplete)) { /* no sub folders */ hr = pSF->QueryInterface(riid, ppvOut); } else { /* go deeper */ hr = pSF->BindToObject(ILGetNext (pidlComplete), NULL, riid, ppvOut); } } TRACE ("-- returning (%p) %08x\n", *ppvOut, hr); return hr; }
void AddFSClassKeysToArray(PCUITEMID_CHILD pidl, HKEY* array, UINT* cKeys) { if (_ILIsValue(pidl)) { FileStructW* pFileData = _ILGetFileStructW(pidl); LPWSTR extension = PathFindExtension(pFileData->wszName); if (extension) { AddClassKeyToArray(extension, array, cKeys); WCHAR wszClass[MAX_PATH], wszClass2[MAX_PATH]; DWORD dwSize = sizeof(wszClass); if (RegGetValueW(HKEY_CLASSES_ROOT, extension, NULL, RRF_RT_REG_SZ, NULL, wszClass, &dwSize) == ERROR_SUCCESS) { swprintf(wszClass2, L"%s//%s", extension, wszClass); AddClassKeyToArray(wszClass, array, cKeys); AddClassKeyToArray(wszClass2, array, cKeys); } swprintf(wszClass2, L"SystemFileAssociations//%s", extension); AddClassKeyToArray(wszClass2, array, cKeys); if (RegGetValueW(HKEY_CLASSES_ROOT, extension, L"PerceivedType ", RRF_RT_REG_SZ, NULL, wszClass, &dwSize) == ERROR_SUCCESS) { swprintf(wszClass2, L"SystemFileAssociations//%s", wszClass); AddClassKeyToArray(wszClass2, array, cKeys); } } AddClassKeyToArray(L"AllFilesystemObjects", array, cKeys); AddClassKeyToArray(L"*", array, cKeys); } else if (_ILIsFolder(pidl)) { AddClassKeyToArray(L"AllFilesystemObjects", array, cKeys); AddClassKeyToArray(L"Directory", array, cKeys); AddClassKeyToArray(L"Folder", array, cKeys); } else { ERR("Got non FS pidl\n"); } }
/************************************************************************** * IExtractIconW::GetIconLocation * * mapping filetype to icon */ static HRESULT WINAPI IExtractIconW_fnGetIconLocation(IExtractIconW * iface, UINT uFlags, LPWSTR szIconFile, UINT cchMax, int * piIndex, UINT * pwFlags) { IExtractIconWImpl *This = impl_from_IExtractIconW(iface); char sTemp[MAX_PATH]; int icon_idx; GUID const * riid; LPITEMIDLIST pSimplePidl = ILFindLastID(This->pidl); TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags); if (pwFlags) *pwFlags = 0; if (_ILIsDesktop(pSimplePidl)) { lstrcpynW(szIconFile, swShell32Name, cchMax); *piIndex = -IDI_SHELL_DESKTOP; } /* my computer and other shell extensions */ else if ((riid = _ILGetGUIDPointer(pSimplePidl))) { static const WCHAR fmt[] = { 'C','L','S','I','D','\\', '{','%','0','8','l','x','-','%','0','4','x','-','%','0','4','x','-', '%','0','2','x','%','0','2','x','-','%','0','2','x', '%','0','2','x', '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0 }; WCHAR xriid[50]; sprintfW(xriid, fmt, riid->Data1, riid->Data2, riid->Data3, riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]); if (HCR_GetDefaultIconW(xriid, szIconFile, cchMax, &icon_idx)) { *piIndex = icon_idx; } else { lstrcpynW(szIconFile, swShell32Name, cchMax); if(IsEqualGUID(riid, &CLSID_MyComputer)) *piIndex = -IDI_SHELL_MY_COMPUTER; else if(IsEqualGUID(riid, &CLSID_MyDocuments)) *piIndex = -IDI_SHELL_MY_DOCUMENTS; else if(IsEqualGUID(riid, &CLSID_NetworkPlaces)) *piIndex = -IDI_SHELL_MY_NETWORK_PLACES; else if(IsEqualGUID(riid, &CLSID_UnixFolder) || IsEqualGUID(riid, &CLSID_UnixDosFolder)) *piIndex = -IDI_SHELL_DRIVE; else *piIndex = -IDI_SHELL_FOLDER; } } else if (_ILIsDrive (pSimplePidl)) { static const WCHAR drive[] = { 'D','r','i','v','e',0 }; int icon_idx = -1; if (_ILGetDrive(pSimplePidl, sTemp, MAX_PATH)) { switch(GetDriveTypeA(sTemp)) { case DRIVE_REMOVABLE: icon_idx = IDI_SHELL_FLOPPY; break; case DRIVE_CDROM: icon_idx = IDI_SHELL_CDROM; break; case DRIVE_REMOTE: icon_idx = IDI_SHELL_NETDRIVE; break; case DRIVE_RAMDISK: icon_idx = IDI_SHELL_RAMDISK; break; } } if (icon_idx != -1) { lstrcpynW(szIconFile, swShell32Name, cchMax); *piIndex = -icon_idx; } else { if (HCR_GetDefaultIconW(drive, szIconFile, cchMax, &icon_idx)) { *piIndex = icon_idx; } else { lstrcpynW(szIconFile, swShell32Name, cchMax); *piIndex = -IDI_SHELL_DRIVE; } } } else if (_ILIsFolder (pSimplePidl)) { getIconLocationForFolder(This, uFlags, szIconFile, cchMax, piIndex, pwFlags); } else { BOOL found = FALSE; if (_ILIsCPanelStruct(pSimplePidl)) { if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl, szIconFile, cchMax, piIndex))) found = TRUE; } else if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH)) { if (HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE) && HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &icon_idx)) { if (!lstrcmpA("%1", sTemp)) /* icon is in the file */ { SHGetPathFromIDListW(This->pidl, szIconFile); *piIndex = 0; } else { MultiByteToWideChar(CP_ACP, 0, sTemp, -1, szIconFile, cchMax); *piIndex = icon_idx; } found = TRUE; } else if (!lstrcmpiA(sTemp, "lnkfile")) { /* extract icon from shell shortcut */ IShellFolder* dsf; IShellLinkW* psl; if (SUCCEEDED(SHGetDesktopFolder(&dsf))) { HRESULT hr = IShellFolder_GetUIObjectOf(dsf, NULL, 1, (LPCITEMIDLIST*)&This->pidl, &IID_IShellLinkW, NULL, (LPVOID*)&psl); if (SUCCEEDED(hr)) { hr = IShellLinkW_GetIconLocation(psl, szIconFile, MAX_PATH, piIndex); if (SUCCEEDED(hr) && *szIconFile) found = TRUE; IShellLinkW_Release(psl); } IShellFolder_Release(dsf); } } } if (!found) /* default icon */ { lstrcpynW(szIconFile, swShell32Name, cchMax); *piIndex = 0; } } TRACE("-- %s %x\n", debugstr_w(szIconFile), *piIndex); return S_OK; }
/************************************************************************** * ISF_Desktop_fnGetDisplayNameOf * * NOTES * special case: pidl = null gives desktop-name back */ static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet) { IDesktopFolderImpl *This = impl_from_IShellFolder2(iface); HRESULT hr = S_OK; LPWSTR pszPath; TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet); pdump (pidl); if (!strRet) return E_INVALIDARG; pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR)); if (!pszPath) return E_OUTOFMEMORY; if (_ILIsDesktop (pidl)) { if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)) strcpyW(pszPath, This->sPathTarget); else HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH); } else if (_ILIsPidlSimple (pidl)) { GUID const *clsid; if ((clsid = _ILGetGUIDPointer (pidl))) { if (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING) { int bWantsForParsing; /* * We can only get a filesystem path from a shellfolder if the * value WantsFORPARSING in CLSID\\{...}\\shellfolder exists. * * Exception: The MyComputer folder doesn't have this key, * but any other filesystem backed folder it needs it. */ if (IsEqualIID (clsid, &CLSID_MyComputer)) { bWantsForParsing = TRUE; } else { /* get the "WantsFORPARSING" flag from the registry */ static const WCHAR clsidW[] = { 'C','L','S','I','D','\\',0 }; static const WCHAR shellfolderW[] = { '\\','s','h','e','l','l','f','o','l','d','e','r',0 }; static const WCHAR wantsForParsingW[] = { 'W','a','n','t','s','F','o','r','P','a','r','s','i','n', 'g',0 }; WCHAR szRegPath[100]; LONG r; lstrcpyW (szRegPath, clsidW); SHELL32_GUIDToStringW (clsid, &szRegPath[6]); lstrcatW (szRegPath, shellfolderW); r = SHGetValueW(HKEY_CLASSES_ROOT, szRegPath, wantsForParsingW, NULL, NULL, NULL); if (r == ERROR_SUCCESS) bWantsForParsing = TRUE; else bWantsForParsing = FALSE; } if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && bWantsForParsing) { /* * we need the filesystem path to the destination folder. * Only the folder itself can know it */ hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, pszPath, MAX_PATH); } else { /* parsing name like ::{...} */ pszPath[0] = ':'; pszPath[1] = ':'; SHELL32_GUIDToStringW (clsid, &pszPath[2]); } } else { /* user friendly name */ HCR_GetClassNameW (clsid, pszPath, MAX_PATH); } } else { int cLen = 0; /* file system folder or file rooted at the desktop */ if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) && (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER)) { lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1); PathAddBackslashW(pszPath); cLen = lstrlenW(pszPath); } _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen); if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags); } } else { /* a complex pidl, let the subfolder do the work */ hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, pszPath, MAX_PATH); } if (SUCCEEDED(hr)) { /* Win9x always returns ANSI strings, NT always returns Unicode strings */ if (GetVersion() & 0x80000000) { strRet->uType = STRRET_CSTR; if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH, NULL, NULL)) strRet->u.cStr[0] = '\0'; CoTaskMemFree(pszPath); } else { strRet->uType = STRRET_WSTR; strRet->u.pOleStr = pszPath; } } else CoTaskMemFree(pszPath); TRACE ("-- (%p)->(%s,0x%08x)\n", This, strRet->uType == STRRET_CSTR ? strRet->u.cStr : debugstr_w(strRet->u.pOleStr), hr); return hr; }
/************************************************************************** * DoOpenProperties */ static void DoOpenProperties(ItemCmImpl *This, HWND hwnd) { static const UINT MAX_PROP_PAGES = 99; static const WCHAR wszFolder[] = {'F','o','l','d','e','r', 0}; static const WCHAR wszFiletypeAll[] = {'*',0}; LPSHELLFOLDER lpDesktopSF; LPSHELLFOLDER lpSF; LPDATAOBJECT lpDo; WCHAR wszFiletype[MAX_PATH]; WCHAR wszFilename[MAX_PATH]; PROPSHEETHEADERW psh; HPROPSHEETPAGE hpages[MAX_PROP_PAGES]; HPSXA hpsxa; UINT ret; TRACE("(%p)->(wnd=%p)\n", This, hwnd); ZeroMemory(&psh, sizeof(PROPSHEETHEADERW)); psh.dwSize = sizeof (PROPSHEETHEADERW); psh.hwndParent = hwnd; psh.dwFlags = PSH_PROPTITLE; psh.nPages = 0; psh.u3.phpage = hpages; psh.u2.nStartPage = 0; _ILSimpleGetTextW(This->apidl[0], (LPVOID)&wszFilename, MAX_PATH); psh.pszCaption = (LPCWSTR)&wszFilename; /* Find out where to look for the shell extensions */ if (_ILIsValue(This->apidl[0])) { char sTemp[64]; sTemp[0] = 0; if (_ILGetExtension(This->apidl[0], sTemp, 64)) { HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE); MultiByteToWideChar(CP_ACP, 0, sTemp, -1, wszFiletype, MAX_PATH); } else { wszFiletype[0] = 0; } } else if (_ILIsFolder(This->apidl[0])) { lstrcpynW(wszFiletype, wszFolder, 64); } else if (_ILIsSpecialFolder(This->apidl[0])) { LPGUID folderGUID; static const WCHAR wszclsid[] = {'C','L','S','I','D','\\', 0}; folderGUID = _ILGetGUIDPointer(This->apidl[0]); lstrcpyW(wszFiletype, wszclsid); StringFromGUID2(folderGUID, &wszFiletype[6], MAX_PATH - 6); } else { FIXME("Requested properties for unknown type.\n"); return; } /* Get a suitable DataObject for accessing the files */ SHGetDesktopFolder(&lpDesktopSF); if (_ILIsPidlSimple(This->pidl)) { ret = IShellFolder_GetUIObjectOf(lpDesktopSF, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl, &IID_IDataObject, NULL, (LPVOID *)&lpDo); IShellFolder_Release(lpDesktopSF); } else { IShellFolder_BindToObject(lpDesktopSF, This->pidl, NULL, &IID_IShellFolder, (LPVOID*) &lpSF); ret = IShellFolder_GetUIObjectOf(lpSF, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl, &IID_IDataObject, NULL, (LPVOID *)&lpDo); IShellFolder_Release(lpSF); IShellFolder_Release(lpDesktopSF); } if (SUCCEEDED(ret)) { hpsxa = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszFiletype, MAX_PROP_PAGES - psh.nPages, lpDo); if (hpsxa != NULL) { SHAddFromPropSheetExtArray(hpsxa, Properties_AddPropSheetCallback, (LPARAM)&psh); SHDestroyPropSheetExtArray(hpsxa); } hpsxa = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszFiletypeAll, MAX_PROP_PAGES - psh.nPages, lpDo); if (hpsxa != NULL) { SHAddFromPropSheetExtArray(hpsxa, Properties_AddPropSheetCallback, (LPARAM)&psh); SHDestroyPropSheetExtArray(hpsxa); } IDataObject_Release(lpDo); } if (psh.nPages) PropertySheetW(&psh); else FIXME("No property pages found.\n"); }
HRESULT SHELL32_GetFSItemAttributes(IShellFolder * psf, LPCITEMIDLIST pidl, LPDWORD pdwAttributes) { DWORD dwFileAttributes, dwShellAttributes; if (!_ILIsFolder(pidl) && !_ILIsValue(pidl)) { ERR("Got wrong type of pidl!\n"); *pdwAttributes &= SFGAO_CANLINK; return S_OK; } if (*pdwAttributes & ~dwSupportedAttr) { WARN ("attributes 0x%08x not implemented\n", (*pdwAttributes & ~dwSupportedAttr)); *pdwAttributes &= dwSupportedAttr; } dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0); /* Set common attributes */ dwShellAttributes = *pdwAttributes; dwShellAttributes |= SFGAO_FILESYSTEM | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANDELETE | SFGAO_CANRENAME | SFGAO_CANLINK | SFGAO_CANMOVE | SFGAO_CANCOPY; if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { dwShellAttributes |= (SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR); } else dwShellAttributes &= ~(SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR); if (dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) dwShellAttributes |= SFGAO_HIDDEN; else dwShellAttributes &= ~SFGAO_HIDDEN; if (dwFileAttributes & FILE_ATTRIBUTE_READONLY) dwShellAttributes |= SFGAO_READONLY; else dwShellAttributes &= ~SFGAO_READONLY; if (SFGAO_LINK & *pdwAttributes) { char ext[MAX_PATH]; if (!_ILGetExtension(pidl, ext, MAX_PATH) || lstrcmpiA(ext, "lnk")) dwShellAttributes &= ~SFGAO_LINK; } if (SFGAO_HASSUBFOLDER & *pdwAttributes) { CComPtr<IShellFolder> psf2; if (SUCCEEDED(psf->BindToObject(pidl, 0, IID_PPV_ARG(IShellFolder, &psf2)))) { CComPtr<IEnumIDList> pEnumIL; if (SUCCEEDED(psf2->EnumObjects(0, SHCONTF_FOLDERS, &pEnumIL))) { if (pEnumIL->Skip(1) != S_OK) dwShellAttributes &= ~SFGAO_HASSUBFOLDER; } } } *pdwAttributes &= dwShellAttributes; TRACE ("-- 0x%08x\n", *pdwAttributes); return S_OK; }
/************************************************************************** * IExtractIconW_Constructor */ IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl) { CComPtr<IDefaultExtractIconInit> initIcon; IExtractIconW *extractIcon; GUID const * riid; int icon_idx; UINT flags; CHAR sTemp[MAX_PATH]; WCHAR wTemp[MAX_PATH]; LPITEMIDLIST pSimplePidl = ILFindLastID(pidl); HRESULT hr; hr = SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit,&initIcon)); if (FAILED(hr)) return NULL; hr = initIcon->QueryInterface(IID_PPV_ARG(IExtractIconW,&extractIcon)); if (FAILED(hr)) return NULL; if (_ILIsDesktop(pSimplePidl)) { initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DESKTOP); } else if ((riid = _ILGetGUIDPointer(pSimplePidl))) { /* my computer and other shell extensions */ static const WCHAR fmt[] = { 'C', 'L', 'S', 'I', 'D', '\\', '{', '%', '0', '8', 'l', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '}', 0 }; WCHAR xriid[50]; swprintf(xriid, fmt, riid->Data1, riid->Data2, riid->Data3, riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]); const WCHAR* iconname = NULL; if (_ILIsBitBucket(pSimplePidl)) { static const WCHAR szFull[] = {'F','u','l','l',0}; static const WCHAR szEmpty[] = {'E','m','p','t','y',0}; IEnumIDList *EnumIDList = NULL; CoInitialize(NULL); IShellFolder2 *psfRecycleBin = NULL; IShellFolder *psfDesktop = NULL; hr = SHGetDesktopFolder(&psfDesktop); if (SUCCEEDED(hr)) hr = psfDesktop->BindToObject(pSimplePidl, NULL, IID_IShellFolder2, (void**) &psfRecycleBin); if (SUCCEEDED(hr)) hr = psfRecycleBin->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &EnumIDList); ULONG itemcount; LPITEMIDLIST pidl = NULL; if (SUCCEEDED(hr) && (hr = EnumIDList->Next(1, &pidl, &itemcount)) == S_OK) { CoTaskMemFree(pidl); iconname = szFull; } else { iconname = szEmpty; } if (psfDesktop) psfDesktop->Release(); if (psfRecycleBin) psfRecycleBin->Release(); if (EnumIDList) EnumIDList->Release(); } if (HCR_GetIconW(xriid, wTemp, iconname, MAX_PATH, &icon_idx)) { initIcon->SetNormalIcon(wTemp, icon_idx); } else { if (IsEqualGUID(*riid, CLSID_MyComputer)) initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_COMPUTER); else if (IsEqualGUID(*riid, CLSID_MyDocuments)) initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_DOCUMENTS); else if (IsEqualGUID(*riid, CLSID_NetworkPlaces)) initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_NETWORK_PLACES); else initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_FOLDER); } } else if (_ILIsDrive (pSimplePidl)) { static const WCHAR drive[] = { 'D', 'r', 'i', 'v', 'e', 0 }; int icon_idx = -1; if (_ILGetDrive(pSimplePidl, sTemp, MAX_PATH)) { switch(GetDriveTypeA(sTemp)) { case DRIVE_REMOVABLE: icon_idx = IDI_SHELL_FLOPPY; break; case DRIVE_CDROM: icon_idx = IDI_SHELL_CDROM; break; case DRIVE_REMOTE: icon_idx = IDI_SHELL_NETDRIVE; break; case DRIVE_RAMDISK: icon_idx = IDI_SHELL_RAMDISK; break; case DRIVE_NO_ROOT_DIR: icon_idx = IDI_SHELL_CDROM; break; } } if (icon_idx != -1) { initIcon->SetNormalIcon(swShell32Name, -icon_idx); } else { if (HCR_GetIconW(drive, wTemp, NULL, MAX_PATH, &icon_idx)) initIcon->SetNormalIcon(wTemp, icon_idx); else initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DRIVE); } } else if (_ILIsFolder (pSimplePidl)) { if (SUCCEEDED(getIconLocationForFolder( pidl, 0, wTemp, MAX_PATH, &icon_idx, &flags))) { initIcon->SetNormalIcon(wTemp, icon_idx); // FIXME: if/when getIconLocationForFolder does something for // GIL_FORSHORTCUT, code below should be uncommented. and // the following line removed. initIcon->SetShortcutIcon(wTemp, icon_idx); } if (SUCCEEDED(getIconLocationForFolder( pidl, GIL_DEFAULTICON, wTemp, MAX_PATH, &icon_idx, &flags))) { initIcon->SetDefaultIcon(wTemp, icon_idx); } // if (SUCCEEDED(getIconLocationForFolder( // pidl, GIL_FORSHORTCUT, wTemp, MAX_PATH, // &icon_idx, // &flags))) // { // initIcon->SetShortcutIcon(wTemp, icon_idx); // } if (SUCCEEDED(getIconLocationForFolder( pidl, GIL_OPENICON, wTemp, MAX_PATH, &icon_idx, &flags))) { initIcon->SetOpenIcon(wTemp, icon_idx); } } else { BOOL found = FALSE; if (_ILIsCPanelStruct(pSimplePidl)) { if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl, wTemp, MAX_PATH, &icon_idx))) found = TRUE; } else if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH)) { if (HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE) && HCR_GetIconA(sTemp, sTemp, NULL, MAX_PATH, &icon_idx)) { if (!lstrcmpA("%1", sTemp)) /* icon is in the file */ { SHGetPathFromIDListW(pidl, wTemp); icon_idx = 0; } else { MultiByteToWideChar(CP_ACP, 0, sTemp, -1, wTemp, MAX_PATH); } found = TRUE; } else if (!lstrcmpiA(sTemp, "lnkfile")) { /* extract icon from shell shortcut */ CComPtr<IShellFolder> dsf; CComPtr<IShellLinkW> psl; if (SUCCEEDED(SHGetDesktopFolder(&dsf))) { HRESULT hr = dsf->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidl, IID_IShellLinkW, NULL, (LPVOID *)&psl); if (SUCCEEDED(hr)) { hr = psl->GetIconLocation(wTemp, MAX_PATH, &icon_idx); if (SUCCEEDED(hr) && *sTemp) found = TRUE; } } } } if (!found) /* default icon */ initIcon->SetNormalIcon(swShell32Name, 0); else initIcon->SetNormalIcon(wTemp, icon_idx); } return extractIcon; }
/************************************************************************** * ISF_Desktop_fnSetNameOf * Changes the name of a file object or subfolder, possibly changing its item * identifier in the process. * * PARAMETERS * HWND hwndOwner, //[in ] Owner window for output * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change * LPCOLESTR lpszName, //[in ] the items new display name * DWORD dwFlags, //[in ] SHGNO formatting flags * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned */ static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /* simple pidl */ LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut) { IGenericSFImpl *This = (IGenericSFImpl *)iface; IShellFolder2 * psf; HRESULT hr; WCHAR szSrc[MAX_PATH + 1], szDest[MAX_PATH + 1]; LPWSTR ptr; BOOL bIsFolder = _ILIsFolder (ILFindLastID (pidl)); TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut); if (_ILGetGUIDPointer(pidl)) { if (SUCCEEDED(IShellFolder2_BindToObject(iface, pidl, NULL, &IID_IShellFolder2, (LPVOID*)&psf))) { hr = IShellFolder2_SetNameOf(psf, hwndOwner, pidl, lpName, dwFlags, pPidlOut); IShellFolder2_Release(psf); return hr; } } /* build source path */ lstrcpynW(szSrc, This->sPathTarget, MAX_PATH); ptr = PathAddBackslashW (szSrc); if (ptr) _ILSimpleGetTextW (pidl, ptr, MAX_PATH + 1 - (ptr - szSrc)); /* build destination path */ if (dwFlags == SHGDN_NORMAL || dwFlags & SHGDN_INFOLDER) { lstrcpynW(szDest, This->sPathTarget, MAX_PATH); ptr = PathAddBackslashW (szDest); if (ptr) lstrcpynW(ptr, lpName, MAX_PATH + 1 - (ptr - szDest)); } else lstrcpynW(szDest, lpName, MAX_PATH); if(!(dwFlags & SHGDN_FORPARSING) && SHELL_FS_HideExtension(szSrc)) { WCHAR *ext = PathFindExtensionW(szSrc); if(*ext != '\0') { INT len = wcslen(szDest); lstrcpynW(szDest + len, ext, MAX_PATH - len); } } if (!memcmp(szSrc, szDest, (wcslen(szDest)+1) * sizeof(WCHAR))) { /* src and destination is the same */ hr = S_OK; if (pPidlOut) hr = _ILCreateFromPathW(szDest, pPidlOut); return hr; } TRACE ("src=%s dest=%s\n", debugstr_w(szSrc), debugstr_w(szDest)); if (MoveFileW (szSrc, szDest)) { hr = S_OK; if (pPidlOut) hr = _ILCreateFromPathW(szDest, pPidlOut); SHChangeNotify (bIsFolder ? SHCNE_RENAMEFOLDER : SHCNE_RENAMEITEM, SHCNF_PATHW, szSrc, szDest); return hr; } return E_FAIL; }
static HRESULT WINAPI ISF_Desktop_ISFHelper_fnDeleteItems (ISFHelper * iface, UINT cidl, LPCITEMIDLIST * apidl) { IGenericSFImpl *This = impl_from_ISFHelper(iface); UINT i; SHFILEOPSTRUCTW op; WCHAR wszPath[MAX_PATH]; WCHAR wszCaption[50]; WCHAR *wszPathsList; HRESULT ret; WCHAR *wszCurrentPath; UINT bRestoreWithDeskCpl = FALSE; int res; TRACE ("(%p)(%u %p)\n", This, cidl, apidl); if (cidl==0) return S_OK; for(i = 0; i < cidl; i++) { if (_ILIsMyComputer(apidl[i])) bRestoreWithDeskCpl++; else if (_ILIsNetHood(apidl[i])) bRestoreWithDeskCpl++; else if (_ILIsMyDocuments(apidl[i])) bRestoreWithDeskCpl++; } if (bRestoreWithDeskCpl) { /* FIXME use FormatMessage * use a similar message resource as in windows */ LoadStringW(shell32_hInstance, IDS_DELETEMULTIPLE_TEXT, wszPath, sizeof(wszPath)/sizeof(WCHAR)); wszPath[(sizeof(wszPath)/sizeof(WCHAR))-1] = 0; LoadStringW(shell32_hInstance, IDS_DELETEITEM_CAPTION, wszCaption, sizeof(wszCaption)/sizeof(WCHAR)); wszCaption[(sizeof(wszCaption)/sizeof(WCHAR))-1] = 0; res = SHELL_ConfirmMsgBox(GetActiveWindow(), wszPath, wszCaption, NULL, cidl > 1); if (res == IDD_YESTOALL || res == IDYES) { for(i = 0; i < cidl; i++) { if (_ILIsMyComputer(apidl[i])) SetNamespaceExtensionVisibleStatus(L"{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0x1); else if (_ILIsNetHood(apidl[i])) SetNamespaceExtensionVisibleStatus(L"{208D2C60-3AEA-1069-A2D7-08002B30309D}", 0x1); else if (_ILIsMyDocuments(apidl[i])) SetNamespaceExtensionVisibleStatus(L"{450D8FBA-AD25-11D0-98A8-0800361B1103}", 0x1); } } } if (This->sPathTarget) lstrcpynW(wszPath, This->sPathTarget, MAX_PATH); else wszPath[0] = '\0'; PathAddBackslashW(wszPath); wszPathsList = build_paths_list(wszPath, cidl, apidl); ZeroMemory(&op, sizeof(op)); op.hwnd = GetActiveWindow(); op.wFunc = FO_DELETE; op.pFrom = wszPathsList; op.fFlags = FOF_ALLOWUNDO; if (SHFileOperationW(&op)) { WARN("SHFileOperation failed\n"); ret = E_FAIL; } else ret = S_OK; /* we currently need to manually send the notifies */ wszCurrentPath = wszPathsList; for (i = 0; i < cidl; i++) { LONG wEventId; if (_ILIsFolder(apidl[i])) wEventId = SHCNE_RMDIR; else if (_ILIsValue(apidl[i])) wEventId = SHCNE_DELETE; else continue; /* check if file exists */ if (GetFileAttributesW(wszCurrentPath) == INVALID_FILE_ATTRIBUTES) { LPITEMIDLIST pidl = ILCombine(This->pidlRoot, apidl[i]); SHChangeNotify(wEventId, SHCNF_IDLIST, pidl, NULL); SHFree(pidl); } wszCurrentPath += wcslen(wszCurrentPath)+1; } HeapFree(GetProcessHeap(), 0, wszPathsList); return ret; }