Example #1
0
        private void BeginProcessing(List<List<string>> duplicateResults)
        {
            DoInvoke((MethodInvoker)delegate()
            {
                duplicateList.BeginUpdate();
            });

            int max = 0;
            foreach (List<string> ss in duplicateResults)
            {
                foreach (string s in ss)
                {
                    max++;
                }
            }

            ProcessProgress progress = new ProcessProgress(max, "Processing");
            DoInvoke((MethodInvoker)delegate()
            {
                progress.Show(this);
            });

            int count = 0;
            int total = 0;

            foreach (List<string> dupeGroup in duplicateResults)
            {
                FileInfo f = new FileInfo(dupeGroup[0]);

                string headerKey = Hasher.md5(Encoding.ASCII.GetBytes(f.FullName));

                DoInvoke((MethodInvoker)delegate()
                {
                    duplicateList.Groups.Add(headerKey, f.Name);
                });

                foreach (string file in dupeGroup)
                {
                    ListViewItem i = new ListViewItem(duplicateList.Groups[headerKey]);
                    i.Text = new FileInfo(file).FullName;

                    DoInvoke((MethodInvoker)delegate()
                    {
                        duplicateList.Items.Add(i);
                    });

                    count++;
                    total++;
                    if (count > 50)
                    {
                        count = 0;
                        progress.UpdateProgress(total);
                    }
                    Application.DoEvents();
                }
            }
            DoInvoke((MethodInvoker)delegate()
            {
                progress.Close();
            });

            DoInvoke((MethodInvoker)delegate()
            {
                duplicateList.EndUpdate();
            });
        }
