public int AddFileIcon(string filePath)
        {
            string text = Path.GetExtension(filePath).TrimStart(".".ToCharArray());
            int    result;

            if (this._extensionList.ContainsKey(text.ToUpper()))
            {
                result = (int)this._extensionList[text.ToUpper()];
            }
            else
            {
                int count = ((ImageList)this._imageLists[0]).Images.Count;
                if (this._manageBothSizes)
                {
                    ((ImageList)this._imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconSize.Small, false));
                    ((ImageList)this._imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconSize.Large, false));
                }
                else
                {
                    ((ImageList)this._imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, this._iconSize, false));
                }
                this.AddExtension(text.ToUpper(), count);
                result = count;
            }
            return(result);
        }
示例#2
0
        public static ImageSource IconFromFile(string fileName)
        {
            var icon = IconReader.GetFileIcon(fileName, IconReader.IconSize.Large, false);
            var bmp  = icon.ToBitmap();

            return(LoadBitmap(bmp));
        }
示例#3
0
        /// <summary>
        /// Called publicly to add a file's icon to the ImageList.
        /// </summary>
        /// <param name="filePath">Full path to the file.</param>
        /// <returns>Integer of the icon's position in the ImageList</returns>
        public int AddFileOverlayIcon(string filePath, string overlayTagName, string overlayFilename)
        {
            // Check if the file exists, otherwise, throw exception.
            if (!System.IO.File.Exists(filePath))
            {
                throw new System.IO.FileNotFoundException("File does not exist");
            }

            // Split it down so we can get the extension
            string[] splitPath = filePath.Split(new Char[] { '.' });
            string   extension = (string)splitPath.GetValue(splitPath.GetUpperBound(0));

            // Add in the special overlay tag name to the extension name
            extension = "{" + overlayTagName + "}" + extension;

            //Check that we haven't already got the extension, if we have, then
            //return back its index
            if (_extensionList.ContainsKey(extension.ToUpper()))
            {
                return((int)_extensionList[extension.ToUpper()]);                               //return existing index
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)_imageLists[0]).Images.Count;                             //store current count -- new item's index

                if (ManageBothSizes == true)
                {
                    //managing two lists, so add it to small first, then large
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small, false));
                    ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large, false));
                }
                else
                {
                    Bitmap myImage = null;

                    // Great, get a copy of that
                    Bitmap lockSource = new Bitmap(overlayFilename);

                    // Great get a copy of that
                    Bitmap source = IconReader.GetFileIcon(filePath, _iconSize, false).ToBitmap();

                    // Ok, if we got a lockSource and a class source icon, lets attempt to overlay them
                    if (source != null && lockSource != null)
                    {
                        myImage = BitmapManipulator.OverlayBitmap(source, lockSource, 100, BitmapManipulator.ImageCornerEnum.BottomRight);
                    }

                    //only doing one size, so use IconSize as specified in _iconSize.
                    ((ImageList)_imageLists[0]).Images.Add(myImage);                            //add to image list
                }

                AddExtension(extension.ToUpper(), pos);                         // add to hash table
                return(pos);
            }
        }
示例#4
0
        /// <summary>
        /// Called publicly to add a file's icon to the ImageList.
        /// </summary>
        /// <param name="filePath">Full path to the file.</param>
        /// <returns>Integer of the icon's position in the ImageList</returns>
        public int AddFileIcon(string filePath)
        {
            // Check if the file exists, otherwise, throw exception.
            if (!System.IO.File.Exists(filePath))
            {
                throw new System.IO.FileNotFoundException("File does not exist");
            }

            // Split it down so we can get the extension
            //string[] splitPath = filePath.Split(new Char[] {'.'});
            string extension = Path.GetExtension(filePath);            //(string)splitPath.GetValue( splitPath.GetUpperBound(0) );

            // Also, we want to pull exe's by filename because mose exe's have special icons
            if (string.Compare(extension, ".exe", true) == 0)
            {
                extension = Path.GetFileName(filePath);
            }
            else if (string.Compare(extension, ".ico") == 0)
            {
                extension = Path.GetFileName(filePath);
            }

            //Check that we haven't already got the extension, if we have, then
            //return back its index
            if (_extensionList.ContainsKey(extension.ToUpper()))
            {
                return((int)_extensionList[extension.ToUpper()]);                               //return existing index
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)_imageLists[0]).Images.Count;                             //store current count -- new item's index

                if (ManageBothSizes == true)
                {
                    //managing two lists, so add it to small first, then large
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small, false));
                    ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large, false));
                }
                else
                {
                    //only doing one size, so use IconSize as specified in _iconSize.
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, _iconSize, false));                         //add to image list
                }

                AddExtension(extension.ToUpper(), pos);                         // add to hash table
                return(pos);
            }
        }
示例#5
0
        public int AddFileId(string extension, string filePath, bool isFolder = false, FolderType folderType = FolderType.Closed)
        {
            // Split it down so we can get the extension
            // string[] splitPath = filePath.Split(new Char[] { '.' });
            // string extension = (string)splitPath.GetValue(splitPath.GetUpperBound(0));

            //Check that we haven't already got the extension, if we have, then
            //return back its index
            if (_extensionList.ContainsKey(extension.ToUpper()))
            {
                return((int)_extensionList[extension.ToUpper()]);        //return existing index
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)_imageLists[0]).Images.Count;     //store current count -- new item's index

                if (ManageBothSizes == true)
                {
                    //managing two lists, so add it to small first, then large
                    if (!isFolder)
                    {
                        ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small, false));
                        ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large, false));
                    }
                    else
                    {
                        ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFolderIcon(filePath, IconReader.IconSize.Small, folderType));
                        ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFolderIcon(filePath, IconReader.IconSize.Large, folderType));
                    }
                }
                else
                {
                    //only doing one size, so use IconSize as specified in _iconSize.
                    if (!isFolder)
                    {
                        ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, _iconSize, false)); //add to image list
                    }
                    else
                    {
                        ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFolderIcon(filePath, IconReader.IconSize.Large, folderType));
                    }
                }

                AddExtension(extension.ToUpper(), pos); // add to hash table
                return(pos);
            }
        }
示例#6
0
        /// <summary>
        /// Called publicly to add a file's icon to the ImageList.
        /// </summary>
        /// <param name="filePath">Full path to the file.</param>
        /// <returns>Integer of the icon's position in the ImageList</returns>
        public int AddFileIcon(string filePath)
        {
#if MONO
            return(2);
#else
            // Check if the file exists, otherwise, throw exception.
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("File does not exist");
            }

            // Split it down so we can get the extension
            string[] splitPath = filePath.Split(new[] { '.' });
            var      extension = (string)splitPath.GetValue(splitPath.GetUpperBound(0));

            //Check that we haven't already got the extension, if we have, then
            //return back its index
            if (_extensionList.ContainsKey(extension.ToUpper()))
            {
                return((int)_extensionList[extension.ToUpper()]); //return existing index
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)_imageLists[0]).Images.Count;  //store current count -- new item's index

                if (ManageBothSizes)
                {
                    //managing two lists, so add it to small first, then large
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small,
                                                                                  false));
                    ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large,
                                                                                  false));
                }
                else
                {
                    //only doing one size, so use IconSize as specified in _iconSize.
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, _iconSize, false));
                    //add to image list
                }

                AddExtension(extension.ToUpper(), pos); // add to hash table
                return(pos);
            }
#endif
        }