コード例 #1
0
        private void ImgDedupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            var tag = listView1.SelectedItems[0].Tag;

            if (tag is TagInfo)
            {
                var dd    = listView1.SelectedItems[0].Tag as TagInfo;
                var files = dd.Files.Select(z => z);

                DedupContext ctx = new DedupContext(new IDirectoryInfo[] { }, files.OfType <IFileInfo>().ToArray());

                ProgressBarOperationDialog pd = new ProgressBarOperationDialog();
                IFileInfo[][] groups          = null;
                pd.Init(() =>
                {
                    groups = ImagesDeduplicationWindow.FindDuplicates(ctx, (p, max, title) => pd.SetProgress(title, p, max));
                    pd.Complete();
                });
                pd.ShowDialog();
                if (pd.DialogResult == DialogResult.Abort)
                {
                    return;
                }


                if (groups.Count() == 0)
                {
                    Stuff.Info("No duplicates found.");
                }
                else
                {
                    ImagesDeduplicationWindow rp = new ImagesDeduplicationWindow();
                    rp.MdiParent = mdi.MainForm;
                    rp.SetGroups(ctx, groups.ToArray());
                    rp.Show();
                }
            }
            else
            {
                List <IFileInfo>      ff = new List <IFileInfo>();
                List <IDirectoryInfo> dd = new List <IDirectoryInfo>();
                for (int i = 0; i < listView1.SelectedItems.Count; i++)
                {
                    var tag0 = listView1.SelectedItems[i].Tag;
                    if (tag0 is IFileInfo)
                    {
                        ff.Add(tag0 as IFileInfo);
                    }
                    if (tag0 is IDirectoryInfo)
                    {
                        dd.Add(tag0 as IDirectoryInfo);
                    }
                }
                DedupContext ctx = new DedupContext(dd.ToArray(), ff.ToArray());
                ProgressBarOperationDialog pd = new ProgressBarOperationDialog();
                IFileInfo[][] groups          = null;
                pd.Init(() =>
                {
                    groups = ImagesDeduplicationWindow.FindDuplicates(ctx, (p, max, title) => pd.SetProgress(title, p, max));
                    pd.Complete();
                });
                pd.ShowDialog();
                if (pd.DialogResult == DialogResult.Abort)
                {
                    return;
                }
                if (groups.Count() == 0)
                {
                    Stuff.Info("No duplicates found.");
                }
                else
                {
                    ImagesDeduplicationWindow rp = new ImagesDeduplicationWindow();
                    rp.MdiParent = mdi.MainForm;
                    rp.SetGroups(ctx, groups.ToArray());
                    rp.Show();
                }
            }
        }