Exemple #1
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();
        }
        private void ToIsoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            List <TagInfo> tags = new List <TagInfo>();

            for (int i = 0; i < listView1.SelectedItems.Count; i++)
            {
                if (!(listView1.SelectedItems[i].Tag is TagInfo))
                {
                    continue;
                }
                tags.Add(listView1.SelectedItems[i].Tag as TagInfo);
            }

            if (tags.Count == 0)
            {
                return;
            }


            var vfs  = new VirtualFilesystem();
            var vdir = new VirtualDirectoryInfo(vfs);

            //vdir.FullName = "z:\\" + tag.Name;
            vdir.FullName = "z:\\";
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt = "iso";
            sfd.Filter     = "iso images|*.iso";
            List <IFileInfo> flss = new List <IFileInfo>();

            foreach (var tag in tags)
            {
                flss.AddRange(tag.Files);
            }

            var gg = flss.GroupBy(z => z.FullName.ToLower()).ToArray();

            flss.Clear();
            foreach (var item in gg)
            {
                flss.Add(item.First());
            }

            var ord  = flss.GroupBy(z => z.FullName.ToLower()).ToArray();
            var ord2 = flss.GroupBy(z => z.Name.ToLower()).ToArray();

            if (ord2.Any(z => z.Count() > 1))
            {
                var fer = ord2.Where(z => z.Count() > 1).Sum(z => z.Count());
                Stuff.Warning(fer + " files has same names. Pack impossible");
                if (Stuff.Question("Open pack editor?") == DialogResult.Yes)
                {
                    PackEditor p = new PackEditor();
                    p.Init(flss);
                    p.MdiParent = mdi.MainForm;
                    p.Show();
                }
                return;
            }

            flss = ord.Select(z => z.First()).ToList();
            flss = flss.Where(z => z.Length > 0).ToList();

            vdir.ChildsFiles.AddRange(flss.Select(z => new VirtualFileInfo(z, vdir)
            {
                Directory = vdir
            }));

            vfs.Files = vdir.ChildsFiles.OfType <VirtualFileInfo>().ToList();
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                PackToIsoSettings stg = new PackToIsoSettings();
                stg.Dirs.Add(vdir);
                stg.Path              = sfd.FileName;
                stg.IncludeMeta       = true;
                stg.Root              = vdir;
                stg.AfterPackFinished = () => { Stuff.Info("Pack complete!"); };
                if (tags.Count == 1)
                {
                    stg.VolumeId = tags.First().Name.Replace(' ', '_');
                }
                else
                {
                    stg.VolumeId = $"Volume[{tags.Count} tags]";
                }
                if (stg.VolumeId.Length > 32)
                {
                    stg.VolumeId = stg.VolumeId.Substring(0, 32);
                }
                Stuff.PackToIso(stg);
            }
        }