Exemplo n.º 1
0
        private void background_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime start = DateTime.Now;
            string   type  = e.Argument.ToString().ToLowerInvariant();

            switch (type)
            {
            case "loaddirectory":
                string query = txtQuery.Text.Trim();
                background.ReportProgress(0, "Open: " + query);
                _results = DossierStream.Dir(query, _events);
                background.ReportProgress(2, "Count: " + _results.Count().ToString());
                if (_results.Count() > 0)
                {
                    DossierRootInfo root = (DossierRootInfo)_results[0];
                    background.ReportProgress(3, "Size: " + Dossier.BytesDisplayText(root.ReportRecursive.GrandTotal.TotalSize));
                }
                break;

            case "createmd5":
            case "verifymd5":
                background.ReportProgress(0, "Start: " + _root.FullPath);
                IEnumerable <DossierFileInfo> all = _root.GetAllFiles().OrderBy(f => f.FullPath);
                int total = all.Count();

                background.ReportProgress(0, "Total: " + total.ToString());
                int count = 0;
                foreach (DossierFileInfo file in all)
                {
                    background.ReportProgress(100 * count / total, "Hash: " + file.FullPath + " @ " + Dossier.BytesDisplayText(file.Size));
                    Guid hash = Dossier.CalculateMd5(file.FullPath);
                    if (type == "createmd5")
                    {
                        file.Hash = hash;
                    }
                    else if (file.Hash != hash)
                    {
                        background.ReportProgress(100 * count / total, "CORRUPT: " + file.FullPath);
                        break;
                    }
                    file.IsVerified = file.Hash == hash;
                    count++;
                }
                break;
            }

            DateTime stop = DateTime.Now;
            TimeSpan time = new TimeSpan(stop.Ticks - start.Ticks);

            background.ReportProgress(100, String.Format("DONE: {0}:{1:00}", time.Minutes, time.Seconds));
        }