コード例 #1
0
ファイル: ShellFolder2.cpp プロジェクト: JetBrains/jdk8u_jdk
/*
 * Class:     sun_awt_shell_Win32ShellFolder2
 * Method:    releaseEnumObjects
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolder2_releaseEnumObjects
    (JNIEnv* env, jobject folder, jlong pEnumObjects)
{
    IEnumIDList* pEnum = (IEnumIDList*)pEnumObjects;
    if (pEnum == NULL) {
        return;
    }
    pEnum->Release();
}
コード例 #2
0
ファイル: PyIEnumIDList.cpp プロジェクト: malrsrch/pywin32
// @pymethod object|PyIEnumIDList|Next|Retrieves a specified number of items in the enumeration sequence.
PyObject *PyIEnumIDList::Next(PyObject *self, PyObject *args)
{
	long celt = 1;
	// @pyparm int|num|1|Number of items to retrieve.
	if ( !PyArg_ParseTuple(args, "|l:Next", &celt) )
		return NULL;

	IEnumIDList *peidl = GetI(self);
	if ( peidl == NULL )
		return NULL;

	LPITEMIDLIST *rgVar = new LPITEMIDLIST [celt];
	if ( rgVar == NULL ) {
		PyErr_SetString(PyExc_MemoryError, "allocating result ITEMIDLISTs");
		return NULL;
	}
	memset(rgVar, 0, sizeof(ITEMIDLIST *) * celt);

	int i;
/*	for ( i = celt; i--; )
		// *** possibly init each structure element???
*/

	ULONG celtFetched = 0;
	PY_INTERFACE_PRECALL;
	HRESULT hr = peidl->Next(celt, rgVar, &celtFetched);
	PY_INTERFACE_POSTCALL;
	if (  HRESULT_CODE(hr) != ERROR_NO_MORE_ITEMS && FAILED(hr) )
	{
		delete [] rgVar;
		return PyCom_BuildPyException(hr,peidl, IID_IEnumIDList);
	}

	PyObject *result = PyList_New(celtFetched);
	if ( result != NULL )
	{
		for ( i = celtFetched; i--; )
		{
			PyObject *ob = PyObject_FromPIDL(rgVar[i], TRUE);
			if ( ob == NULL )
			{
				Py_DECREF(result);
				result = NULL;
				break;
			}
			PyList_SET_ITEM(result, i, ob);
		}
	}

	// Each item free'd by PyObject_FromPIDL'd TRUE param
	delete [] rgVar;
	return result;
}
コード例 #3
0
void CreateLnkOnDesktop(const LPWSTR connTitle)
{
	IShellLink   *SLink;
	IPersistFile *PF;
	HRESULT HRes;
	TCHAR desktop_path[MAX_PATH] = TEXT("");
	TCHAR pszFullLnkPath[MAX_PATH]; 

	CoInitialize(NULL);

	ITEMIDLIST* pidl1 = NULL;
    SHGetFolderLocation(NULL, CSIDL_CONNECTIONS, NULL, 0, &pidl1);
    IShellFolder *desktop, *ncfolder;
    SHGetDesktopFolder(&desktop);
    desktop->BindToObject(pidl1, NULL, IID_IShellFolder, (void**)&ncfolder);

    IEnumIDList *items;
    ncfolder->EnumObjects(NULL, SHCONTF_NONFOLDERS, &items);
    ITEMIDLIST* pidl2 = NULL;
    while (S_OK == items->Next(1, &pidl2, NULL))
    {
        STRRET sr = {STRRET_WSTR};
        ncfolder->GetDisplayNameOf(pidl2, SHGDN_NORMAL, &sr);

        TCHAR buf[MAX_PATH] = TEXT("");
        StrRetToBuf(&sr, pidl2, buf, MAX_PATH);

        if (0 == StrCmpI(buf, connTitle))
        {
            ITEMIDLIST* pidl3 = ILCombine(pidl1, pidl2);
			HRESULT HRes = CoCreateInstance(CLSID_ShellLink, 0, CLSCTX_INPROC_SERVER, IID_IShellLink, ( LPVOID*)&SLink);
            SLink->SetIDList(pidl3);
			SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, desktop_path);
			StringCbPrintf(pszFullLnkPath, MAX_PATH * sizeof(TCHAR), TEXT("%s\\%s.lnk"), desktop_path, connTitle);
			HRes = SLink->QueryInterface(IID_IPersistFile, (LPVOID*)&PF);
			HRes = PF->Save((LPCOLESTR)pszFullLnkPath, TRUE);
			PF->Release();
			SLink->Release();
            ILFree(pidl3);
            ILFree(pidl2);
            break;
        }

        ILFree(pidl2);
        pidl2 = NULL;
    }
	ncfolder->Release();
	desktop->Release();

    ILFree(pidl1);

	CoUninitialize();
}
コード例 #4
0
ファイル: ShellFolder2.cpp プロジェクト: JetBrains/jdk8u_jdk
/*
 * Class:     sun_awt_shell_Win32ShellFolder2
 * Method:    getNextChild
 * Signature: (J)J
 */
JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getNextChild
    (JNIEnv* env, jobject folder, jlong pEnumObjects)
{
    IEnumIDList* pEnum = (IEnumIDList*)pEnumObjects;
    if (pEnum == NULL) {
        return 0;
    }
    LPITEMIDLIST pidl;
    if (pEnum->Next(1, &pidl, NULL) != S_OK) {
        return 0;
    }
    return (jlong)pidl;
}
コード例 #5
0
ファイル: PyIEnumIDList.cpp プロジェクト: malrsrch/pywin32
// @pymethod <o PyIEnumIDList>|PyIEnumIDList|Clone|Creates another enumerator that contains the same enumeration state as the current one
PyObject *PyIEnumIDList::Clone(PyObject *self, PyObject *args)
{
	if ( !PyArg_ParseTuple(args, ":Clone") )
		return NULL;

	IEnumIDList *peidl = GetI(self);
	if ( peidl == NULL )
		return NULL;

	IEnumIDList *pClone;
	PY_INTERFACE_PRECALL;
	HRESULT hr = peidl->Clone(&pClone);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, peidl, IID_IEnumIDList);

	return PyCom_PyObjectFromIUnknown(pClone, IID_IEnumIDList, FALSE);
}
コード例 #6
0
ファイル: PyIEnumIDList.cpp プロジェクト: malrsrch/pywin32
// @pymethod |PyIEnumIDList|Reset|Resets the enumeration sequence to the beginning.
PyObject *PyIEnumIDList::Reset(PyObject *self, PyObject *args)
{
	if ( !PyArg_ParseTuple(args, ":Reset") )
		return NULL;

	IEnumIDList *peidl = GetI(self);
	if ( peidl == NULL )
		return NULL;

	PY_INTERFACE_PRECALL;
	HRESULT hr = peidl->Reset();
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, peidl, IID_IEnumIDList);

	Py_INCREF(Py_None);
	return Py_None;
}
コード例 #7
0
ファイル: favengine.cpp プロジェクト: henrywoo/ultraie
PFAVORITELIST CFavoriteEngine::GetAllFavorites(){
  if(FAILED(CoInitialize(NULL)))
    return NULL;
  HRESULT hRet = ::SHGetMalloc(&m_pMalloc);
  if(FAILED(hRet)){
    m_pMalloc->Release();
    return NULL;
  }
  LPITEMIDLIST pidl;
  hRet = ::SHGetSpecialFolderLocation( NULL, CSIDL_FAVORITES, &pidl);
  if(FAILED(hRet)){
    m_pMalloc->Release();
    return NULL;
  }

  IShellFolder *pShellFolder = NULL;
  hRet = ::SHGetDesktopFolder (&pShellFolder);
  if (FAILED (hRet)){
    m_pMalloc->Free (pidl);
    m_pMalloc->Release ();
    return NULL;
  }

  IShellFolder *pFavFolder = NULL;
  hRet = pShellFolder->BindToObject (pidl, NULL, IID_IShellFolder, reinterpret_cast<void **>(&pFavFolder));

  long nItems = 0;
  IEnumIDList* pItems = NULL;
  hRet = pFavFolder->EnumObjects(NULL, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS, &pItems);

  if(m_pFavoListRoot){
    CleanUp();
  }
  m_pFavoListRoot = new FAVORITELIST;
  ZeroMemory(m_pFavoListRoot, sizeof(FAVORITELIST));
  PFAVORITELIST pFavoListCur = GetFavorite( pFavFolder, m_pFavoListRoot, pItems);
  if (NULL != pItems){
    pItems->Release();
  }
  m_pMalloc->Free(pidl);
  m_pMalloc->Release();

  return m_pFavoListRoot;
}
コード例 #8
0
ファイル: DriveViewer.cpp プロジェクト: avrionov/explorerxp
void GetDrives (CDriveArray &array)
{
	array.clear ();

	IShellFolder   *psfDesktop;

	SHGetDesktopFolder(&psfDesktop);
	if(psfDesktop == NULL)
		return;
	
	LPITEMIDLIST   pidlMyComputer;

	SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidlMyComputer);

	if(pidlMyComputer == NULL)
	{
		psfDesktop->Release();
		return;
	}
	
	IShellFolder   *psfMyComputer;

	psfDesktop->BindToObject(pidlMyComputer, NULL, IID_IShellFolder, (LPVOID*)&psfMyComputer);
	
	if(psfMyComputer)
	 {
			IEnumIDList* pEnum;
			if(SUCCEEDED(psfMyComputer->EnumObjects(NULL, SHCONTF_FOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum)))
			{
				ITEMIDLIST* pidl;
				DWORD  dwFetched = 1;
				TCHAR  path[MAX_PATH];

				while(SUCCEEDED(pEnum->Next(1, &pidl, &dwFetched)) && dwFetched)
				{
					SHFILEINFO     sfi;	
					
					//LPITEMIDLIST pidl_full = Pidl_Concatenate (pidlMyComputer, pidl);
					LPITEMIDLIST pidl_full = ILCombine (pidlMyComputer, pidl);					
					SHGetPathFromIDList (pidl_full, path);

					UINT nType = GetDriveType( path);
				//	if( DRIVE_REMOVABLE < nType && nType <= DRIVE_RAMDISK )
					if( nType != DRIVE_UNKNOWN && nType != DRIVE_NO_ROOT_DIR )
					if(SHGetFileInfo((LPCTSTR)pidl_full, 0, &sfi, sizeof(sfi), SHGFI_PIDL | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_LINKOVERLAY))
					{
						CDriveInfo info;
						info.m_Name = sfi.szDisplayName;
						info.m_Path = path;
						info.m_Type = sfi.szTypeName;
						info.m_nImage = sfi.iIcon;
						info.m_nType = nType;
						
						DWORD SectorsPerCluster;     // sectors per cluster
						DWORD BytesPerSector;        // bytes per sector
						DWORD NumberOfFreeClusters;  // free clusters
						DWORD TotalNumberOfClusters; // total clusters
					//	TRACE (L"%s %s\n", sfi.szDisplayName, path);		
						if (nType != DRIVE_REMOVABLE )
						if (GetDiskFreeSpace (path, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters))
							{	
									DWORD BytesPerCluster = BytesPerSector * SectorsPerCluster;								
									info.m_FreeSpace = UInt32x32To64(NumberOfFreeClusters, BytesPerCluster);
									info.m_TotalSize= UInt32x32To64(TotalNumberOfClusters, BytesPerCluster);
							}
						array.push_back (info);
					}
				}
				pEnum->Release ();
			}
		 psfMyComputer->Release();
	 }

	
	CoTaskMemFree(pidlMyComputer);
	
	psfDesktop->Release();    	
}
コード例 #9
0
ファイル: file_tree_view.cpp プロジェクト: AzyxWare/ryzom
bool CFileTreeCtrl::enumObjects(HTREEITEM hParentItem,IShellFolder* pParentFolder, ITEMIDLIST* pidlParent)
{
	IEnumIDList* pEnum;
	if(SUCCEEDED(pParentFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS |SHCONTF_FOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum)))
	{
		ITEMIDLIST* pidl;
		DWORD  dwFetched = 1;
		TV_ITEM tvItem={0};
		TV_INSERTSTRUCT   tvInsert={0};
		bool inserted = false;
		while(SUCCEEDED(pEnum->Next(1, &pidl, &dwFetched)) && dwFetched)
		{
			CTreeItemInfo* pItemInfo = new CTreeItemInfo;
			pItemInfo->pidlSelf = pidl;
			pItemInfo->pidlFullyQual = Pidl_Concatenate(pidlParent,pidl);
			pParentFolder->AddRef();
			pItemInfo->pParentFolder = pParentFolder;
			ZeroMemory(&tvItem, sizeof(tvItem));
			tvItem.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN;
			tvItem.pszText = LPSTR_TEXTCALLBACK;
			tvItem.iImage = tvItem.iSelectedImage = I_IMAGECALLBACK;
			tvItem.lParam= (LPARAM)pItemInfo;
			pItemInfo->dwFlags = SFGAO_LINK | SFGAO_HASSUBFOLDER | SFGAO_FOLDER | SFGAO_DISPLAYATTRMASK | SFGAO_CANRENAME;
			pParentFolder->GetAttributesOf(1, (LPCITEMIDLIST*)&pidl, &pItemInfo->dwFlags);

			// Convert display name in file system path
			char name[MAX_PATH];
			nlverify ( SHGetPathFromIDList ( pidl, name ) );

			// Save it
			pItemInfo->displayName = name;

			// Is a folder ?
			bool folder = (pItemInfo->dwFlags&SFGAO_FOLDER) !=0;

			// No CVS directory
			uint displayNameSize = pItemInfo->displayName.size ();
			string ext3 = pItemInfo->displayName.substr(displayNameSize-3);
			string ext4 = pItemInfo->displayName.substr(displayNameSize-4);
			string ext5 = pItemInfo->displayName.substr(displayNameSize-5);

			bool cvs = ext3 == "CVS" || ext4 == "CVS\\" || ext4 == "CVS/" ||
				ext4 == ".svn" || ext5 == ".svn\\" || ext5 == ".svn/";

/*			bool cvs = ( pItemInfo->displayName[displayNameSize-3] == 'C') &&
				(pItemInfo->displayName[displayNameSize-2] == 'V') &&
				(pItemInfo->displayName[displayNameSize-1] == 'S');
			if (!cvs)
			{
				cvs = ( pItemInfo->displayName[displayNameSize-4] == 'C') &&
					(pItemInfo->displayName[displayNameSize-3] == 'V') &&
					(pItemInfo->displayName[displayNameSize-2] == 'S') &&
					( (pItemInfo->displayName[displayNameSize-1] == '\\') || (pItemInfo->displayName[displayNameSize-1] == '/') );
			}*/

			// Continue ?
			if (!folder || !cvs)
			{
				// Filter
				uint filter;
				uint filterCount = _ExclusiveExtFilter.size ();

				// Get the extension
				uint pos = pItemInfo->displayName.rfind ('.');
				const char *extName = NULL;
				if (pos != string::npos)
					extName = pItemInfo->displayName.c_str ()+pos;

				if (!folder)
				for (filter=0; filter<filterCount; filter++)
				{
					if (extName)
					{
						if (stricmp (extName, _ExclusiveExtFilter[filter].c_str ()) == 0)
							break;
					}
				}

				// All exclusive filters ok ?
				if (folder || (filter < filterCount) || (filterCount == 0))
				{
					filterCount = _NegativeExtFilter.size ();

					if (!folder)
					for (filter=0; filter<filterCount; filter++)
					{
						if (extName)
						{
							if (stricmp (extName, _NegativeExtFilter[filter].c_str ()) == 0)
								break;
						}
					}

					// All negative filters ok ?
					if (folder || (filter == filterCount))
					{
						tvItem.cChildren = (pItemInfo->dwFlags & SFGAO_FOLDER) && ((pItemInfo->dwFlags & SFGAO_LINK) ==0);
						if(pItemInfo->dwFlags & SFGAO_SHARE)
						{
							tvItem.mask |= TVIF_STATE;
							tvItem.stateMask |= TVIS_OVERLAYMASK;
							tvItem.state |= INDEXTOOVERLAYMASK(1);
						}
						tvInsert.item = tvItem;
						tvInsert.hInsertAfter = TVI_LAST;
						tvInsert.hParent = hParentItem;
						_TreeCtrl.InsertItem(&tvInsert);
						dwFetched = 0;
						inserted = true;
					}
				}
			}
		}
		if (!inserted)
		{
			/*tvInsert.item.mask = LVIF_IMAGE;
			tvInsert.item.stateMask = 0;
			tvInsert.item.state = 0;
			tvInsert.item.mask = 0;
			tvInsert.item.pszText = 0;
			tvInsert.item.iImage = tvInsert.item.iSelectedImage = 10;
			tvInsert.item.lParam = NULL;
			tvInsert.item.cChildren = 0;
			tvInsert.hInsertAfter = TVI_LAST;
			tvInsert.hParent = hParentItem;
			_TreeCtrl.InsertItem(&tvInsert);*/
			/*HTREEITEM hItem = _TreeCtrl.InsertItem ("", hParentItem );
			_TreeCtrl.SetItemImage( hItem, 0xffffffff, 0xffffffff );*/
			/*memset (&tvItem, 0, sizeof (TVITEM));
			tvItem.hItem = hParentItem;
			nlverify (_TreeCtrl.GetItem( &tvItem ));
			tvItem.cChildren = 0;
			nlverify (_TreeCtrl.SetItem( &tvItem ));*/
		}

		// Sort the list
		if (_ArrangeMode != None)
		{
			TVSORTCB tvSort;
			tvSort.hParent = hParentItem;
			tvSort.lpfnCompare = CompareFunc;
			tvSort.lParam = (LPARAM)this;
			_TreeCtrl.SortChildrenCB( &tvSort );
		}

		pEnum->Release();
		return true;
	}
	return false;
}
コード例 #10
0
ファイル: ExPaths.cpp プロジェクト: SpivEgin/stexbar
bool CDeskBand::FindPaths()
{
    m_currentDirectory.clear();
    m_selectedItems.clear();
    m_bFilesSelected = false;
    m_bFolderSelected = false;

    if (m_pSite == NULL)
        return false;
    IServiceProvider * pServiceProvider;
    if (SUCCEEDED(m_pSite->QueryInterface(IID_IServiceProvider, (LPVOID*)&pServiceProvider)))
    {
        IShellBrowser * pShellBrowser;
        if (SUCCEEDED(pServiceProvider->QueryService(SID_SShellBrowser, IID_IShellBrowser, (LPVOID*)&pShellBrowser)))
        {
            IShellView * pShellView;
            if (SUCCEEDED(pShellBrowser->QueryActiveShellView(&pShellView)))
            {
                IFolderView * pFolderView;
                if (SUCCEEDED(pShellView->QueryInterface(IID_IFolderView, (LPVOID*)&pFolderView)))
                {
                    // hooray! we got the IFolderView interface!
                    // that means the explorer is active and well :)

                    // but we also need the IShellFolder interface because
                    // we need its GetCurFolder() method
                    IPersistFolder2 * pPersistFolder;
                    if (SUCCEEDED(pFolderView->GetFolder(IID_IPersistFolder2, (LPVOID*)&pPersistFolder)))
                    {
                        LPITEMIDLIST folderpidl;
                        if (SUCCEEDED(pPersistFolder->GetCurFolder(&folderpidl)))
                        {
                            // we have the current folder
                            TCHAR buf[MAX_PATH] = {0};
                            // find the path of the folder
                            if (SHGetPathFromIDList(folderpidl, buf))
                            {
                                m_currentDirectory = buf;
                            }
                            // if m_currentDirectory is empty here, that means
                            // the current directory is a virtual path

                            IShellFolder * pShellFolder;
                            if (SUCCEEDED(pPersistFolder->QueryInterface(IID_IShellFolder, (LPVOID*)&pShellFolder)))
                            {
                                // if there was a new folder created but not found to set into editing mode,
                                // we try here to do that
                                if (!m_newfolderPidls.empty())
                                {
                                    int nCount2 = 0;
                                    IShellFolder * pShellFolder;
                                    if (SUCCEEDED(pPersistFolder->QueryInterface(IID_IShellFolder, (LPVOID*)&pShellFolder)))
                                    {
                                        if (SUCCEEDED(pFolderView->ItemCount(SVGIO_ALLVIEW, &nCount2)))
                                        {
                                            for (int i=0; i<nCount2; ++i)
                                            {
                                                LPITEMIDLIST pidl;
                                                pFolderView->Item(i, &pidl);
                                                bool bFound = false;
                                                for (std::vector<LPITEMIDLIST>::iterator it = m_newfolderPidls.begin(); it != m_newfolderPidls.end(); ++it)
                                                {
                                                    HRESULT hr = pShellFolder->CompareIDs(0, pidl, *it);
                                                    if (HRESULT_CODE(hr) == 0)
                                                    {
                                                        // this item was there before, so it's not the new folder
                                                        CoTaskMemFree(*it);
                                                        m_newfolderPidls.erase(it);
                                                        bFound = true;
                                                        break;
                                                    }
                                                }
                                                if (!bFound)
                                                {
                                                    pShellView->SelectItem(pidl, SVSI_EDIT);
                                                }
                                                CoTaskMemFree(pidl);
                                            }
                                        }
                                        if ((nCount2)||(m_newfolderTimeoutCounter-- <= 0))
                                        {
                                            m_newfolderTimeoutCounter = 0;
                                            for (std::vector<LPITEMIDLIST>::iterator it = m_newfolderPidls.begin(); it != m_newfolderPidls.end(); ++it)
                                            {
                                                CoTaskMemFree(*it);
                                            }
                                            m_newfolderPidls.clear();
                                        }
                                        pShellFolder->Release();
                                    }

                                }
                                // find all selected items
                                IEnumIDList * pEnum;
                                if (SUCCEEDED(pFolderView->Items(SVGIO_SELECTION, IID_IEnumIDList, (LPVOID*)&pEnum)))
                                {
                                    LPITEMIDLIST pidl;
                                    WCHAR buf[MAX_PATH] = {0};
                                    ULONG fetched = 0;
                                    ULONG attribs = 0;
                                    do
                                    {
                                        pidl = NULL;
                                        if (SUCCEEDED(pEnum->Next(1, &pidl, &fetched)))
                                        {
                                            if (fetched)
                                            {
                                                // the pidl we get here is relative!
                                                attribs = SFGAO_FILESYSTEM|SFGAO_FOLDER;
                                                if (SUCCEEDED(pShellFolder->GetAttributesOf(1, (LPCITEMIDLIST*)&pidl, &attribs)))
                                                {
                                                    if (attribs & SFGAO_FILESYSTEM)
                                                    {
                                                        // create an absolute pidl with the pidl we got above
                                                        LPITEMIDLIST abspidl = CPidl::Append(folderpidl, pidl);
                                                        if (abspidl)
                                                        {
                                                            if (SHGetPathFromIDList(abspidl, buf))
                                                            {
                                                                m_selectedItems[std::wstring(buf)] = attribs;
                                                                if (m_currentDirectory.empty())
                                                                {
                                                                    // remove the last part of the path of the selected item
                                                                    WCHAR * pSlash = _tcsrchr(buf, '\\');
                                                                    if (pSlash)
                                                                        *pSlash = 0;
                                                                    m_currentDirectory = std::wstring(buf);
                                                                }
                                                            }
                                                            CoTaskMemFree(abspidl);
                                                        }
                                                        if (attribs & SFGAO_FOLDER)
                                                            m_bFolderSelected = true;
                                                        else
                                                            m_bFilesSelected = true;
                                                    }
                                                }
                                            }
                                            CoTaskMemFree(pidl);
                                        }
                                    } while(fetched);
                                    pEnum->Release();
                                }
                                pShellFolder->Release();
                            }
                            CoTaskMemFree(folderpidl);
                        }
                        pPersistFolder->Release();
                    }
                    pFolderView->Release();
                }
                pShellView->Release();
            }
            pShellBrowser->Release();
        }
        pServiceProvider->Release();
    }
    return ((!m_currentDirectory.empty()) || (!m_selectedItems.empty()));
}
コード例 #11
0
ファイル: Rename.cpp プロジェクト: SpivEgin/stexbar
void CDeskBand::Rename(HWND hwnd, const std::map<std::wstring, ULONG>& items)
{
    // fill the list of selected file/foldernames
    m_filelist.clear();
    if (items.size() > 1)
    {
        for (std::map<std::wstring, ULONG>::const_iterator it = items.begin(); it != items.end(); ++it)
        {
            size_t pos = it->first.find_last_of('\\');
            if (pos != std::wstring::npos)
            {
                m_filelist.insert(it->first.substr(pos+1));
            }
        }
    }
    else if (items.size() == 1)
    {
        for (std::map<std::wstring, ULONG>::const_iterator it = items.begin(); it != items.end(); ++it)
        {
            size_t pos = it->first.find_last_of('\\');
            if (pos != std::wstring::npos)
            {
                m_filelist.insert(it->first.substr(pos+1));
            }
        }
    }
    else
    {
        // no files or only one file were selected.
        // use all files and folders in the current folder instead
        IServiceProvider * pServiceProvider = NULL;
        if (SUCCEEDED(GetIServiceProvider(hwnd, &pServiceProvider)))
        {
            IShellBrowser * pShellBrowser;
            if (SUCCEEDED(pServiceProvider->QueryService(SID_SShellBrowser, IID_IShellBrowser, (LPVOID*)&pShellBrowser)))
            {
                IShellView * pShellView;
                if (SUCCEEDED(pShellBrowser->QueryActiveShellView(&pShellView)))
                {
                    IFolderView * pFolderView;
                    if (SUCCEEDED(pShellView->QueryInterface(IID_IFolderView, (LPVOID*)&pFolderView)))
                    {
                        // hooray! we got the IFolderView interface!
                        // that means the explorer is active and well :)

                        // but we also need the IShellFolder interface because
                        // we need its GetCurFolder() method
                        IPersistFolder2 * pPersistFolder;
                        if (SUCCEEDED(pFolderView->GetFolder(IID_IPersistFolder2, (LPVOID*)&pPersistFolder)))
                        {
                            LPITEMIDLIST folderpidl;
                            if (SUCCEEDED(pPersistFolder->GetCurFolder(&folderpidl)))
                            {
                                // we have the current folder
                                TCHAR buf[MAX_PATH] = {0};
                                // find the path of the folder
                                if (SHGetPathFromIDList(folderpidl, buf))
                                {
                                    m_currentDirectory = buf;
                                }
                                // if m_currentDirectory is empty here, that means
                                // the current directory is a virtual path

                                IShellFolder * pShellFolder;
                                if (SUCCEEDED(pPersistFolder->QueryInterface(IID_IShellFolder, (LPVOID*)&pShellFolder)))
                                {
                                    // find all selected items
                                    IEnumIDList * pEnum;
                                    if (SUCCEEDED(pFolderView->Items(SVGIO_ALLVIEW, IID_IEnumIDList, (LPVOID*)&pEnum)))
                                    {
                                        LPITEMIDLIST pidl;
                                        WCHAR buf[MAX_PATH] = {0};
                                        ULONG fetched = 0;
                                        ULONG attribs = 0;
                                        do
                                        {
                                            pidl = NULL;
                                            if (SUCCEEDED(pEnum->Next(1, &pidl, &fetched)))
                                            {
                                                if (fetched)
                                                {
                                                    // the pidl we get here is relative!
                                                    attribs = SFGAO_FILESYSTEM|SFGAO_FOLDER;
                                                    if (SUCCEEDED(pShellFolder->GetAttributesOf(1, (LPCITEMIDLIST*)&pidl, &attribs)))
                                                    {
                                                        if (attribs & SFGAO_FILESYSTEM)
                                                        {
                                                            // create an absolute pidl with the pidl we got above
                                                            LPITEMIDLIST abspidl = CPidl::Append(folderpidl, pidl);
                                                            if (abspidl)
                                                            {
                                                                if (SHGetPathFromIDList(abspidl, buf))
                                                                {
                                                                    std::wstring p = buf;
                                                                    size_t pos = p.find_last_of('\\');
                                                                    if (pos != std::wstring::npos)
                                                                    {
                                                                        m_filelist.insert(p.substr(pos+1));
                                                                    }
                                                                }
                                                                CoTaskMemFree(abspidl);
                                                            }
                                                        }
                                                    }
                                                }
                                                CoTaskMemFree(pidl);
                                            }
                                        } while(fetched);
                                        pEnum->Release();
                                    }
                                    pShellFolder->Release();
                                }
                                CoTaskMemFree(folderpidl);
                            }
                            pPersistFolder->Release();
                        }
                        pFolderView->Release();
                    }
                    pShellView->Release();
                }
                pShellBrowser->Release();
            }
            pServiceProvider->Release();
        }
    }

    // show the rename dialog
    m_bDialogShown = TRUE;
    CRenameDlg dlg(hwnd);
    dlg.SetFileList(m_filelist);
    if (dlg.DoModal(g_hInst, IDD_RENAMEDLG, hwnd, NULL) == IDOK)
    {
        try
        {
            const std::tr1::wregex regCheck(dlg.GetMatchString(), dlg.GetRegexFlags());
            NumberReplaceHandler handler(dlg.GetReplaceString());

            // start renaming the files
            IServiceProvider * pServiceProvider = NULL;
            if (SUCCEEDED(GetIServiceProvider(hwnd, &pServiceProvider)))
            {
                IShellBrowser * pShellBrowser;
                if (SUCCEEDED(pServiceProvider->QueryService(SID_SShellBrowser, IID_IShellBrowser, (LPVOID*)&pShellBrowser)))
                {
                    IShellView * pShellView;
                    if (SUCCEEDED(pShellBrowser->QueryActiveShellView(&pShellView)))
                    {
                        IFolderView * pFolderView;
                        if (SUCCEEDED(pShellView->QueryInterface(IID_IFolderView, (LPVOID*)&pFolderView)))
                        {
                            // hooray! we got the IFolderView interface!
                            // that means the explorer is active and well :)

                            // but we also need the IShellFolder interface because
                            // we need its GetDisplayNameOf() method
                            IPersistFolder2 * pPersistFolder;
                            if (SUCCEEDED(pFolderView->GetFolder(IID_IPersistFolder2, (LPVOID*)&pPersistFolder)))
                            {
                                IShellFolder * pShellFolder;
                                if (SUCCEEDED(pPersistFolder->QueryInterface(IID_IShellFolder, (LPVOID*)&pShellFolder)))
                                {
                                    // our next task is to enumerate all the
                                    // items in the folder view and select those
                                    // which match the text in the edit control

                                    int nCount = 0;
                                    if (SUCCEEDED(pFolderView->ItemCount(SVGIO_ALLVIEW, &nCount)))
                                    {
                                        for (int i=0; i<nCount; ++i)
                                        {
                                            LPITEMIDLIST pidl;
                                            if (SUCCEEDED(pFolderView->Item(i, &pidl)))
                                            {
                                                STRRET str;
                                                if (SUCCEEDED(pShellFolder->GetDisplayNameOf(pidl,
                                                    // SHGDN_FORPARSING needed to get the extensions even if they're not shown
                                                    SHGDN_INFOLDER|SHGDN_FORPARSING,
                                                    &str)))
                                                {
                                                    TCHAR dispname[MAX_PATH];
                                                    StrRetToBuf(&str, pidl, dispname, _countof(dispname));

                                                    std::wstring replaced;
                                                    try
                                                    {
                                                        std::wstring sDispName = dispname;
                                                        // check if the item is in the list of selected items
                                                        if (m_filelist.find(sDispName) != m_filelist.end())
                                                        {
                                                            replaced = std::tr1::regex_replace(sDispName, regCheck, dlg.GetReplaceString());
                                                            replaced = handler.ReplaceCounters(replaced);
                                                            if (replaced.compare(sDispName))
                                                            {
                                                                ITEMIDLIST * pidlrenamed;
                                                                pShellFolder->SetNameOf(NULL, pidl, replaced.c_str(), SHGDN_FORPARSING|SHGDN_INFOLDER, &pidlrenamed);
                                                                // if the rename was successful, select the renamed item
                                                                if (pidlrenamed)
                                                                    pFolderView->SelectItem(i, SVSI_CHECK|SVSI_SELECT);
                                                            }
                                                        }
                                                    }
                                                    catch (std::exception)
                                                    {
                                                    }
                                                }
                                                CoTaskMemFree(pidl);
                                            }
                                        }
                                    }
                                    pShellFolder->Release();
                                }
                                pPersistFolder->Release();
                            }
                            pFolderView->Release();
                        }
                        pShellView->Release();
                    }
                    pShellBrowser->Release();
                }
                pServiceProvider->Release();
            }
        }
        catch (std::exception)
        {
        }
    }
    m_bDialogShown = FALSE;
}
コード例 #12
0
ファイル: file_system.cpp プロジェクト: eledot/aseprite
const FileItemList& FileItem::getChildren()
{
  // Is the file-item a folder?
  if (IS_FOLDER(this) &&
      // if the children list is empty, or the file-system version
      // change (it's like to say: the current this->children list
      // is outdated)...
      (this->children.empty() ||
       current_file_system_version > this->version)) {
    FileItemList::iterator it;
    FileItem* child;

    // we have to mark current items as deprecated
    for (it=this->children.begin();
         it!=this->children.end(); ++it) {
      child = static_cast<FileItem*>(*it);
      child->removed = true;
    }

    //PRINTF("FS: Loading files for %p (%s)\n", fileitem, fileitem->displayname);
#ifdef USE_PIDLS
    {
      IShellFolder* pFolder = NULL;

      if (this == rootitem)
        pFolder = shl_idesktop;
      else
        shl_idesktop->BindToObject(this->fullpidl,
                                   NULL,
                                   IID_IShellFolder,
                                   (LPVOID *)&pFolder);

      if (pFolder != NULL) {
        IEnumIDList *pEnum = NULL;
        ULONG c, fetched;

        /* get the interface to enumerate subitems */
        pFolder->EnumObjects(win_get_window(),
                             SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnum);

        if (pEnum != NULL) {
          LPITEMIDLIST itempidl[256];
          SFGAOF attribs[256];

          /* enumerate the items in the folder */
          while (pEnum->Next(256, itempidl, &fetched) == S_OK && fetched > 0) {
            /* request the SFGAO_FOLDER attribute to know what of the
               item is a folder */
            for (c=0; c<fetched; ++c) {
              attribs[c] = SFGAO_FOLDER;
              pFolder->GetAttributesOf(1, (LPCITEMIDLIST *)itempidl, attribs+c);
            }

            /* generate the FileItems */
            for (c=0; c<fetched; ++c) {
              LPITEMIDLIST fullpidl = concat_pidl(this->fullpidl,
                                                  itempidl[c]);

              child = get_fileitem_by_fullpidl(fullpidl, false);
              if (!child) {
                child = new FileItem(this);

                child->pidl = itempidl[c];
                child->fullpidl = fullpidl;
                child->attrib = attribs[c];

                update_by_pidl(child);
                put_fileitem(child);
              }
              else {
                ASSERT(child->parent == this);
                free_pidl(fullpidl);
                free_pidl(itempidl[c]);
              }

              this->insertChildSorted(child);
            }
          }

          pEnum->Release();
        }

        if (pFolder != shl_idesktop)
          pFolder->Release();
      }
    }
#else
    {
      char buf[MAX_PATH], path[MAX_PATH], tmp[32];

      ustrcpy(path, this->filename.c_str());
      put_backslash(path);

      replace_filename(buf,
                       path,
                       uconvert_ascii("*.*", tmp),
                       sizeof(buf));

#ifdef WORKAROUND_64BITS_SUPPORT
      // we cannot use the for_each_file's 'param' to wrap a 64-bits pointer
      for_each_child_callback_param = this;
      for_each_file(buf, FA_TO_SHOW, for_each_child_callback, 0);
#else
      for_each_file(buf, FA_TO_SHOW,
                    for_each_child_callback,
                    (int)this);
#endif
  }
#endif

    // check old file-items (maybe removed directories or file-items)
    for (it=this->children.begin();
         it!=this->children.end(); ) {
      child = static_cast<FileItem*>(*it);
      if (child->removed) {
        it = this->children.erase(it);

        fileitems_map->erase(fileitems_map->find(child->keyname));
        delete child;
      }
      else
        ++it;
    }

    // now this file-item is updated
    this->version = current_file_system_version;
  }

  return this->children;
}
コード例 #13
0
bool CFileSelectList::AddFileItem(LPITEMIDLIST pFullIDLS,int nOption)
{
	bool res = false;

	SHFILEINFO fileInfo={0};
	if(SHGetFileInfo((LPCTSTR)pFullIDLS,0,&fileInfo,sizeof(fileInfo),SHGFI_PIDL |SHGFI_DISPLAYNAME|SHGFI_ATTRIBUTES|SHGFI_ICON|SHGFI_SMALLICON) != 0)
	{
		if(fileInfo.dwAttributes & SFGAO_FILESYSTEM)
		{

			bool bIsFile = false;
			if(fileInfo.dwAttributes & SFGAO_FOLDER)//判断是否是文件系统对象文件夹,排除zip文件
			{
				if(fileInfo.dwAttributes & SFGAO_STREAM) 
				{
					int nSysID = GetWindowsSystemID();
					if(nSysID == WINDOWS_XP || nSysID == WINDOWS_VISTA || nSysID == WINDOWS_2003)
					{
							bIsFile = true;//zip文件
					}
				}
			}
			else
			{
				bIsFile = true;
			}

			if(!bIsFile) //是文件夹,但不是.zip文件
			{
				IShellFolder *pIParentFolder,*pICurFolder;
				LPITEMIDLIST pLocalIDLS;

				if(nOption & UNIFOLDER_PIG)//作为整体归档
				{
					goto PIG_FILE;
				}
				else//归档下面的文件
				{
					if(S_OK == SHBindToParent(pFullIDLS,IID_IShellFolder,(void**)&pIParentFolder,(LPCITEMIDLIST*)&pLocalIDLS))
					{
						if(S_OK == pIParentFolder->BindToObject(pLocalIDLS,NULL,IID_IShellFolder,(void**)&pICurFolder))
						{
							IEnumIDList* pIEnum;
							SHCONTF enumFlag = (nOption&FOLDER_RECURSIVEG_PIG)?(SHCONTF_FOLDERS|SHCONTF_NONFOLDERS):SHCONTF_NONFOLDERS;
							if(S_OK == pICurFolder->EnumObjects(NULL,enumFlag,&pIEnum))
							{
								for(HRESULT call_res = pIEnum->Next(1,&pLocalIDLS,NULL);call_res == S_OK;call_res = pIEnum->Next(1,&pLocalIDLS,NULL))
								{
									LPITEMIDLIST pFullChildIDLST = ILCombine(pFullIDLS,pLocalIDLS);
									if(pFullChildIDLST != NULL)
									{
										AddFileItem(pFullChildIDLST,nOption);
										ILFree(pFullChildIDLST);
									}

									CoTaskMemFree(pLocalIDLS);
								}
								pIEnum->Release();
							}
							pICurFolder->Release();
						}
						pIParentFolder->Release();
					}
				}

			}
			else //is file
			{
PIG_FILE:
				TCHAR tcbufPath[MAX_PATH];
				if(SHGetPathFromIDList(pFullIDLS,tcbufPath))
				{
					if(!IsAlreayIn(FilePath2Url(CString(tcbufPath))))
					{
						CString strPathFolder,strFName,strDriver,strExt;
						SplitFilePath(CString(tcbufPath),strPathFolder,strDriver,strFName,strExt);

						LVITEM lvit = {0};
						lvit.mask = LVIF_IMAGE|LVIF_TEXT;
						lvit.iItem = GetItemCount();
						lvit.pszText = (LPWSTR)(LPCTSTR)strFName;
						lvit.cchTextMax = strFName.GetLength();

						int iImg;
						if(!m_iSys2Self.Lookup(fileInfo.iIcon,iImg))
						{

							//CImageList *pImgLs = GetImageList(LVSIL_SMALL);
							iImg = GetImageList(LVSIL_SMALL)->Add(fileInfo.hIcon);
							m_iSys2Self.SetAt(fileInfo.iIcon,iImg);
						}

						lvit.iImage = iImg;
						int iItem = InsertItem(&lvit);
						//SetItem(iItem,1,LVIF_TEXT,strPathFolder+L"\\",0,0,0,0);
						SetItemText(iItem,1,tcbufPath);

						ItemDataType* pItemData = new ItemDataType;
						pItemData->strItemUrl = FilePath2Url(tcbufPath);
						SetItemData(iItem,(DWORD_PTR)pItemData);

					}
				}
			}
		}
		DestroyIcon(fileInfo.hIcon);
	}
	
	return res;
}
コード例 #14
0
ファイル: folders.cpp プロジェクト: Nevermore2015/reactos
/**************************************************************************
*  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;
}
コード例 #15
0
void CShellBrowser::BrowseVirtualFolder(LPITEMIDLIST pidlDirectory)
{
	IShellFolder	*pShellFolder = NULL;
	IEnumIDList		*pEnumIDList = NULL;
	LPITEMIDLIST	rgelt = NULL;
	STRRET			str;
	SHCONTF			EnumFlags;
	TCHAR			szFileName[MAX_PATH];
	ULONG			uFetched;
	HRESULT			hr;

	DetermineFolderVirtual(pidlDirectory);

	hr = BindToIdl(pidlDirectory, IID_PPV_ARGS(&pShellFolder));

	if(SUCCEEDED(hr))
	{
		m_pidlDirectory = ILClone(pidlDirectory);

		EnumFlags = SHCONTF_FOLDERS|SHCONTF_NONFOLDERS;

		if(m_bShowHidden)
			EnumFlags |= SHCONTF_INCLUDEHIDDEN;

		hr = pShellFolder->EnumObjects(m_hOwner,EnumFlags,&pEnumIDList);

		if(SUCCEEDED(hr) && pEnumIDList != NULL)
		{
			uFetched = 1;
			while(pEnumIDList->Next(1,&rgelt,&uFetched) == S_OK && (uFetched == 1))
			{
				ULONG uAttributes = SFGAO_FOLDER;

				pShellFolder->GetAttributesOf(1,(LPCITEMIDLIST *)&rgelt,&uAttributes);

				/* If this is a virtual folder, only use SHGDN_INFOLDER. If this is
				a real folder, combine SHGDN_INFOLDER with SHGDN_FORPARSING. This is
				so that items in real folders can still be shown with extensions, even
				if the global, Explorer option is disabled.
				Also use only SHGDN_INFOLDER if this item is a folder. This is to ensure
				that specific folders in Windows 7 (those under C:\Users\Username) appear
				correctly. */
				if(m_bVirtualFolder || (uAttributes & SFGAO_FOLDER))
					hr = pShellFolder->GetDisplayNameOf(rgelt,SHGDN_INFOLDER,&str);
				else
					hr = pShellFolder->GetDisplayNameOf(rgelt,SHGDN_INFOLDER|SHGDN_FORPARSING,&str);

				if(SUCCEEDED(hr))
				{
					StrRetToBuf(&str,rgelt,szFileName,MAX_PATH);

					AddItemInternal(pidlDirectory,rgelt,szFileName,-1,FALSE);
				}

				CoTaskMemFree((LPVOID)rgelt);
			}

			pEnumIDList->Release();
		}

		pShellFolder->Release();
	}
}
コード例 #16
0
ファイル: Utils.cpp プロジェクト: Feoggou/filetransfer
void SearchFolder(IShellFolder* pSearchFolder, CDoubleList<FILE_ITEM> &Items, LARGE_INTEGER& liSize)
{
	//getting the enumerator object to enumerate the items of the search folder
	IEnumIDList* pEnumIDList = NULL;
	HRESULT hr = pSearchFolder->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &pEnumIDList);
	if (FAILED(hr))
	{
		if (hr != E_ACCESSDENIED)
			DisplayError(hr);
		return;
	}

	if (hr == S_FALSE) return;

	//getting pidl to each child item
	ITEMIDLIST* pidlChild = NULL;
	HRESULT hrEnum;
	do
	{
		hrEnum = pEnumIDList->Next(1, &pidlChild, NULL);
		if (FAILED(hrEnum))
		{
			pEnumIDList->Release();

			_ASSERT(0);
			DisplayError(hrEnum);
			return;
		}

		if (S_FALSE == hrEnum) break;

		//we need to know whether this is a folder or a file, and if it is a system item
		ULONG ulFlags = 0xFFFFFFFF;
		hr = pSearchFolder->GetAttributesOf(1, (LPCITEMIDLIST*)&pidlChild, &ulFlags);
		if (FAILED(hr))
		{
			CoTaskMemFree(pidlChild);
			pidlChild = NULL;
			pEnumIDList->Release();

			_ASSERT(0);
			MessageBox(0, L"Could not get the attributes of the item: pSearchFolder->GetAttributesOf", 0, 0);
			return;
		}

		if (ulFlags & SFGAO_FILESYSTEM)
		{
			if (ulFlags & SFGAO_FOLDER && ulFlags & SFGAO_FILESYSANCESTOR && ulFlags & SFGAO_STORAGE)
			{
				//we need to search it
				IShellFolder* pNewSearchFolder = NULL;
				hr = pSearchFolder->BindToObject(pidlChild, NULL, IID_IShellFolder, (void**)&pNewSearchFolder);
				if (FAILED(hr))
				{
					CoTaskMemFree(pidlChild);
					pidlChild = NULL;
					pEnumIDList->Release();

					_ASSERT(0);
					MessageBox(0, L"Could not bind to new folder: pSearchFolder->BindToObject", 0, 0);
					return;
				}

				//it is a folder!!
				//get its full name
				STRRET strret;
				pSearchFolder->GetDisplayNameOf(pidlChild, SHGDN_FORPARSING, &strret);
				WCHAR* wsFullName;
				StrRetToStrW(&strret, NULL, &wsFullName);

				FILE_ITEM item;
				item.size = 0;

				item.wsFullName = wsFullName;
				item.type = ItemType::Folder;
				Items.push_back(item);

				SearchFolder(pNewSearchFolder, Items, liSize);
				pNewSearchFolder->Release();
			}
			else if (ulFlags & SFGAO_STREAM)
			{
				//it is a file!!
				//get its full name
				STRRET strret;
				pSearchFolder->GetDisplayNameOf(pidlChild, SHGDN_FORPARSING, &strret);
				WCHAR* wsFullName;
				StrRetToStrW(&strret, NULL, &wsFullName);

				FILE_ITEM item;
				LARGE_INTEGER li;
				CalcFileSize(wsFullName, li);
				item.size = li.QuadPart;
				liSize.QuadPart += item.size;

				item.wsFullName = wsFullName;
				item.type = ItemType::File;
				Items.push_back(item);
			}
		}

		CoTaskMemFree(pidlChild);
		pidlChild = NULL;

	#pragma warning(suppress: 4127)
	}while (1);

	if (pidlChild)
		CoTaskMemFree(pidlChild);
	pEnumIDList->Release();
}