Ejemplo n.º 1
0
        private void RunRepeatFilter(ref PSFilterPdnConfigToken token, IWin32Window window)
        {
            try
            {
                using (LoadPsFilter lps = new LoadPsFilter(EnvironmentParameters, window.Handle, null))
                {
                    lps.SetAbortCallback(AbortCallback);
                    if (token.DescriptorRegistry != null)
                    {
                        lps.SetRegistryValues(token.DescriptorRegistry);
                    }

                    ParameterData parameterData;
                    if (token.FilterParameters.TryGetValue(token.FilterData, out parameterData))
                    {
                        lps.FilterParameters = parameterData;
                    }
                    lps.PseudoResources = token.PseudoResources;
                    lps.IsRepeatEffect  = true;

                    bool result = lps.RunPlugin(token.FilterData, false);

                    if (result)
                    {
                        token.Dest = lps.Dest.Clone();
                    }
                    else if (!string.IsNullOrEmpty(lps.ErrorMessage))
                    {
                        ShowErrorMessage(window, lps.ErrorMessage);
                    }
                }
            }
            catch (FileNotFoundException fnfex)
            {
                ShowErrorMessage(window, fnfex.Message);
            }
            catch (NullReferenceException nrex)
            {
                // The filter probably tried to access an unimplemented callback function without checking if it is valid.
                ShowErrorMessage(window, nrex.Message);
            }
            catch (Win32Exception w32ex)
            {
                ShowErrorMessage(window, w32ex.Message);
            }
            catch (System.Runtime.InteropServices.ExternalException eex)
            {
                ShowErrorMessage(window, eex.Message);
            }
            finally
            {
                filterDone.Set();
            }
        }
Ejemplo n.º 2
0
        static void RunFilter()
        {
            PluginData           pdata    = pipeClient.GetPluginData();
            PSFilterShimSettings settings = pipeClient.GetShimSettings();

            Region selectionRegion = null;

            if (!string.IsNullOrEmpty(settings.RegionDataPath))
            {
                RegionDataWrapper wrapper = DataContractSerializerUtil.Deserialize <RegionDataWrapper>(settings.RegionDataPath);

                using (Region temp = new Region())
                {
                    RegionData rgnData = temp.GetRegionData();
                    rgnData.Data = wrapper.GetData();

                    selectionRegion = new Region(rgnData);
                }
            }
            try
            {
                ParameterData filterParameters = null;
                try
                {
                    filterParameters = DataContractSerializerUtil.Deserialize <ParameterData>(settings.ParameterDataPath);
                }
                catch (FileNotFoundException)
                {
                }

                PseudoResourceCollection pseudoResources = null;
                try
                {
                    pseudoResources = DataContractSerializerUtil.Deserialize <PseudoResourceCollection>(settings.PseudoResourcePath);
                }
                catch (FileNotFoundException)
                {
                }

                DescriptorRegistryValues registryValues = null;
                try
                {
                    registryValues = DataContractSerializerUtil.Deserialize <DescriptorRegistryValues>(settings.DescriptorRegistryPath);
                }
                catch (FileNotFoundException)
                {
                }

                using (LoadPsFilter lps = new LoadPsFilter(settings, selectionRegion))
                {
                    lps.SetAbortCallback(pipeClient.AbortFilter);

                    if (!settings.RepeatEffect)
                    {
                        // As Paint.NET does not currently allow custom progress reporting only set this callback for the effect dialog.
                        lps.SetProgressCallback(pipeClient.UpdateFilterProgress);
                    }

                    if (filterParameters != null)
                    {
                        // Ignore the filters that only use the data handle, e.g. Filter Factory.
                        byte[] parameterData = filterParameters.GlobalParameters.GetParameterDataBytes();

                        if (parameterData != null || filterParameters.AETEDictionary != null)
                        {
                            lps.FilterParameters = filterParameters;
                            lps.IsRepeatEffect   = settings.RepeatEffect;
                        }
                    }

                    if (pseudoResources != null)
                    {
                        lps.PseudoResources = pseudoResources;
                    }

                    if (registryValues != null)
                    {
                        lps.SetRegistryValues(registryValues);
                    }

                    bool result = lps.RunPlugin(pdata, settings.ShowAboutDialog);

                    if (result)
                    {
                        if (!settings.ShowAboutDialog)
                        {
                            PSFilterShimImage.Save(settings.DestinationImagePath, lps.Dest);

                            if (!lps.IsRepeatEffect)
                            {
                                DataContractSerializerUtil.Serialize(settings.ParameterDataPath, lps.FilterParameters);
                                DataContractSerializerUtil.Serialize(settings.PseudoResourcePath, lps.PseudoResources);

                                registryValues = lps.GetRegistryValues();
                                if (registryValues != null)
                                {
                                    DataContractSerializerUtil.Serialize(settings.DescriptorRegistryPath, registryValues);
                                }
                            }
                        }
                    }
                    else
                    {
                        pipeClient.SetProxyErrorMessage(lps.ErrorMessage);
                    }
                }
            }
            catch (BadImageFormatException ex)
            {
                pipeClient.SetProxyErrorMessage(ex.Message);
            }
            catch (EntryPointNotFoundException epnf)
            {
                pipeClient.SetProxyErrorMessage(epnf.Message);
            }
            catch (FileNotFoundException fx)
            {
                pipeClient.SetProxyErrorMessage(fx.Message);
            }
            catch (NullReferenceException ex)
            {
#if DEBUG
                pipeClient.SetProxyErrorMessage(ex.Message + Environment.NewLine + ex.StackTrace);
#else
                pipeClient.SetProxyErrorMessage(ex.Message);
#endif
            }
            catch (Win32Exception ex)
            {
                pipeClient.SetProxyErrorMessage(ex.Message);
            }
            finally
            {
                if (selectionRegion != null)
                {
                    selectionRegion.Dispose();
                    selectionRegion = null;
                }
            }
        }