private void ProcessBtn_Click(object sender, EventArgs e) { ProcessBtn.Text = "Processing..."; this.Cursor = Cursors.WaitCursor; Application.DoEvents(); mainProgressBar.Maximum = (int)totalSize; foreach (string filename in fileList) { // modified code from: http://stackoverflow.com/questions/10520048/calculate-md5-checksum-for-a-file using (var md5 = MD5.Create()) { try { using (var stream = File.OpenRead(filename)) { HashInfo currentHash = new HashInfo(); processingLabel.Text = "Currently processing file: " + filename; sizeLabel.Text = "Size: " + Math.Round(new FileInfo(filename).Length / 1048576.0, 2).ToString() + " MB Total size of duplicates found: " + Math.Round(bst.getDuplicates().getTotalSize() / 1024, 2) + " MB Duplicates Found: " + bst.getDuplicates().getCount(); Application.DoEvents(); currentHash.setHashString(BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower()); currentHash.SetFileName(filename); bst.Add(currentHash); mainProgressBar.Increment((int)new FileInfo(filename).Length / 8192); } } catch (System.Exception ex) { //ignore file } } } List <DuplicateInfo.duplicate> duplicateList = bst.getDuplicates().getDuplicateList(); for (int i = 0; i < bst.getDuplicates().getDuplicateList().Count; i++) { DuplicateInfo.duplicate aDuplicate = bst.getDuplicates().getDuplicateList()[i]; lstFilesFound.Items.Add(aDuplicate.message); } ProcessBtn.Text = "Process"; this.Cursor = Cursors.Default; cboDirectory.Enabled = true; ProcessBtn.Enabled = false; btnSearch.Enabled = true; mainProgressBar.Value = 0; deleteBtn.Enabled = true; }
private List <string> generateUndoArray() { List <string> undoArray = new List <string>(); for (int i = bst.getDuplicates().getCount() - 1; i >= 0; i--) { DuplicateInfo.duplicate curDuplicate = bst.getDuplicates().getDuplicateList()[i]; string curOutput = curDuplicate.duplicateA.GetFileName() + ";" + curDuplicate.duplicateB.GetFileName() + ";" + curDuplicate.type.ToString(); undoArray.Add(curOutput); } return(undoArray); }