示例#1
0
        /// <summary>
        ///     Loads additional ScanMode objects from dlls in the scanmode plugin directory.
        /// </summary>
        /// <returns>A Collection of ScanMode objects.</returns>
        private static ScanModeCollection GatherScanModes()
        {
            var assemblies = new List<Assembly>();

            // this assembly
            assemblies.Add(Assembly.GetExecutingAssembly());

            // PaintDotNet.Effects.dll
            assemblies.Add(Assembly.GetAssembly(typeof(Scanmode)));

            // TARGETDIR\Effects\*.dll
            string homeDir = Info.GetApplicationDir();
            string effectsDir = Path.Combine(homeDir, InvariantStrings.EffectsSubDir);
            bool dirExists;

            try
            {
                dirExists = Directory.Exists(effectsDir);
            }
            catch
            {
                dirExists = false;
            }

            if (dirExists)
            {
                string fileSpec = "*" + InvariantStrings.DllExtension;
                string[] filePaths = Directory.GetFiles(effectsDir, fileSpec);

                foreach (string filePath in filePaths)
                {
                    Assembly pluginAssembly = null;

                    try
                    {
                        pluginAssembly = Assembly.LoadFrom(filePath);
                        assemblies.Add(pluginAssembly);
                    }
                    catch (Exception ex)
                    {
                        Tracing.Ping("Exception while loading " + filePath + ": " + ex);
                    }
                }
            }

            var ec = new ScanModeCollection(assemblies);
            return ec;
        }
示例#2
0
        /// <summary>
        /// The add scan modes to combo box.
        /// </summary>
        private void AddScanModesToComboBox()
        {
            if (this.m_scmcScanModes == null)
            {
                this.m_scmcScanModes = GatherScanModes();
            }

            ScanModeCollection _colScanModesCollection = this.m_scmcScanModes;
            Type[] effectTypes = _colScanModesCollection.Scanmodes;

            foreach (Type type in effectTypes)
            {
                try
                {
                    var _ScanModeAttributes =
                        type.GetCustomAttributes(typeof(ScanModeAttribute), true) as ScanModeAttribute[];
                    this.Items.Add(new ComboBoxItem<Type>(_ScanModeAttributes[0].Name, type));
                }
                catch
                {
                    // We don't want a DLL that can't be figured out to cause the app to crash
                }
            }

            this.SelectedIndex = 0;
        }