/// <summary> /// Get the icon index associated with a given filename /// </summary> /// <param name="filename">the filename of interest</param> /// <param name="open">if true, the file is "open", most useful for folders</param> /// <returns>the index into the image list for the icon associated with this file</returns> public int GetIconIndex(ExtraSpecialFolder folder, bool open) { GetInfoFlags flags = GetInfoFlags.SHGFI_ICON | GetInfoFlags.SHGFI_SMALLICON | GetInfoFlags.SHGFI_PIDL; if (open) { flags |= GetInfoFlags.SHGFI_OPENICON; } IntPtr ppidl; if (SHGetFolderLocation(IntPtr.Zero, (int)folder, IntPtr.Zero, 0, out ppidl) != 0) { throw new Exception("SHGetFolderLocation failed"); } SHFILEINFO info = new SHFILEINFO(); SHGetFileInfoPIDL(ppidl, 0, ref info, (uint)Marshal.SizeOf(info), (uint)flags); int iIcon = MapIcon(info.hIcon, info.iIcon); ILFree(ppidl); DestroyIcon(info.hIcon); return(iIcon); }
public string GetDisplayName(FileSystemInfo filename) { GetInfoFlags flags = GetInfoFlags.SHGFI_DISPLAYNAME; SHFILEINFO info = new SHFILEINFO(); if (SHGetFileInfo(filename.FullName, (uint)filename.Attributes, ref info, (uint)Marshal.SizeOf(info), (uint)flags) == IntPtr.Zero) { return(filename.Name); } return(info.szDisplayName); }
public string GetDisplayName(ExtraSpecialFolder folder) { GetInfoFlags flags = GetInfoFlags.SHGFI_PIDL | GetInfoFlags.SHGFI_DISPLAYNAME; SHFILEINFO info = new SHFILEINFO(); IntPtr ppidl; if (SHGetFolderLocation(IntPtr.Zero, (int)folder, IntPtr.Zero, 0, out ppidl) != 0) { throw new Exception("SHGetFolderLocation failed"); } if (SHGetFileInfoPIDL(ppidl, 0, ref info, (uint)Marshal.SizeOf(info), (uint)flags) == IntPtr.Zero) { ILFree(ppidl); throw new Exception("SHGetFileInfo failed"); } ILFree(ppidl); return(info.szDisplayName); }
/// <summary> /// Get the icon index associated with a given filename /// </summary> /// <param name="filename">the filename of interest</param> /// <param name="open">if true, the file is "open", most useful for folders</param> /// <returns>the index into the image list for the icon associated with this file</returns> public int GetIconIndex(FileSystemInfo filename, bool open) { int iIcon; if (filename is FileInfo && m_extension_map.TryGetValue(filename.Extension.ToLower(), out iIcon)) { return(iIcon); } GetInfoFlags flags = GetInfoFlags.SHGFI_ICON | GetInfoFlags.SHGFI_SMALLICON | GetInfoFlags.SHGFI_USEFILEATTRIBUTES; if (open) { flags |= GetInfoFlags.SHGFI_OPENICON; } SHFILEINFO info = new SHFILEINFO(); SHGetFileInfo(filename.FullName, filename.Exists ? (uint)filename.Attributes : 0, ref info, (uint)Marshal.SizeOf(info), (uint)flags); iIcon = MapIcon(info.hIcon, info.iIcon); DestroyIcon(info.hIcon); return(iIcon); }
void RequiresGetInfo(GetInfoFlags flags) { lock (_getInfoLock) { flags &= ~_getInfoFlags; // Remove flags we already have. if (flags == 0) { return; } if (!TryOpenToGetInfo(handle => { if ((flags & GetInfoFlags.Manufacturer) != 0) { if (!TryGetDeviceString(handle, NativeMethods.HidD_GetManufacturerString, out _manufacturer)) { return(false); } } if ((flags & GetInfoFlags.ProductName) != 0) { if (!TryGetDeviceString(handle, NativeMethods.HidD_GetProductString, out _productName)) { return(false); } } if ((flags & GetInfoFlags.SerialNumber) != 0) { if (!TryGetDeviceString(handle, NativeMethods.HidD_GetSerialNumberString, out _serialNumber)) { return(false); } } if ((flags & GetInfoFlags.ReportInfo) != 0) { IntPtr preparsed; if (!NativeMethods.HidD_GetPreparsedData(handle, out preparsed)) { return(false); } try { NativeMethods.HIDP_CAPS caps; int statusCaps = NativeMethods.HidP_GetCaps(preparsed, out caps); if (statusCaps != NativeMethods.HIDP_STATUS_SUCCESS) { return(false); } _maxInput = caps.InputReportByteLength; _maxOutput = caps.OutputReportByteLength; _maxFeature = caps.FeatureReportByteLength; try { _reportDescriptor = new ReportDescriptorReconstructor().Run(preparsed, caps); } catch (NotImplementedException) { _reportDescriptor = null; } catch { return(false); } } finally { NativeMethods.HidD_FreePreparsedData(preparsed); } } return(true); })) { throw DeviceException.CreateIOException(this, "Failed to get info."); } _getInfoFlags |= flags; } }