/// <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 = System.IO.Path.GetFileName(assembly.Location);
                    filename = filename.Replace(System.IO.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);
                            }
                        }
                    }

                    // snag the image from the assembly, it should be an executable so...
                    Icon largeIcon = ShellInformation.GetIconFromPath(assembly.Location, IconSizes.LargeIconSize, IconStyles.NormalIconStyle, FileAttributes.Normal);
                    if (largeIcon != null)
                    {
                        ProgressViewer.SetImage(this, largeIcon.ToBitmap() as Image);
                    }

                    Icon smallIcon = ShellInformation.GetIconFromPath(assembly.Location, IconSizes.SmallIconSize, IconStyles.NormalIconStyle, FileAttributes.Normal);
                    if (smallIcon != null)
                    {
                        this.Icon = smallIcon;
                    }
                }
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
        }
Exemple #2
0
        public virtual int GetIconIndex(ImageList imageList, string path)
        {
            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
                    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 (_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(ShellInformation.GetImageFromPath(path, _size, _style, attribs));

            if (!_extensions.ContainsKey(extension))
            {
                _extensions.Add(extension, index);
            }

            return(index);
        }