Ejemplo n.º 1
0
        public void Init(IDirectoryInfo d)
        {
            if (StartDirectory == null)
            {
                StartDirectory = d;
            }
            Sectors.Clear();
            Text             = "Memory report: " + d.FullName;
            CurrentDirectory = d;
            var list  = Stuff.GetAllFiles(d);
            var total = list.Sum(z => z.Length);

            TotalLen = total;
            var rootl = d.GetFiles().Sum(z => z.Length);

            if (rootl > 0)
            {
                Sectors.Add(new ReportSectorInfo()
                {
                    Name = ".root", Length = rootl, Tag = d, Percentage = (float)rootl / total
                });
            }
            foreach (var item in d.GetDirectories())
            {
                var f = Stuff.GetAllFiles(item);
                var l = f.Sum(z => z.Length);
                Sectors.Add(new ReportSectorInfo()
                {
                    Name       = item.Name,
                    Length     = l,
                    Percentage = (float)l / total,

                    Tag = item
                });
            }
            Sectors = Sectors.OrderByDescending(z => z.Percentage).ToList();

            listView1.Items.Clear();
            foreach (var item in Sectors)
            {
                listView1.Items.Add(new ListViewItem(new string[] { item.Name, Stuff.GetUserFriendlyFileSize(item.Length), (item.Percentage * 100).ToString("F") + "%" })
                {
                    Tag = item
                });
            }
            //listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            //listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }