コード例 #1
0
        public void Load(TreeNode parent)
        {
            if (parent == null)
            {
                return;
            }
            if (parent.Tag == null)
            {
                return;
            }
            if (Root != null)
            {
                if (Root.Pidl == ((PIDL)parent.Tag).Pidl)
                {
                    return;
                }
            }
            if (diskReader != null)
            {
                foreach (DiskReader reader in diskReader)
                {
                    reader.Cancel = true;
                }
            }
            diskReader  = new List <DiskReader>();
            this.parent = parent;
            BeginUpdate();
            SuspendLayout();
            Items.Clear();
            largeimagelist.Images.Clear();
            smallimagelist.Images.Clear();
            Root = (PIDL)((PIDL)parent.Tag).Clone();
            {
                ListViewItems = new List <ListViewItem>();
                //if (parent.Parent != null)
                //{
                //    using (PIDL owner = (PIDL)((PIDL)parent.Parent.Tag).Clone())
                //        ListViewItems.Add(new ListViewItem(owner.DisplayName));
                //}
                Cursor = Cursors.WaitCursor;
                using (ShellFolder folder = new ShellFolder(Root))
                {
                    List <PIDL> children = folder.GetFolders(ShowHidden);
                    if (children == null)
                    {
                        ResumeLayout();
                        EndUpdate();
                        Cursor = Cursors.Default;
                        return;
                    }
                    foreach (PIDL child in children)
                    {
                        ListViewItem item = new ListViewItem(child.DisplayName);
                        item.ImageIndex = -1;
                        item.Tag        = child;
                        item.SubItems.Add(child.TypeName);

                        ListViewItems.Add(item);

                        item.Name = child.PhysicalPath + child.DisplayName;
                        if (child.IsFileSystem)
                        {
                            if (child.IsCompressed)
                            {
                                FileInfo fi = new FileInfo(child.PhysicalPath);
                                try
                                {
                                    item.SubItems.Add(StrFormatByteSize(fi.Length));
                                }
                                catch (Exception ex)
                                {
                                    item.SubItems.Add(ex.Message);
                                }
                            }
                            else
                            {
                                diskReader.Add(new DiskReader(child.PhysicalPath, item));
                                diskReader[diskReader.Count - 1].DiskReadComplete += DiskReader_DiskReadComplete;
                                diskReader[diskReader.Count - 1].Progress         += ListViewEx_Progress;
                                item.SubItems.Add("");
                                item.BackColor = Color.Wheat;
                                item.UseItemStyleForSubItems = true;
                                item.SubItems.Add("");
                                item.SubItems.Add("");
                            }
                        }
                        else
                        {
                            item.SubItems.Add("");
                        }
                        item.SubItems.Add("");
                        item.Name = child.PhysicalPath + child.DisplayName;
                    }

                    children = folder.GetFiles(ShowHidden);
                    if (children == null)
                    {
                        return;
                    }
                    foreach (PIDL child in children)
                    {
                        if (!child.IsFolder)
                        {
                            ListViewItem item = new ListViewItem(child.DisplayName);
                            item.ImageIndex = -1;
                            item.Tag        = child;
                            item.SubItems.Add(child.TypeName);

                            ListViewItems.Add(item);
                            if (child.PhysicalPath.Length > 0)
                            {
                                FileInfo fi = new FileInfo(child.PhysicalPath);
                                item.SubItems.Add(StrFormatByteSize(fi.Length));
                            }
                            else
                            {
                                item.SubItems.Add("");
                            }

                            item.SubItems.Add("");
                        }
                    }
                    Items.AddRange(ListViewItems.ToArray());
                    ResumeLayout();
                    EndUpdate();
                    Cursor = Cursors.Default;
                    ThreadPool.QueueUserWorkItem(UpdateIcons);
                }
            }
        }