Exemplo n.º 1
0
    private void _BuildShellLists(out List <JumpItem> successList, out List <JumpList._RejectedJumpItemPair> rejectedList, out List <JumpList._ShellObjectPair> removedList)
    {
        List <List <JumpList._ShellObjectPair> > list = null;

        removedList = null;
        ICustomDestinationList customDestinationList = CLSID.CoCreateInstance <ICustomDestinationList>("77f10cf0-3db5-4966-b520-b7c54fd35ed6");

        try
        {
            string runtimeId = JumpList._RuntimeId;
            if (!string.IsNullOrEmpty(runtimeId))
            {
                customDestinationList.SetAppID(runtimeId);
            }
            Guid         guid = new Guid("92CA9DCD-5622-4bba-A805-5E9F541BD8C9");
            uint         num;
            IObjectArray shellObjects = (IObjectArray)customDestinationList.BeginList(out num, ref guid);
            removedList  = JumpList.GenerateJumpItems(shellObjects);
            successList  = new List <JumpItem>(this.JumpItems.Count);
            rejectedList = new List <JumpList._RejectedJumpItemPair>(this.JumpItems.Count);
            list         = new List <List <JumpList._ShellObjectPair> >
            {
                new List <JumpList._ShellObjectPair>()
            };
            foreach (JumpItem jumpItem in this.JumpItems)
            {
                if (jumpItem == null)
                {
                    rejectedList.Add(new JumpList._RejectedJumpItemPair
                    {
                        JumpItem = jumpItem,
                        Reason   = JumpItemRejectionReason.InvalidItem
                    });
                }
                else
                {
                    object obj = null;
                    try
                    {
                        obj = JumpList.GetShellObjectForJumpItem(jumpItem);
                        if (obj == null)
                        {
                            rejectedList.Add(new JumpList._RejectedJumpItemPair
                            {
                                Reason   = JumpItemRejectionReason.InvalidItem,
                                JumpItem = jumpItem
                            });
                        }
                        else if (JumpList.ListContainsShellObject(removedList, obj))
                        {
                            rejectedList.Add(new JumpList._RejectedJumpItemPair
                            {
                                Reason   = JumpItemRejectionReason.RemovedByUser,
                                JumpItem = jumpItem
                            });
                        }
                        else
                        {
                            JumpList._ShellObjectPair item = new JumpList._ShellObjectPair
                            {
                                JumpItem    = jumpItem,
                                ShellObject = obj
                            };
                            if (string.IsNullOrEmpty(jumpItem.CustomCategory))
                            {
                                list[0].Add(item);
                            }
                            else
                            {
                                bool flag = false;
                                foreach (List <JumpList._ShellObjectPair> list2 in list)
                                {
                                    if (list2.Count > 0 && list2[0].JumpItem.CustomCategory == jumpItem.CustomCategory)
                                    {
                                        list2.Add(item);
                                        flag = true;
                                        break;
                                    }
                                }
                                if (!flag)
                                {
                                    list.Add(new List <JumpList._ShellObjectPair>
                                    {
                                        item
                                    });
                                }
                            }
                            obj = null;
                        }
                    }
                    finally
                    {
                        Utility.SafeRelease <object>(ref obj);
                    }
                }
            }
            list.Reverse();
            if (this.ShowFrequentCategory)
            {
                customDestinationList.AppendKnownCategory(KDC.FREQUENT);
            }
            if (this.ShowRecentCategory)
            {
                customDestinationList.AppendKnownCategory(KDC.RECENT);
            }
            foreach (List <JumpList._ShellObjectPair> list3 in list)
            {
                if (list3.Count > 0)
                {
                    string customCategory = list3[0].JumpItem.CustomCategory;
                    JumpList.AddCategory(customDestinationList, customCategory, list3, successList, rejectedList);
                }
            }
            customDestinationList.CommitList();
            successList.Reverse();
        }
        finally
        {
            Utility.SafeRelease <ICustomDestinationList>(ref customDestinationList);
            if (list != null)
            {
                foreach (List <JumpList._ShellObjectPair> list4 in list)
                {
                    JumpList._ShellObjectPair.ReleaseShellObjects(list4);
                }
            }
            JumpList._ShellObjectPair.ReleaseShellObjects(removedList);
        }
    }