Example #2
0
        private void _deleteSelected()
        {
            if (MessageBox.Show("WARNING: This will permanently delete all selected files in this list. This action cannot be undone.\r\n\r\nAre you sure you want to delete the selected files?", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                ProcessProgress progress = new ProcessProgress(duplicateList.Items.Count, "Deleting");
                DoInvoke((MethodInvoker)delegate()
                {
                    progress.Show(this);
                });

                List<ListViewItem> toRemove = new List<ListViewItem>();

                int total = 0;

                DoInvoke((MethodInvoker)delegate()
                {
                    foreach (ListViewItem i in duplicateList.Items)
                    {
                        if (i.Selected)
                        {
                            try
                            {
                                FileInfo f = new FileInfo(i.Text);
                                f.Delete();
                                toRemove.Add(i);
                            }
                            catch
                            {
                                // Delete failed. Skip the file.
                            }
                        }
                        total++;
                        progress.UpdateProgress(total);
                    }
                });

                DoInvoke((MethodInvoker)delegate()
                {
                    progress.Close();
                });

                ProcessProgress cleanup = new ProcessProgress(toRemove.Count, "Cleaning up");
                int count = 0;
                DoInvoke((MethodInvoker)delegate()
                {
                    cleanup.Show(this);

                    // Remove deleted files
                    duplicateList.BeginUpdate();
                    foreach (ListViewItem i in toRemove)
                    {
                        duplicateList.Items.Remove(i);
                        cleanup.UpdateProgress(count++);
                    }
                    duplicateList.EndUpdate();
                    cleanup.Close();
                });

                if (toRemove.Count != count)
                {
                    MessageBox.Show("Some files could not be deleted. These items were not removed from the list.", "Partial File Deletion", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show("All selected files have been deleted.", "All Files Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Example #3
0
        private void _deleteFiles()
        {
            if (MessageBox.Show("WARNING: This will permanently delete all checked files in this list. This action cannot be undone.\r\n\r\nAre you sure you want to delete the selected files?", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                ProcessProgress progress = new ProcessProgress(duplicateList.Items.Count, "Deleting");
                DoInvoke((MethodInvoker) delegate()
                {
                    progress.Show(this);
                });

                List <ListViewItem> toRemove = new List <ListViewItem>();

                int total = 0;

                DoInvoke((MethodInvoker) delegate()
                {
                    foreach (ListViewItem i in duplicateList.Items)
                    {
                        if (i.Checked)
                        {
                            try
                            {
                                FileInfo f = new FileInfo(i.Text);
                                f.Delete();
                                toRemove.Add(i);
                            }
                            catch
                            {
                                // Delete failed. Skip the file.
                            }
                        }
                        total++;
                        progress.UpdateProgress(total);
                    }
                });

                DoInvoke((MethodInvoker) delegate()
                {
                    progress.Close();
                });

                ProcessProgress cleanup = new ProcessProgress(toRemove.Count, "Cleaning up");
                int             count   = 0;
                DoInvoke((MethodInvoker) delegate()
                {
                    cleanup.Show(this);

                    // Remove deleted files
                    duplicateList.BeginUpdate();
                    foreach (ListViewItem i in toRemove)
                    {
                        duplicateList.Items.Remove(i);
                        cleanup.UpdateProgress(count++);
                    }
                    duplicateList.EndUpdate();
                    cleanup.Close();
                });

                if (toRemove.Count != count)
                {
                    MessageBox.Show("Some files could not be deleted. These items were not removed from the list.", "Partial File Deletion", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show("All selected files have been deleted.", "All Files Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Example #4
0
        private void BeginProcessing(Hashtable duplicateResults)
        {
            DoInvoke((MethodInvoker) delegate()
            {
                duplicateList.BeginUpdate();
            });

            int max = 0;

            foreach (DictionaryEntry ss in duplicateResults)
            {
                max += ((List <string>)ss.Value).Count;
            }

            ProcessProgress progress = new ProcessProgress(max, "Processing");

            DoInvoke((MethodInvoker) delegate()
            {
                progress.Show(this);
            });

            int count = 0;
            int total = 0;

            foreach (DictionaryEntry dupeGroup in duplicateResults)
            {
                List <string> dupeGroupFiles = (List <string>)dupeGroup.Value;

                string headerKey = "Hasg: " + dupeGroup.Key.ToString() + ", Size: " + new FileInfo(dupeGroupFiles[0]).Length.ToString();

                DoInvoke((MethodInvoker) delegate()
                {
                    duplicateList.Groups.Add(headerKey, headerKey);
                });

                foreach (string file in dupeGroupFiles)
                {
                    ListViewItem i = new ListViewItem(duplicateList.Groups[headerKey]);
                    i.Text = file;

                    DoInvoke((MethodInvoker) delegate()
                    {
                        duplicateList.Items.Add(i);
                    });

                    count++;
                    total++;
                    if (count > 50)
                    {
                        count = 0;
                        progress.UpdateProgress(total);
                    }
                    Application.DoEvents();
                }
            }
            DoInvoke((MethodInvoker) delegate()
            {
                progress.Close();
            });

            DoInvoke((MethodInvoker) delegate()
            {
                duplicateList.EndUpdate();
            });
        }
Example #5
0
        private void BeginProcessing(List <List <string> > duplicateResults)
        {
            DoInvoke((MethodInvoker) delegate()
            {
                duplicateList.BeginUpdate();
            });

            int max = 0;

            foreach (List <string> ss in duplicateResults)
            {
                foreach (string s in ss)
                {
                    max++;
                }
            }

            ProcessProgress progress = new ProcessProgress(max, "Processing");

            DoInvoke((MethodInvoker) delegate()
            {
                progress.Show(this);
            });

            int count = 0;
            int total = 0;

            foreach (List <string> dupeGroup in duplicateResults)
            {
                FileInfo f = new FileInfo(dupeGroup[0]);

                string headerKey = Hasher.md5(Encoding.ASCII.GetBytes(f.FullName));

                DoInvoke((MethodInvoker) delegate()
                {
                    duplicateList.Groups.Add(headerKey, f.Name);
                });

                foreach (string file in dupeGroup)
                {
                    ListViewItem i = new ListViewItem(duplicateList.Groups[headerKey]);
                    i.Text = new FileInfo(file).FullName;

                    DoInvoke((MethodInvoker) delegate()
                    {
                        duplicateList.Items.Add(i);
                    });

                    count++;
                    total++;
                    if (count > 50)
                    {
                        count = 0;
                        progress.UpdateProgress(total);
                    }
                    Application.DoEvents();
                }
            }
            DoInvoke((MethodInvoker) delegate()
            {
                progress.Close();
            });

            DoInvoke((MethodInvoker) delegate()
            {
                duplicateList.EndUpdate();
            });
        }