コード例 #1
0
 private void GetFileHashtable(List <string> fileList, ref Hashtable existing)
 {
     foreach (string filename in fileList)
     {
         FileInfo file = new FileInfo(filename);
         if (!ExcludeFiles.IsExcludedFile(file.Name))
         {
             try
             {
                 string hash = Hasher.md5(File.ReadAllBytes(file.FullName));
                 if (existing.ContainsKey(hash))
                 {
                     ((List <string>)existing[hash]).Add(file.FullName);
                     uiData.DuplicatesFound++;
                     updateUI(uiData);
                 }
                 else
                 {
                     List <string> newFileList = new List <string>();
                     newFileList.Add(file.FullName);
                     existing.Add(hash, newFileList);
                 }
             }
             catch
             {
                 // Nothing on error, if we can't do anything with the file just skip it.
                 continue;
             }
         }
         uiData.CompletedFiles++;
         updateUI(uiData);
     }
 }
コード例 #2
0
        private void BeginProcessing(List <List <string> > duplicateResults)
        {
            DoInvoke((MethodInvoker) delegate()
            {
                duplicateList.BeginUpdate();
            });

            int max = 0;

            foreach (List <string> ss in duplicateResults)
            {
                foreach (string s in ss)
                {
                    max++;
                }
            }

            ProcessProgress progress = new ProcessProgress(max, "Processing");

            DoInvoke((MethodInvoker) delegate()
            {
                progress.Show(this);
            });

            int count = 0;
            int total = 0;

            foreach (List <string> dupeGroup in duplicateResults)
            {
                FileInfo f = new FileInfo(dupeGroup[0]);

                string headerKey = Hasher.md5(Encoding.ASCII.GetBytes(f.FullName));

                DoInvoke((MethodInvoker) delegate()
                {
                    duplicateList.Groups.Add(headerKey, f.Name);
                });

                foreach (string file in dupeGroup)
                {
                    ListViewItem i = new ListViewItem(duplicateList.Groups[headerKey]);
                    i.Text = new FileInfo(file).FullName;

                    DoInvoke((MethodInvoker) delegate()
                    {
                        duplicateList.Items.Add(i);
                    });

                    count++;
                    total++;
                    if (count > 50)
                    {
                        count = 0;
                        progress.UpdateProgress(total);
                    }
                    Application.DoEvents();
                }
            }
            DoInvoke((MethodInvoker) delegate()
            {
                progress.Close();
            });

            DoInvoke((MethodInvoker) delegate()
            {
                duplicateList.EndUpdate();
            });
        }