private async void button1_Click(object sender, EventArgs e) { finder = new DuplicateFinder { SelectedDirectory = new DirectoryInfo(TxtFolderPath.Text) }; finder.Progress.ProgressChanged += Progress_ProgressChanged1; try { var watch = new Stopwatch(); watch.Start(); await Task.Run(() => finder.StartSearchOfDuplicatesAsync()); watch.Stop(); pbOverallProgress.Value = 100; loadingScreen = new FrmLoading(watch.Elapsed, finder.ProcessedDirectoriesCount, finder.Duplicates.Count, finder.TotalSpaceInDuplicates, finder.TotalSpaceLostByDuplicates); loadingScreen.Show(); await Task.Run(() => SearchDuplicates()); stlbStatus.Text = $"Task finished in: {watch.Elapsed}. Found: {finder.Duplicates.Count} files with duplications. Total space lost by duplicates: {Toolkit.GetSizeString(finder.TotalSpaceInDuplicates)}."; #region ToLog //txtConsole.AppendText($"Task started at: {DateTime.Now}{Environment.NewLine}"); //txtConsole.AppendText($"Task finished at: {DateTime.Now}{Environment.NewLine}Task time: {watch.Elapsed}{Environment.NewLine}"); //txtConsole.AppendText($"-------------------------------------{Environment.NewLine}"); //txtConsole.AppendText($"Founded: {finder.Duplicates.Count} files repeated at least 1 time.{Environment.NewLine}"); //txtConsole.AppendText($"Total space in duplicates: {Toolkit.GetSizeString(finder.TotalSpaceInDuplicates)}{Environment.NewLine}"); //txtConsole.AppendText($"Total space lost by duplicates: {Toolkit.GetSizeString(finder.TotalSpaceLostByDuplicates)}{Environment.NewLine}"); //txtConsole.AppendText("-------------------------------------"); //txtConsole.SuspendLayout(); //foreach (var file in finder.Duplicates) //{ // txtConsole.AppendText($"-------------------------------------{ Environment.NewLine }File: { file.FileName } - Repeated: { file.TimesRepeated } times. - Average size: { Toolkit.GetSizeString(file.AverageFileSize) } - Total size in duplicates: { Toolkit.GetSizeString(file.TotalDuplicationSize) } { Environment.NewLine }{ string.Join(Environment.NewLine, file.Files.Select(f => f.FullName).ToArray()) } {Environment.NewLine}"); //} //txtConsole.AppendText("-------------------------"); //txtConsole.AppendText(Environment.NewLine); //txtConsole.AppendText($"Total space in duplicates: { Toolkit.GetSizeString(finder.TotalSpaceInDuplicates) }"); //txtConsole.AppendText(Environment.NewLine); //txtConsole.AppendText($"Total space lost by duplicates: { Toolkit.GetSizeString(finder.TotalSpaceLostByDuplicates) }"); //txtConsole.ResumeLayout(); #endregion return; } catch (Exception ex) { _ = MessageBox.Show($"Ups! Something happend. This is the message: {ex.Message}", "Problem", MessageBoxButtons.OK, MessageBoxIcon.Error); ResetUI(); return; } }
private void AddDatagridRow(DuplicatedFile duplicate) { Bitmap icon = null; try { icon = Icon.ExtractAssociatedIcon(duplicate.Files[0].FullName).ToBitmap(); } catch (Exception) { // TODO - Log the error extracting icon. } var added = dgvDuplicates.Rows.Add(icon, duplicate.FileName, duplicate.TimesRepeated, Toolkit.GetSizeString(duplicate.AverageFileSize), Toolkit.GetSizeString(duplicate.TotalDuplicationSize)); dgvDuplicates.Rows[added].Tag = duplicate; }