예제 #1
0
        /// <summary>Creates a ResourceData instance from a stream containing data convertible into a resource. For instance a stream containing a  *.bmp file's content can be converted into a BITMAP resource.</summary>
        public static ResourceData FromFile(Stream stream, String extension, ResourceSource source)
        {
            // 'intelligent reading' of the file itself is too resource intensive. Better just to trust the extension.

            extension = extension.ToLowerInvariant();
            if (extension.StartsWith("."))
            {
                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 Exception("Unable to locate factory for resource data.");
                }

                data = factories[i++].FromFile(stream, extension, source);
            }

            return(data);

            throw new NotImplementedException();
        }
예제 #2
0
        /// <summary>Constructs a Win32 resource type based on a Win32 resource type LPCTSTR.</summary>
        internal ResourceType(IntPtr typePointer, ResourceSource source)
        {
            Identifier = new ResourceTypeIdentifier(typePointer);
            Source     = source;

            _names = new List <ResourceName>();
            Names  = new ResourceNameCollection(_names);                 // ResourceNameCollection is a read-only decorator of any List
        }
예제 #3
0
        /// <summary>Creates a ResourceData instance from a file containing data convertible into a resource. For instance a *.bmp can be converted into a BITMAP resource.</summary>
        public static ResourceData FromFile(String filename, ResourceSource source)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("The file to load the resource data from was not found", filename);
            }

            using (Stream stream = File.OpenRead(filename)) {
                return(FromFile(stream, Path.GetExtension(filename), source));
            }
        }