Beispiel #1
0
        public void ReloadFilters()
        {
            log("reload filters..");
            IEnumFilters ef;

            ClearFiltersSelection();
            ClearConnections();

            filter_positions.Clear();
            foreach (Filter f in filters)
            {
                filter_positions.Add(f.Name, f.Coords);
            }
            filters.Clear();
            log("reload_filters 1");
            try
            {
                int hr = graphBuilder.EnumFilters(out ef);
                DsError.ThrowExceptionForHR(hr);
                IBaseFilter[] fs      = new IBaseFilter[1];
                IntPtr        fetched = Marshal.AllocHGlobal(4);
                while ((hr = ef.Next(1, fs, fetched)) == 0)
                {
                    log("reload_filters 2");
                    FilterInfo fi;
                    fs[0].QueryFilterInfo(out fi);
                    log("reload_filters: " + fi.achName);
                    Filter ff = FindFilterByName(fi.achName);
                    if (ff == null) //not found
                    {
                        ff = new Filter(fs[0]);
                        AddFilterHere(ff, false, null);
                        history.AddFilterIfNew(ff.filterProps, ff.Name, ff.srcFileName, ff.dstFileName, ff);
                    }
                    else
                    {
                        ff.ReloadPins();
                    }
                    log("reload_filters 3");
                    foreach (Pin pin in ff.Pins)
                    {
                        log("reload_filters 4: " + pin.Name);
                        IPin ip = pin.IPin, connected_ipin;
                        hr = ip.ConnectedTo(out connected_ipin);
                        if (hr != 0)
                        {
                            continue;
                        }
                        PinInfo cpi;
                        connected_ipin.QueryPinInfo(out cpi);
                        FilterInfo cfi;
                        cpi.filter.QueryFilterInfo(out cfi);
                        Filter connected_filter = FindFilterByName(cfi.achName);
                        if (connected_filter != null)
                        {
                            Pin cp = connected_filter.FindPinByName(connected_filter.Name + "." + cpi.name);
                            if (cp != null)
                            {
                                string con_uniqname = (pin.Direction == PinDirection.Input) ?
                                                      cp.UniqName + "-" + pin.UniqName : pin.UniqName + "-" + cp.UniqName;
                                PinConnection con = FindConnectionByName(con_uniqname);
                                if (con == null)
                                {
                                    if (pin.Direction == PinDirection.Input)
                                    {
                                        Connect(cp, pin);
                                    }
                                    else
                                    {
                                        Connect(pin, cp);
                                    }
                                }
                            }
                        }
                        DsUtils.FreePinInfo(cpi);
                    }
                }
                Marshal.FreeHGlobal(fetched);
                if (hr < 0)
                {
                    DsError.ThrowExceptionForHR(hr);
                }
            }
            catch (COMException e)
            {
                ShowCOMException(e, "Error while enumerating filters in the graph");
                return;
            }

            /*catch (Exception e)
             * {
             *  MessageBox.Show(e.Message, "Error while enumerating filters in the graph");
             *  return;
             * }*/
            log("reload_filters: almost done");
            history.CommitAdded();
            log("reload_filters: done");
        }