/// <summary> /// Reads the meta data from assembly attributes and extracts the shell icon to display on the progress dialog /// </summary> /// <param name="assembly"></param> private void DisplayInformationAboutAssembly(System.Reflection.Assembly assembly, bool showVersion) { try { ProgressViewer.SetTitle(this, "Loading..."); ProgressViewer.SetDescription(this, "This operation could take several seconds..."); if (assembly != null) { // snag the name of the file minus path and extention and set it as the heading string filename = Path.GetFileName(assembly.Location); filename = filename.Replace(Path.GetExtension(assembly.Location), null); ProgressViewer.SetHeading(this, filename); // DirectoryInfo directory = new DirectoryInfo(Application.StartupPath); // //// // snag the version of the assembly, and tack it onto the heading // AssemblyAttributeReader reader = new AssemblyAttributeReader(assembly); //// Version v = reader.GetAssemblyVersion(); //// if (v != null) // ProgressViewer.SetHeading(this, filename + (showVersion ? " Version " + SnapInHostingEngine.Instance.AppVersion.ToString(): null)); // // // snag the company that made the assembly, and set it in the title // System.Reflection.AssemblyCompanyAttribute[] companyAttributes = reader.GetAssemblyCompanyAttributes(); // if (companyAttributes != null) // if (companyAttributes.Length > 0) // if (companyAttributes[0].Company != null && companyAttributes[0].Company != string.Empty) // ProgressViewer.SetTitle(this, companyAttributes[0].Company + " " + filename); // // get the large icon for the info panel Icon largeIcon = ShellUtilities.GetIconFromPath(assembly.Location, IconSizes.LargeIconSize, IconStyles.NormalIconStyle, FileAttributes.Normal); if (largeIcon != null) { ProgressViewer.SetImage(this, largeIcon.ToBitmap() as Image); } // get the small icon for the window Icon smallIcon = ShellUtilities.GetIconFromPath(assembly.Location, IconSizes.SmallIconSize, IconStyles.NormalIconStyle, FileAttributes.Normal); if (smallIcon != null) { this.Icon = smallIcon; } } } catch (Exception ex) { Log.WriteLine(ex); } }
/// <summary> /// Returns the index of the Image/Icon to use in the specified ImageList for the path of the file or folder specified. /// </summary> /// <param name="imageList">The ImageList where the Image is stored</param> /// <param name="path">The file or folder to retrieve the Image/Icon index for</param> /// <param name="extractNew">A flag that determines if a cached Image/Icon is used or if the sub-system will extract a new Image/Icon instead</param> /// <returns></returns> public int GetIconIndex(ImageList imageList, string path, bool extractNew) { string extension; bool useNormalAttribs = false; System.IO.FileAttributes attributes = System.IO.FileAttributes.Normal; try { attributes = File.GetAttributes(path); if ((attributes & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory) { DirectoryInfo directory = new DirectoryInfo(path); extension = directory.Extension; if (extension == null || extension == string.Empty) { extension = @"Folder"; } } else { FileInfo file = new FileInfo(path); // be carefull on these certain extensions! they will prolly contain different icons // if we wanted to be more elegant, these should be loaded from the config for extensibility reasons switch (file.Extension) { case ".exe": extension = file.FullName; break; case ".lnk": extension = file.FullName; break; case ".url": extension = file.FullName; break; case ".ico": extension = file.FullName; break; case ".cur": extension = file.FullName; break; case ".ani": extension = file.FullName; break; case ".msc": extension = file.FullName; break; default: extension = file.Extension; break; } } } catch { extension = path; useNormalAttribs = true; } if (!extractNew) { if (_extensions.ContainsKey(extension)) { return((int)_extensions[extension]); } } int index = imageList.Images.Count; FileAttributes attribs = FileAttributes.Normal; if (!useNormalAttribs) { attribs = ((attributes & FileAttributes.Directory) == FileAttributes.Directory ? FileAttributes.Directory : FileAttributes.Normal); } imageList.Images.Add(ShellUtilities.GetIconFromPath(path, _size, _style, attribs)); if (!_extensions.ContainsKey(extension)) { _extensions.Add(extension, index); } return(index); }