void CWordBinaryMetadataDiscoveryWorker::DiscoverSummaryInformation(REFFMTID iidPropsertySet) 
{
	bool bNotFound;
	OpenPropertySet(iidPropsertySet, bNotFound);
	if(bNotFound)
	{
		ClosePropertySet();
		return;
	}

	if(NULL == m_pPropertyStg)
		throw Workshare::Exception(_T("NULL pointer encountered (m_pPropertyStg)"));

	IEnumSTATPROPSTG *pEnumProp;
	
	HRESULT hRes = m_pPropertyStg->Enum(&pEnumProp);
	if(FAILED(hRes))
	{
		ClosePropertySet();
		HandlePropertyError(_T(__FUNCTION__), _T("Enumerate user-defined properties failed"), hRes);
		return;
	}

	STATPROPSTG PropertyInformation;
	ZeroMemory(&PropertyInformation, sizeof(STATPROPSTG));
	PROPSPEC propSpec;
	PROPVARIANT propVar;

	SetCodePageProperty();

	while(S_OK == pEnumProp->Next(1, &PropertyInformation, NULL))
	{
		PropVariantInit(&propVar);
		// Build a PROPSPEC for this property.
		ZeroMemory(&propSpec, sizeof(PROPSPEC));
		propSpec.ulKind = PRSPEC_PROPID;
		propSpec.propid = PropertyInformation.propid;

		// Read this property.
		hRes = m_pPropertyStg->ReadMultiple(1, &propSpec, &propVar);
		if(SUCCEEDED(hRes))
		{
			if (FMTID_SummaryInformation == iidPropsertySet)
				AddBuiltInPropertyForSummary(propVar, PropertyInformation.propid);
			else if (FMTID_DocSummaryInformation == iidPropsertySet)
				AddBuiltInPropertyForDocSummary(propVar, PropertyInformation.propid);
		}
		else
		{
			CStdString sErr;
			sErr.Format(_T("Failed to read property id: %d, error code: %d"), propSpec.propid, hRes);
			LOG_WS_ERROR(sErr);
		}
	}
	pEnumProp->Release();
	ClosePropertySet();
}
Exemplo n.º 2
0
// @pymethod object|PyIEnumSTATPROPSTG|Next|Retrieves a specified number of items in the enumeration sequence.
PyObject *PyIEnumSTATPROPSTG::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;

	IEnumSTATPROPSTG *pIESTATPROPSTG = GetI(self);
	if ( pIESTATPROPSTG == NULL )
		return NULL;

	STATPROPSTG *rgVar = new STATPROPSTG[celt];
	if ( rgVar == NULL ) {
		PyErr_SetString(PyExc_MemoryError, "allocating result STATPROPSTGs");
		return NULL;
	}

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

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

	PyObject *result = PyTuple_New(celtFetched);
	if ( result != NULL )
	{
		for ( i = celtFetched; i--; )
		{
			PyObject *ob = Py_BuildValue("NkH",
				PyWinObject_FromWCHAR(rgVar[i].lpwstrName),
				rgVar[i].propid,
				rgVar[i].vt);
			if (ob == NULL){
				Py_DECREF(result);
				result = NULL;
				break;
				}
			PyTuple_SET_ITEM(result, i, ob);
		}
	}

	for ( i = celtFetched; i--; )
		CoTaskMemFree(rgVar[i].lpwstrName);

	delete [] rgVar;
	return result;
}
Exemplo n.º 3
0
// @pymethod <o PyIEnumSTATPROPSTG>|PyIEnumSTATPROPSTG|Clone|Creates another enumerator that contains the same enumeration state as the current one
PyObject *PyIEnumSTATPROPSTG::Clone(PyObject *self, PyObject *args)
{
	if ( !PyArg_ParseTuple(args, ":Clone") )
		return NULL;

	IEnumSTATPROPSTG *pIESTATPROPSTG = GetI(self);
	if ( pIESTATPROPSTG == NULL )
		return NULL;

	IEnumSTATPROPSTG *pClone;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIESTATPROPSTG->Clone(&pClone);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr);

	return PyCom_PyObjectFromIUnknown(pClone, IID_IEnumSTATPROPSTG, FALSE);
}
Exemplo n.º 4
0
// @pymethod |PyIEnumSTATPROPSTG|Reset|Resets the enumeration sequence to the beginning.
PyObject *PyIEnumSTATPROPSTG::Reset(PyObject *self, PyObject *args)
{
	if ( !PyArg_ParseTuple(args, ":Reset") )
		return NULL;

	IEnumSTATPROPSTG *pIESTATPROPSTG = GetI(self);
	if ( pIESTATPROPSTG == NULL )
		return NULL;

	PY_INTERFACE_PRECALL;
	HRESULT hr = pIESTATPROPSTG->Reset();
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr);

	Py_INCREF(Py_None);
	return Py_None;
}
void CWordBinaryMetadataDiscoveryWorker::DiscoverCustomProperties() 
{
	bool bNotFound;
	OpenPropertySet(FMTID_UserDefinedProperties, bNotFound);

	if(bNotFound)
	{
		ClosePropertySet();
		return;
	}

	if(NULL == m_pPropertyStg)
		throw Workshare::Exception(_T("NULL pointer encountered (m_pPropertyStg)"));

	IEnumSTATPROPSTG *pEnumProp;
	
	HRESULT hRes = m_pPropertyStg->Enum(&pEnumProp);
	if(FAILED(hRes))
	{
		ClosePropertySet();
		HandlePropertyError(_T(__FUNCTION__), _T("Enumerate user-defined properties failed"), hRes);
		return;
	}

	STATPROPSTG PropertyInformation;
	ZeroMemory(&PropertyInformation, sizeof(STATPROPSTG));
	PROPSPEC propSpec;
	PROPVARIANT propVar;

   CStdString exclusions = CMetawallGatewaySettings::GetCustomPropertiesExclusions();

	while(S_OK == pEnumProp->Next(1, &PropertyInformation, NULL))
	{
		PropVariantInit(&propVar);
		// Build a PROPSPEC for this property.
		ZeroMemory(&propSpec, sizeof(PROPSPEC));
		propSpec.ulKind = PRSPEC_PROPID;
		propSpec.propid = PropertyInformation.propid;

		// Read this property.
		hRes = m_pPropertyStg->ReadMultiple(1, &propSpec, &propVar);
		if(SUCCEEDED(hRes))
		{
			if(PropertyInformation.lpwstrName != 0 && !ShouldExcludeCustomProperty(exclusions, CStdString(PropertyInformation.lpwstrName)))
			{
				WordPropertyTypes WordPropertyType;
				if(IsWordInternalCustomProperty(PropertyInformation, propVar))
					WordPropertyType = BUILT_IN_PROPERTY;
				else
					WordPropertyType = CUSTOM_PROPERTY;
				CStdString sPropertyValue((LPCTSTR)PropVariantToString(propVar));
				PopulatePropertyLists(WordPropertyType, CStdString(PropertyInformation.lpwstrName), sPropertyValue);
			}
		}
		else
		{
			CStdString sErr;
			sErr.Format(_T("Failed to read property id: %d, error code: %d"), propSpec.propid, hRes);
			LOG_WS_ERROR(sErr);
		}
	}
	pEnumProp->Release();
	ClosePropertySet();
}
Exemplo n.º 6
0
void App::GetProperties()
{
    LPSTORAGE				pStorage = NULL;
    IPropertySetStorage*	pPropertySetStorage = NULL;
    IPropertyStorage*		pSummaryInfoStorage = NULL;
    IPropertyStorage*		pDocumentSummaryInfoStorage = NULL;
    IPropertyStorage*		pUserDefinedPropertyStorage = NULL;
    wchar_t					wfilename[_MAX_PATH];
    char					szBuf[256];
    char					filename[MAX_PATH];

    SendMessage(GetDlgItem(hPropDialog, IDC_TITLE), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_SUBJECT), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_AUTHOR), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_MANAGER), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_COMPANY), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_CATEGORY), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_KEYWORDS), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_COMMENTS), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_CONTENTS), LB_RESETCONTENT, 0, 0);
    ListView_DeleteAllItems(GetDlgItem(hPropDialog, IDC_CUSTOM));

    int idx = SendMessage(hListBox, LB_GETCURSEL, 0, 0);

    SendMessage(hListBox, LB_GETTEXT, idx, (LPARAM)filename);
    SetWindowText(hPropDialog, filename);

    MultiByteToWideChar(CP_ACP, 0, filename, -1, wfilename, _MAX_PATH);
    HRESULT	res = StgOpenStorage(wfilename, (LPSTORAGE)0, STGM_DIRECT|STGM_READ|STGM_SHARE_EXCLUSIVE,	NULL,0,&pStorage);
    if (res!=S_OK) {
        return;
    }


    // Get the Storage interface
    if (S_OK != pStorage->QueryInterface(IID_IPropertySetStorage, (void**)&pPropertySetStorage)) {
        pStorage->Release();
        return;
    }

    // Get the SummaryInfo property set interface
    if (S_OK == pPropertySetStorage->Open(FMTID_SummaryInformation, STGM_READ|STGM_SHARE_EXCLUSIVE, &pSummaryInfoStorage)) {
        BOOL bFound = FALSE;

        PROPSPEC	PropSpec[5];
        PROPVARIANT	PropVar[5];

        PropSpec[0].ulKind = PRSPEC_PROPID;
        PropSpec[0].propid = PID_TITLE;

        PropSpec[1].ulKind = PRSPEC_PROPID;
        PropSpec[1].propid = PID_SUBJECT;

        PropSpec[2].ulKind = PRSPEC_PROPID;
        PropSpec[2].propid = PID_AUTHOR;

        PropSpec[3].ulKind = PRSPEC_PROPID;
        PropSpec[3].propid = PID_KEYWORDS;

        PropSpec[4].ulKind = PRSPEC_PROPID;
        PropSpec[4].propid = PID_COMMENTS;

        HRESULT hr = pSummaryInfoStorage->ReadMultiple(5, PropSpec, PropVar);
        if (S_OK == hr) {
            if (PropVar[0].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_TITLE), WM_SETTEXT, 0, (LPARAM)PropVar[0].pszVal);
            }
            if (PropVar[1].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_SUBJECT), WM_SETTEXT, 0, (LPARAM)PropVar[1].pszVal);
            }
            if (PropVar[2].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_AUTHOR), WM_SETTEXT, 0, (LPARAM)PropVar[2].pszVal);
            }
            if (PropVar[3].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_KEYWORDS), WM_SETTEXT, 0, (LPARAM)PropVar[3].pszVal);
            }
            if (PropVar[4].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_COMMENTS), WM_SETTEXT, 0, (LPARAM)PropVar[4].pszVal);
            }
        }

        FreePropVariantArray(5, PropVar);
        pSummaryInfoStorage->Release();
    }


    // Get the DocumentSummaryInfo property set interface
    if (S_OK == pPropertySetStorage->Open(FMTID_DocSummaryInformation, STGM_READ|STGM_SHARE_EXCLUSIVE, &pDocumentSummaryInfoStorage)) {
        BOOL bFound = FALSE;

        PROPSPEC	PropSpec[5];
        PROPVARIANT	PropVar[5];

        PropSpec[0].ulKind = PRSPEC_PROPID;
        PropSpec[0].propid = PID_MANAGER;

        PropSpec[1].ulKind = PRSPEC_PROPID;
        PropSpec[1].propid = PID_COMPANY;

        PropSpec[2].ulKind = PRSPEC_PROPID;
        PropSpec[2].propid = PID_CATEGORY;

        PropSpec[3].ulKind = PRSPEC_PROPID;
        PropSpec[3].propid = PID_HEADINGPAIR;

        PropSpec[4].ulKind = PRSPEC_PROPID;
        PropSpec[4].propid = PID_DOCPARTS;

        HRESULT hr = pDocumentSummaryInfoStorage->ReadMultiple(5, PropSpec, PropVar);
        if (S_OK == hr) {
            if (PropVar[0].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_MANAGER), WM_SETTEXT, 0, (LPARAM)PropVar[0].pszVal);
            }
            if (PropVar[1].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_COMPANY), WM_SETTEXT, 0, (LPARAM)PropVar[1].pszVal);
            }
            if (PropVar[2].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_CATEGORY), WM_SETTEXT, 0, (LPARAM)PropVar[2].pszVal);
            }
            if ((PropVar[3].vt == (VT_VARIANT | VT_VECTOR)) && (PropVar[4].vt == (VT_LPSTR | VT_VECTOR))) {
                CAPROPVARIANT*	pHeading = &PropVar[3].capropvar;
                CALPSTR*		pDocPart = &PropVar[4].calpstr;

                // Headings:
                // =========
                // 0  - General
                // 2  - Mesh Totals
                // 4  - Scene Totals
                // 6  - External Dependencies
                // 8  - Objects
                // 10 - Materials
                // 12 - Plug-Ins

                int nDocPart = 0;
                for (UINT i=0; i<pHeading->cElems; i+=2) {
                    SendMessage(GetDlgItem(hPropDialog, IDC_CONTENTS), LB_ADDSTRING, 0, (LPARAM)pHeading->pElems[i].pszVal);
                    for (int j=0; j<pHeading->pElems[i+1].lVal; j++) {
                        sprintf(szBuf, "\t%s", pDocPart->pElems[nDocPart]);
                        SendMessage(GetDlgItem(hPropDialog, IDC_CONTENTS), LB_ADDSTRING, 0, (LPARAM)szBuf);
                        nDocPart++;
                    }
                }

            }

        }

        FreePropVariantArray(5, PropVar);
        pDocumentSummaryInfoStorage->Release();
    }

    if (S_OK == pPropertySetStorage->Open(FMTID_UserDefinedProperties, STGM_READ|STGM_SHARE_EXCLUSIVE, &pUserDefinedPropertyStorage)) {
        int		numUserProps = 0;

        // First we need to count the properties
        IEnumSTATPROPSTG*	pIPropertyEnum;
        if (S_OK == pUserDefinedPropertyStorage->Enum(&pIPropertyEnum)) {
            STATPROPSTG property;
            while (pIPropertyEnum->Next(1, &property, NULL) == S_OK) {
                if (property.lpwstrName) {
                    CoTaskMemFree(property.lpwstrName);
                    property.lpwstrName = NULL;
                    numUserProps++;
                }
            }

            PROPSPEC* pPropSpec = new PROPSPEC[numUserProps];
            PROPVARIANT* pPropVar = new PROPVARIANT[numUserProps];

            ZeroMemory(pPropVar, numUserProps*sizeof(PROPVARIANT));
            ZeroMemory(pPropSpec, numUserProps*sizeof(PROPSPEC));

            pIPropertyEnum->Reset();
            int idx = 0;
            while (pIPropertyEnum->Next(1, &property, NULL) == S_OK) {
                if (property.lpwstrName) {
                    pPropSpec[idx].ulKind = PRSPEC_LPWSTR;
                    pPropSpec[idx].lpwstr = (LPWSTR)CoTaskMemAlloc(sizeof(wchar_t)*(wcslen(property.lpwstrName)+1));
                    wcscpy(pPropSpec[idx].lpwstr, property.lpwstrName);
                    idx++;
                    CoTaskMemFree(property.lpwstrName);
                    property.lpwstrName = NULL;
                }
            }
            pIPropertyEnum->Release();

            ListView_DeleteAllItems(GetDlgItem(hPropDialog, IDC_CUSTOM));
            HRESULT hr = pUserDefinedPropertyStorage->ReadMultiple(idx, pPropSpec, pPropVar);
            if (S_OK == hr) {
                for (int i=0; i<idx; i++) {
                    wcstombs(szBuf, pPropSpec[i].lpwstr, 255);
                    LV_ITEM item;
                    item.mask = LVIF_TEXT;
                    item.iItem = i;
                    item.iSubItem = 0;
                    item.pszText = szBuf;
                    item.cchTextMax = strlen(szBuf);
                    ListView_InsertItem(GetDlgItem(hPropDialog, IDC_CUSTOM), &item);

                    VariantToString(this, &pPropVar[i], szBuf, 255);
                    item.iSubItem = 1;
                    item.pszText = szBuf;
                    item.cchTextMax = strlen(szBuf);
                    ListView_SetItem(GetDlgItem(hPropDialog, IDC_CUSTOM), &item);

                    TypeNameFromVariant(this, &pPropVar[i], szBuf, 255);
                    item.iSubItem = 2;
                    item.pszText = szBuf;
                    item.cchTextMax = strlen(szBuf);
                    ListView_SetItem(GetDlgItem(hPropDialog, IDC_CUSTOM), &item);
                }
            }

            for (int i=0; i<idx; i++) {
                CoTaskMemFree(pPropSpec[i].lpwstr);
            }

            FreePropVariantArray(numUserProps, pPropVar);

            delete [] pPropSpec;
            delete [] pPropVar;
        }

        pUserDefinedPropertyStorage->Release();
    }

    pPropertySetStorage->Release();
    pStorage->Release();
}
Exemplo n.º 7
0
OleProperties::OleProperties(OleStorage& storage) :
   m_pStorage(storage), m_wCodePage(ENCODING_NONE)
{     
   USES_CONVERSION;
   
   IPropertySetStoragePtr spPropertySetStorage(storage.GetInternalObject());

   IPropertyStorage* pPropertyStorage = 0;
   HRESULT hr = spPropertySetStorage->Open(FMTID_UserDefinedProperties, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &pPropertyStorage);
   if(STG_E_FILENOTFOUND == hr)
      return;

   if(FAILED(hr))  
   {
      std::wostringstream os; 
      os << L"Failed to open the user defined property set" << FMTID_UserDefinedProperties << std::ends; 
      LOG_WS_INFO(os.str().c_str());
      return;
   }

   IPropertyStoragePtr spPropertyStorage(pPropertyStorage, false);

   IEnumSTATPROPSTG* pEnumProp = 0;	
	hr = spPropertyStorage->Enum(&pEnumProp);
	if(FAILED(hr))  // if fails, it is an Office bug
   {
      std::wostringstream os; 
      os << _T("Failed to get an IEnumSTATPROPSTG enumerator from the property set. PropertySet ID:[") << FMTID_UserDefinedProperties << _T("]. Continue process as this is not critical.") << std::ends; 
      LOG_WS_INFO(os.str().c_str());
      return;
   }
	
   SetCodePageProperty(spPropertyStorage);

   CollectionType collection;
   try
   {
      IEnumSTATPROPSTGPtr spEnumProp(pEnumProp, false);

      STATPROPSTG propertyInfo;
	   ZeroMemory(&propertyInfo, sizeof(STATPROPSTG));   
      hr = pEnumProp->Next(1, &propertyInfo, NULL);  

      while(S_OK == hr)
      {
         PROPVARIANT propertyVariant;  
         PropVariantInit(&propertyVariant);		
         PROPSPEC propSpec;
         ZeroMemory(&propSpec, sizeof(PROPSPEC));
         propSpec.ulKind = PRSPEC_PROPID;
         propSpec.propid = propertyInfo.propid;

         // Read this property.
         hr = spPropertyStorage->ReadMultiple(1, &propSpec, &propertyVariant);
         if(SUCCEEDED(hr))
         {		   		   
            bool visibleInExplorer = false;
            switch(propertyVariant.vt)
            {
            case VT_LPSTR:
            case VT_FILETIME:
            case VT_I4:
            case VT_BOOL:
               visibleInExplorer = true;
            }

            std::wstring name; 
            if(propertyInfo.lpwstrName != 0)
               name = W2T(propertyInfo.lpwstrName);

            std::wstring value;

            if(PIDSI_EDITTIME == propSpec.propid)
               value =FiletimeAsTimeSpan(propertyVariant);
            else
			{
				if (m_wCodePage == ENCODING_UTF8 && propertyVariant.vt == VT_LPSTR)
					value = ConvertPropertyFromUTF8(propertyVariant.pszVal);
				else
					value = (LPCTSTR)PropVariantToString(propertyVariant);
			}

            collection.push_back(new OleProperty(OlePropertySetGroupUserProperties, propSpec.propid, name, value, visibleInExplorer));
         }		      
         hr = pEnumProp->Next(1, &propertyInfo, NULL);
      }
      
      m_collection = collection;
   }
   catch(...)
   {
      for(CollectionType::iterator i = collection.begin(); i != collection.end(); i++)
         delete *i;

      std::wostringstream os; 
      os << _T("Failed to read a property. PropertySet ID:[") << FMTID_UserDefinedProperties  << _T("]. Continue process as this is not critical.") << std::ends; 
      LOG_WS_INFO(os.str().c_str());
   }
}