Exemplo n.º 1
0
        private void PopulateListView(string folder)
        {
            long duplicateCount = 0;

            this.duplicateFileList.Clear();


            FileIdentityDuplicate lastItem = null;

            IEnumerable <FileIdentity> infos = this._FileInfoDb.FindAll(folder);

            foreach (var inf in infos)
            {
                FileIdentityDuplicate d = new FileIdentityDuplicate {
                    item = inf, selected = false
                };
                this.duplicateFileList.Add(d);
                if (lastItem != null)
                {
                    FileIdentity fi = lastItem.item;
                    if (fi.Name.Equals(inf.Name) && fi.Size == inf.Size)
                    {
                        d.selected = true;
                        duplicateCount++;
                    }
                    else
                    {
                        if (!lastItem.selected)
                        {
                            this.duplicateFileList.Remove(lastItem);
                        }
                    }
                }

                lastItem = d;
            }

            this.toolStripStatusLabel2.Text = string.Empty;
            if (duplicateCount > 0)
            {
                this.toolStripButton1.Enabled = true;
            }
            else
            {
                this.toolStripButton1.Enabled = false;
            }
            this.toolStripStatusLabel2.Text = "Total File: " + infos.Count().ToString() + " Duplicate: " + duplicateCount;
            this.toolStripStatusLabel1.Text = "Completed";
            this.listFiles.VirtualListSize  = this.duplicateFileList.Count;
        }
Exemplo n.º 2
0
        private void listFiles_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            if (this.duplicateFileList.Count > e.ItemIndex)
            {
                FileIdentityDuplicate d    = this.duplicateFileList[e.ItemIndex];
                FileIdentity          inf  = d.item;
                ListViewItem          item = new ListViewItem(inf.Name, 1);
                item.Tag = inf;
                ListViewItem.ListViewSubItem[] subItems = new ListViewItem.ListViewSubItem[]
                { new ListViewItem.ListViewSubItem(item, inf.FilePath),
                  new ListViewItem.ListViewSubItem(item,
                                                   inf.LastModified.ToShortDateString()),
                  new ListViewItem.ListViewSubItem(item,
                                                   inf.Size.ToString()),
                  new ListViewItem.ListViewSubItem(item,
                                                   inf.CheckSum.ToString()) };

                item.SubItems.AddRange(subItems);
                if (d.selected)
                {
                    item.BackColor = Color.Red;
                    item.Checked   = true;
                }
                e.Item = item;
            }
            else
            {
                ListViewItem item = new ListViewItem();

                ListViewItem.ListViewSubItem[] subItems = new ListViewItem.ListViewSubItem[]
                { new ListViewItem.ListViewSubItem(item, string.Empty),
                  new ListViewItem.ListViewSubItem(item,
                                                   string.Empty),
                  new ListViewItem.ListViewSubItem(item,
                                                   string.Empty),
                  new ListViewItem.ListViewSubItem(item,
                                                   string.Empty) };

                item.SubItems.AddRange(subItems);

                e.Item = item;
            }
        }