Ejemplo 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;
        }
Ejemplo n.º 2
0
        private void ScanAndUpdate(FileInfo fileInfo)
        {
            FileIdentity id = new FileIdentity
            {
                CheckSum     = 0,
                FilePath     = fileInfo.FullName,
                LastModified = fileInfo.LastWriteTime,
                Name         = fileInfo.Name,
                Size         = fileInfo.Length,
                Type         = fileInfo.Extension
            };

            this._FileInfoDb.AddOrUpdate(id);
        }
Ejemplo n.º 3
0
        public void AddOrUpdate(FileIdentity file)
        {
            FileIdentity fileOld = this.Find(file.FilePath);

            file.LastModified = DateTime.Now;
            if (fileOld == null)
            {
                this.fileCollection.Insert(file);
                this.fileCollection.EnsureIndex(x => x.FilePath);
            }
            else
            {
                file.Id = fileOld.Id;
                this.fileCollection.Update(file);
            }
            this.db.Commit();
        }
Ejemplo n.º 4
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;
            }
        }