Exemplo n.º 1
0
 /// <summary>
 ///     Extracts a large or small icon resource under the specified index, from the
 ///     'imageres.dll' under specified location, and returns its <see cref="Icon"/>
 ///     instance.
 /// </summary>
 /// <param name="index">
 ///     The index of the icon to extract.
 /// </param>
 /// <param name="large">
 ///     <see langword="true"/> to return the large image; otherwise,
 ///     <see langword="false"/>.
 /// </param>
 /// <param name="location">
 ///     The directory where the 'imageres.dll' file is located.
 /// </param>
 public static Icon GetSystemIcon(ImageResourceSymbol index, bool large = false, string location = "%system%")
 {
     try
     {
         var path = PathEx.Combine(location);
         if (string.IsNullOrWhiteSpace(path))
         {
             throw new ArgumentNullException(nameof(location));
         }
         if (PathEx.IsDir(path))
         {
             path = Path.Combine(path, "imageres.dll");
         }
         if (!File.Exists(path))
         {
             path = PathEx.Combine("%system%\\imageres.dll");
         }
         return(GetIconFromFile(path, GetImageResourceValue(index), large));
     }
     catch (Exception ex) when(ex.IsCaught())
     {
         if (Log.DebugMode > 1)
         {
             Log.Write(ex);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        internal static Image GetSystemImage(ImageResourceSymbol index, bool large = false)
        {
            Image image;

            if (Images.Any())
            {
                image = Images.FirstOrDefault(x => x.Item1.Equals(index) && x.Item2.Equals(large))?.Item3;
                if (image != default)
                {
                    goto Return;
                }
            }
            image = GetSystemIcon(index, large)?.ToBitmap();
            if (image == default)
            {
                goto Return;
            }
            var tuple = new Tuple <ImageResourceSymbol, bool, Image>(index, large, image);

            Images.Add(tuple);
Return:
            return(image);
        }
Exemplo n.º 3
0
        internal static Icon GetSystemIcon(ImageResourceSymbol index, bool large = false)
        {
            Icon icon;

            if (Icons.Any())
            {
                icon = Icons.FirstOrDefault(x => x.Item1.Equals(index) && x.Item2.Equals(large))?.Item3;
                if (icon != default)
                {
                    goto Return;
                }
            }
            icon = ResourcesEx.GetSystemIcon(index, large);
            if (icon == default)
            {
                goto Return;
            }
            var tuple = new Tuple <ImageResourceSymbol, bool, Icon>(index, large, icon);

            Icons.Add(tuple);
Return:
            return(icon);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Retrieves a backward-compatible integer value of the specified
        ///     <see cref="ImageResourceSymbol"/> value, which depends on the file version
        ///     of the 'imageres.dll' file under the specified location.
        /// </summary>
        /// <param name="value">
        ///     The <see cref="ImageResourceSymbol"/> value.
        /// </param>
        /// <param name="location">
        ///     The directory where the 'imageres.dll' file is located.
        /// </param>
        public static int GetImageResourceValue(ImageResourceSymbol value, string location = "%system%")
        {
            var path = PathEx.Combine(location);

            if (!string.IsNullOrWhiteSpace(path) && PathEx.IsDir(path))
            {
                path = Path.Combine(path, "imageres.dll");
            }
            if (!path.EndsWithEx("imageres.dll") || !File.Exists(path))
            {
                path = PathEx.Combine("%system%\\imageres.dll");
            }
            var version = FileEx.GetFileVersion(path);

            // Windows 10
            if (version.Major >= 10)
            {
                return((int)value);
            }

            // Windows 7 + 8
            var index = (int)value;

            if (index < 187)
            {
                return(index);
            }
            if (index.IsBetween(187, 215))
            {
                return(--index);
            }
            if (index.IsBetween(233, version.Minor < 2 ? 235 : 322))
            {
                return(index - (index < 257 ? 17 : 16));
            }
            return(-1);
        }
Exemplo n.º 5
0
 /// <summary>
 ///     Extracts a small icon resource under the specified index, from the
 ///     'imageres.dll' under specified location, and returns its <see cref="Icon"/>
 ///     instance.
 /// </summary>
 /// <param name="index">
 ///     The index of the icon to extract.
 /// </param>
 /// <param name="location">
 ///     The directory where the 'imageres.dll' file is located.
 /// </param>
 public static Icon GetSystemIcon(ImageResourceSymbol index, string location) =>
 GetSystemIcon(index, false, location);