コード例 #1
0
        private void ArchiveTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            CurrentView.Clear();
            ImageList Images = new ImageList();

            Images.ImageSize  = new Size(32, 32);
            Images.ColorDepth = ColorDepth.Depth32Bit;

            Manifest.Folder Folder = e.Node.Tag as Manifest.Folder;

            Images.Images.Add(Properties.Resources.Folder);             // Image Index 0 is for folders
            foreach (Manifest.Folder Subfolder in Folder.Folders)
            {
                ListViewItem NewItem = new ListViewItem(Subfolder.Name, 0);
                NewItem.Tag = Subfolder;
                CurrentView.Items.Add(NewItem);
            }

            //Images.Images.Add(WhiteBox);            // Image index 1 is for missing icons.
            //const int iMissingIcon = 1;
            Images.Images.Add(GreenStar);           // Image index 2 is for missing icons with a green star.
            const int iMissingIconWithStar = 1;

            string ArchiveName = Archive.ToString().ToLower();
            Dictionary <string, int> ExtensionToImageIndex         = new Dictionary <string, int>();
            Dictionary <string, int> ExtensionToImageIndexWithStar = new Dictionary <string, int>();

            foreach (Manifest.File File in Folder.Files)
            {
                bool NeedStar = (File.ArchiveFile.ToLower() == ArchiveName);
                int  iImage   = -1;
                if (NeedStar)
                {
                    if (!ExtensionToImageIndexWithStar.TryGetValue(File.Extension.ToLower(), out iImage))
                    {
                        iImage = -1;
                    }
                }
                else
                {
                    if (!ExtensionToImageIndex.TryGetValue(File.Extension.ToLower(), out iImage))
                    {
                        iImage = -1;
                    }
                }

                if (iImage < 0)
                {
                    Icon FileIcon = Utility.GetFileIcon(File.Extension, true);
                    if (FileIcon == null)
                    {
                        if (NeedStar)
                        {
                            iImage = iMissingIconWithStar;
                        }
                        else
                        {
                            ListViewItem NewItemNI = new ListViewItem(File.Name);
                            NewItemNI.Tag = File;
                            CurrentView.Items.Add(NewItemNI);
                            continue;
                        }
                    }
                    else
                    {
                        Bitmap FileImage;
                        if (NeedStar)
                        {
                            FileImage = OverlayOnIcon(FileIcon, GreenStar);
                        }
                        else
                        {
                            FileImage = FileIcon.ToBitmap();
                        }

                        iImage = Images.Images.Count;
                        Images.Images.Add(FileImage);
                        if (NeedStar)
                        {
                            ExtensionToImageIndexWithStar.Add(File.Extension.ToLower(), iImage);
                        }
                        else
                        {
                            ExtensionToImageIndex.Add(File.Extension.ToLower(), iImage);
                        }
                    }
                }

                ListViewItem NewItem = new ListViewItem(File.Name, iImage);
                NewItem.Tag = File;
                CurrentView.Items.Add(NewItem);
            }

            CurrentView.View           = View.LargeIcon;
            CurrentView.LargeImageList = Images;

            btnExtract.Enabled = (ArchiveTree.SelectedNode != null) || (CurrentView.SelectedItems.Count > 0);
        }