/// <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]); } }
/// <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]; }
/// <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; }
/// <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); }
/// <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); }
/// <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; }
/// <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); } }
/// <summary> /// Check if class contain a icon /// </summary> public bool IsValid(IconReader.IconSize size) { return Icons.ContainsKey(size); }
/// <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; }
/// <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; }