Beispiel #1
0
        private static Icon ExtractIcon(string fileName)
        {
            // Are we looking at an icon itself?
            if (TryExtractIconFromIco(fileName, out Icon icon))
            {
                return(icon);
            }

            // Otherwise, fall back to the first icon in the file
            return(IconExtractor.ExtractIconByIndex(fileName, 0));
        }
Beispiel #2
0
        public static Icon ExtractIconByIndex(string fileName, int index)
        {
            using (IconExtractor extractor = IconExtractor.Open(fileName))
            {
                if (index < 0)
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                if (index >= extractor.IconNames.Count)
                {
                    return(null);
                }

                return(extractor.GetIconByIndex(index));
            }
        }
Beispiel #3
0
        public static Icon ExtractIconByIdOrIndex(string fileNameAndIdOrIndex)
        {
            string[] parts = fileNameAndIdOrIndex.Split(new char[] { ',' }, 2);

            parts[0] = Environment.ExpandEnvironmentVariables(parts[0]);
            if (parts.Length == 1)
            {
                return(ExtractIcon(parts[0]));
            }

            if (!int.TryParse(parts[1], out int index))
            {
                throw new FormatException();
            }

            if (index >= 0)
            {
                return(IconExtractor.ExtractIconByIndex(parts[0], index));
            }

            return(IconExtractor.ExtractIconById(parts[0], Math.Abs(index)));
        }
Beispiel #4
0
        public static Icon ExtractIconById(string fileName, int id)
        {
            using (IconExtractor extractor = IconExtractor.Open(fileName))
            {
                if (id < 0)
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                int count = extractor.IconNames.Count;
                for (int i = 0; i < count; i++)
                {
                    ResourceName name = extractor.IconNames[i];
                    if (name.Id != null && name.Id == id)
                    {
                        return(extractor.GetIconByIndex(i));
                    }
                }
            }

            return(null);
        }