Example #1
0
        /// <summary>Creates a ResourceData instance from a stream containing data convertible into a resource ready to replace the specified ResourceLang (but doesn't actually replace it). For instance a stream containing a  *.bmp file's content can be converted into a BITMAP resource.</summary>
        public static ResourceData FromFileToUpdate(Stream stream, String extension, ResourceLang lang)
        {
            // 'intelligent reading' of the file itself is too resource intensive. Better just to trust the extension.

            extension = extension.ToUpperInvariant();
            if (extension.StartsWith(".", StringComparison.OrdinalIgnoreCase))
            {
                extension = extension.Substring(1);
            }

            ResourceDataFactory[] factories = ResourceDataFactory.GetFactoriesForExtension(extension);

            // try the factories in order of compatibility.

            Int32        i    = 0;
            ResourceData data = null;

            while (data == null)
            {
                if (i >= factories.Length)
                {
                    throw new ResourceDataException("Unable to locate factory for resource data.");
                }

                data = factories[i++].FromFileToUpdate(stream, extension, lang);
            }

            return(data);
        }
Example #2
0
        public static ResourceData FromResource(ResourceLang lang, Byte[] rawData)
        {
            ResourceTypeIdentifier typeId = lang.Name.Type.Identifier;

            // get a list of suitable factories

            ResourceDataFactory[] factories = ResourceDataFactory.GetFactoriesForType(typeId);

            // try the factories in order of compatibility.

            Int32        i    = 0;
            ResourceData data = null;

            while (data == null)
            {
                if (i >= factories.Length)
                {
                    throw new AnolisException("Unable to locate factory for resource data.");
                }

                try {
                    data = factories[i++].FromResource(lang, rawData);
                } catch (ResourceDataException) {
                }
            }

            return(data);
        }
Example #3
0
        private static void LoadFactoriesFromAssembly(List <ResourceDataFactory> list, String assemblyFilename)
        {
            if (!File.Exists(assemblyFilename))
            {
                return;
            }

            Assembly assembly;

            try {
                assembly = Assembly.LoadFile(assemblyFilename);
            } catch (FileLoadException) {
                return;
            } catch (BadImageFormatException) {
                return;
            }

            Type[] types = assembly.GetTypes();

            foreach (Type t in types)
            {
                if (t.IsSubclassOf(_type))
                {
                    ResourceDataFactory f = Activator.CreateInstance(t) as ResourceDataFactory;
                    list.Add(f);
                }
            }
        }
Example #4
0
        private static IconImageResourceDataFactory GetIconImageFactory()
        {
            IconImageResourceDataFactory factory = null;

            ResourceTypeIdentifier typeId = new ResourceTypeIdentifier(new IntPtr((int)Win32ResourceType.IconImage));

            ResourceDataFactory[] factories = ResourceDataFactory.GetFactoriesForType(typeId);

            foreach (ResourceDataFactory f in factories)
            {
                if (f is IconImageResourceDataFactory)
                {
                    factory = f as IconImageResourceDataFactory;
                    break;
                }
            }

            if (factory == null)
            {
                throw ME(new ApplicationException("Unable to locate IconImageResourceDataFactory"));
            }

            return(factory);
        }
Example #5
0
 protected static Boolean IsExtension(String extension, params String[] extensions)
 {
     return(ResourceDataFactory.IsExtension(extension, extensions));
 }
Example #6
0
 protected static bool IsExtension(string extension, params string[] extensions)
 {
     return(ResourceDataFactory.IsExtension(extension, extensions));
 }