Example #1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Displays the transforms for the currently selected category. Since each
        /// </summary>
        /// <history>
        ///    01 Nov 18  Cynic - Started
        /// </history>
        private void DisplayTransformsForCurrentCategory()
        {
            int numResults;

            IMFActivate[] activatorArray;
            List <TantaMFTCapabilityContainer> transformList = new List <TantaMFTCapabilityContainer>();
            HResult hr;

            try
            {
                // clear what we have now
                listViewAvailableTransforms.Clear();
                // reset this
                listViewAvailableTransforms.ListViewItemSorter = null;

                // get the currently selected major category
                TantaGuidNamePair currentCategory = (TantaGuidNamePair)comboBoxTransformCategories.SelectedItem;
                if (currentCategory == null)
                {
                    return;
                }

                // we have multiple sub-categories. These are set by specific flags on the MFTEnumX call. We iterate
                // through each flag and get the matching transforms. If we already have it we just set the flag on
                // the exisiting one to show it is in multiple sub-categories

                foreach (MFT_EnumFlag flagVal in Enum.GetValues(typeof(MFT_EnumFlag)))
                {
                    // we do not need this one
                    if (flagVal == MFT_EnumFlag.None)
                    {
                        continue;
                    }
                    // The documentation states that there is no way to enumerate just local MFTs and nothing else.
                    // Setting Flags equal to MFT_ENUM_FLAG_LOCALMFT is equivalent to including the MFT_ENUM_FLAG_SYNCMFT flag
                    // which messes us up. This also appears to be true for the FieldOfUse and transcode only flags so we
                    // do not include them
                    if (flagVal == MFT_EnumFlag.LocalMFT)
                    {
                        continue;
                    }
                    if (flagVal == MFT_EnumFlag.FieldOfUse)
                    {
                        continue;
                    }
                    if (flagVal == MFT_EnumFlag.TranscodeOnly)
                    {
                        continue;
                    }
                    // some of the higher flags are just for sorting the return results
                    if (flagVal >= MFT_EnumFlag.All)
                    {
                        break;
                    }

                    hr = MFExtern.MFTEnumEx(currentCategory.GuidValue, flagVal, null, null, out activatorArray, out numResults);
                    if (hr != HResult.S_OK)
                    {
                        throw new Exception("DisplayTransformsForCurrentCategory, call to MFExtern.MFTEnumEx failed. HR=" + hr.ToString());
                    }

                    // now loop through the returned activators
                    for (int i = 0; i < numResults; i++)
                    {
                        // extract the friendlyName and symbolicLinkName
                        Guid   outGuid      = TantaWMFUtils.GetGuidForKeyFromActivator(activatorArray[i], MFAttributesClsid.MFT_TRANSFORM_CLSID_Attribute);
                        string friendlyName = TantaWMFUtils.GetStringForKeyFromActivator(activatorArray[i], MFAttributesClsid.MFT_FRIENDLY_NAME_Attribute);

                        // create a new TantaMFTCapabilityContainer for it
                        TantaMFTCapabilityContainer workingMFTContainer = new TantaMFTCapabilityContainer(friendlyName, outGuid, currentCategory);
                        // do we have this in our list yet
                        int index = transformList.FindIndex(x => x.TransformGuidValue == workingMFTContainer.TransformGuidValue);
                        if (index >= 0)
                        {
                            // yes, it does contain this transform, just record the new sub-category
                            transformList[index].EnumFlags |= flagVal;
                        }
                        else
                        {
                            // no, it does not contain this transform yet, set the sub-category
                            workingMFTContainer.EnumFlags = flagVal;
                            // and add it
                            transformList.Add(workingMFTContainer);

                            if ((activatorArray[i] is IMFAttributes) == true)
                            {
                                StringBuilder outSb = null;
                                List <string> attributesToIgnore = new List <string>();
                                attributesToIgnore.Add("MFT_FRIENDLY_NAME_Attribute");
                                attributesToIgnore.Add("MFT_TRANSFORM_CLSID_Attribute");
                                attributesToIgnore.Add("MF_TRANSFORM_FLAGS_Attribute");
                                attributesToIgnore.Add("MF_TRANSFORM_CATEGORY_Attribute");
                                hr = TantaWMFUtils.EnumerateAllAttributeNamesAsText((activatorArray[i] as IMFAttributes), attributesToIgnore, 100, out outSb);
                            }
                        }

                        // clean up our activator
                        Marshal.ReleaseComObject(activatorArray[i]);
                    }
                }

                // now display the transforms
                foreach (TantaMFTCapabilityContainer mftCapability in transformList)
                {
                    ListViewItem lvi = new ListViewItem(new[] { mftCapability.TransformFriendlyName, mftCapability.IsSyncMFT, mftCapability.IsAsyncMFT, mftCapability.IsHardware, /* mftCapability.IsFieldOfUse, mftCapability.IsLocalMFT, mftCapability.IsTranscodeOnly, */ mftCapability.TransformGuidValueAsString });
                    lvi.Tag = mftCapability;
                    listViewAvailableTransforms.Items.Add(lvi);
                }

                listViewAvailableTransforms.Columns.Add("Name", 250);
                listViewAvailableTransforms.Columns.Add("IsSyncMFT", 70);
                listViewAvailableTransforms.Columns.Add("IsAsyncMFT", 90);
                listViewAvailableTransforms.Columns.Add("IsHardware", 90);
                //  listViewAvailableTransforms.Columns.Add("IsFieldOfUse", 90);
                //  listViewAvailableTransforms.Columns.Add("IsLocalMFT", 90);
                //  listViewAvailableTransforms.Columns.Add("IsTranscodeOnly", 90);
                listViewAvailableTransforms.Columns.Add("Guid", 200);
            }
            finally
            {
            }
        }
 /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="transformFriendlyNameIn">the transformFriendlyName</param>
 /// <param name="transformGuidValueIn">the guid value </param>
 /// <param name="mftCategoryGuidNamePairIn">the category guid name pair</param>
 /// <history>
 ///    01 Nov 18  Cynic - Started
 /// </history>
 public TantaMFTCapabilityContainer(string transformFriendlyNameIn, Guid transformGuidValueIn, TantaGuidNamePair mftCategoryGuidNamePairIn)
 {
     TransformFriendlyName = transformFriendlyNameIn;
     TransformGuidValue    = transformGuidValueIn;
     if (mftCategoryGuidNamePairIn != null)
     {
         MFTCategoryFriendlyName = mftCategoryGuidNamePairIn.FriendlyName;
         MFTCategoryGuidValue    = mftCategoryGuidNamePairIn.GuidValue;
     }
 }