コード例 #1
0
ファイル: Program.cs プロジェクト: Krutonium/IronShell
        private BitmapSource GetIcon(IconReader.IconSize size)
        {
            var path = Path;

            if (Path.ToLower().EndsWith(".lnk"))
            {
                var shell = new WshShell();
                var link  = (IWshShortcut)shell.CreateShortcut(Path);
                if (link.TargetPath != string.Empty)
                {
                    var info = new FileInfo(link.TargetPath);
                    if (info.Exists)
                    {
                        path = link.TargetPath;
                    }
                }
            }

            var ic   = IconReader.GetFileIcon(path, size, false);
            var icon = Imaging.CreateBitmapSourceFromHBitmap((ic.ToBitmap()).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            icon.Freeze();
            ic.Dispose();
            return(icon);
        }
コード例 #2
0
        /// <summary>
        /// Util function to Add Folders icons and information to list
        /// </summary>
        /// <param name="iconSize">The icon size, support multi size flags</param>
        public void AddFolder(IconReader.IconSize iconSize)
        {
            IconProperties iconPropOpen   = new IconProperties();
            IconProperties iconPropClosed = new IconProperties();

            if ((iconSize & IconReader.IconSize.Small) == IconReader.IconSize.Small)
            {
                Add(FolderOpen, IconReader.IconSize.Small, iconPropOpen, IconReader.FolderType.Open);
                Add(FolderClosed, IconReader.IconSize.Small, iconPropClosed, IconReader.FolderType.Closed);
            }
            if ((iconSize & IconReader.IconSize.Large) == IconReader.IconSize.Large)
            {
                Add(FolderOpen, IconReader.IconSize.Large, iconPropOpen, IconReader.FolderType.Open);
                Add(FolderClosed, IconReader.IconSize.Large, iconPropClosed, IconReader.FolderType.Closed);
            }
            if ((iconSize & IconReader.IconSize.ExtraLarge) == IconReader.IconSize.ExtraLarge)
            {
                Add(FolderOpen, IconReader.IconSize.ExtraLarge, iconPropOpen, IconReader.FolderType.Open);
                Add(FolderClosed, IconReader.IconSize.ExtraLarge, iconPropClosed, IconReader.FolderType.Closed);
            }
            if ((iconSize & IconReader.IconSize.Jumbo) == IconReader.IconSize.Jumbo)
            {
                Add(FolderOpen, IconReader.IconSize.Jumbo, iconPropOpen, IconReader.FolderType.Open);
                Add(FolderClosed, IconReader.IconSize.Jumbo, iconPropClosed, IconReader.FolderType.Closed);
            }
            IconList.Add(FolderOpen, iconPropOpen);
            IconList.Add(FolderClosed, iconPropClosed);
        }
コード例 #3
0
        private bool manageBothSizes__ = false;                              //flag, used to determine whether to create two ImageLists.


        public FilesIconListManager(ImageList _imageList, IconReader.IconSize _iconSize)
        {
            // Initialise the members of the class that will hold the image list we're
            // targeting, as well as the icon size (32 or 16)
            imageLists__.Add(_imageList);
            iconSize__ = _iconSize;
        }
コード例 #4
0
ファイル: IconListManager.cs プロジェクト: Yonom/EEFileDrop
        private readonly ArrayList _imageLists = new ArrayList(); //will hold ImageList objects

        /// <summary>
        ///     Creates an instance of <c>IconListManager</c> that will add icons to a single <c>ImageList</c> using the
        ///     specified <c>IconSize</c>.
        /// </summary>
        /// <param name="imageList"><c>ImageList</c> to add icons to.</param>
        /// <param name="iconSize">Size to use (either 32 or 16 pixels).</param>
        public IconListManager(ImageList imageList, IconReader.IconSize iconSize)
        {
            // Initialise the members of the class that will hold the image list we're
            // targeting, as well as the icon size (32 or 16)
            this._imageLists.Add(imageList);
            this._iconSize = iconSize;
        }
コード例 #5
0
 /// <summary>
 /// Util function to Add Computer drivers icons and information to list
 /// </summary>
 /// <param name="iconSize">The icon size, support multi size flags</param>
 public void AddComputerDrives(IconReader.IconSize iconSize)
 {
     foreach (string drive in Directory.GetLogicalDrives())
     {
         AddEx(drive, iconSize);
     }
 }
コード例 #6
0
        private ArrayList _imageLists = new ArrayList(); //will hold ImageList objects

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Creates an instance of <c>IconListManager</c> that will add icons to a single <c>ImageList</c> using the
        /// specified <c>IconSize</c>.
        /// </summary>
        /// <param name="imageList"><c>ImageList</c> to add icons to.</param>
        /// <param name="iconSize">Size to use (either 32 or 16 pixels).</param>
        public IconListManager(ImageList imageList, IconReader.IconSize iconSize)
        {
            // Initialise the members of the class that will hold the image list we're
            // targeting, as well as the icon size (32 or 16)
            _imageLists.Add(imageList);
            _iconSize = iconSize;
        }
コード例 #7
0
        private bool manageBothSizes__ = false; //flag, used to determine whether to create two ImageLists.

        #endregion Fields

        #region Constructors

        public FilesIconListManager(ImageList _imageList, IconReader.IconSize _iconSize )
        {
            // Initialise the members of the class that will hold the image list we're
            // targeting, as well as the icon size (32 or 16)
            imageLists__.Add( _imageList );
            iconSize__ = _iconSize;
        }
コード例 #8
0
        bool ManageBothSizes = false;                                       //flag, used to determine whether to create two ImageLists.

        /// <summary>
        /// Creates an instance of <c>IconListManager</c> that will add icons to a single <c>ImageList</c> using the
        /// specified <c>IconSize</c>.
        /// </summary>
        /// <param name="imageList"><c>ImageList</c> to add icons to.</param>
        /// <param name="iconSize">Size to use (either 32 or 16 pixels).</param>
        public IconListManager(System.Windows.Forms.ImageList imageList, IconReader.IconSize iconSize)
        {
            // Initialise the members of the class that will hold the image list we're
            // targeting, as well as the icon size (32 or 16)
            _imageLists.Add(imageList);
            _iconSize = iconSize;
        }
コード例 #9
0
 /// <summary>
 /// Check if class contain a icon
 /// And if that icon is not null
 /// </summary>
 /// <param name="size">Icon Size to check</param>
 public bool IsValidEx(IconReader.IconSize size)
 {
     if (!Icons.ContainsKey(size))
     {
         return(false);
     }
     return(Icons[size] != null);
 }
コード例 #10
0
            /// <summary>
            /// Remove a especified icon size from class,
            /// Supports multi sizes flags
            /// </summary>
            /// <param name="iconSize">Icon Size to remove, support multi size flags</param>
            /// <returns>A dictionary with removed icons (size and thier index on ListImage)</returns>
            public Dictionary <IconReader.IconSize, int> Remove(IconReader.IconSize iconSize)
            {
                Dictionary <IconReader.IconSize, int> removedIcons = new Dictionary <IconReader.IconSize, int>();

                if ((iconSize & IconReader.IconSize.Small) == IconReader.IconSize.Small)
                {
                    if (Icons.ContainsKey(IconReader.IconSize.Small))
                    {
                        if (IconsIndex[IconReader.IconSize.Small] >= 0)
                        {
                            removedIcons.Add(IconReader.IconSize.Small, IconsIndex[IconReader.IconSize.Small]);
                        }
                        Icons.Remove(IconReader.IconSize.Small);
                        IconsInfo.Remove(IconReader.IconSize.Small);
                        IconsIndex.Remove(IconReader.IconSize.Small);
                    }
                }
                if ((iconSize & IconReader.IconSize.Large) == IconReader.IconSize.Large)
                {
                    if (Icons.ContainsKey(IconReader.IconSize.Large))
                    {
                        if (IconsIndex[IconReader.IconSize.Large] >= 0)
                        {
                            removedIcons.Add(IconReader.IconSize.Large, IconsIndex[IconReader.IconSize.Large]);
                        }
                        Icons.Remove(IconReader.IconSize.Large);
                        IconsInfo.Remove(IconReader.IconSize.Large);
                        IconsIndex.Remove(IconReader.IconSize.Large);
                    }
                }
                if ((iconSize & IconReader.IconSize.ExtraLarge) == IconReader.IconSize.ExtraLarge)
                {
                    if (Icons.ContainsKey(IconReader.IconSize.ExtraLarge))
                    {
                        if (IconsIndex[IconReader.IconSize.ExtraLarge] >= 0)
                        {
                            removedIcons.Add(IconReader.IconSize.ExtraLarge, IconsIndex[IconReader.IconSize.ExtraLarge]);
                        }
                        Icons.Remove(IconReader.IconSize.ExtraLarge);
                        IconsInfo.Remove(IconReader.IconSize.ExtraLarge);
                        IconsIndex.Remove(IconReader.IconSize.ExtraLarge);
                    }
                }
                if ((iconSize & IconReader.IconSize.Jumbo) == IconReader.IconSize.Jumbo)
                {
                    if (Icons.ContainsKey(IconReader.IconSize.Jumbo))
                    {
                        if (IconsIndex[IconReader.IconSize.Jumbo] >= 0)
                        {
                            removedIcons.Add(IconReader.IconSize.Jumbo, IconsIndex[IconReader.IconSize.Jumbo]);
                        }
                        Icons.Remove(IconReader.IconSize.Jumbo);
                        IconsInfo.Remove(IconReader.IconSize.Jumbo);
                        IconsIndex.Remove(IconReader.IconSize.Jumbo);
                    }
                }
                return(removedIcons);
            }
コード例 #11
0
ファイル: Folder.cs プロジェクト: Krutonium/IronShell
        private BitmapSource GetIcon(IconReader.IconSize size)
        {
            var ic   = IconReader.GetFolderIcon(Path, size, IconReader.FolderType.Open);
            var icon = Imaging.CreateBitmapSourceFromHBitmap((ic.ToBitmap()).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            icon.Freeze();
            ic.Dispose();
            return(icon);
        }
コード例 #12
0
 /// <summary>
 /// Retrive the icon index from the ImageList
 /// </summary>
 /// <param name="extension">The extension,
 /// such as ex: ".mp3".</param>
 /// <param name="iconSize">The icon size.</param>
 /// <returns>Returns -1 if extension not exist on list, otherwise returns >= 0</returns>
 public int GetIconIndex(string extension, IconReader.IconSize iconSize, bool check)
 {
     if (check)
     {
         if (!IsValid(extension))
         {
             return(-1);
         }
     }
     return(IconList[extension].IconsIndex[iconSize]);
 }
コード例 #13
0
        /// <summary>
        /// Internal add a icon to class
        /// FOLDERS ONLY!!!!!!
        /// </summary>
        /// <param name="path">Icon Path on filesystem, or extension</param>
        /// <param name="iconSize">Icon Size</param>
        /// <param name="iconProp">Icon Properties to assign to list</param>
        /// <param name="folder">Folder type (open or closed)</param>
        private void Add(string path, IconReader.IconSize iconSize, IconProperties iconProp, IconReader.FolderType folder)
        {
            iconProp.IconsIndex[iconSize] = -1;
            iconProp.IconsInfo[iconSize]  = new Shell32.SHFILEINFO();
            Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO();
            iconProp.Icons[iconSize] = IconReader.GetFolderIcon(iconSize, folder, ref shfi);

            iconProp.IconsInfo[iconSize] = shfi;
            if (IImageList[iconSize] != null)
            {
                iconProp.IconsIndex[iconSize] = IImageList[iconSize].Images.Count;
                IImageList[iconSize].Images.Add(path, iconProp.Icons[iconSize]);
            }
        }
コード例 #14
0
        private MemoryStream GetFileIcon(string name, IconReader.IconSize size)
        {
            Icon icon = IconReader.GetFileIcon(name, size, false);

            using (icon)
            {
                using (var bmp = icon.ToBitmap())
                {
                    MemoryStream ms = new MemoryStream();
                    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    ms.Seek(0, SeekOrigin.Begin);
                    return(ms);
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// Remove icons information for a especified icon size
        /// </summary>
        /// <param name="path">Icon path or extension</param>
        /// <param name="iconSize">The icon size, support multi size flags</param>
        /// <param name="removeIconFromList">Did you want remove icon from ImageList? true or false</param>
        /// <example>Remove(".txt", IconReader.IconSize.Jumbo | IconReader.IconSize.ExtraLarge, true);</example>
        public bool Remove(string path, IconReader.IconSize iconSize, bool removeIconFromList)
        {
            if (!IsValid(path))
            {
                return(false);
            }
            Dictionary <IconReader.IconSize, int> removedIcons = IconList[path].Remove(iconSize);

            if (removeIconFromList)
            {
                foreach (KeyValuePair <IconReader.IconSize, int> item in removedIcons)
                {
                    IImageList[item.Key].Images.RemoveAt(item.Value);
                }
            }
            if (!IconList[path].IsValid())
            {
                IconList[path].Dispose();
                IconList.Remove(path);
            }
            return(true);
        }
コード例 #16
0
        /// <summary>
        /// Add an extension to List
        /// </summary>
        /// <param name="path">The extension,
        /// such as ex: ".mp3" or full path "C:\\mymusic.mp3".</param>
        /// <param name="iconSize">The icon size, support multi size flags</param>
        /// <returns>Returns Icon and thier information.</returns>
        public IconProperties AddEx(string path, IconReader.IconSize iconSize)
        {
            IconProperties iconProp = IsValidEx(path);

            if ((iconSize & IconReader.IconSize.Small) == IconReader.IconSize.Small)
            {
                if (!iconProp.IsValidEx(IconReader.IconSize.Small))
                {
                    Add(path, IconReader.IconSize.Small, iconProp);
                }
            }
            if ((iconSize & IconReader.IconSize.Large) == IconReader.IconSize.Large)
            {
                if (!iconProp.IsValidEx(IconReader.IconSize.Large))
                {
                    Add(path, IconReader.IconSize.Large, iconProp);
                }
            }
            if ((iconSize & IconReader.IconSize.ExtraLarge) == IconReader.IconSize.ExtraLarge)
            {
                if (!iconProp.IsValidEx(IconReader.IconSize.ExtraLarge))
                {
                    Add(path, IconReader.IconSize.ExtraLarge, iconProp);
                }
            }
            if ((iconSize & IconReader.IconSize.Jumbo) == IconReader.IconSize.Jumbo)
            {
                if (!iconProp.IsValidEx(IconReader.IconSize.Jumbo))
                {
                    Add(path, IconReader.IconSize.Jumbo, iconProp);
                }
            }
            if (!IsValid(path))
            {
                IconList.Add(path, iconProp);
            }
            return(iconProp);
        }
コード例 #17
0
 /// <summary>
 /// Retrive the icon index from the ImageList
 /// </summary>
 /// <param name="extension">The extension,
 /// such as ex: ".mp3".</param>
 /// <param name="iconSize">The icon size.</param>
 /// <returns>Returns icon index from ImageList, if not exist will trown an exception</returns>
 public int GetIconIndex(string extension, IconReader.IconSize iconSize)
 {
     return(GetIconIndex(extension, iconSize, true));
 }
コード例 #18
0
 /// <summary>
 /// Check if class contain a icon
 /// </summary>
 public bool IsValid(IconReader.IconSize size)
 {
     return(Icons.ContainsKey(size));
 }
コード例 #19
0
        /// <summary>
        /// Initalize class
        /// </summary>
        /// <param name="createSmallIconList">Create or not the Small ImageList.</param>
        /// <param name="createLargeIconList">Create or not the Large ImageList.</param>
        /// <param name="createExtraLargeIconList">Create or not the ExtraLarge ImageList.</param>
        /// <param name="createJumboIconList">Create or not the Jumbo ImageList.</param>
        /// <param name="optimizeToOS">Since XP or above support ExtraLarge And Vista or abdove support Jumbo icon sizes
        /// Disable unless sizes and ImageList on OS that not support that features.</param>
        public IconManager(bool createSmallIconList, bool createLargeIconList, bool createExtraLargeIconList, bool createJumboIconList, bool optimizeToOS)
        {
            IconList = new Dictionary<string, IconProperties>(4);
            IImageList = new Dictionary<IconReader.IconSize, ImageList>();

            // Add extra flags to supported sizes for the current OS
            if (Utils.IsXpOrAbove())
                IconsSizeAllSupported |= IconReader.IconSize.ExtraLarge;
            if (Utils.IsVistaOrAbove())
                IconsSizeAllSupported |= IconReader.IconSize.Jumbo;

            if(optimizeToOS)
            {
                // Check if a some features work on current OS, if not disable it by force
                if (!Utils.IsXpOrAbove())       // XP+ Support ExtraLarge
                    createExtraLargeIconList = false;
                if (!Utils.IsVistaOrAbove())    // Vista+ Support Jumbo
                    createJumboIconList = false;
            }

            // Create a imagelist with all colected icons and information
            if (createSmallIconList)
            {
                IImageList[IconReader.IconSize.Small] = new ImageList();
                IImageList[IconReader.IconSize.Small].TransparentColor = Color.Transparent;
                IImageList[IconReader.IconSize.Small].ColorDepth = ColorDepth.Depth32Bit;
                IImageList[IconReader.IconSize.Small].ImageSize = new Size(16, 16);
            }
            else
                IImageList[IconReader.IconSize.Small] = null;

            if (createLargeIconList)
            {
                IImageList[IconReader.IconSize.Large] = new ImageList();
                IImageList[IconReader.IconSize.Large].TransparentColor = Color.Transparent;
                IImageList[IconReader.IconSize.Large].ColorDepth = ColorDepth.Depth32Bit;
                IImageList[IconReader.IconSize.Large].ImageSize = new Size(32, 32);
            }
            else
                IImageList[IconReader.IconSize.Large] = null;

            if(createExtraLargeIconList)
            {
                IImageList[IconReader.IconSize.ExtraLarge] = new ImageList();
                IImageList[IconReader.IconSize.ExtraLarge].TransparentColor = Color.Transparent;
                IImageList[IconReader.IconSize.ExtraLarge].ColorDepth = ColorDepth.Depth32Bit;
                IImageList[IconReader.IconSize.ExtraLarge].ImageSize = new Size(48, 48);
            }
            else
                IImageList[IconReader.IconSize.Small] = null;

            if(createJumboIconList)
            {
                IImageList[IconReader.IconSize.Jumbo] = new ImageList();
                IImageList[IconReader.IconSize.Jumbo].TransparentColor = Color.Transparent;
                IImageList[IconReader.IconSize.Jumbo].ColorDepth = ColorDepth.Depth32Bit;
                IImageList[IconReader.IconSize.Jumbo].ImageSize = new Size(256, 256);
            }
            else
                IImageList[IconReader.IconSize.Jumbo] = null;
        }
コード例 #20
0
 public IconProvider(IconReader.IconSize iconSize)
 {
     IconSize = iconSize;
 }
コード例 #21
0
        /// <summary>
        /// Initalize class
        /// </summary>
        /// <param name="createSmallIconList">Create or not the Small ImageList.</param>
        /// <param name="createLargeIconList">Create or not the Large ImageList.</param>
        /// <param name="createExtraLargeIconList">Create or not the ExtraLarge ImageList.</param>
        /// <param name="createJumboIconList">Create or not the Jumbo ImageList.</param>
        /// <param name="optimizeToOS">Since XP or above support ExtraLarge And Vista or abdove support Jumbo icon sizes
        /// Disable unless sizes and ImageList on OS that not support that features.</param>
        public IconManager(bool createSmallIconList, bool createLargeIconList, bool createExtraLargeIconList, bool createJumboIconList, bool optimizeToOS)
        {
            IconList   = new Dictionary <string, IconProperties>(4);
            IImageList = new Dictionary <IconReader.IconSize, ImageList>();

            // Add extra flags to supported sizes for the current OS
            if (Utils.IsXpOrAbove())
            {
                IconsSizeAllSupported |= IconReader.IconSize.ExtraLarge;
            }
            if (Utils.IsVistaOrAbove())
            {
                IconsSizeAllSupported |= IconReader.IconSize.Jumbo;
            }

            if (optimizeToOS)
            {
                // Check if a some features work on current OS, if not disable it by force
                if (!Utils.IsXpOrAbove())       // XP+ Support ExtraLarge
                {
                    createExtraLargeIconList = false;
                }
                if (!Utils.IsVistaOrAbove())    // Vista+ Support Jumbo
                {
                    createJumboIconList = false;
                }
            }

            // Create a imagelist with all colected icons and information
            if (createSmallIconList)
            {
                IImageList[IconReader.IconSize.Small] = new ImageList();
                IImageList[IconReader.IconSize.Small].TransparentColor = Color.Transparent;
                IImageList[IconReader.IconSize.Small].ColorDepth       = ColorDepth.Depth32Bit;
                IImageList[IconReader.IconSize.Small].ImageSize        = new Size(16, 16);
            }
            else
            {
                IImageList[IconReader.IconSize.Small] = null;
            }

            if (createLargeIconList)
            {
                IImageList[IconReader.IconSize.Large] = new ImageList();
                IImageList[IconReader.IconSize.Large].TransparentColor = Color.Transparent;
                IImageList[IconReader.IconSize.Large].ColorDepth       = ColorDepth.Depth32Bit;
                IImageList[IconReader.IconSize.Large].ImageSize        = new Size(32, 32);
            }
            else
            {
                IImageList[IconReader.IconSize.Large] = null;
            }

            if (createExtraLargeIconList)
            {
                IImageList[IconReader.IconSize.ExtraLarge] = new ImageList();
                IImageList[IconReader.IconSize.ExtraLarge].TransparentColor = Color.Transparent;
                IImageList[IconReader.IconSize.ExtraLarge].ColorDepth       = ColorDepth.Depth32Bit;
                IImageList[IconReader.IconSize.ExtraLarge].ImageSize        = new Size(48, 48);
            }
            else
            {
                IImageList[IconReader.IconSize.Small] = null;
            }

            if (createJumboIconList)
            {
                IImageList[IconReader.IconSize.Jumbo] = new ImageList();
                IImageList[IconReader.IconSize.Jumbo].TransparentColor = Color.Transparent;
                IImageList[IconReader.IconSize.Jumbo].ColorDepth       = ColorDepth.Depth32Bit;
                IImageList[IconReader.IconSize.Jumbo].ImageSize        = new Size(256, 256);
            }
            else
            {
                IImageList[IconReader.IconSize.Jumbo] = null;
            }
        }