Beispiel #1
0
        /// <summary>
        /// Function to load our useless image codec plug-in.
        /// </summary>
        /// <returns>TRUE if successful, FALSE if not.</returns>
        private bool LoadCodec()
        {
            // Load our plug-in.
            string plugInPath = Gorgon.ApplicationDirectory + "TVImageCodec.dll";

            if (!File.Exists(plugInPath))
            {
                return(false);
            }

            if (!Gorgon.PlugIns.IsPlugInAssembly(plugInPath))
            {
                return(false);
            }

            Gorgon.PlugIns.LoadPlugInAssembly(plugInPath);

            // Get the plug-in object.
            var plugIn = Gorgon.PlugIns["GorgonLibrary.Graphics.Example.TvImageCodecPlugIn"] as GorgonCodecPlugIn;

            if (plugIn == null)
            {
                return(false);
            }

            // Create the codec.
            _customCodec = plugIn.CreateCodec();

            return(_customCodec != null);
        }
Beispiel #2
0
        /// <summary>
        /// Function to load an external codec assembly.
        /// </summary>
        /// <param name="assemblyPath">Path to the assembly.</param>
        private static void LoadExternalCodec(string assemblyPath)
        {
            if (string.IsNullOrWhiteSpace(assemblyPath))
            {
                return;
            }

            if (!File.Exists(assemblyPath))
            {
                EditorLogging.Print("The codec plug-in '{0}' was not found.", assemblyPath);
                return;
            }

            // Check to see if the assembly is an image codec plug-in.
            if (!Gorgon.PlugIns.IsPlugInAssembly(assemblyPath))
            {
                EditorLogging.Print("The codec plug-in '{0}' is not a valid .NET assembly.", assemblyPath);
                return;
            }

            if (Gorgon.PlugIns.EnumeratePlugIns(assemblyPath).Count == 0)
            {
                EditorLogging.Print("The codec plug-in '{0}' does not contain any image codecs.", assemblyPath);
                return;
            }

            // Load the assembly.
            Gorgon.PlugIns.LoadPlugInAssembly(assemblyPath);

            // Get all the plug-ins that support image codecs.
            IEnumerable <GorgonCodecPlugIn> codecPlugIns = from plugIn in Gorgon.PlugIns
                                                           let codecPlugIn = plugIn as GorgonCodecPlugIn
                                                                             where codecPlugIn != null
                                                                             select codecPlugIn;

            // Enumerate our codecs.
            foreach (GorgonCodecPlugIn plugIn in codecPlugIns)
            {
                GorgonImageCodec codec = plugIn.CreateCodec();

                if (codec == null)
                {
                    continue;
                }

                // Retrieve extensions.
                var description = new StringBuilder(256);
                description.AppendFormat("{0} (*.{1})", codec.CodecDescription, string.Join("; *.", codec.CodecCommonExtensions));
                foreach (string extension in codec.CodecCommonExtensions)
                {
                    _codecs[new GorgonFileExtension(extension, description.ToString())] = codec;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Function to populate file editor attributes for imported content.
        /// </summary>
        /// <param name="stream">Stream to the file.</param>
        /// <param name="attributes">Attributes to populate.</param>
        public override void GetEditorFileAttributes(Stream stream, IDictionary <string, string> attributes)
        {
            GorgonImageCodec codec = CodecDropDownList.FirstOrDefault(item => item.IsReadable(stream));

            if (codec == null)
            {
                return;
            }

            attributes["Codec"] = codec.GetType().FullName;
            attributes["Type"]  = Resources.GORIMG_CONTENT_TYPE;
        }
Beispiel #4
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param>
        /// <param name="value">The <see cref="T:System.Object" /> to convert.</param>
        /// <returns>
        /// An <see cref="T:System.Object" /> that represents the converted value.
        /// </returns>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if ((value == null) ||
                (value.GetType() != typeof(string)))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            string           formatString = value.ToString();
            var              content      = (GorgonImageContent)((ContentTypeDescriptor)context.Instance).Content;
            GorgonImageCodec codec        =
                ((GorgonImageEditorPlugIn)content.PlugIn).CodecDropDownList.FirstOrDefault(item =>
                                                                                           string.Equals(item.Codec + " - " + item.CodecDescription,
                                                                                                         formatString,
                                                                                                         StringComparison.OrdinalIgnoreCase));

            if (codec == null)
            {
                throw new InvalidCastException(Resources.GORIMG_TEXT_INVALID_CODEC);
            }

            return(codec);
        }