private void dgMultiple_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { SelectAllMultipleVersions(); RefreshDataBind(); } else if (e.ColumnIndex == 0) { string ID = dgMultiple.Rows[e.RowIndex].Cells[1].Value.ToString(); string path = dgMultiple.Rows[e.RowIndex].Cells[5].Value.ToString(); SearchData.MultipleVersionRow row = dataset.MultipleVersion.Single(d => d.ID == ID && d.FilePath == path); row.BeginEdit(); if (row.Deleted) { dgMultiple.Rows[e.RowIndex].Cells[0].Value = row.Deleted = false; } else { dgMultiple.Rows[e.RowIndex].Cells[0].Value = row.Deleted = true; } row.EndEdit(); dataset.MultipleVersion.AcceptChanges(); // ((SearchData.MultipleVersionRow)dataset.MultipleVersion.Rows[e.RowIndex]).Deleted = !(((SearchData.MultipleVersionRow)dataset.MultipleVersion.Rows[e.RowIndex]).Deleted); // dgMultiple.DataSource = dataset.MultipleVersion; } UpdateFinalDeleteList(); }
/// <summary> /// _searchDuplicate - creates new thread and get the data /// </summary> /// <param name="startPath"></param> /// <param name="extension"></param> /// <param name="includeTempFiles"></param> /// <returns></returns> SearchData _searchDuplicate(string startPath, string extension, bool includeTempFiles, Logger log) { if (QuitNow) { return(searchData); } SendMessage("FileSearcher Starting in " + startPath); IEnumerable <string> directories = new List <string>(); //Enumerate all child directories if (Directory.Exists(startPath)) { directories = Directory.EnumerateDirectories(startPath); if (directories != null && directories.Count <string>() >= 0) { foreach (string directory in directories) { DirectoryInfo di = new DirectoryInfo(directory); if (((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) || ((di.Attributes & FileAttributes.System) == FileAttributes.System) || ((di.Attributes & FileAttributes.Temporary) == FileAttributes.Temporary) && includeTempFiles) { continue; } //IAsyncResult ar = BeginSearcherAsync(directory, extension, includeTempFiles, log, CallbackMethod); SearchData dataInDir = _searchDuplicate(directory, extension, includeTempFiles, log); if (dataInDir != null) { searchData.Merge(dataInDir); } if (QuitNow) { return(searchData); } } } } //Enumerate files in that directory only. IEnumerable <string> files = Directory.EnumerateFiles(startPath, extension, SearchOption.TopDirectoryOnly); //string[] files = Directory.GetFiles(startPath, extension, SearchOption.AllDirectories); SendMessage("Files in " + startPath + " Received."); SendMessage(" Processing files in " + startPath); foreach (string file in files) { //Quit with available result if Cancellation requested if (QuitNow) { return(searchData); } FileInfo fi = new FileInfo(file); if (((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) || ((fi.Attributes & FileAttributes.System) == FileAttributes.System) || ((fi.Attributes & FileAttributes.Temporary) == FileAttributes.Temporary) && includeTempFiles) { continue; } //To compare we dont need to use file name. //1 # Possible duplicate - Compare = file length and extension and last update time. //2 # Matching different version - Compare = file name and file length and extension //3 # Exact match file name and file length and extension and last update time string rowID = fi.Name + fi.Length.ToString() + fi.Extension; //Search for an exact duplicate if (searchData.Documents.FindByID(rowID + fi.LastWriteTimeUtc.Ticks.ToString()) != null) //log a duplicate file found { SearchData.ExactDuplicateRow counterRow = searchData.ExactDuplicate.NewExactDuplicateRow(); counterRow.FileName = fi.Name; counterRow.ID = rowID; counterRow.ID_NoVersion = rowID; counterRow.FilePath = fi.DirectoryName; counterRow.LastModifiedTime = fi.LastWriteTimeUtc; counterRow.Size = fi.Length / 1024; if (searchData.ExactDuplicate.FindByIDFilePath(counterRow.ID, counterRow.FilePath) == null) { searchData.ExactDuplicate.AddExactDuplicateRow(counterRow); } } //Search for another version(Not an exact duplicate version) else if (searchData.Documents.FindByID(rowID) != null && searchData.Documents.Any(r => r.ID.StartsWith(rowID))) { SearchData.MultipleVersionRow multipleVersionRow = searchData.MultipleVersion.NewMultipleVersionRow(); multipleVersionRow.FileName = fi.Name; multipleVersionRow.ID_NoVersion = rowID; multipleVersionRow.ID = rowID + fi.LastWriteTimeUtc.Ticks.ToString(); multipleVersionRow.FilePath = fi.DirectoryName; multipleVersionRow.LastModifiedTime = fi.LastWriteTimeUtc; multipleVersionRow.Size = fi.Length / 1024; searchData.MultipleVersion.AddMultipleVersionRow(multipleVersionRow); } else// This file is not yet in the list { SearchData.DocumentsRow row = searchData.Documents.NewDocumentsRow(); row.LastModifiedTime = fi.LastWriteTimeUtc; row.ID_NoVersion = rowID; row.ID = rowID + fi.LastWriteTimeUtc.Ticks.ToString(); row.FileName = fi.Name; row.Size = fi.Length / 1024; row.FilePath = fi.DirectoryName; searchData.Documents.AddDocumentsRow(row); } searchData.AcceptChanges(); } SendMessage("processing complete " + startPath + "... now saving"); return(searchData); }