public static bool ParseToolbarButtonLine(string source, out string command, ref ToolStripItemDisplayStyle displayStyle, out IconLocation imageLocation) { command = null; imageLocation = null; if (string.IsNullOrEmpty(source)) { return false; } int startIndex = 0; command = StringHelper.ReadValue(source, ref startIndex, new char[] { ',' }).Trim(); if (startIndex > 0) { string str = StringHelper.ReadValue(source, ref startIndex, new char[] { ',' }).Trim(); try { displayStyle = (ToolStripItemDisplayStyle) Enum.Parse(typeof(ToolStripItemDisplayStyle), str); } catch (ArgumentException) { } } if (startIndex > 0) { string iconLocation = source.Substring(startIndex).Trim(); imageLocation = IconLocation.TryParse(iconLocation); if (!(((imageLocation == null) || (imageLocation.IconIndex != 0)) || iconLocation.EndsWith(",0", StringComparison.Ordinal))) { imageLocation = new IconLocation(imageLocation.IconFileName, -1); } } return true; }
public static string CreateToolbarButtonLine(string command, ToolStripItemDisplayStyle displayStyle, IconLocation imageLocation) { if (command == null) { throw new ArgumentNullException(); } if (command == string.Empty) { throw new ArgumentException(); } StringBuilder builder = new StringBuilder(); builder.Append(command); if (displayStyle != ToolStripItemDisplayStyle.Image) { builder.Append(','); builder.Append(displayStyle); } if (imageLocation != null) { if (displayStyle == ToolStripItemDisplayStyle.Image) { builder.Append(','); } builder.Append(','); builder.Append(imageLocation.IconFileName); if (imageLocation.IconIndex >= 0) { builder.Append(','); builder.Append(imageLocation.IconIndex); } } return builder.ToString(); }
public SimpleCustomizeFolder(ICustomizeFolder source) { this.FAutoSizeColumns = source.AutoSizeColumns; this.FColumns = source.Columns; this.FIcon = source.Icon; this.FFilter = source.Filter; this.FSort = source.Sort; this.FListColumnCount = source.ListColumnCount; this.FThumbnailSize = source.ThumbnailSize; this.FThumbnailSpacing = source.ThumbnailSpacing; this.FView = source.View; this.FBackColor = source.BackColor; this.FForeColor = source.ForeColor; }
public static bool Equals(IconLocation x, IconLocation y) { return ((((x != null) && (y != null)) && x.Equals(y)) || ((x == null) && (y == null))); }
private ListViewItem GetFocusItem(IEnumerable<ListViewItem> items, IconLocation imageLocation) { if (items != null) { string iconFileName = imageLocation.IconFileName; if (imageLocation.IconIndex >= 0) { iconFileName = iconFileName + ',' + imageLocation.IconIndex.ToString(); } foreach (ListViewItem item in items) { if (item.ImageKey.Equals(iconFileName, StringComparison.OrdinalIgnoreCase)) { return item; } } } return null; }
private static void AddIconToCache(IconLocation iconLocation, ref Size size, Image icon) { lock (LocationIconCache) { IDictionary<Size, Image> dictionary; if ((LocationIconCache.TryGetValue(iconLocation, out dictionary) && (dictionary != null)) && (icon != null)) { dictionary[size] = icon; } else if (icon == null) { LocationIconCache[iconLocation] = null; } else { dictionary = IconCollection.Create(); dictionary.Add(size, icon); LocationIconCache[iconLocation] = dictionary; } } }
protected virtual Image GetFileIcon(string fileName, string extension, ref Size size) { string g = null; string fileClass = GetFileClass(extension); if (!string.IsNullOrEmpty(fileClass)) { g = ReadRegistryValue(Registry.ClassesRoot, fileClass + @"\shellex\IconHandler", null) as string; } IconLocation iconLocation = null; Image defaultFileIconFromExt = null; if (g != null) { object obj2; Guid rclsid = new Guid(g); if (ActiveX.CoCreateInstance(rclsid, null, CLSCTX.CLSCTX_INPROC_HANDLER | CLSCTX.CLSCTX_INPROC_SERVER, typeof(IPersistFile).GUID, out obj2) == 0) { try { ((IPersistFile) obj2).Load(fileName, 0); StringBuilder szIconFile = new StringBuilder(0x400); GIL_OUT pwFlags = 0; string iconFileName = null; int piIndex = 0; int num2 = 1; IExtractIconW nw = obj2 as IExtractIconW; if (nw != null) { num2 = nw.GetIconLocation(GIL_IN.GIL_FORSHELL, szIconFile, (uint) szIconFile.Capacity, out piIndex, out pwFlags); } else { IExtractIconA na = obj2 as IExtractIconA; if (na != null) { num2 = na.GetIconLocation(GIL_IN.GIL_FORSHELL, szIconFile, (uint) szIconFile.Capacity, out piIndex, out pwFlags); } } if (num2 == 0) { iconFileName = Environment.ExpandEnvironmentVariables(szIconFile.ToString()); if ((pwFlags & GIL_OUT.GIL_NOTFILENAME) == ((GIL_OUT) 0)) { iconLocation = new IconLocation(iconFileName, piIndex); } else { defaultFileIconFromExt = ExtractIcon(obj2, new ClassIconLocation(ref rclsid, iconFileName, piIndex), (pwFlags & GIL_OUT.GIL_DONTCACHE) == ((GIL_OUT) 0), ref size); if (defaultFileIconFromExt != null) { return defaultFileIconFromExt; } try { string str4 = Path.GetExtension(iconFileName); if (!string.IsNullOrEmpty(str4)) { iconLocation = new IconLocation(iconFileName, 0); extension = str4; } } catch (ArgumentException) { } } } } catch (IOException) { } catch (UnauthorizedAccessException) { } catch (COMException exception) { if (Marshal.GetHRForException(exception) != -2147467259) { Debug.WriteLine(exception, "ImageProvider"); } } finally { Marshal.ReleaseComObject(obj2); } } } if (iconLocation == null) { iconLocation = GetDefaultFileIconLocation(extension); } if (iconLocation != null) { if (iconLocation.IconFileName == "%1") { iconLocation = new IconLocation(fileName, 0); } defaultFileIconFromExt = LoadIconFromLocation2(iconLocation, ref size); } if (defaultFileIconFromExt == null) { defaultFileIconFromExt = this.GetDefaultFileIconFromExt(extension, ref size); } return defaultFileIconFromExt; }
protected override Image GetShellLinkIcon(ShellLink link, ref Size size) { string str; int num; link.GetIconLocation(out str, out num); if (!string.IsNullOrEmpty(str)) { IconLocation iconLocation = new IconLocation(Environment.ExpandEnvironmentVariables(str), num); return LoadIconFromLocation2(iconLocation, ref size); } return null; }
public OverlayIdentifier(IntPtr identifier) { int num; Debug.WriteLine(string.Format("OverlayIdenfifier({0})", identifier), "ImageProvider"); this.FIdentifierPtr = identifier; StringBuilder pwszIconFile = new StringBuilder(0x400); IShellIconOverlayIdentifier typedObjectForIUnknown = (IShellIconOverlayIdentifier) Marshal.GetTypedObjectForIUnknown(this.FIdentifierPtr, typeof(IShellIconOverlayIdentifier)); try { ISIOI isioi; typedObjectForIUnknown.GetOverlayInfo(pwszIconFile, pwszIconFile.Capacity, out num, out isioi); Debug.WriteLine(string.Format("> IconName = '{0}', IconIndex = {1}, Flags = {2}", pwszIconFile.ToString(), num, isioi), "ImageProvider"); this.Priority = typedObjectForIUnknown.GetPriority(); Debug.WriteLine("> Priority = " + this.Priority.ToString(), "ImageProvider"); } finally { Marshal.ReleaseComObject(typedObjectForIUnknown); } this.IconLocation = new Nomad.Commons.Drawing.IconLocation(pwszIconFile.ToString(), num); }
public static Image LoadShellDllIcon(int iconIndex, Size size) { IconLocation location; Dictionary<int, IconLocation> dictionary; lock ((dictionary = ShellDllIconMap)) { ShellDllIconMap.TryGetValue(iconIndex, out location); } if (location == null) { location = IconLocation.TryParse(ReadRegistryValue(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons", iconIndex.ToString()) as string); if (location == null) { location = new IconLocation(ShellDllLocation, iconIndex); } lock ((dictionary = ShellDllIconMap)) { ShellDllIconMap[iconIndex] = location; } } return LoadIconFromLocation(location, size); }
private static Image LoadIconFromLocation2(IconLocation iconLocation, ref Size size) { if (iconLocation.IconFileName.Equals(ShellDllLocation, StringComparison.OrdinalIgnoreCase)) { return LoadShellDllIcon(iconLocation.IconIndex, size); } return LoadIconFromLocation(iconLocation, size); }
public static Image LoadIconFromLocation(IconLocation iconLocation, Size size) { Image image; if (iconLocation == null) { throw new ArgumentNullException("iconLocation"); } if (!GetIconFromCache(iconLocation, ref size, out image)) { image = LoadIcon(iconLocation.IconFileName, iconLocation.IconIndex, size); AddIconToCache(iconLocation, ref size, image); } return image; }
public static void LoadIconCache(Stream cacheStream) { BinaryReader reader = new BinaryReader(cacheStream, Encoding.UTF8); if (new string(reader.ReadChars(4)) != "IMCH") { throw new InvalidDataException(); } if (reader.ReadInt32() != 1) { throw new InvalidDataException("Unknown icon cache format version."); } lock (LocationIconCache) { LocationIconCache.Clear(); int num = reader.ReadInt32(); for (int i = 0; i < num; i++) { IconLocation location; switch (reader.ReadByte()) { case 0: location = new IconLocation(reader.ReadString(), reader.ReadInt32()); break; case 1: { Guid classId = new Guid(reader.ReadBytes(0x10)); location = new ClassIconLocation(ref classId, reader.ReadString(), reader.ReadInt32()); break; } default: throw new InvalidDataException("Unknown icon location format."); } IDictionary<Size, Image> dictionary = IconCollection.Create(); int num4 = reader.ReadInt32(); for (int j = 0; j < num4; j++) { Size key = new Size(reader.ReadInt32(), reader.ReadInt32()); int num6 = reader.ReadInt32(); long position = cacheStream.Position; using (Image image = Image.FromStream(new SubStream(cacheStream, FileAccess.Read, (long) num6))) { dictionary.Add(key, new Bitmap(image)); } cacheStream.Position = position + num6; } LocationIconCache.Add(location, (dictionary.Count == 0) ? null : dictionary); } } }
private static bool IsIconSizeInCache(IconLocation iconLocation, Size size) { lock (LocationIconCache) { IDictionary<Size, Image> dictionary; if (LocationIconCache.TryGetValue(iconLocation, out dictionary) && (dictionary != null)) { return dictionary.ContainsKey(size); } } return false; }
private static Image GetDefaultContainerIcon(string classKey, string extKey, int shellIconIndex, ref Size size) { IconLocation location; Dictionary<string, IconLocation> dictionary; lock ((dictionary = ExtIconMap)) { ExtIconMap.TryGetValue(extKey, out location); } if (location == null) { location = IconLocation.TryParse(ReadRegistryValue(Registry.ClassesRoot, classKey + @"\DefaultIcon", null) as string); if (location == null) { location = new IconLocation(ShellDllLocation, shellIconIndex); } lock ((dictionary = ExtIconMap)) { ExtIconMap[extKey] = location; } } return LoadIconFromLocation2(location, ref size); }
protected SimpleCustomizeFolder(SerializationInfo info, StreamingContext context) { this.FUpdatebleParts = (CustomizeFolderParts) info.GetValue("UpdateableParts", typeof(CustomizeFolderParts)); string str = null; int iconIndex = 0; SerializationInfoEnumerator enumerator = info.GetEnumerator(); while (enumerator.MoveNext()) { SerializationEntry current = enumerator.Current; switch (current.Name) { case "AutoSizeColumns": this.FAutoSizeColumns = new bool?(Convert.ToBoolean(current.Value)); break; case "Columns": this.FColumns = (ListViewColumnInfo[]) current.Value; break; case "Filter": this.FFilter = (IVirtualItemFilter) current.Value; break; case "Sort": this.FSort = (VirtualItemComparer) current.Value; break; case "ListColumnCount": this.FListColumnCount = new int?(Convert.ToInt32(current.Value)); break; case "ThumbnailSize": this.FThumbnailSize = (Size) current.Value; break; case "ThumbnailSpacing": this.FThumbnailSpacing = (Size) current.Value; break; case "View": this.FView = new PanelView?((PanelView) current.Value); break; case "IconFile": str = current.Value as string; break; case "IconIndex": iconIndex = Convert.ToInt32(current.Value); break; case "BackColor": this.FBackColor = (Color) current.Value; break; case "ForeColor": this.FForeColor = (Color) current.Value; break; } } if (!string.IsNullOrEmpty(str)) { this.FIcon = new IconLocation(str, iconIndex); } }
private static bool GetIconFromCache(IconLocation iconLocation, ref Size size, out Image icon) { if (iconLocation == null) { throw new ArgumentNullException("iconLocation"); } icon = null; lock (LocationIconCache) { IDictionary<Size, Image> dictionary; if (LocationIconCache.TryGetValue(iconLocation, out dictionary)) { if (dictionary != null) { return dictionary.TryGetValue(size, out icon); } return true; } } return false; }