Esempio n. 1
0
// @pymethod int|PyIShellItem|GetAttributes|Returns shell attributes of the item
// @rdesc Returns a combination of shellcon.SFGAO_* values
PyObject *PyIShellItem::GetAttributes(PyObject *self, PyObject *args)
{
	IShellItem *pISI = GetI(self);
	if ( pISI == NULL )
		return NULL;
	SFGAOF sfgaoMask;
	SFGAOF ret;
	// @pyparm int|Mask||Combination of shellcon.SFGAO_* values indicating the flags to return
	if ( !PyArg_ParseTuple(args, "k:GetAttributes", &sfgaoMask) )
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pISI->GetAttributes( sfgaoMask, &ret);
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pISI, IID_IShellItem );
	return PyLong_FromUnsignedLong(ret);
}
 IFACEMETHODIMP OnSelectionChange(IFileDialog *pfd)
 {
     // Update the text of the Open/Add button here based on the selection
     IShellItem *psi;
     HRESULT hr = pfd->GetCurrentSelection(&psi);
     if (SUCCEEDED(hr))
     {
         SFGAOF attr;
         hr = psi->GetAttributes(SFGAO_FOLDER | SFGAO_STREAM, &attr);
         if (SUCCEEDED(hr) && (SFGAO_FOLDER == attr))
         {
             pfd->SetOkButtonLabel(L"Open");
         }
         else
         {
             pfd->SetOkButtonLabel(L"Add");
         }
         psi->Release();
     }
     return S_OK;
 }
	void getPaths(IShellItemArray* shellItems, Vector<Path>& paths)
	{
		DWORD numShellItems;
		shellItems->GetCount(&numShellItems);

		for (DWORD i = 0; i < numShellItems; ++i)
		{
			IShellItem* shellItem = nullptr;
			shellItems->GetItemAt(i, &shellItem);

			SFGAOF attribs;
			shellItem->GetAttributes(SFGAO_FILESYSTEM, &attribs);

			if (!(attribs & SFGAO_FILESYSTEM))
				continue;

			LPWSTR name;
			shellItem->GetDisplayName(SIGDN_FILESYSPATH, &name);
			paths.push_back((Path)UTF8::fromWide(WString(name)));
			CoTaskMemFree(name);
		}
	}