Пример #1
0
        private bool IsImageFilter(IFileInfo item)
        {
            if (!checkBox3.Checked)
            {
                return(true);
            }
            var h = ImagesDeduplicationWindow.GetImageHash(item.FullName);

            return(Diff(h, imgHashInt) < 800);
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (searchThread != null)
            {
                button1.Text = "Start";
                searchThread.Abort();
                searchThread = null;
                return;
            }
            button1.Text = "Stop";

            var spl = textBox1.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
            var dd  = (spl.Select(z => new DirectoryInfoWrapper(z))).OfType <IDirectoryInfo>().ToList();

            if (tagStorageSearchMode)
            {
                dd = Stuff.Tags.Select(z => new VirtualDirectoryInfo(null)
                {
                    ChildsFiles = z.Files.Select(u => u).OfType <IFileInfo>().ToList()
                }).OfType <IDirectoryInfo>().ToList();
            }

            if (checkBox2.Checked)
            {
                dd.Clear();
                var vfs = new VirtualFilesystem()
                {
                    UseIndexes = true
                };

                var vdir = new VirtualDirectoryInfo(vfs);
                vdir.Name     = "indexes";
                vdir.FullName = "indexes";


                foreach (var item in Stuff.Indexes)
                {
                    vdir.ChildsFiles.Add(new VirtualFileInfo(new FileInfoWrapper(item.Path), vdir));
                }
                vfs.Files.AddRange(vdir.ChildsFiles.OfType <VirtualFileInfo>());
                dd.Add(vdir);
            }

            searchThread = new Thread(() =>
            {
                List <IFileInfo> files = new List <IFileInfo>();

                if (tagStorageSearchMode)
                {
                    foreach (var item in Stuff.Tags)
                    {
                        files.AddRange(item.Files.Select(z => z));
                    }
                }
                else
                {
                    foreach (var item in dd)
                    {
                        files.AddRange(Stuff.GetAllFiles(item, level: 0, maxlevel: (int)numericUpDown1.Value));
                    }
                }

                progressBar1.Invoke((Action)(() =>
                {
                    progressBar1.Value = 0;
                    progressBar1.Maximum = files.Count;
                }));


                listView2.Items.Clear();
                searchHash.Clear();

                if (checkBox3.Checked)
                {
                    var b = pictureBox1.Image as Bitmap;
                    b.SetResolution(96, 96);
                    imgHashInt = ImagesDeduplicationWindow.GetImageHash2D(b);
                    //imgHash = ImagesDeduplicationWindow.ToHash(imgHashInt);
                }
                foreach (var d in dd)
                {
                    loop(d, () =>
                    {
                        progressBar1.Invoke((Action)(() =>
                        {
                            progressBar1.Value++;
                        }));
                    }, (int)numericUpDown1.Value);
                }

                //rec1(d, () => { progressBar1.Value++; });
                progressBar1.Invoke((Action)(() =>
                {
                    toolStripStatusLabel1.Text = "Files found: " + listView2.Items.Count;
                    button1.Text = "Start";
                }));
                searchThread = null;
            });
            searchThread.IsBackground = true;
            searchThread.Start();
        }
Пример #3
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();
                }
            }
        }