Exemple #1
0
        private void button_Prehash(object sender, RoutedEventArgs e)
        {
            System.Windows.MessageBox.Show("Select a folder to generate the hashmap from.");
            FolderBrowserDialog diag = new FolderBrowserDialog();

            if (diag.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            string path = diag.SelectedPath;

            if (!Directory.Exists(path))
            {
                System.Windows.MessageBox.Show("INVALID PATH!");
                return;
            }

            WorkWindow win = new WorkWindow();

            win.Owner = this;
            win.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            win.Show();
            win.SetSecondaryMessage(">> READY!");

            string text = path;

            System.Windows.MessageBox.Show("Select a file to save the hashmap to.");

            SaveFileDialog sfdiag = new SaveFileDialog();

            sfdiag.Title        = "Serialized cache save location:";
            sfdiag.DefaultExt   = ".hcd";
            sfdiag.AddExtension = true;
            sfdiag.Filter       = "(Hashmap Cache Data File)|*.hcd";
            if (sfdiag.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            string fname = sfdiag.FileName;

            RunWorker(() =>
            {
                Prehash(text, win, fname);
                win.Dispatcher.Invoke(() =>
                {
                    win.SetPBarScore(100, 100);
                    win.SetSecondaryMessage(">> FINISHED!");
                    System.Windows.MessageBox.Show("Done!");
                    win.Close();
                });
            });
        }
Exemple #2
0
        private void Prehash(string dir, WorkWindow wwin, string fname)
        {
            IEnumerable <string> files =
                Directory.EnumerateFiles(dir, "*", SearchOption.AllDirectories)
                .Where(file => file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg"));

            ParallelOptions opts = new ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount - 1
            };

            int idx   = 0;
            int total = files.Count();

            Parallel.ForEach(files, opts, (file) =>
            {
                wwin.SetPBarScore(idx, total);
                wwin.SetSecondaryMessage($"BUILDING CACHE...\n  [{idx}] out of [{files.Count()}]");
                BitmapComparer.CacheDiff(file);
                idx++;
            });

            BitmapComparer.SaveDiffCacheToDisk(fname);
        }